@@ -43,6 +43,7 @@ var lnCommands = []cli.Command{
43
43
sendPaymentCommand ,
44
44
payInvoiceCommand ,
45
45
addInvoiceCommand ,
46
+ decodeAssetInvoiceCommand ,
46
47
},
47
48
},
48
49
}
@@ -650,3 +651,65 @@ func addInvoice(ctx *cli.Context) error {
650
651
651
652
return nil
652
653
}
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