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