Skip to content

Commit f89b907

Browse files
committed
cmd/litcli: add new decodeassetinvoice command
1 parent 5f43ede commit f89b907

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

cmd/litcli/ln.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var lnCommands = []cli.Command{
4343
sendPaymentCommand,
4444
payInvoiceCommand,
4545
addInvoiceCommand,
46+
decodeAssetInvoiceCommand,
4647
},
4748
},
4849
}
@@ -650,3 +651,65 @@ func addInvoice(ctx *cli.Context) error {
650651

651652
return nil
652653
}
654+
655+
var decodeAssetInvoiceCommand = cli.Command{
656+
Name: "decodeassetinvoice",
657+
Category: "Payments",
658+
Usage: "Decodes an LN invoice and displays the invoice's amount in asset " +
659+
"units specified by an asset ID",
660+
Description: `
661+
This command can be used to display the information encoded in an invoice.
662+
Given a chosen asset_id, the invoice's amount expressed in units of the asset
663+
will be displayed.
664+
665+
Other information such as the decimal display of an asset, and the asset
666+
group information (if applicable) are also shown.
667+
`,
668+
ArgsUsage: "--pay_req=X --asset_id=X",
669+
Flags: []cli.Flag{
670+
cli.StringFlag{
671+
Name: "pay_req",
672+
Usage: "a zpay32 encoded payment request to fulfill",
673+
},
674+
assetIDFlag,
675+
},
676+
Action: decodeAssetInvoice,
677+
}
678+
679+
func decodeAssetInvoice(ctx *cli.Context) error {
680+
ctxb := context.Background()
681+
682+
switch {
683+
case !ctx.IsSet("pay_req"):
684+
return fmt.Errorf("pay_req argument missing")
685+
case !ctx.IsSet(assetIDFlag.Name):
686+
return fmt.Errorf("the --asset_id flag must be set")
687+
}
688+
689+
payReq := ctx.String("pay_req")
690+
691+
assetIDStr := ctx.String(assetIDFlag.Name)
692+
assetIDBytes, err := hex.DecodeString(assetIDStr)
693+
if err != nil {
694+
return fmt.Errorf("unable to decode assetID: %v", err)
695+
}
696+
697+
tapdConn, cleanup, err := connectSuperMacClient(ctx)
698+
if err != nil {
699+
return fmt.Errorf("unable to make rpc con: %w", err)
700+
}
701+
defer cleanup()
702+
703+
channelsClient := tchrpc.NewTaprootAssetChannelsClient(tapdConn)
704+
resp, err := channelsClient.DecodeAssetPayReq(ctxb, &tchrpc.AssetPayReq{
705+
AssetId: assetIDBytes,
706+
PayReqString: payReq,
707+
})
708+
if err != nil {
709+
return fmt.Errorf("error adding invoice: %w", err)
710+
}
711+
712+
printRespJSON(resp)
713+
714+
return nil
715+
}

0 commit comments

Comments
 (0)