mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-16 20:44:27 +01:00
Update boltz-rust and add receive payment description (#409)
* Update boltz-rust * Store description and add to Payment struct * Fix examples
This commit is contained in:
@@ -1205,6 +1205,7 @@ fun asPayment(payment: ReadableMap): Payment? {
|
||||
"feesSat",
|
||||
"paymentType",
|
||||
"status",
|
||||
"description",
|
||||
),
|
||||
)
|
||||
) {
|
||||
@@ -1215,6 +1216,7 @@ fun asPayment(payment: ReadableMap): Payment? {
|
||||
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
|
||||
@@ -1227,6 +1229,7 @@ fun asPayment(payment: ReadableMap): Payment? {
|
||||
feesSat,
|
||||
paymentType,
|
||||
status,
|
||||
description,
|
||||
txId,
|
||||
swapId,
|
||||
preimage,
|
||||
@@ -1243,6 +1246,7 @@ fun readableMapOf(payment: Payment): ReadableMap =
|
||||
"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,
|
||||
@@ -1490,9 +1494,9 @@ fun asPrepareReceiveOnchainResponseList(arr: ReadableArray): List<PrepareReceive
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareReceiveRequest(prepareReceiveRequest: ReadableMap): PrepareReceiveRequest? {
|
||||
fun asPrepareReceivePaymentRequest(prepareReceivePaymentRequest: ReadableMap): PrepareReceivePaymentRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareReceiveRequest,
|
||||
prepareReceivePaymentRequest,
|
||||
arrayOf(
|
||||
"payerAmountSat",
|
||||
),
|
||||
@@ -1500,31 +1504,31 @@ fun asPrepareReceiveRequest(prepareReceiveRequest: ReadableMap): PrepareReceiveR
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val payerAmountSat = prepareReceiveRequest.getDouble("payerAmountSat").toULong()
|
||||
return PrepareReceiveRequest(
|
||||
val payerAmountSat = prepareReceivePaymentRequest.getDouble("payerAmountSat").toULong()
|
||||
return PrepareReceivePaymentRequest(
|
||||
payerAmountSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareReceiveRequest: PrepareReceiveRequest): ReadableMap =
|
||||
fun readableMapOf(prepareReceivePaymentRequest: PrepareReceivePaymentRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"payerAmountSat" to prepareReceiveRequest.payerAmountSat,
|
||||
"payerAmountSat" to prepareReceivePaymentRequest.payerAmountSat,
|
||||
)
|
||||
|
||||
fun asPrepareReceiveRequestList(arr: ReadableArray): List<PrepareReceiveRequest> {
|
||||
val list = ArrayList<PrepareReceiveRequest>()
|
||||
fun asPrepareReceivePaymentRequestList(arr: ReadableArray): List<PrepareReceivePaymentRequest> {
|
||||
val list = ArrayList<PrepareReceivePaymentRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareReceiveRequest(value)!!)
|
||||
is ReadableMap -> list.add(asPrepareReceivePaymentRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiveResponse? {
|
||||
fun asPrepareReceivePaymentResponse(prepareReceivePaymentResponse: ReadableMap): PrepareReceivePaymentResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
prepareReceiveResponse,
|
||||
prepareReceivePaymentResponse,
|
||||
arrayOf(
|
||||
"payerAmountSat",
|
||||
"feesSat",
|
||||
@@ -1533,25 +1537,25 @@ fun asPrepareReceiveResponse(prepareReceiveResponse: ReadableMap): PrepareReceiv
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val payerAmountSat = prepareReceiveResponse.getDouble("payerAmountSat").toULong()
|
||||
val feesSat = prepareReceiveResponse.getDouble("feesSat").toULong()
|
||||
return PrepareReceiveResponse(
|
||||
val payerAmountSat = prepareReceivePaymentResponse.getDouble("payerAmountSat").toULong()
|
||||
val feesSat = prepareReceivePaymentResponse.getDouble("feesSat").toULong()
|
||||
return PrepareReceivePaymentResponse(
|
||||
payerAmountSat,
|
||||
feesSat,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(prepareReceiveResponse: PrepareReceiveResponse): ReadableMap =
|
||||
fun readableMapOf(prepareReceivePaymentResponse: PrepareReceivePaymentResponse): ReadableMap =
|
||||
readableMapOf(
|
||||
"payerAmountSat" to prepareReceiveResponse.payerAmountSat,
|
||||
"feesSat" to prepareReceiveResponse.feesSat,
|
||||
"payerAmountSat" to prepareReceivePaymentResponse.payerAmountSat,
|
||||
"feesSat" to prepareReceivePaymentResponse.feesSat,
|
||||
)
|
||||
|
||||
fun asPrepareReceiveResponseList(arr: ReadableArray): List<PrepareReceiveResponse> {
|
||||
val list = ArrayList<PrepareReceiveResponse>()
|
||||
fun asPrepareReceivePaymentResponseList(arr: ReadableArray): List<PrepareReceivePaymentResponse> {
|
||||
val list = ArrayList<PrepareReceivePaymentResponse>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asPrepareReceiveResponse(value)!!)
|
||||
is ReadableMap -> list.add(asPrepareReceivePaymentResponse(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
@@ -1777,6 +1781,41 @@ fun asReceiveOnchainResponseList(arr: ReadableArray): List<ReceiveOnchainRespons
|
||||
return list
|
||||
}
|
||||
|
||||
fun asReceivePaymentRequest(receivePaymentRequest: ReadableMap): ReceivePaymentRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
receivePaymentRequest,
|
||||
arrayOf(
|
||||
"prepareRes",
|
||||
),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val prepareRes = receivePaymentRequest.getMap("prepareRes")?.let { asPrepareReceivePaymentResponse(it) }!!
|
||||
val description = if (hasNonNullKey(receivePaymentRequest, "description")) receivePaymentRequest.getString("description") else null
|
||||
return ReceivePaymentRequest(
|
||||
prepareRes,
|
||||
description,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(receivePaymentRequest: ReceivePaymentRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"prepareRes" to readableMapOf(receivePaymentRequest.prepareRes),
|
||||
"description" to receivePaymentRequest.description,
|
||||
)
|
||||
|
||||
fun asReceivePaymentRequestList(arr: ReadableArray): List<ReceivePaymentRequest> {
|
||||
val list = ArrayList<ReceivePaymentRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asReceivePaymentRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asReceivePaymentResponse(receivePaymentResponse: ReadableMap): ReceivePaymentResponse? {
|
||||
if (!validateMandatoryFields(
|
||||
receivePaymentResponse,
|
||||
|
||||
@@ -227,10 +227,10 @@ class BreezSDKLiquidModule(
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareReceiveRequest =
|
||||
asPrepareReceiveRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceiveRequest")) }
|
||||
val res = getBindingLiquidSdk().prepareReceivePayment(prepareReceiveRequest)
|
||||
val prepareReceivePaymentRequest =
|
||||
asPrepareReceivePaymentRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceivePaymentRequest")) }
|
||||
val res = getBindingLiquidSdk().prepareReceivePayment(prepareReceivePaymentRequest)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
@@ -245,10 +245,10 @@ class BreezSDKLiquidModule(
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val prepareReceiveResponse =
|
||||
asPrepareReceiveResponse(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "PrepareReceiveResponse")) }
|
||||
val res = getBindingLiquidSdk().receivePayment(prepareReceiveResponse)
|
||||
val receivePaymentRequest =
|
||||
asReceivePaymentRequest(req)
|
||||
?: run { throw SdkException.Generic(errMissingMandatoryField("req", "ReceivePaymentRequest")) }
|
||||
val res = getBindingLiquidSdk().receivePayment(receivePaymentRequest)
|
||||
promise.resolve(readableMapOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
|
||||
Reference in New Issue
Block a user