@@ -43,6 +43,7 @@ var lnCommands = []cli.Command{
4343 sendPaymentCommand ,
4444 payInvoiceCommand ,
4545 addInvoiceCommand ,
46+ decodeAssetInvoiceCommand ,
4647 },
4748 },
4849}
@@ -639,3 +640,73 @@ 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 encoAddInvoiceded in an
651+ invoice. Given a chosen asset_id, the invoice's amount expressed in units of
652+ the asset 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 --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+ args := ctx .Args ()
670+ ctxb := context .Background ()
671+
672+ var payReq string
673+ switch {
674+ case ctx .IsSet ("pay_req" ):
675+ payReq = ctx .String ("pay_req" )
676+ case args .Present ():
677+ payReq = args .First ()
678+ default :
679+ return fmt .Errorf ("pay_req argument missing" )
680+ }
681+
682+ if ! ctx .IsSet (assetIDFlag .Name ) {
683+ return fmt .Errorf ("the --asset_id flag must be set" )
684+ }
685+
686+ assetIDStr := ctx .String (assetIDFlag .Name )
687+ assetIDBytes , err := hex .DecodeString (assetIDStr )
688+ if err != nil {
689+ return fmt .Errorf ("unable to decode assetID: %v" , err )
690+ }
691+
692+ tapdConn , cleanup , err := connectSuperMacClient (ctx )
693+ if err != nil {
694+ return fmt .Errorf ("unable to make rpc con: %w" , err )
695+ }
696+ defer cleanup ()
697+
698+ channelsClient := tchrpc .NewTaprootAssetChannelsClient (tapdConn )
699+ resp , err := channelsClient .DecodeAssetPayReq (ctxb , & tchrpc.AssetPayReq {
700+ AssetId : assetIDBytes ,
701+ payReq : & lnrpc.PayReqString {
702+ PayReq : payReq ,
703+ },
704+ })
705+ if err != nil {
706+ return fmt .Errorf ("error adding invoice: %w" , err )
707+ }
708+
709+ printRespJSON (resp )
710+
711+ return nil
712+ }
0 commit comments