mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
lnrpc+rpcserver: add and populate custom channel data
This commit is contained in:
parent
ea83300942
commit
5e1a98cd43
@ -4703,6 +4703,8 @@ type Channel struct {
|
||||
// useful information. This is only ever stored locally and in no way impacts
|
||||
// the channel's operation.
|
||||
Memo string `protobuf:"bytes,36,opt,name=memo,proto3" json:"memo,omitempty"`
|
||||
// Custom channel data that might be populated in custom channels.
|
||||
CustomChannelData []byte `protobuf:"bytes,37,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Channel) Reset() {
|
||||
@ -4993,6 +4995,13 @@ func (x *Channel) GetMemo() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Channel) GetCustomChannelData() []byte {
|
||||
if x != nil {
|
||||
return x.CustomChannelData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ListChannelsRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -9505,6 +9514,9 @@ type ChannelBalanceResponse struct {
|
||||
PendingOpenLocalBalance *Amount `protobuf:"bytes,7,opt,name=pending_open_local_balance,json=pendingOpenLocalBalance,proto3" json:"pending_open_local_balance,omitempty"`
|
||||
// Sum of channels pending remote balances.
|
||||
PendingOpenRemoteBalance *Amount `protobuf:"bytes,8,opt,name=pending_open_remote_balance,json=pendingOpenRemoteBalance,proto3" json:"pending_open_remote_balance,omitempty"`
|
||||
// Custom channel data that might be populated if there are custom channels
|
||||
// present.
|
||||
CustomChannelData []byte `protobuf:"bytes,9,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ChannelBalanceResponse) Reset() {
|
||||
@ -9597,6 +9609,13 @@ func (x *ChannelBalanceResponse) GetPendingOpenRemoteBalance() *Amount {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *ChannelBalanceResponse) GetCustomChannelData() []byte {
|
||||
if x != nil {
|
||||
return x.CustomChannelData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type QueryRoutesRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -17642,6 +17661,8 @@ type PendingChannelsResponse_PendingChannel struct {
|
||||
// useful information. This is only ever stored locally and in no way
|
||||
// impacts the channel's operation.
|
||||
Memo string `protobuf:"bytes,13,opt,name=memo,proto3" json:"memo,omitempty"`
|
||||
// Custom channel data that might be populated in custom channels.
|
||||
CustomChannelData []byte `protobuf:"bytes,34,opt,name=custom_channel_data,json=customChannelData,proto3" json:"custom_channel_data,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PendingChannelsResponse_PendingChannel) Reset() {
|
||||
@ -17767,6 +17788,13 @@ func (x *PendingChannelsResponse_PendingChannel) GetMemo() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *PendingChannelsResponse_PendingChannel) GetCustomChannelData() []byte {
|
||||
if x != nil {
|
||||
return x.CustomChannelData
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type PendingChannelsResponse_PendingOpenChannel struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -18652,7 +18680,7 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x61, 0x74, 0x12, 0x2c, 0x0a, 0x12, 0x6d, 0x61, 0x78, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74,
|
||||
0x65, 0x64, 0x5f, 0x68, 0x74, 0x6c, 0x63, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x10,
|
||||
0x6d, 0x61, 0x78, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x48, 0x74, 0x6c, 0x63, 0x73,
|
||||
0x22, 0xad, 0x0b, 0x0a, 0x07, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x22, 0xdd, 0x0b, 0x0a, 0x07, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x16, 0x0a, 0x06,
|
||||
0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x61, 0x63,
|
||||
0x74, 0x69, 0x76, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5f, 0x70,
|
||||
0x75, 0x62, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x6d,
|
||||
@ -18743,6 +18771,9 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x69, 0x61, 0x73, 0x18, 0x23, 0x20, 0x01, 0x28, 0x04, 0x42, 0x02, 0x30, 0x01, 0x52, 0x0d, 0x70,
|
||||
0x65, 0x65, 0x72, 0x53, 0x63, 0x69, 0x64, 0x41, 0x6c, 0x69, 0x61, 0x73, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x6d, 0x65, 0x6d, 0x6f, 0x18, 0x24, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x65, 0x6d, 0x6f,
|
||||
0x12, 0x2e, 0x0a, 0x13, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e,
|
||||
0x65, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x25, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x11, 0x63,
|
||||
0x75, 0x73, 0x74, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x44, 0x61, 0x74, 0x61,
|
||||
0x22, 0xdf, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c,
|
||||
0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x74, 0x69,
|
||||
0x76, 0x65, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x61,
|
||||
@ -19326,7 +19357,7 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a,
|
||||
0x0e, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x74, 0x78, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x52, 0x61,
|
||||
0x77, 0x54, 0x78, 0x22, 0xe1, 0x13, 0x0a, 0x17, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x43,
|
||||
0x77, 0x54, 0x78, 0x22, 0x91, 0x14, 0x0a, 0x17, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x43,
|
||||
0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
|
||||
0x2e, 0x0a, 0x13, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x6c, 0x69, 0x6d, 0x62, 0x6f, 0x5f, 0x62,
|
||||
0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x11, 0x74, 0x6f,
|
||||
@ -19358,7 +19389,7 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x6c, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x57, 0x61, 0x69, 0x74, 0x69,
|
||||
0x6e, 0x67, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x52, 0x14,
|
||||
0x77, 0x61, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e,
|
||||
0x6e, 0x65, 0x6c, 0x73, 0x1a, 0xb3, 0x04, 0x0a, 0x0e, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67,
|
||||
0x6e, 0x65, 0x6c, 0x73, 0x1a, 0xe3, 0x04, 0x0a, 0x0e, 0x50, 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67,
|
||||
0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x26, 0x0a, 0x0f, 0x72, 0x65, 0x6d, 0x6f, 0x74,
|
||||
0x65, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x70, 0x75, 0x62, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x0d, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x50, 0x75, 0x62, 0x12,
|
||||
@ -19393,7 +19424,10 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x12, 0x18, 0x0a, 0x07,
|
||||
0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70,
|
||||
0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x18, 0x0d,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x1a, 0xf9, 0x01, 0x0a, 0x12, 0x50,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x65, 0x6d, 0x6f, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x75,
|
||||
0x73, 0x74, 0x6f, 0x6d, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x64, 0x61, 0x74,
|
||||
0x61, 0x18, 0x22, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x43,
|
||||
0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x1a, 0xf9, 0x01, 0x0a, 0x12, 0x50,
|
||||
0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x4f, 0x70, 0x65, 0x6e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65,
|
||||
0x6c, 0x12, 0x47, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x50, 0x65, 0x6e, 0x64, 0x69,
|
||||
@ -19571,7 +19605,7 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x04, 0x52, 0x03, 0x73, 0x61, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x73, 0x61, 0x74, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x6d, 0x73, 0x61, 0x74, 0x22, 0x17, 0x0a, 0x15, 0x43, 0x68,
|
||||
0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x22, 0x80, 0x04, 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x42,
|
||||
0x65, 0x73, 0x74, 0x22, 0xb0, 0x04, 0x0a, 0x16, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x42,
|
||||
0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c,
|
||||
0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42,
|
||||
0x02, 0x18, 0x01, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x14,
|
||||
@ -19603,7 +19637,10 @@ var file_lightning_proto_rawDesc = []byte{
|
||||
0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e,
|
||||
0x6c, 0x6e, 0x72, 0x70, 0x63, 0x2e, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x18, 0x70, 0x65,
|
||||
0x6e, 0x64, 0x69, 0x6e, 0x67, 0x4f, 0x70, 0x65, 0x6e, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x42,
|
||||
0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x22, 0x9a, 0x07, 0x0a, 0x12, 0x51, 0x75, 0x65, 0x72, 0x79,
|
||||
0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2e, 0x0a, 0x13, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d,
|
||||
0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x09, 0x20,
|
||||
0x01, 0x28, 0x0c, 0x52, 0x11, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x43, 0x68, 0x61, 0x6e, 0x6e,
|
||||
0x65, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x22, 0x9a, 0x07, 0x0a, 0x12, 0x51, 0x75, 0x65, 0x72, 0x79,
|
||||
0x52, 0x6f, 0x75, 0x74, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a,
|
||||
0x07, 0x70, 0x75, 0x62, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
|
||||
0x70, 0x75, 0x62, 0x4b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x6d, 0x74, 0x18, 0x02, 0x20,
|
||||
|
@ -1592,6 +1592,11 @@ message Channel {
|
||||
the channel's operation.
|
||||
*/
|
||||
string memo = 36;
|
||||
|
||||
/*
|
||||
Custom channel data that might be populated in custom channels.
|
||||
*/
|
||||
bytes custom_channel_data = 37;
|
||||
}
|
||||
|
||||
message ListChannelsRequest {
|
||||
@ -2709,6 +2714,11 @@ message PendingChannelsResponse {
|
||||
impacts the channel's operation.
|
||||
*/
|
||||
string memo = 13;
|
||||
|
||||
/*
|
||||
Custom channel data that might be populated in custom channels.
|
||||
*/
|
||||
bytes custom_channel_data = 34;
|
||||
}
|
||||
|
||||
message PendingOpenChannel {
|
||||
@ -2968,6 +2978,12 @@ message ChannelBalanceResponse {
|
||||
|
||||
// Sum of channels pending remote balances.
|
||||
Amount pending_open_remote_balance = 8;
|
||||
|
||||
/*
|
||||
Custom channel data that might be populated if there are custom channels
|
||||
present.
|
||||
*/
|
||||
bytes custom_channel_data = 9;
|
||||
}
|
||||
|
||||
message QueryRoutesRequest {
|
||||
|
@ -3127,6 +3127,11 @@
|
||||
"memo": {
|
||||
"type": "string",
|
||||
"description": "An optional note-to-self to go along with the channel containing some\nuseful information. This is only ever stored locally and in no way\nimpacts the channel's operation."
|
||||
},
|
||||
"custom_channel_data": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "Custom channel data that might be populated in custom channels."
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -3849,6 +3854,11 @@
|
||||
"memo": {
|
||||
"type": "string",
|
||||
"description": "An optional note-to-self to go along with the channel containing some\nuseful information. This is only ever stored locally and in no way impacts\nthe channel's operation."
|
||||
},
|
||||
"custom_channel_data": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "Custom channel data that might be populated in custom channels."
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -4052,6 +4062,11 @@
|
||||
"pending_open_remote_balance": {
|
||||
"$ref": "#/definitions/lnrpcAmount",
|
||||
"description": "Sum of channels pending remote balances."
|
||||
},
|
||||
"custom_channel_data": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "Custom channel data that might be populated if there are custom channels\npresent."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -964,6 +964,11 @@ func (h *HarnessTest) AssertChannelBalanceResp(hn *node.HarnessNode,
|
||||
expected *lnrpc.ChannelBalanceResponse) {
|
||||
|
||||
resp := hn.RPC.ChannelBalance()
|
||||
|
||||
// Ignore custom channel data of both expected and actual responses.
|
||||
expected.CustomChannelData = nil
|
||||
resp.CustomChannelData = nil
|
||||
|
||||
require.True(h, proto.Equal(expected, resp), "balance is incorrect "+
|
||||
"got: %v, want: %v", resp, expected)
|
||||
}
|
||||
|
68
rpcserver.go
68
rpcserver.go
@ -3529,6 +3529,7 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
||||
unsettledRemoteBalance lnwire.MilliSatoshi
|
||||
pendingOpenLocalBalance lnwire.MilliSatoshi
|
||||
pendingOpenRemoteBalance lnwire.MilliSatoshi
|
||||
customDataBuf bytes.Buffer
|
||||
)
|
||||
|
||||
openChannels, err := r.server.chanStateDB.FetchAllOpenChannels()
|
||||
@ -3536,6 +3537,12 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Encode the number of open channels to the custom data buffer.
|
||||
err = wire.WriteVarInt(&customDataBuf, 0, uint64(len(openChannels)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, channel := range openChannels {
|
||||
c := channel.LocalCommitment
|
||||
localBalance += c.LocalBalance
|
||||
@ -3549,6 +3556,13 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
||||
unsettledRemoteBalance += htlc.Amt
|
||||
}
|
||||
}
|
||||
|
||||
// Encode the custom data for this open channel.
|
||||
openChanData := channel.LocalCommitment.CustomBlob.UnwrapOr(nil)
|
||||
err = wire.WriteVarBytes(&customDataBuf, 0, openChanData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
pendingChannels, err := r.server.chanStateDB.FetchPendingChannels()
|
||||
@ -3556,10 +3570,23 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Encode the number of pending channels to the custom data buffer.
|
||||
err = wire.WriteVarInt(&customDataBuf, 0, uint64(len(pendingChannels)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, channel := range pendingChannels {
|
||||
c := channel.LocalCommitment
|
||||
pendingOpenLocalBalance += c.LocalBalance
|
||||
pendingOpenRemoteBalance += c.RemoteBalance
|
||||
|
||||
// Encode the custom data for this pending channel.
|
||||
openChanData := channel.LocalCommitment.CustomBlob.UnwrapOr(nil)
|
||||
err = wire.WriteVarBytes(&customDataBuf, 0, openChanData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
rpcsLog.Debugf("[channelbalance] local_balance=%v remote_balance=%v "+
|
||||
@ -3594,6 +3621,7 @@ func (r *rpcServer) ChannelBalance(ctx context.Context,
|
||||
Sat: uint64(pendingOpenRemoteBalance.ToSatoshis()),
|
||||
Msat: uint64(pendingOpenRemoteBalance),
|
||||
},
|
||||
CustomChannelData: customDataBuf.Bytes(),
|
||||
|
||||
// Deprecated fields.
|
||||
Balance: int64(localBalance.ToSatoshis()),
|
||||
@ -3654,6 +3682,12 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
|
||||
pendingChan.BroadcastHeight()
|
||||
fundingExpiryBlocks := int32(maxFundingHeight) - currentHeight
|
||||
|
||||
customChanBytes, err := encodeCustomChanData(pendingChan)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode open chan "+
|
||||
"data: %w", err)
|
||||
}
|
||||
|
||||
result[i] = &lnrpc.PendingChannelsResponse_PendingOpenChannel{
|
||||
Channel: &lnrpc.PendingChannelsResponse_PendingChannel{
|
||||
RemoteNodePub: hex.EncodeToString(pub),
|
||||
@ -3667,6 +3701,7 @@ func (r *rpcServer) fetchPendingOpenChannels() (pendingOpenChannels, error) {
|
||||
CommitmentType: rpcCommitmentType(pendingChan.ChanType),
|
||||
Private: isPrivate(pendingChan),
|
||||
Memo: string(pendingChan.Memo),
|
||||
CustomChannelData: customChanBytes,
|
||||
},
|
||||
CommitWeight: commitWeight,
|
||||
CommitFee: int64(localCommitment.CommitFee),
|
||||
@ -4397,6 +4432,30 @@ func isPrivate(dbChannel *channeldb.OpenChannel) bool {
|
||||
return dbChannel.ChannelFlags&lnwire.FFAnnounceChannel != 1
|
||||
}
|
||||
|
||||
// encodeCustomChanData encodes the custom channel data for the open channel.
|
||||
// It encodes that data as a pair of var bytes blobs.
|
||||
func encodeCustomChanData(lnChan *channeldb.OpenChannel) ([]byte, error) {
|
||||
customOpenChanData := lnChan.CustomBlob.UnwrapOr(nil)
|
||||
customLocalCommitData := lnChan.LocalCommitment.CustomBlob.UnwrapOr(nil)
|
||||
|
||||
// We'll encode our custom channel data as two blobs. The first is a
|
||||
// set of var bytes encoding of the open chan data, the second is an
|
||||
// encoding of the local commitment data.
|
||||
var customChanDataBuf bytes.Buffer
|
||||
err := wire.WriteVarBytes(&customChanDataBuf, 0, customOpenChanData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode open chan "+
|
||||
"data: %w", err)
|
||||
}
|
||||
err = wire.WriteVarBytes(&customChanDataBuf, 0, customLocalCommitData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode local commit "+
|
||||
"data: %w", err)
|
||||
}
|
||||
|
||||
return customChanDataBuf.Bytes(), nil
|
||||
}
|
||||
|
||||
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
|
||||
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
||||
isActive, peerAliasLookup bool) (*lnrpc.Channel, error) {
|
||||
@ -4451,6 +4510,14 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
||||
// is returned and peerScidAlias will be an empty ShortChannelID.
|
||||
peerScidAlias, _ := r.server.aliasMgr.GetPeerAlias(chanID)
|
||||
|
||||
// Finally we'll attempt to encode the custom channel data if any
|
||||
// exists.
|
||||
customChanBytes, err := encodeCustomChanData(dbChannel)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to encode open chan data: %w",
|
||||
err)
|
||||
}
|
||||
|
||||
channel := &lnrpc.Channel{
|
||||
Active: isActive,
|
||||
Private: isPrivate(dbChannel),
|
||||
@ -4483,6 +4550,7 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
|
||||
ZeroConf: dbChannel.IsZeroConf(),
|
||||
ZeroConfConfirmedScid: dbChannel.ZeroConfRealScid().ToUint64(),
|
||||
Memo: string(dbChannel.Memo),
|
||||
CustomChannelData: customChanBytes,
|
||||
// TODO: remove the following deprecated fields
|
||||
CsvDelay: uint32(dbChannel.LocalChanCfg.CsvDelay),
|
||||
LocalChanReserveSat: int64(dbChannel.LocalChanCfg.ChanReserve),
|
||||
|
Loading…
Reference in New Issue
Block a user