rpcserver+cmd/lncli: implement DecodePayReq
This commit implements the newly added RPC to decode payment requests passed over the command line or directly via gRPC. With this tool, users can now examine payment requests they see in the wild for diagnostic or debugging purposes.
This commit is contained in:
parent
faae0b3bf2
commit
9662887d2f
@ -531,6 +531,8 @@ func listChannels(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(roasbeef): defer close the client for the all
|
||||||
|
|
||||||
printRespJson(resp)
|
printRespJson(resp)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -955,3 +957,33 @@ func debugLevel(ctx *cli.Context) error {
|
|||||||
printRespJson(resp)
|
printRespJson(resp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DecodePayReq = cli.Command{
|
||||||
|
Name: "decodepayreq",
|
||||||
|
Usage: "decodepayreq --pay_req=[encoded_pay_req]",
|
||||||
|
Description: "Decode the passed payment request revealing the destination, payment hash and value of the payment request",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "pay_req",
|
||||||
|
Usage: "the zpay32 encoded payment request",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: decodePayReq,
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodePayReq(ctx *cli.Context) error {
|
||||||
|
ctxb := context.Background()
|
||||||
|
client := getClient(ctx)
|
||||||
|
|
||||||
|
req := &lnrpc.PayReqString{
|
||||||
|
PayReq: ctx.String("pay_req"),
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.DecodePayReq(ctxb, req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printRespJson(resp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -71,6 +71,7 @@ func main() {
|
|||||||
QueryRouteCommand,
|
QueryRouteCommand,
|
||||||
GetNetworkInfoCommand,
|
GetNetworkInfoCommand,
|
||||||
DebugLevel,
|
DebugLevel,
|
||||||
|
DecodePayReq,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
@ -1020,6 +1020,7 @@ func testInvoiceSubscriptions(net *networkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// With the assertion above set up, send a payment from Alice to Bob
|
// With the assertion above set up, send a payment from Alice to Bob
|
||||||
// which should finalize and settle the invoice.
|
// which should finalize and settle the invoice.
|
||||||
|
time.Sleep(time.Millisecond * 500)
|
||||||
sendStream, err := net.Alice.SendPayment(ctxb)
|
sendStream, err := net.Alice.SendPayment(ctxb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create alice payment stream: %v", err)
|
t.Fatalf("unable to create alice payment stream: %v", err)
|
||||||
|
22
rpcserver.go
22
rpcserver.go
@ -1792,3 +1792,25 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
|
|||||||
|
|
||||||
return &lnrpc.DebugLevelResponse{}, nil
|
return &lnrpc.DebugLevelResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DecodePayReq takes an encoded payment request string and attempts to decode
|
||||||
|
// it, returning a full description of the conditions encoded within the
|
||||||
|
// payment request.
|
||||||
|
func (r *rpcServer) DecodePayReq(ctx context.Context,
|
||||||
|
req *lnrpc.PayReqString) (*lnrpc.PayReq, error) {
|
||||||
|
|
||||||
|
// Fist we'll attempt to decode the payment request string, if the
|
||||||
|
// request is invalid or the checksum doesn't match, then we'll exit
|
||||||
|
// here with an error.
|
||||||
|
payReq, err := zpay32.Decode(req.PayReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dest := payReq.Destination.SerializeCompressed()
|
||||||
|
return &lnrpc.PayReq{
|
||||||
|
Destination: hex.EncodeToString(dest),
|
||||||
|
PaymentHash: hex.EncodeToString(payReq.PaymentHash[:]),
|
||||||
|
NumSatoshis: int64(payReq.Amount),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user