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:
Olaoluwa Osuntokun
2017-01-17 13:39:30 -08:00
parent faae0b3bf2
commit 9662887d2f
4 changed files with 56 additions and 0 deletions

View File

@@ -531,6 +531,8 @@ func listChannels(ctx *cli.Context) error {
return err
}
// TODO(roasbeef): defer close the client for the all
printRespJson(resp)
return nil
@@ -955,3 +957,33 @@ func debugLevel(ctx *cli.Context) error {
printRespJson(resp)
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
}