Skip to content

Commit c639f47

Browse files
committed
cmd/litcli: add new decodeassetinvoice command
1 parent 1f4a0cd commit c639f47

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

cmd/litcli/ln.go

Lines changed: 71 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
}
@@ -635,3 +636,73 @@ func addInvoice(ctx *cli.Context) error {
635636

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

0 commit comments

Comments
 (0)