@@ -14,8 +14,48 @@ import (
14
14
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
15
15
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
16
16
"github.com/urfave/cli"
17
+ "golang.org/x/exp/maps"
17
18
)
18
19
20
+ var (
21
+ // nolint:lll
22
+ scriptKeyTypeMap = map [string ]taprpc.ScriptKeyType {
23
+ "unknown" : taprpc .ScriptKeyType_SCRIPT_KEY_UNKNOWN ,
24
+ "bip86" : taprpc .ScriptKeyType_SCRIPT_KEY_BIP86 ,
25
+ "script-path" : taprpc .ScriptKeyType_SCRIPT_KEY_SCRIPT_PATH_EXTERNAL ,
26
+ "burn" : taprpc .ScriptKeyType_SCRIPT_KEY_BURN ,
27
+ "tombstone" : taprpc .ScriptKeyType_SCRIPT_KEY_TOMBSTONE ,
28
+ "channel" : taprpc .ScriptKeyType_SCRIPT_KEY_CHANNEL ,
29
+ }
30
+ )
31
+
32
+ // parseScriptKeyType parses the script key type query from the command line
33
+ // context. If the user didn't specify a script key type, the "show all" query
34
+ // type is returned.
35
+ func parseScriptKeyType (c * cli.Context ) (* taprpc.ScriptKeyTypeQuery , error ) {
36
+ allScriptKeysQuery := & taprpc.ScriptKeyTypeQuery {
37
+ Type : & taprpc.ScriptKeyTypeQuery_AllTypes {
38
+ AllTypes : true ,
39
+ },
40
+ }
41
+
42
+ if ! c .IsSet (scriptKeyTypeName ) || c .String (scriptKeyTypeName ) == "" {
43
+ return allScriptKeysQuery , nil
44
+ }
45
+
46
+ scriptKeyType , ok := scriptKeyTypeMap [c .String (scriptKeyTypeName )]
47
+ if ! ok {
48
+ return nil , fmt .Errorf ("script key type '%v' is unknown" ,
49
+ c .String (scriptKeyTypeName ))
50
+ }
51
+
52
+ return & taprpc.ScriptKeyTypeQuery {
53
+ Type : & taprpc.ScriptKeyTypeQuery_ExplicitType {
54
+ ExplicitType : scriptKeyType ,
55
+ },
56
+ }, nil
57
+ }
58
+
19
59
var assetsCommands = []cli.Command {
20
60
{
21
61
Name : "assets" ,
64
104
skipProofCourierPingCheckName = "skip-proof-courier-ping-check"
65
105
assetAmountName = "amount"
66
106
burnOverrideConfirmationName = "override_confirmation_destroy_assets"
107
+ scriptKeyTypeName = "script_key_type"
67
108
)
68
109
69
110
var mintAssetCommand = cli.Command {
@@ -666,6 +707,12 @@ var listAssetsCommand = cli.Command{
666
707
Usage : "include freshly minted and not yet confirmed " +
667
708
"assets in the list" ,
668
709
},
710
+ cli.StringFlag {
711
+ Name : scriptKeyTypeName ,
712
+ Usage : "filter assets by the type of script key they " +
713
+ "use; possible values are: " +
714
+ strings .Join (maps .Keys (scriptKeyTypeMap ), ", " ),
715
+ },
669
716
},
670
717
Action : listAssets ,
671
718
}
@@ -677,15 +724,22 @@ func listAssets(ctx *cli.Context) error {
677
724
678
725
// TODO(roasbeef): need to reverse txid
679
726
727
+ scriptKeyQuery , err := parseScriptKeyType (ctx )
728
+ if err != nil {
729
+ return fmt .Errorf ("unable to parse script key type: %w" , err )
730
+ }
731
+
680
732
resp , err := client .ListAssets (ctxc , & taprpc.ListAssetRequest {
681
733
WithWitness : ctx .Bool (assetShowWitnessName ),
682
734
IncludeSpent : ctx .Bool (assetShowSpentName ),
683
735
IncludeLeased : ctx .Bool (assetShowLeasedName ),
684
736
IncludeUnconfirmedMints : ctx .Bool (assetShowUnconfMintsName ),
737
+ ScriptKeyType : scriptKeyQuery ,
685
738
})
686
739
if err != nil {
687
740
return fmt .Errorf ("unable to list assets: %w" , err )
688
741
}
742
+
689
743
printRespJSON (resp )
690
744
return nil
691
745
}
@@ -695,18 +749,39 @@ var listUtxosCommand = cli.Command{
695
749
ShortName : "u" ,
696
750
Usage : "list all utxos" ,
697
751
Description : "list all utxos managing assets" ,
698
- Action : listUtxos ,
752
+ Flags : []cli.Flag {
753
+ cli.BoolFlag {
754
+ Name : assetShowLeasedName ,
755
+ Usage : "include leased assets in the list" ,
756
+ },
757
+ cli.StringFlag {
758
+ Name : scriptKeyTypeName ,
759
+ Usage : "filter assets by the type of script key they " +
760
+ "use; possible values are: " +
761
+ strings .Join (maps .Keys (scriptKeyTypeMap ), ", " ),
762
+ },
763
+ },
764
+ Action : listUtxos ,
699
765
}
700
766
701
767
func listUtxos (ctx * cli.Context ) error {
702
768
ctxc := getContext ()
703
769
client , cleanUp := getClient (ctx )
704
770
defer cleanUp ()
705
771
706
- resp , err := client .ListUtxos (ctxc , & taprpc.ListUtxosRequest {})
772
+ scriptKeyQuery , err := parseScriptKeyType (ctx )
773
+ if err != nil {
774
+ return fmt .Errorf ("unable to parse script key type: %w" , err )
775
+ }
776
+
777
+ resp , err := client .ListUtxos (ctxc , & taprpc.ListUtxosRequest {
778
+ IncludeLeased : ctx .Bool (assetShowLeasedName ),
779
+ ScriptKeyType : scriptKeyQuery ,
780
+ })
707
781
if err != nil {
708
782
return fmt .Errorf ("unable to list utxos: %w" , err )
709
783
}
784
+
710
785
printRespJSON (resp )
711
786
return nil
712
787
}
@@ -758,6 +833,12 @@ var listAssetBalancesCommand = cli.Command{
758
833
"balance query against. Must be used " +
759
834
"together with --by_group" ,
760
835
},
836
+ cli.StringFlag {
837
+ Name : scriptKeyTypeName ,
838
+ Usage : "filter assets by the type of script key they " +
839
+ "use; possible values are: " +
840
+ strings .Join (maps .Keys (scriptKeyTypeMap ), ", " ),
841
+ },
761
842
},
762
843
}
763
844
@@ -766,10 +847,14 @@ func listAssetBalances(ctx *cli.Context) error {
766
847
client , cleanUp := getClient (ctx )
767
848
defer cleanUp ()
768
849
769
- var err error
850
+ scriptKeyQuery , err := parseScriptKeyType (ctx )
851
+ if err != nil {
852
+ return fmt .Errorf ("unable to parse script key type: %w" , err )
853
+ }
770
854
771
855
req := & taprpc.ListBalancesRequest {
772
856
IncludeLeased : ctx .Bool (assetIncludeLeasedName ),
857
+ ScriptKeyType : scriptKeyQuery ,
773
858
}
774
859
775
860
if ! ctx .Bool (groupByGroupName ) {
0 commit comments