mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-18 13:34:22 +01:00
feat: add BIP21 support (#414)
Co-authored-by: Erdem Yerebasmaz <erdem@yerebasmaz.com> Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
This commit is contained in:
@@ -118,23 +118,23 @@ fun asBuyBitcoinRequest(buyBitcoinRequest: ReadableMap): BuyBitcoinRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
buyBitcoinRequest,
|
||||
arrayOf(
|
||||
"prepareRes",
|
||||
"prepareResponse",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val prepareRes = buyBitcoinRequest.getMap("prepareRes")?.let { asPrepareBuyBitcoinResponse(it) }!!
|
||||
val prepareResponse = buyBitcoinRequest.getMap("prepareResponse")?.let { asPrepareBuyBitcoinResponse(it) }!!
|
||||
val redirectUrl = if (hasNonNullKey(buyBitcoinRequest, "redirectUrl")) buyBitcoinRequest.getString("redirectUrl") else null
|
||||
return BuyBitcoinRequest(
|
||||
prepareRes,
|
||||
prepareResponse,
|
||||
redirectUrl,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(buyBitcoinRequest: BuyBitcoinRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"prepareRes" to readableMapOf(buyBitcoinRequest.prepareRes),
|
||||
"prepareResponse" to readableMapOf(buyBitcoinRequest.prepareResponse),
|
||||
"redirectUrl" to buyBitcoinRequest.redirectUrl,
|
||||
)
|
||||
|
||||
@@ -1213,24 +1213,24 @@ fun asPayOnchainRequest(payOnchainRequest: ReadableMap): PayOnchainRequest? {
|
||||
payOnchainRequest,
|
||||
arrayOf(
|
||||
"address",
|
||||
"prepareRes",
|
||||
"prepareResponse",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val address = payOnchainRequest.getString("address")!!
|
||||
val prepareRes = payOnchainRequest.getMap("prepareRes")?.let { asPreparePayOnchainResponse(it) }!!
|
||||
val prepareResponse = payOnchainRequest.getMap("prepareResponse")?.let { asPreparePayOnchainResponse(it) }!!
|
||||
return PayOnchainRequest(
|
||||
address,
|
||||
prepareRes,
|
||||
prepareResponse,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(payOnchainRequest: PayOnchainRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"address" to payOnchainRequest.address,
|
||||
"prepareRes" to readableMapOf(payOnchainRequest.prepareRes),
|
||||
"prepareResponse" to readableMapOf(payOnchainRequest.prepareResponse),
|
||||
)
|
||||
|
||||
fun asPayOnchainRequestList(arr: ReadableArray): List<PayOnchainRequest> {
|
||||
@@ -1253,54 +1253,41 @@ fun asPayment(payment: ReadableMap): Payment? {
|
||||
"feesSat",
|
||||
"paymentType",
|
||||
"status",
|
||||
"description",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val destination = if (hasNonNullKey(payment, "destination")) payment.getString("destination") else null
|
||||
val txId = if (hasNonNullKey(payment, "txId")) payment.getString("txId") else null
|
||||
val timestamp = payment.getInt("timestamp").toUInt()
|
||||
val amountSat = payment.getDouble("amountSat").toULong()
|
||||
val feesSat = payment.getDouble("feesSat").toULong()
|
||||
val paymentType = payment.getString("paymentType")?.let { asPaymentType(it) }!!
|
||||
val status = payment.getString("status")?.let { asPaymentState(it) }!!
|
||||
val description = payment.getString("description")!!
|
||||
val txId = if (hasNonNullKey(payment, "txId")) payment.getString("txId") else null
|
||||
val swapId = if (hasNonNullKey(payment, "swapId")) payment.getString("swapId") else null
|
||||
val preimage = if (hasNonNullKey(payment, "preimage")) payment.getString("preimage") else null
|
||||
val bolt11 = if (hasNonNullKey(payment, "bolt11")) payment.getString("bolt11") else null
|
||||
val refundTxId = if (hasNonNullKey(payment, "refundTxId")) payment.getString("refundTxId") else null
|
||||
val refundTxAmountSat = if (hasNonNullKey(payment, "refundTxAmountSat")) payment.getDouble("refundTxAmountSat").toULong() else null
|
||||
val details = if (hasNonNullKey(payment, "details")) payment.getMap("details")?.let { asPaymentDetails(it) } else null
|
||||
return Payment(
|
||||
destination,
|
||||
txId,
|
||||
timestamp,
|
||||
amountSat,
|
||||
feesSat,
|
||||
paymentType,
|
||||
status,
|
||||
description,
|
||||
txId,
|
||||
swapId,
|
||||
preimage,
|
||||
bolt11,
|
||||
refundTxId,
|
||||
refundTxAmountSat,
|
||||
details,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(payment: Payment): ReadableMap =
|
||||
readableMapOf(
|
||||
"destination" to payment.destination,
|
||||
"txId" to payment.txId,
|
||||
"timestamp" to payment.timestamp,
|
||||
"amountSat" to payment.amountSat,
|
||||
"feesSat" to payment.feesSat,
|
||||
"paymentType" to payment.paymentType.name.lowercase(),
|
||||
"status" to payment.status.name.lowercase(),
|
||||
"description" to payment.description,
|
||||
"txId" to payment.txId,
|
||||
"swapId" to payment.swapId,
|
||||
"preimage" to payment.preimage,
|
||||
"bolt11" to payment.bolt11,
|
||||
"refundTxId" to payment.refundTxId,
|
||||
"refundTxAmountSat" to payment.refundTxAmountSat,
|
||||
"details" to payment.details?.let { readableMapOf(it) },
|
||||
)
|
||||
|
||||
fun asPaymentList(arr: ReadableArray): List<Payment> {
|
||||
@@ -1474,136 +1461,92 @@ fun asPreparePayOnchainResponseList(arr: ReadableArray): List<PreparePayOnchainR
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareReceiveOnchainRequest(prepareReceiveOnchainRequest: ReadableMap): PrepareReceiveOnchainRequest? {
|
||||
fun asPrepareReceiveRequest(prepareReceiveRequest: ReadableMap): PrepareReceiveRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareReceiveOnchainRequest,
|
||||
prepareReceiveRequest,
|
||||
arrayOf(
|
||||
"payerAmountSat",
|
||||
"paymentMethod",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val payerAmountSat = prepareReceiveOnchainRequest.getDouble("payerAmountSat").toULong()
|
||||
return PrepareReceiveOnchainRequest(
|
||||
val payerAmountSat =
|
||||
if (hasNonNullKey(
|
||||
prepareReceiveRequest,
|
||||
"payerAmountSat",
|
||||
)
|
||||
) {
|
||||
prepareReceiveRequest.getDouble("payerAmountSat").toULong()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val paymentMethod = prepareReceiveRequest.getString("paymentMethod")?.let { asPaymentMethod(it) }!!
|
||||
return PrepareReceiveRequest(
|
||||
payerAmountSat,
|
||||
paymentMethod,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareReceiveOnchainRequest: PrepareReceiveOnchainRequest): ReadableMap =
|
||||
fun readableMapOf(prepareReceiveRequest: PrepareReceiveRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"payerAmountSat" to prepareReceiveOnchainRequest.payerAmountSat,
|
||||
"payerAmountSat" to prepareReceiveRequest.payerAmountSat,
|
||||
"paymentMethod" to prepareReceiveRequest.paymentMethod.name.lowercase(),
|
||||
)
|
||||
|
||||
fun asPrepareReceiveOnchainRequestList(arr: ReadableArray): List<PrepareReceiveOnchainRequest> {
|
||||
val list = ArrayList<PrepareReceiveOnchainRequest>()
|
||||
fun asPrepareReceiveRequestList(arr: ReadableArray): List<PrepareReceiveRequest> {
|
||||
val list = ArrayList<PrepareReceiveRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareReceiveOnchainRequest(value)!!)
|
||||
is ReadableMap -> list.add(asPrepareReceiveRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareReceiveOnchainResponse(prepareReceiveOnchainResponse: ReadableMap): PrepareReceiveOnchainResponse? {
|
||||
fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiveResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareReceiveOnchainResponse,
|
||||
prepareReceiveResponse,
|
||||
arrayOf(
|
||||
"payerAmountSat",
|
||||
"paymentMethod",
|
||||
"feesSat",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val payerAmountSat = prepareReceiveOnchainResponse.getDouble("payerAmountSat").toULong()
|
||||
val feesSat = prepareReceiveOnchainResponse.getDouble("feesSat").toULong()
|
||||
return PrepareReceiveOnchainResponse(
|
||||
val payerAmountSat =
|
||||
if (hasNonNullKey(
|
||||
prepareReceiveResponse,
|
||||
"payerAmountSat",
|
||||
)
|
||||
) {
|
||||
prepareReceiveResponse.getDouble("payerAmountSat").toULong()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val paymentMethod = prepareReceiveResponse.getString("paymentMethod")?.let { asPaymentMethod(it) }!!
|
||||
val feesSat = prepareReceiveResponse.getDouble("feesSat").toULong()
|
||||
return PrepareReceiveResponse(
|
||||
payerAmountSat,
|
||||
paymentMethod,
|
||||
feesSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareReceiveOnchainResponse: PrepareReceiveOnchainResponse): ReadableMap =
|
||||
fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"payerAmountSat" to prepareReceiveOnchainResponse.payerAmountSat,
|
||||
"feesSat" to prepareReceiveOnchainResponse.feesSat,
|
||||
"payerAmountSat" to prepareReceiveResponse.payerAmountSat,
|
||||
"paymentMethod" to prepareReceiveResponse.paymentMethod.name.lowercase(),
|
||||
"feesSat" to prepareReceiveResponse.feesSat,
|
||||
)
|
||||
|
||||
fun asPrepareReceiveOnchainResponseList(arr: ReadableArray): List<PrepareReceiveOnchainResponse> {
|
||||
val list = ArrayList<PrepareReceiveOnchainResponse>()
|
||||
fun asPrepareReceiveResponseList(arr: ReadableArray): List<PrepareReceiveResponse> {
|
||||
val list = ArrayList<PrepareReceiveResponse>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareReceiveOnchainResponse(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareReceivePaymentRequest(prepareReceivePaymentRequest: ReadableMap): PrepareReceivePaymentRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareReceivePaymentRequest,
|
||||
arrayOf(
|
||||
"payerAmountSat",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val payerAmountSat = prepareReceivePaymentRequest.getDouble("payerAmountSat").toULong()
|
||||
return PrepareReceivePaymentRequest(
|
||||
payerAmountSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareReceivePaymentRequest: PrepareReceivePaymentRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"payerAmountSat" to prepareReceivePaymentRequest.payerAmountSat,
|
||||
)
|
||||
|
||||
fun asPrepareReceivePaymentRequestList(arr: ReadableArray): List<PrepareReceivePaymentRequest> {
|
||||
val list = ArrayList<PrepareReceivePaymentRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareReceivePaymentRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareReceivePaymentResponse(prepareReceivePaymentResponse: ReadableMap): PrepareReceivePaymentResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareReceivePaymentResponse,
|
||||
arrayOf(
|
||||
"payerAmountSat",
|
||||
"feesSat",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val payerAmountSat = prepareReceivePaymentResponse.getDouble("payerAmountSat").toULong()
|
||||
val feesSat = prepareReceivePaymentResponse.getDouble("feesSat").toULong()
|
||||
return PrepareReceivePaymentResponse(
|
||||
payerAmountSat,
|
||||
feesSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareReceivePaymentResponse: PrepareReceivePaymentResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"payerAmountSat" to prepareReceivePaymentResponse.payerAmountSat,
|
||||
"feesSat" to prepareReceivePaymentResponse.feesSat,
|
||||
)
|
||||
|
||||
fun asPrepareReceivePaymentResponseList(arr: ReadableArray): List<PrepareReceivePaymentResponse> {
|
||||
val list = ArrayList<PrepareReceivePaymentResponse>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareReceivePaymentResponse(value)!!)
|
||||
is ReadableMap -> list.add(asPrepareReceiveResponse(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
@@ -1693,21 +1636,24 @@ fun asPrepareSendRequest(prepareSendRequest: ReadableMap): PrepareSendRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareSendRequest,
|
||||
arrayOf(
|
||||
"invoice",
|
||||
"destination",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val invoice = prepareSendRequest.getString("invoice")!!
|
||||
val destination = prepareSendRequest.getString("destination")!!
|
||||
val amountSat = if (hasNonNullKey(prepareSendRequest, "amountSat")) prepareSendRequest.getDouble("amountSat").toULong() else null
|
||||
return PrepareSendRequest(
|
||||
invoice,
|
||||
destination,
|
||||
amountSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareSendRequest: PrepareSendRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"invoice" to prepareSendRequest.invoice,
|
||||
"destination" to prepareSendRequest.destination,
|
||||
"amountSat" to prepareSendRequest.amountSat,
|
||||
)
|
||||
|
||||
fun asPrepareSendRequestList(arr: ReadableArray): List<PrepareSendRequest> {
|
||||
@@ -1725,24 +1671,24 @@ fun asPrepareSendResponse(prepareSendResponse: ReadableMap): PrepareSendResponse
|
||||
if (!validateMandatoryFields(
|
||||
prepareSendResponse,
|
||||
arrayOf(
|
||||
"invoice",
|
||||
"destination",
|
||||
"feesSat",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val invoice = prepareSendResponse.getString("invoice")!!
|
||||
val destination = prepareSendResponse.getMap("destination")?.let { asSendDestination(it) }!!
|
||||
val feesSat = prepareSendResponse.getDouble("feesSat").toULong()
|
||||
return PrepareSendResponse(
|
||||
invoice,
|
||||
destination,
|
||||
feesSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareSendResponse: PrepareSendResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"invoice" to prepareSendResponse.invoice,
|
||||
"destination" to readableMapOf(prepareSendResponse.destination),
|
||||
"feesSat" to prepareSendResponse.feesSat,
|
||||
)
|
||||
|
||||
@@ -1793,63 +1739,27 @@ fun asRateList(arr: ReadableArray): List<Rate> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asReceiveOnchainResponse(receiveOnchainResponse: ReadableMap): ReceiveOnchainResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
receiveOnchainResponse,
|
||||
arrayOf(
|
||||
"address",
|
||||
"bip21",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val address = receiveOnchainResponse.getString("address")!!
|
||||
val bip21 = receiveOnchainResponse.getString("bip21")!!
|
||||
return ReceiveOnchainResponse(
|
||||
address,
|
||||
bip21,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(receiveOnchainResponse: ReceiveOnchainResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"address" to receiveOnchainResponse.address,
|
||||
"bip21" to receiveOnchainResponse.bip21,
|
||||
)
|
||||
|
||||
fun asReceiveOnchainResponseList(arr: ReadableArray): List<ReceiveOnchainResponse> {
|
||||
val list = ArrayList<ReceiveOnchainResponse>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asReceiveOnchainResponse(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asReceivePaymentRequest(receivePaymentRequest: ReadableMap): ReceivePaymentRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
receivePaymentRequest,
|
||||
arrayOf(
|
||||
"prepareRes",
|
||||
"prepareResponse",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val prepareRes = receivePaymentRequest.getMap("prepareRes")?.let { asPrepareReceivePaymentResponse(it) }!!
|
||||
val prepareResponse = receivePaymentRequest.getMap("prepareResponse")?.let { asPrepareReceiveResponse(it) }!!
|
||||
val description = if (hasNonNullKey(receivePaymentRequest, "description")) receivePaymentRequest.getString("description") else null
|
||||
return ReceivePaymentRequest(
|
||||
prepareRes,
|
||||
prepareResponse,
|
||||
description,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(receivePaymentRequest: ReceivePaymentRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"prepareRes" to readableMapOf(receivePaymentRequest.prepareRes),
|
||||
"prepareResponse" to readableMapOf(receivePaymentRequest.prepareResponse),
|
||||
"description" to receivePaymentRequest.description,
|
||||
)
|
||||
|
||||
@@ -1868,25 +1778,21 @@ fun asReceivePaymentResponse(receivePaymentResponse: ReadableMap): ReceivePaymen
|
||||
if (!validateMandatoryFields(
|
||||
receivePaymentResponse,
|
||||
arrayOf(
|
||||
"id",
|
||||
"invoice",
|
||||
"destination",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val id = receivePaymentResponse.getString("id")!!
|
||||
val invoice = receivePaymentResponse.getString("invoice")!!
|
||||
val destination = receivePaymentResponse.getString("destination")!!
|
||||
return ReceivePaymentResponse(
|
||||
id,
|
||||
invoice,
|
||||
destination,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(receivePaymentResponse: ReceivePaymentResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"id" to receivePaymentResponse.id,
|
||||
"invoice" to receivePaymentResponse.invoice,
|
||||
"destination" to receivePaymentResponse.destination,
|
||||
)
|
||||
|
||||
fun asReceivePaymentResponseList(arr: ReadableArray): List<ReceivePaymentResponse> {
|
||||
@@ -2176,6 +2082,38 @@ fun asRouteHintHopList(arr: ReadableArray): List<RouteHintHop> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asSendPaymentRequest(sendPaymentRequest: ReadableMap): SendPaymentRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
sendPaymentRequest,
|
||||
arrayOf(
|
||||
"prepareResponse",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val prepareResponse = sendPaymentRequest.getMap("prepareResponse")?.let { asPrepareSendResponse(it) }!!
|
||||
return SendPaymentRequest(
|
||||
prepareResponse,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(sendPaymentRequest: SendPaymentRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"prepareResponse" to readableMapOf(sendPaymentRequest.prepareResponse),
|
||||
)
|
||||
|
||||
fun asSendPaymentRequestList(arr: ReadableArray): List<SendPaymentRequest> {
|
||||
val list = ArrayList<SendPaymentRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asSendPaymentRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asSendPaymentResponse(sendPaymentResponse: ReadableMap): SendPaymentResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
sendPaymentResponse,
|
||||
@@ -2580,6 +2518,73 @@ fun asNetworkList(arr: ReadableArray): List<Network> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPaymentDetails(paymentDetails: ReadableMap): PaymentDetails? {
|
||||
val type = paymentDetails.getString("type")
|
||||
|
||||
if (type == "lightning") {
|
||||
return PaymentDetails.Lightning(paymentDetails.getString("swapId")!!)
|
||||
}
|
||||
if (type == "liquid") {
|
||||
return PaymentDetails.Liquid(paymentDetails.getString("destination")!!)
|
||||
}
|
||||
if (type == "bitcoin") {
|
||||
return PaymentDetails.Bitcoin(paymentDetails.getString("swapId")!!)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun readableMapOf(paymentDetails: PaymentDetails): ReadableMap? {
|
||||
val map = Arguments.createMap()
|
||||
when (paymentDetails) {
|
||||
is PaymentDetails.Lightning -> {
|
||||
pushToMap(map, "type", "lightning")
|
||||
pushToMap(map, "swapId", paymentDetails.swapId)
|
||||
pushToMap(map, "description", paymentDetails.description)
|
||||
pushToMap(map, "preimage", paymentDetails.preimage)
|
||||
pushToMap(map, "bolt11", paymentDetails.bolt11)
|
||||
pushToMap(map, "refundTxId", paymentDetails.refundTxId)
|
||||
pushToMap(map, "refundTxAmountSat", paymentDetails.refundTxAmountSat)
|
||||
}
|
||||
is PaymentDetails.Liquid -> {
|
||||
pushToMap(map, "type", "liquid")
|
||||
pushToMap(map, "destination", paymentDetails.destination)
|
||||
pushToMap(map, "description", paymentDetails.description)
|
||||
}
|
||||
is PaymentDetails.Bitcoin -> {
|
||||
pushToMap(map, "type", "bitcoin")
|
||||
pushToMap(map, "swapId", paymentDetails.swapId)
|
||||
pushToMap(map, "description", paymentDetails.description)
|
||||
pushToMap(map, "refundTxId", paymentDetails.refundTxId)
|
||||
pushToMap(map, "refundTxAmountSat", paymentDetails.refundTxAmountSat)
|
||||
}
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
fun asPaymentDetailsList(arr: ReadableArray): List<PaymentDetails> {
|
||||
val list = ArrayList<PaymentDetails>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPaymentDetails(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPaymentMethod(type: String): PaymentMethod = PaymentMethod.valueOf(camelToUpperSnakeCase(type))
|
||||
|
||||
fun asPaymentMethodList(arr: ReadableArray): List<PaymentMethod> {
|
||||
val list = ArrayList<PaymentMethod>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is String -> list.add(asPaymentMethod(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPaymentState(type: String): PaymentState = PaymentState.valueOf(camelToUpperSnakeCase(type))
|
||||
|
||||
fun asPaymentStateList(arr: ReadableArray): List<PaymentState> {
|
||||
@@ -2678,6 +2683,44 @@ fun asSdkEventList(arr: ReadableArray): List<SdkEvent> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asSendDestination(sendDestination: ReadableMap): SendDestination? {
|
||||
val type = sendDestination.getString("type")
|
||||
|
||||
if (type == "liquidAddress") {
|
||||
return SendDestination.LiquidAddress(sendDestination.getMap("addressData")?.let { asLiquidAddressData(it) }!!)
|
||||
}
|
||||
if (type == "bolt11") {
|
||||
return SendDestination.Bolt11(sendDestination.getMap("invoice")?.let { asLnInvoice(it) }!!)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun readableMapOf(sendDestination: SendDestination): ReadableMap? {
|
||||
val map = Arguments.createMap()
|
||||
when (sendDestination) {
|
||||
is SendDestination.LiquidAddress -> {
|
||||
pushToMap(map, "type", "liquidAddress")
|
||||
pushToMap(map, "addressData", readableMapOf(sendDestination.addressData))
|
||||
}
|
||||
is SendDestination.Bolt11 -> {
|
||||
pushToMap(map, "type", "bolt11")
|
||||
pushToMap(map, "invoice", readableMapOf(sendDestination.invoice))
|
||||
}
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
fun asSendDestinationList(arr: ReadableArray): List<SendDestination> {
|
||||
val list = ArrayList<SendDestination>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asSendDestination(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asSuccessActionProcessed(successActionProcessed: ReadableMap): SuccessActionProcessed? {
|
||||
val type = successActionProcessed.getString("type")
|
||||
|
||||
|
||||
@@ -210,9 +210,9 @@ class BreezSDKLiquidModule(
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareSendResponse =
|
||||
asPrepareSendResponse(req) ?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareSendResponse")) }
|
||||
val res = getBindingLiquidSdk().sendPayment(prepareSendResponse)
|
||||
val sendPaymentRequest =
|
||||
asSendPaymentRequest(req) ?: run { throw SdkException.Generic(errMissingMandatoryField("req", "SendPaymentRequest")) }
|
||||
val res = getBindingLiquidSdk().sendPayment(sendPaymentRequest)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
@@ -227,10 +227,10 @@ class BreezSDKLiquidModule(
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareReceivePaymentRequest =
|
||||
asPrepareReceivePaymentRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceivePaymentRequest")) }
|
||||
val res = getBindingLiquidSdk().prepareReceivePayment(prepareReceivePaymentRequest)
|
||||
val prepareReceiveRequest =
|
||||
asPrepareReceiveRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceiveRequest")) }
|
||||
val res = getBindingLiquidSdk().prepareReceivePayment(prepareReceiveRequest)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
@@ -315,42 +315,6 @@ class BreezSDKLiquidModule(
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun prepareReceiveOnchain(
|
||||
req: ReadableMap,
|
||||
promise: Promise,
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareReceiveOnchainRequest =
|
||||
asPrepareReceiveOnchainRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceiveOnchainRequest")) }
|
||||
val res = getBindingLiquidSdk().prepareReceiveOnchain(prepareReceiveOnchainRequest)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun receiveOnchain(
|
||||
req: ReadableMap,
|
||||
promise: Promise,
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareReceiveOnchainResponse =
|
||||
asPrepareReceiveOnchainResponse(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceiveOnchainResponse")) }
|
||||
val res = getBindingLiquidSdk().receiveOnchain(prepareReceiveOnchainResponse)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun prepareBuyBitcoin(
|
||||
req: ReadableMap,
|
||||
|
||||
Reference in New Issue
Block a user