Skip to content

Commit 053a88a

Browse files
authored
Merge pull request #1690 from lightninglabs/cli-additions
cli: add missing `assets removelease` command, fix default value for balances
2 parents 39673f2 + 1374e94 commit 053a88a

File tree

5 files changed

+110
-4
lines changed

5 files changed

+110
-4
lines changed

cmd/commands/assets.go

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"strconv"
99
"strings"
1010

11+
"github.com/btcsuite/btcd/wire"
1112
taprootassets "github.com/lightninglabs/taproot-assets"
1213
"github.com/lightninglabs/taproot-assets/tapcfg"
1314
"github.com/lightninglabs/taproot-assets/taprpc"
15+
wrpc "github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
1416
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
1517
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1618
"github.com/urfave/cli"
@@ -38,9 +40,28 @@ func parseScriptKeyType(c *cli.Context) (*taprpc.ScriptKeyTypeQuery, error) {
3840
AllTypes: true,
3941
},
4042
}
43+
bip86ScriptKeysQuery := &taprpc.ScriptKeyTypeQuery{
44+
Type: &taprpc.ScriptKeyTypeQuery_ExplicitType{
45+
ExplicitType: taprpc.ScriptKeyType_SCRIPT_KEY_BIP86,
46+
},
47+
}
4148

42-
if !c.IsSet(scriptKeyTypeName) || c.String(scriptKeyTypeName) == "" {
49+
// The default value if no script key type is set is aligned with the
50+
// default value of the RPC interface, which is BIP-86 script keys.
51+
switch {
52+
// Both flags are set, which is not allowed.
53+
case c.IsSet(scriptKeyTypeName) && c.IsSet(scriptKeyTypeAll):
54+
return nil, fmt.Errorf("cannot set both '%s' and '%s'",
55+
scriptKeyTypeName, scriptKeyTypeAll)
56+
57+
// The "all script key types" flag is set, so we return a query
58+
// that requests all script key types.
59+
case c.Bool(scriptKeyTypeAll):
4360
return allScriptKeysQuery, nil
61+
62+
// No flag is set, use the default value of BIP-86 script keys.
63+
case !c.IsSet(scriptKeyTypeName) || c.String(scriptKeyTypeName) == "":
64+
return bip86ScriptKeysQuery, nil
4465
}
4566

4667
scriptKeyType, ok := scriptKeyTypeMap[c.String(scriptKeyTypeName)]
@@ -73,11 +94,12 @@ var assetsCommands = []cli.Command{
7394
listBurnsCommand,
7495
listTransfersCommand,
7596
fetchMetaCommand,
97+
removeUtxoLeaseCommand,
7698
},
7799
},
78100
}
79101

80-
var (
102+
const (
81103
assetTypeName = "type"
82104
assetTagName = "name"
83105
assetSupplyName = "supply"
@@ -105,6 +127,7 @@ var (
105127
assetAmountName = "amount"
106128
burnOverrideConfirmationName = "override_confirmation_destroy_assets"
107129
scriptKeyTypeName = "script_key_type"
130+
scriptKeyTypeAll = "all_script_key_types"
108131
)
109132

110133
var mintAssetCommand = cli.Command{
@@ -714,6 +737,13 @@ var listAssetsCommand = cli.Command{
714737
Usage: "filter assets by the type of script key they " +
715738
"use; possible values are: " +
716739
strings.Join(maps.Keys(scriptKeyTypeMap), ", "),
740+
Value: "bip86",
741+
},
742+
cli.BoolFlag{
743+
Name: scriptKeyTypeAll,
744+
Usage: "show all assets, regardless of the script " +
745+
"key type; cannot be used at the same time " +
746+
"as --" + scriptKeyTypeName,
717747
},
718748
},
719749
Action: listAssets,
@@ -761,6 +791,13 @@ var listUtxosCommand = cli.Command{
761791
Usage: "filter assets by the type of script key they " +
762792
"use; possible values are: " +
763793
strings.Join(maps.Keys(scriptKeyTypeMap), ", "),
794+
Value: "bip86",
795+
},
796+
cli.BoolFlag{
797+
Name: scriptKeyTypeAll,
798+
Usage: "show all assets, regardless of the script " +
799+
"key type; cannot be used at the same time " +
800+
"as --" + scriptKeyTypeName,
764801
},
765802
},
766803
Action: listUtxos,
@@ -840,6 +877,13 @@ var listAssetBalancesCommand = cli.Command{
840877
Usage: "filter assets by the type of script key they " +
841878
"use; possible values are: " +
842879
strings.Join(maps.Keys(scriptKeyTypeMap), ", "),
880+
Value: "bip86",
881+
},
882+
cli.BoolFlag{
883+
Name: scriptKeyTypeAll,
884+
Usage: "show all assets, regardless of the script " +
885+
"key type; cannot be used at the same time " +
886+
"as --" + scriptKeyTypeName,
843887
},
844888
},
845889
}
@@ -1212,3 +1256,53 @@ func fetchMeta(ctx *cli.Context) error {
12121256
printRespJSON(resp)
12131257
return nil
12141258
}
1259+
1260+
var removeUtxoLeaseCommand = cli.Command{
1261+
Name: "removelease",
1262+
ShortName: "rl",
1263+
Usage: "release the lease/lock/reservation on an asset UTXO",
1264+
Description: `
1265+
Allows the caller to release the lease/lock/reservation that is put on
1266+
an asset UTXO when it is used in a transaction. The lease is to prevent
1267+
the asset UTXO from being used in another transaction while the current
1268+
transaction is being signed and broadcast. If the transaction fails to
1269+
broadcast, the lease will remain in place for up to 10 minutes. With
1270+
this command, the caller can release the lease early, allowing the
1271+
UTXO to be used in another transaction immediately.
1272+
1273+
This command either returns an empty response ({}), or an error if the
1274+
lease could not be released.
1275+
`,
1276+
Flags: []cli.Flag{
1277+
cli.StringFlag{
1278+
Name: outpointName,
1279+
Usage: "the outpoint (<txid>:<vout>) of the UTXO to " +
1280+
"release the lease for",
1281+
},
1282+
},
1283+
Action: removeUtxoLease,
1284+
}
1285+
1286+
func removeUtxoLease(ctx *cli.Context) error {
1287+
ctxc := getContext()
1288+
client, cleanUp := getWalletClient(ctx)
1289+
defer cleanUp()
1290+
1291+
outpoint, err := wire.NewOutPointFromString(ctx.String(outpointName))
1292+
if err != nil {
1293+
return fmt.Errorf("error parsing outpoint: %w", err)
1294+
}
1295+
1296+
resp, err := client.RemoveUTXOLease(ctxc, &wrpc.RemoveUTXOLeaseRequest{
1297+
Outpoint: &taprpc.OutPoint{
1298+
Txid: outpoint.Hash[:],
1299+
OutputIndex: outpoint.Index,
1300+
},
1301+
})
1302+
if err != nil {
1303+
return fmt.Errorf("unable to remove utxo lease: %w", err)
1304+
}
1305+
1306+
printRespJSON(resp)
1307+
return nil
1308+
}

docs/release-notes/release-notes-0.7.0.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
asset command flag from `--universe_commitments` to
8686
`--enable_supply_commitments` for consistency with the updated terminology.
8787

88+
- The [CLI command `tapcli assets removelease` was added to give access to the
89+
`RemoveUTXOLease` RPC method on the command line as
90+
well](https://github.com/lightninglabs/taproot-assets/pull/1690).
91+
8892
# Improvements
8993

9094
## Functional Updates
@@ -93,6 +97,12 @@
9397

9498
## tapcli Updates
9599

100+
- The default script key type in the `tapcli assets list`,
101+
`tapcli assets balance` and `tapcli assets utxos` commands was changed from
102+
the default "all script key types" [to the value
103+
`bip86`](https://github.com/lightninglabs/taproot-assets/pull/1690) to match
104+
the default value of the RPC interface.
105+
96106
## Code Health
97107

98108
- A series of PRs was created that refactored the send and funding logic in

taprpc/assetwalletrpc/assetwallet.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ service AssetWallet {
9898
rpc VerifyAssetOwnership (VerifyAssetOwnershipRequest)
9999
returns (VerifyAssetOwnershipResponse);
100100

101-
/*
101+
/* `tapcli: assets removelease`
102102
RemoveUTXOLease removes the lease/lock/reservation of the given managed
103103
UTXO.
104104
*/

taprpc/assetwalletrpc/assetwallet.swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
},
250250
"/v1/taproot-assets/wallet/utxo-lease/delete": {
251251
"post": {
252-
"summary": "RemoveUTXOLease removes the lease/lock/reservation of the given managed\nUTXO.",
252+
"summary": "`tapcli: assets removelease`\nRemoveUTXOLease removes the lease/lock/reservation of the given managed\nUTXO.",
253253
"operationId": "AssetWallet_RemoveUTXOLease",
254254
"responses": {
255255
"200": {

taprpc/assetwalletrpc/assetwallet_grpc.pb.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)