mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 21:42:48 +01:00
Add lnd invoice client (#4289)
This commit is contained in:
parent
587bca87c4
commit
95bbb06789
4 changed files with 204 additions and 4 deletions
|
@ -61,6 +61,16 @@ class LndRpcClientTest extends LndFixture {
|
|||
}
|
||||
}
|
||||
|
||||
it must "create an invoice and cancel it" in { lnd =>
|
||||
val memo = "this is my memo"
|
||||
val amount = Satoshis(1000)
|
||||
|
||||
for {
|
||||
invoiceResult <- lnd.addInvoice(memo, amount, 1000)
|
||||
_ <- lnd.cancelInvoice(invoiceResult.invoice)
|
||||
} yield succeed
|
||||
}
|
||||
|
||||
it must "get an on-chain address" in { lnd =>
|
||||
for {
|
||||
addr <- lnd.getNewAddress
|
||||
|
|
|
@ -12,7 +12,7 @@ enablePlugins(AkkaGrpcPlugin)
|
|||
|
||||
// Disable deprecation warning otherwise protobuf deprecation warnings will cause errors
|
||||
Compile / scalacOptions += {
|
||||
"-Wconf:cat=deprecation:site=lnrpc\\..*:silent,cat=deprecation:site=signrpc\\..*:silent,cat=deprecation:site=walletrpc\\..*:silent,cat=deprecation:site=routerrpc\\..*:silent"
|
||||
"-Wconf:cat=deprecation:site=lnrpc\\..*:silent,cat=deprecation:site=signrpc\\..*:silent,cat=deprecation:site=walletrpc\\..*:silent,cat=deprecation:site=routerrpc\\..*:silent,cat=deprecation:site=invoicesrpc\\..*:silent"
|
||||
}
|
||||
|
||||
TaskKeys.downloadLnd := {
|
||||
|
|
172
lnd-rpc/src/main/protobuf/invoicesrpc/invoices.proto
Normal file
172
lnd-rpc/src/main/protobuf/invoicesrpc/invoices.proto
Normal file
|
@ -0,0 +1,172 @@
|
|||
syntax = "proto3";
|
||||
|
||||
import "lightning.proto";
|
||||
|
||||
package invoicesrpc;
|
||||
|
||||
option go_package = "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc";
|
||||
|
||||
// Invoices is a service that can be used to create, accept, settle and cancel
|
||||
// invoices.
|
||||
service Invoices {
|
||||
/*
|
||||
SubscribeSingleInvoice returns a uni-directional stream (server -> client)
|
||||
to notify the client of state transitions of the specified invoice.
|
||||
Initially the current invoice state is always sent out.
|
||||
*/
|
||||
rpc SubscribeSingleInvoice (SubscribeSingleInvoiceRequest)
|
||||
returns (stream lnrpc.Invoice);
|
||||
|
||||
/*
|
||||
CancelInvoice cancels a currently open invoice. If the invoice is already
|
||||
canceled, this call will succeed. If the invoice is already settled, it will
|
||||
fail.
|
||||
*/
|
||||
rpc CancelInvoice (CancelInvoiceMsg) returns (CancelInvoiceResp);
|
||||
|
||||
/*
|
||||
AddHoldInvoice creates a hold invoice. It ties the invoice to the hash
|
||||
supplied in the request.
|
||||
*/
|
||||
rpc AddHoldInvoice (AddHoldInvoiceRequest) returns (AddHoldInvoiceResp);
|
||||
|
||||
/*
|
||||
SettleInvoice settles an accepted invoice. If the invoice is already
|
||||
settled, this call will succeed.
|
||||
*/
|
||||
rpc SettleInvoice (SettleInvoiceMsg) returns (SettleInvoiceResp);
|
||||
|
||||
/*
|
||||
LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced
|
||||
using either its payment hash, payment address, or set ID.
|
||||
*/
|
||||
rpc LookupInvoiceV2 (LookupInvoiceMsg) returns (lnrpc.Invoice);
|
||||
}
|
||||
|
||||
message CancelInvoiceMsg {
|
||||
// Hash corresponding to the (hold) invoice to cancel.
|
||||
bytes payment_hash = 1;
|
||||
}
|
||||
message CancelInvoiceResp {
|
||||
}
|
||||
|
||||
message AddHoldInvoiceRequest {
|
||||
/*
|
||||
An optional memo to attach along with the invoice. Used for record keeping
|
||||
purposes for the invoice's creator, and will also be set in the description
|
||||
field of the encoded payment request if the description_hash field is not
|
||||
being used.
|
||||
*/
|
||||
string memo = 1;
|
||||
|
||||
// The hash of the preimage
|
||||
bytes hash = 2;
|
||||
|
||||
/*
|
||||
The value of this invoice in satoshis
|
||||
|
||||
The fields value and value_msat are mutually exclusive.
|
||||
*/
|
||||
int64 value = 3;
|
||||
|
||||
/*
|
||||
The value of this invoice in millisatoshis
|
||||
|
||||
The fields value and value_msat are mutually exclusive.
|
||||
*/
|
||||
int64 value_msat = 10;
|
||||
|
||||
/*
|
||||
Hash (SHA-256) of a description of the payment. Used if the description of
|
||||
payment (memo) is too long to naturally fit within the description field
|
||||
of an encoded payment request.
|
||||
*/
|
||||
bytes description_hash = 4;
|
||||
|
||||
// Payment request expiry time in seconds. Default is 3600 (1 hour).
|
||||
int64 expiry = 5;
|
||||
|
||||
// Fallback on-chain address.
|
||||
string fallback_addr = 6;
|
||||
|
||||
// Delta to use for the time-lock of the CLTV extended to the final hop.
|
||||
uint64 cltv_expiry = 7;
|
||||
|
||||
/*
|
||||
Route hints that can each be individually used to assist in reaching the
|
||||
invoice's destination.
|
||||
*/
|
||||
repeated lnrpc.RouteHint route_hints = 8;
|
||||
|
||||
// Whether this invoice should include routing hints for private channels.
|
||||
bool private = 9;
|
||||
}
|
||||
|
||||
message AddHoldInvoiceResp {
|
||||
/*
|
||||
A bare-bones invoice for a payment within the Lightning Network. With the
|
||||
details of the invoice, the sender has all the data necessary to send a
|
||||
payment to the recipient.
|
||||
*/
|
||||
string payment_request = 1;
|
||||
|
||||
/*
|
||||
The "add" index of this invoice. Each newly created invoice will increment
|
||||
this index making it monotonically increasing. Callers to the
|
||||
SubscribeInvoices call can use this to instantly get notified of all added
|
||||
invoices with an add_index greater than this one.
|
||||
*/
|
||||
uint64 add_index = 2;
|
||||
|
||||
/*
|
||||
The payment address of the generated invoice. This value should be used
|
||||
in all payments for this invoice as we require it for end to end
|
||||
security.
|
||||
*/
|
||||
bytes payment_addr = 3;
|
||||
}
|
||||
|
||||
message SettleInvoiceMsg {
|
||||
// Externally discovered pre-image that should be used to settle the hold
|
||||
// invoice.
|
||||
bytes preimage = 1;
|
||||
}
|
||||
|
||||
message SettleInvoiceResp {
|
||||
}
|
||||
|
||||
message SubscribeSingleInvoiceRequest {
|
||||
reserved 1;
|
||||
|
||||
// Hash corresponding to the (hold) invoice to subscribe to.
|
||||
bytes r_hash = 2;
|
||||
}
|
||||
|
||||
enum LookupModifier {
|
||||
// The default look up modifier, no look up behavior is changed.
|
||||
DEFAULT = 0;
|
||||
|
||||
/*
|
||||
Indicates that when a look up is done based on a set_id, then only that set
|
||||
of HTLCs related to that set ID should be returned.
|
||||
*/
|
||||
HTLC_SET_ONLY = 1;
|
||||
|
||||
/*
|
||||
Indicates that when a look up is done using a payment_addr, then no HTLCs
|
||||
related to the payment_addr should be returned. This is useful when one
|
||||
wants to be able to obtain the set of associated setIDs with a given
|
||||
invoice, then look up the sub-invoices "projected" by that set ID.
|
||||
*/
|
||||
HTLC_SET_BLANK = 2;
|
||||
}
|
||||
|
||||
message LookupInvoiceMsg {
|
||||
oneof invoice_ref {
|
||||
bytes payment_hash = 1;
|
||||
bytes payment_addr = 2;
|
||||
bytes set_id = 3;
|
||||
}
|
||||
|
||||
LookupModifier lookup_modifier = 4;
|
||||
}
|
|
@ -6,6 +6,8 @@ import akka.grpc.{GrpcClientSettings, SSLContextUtils}
|
|||
import akka.stream.scaladsl.{Sink, Source}
|
||||
import com.google.protobuf.ByteString
|
||||
import grizzled.slf4j.Logging
|
||||
import invoicesrpc.LookupInvoiceMsg.InvoiceRef
|
||||
import invoicesrpc._
|
||||
import io.grpc.{CallCredentials, Metadata}
|
||||
import lnrpc.ChannelPoint.FundingTxid.FundingTxidBytes
|
||||
import lnrpc.CloseStatusUpdate.Update.ClosePending
|
||||
|
@ -136,6 +138,7 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
|
|||
lazy val unlocker: WalletUnlockerClient = WalletUnlockerClient(clientSettings)
|
||||
lazy val signer: SignerClient = SignerClient(clientSettings)
|
||||
lazy val router: RouterClient = RouterClient(clientSettings)
|
||||
lazy val invoices: InvoicesClient = InvoicesClient(clientSettings)
|
||||
|
||||
def genSeed(): Future[GenSeedResponse] = {
|
||||
logger.trace("lnd calling genseed")
|
||||
|
@ -183,11 +186,26 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
|
|||
}
|
||||
|
||||
def lookupInvoice(rHash: PaymentHashTag): Future[Invoice] = {
|
||||
logger.trace("lnd calling lookupinvoice")
|
||||
val hash = InvoiceRef.PaymentHash(rHash.bytes)
|
||||
val req = LookupInvoiceMsg(hash)
|
||||
|
||||
val req: PaymentHash = PaymentHash(rHash = rHash.bytes)
|
||||
lookupInvoice(req)
|
||||
}
|
||||
|
||||
lnd.lookupInvoice(req)
|
||||
def lookupInvoice(req: LookupInvoiceMsg): Future[Invoice] = {
|
||||
logger.trace("lnd calling lookupinvoiceV2")
|
||||
|
||||
invoices.lookupInvoiceV2(req)
|
||||
}
|
||||
|
||||
def cancelInvoice(invoice: LnInvoice): Future[Unit] = {
|
||||
cancelInvoice(invoice.lnTags.paymentHash.hash)
|
||||
}
|
||||
|
||||
def cancelInvoice(hash: Sha256Digest): Future[Unit] = {
|
||||
logger.trace("lnd calling cancelinvoice")
|
||||
|
||||
invoices.cancelInvoice(CancelInvoiceMsg(hash.bytes)).map(_ => ())
|
||||
}
|
||||
|
||||
def addInvoice(
|
||||
|
|
Loading…
Add table
Reference in a new issue