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 committed 2017-01-17 13:49:44 -08:00
1 parent faae0b3bf2
commit 9662887d2f
4 files changed
+56

No files matched your search

+22
View File
@@ -1792,3 +1792,25 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
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
}