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

GetChanInfo - 获取通道信息

GetChanInfo返回指定通道的最新信息。通道ID为8字节整数。

gRPC请求 - ChanInfoRequest

字段如下:

  • chan_id:通道的ID, uint64,前3个字节表示区块高度,接下来3个字节表示 在区块内的索引,最后的2个字节表示通道的输出索引

gRPC响应 - ChannelEdge

字段如下:

  • channel_id:通道ID, uint64
  • chan_point: string
  • last_update :uint32
  • node1_pub: string
  • node2_pub: string
  • capacity: int64
  • node1_policy: RoutingPolicy
  • node2_policy: RoutingPolicy

示例代码

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.ChanInfoRequest(
        chan_id=<uint64>,
    )
>>> response = stub.GetChanInfo(request)
>>> print(response)
{ 
    "channel_id": <uint64>,
    "chan_point": <string>,
    "last_update": <uint32>,
    "node1_pub": <string>,
    "node2_pub": <string>,
    "capacity": <int64>,
    "node1_policy": <RoutingPolicy>,
    "node2_policy": <RoutingPolicy>,
}

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 = { 
    chan_id: <uint64>, 
  } 
> lightning.getChanInfo(request, function(err, response) {
    console.log(response);
  })
{ 
    "channel_id": <uint64>,
    "chan_point": <string>,
    "last_update": <uint32>,
    "node1_pub": <string>,
    "node2_pub": <string>,
    "capacity": <int64>,
    "node1_policy": <RoutingPolicy>,
    "node2_policy": <RoutingPolicy>,
}