Skip to content

Commit e157457

Browse files
authored
Merge pull request #1823 from lightninglabs/wip/supplycommit/locator-fetch-latest-supply-commit
Add support for fetching latest supply commitment via new locator type
2 parents d7d8f9d + c9ae4bc commit e157457

File tree

11 files changed

+887
-523
lines changed

11 files changed

+887
-523
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

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
- https://github.com/lightninglabs/taproot-assets/pull/1777
7777
- https://github.com/lightninglabs/taproot-assets/pull/1796
7878
- https://github.com/lightninglabs/taproot-assets/pull/1797
79+
- https://github.com/lightninglabs/taproot-assets/pull/1823
7980

8081
- A new [address version 2 was introduced that supports grouped assets and
8182
custom (sender-defined)
@@ -192,6 +193,11 @@
192193
- The `tapcli addrs receives` command now supports
193194
[new `--start_timestamp` and `--end_timestamp` flags](https://github.com/lightninglabs/taproot-assets/pull/1794).
194195

196+
- The `fetchsupplycommit` command [now supports](https://github.com/lightninglabs/taproot-assets/pull/1823)
197+
a `--first` flag to fetch the very first supply commitment; if no flag is
198+
provided, it defaults to fetching the latest. Only one of `--first`,
199+
`--outpoint`, or `--spent_outpoint` may be set.
200+
195201
# Improvements
196202

197203
## Functional Updates

itest/rpcassert/universerpc.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package rpcassert
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
8+
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
9+
"github.com/lightningnetwork/lnd/lntest/wait"
10+
)
11+
12+
// FetchSupplyCommitRPC calls the FetchSupplyCommit RPC and asserts that the
13+
// returned response matches the given predicate. If the predicate is nil, only
14+
// basic checks are performed (non-nil response).
15+
//
16+
// If the assertion fails, the test is failed.
17+
func FetchSupplyCommitRPC(t *testing.T, ctx context.Context,
18+
client unirpc.UniverseClient,
19+
assertPredicate func(*unirpc.FetchSupplyCommitResponse) error,
20+
req *unirpc.FetchSupplyCommitRequest) *unirpc.FetchSupplyCommitResponse { // nolint: lll
21+
22+
t.Helper()
23+
24+
var resp *unirpc.FetchSupplyCommitResponse
25+
err := wait.NoError(func() error {
26+
var err error
27+
resp, err = client.FetchSupplyCommit(ctx, req)
28+
if err != nil {
29+
return err
30+
}
31+
32+
if resp == nil {
33+
return fmt.Errorf("nil response")
34+
}
35+
36+
if assertPredicate != nil {
37+
return assertPredicate(resp)
38+
}
39+
40+
return nil
41+
}, defaultWaitTimeout)
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
46+
return resp
47+
}

0 commit comments

Comments
 (0)