LND API手册

gRPC API
GenSeed - 生成加密种子 InitWallet - 初始化钱包 UnlockWallet - 解锁钱包 ChangePassword - 修改钱包密码 WalletBalance - 查询钱包余额 ChannelBalance - 查询通道余额 GetTransactions - 查询钱包交易 EstimateFee - 估算交易手续费 SendCoins - 单址转账 ListUnspent - 查询钱包UTXO SubscribeTransactions - 订阅交易事件 SendMany - 多址转账 NewAddress - 生成新地址 SignMessage - 生成消息签名 VerifyMessage - 验证消息签名 ConnectPeer - 连接对端节点 DisconnectPeer - 断开对端节点的连接 ListPeers - 查询对端节点 GetInfo - 查询节点信息 PendingChannels - 查询待确认通道 ListChannels - 查询已开启通道 SubscribeChannelEvents - 订阅通道事件 ClosedChannels - 查询已关闭通道 OpenChannelSync - 同步开启通道 OpenChannel - 开启通道 CloseChannel - 关闭通道 AbandonChannel - 启用通道 SendPayment - 发送支付 SendPaymentSync - 同步支付 SendToRoute - 指定路由支付 SendToRouteSync - 指定路由同步支付 AddInvoice - 添加发票 ListInvoices - 返回发票清单 LookupInvoice - 查询发票 SubscribeInvoices - 订阅发票 DecodePayReq - 解码支付请求 ListPayments - 返回支付清单 DeleteAllPayments - 删除所有支付 DescribeGraph - 返回图描述 GetChanInfo - 获取通道信息 GetNodeInfo - 获取节点信息 QueryRoutes - 查询路径 GetNetworkInfo - 获取支付网络信息 StopDaemon - 停止后台服务 SubscribeChannelGraph - 订阅通道图事件 DebugLevel - 设置调试等级 FeeReport - 获取手续费报告 UpdateChannelPolicy - 更新通道政策 ForwardingHistory - 查询转发历史 ExportChannelBackup - 导出通道备份 ExportAllChannelBackups - 导出所有通道的备份 VerifyChanBackup - 验证通道备份完整性 RestoreChannelBackups - 恢复通道备份 SubscribeChannelBackups - 订阅通道备份
Messages
OpenStatusUpdate ChannelEventSubscription ChannelPoint GraphTopologySubscription UnlockWalletResponse ChannelOpenUpdate ChannelGraph ListInvoiceResponse VerifyChanBackupResponse EdgeLocator ForwardingHistoryRequest ClosedChannelUpdate HopHint Route ListPaymentsResponse HTLC FeeLimit StopResponse Peer ChangePasswordResponse ListINvoiceRequest SendCoinsRequest ForwardingEvent NetworkInfoRequest ForwardingHistoryResponse WalletBalanceResponse ListChannelsResponse ChangePasswordRequest Channel DeleteAllPaymentsResponse SendCoinsResponse MultiChanBackup GetInfoResponse ChannelBackup DeleteAllPaymentsRequest Transaction QueryRoutesRequest VerifyMessageResponse ChannelGraphRequest SendRequest FeeReportResponse ForceClosedChannel OutPoint LightningAddress Hop PolicyUpdateResponse SignMessageResponse EstimateFeeResponse AddInvoiceResponse Invoice InitWalletResponse ListUnspentResponse DisconnectPeerResponse ChannelCloseSummary SignMessageRequest NodeInfo NodeUpdate ListPeersRequest ClosedChannelsResponse StopRequest PayReqString SendManyResponse ChannelBackupSubscription Payment GenSeedRequest ConfirmationUpdate CloseStatusUpdate GetTransactionsRequest SendToRouteRequest Chain QueryRoutesResponse PaymentHash SendResponse DebugLevelResponse AbandonChannelResponse ChanBackupExportRequest ChannelCloseUpdate PendingChannel Utxo DebugLevelRequest PendingHTLC UnlockWalletRequest SendManyRequest PayReq PendingChannelsRequest RestoreChanBackupRequest ExportChannelBackupRequest ChannelBackups ChannelEdgeUpdate ClosedChannel CLoseChannelRequest OpenChannelRequest ChannelEventUpdate ChanInfoRequest ConnectPeerResponse NewAddressRequest ListPeersResponse ListChannelsRequest EstimateFeeRequest LightningNode WaitingCloseChannel PendingOpenChannel NewAddressResponse ChannelBalanceResponse ChanBackupSnapshot TransactionDetails PendingChannelsResponse ChannelEdge ConnectPeerRequest PendingUpdate RestoreBackupResponse DisconnectPeerRequest ClosedChannelsRequest InvoiceSubscription RouteHint NodeInfoRequest AddrToAmountEntry FeeReportRequest NetworkInfo ListPaymentsRequest AbandonChannelRequest GetInfoRequest GraphTopologyUpdate InitWalletRequest VerifyMessageRequest ChannelFeeReport PolicyUpdateRequest GenSeedResponse ChannelBalanceRequest NodeAddress WalletBalanceRequest RoutingPolicy ListUnspentRequest
Enums
ClosureType SyncType InvoiceState PyamentStatus UpdateType AddressType
在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

SendPaymentSync - 同步支付

SendPaymentSync是SendPayment的非流式同步版本。这个RPC调用主要用于 客户端通过REST代理的调用。另外,这个调用需要目标公钥和支付哈希以 16进制字符串编码。

gRPC请求 - SendRequest

字段如下:

  • dest:支付接收方的标识公钥, bytes
  • dest_string:支付接收方的公钥的16进制字符串表示, string
  • amt:要发送的satoshi数量, int64
  • payment_hash:在支付的HTLC中要使用的哈希, bytes
  • payment_hash_string:支付的HTLC中的哈希的16进制字符串表示ID, string
  • payment_request:闪电网络内的支付请求,string
  • final_cltv_delta:CTTV差值, int32
  • fee_limit FeeLimit:手续费上限,单位:satoshi
  • outgoing_chan_id:第一跳的通道ID,0表示可用任何通道, uint64
  • cltv_limit:路由的最大时间锁, uint32 ,可选

gRPC响应 - SendResponse

字段如下:

  • payment_error:string
  • payment_preimage:bytes
  • payment_route:Route
  • payment_hash:bytes

示例代码

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.SendRequest(
        dest=<bytes>,
        dest_string=<string>,
        amt=<int64>,
        payment_hash=<bytes>,
        payment_hash_string=<string>,
        payment_request=<string>,
        final_cltv_delta=<int32>,
        fee_limit=<FeeLimit>,
        outgoing_chan_id=<uint64>,
        cltv_limit=<uint32>,
    )
>>> response = stub.SendPaymentSync(request)
>>> print(response)
{ 
    "payment_error": <string>,
    "payment_preimage": <bytes>,
    "payment_route": <Route>,
    "payment_hash": <bytes>,
}

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 = { 
    dest: <bytes>, 
    dest_string: <string>, 
    amt: <int64>, 
    payment_hash: <bytes>, 
    payment_hash_string: <string>, 
    payment_request: <string>, 
    final_cltv_delta: <int32>, 
    fee_limit: <FeeLimit>, 
    outgoing_chan_id: <uint64>, 
    cltv_limit: <uint32>, 
  } 
> lightning.sendPaymentSync(request, function(err, response) {
    console.log(response);
  })
{ 
    "payment_error": <string>,
    "payment_preimage": <bytes>,
    "payment_route": <Route>,
    "payment_hash": <bytes>,
}