Skip to content

Commit 1f8a5c6

Browse files
committed
cmd: add --first flag to fetchSupplyCommit, default to latest
Extend the `universe fetchsupplycommit` command with a new `--first` flag to explicitly fetch the very first supply commitment for a group. Update argument validation to allow at most one of `--first`, `--outpoint`, or `--spent_outpoint`. If no flag is provided, the command now defaults to fetching the latest supply commitment instead of the first.
1 parent 4f39a54 commit 1f8a5c6

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

cmd/commands/universe.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,16 +1634,20 @@ var fetchSupplyCommitCmd = cli.Command{
16341634
Description: `
16351635
Fetch the on-chain supply commitment for a specific asset group.
16361636
1637-
At most one of --outpoint and --spent_outpoint may be provided. If
1638-
neither is provided, the very first supply commitment for the asset
1639-
group will be fetched.
1637+
At most one of --first, --outpoint, and --spent_outpoint may be
1638+
provided. If none are provided, the latest supply commitment for the
1639+
asset group will be fetched.
16401640
`,
16411641
Flags: []cli.Flag{
16421642
&cli.StringFlag{
16431643
Name: "group_key",
16441644
Usage: "the group key of the asset group to fetch",
16451645
Required: true,
16461646
},
1647+
&cli.BoolFlag{
1648+
Name: "first",
1649+
Usage: "fetch the very first supply commitment",
1650+
},
16471651
&cli.StringFlag{
16481652
Name: "outpoint",
16491653
Usage: "(format <txid>:<vout>) fetch the supply " +
@@ -1665,13 +1669,25 @@ func fetchSupplyCommit(ctx *cli.Context) error {
16651669
client, cleanUp := getUniverseClient(ctx)
16661670
defer cleanUp()
16671671

1672+
firstSet := ctx.IsSet("first")
16681673
outpointSet := ctx.IsSet("outpoint")
16691674
spentOutpointSet := ctx.IsSet("spent_outpoint")
16701675

1671-
if outpointSet && spentOutpointSet {
1672-
return fmt.Errorf(
1673-
"only one of --outpoint or --spent_outpoint can be set",
1674-
)
1676+
// Check that at most one of the three flags is set.
1677+
flagsSet := 0
1678+
if firstSet {
1679+
flagsSet++
1680+
}
1681+
if outpointSet {
1682+
flagsSet++
1683+
}
1684+
if spentOutpointSet {
1685+
flagsSet++
1686+
}
1687+
1688+
if flagsSet > 1 {
1689+
return fmt.Errorf("only one of --first, --outpoint, or " +
1690+
"--spent_outpoint can be set")
16751691
}
16761692

16771693
req := &unirpc.FetchSupplyCommitRequest{
@@ -1681,6 +1697,11 @@ func fetchSupplyCommit(ctx *cli.Context) error {
16811697
}
16821698

16831699
switch {
1700+
case firstSet:
1701+
req.Locator = &unirpc.FetchSupplyCommitRequest_VeryFirst{
1702+
VeryFirst: true,
1703+
}
1704+
16841705
case outpointSet:
16851706
arg := ctx.String("outpoint")
16861707
outpoint, err := wire.NewOutPointFromString(arg)
@@ -1710,8 +1731,8 @@ func fetchSupplyCommit(ctx *cli.Context) error {
17101731
}
17111732

17121733
default:
1713-
req.Locator = &unirpc.FetchSupplyCommitRequest_VeryFirst{
1714-
VeryFirst: true,
1734+
req.Locator = &unirpc.FetchSupplyCommitRequest_Latest{
1735+
Latest: true,
17151736
}
17161737
}
17171738

0 commit comments

Comments
 (0)