mirror of
https://github.com/ACINQ/eclair.git
synced 2025-03-04 09:58:02 +01:00
* Add API method to accept requests with custom amount - can be used to send up to 2x higher amount than requested according to BOLT11 - should be used for payment requests without amounts * Refactor 'send' method in API * Add comments and description for 'send' API method
This commit is contained in:
parent
76f744c57c
commit
4cd081c11c
2 changed files with 10 additions and 2 deletions
|
@ -109,6 +109,7 @@ option | description | default value
|
||||||
receive | amountMsat, description | generate a payment request for a given amount
|
receive | amountMsat, description | generate a payment request for a given amount
|
||||||
send | amountMsat, paymentHash, nodeId | send a payment to a lightning node
|
send | amountMsat, paymentHash, nodeId | send a payment to a lightning node
|
||||||
send | paymentRequest | send a payment to a lightning node using a BOLT11 payment request
|
send | paymentRequest | send a payment to a lightning node using a BOLT11 payment request
|
||||||
|
send | paymentRequest, amountMsat | send a payment to a lightning node using a BOLT11 payment request and a custom amount
|
||||||
close | channelId | close a channel
|
close | channelId | close a channel
|
||||||
close | channelId, scriptPubKey (optional) | close a channel and send the funds to the given scriptPubKey
|
close | channelId, scriptPubKey (optional) | close a channel and send the funds to the given scriptPubKey
|
||||||
help | | display available methods
|
help | | display available methods
|
||||||
|
|
|
@ -99,10 +99,16 @@ trait Service extends Logging {
|
||||||
(paymentHandler ? ReceivePayment(MilliSatoshi(amountMsat.toLong), description)).mapTo[PaymentRequest].map(PaymentRequest.write)
|
(paymentHandler ? ReceivePayment(MilliSatoshi(amountMsat.toLong), description)).mapTo[PaymentRequest].map(PaymentRequest.write)
|
||||||
case JsonRPCBody(_, _, "send", JInt(amountMsat) :: JString(paymentHash) :: JString(nodeId) :: Nil) =>
|
case JsonRPCBody(_, _, "send", JInt(amountMsat) :: JString(paymentHash) :: JString(nodeId) :: Nil) =>
|
||||||
(paymentInitiator ? SendPayment(amountMsat.toLong, paymentHash, PublicKey(nodeId))).mapTo[PaymentResult]
|
(paymentInitiator ? SendPayment(amountMsat.toLong, paymentHash, PublicKey(nodeId))).mapTo[PaymentResult]
|
||||||
case JsonRPCBody(_, _, "send", JString(paymentRequest) :: Nil) =>
|
case JsonRPCBody(_, _, "send", JString(paymentRequest) :: rest) =>
|
||||||
for {
|
for {
|
||||||
req <- Future(PaymentRequest.read(paymentRequest))
|
req <- Future(PaymentRequest.read(paymentRequest))
|
||||||
res <- (paymentInitiator ? SendPayment(req.amount.getOrElse(throw new RuntimeException("request without amounts are not supported")).amount, req.paymentHash, req.nodeId)).mapTo[PaymentResult]
|
amount = (req.amount, rest) match {
|
||||||
|
case (Some(amt), Nil) => amt.amount
|
||||||
|
case (Some(_), JInt(amt) :: Nil) => amt.toLong // overriding payment request amount with the one provided
|
||||||
|
case (None, JInt(amt) :: Nil) => amt.toLong // amount wasn't specified in request, using custom one
|
||||||
|
case (None, Nil) => throw new RuntimeException("you need to manually specify an amount for this payment request")
|
||||||
|
}
|
||||||
|
res <- (paymentInitiator ? SendPayment(amount, req.paymentHash, req.nodeId)).mapTo[PaymentResult]
|
||||||
} yield res
|
} yield res
|
||||||
case JsonRPCBody(_, _, "close", JString(channelId) :: JString(scriptPubKey) :: Nil) =>
|
case JsonRPCBody(_, _, "close", JString(channelId) :: JString(scriptPubKey) :: Nil) =>
|
||||||
getChannel(channelId).flatMap(_ ? CMD_CLOSE(scriptPubKey = Some(scriptPubKey))).mapTo[String]
|
getChannel(channelId).flatMap(_ ? CMD_CLOSE(scriptPubKey = Some(scriptPubKey))).mapTo[String]
|
||||||
|
@ -120,6 +126,7 @@ trait Service extends Logging {
|
||||||
"receive (amountMsat, description): generate a payment request for a given amount",
|
"receive (amountMsat, description): generate a payment request for a given amount",
|
||||||
"send (amountMsat, paymentHash, nodeId): send a payment to a lightning node",
|
"send (amountMsat, paymentHash, nodeId): send a payment to a lightning node",
|
||||||
"send (paymentRequest): send a payment to a lightning node using a BOLT11 payment request",
|
"send (paymentRequest): send a payment to a lightning node using a BOLT11 payment request",
|
||||||
|
"send (paymentRequest, amountMsat): send a payment to a lightning node using a BOLT11 payment request and a custom amount",
|
||||||
"close (channelId): close a channel",
|
"close (channelId): close a channel",
|
||||||
"close (channelId, scriptPubKey): close a channel and send the funds to the given scriptPubKey",
|
"close (channelId, scriptPubKey): close a channel and send the funds to the given scriptPubKey",
|
||||||
"help: display this message"))
|
"help: display this message"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue