mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-15 03:51:23 +01:00
Merge pull request #8813 from hieblmi/chaninfo-per-outpoint
Allow for a channel point in `GetChanInfo`
This commit is contained in:
commit
98c52df4d2
7 changed files with 1459 additions and 1372 deletions
|
@ -1787,8 +1787,16 @@ var getChanInfoCommand = cli.Command{
|
||||||
ArgsUsage: "chan_id",
|
ArgsUsage: "chan_id",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.Uint64Flag{
|
cli.Uint64Flag{
|
||||||
Name: "chan_id",
|
Name: "chan_id",
|
||||||
Usage: "the 8-byte compact channel ID to query for",
|
Usage: "The 8-byte compact channel ID to query for. " +
|
||||||
|
"If this is set the chan_point param is " +
|
||||||
|
"ignored.",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "chan_point",
|
||||||
|
Usage: "The channel point in format txid:index. If " +
|
||||||
|
"the chan_id param is set this param is " +
|
||||||
|
"ignored.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: actionDecorator(getChanInfo),
|
Action: actionDecorator(getChanInfo),
|
||||||
|
@ -1800,24 +1808,31 @@ func getChanInfo(ctx *cli.Context) error {
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
chanID uint64
|
chanID uint64
|
||||||
err error
|
chanPoint string
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case ctx.IsSet("chan_id"):
|
case ctx.IsSet("chan_id"):
|
||||||
chanID = ctx.Uint64("chan_id")
|
chanID = ctx.Uint64("chan_id")
|
||||||
|
|
||||||
case ctx.Args().Present():
|
case ctx.Args().Present():
|
||||||
chanID, err = strconv.ParseUint(ctx.Args().First(), 10, 64)
|
chanID, err = strconv.ParseUint(ctx.Args().First(), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing chan_id: %w", err)
|
return fmt.Errorf("error parsing chan_id: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ctx.IsSet("chan_point"):
|
||||||
|
chanPoint = ctx.String("chan_point")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("chan_id argument missing")
|
return fmt.Errorf("chan_id or chan_point argument missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
req := &lnrpc.ChanInfoRequest{
|
req := &lnrpc.ChanInfoRequest{
|
||||||
ChanId: chanID,
|
ChanId: chanID,
|
||||||
|
ChanPoint: chanPoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
chanInfo, err := client.GetChanInfo(ctxc, req)
|
chanInfo, err := client.GetChanInfo(ctxc, req)
|
||||||
|
|
|
@ -35,10 +35,16 @@
|
||||||
* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779)
|
* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779)
|
||||||
now accepts `0` failure amounts.
|
now accepts `0` failure amounts.
|
||||||
|
|
||||||
|
* [`ChanInfoRequest`](https://github.com/lightningnetwork/lnd/pull/8813)
|
||||||
|
adds support for channel points.
|
||||||
|
|
||||||
## lncli Updates
|
## lncli Updates
|
||||||
|
|
||||||
* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
|
* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
|
||||||
`0` failure amounts.
|
`0` failure amounts.
|
||||||
|
|
||||||
|
* [`getchaninfo`](https://github.com/lightningnetwork/lnd/pull/8813) now accepts
|
||||||
|
a channel outpoint besides a channel id.
|
||||||
|
|
||||||
## Code Health
|
## Code Health
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1555,6 +1555,10 @@ func local_request_Lightning_GetNodeMetrics_0(ctx context.Context, marshaler run
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
filter_Lightning_GetChanInfo_0 = &utilities.DoubleArray{Encoding: map[string]int{"chan_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
||||||
|
)
|
||||||
|
|
||||||
func request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
func request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
var protoReq ChanInfoRequest
|
var protoReq ChanInfoRequest
|
||||||
var metadata runtime.ServerMetadata
|
var metadata runtime.ServerMetadata
|
||||||
|
@ -1576,6 +1580,13 @@ func request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtime.Mars
|
||||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chan_id", err)
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chan_id", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := req.ParseForm(); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Lightning_GetChanInfo_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
msg, err := client.GetChanInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
msg, err := client.GetChanInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
return msg, metadata, err
|
return msg, metadata, err
|
||||||
|
|
||||||
|
@ -1602,6 +1613,13 @@ func local_request_Lightning_GetChanInfo_0(ctx context.Context, marshaler runtim
|
||||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chan_id", err)
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "chan_id", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := req.ParseForm(); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Lightning_GetChanInfo_0); err != nil {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
msg, err := server.GetChanInfo(ctx, &protoReq)
|
msg, err := server.GetChanInfo(ctx, &protoReq)
|
||||||
return msg, metadata, err
|
return msg, metadata, err
|
||||||
|
|
||||||
|
|
|
@ -3443,6 +3443,10 @@ message ChanInfoRequest {
|
||||||
output index for the channel.
|
output index for the channel.
|
||||||
*/
|
*/
|
||||||
uint64 chan_id = 1 [jstype = JS_STRING];
|
uint64 chan_id = 1 [jstype = JS_STRING];
|
||||||
|
|
||||||
|
// The channel point of the channel in format funding_txid:output_index. If
|
||||||
|
// chan_id is specified, this field is ignored.
|
||||||
|
string chan_point = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message NetworkInfoRequest {
|
message NetworkInfoRequest {
|
||||||
|
|
|
@ -1204,6 +1204,13 @@
|
||||||
"required": true,
|
"required": true,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "uint64"
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "chan_point",
|
||||||
|
"description": "The channel point of the channel in format funding_txid:output_index. If\nchan_id is specified, this field is ignored.",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|
35
rpcserver.go
35
rpcserver.go
|
@ -6295,15 +6295,40 @@ func (r *rpcServer) GetNodeMetrics(ctx context.Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChanInfo returns the latest authenticated network announcement for the
|
// GetChanInfo returns the latest authenticated network announcement for the
|
||||||
// given channel identified by its channel ID: an 8-byte integer which uniquely
|
// given channel identified by either its channel ID or a channel outpoint. Both
|
||||||
// identifies the location of transaction's funding output within the block
|
// uniquely identify the location of transaction's funding output within the
|
||||||
// chain.
|
// blockchain. The former is an 8-byte integer, while the latter is a string
|
||||||
func (r *rpcServer) GetChanInfo(ctx context.Context,
|
// formatted as funding_txid:output_index.
|
||||||
|
func (r *rpcServer) GetChanInfo(_ context.Context,
|
||||||
in *lnrpc.ChanInfoRequest) (*lnrpc.ChannelEdge, error) {
|
in *lnrpc.ChanInfoRequest) (*lnrpc.ChannelEdge, error) {
|
||||||
|
|
||||||
graph := r.server.graphDB
|
graph := r.server.graphDB
|
||||||
|
|
||||||
edgeInfo, edge1, edge2, err := graph.FetchChannelEdgesByID(in.ChanId)
|
var (
|
||||||
|
edgeInfo *models.ChannelEdgeInfo
|
||||||
|
edge1, edge2 *models.ChannelEdgePolicy
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case in.ChanId != 0:
|
||||||
|
edgeInfo, edge1, edge2, err = graph.FetchChannelEdgesByID(
|
||||||
|
in.ChanId,
|
||||||
|
)
|
||||||
|
|
||||||
|
case in.ChanPoint != "":
|
||||||
|
var chanPoint *wire.OutPoint
|
||||||
|
chanPoint, err = wire.NewOutPointFromString(in.ChanPoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
edgeInfo, edge1, edge2, err = graph.FetchChannelEdgesByOutpoint(
|
||||||
|
chanPoint,
|
||||||
|
)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("specify either chan_id or chan_point")
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue