SubscribeInvoices - 订阅发票
SubscribeInvoices 返回一个从服务端到客户端的单向流用于推送新添加或结算的发票。 可选地,调用者可以指定add_index或settle_index。
gRPC请求 - InvoiceSubscription
字段如下:
- add_index:如果设置这个参数,那么将发送所有add_index大于此编号的发票, uint64
- settle_index:如果设置这个参数,那么将发送所有settle_index大于此偏好的发票, uint64
gRPC响应 - Invoice (Streaming)
字段如下:
- memo:发票备注,可选, string
- receipt:支付密码学收据,可选,已弃用, bytes
- r_preimage:16进制编码的原像,用于结算收到的HTLC应付,32字节
- r_hash:原像的哈希, bytes
- value:发票金额,单位:satoshi, int64
- settled:是否已结算, bool
- creation_date:创建日期, int64
- settle_date:结算日期, int64
- payment_request:支付请求, string
- description_hash:支付描述的哈希, bytes
- expiry:支付请求超时时间,单位:秒, int64
- fallback_addr:失败回退的链上地址, string
- cltv_expiry:CLTV超时, uint64
- route_hints:路由指示, RouteHint 数组
- private:是否使用私有通道, bool
- add_index:发票的add索引, uint64
- settle_index:结算索引, uint64
- amt_paid:已弃用,使用amt_paid_sat或amt_paid_msat, int64
- amt_paid_sat:已接收的金额,单位:satoshi, int64
- amt_paid_msat:已接收的金额,单位:satoshi, int64
- state:发票状态, InvoiceState
示例代码
Python示例代码
>>> import codecs, grpc, os
>>> import rpc_pb2 as ln, rpc_pb2_grpc as lnrpc
>>> macaroon = codecs.encode(open('LND_DIR/data/chain/bitcoin/simnet/admin.macaroon', 'rb').read(), 'hex')
>>> os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
>>> cert = open('LND_DIR/tls.cert', 'rb').read()
>>> ssl_creds = grpc.ssl_channel_credentials(cert)
>>> channel = grpc.secure_channel('localhost:10009', ssl_creds)
>>> stub = lnrpc.LightningStub(channel)
>>> request = ln.InvoiceSubscription(
add_index=<uint64>,
settle_index=<uint64>,
)
>>> for response in stub.SubscribeInvoices(request):
print(response)
{
"memo": <string>,
"receipt": <bytes>,
"r_preimage": <bytes>,
"r_hash": <bytes>,
"value": <int64>,
"settled": <bool>,
"creation_date": <int64>,
"settle_date": <int64>,
"payment_request": <string>,
"description_hash": <bytes>,
"expiry": <int64>,
"fallback_addr": <string>,
"cltv_expiry": <uint64>,
"route_hints": <array RouteHint>,
"private": <bool>,
"add_index": <uint64>,
"settle_index": <uint64>,
"amt_paid": <int64>,
"amt_paid_sat": <int64>,
"amt_paid_msat": <int64>,
"state": <InvoiceState>,
}
JavaScript示例代码
> var fs = require('fs');
> var grpc = require('grpc');
> var lnrpc = grpc.load('rpc.proto').lnrpc;
> process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'
> var lndCert = fs.readFileSync('LND_DIR/tls.cert');
> var sslCreds = grpc.credentials.createSsl(lndCert);
> var macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
var macaroon = fs.readFileSync("LND_DIR/data/chain/bitcoin/simnet/admin.macaroon").toString('hex');
var metadata = new grpc.Metadata()
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
> var creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
> var lightning = new lnrpc.Lightning('localhost:10009', creds);
> var request = {
add_index: <uint64>,
settle_index: <uint64>,
}
> var call = lightning.subscribeInvoices(request)
> call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
> call.on('status', function(status) {
// The current status of the stream.
});
> call.on('end', function() {
// The server has closed the stream.
});
{
"memo": <string>,
"receipt": <bytes>,
"r_preimage": <bytes>,
"r_hash": <bytes>,
"value": <int64>,
"settled": <bool>,
"creation_date": <int64>,
"settle_date": <int64>,
"payment_request": <string>,
"description_hash": <bytes>,
"expiry": <int64>,
"fallback_addr": <string>,
"cltv_expiry": <uint64>,
"route_hints": <array RouteHint>,
"private": <bool>,
"add_index": <uint64>,
"settle_index": <uint64>,
"amt_paid": <int64>,
"amt_paid_sat": <int64>,
"amt_paid_msat": <int64>,
"state": <InvoiceState>,
}