Skip to content

Commit c8dc6c5

Browse files
authored
Merge pull request #589 from lightninglabs/multi-fixes
Fix runtime ID, check amount when minting collectibles, rebase GetInfo RPC fixes commit
2 parents 75a67e5 + 17b2574 commit c8dc6c5

File tree

6 files changed

+329
-200
lines changed

6 files changed

+329
-200
lines changed

cmd/tapcli/assets.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,18 @@ var mintAssetCommand = cli.Command{
119119
},
120120
}
121121

122-
func parseAssetType(ctx *cli.Context) taprpc.AssetType {
123-
assetType := taprpc.AssetType_NORMAL
124-
if ctx.String(assetTypeName) == "collectible" {
125-
assetType = taprpc.AssetType_COLLECTIBLE
126-
}
122+
func parseAssetType(ctx *cli.Context) (taprpc.AssetType, error) {
123+
switch ctx.String(assetTypeName) {
124+
case "normal":
125+
return taprpc.AssetType_NORMAL, nil
126+
127+
case "collectible":
128+
return taprpc.AssetType_COLLECTIBLE, nil
127129

128-
return assetType
130+
default:
131+
return 0, fmt.Errorf("unknown asset type '%v'",
132+
ctx.String(assetTypeName))
133+
}
129134
}
130135

131136
func mintAsset(ctx *cli.Context) error {
@@ -178,16 +183,43 @@ func mintAsset(ctx *cli.Context) error {
178183
}
179184
}
180185

186+
assetType, err := parseAssetType(ctx)
187+
if err != nil {
188+
return err
189+
}
190+
191+
var (
192+
amount = ctx.Uint64(assetSupplyName)
193+
isCollectible = assetType == taprpc.AssetType_COLLECTIBLE
194+
)
195+
switch {
196+
// If the user did not specify the supply, we can silently assume they
197+
// are aware that the collectible amount is always 1.
198+
case isCollectible && !ctx.IsSet(assetSupplyName):
199+
amount = 1
200+
201+
// If the user explicitly supplied a supply that is incorrect, we must
202+
// inform them instead of silently changing the value to 1, otherwise
203+
// there will be surprises later.
204+
case isCollectible && amount != 1:
205+
return fmt.Errorf("supply must be 1 for collectibles")
206+
207+
// Check that the amount is greater than 0 for normal assets. This is
208+
// also checked in the RPC server, but we can avoid the round trip.
209+
case !isCollectible && amount == 0:
210+
return fmt.Errorf("supply must be set for normal assets")
211+
}
212+
181213
ctxc := getContext()
182214
client, cleanUp := getMintClient(ctx)
183215
defer cleanUp()
184216

185217
resp, err := client.MintAsset(ctxc, &mintrpc.MintAssetRequest{
186218
Asset: &mintrpc.MintAsset{
187-
AssetType: parseAssetType(ctx),
219+
AssetType: assetType,
188220
Name: ctx.String(assetTagName),
189221
AssetMeta: assetMeta,
190-
Amount: ctx.Uint64(assetSupplyName),
222+
Amount: amount,
191223
GroupKey: groupKey,
192224
GroupAnchor: ctx.String(assetGroupAnchorName),
193225
AssetVersion: taprpc.AssetVersion(

rpcserver.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,30 @@ func (r *rpcServer) DebugLevel(ctx context.Context,
284284

285285
// GetInfo returns general information relating to the active daemon. For
286286
// example: its version, network, and lnd version.
287-
func (r *rpcServer) GetInfo(context.Context,
288-
*taprpc.GetInfoRequest) (*taprpc.GetInfoResponse, error) {
287+
func (r *rpcServer) GetInfo(ctx context.Context,
288+
_ *taprpc.GetInfoRequest) (*taprpc.GetInfoResponse, error) {
289+
290+
// Retrieve the best block hash and height from the chain backend.
291+
blockHash, blockHeight, err := r.cfg.Lnd.ChainKit.GetBestBlock(ctx)
292+
if err != nil {
293+
return nil, err
294+
}
295+
296+
// Retrieve the current lnd node's info.
297+
info, err := r.cfg.Lnd.Client.GetInfo(context.Background())
298+
if err != nil {
299+
return nil, err
300+
}
289301

290302
return &taprpc.GetInfoResponse{
291-
Version: Version(),
292-
LndVersion: r.cfg.Lnd.Version.Version,
293-
Network: r.cfg.ChainParams.Name,
303+
Version: Version(),
304+
LndVersion: r.cfg.Lnd.Version.Version,
305+
Network: r.cfg.ChainParams.Name,
306+
LndIdentityPubkey: r.cfg.Lnd.NodePubkey.String(),
307+
NodeAlias: info.Alias,
308+
BlockHeight: uint32(blockHeight),
309+
BlockHash: blockHash.String(),
310+
SyncToChain: info.SyncedToChain,
294311
}, nil
295312
}
296313

tapcfg/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package tapcfg
22

33
import (
44
"context"
5+
"crypto/rand"
56
"database/sql"
7+
"encoding/binary"
68
"fmt"
7-
prand "math/rand"
89

910
"github.com/btcsuite/btclog"
1011
"github.com/lightninglabs/lndclient"
@@ -275,7 +276,13 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
275276
SyncBatchSize: defaultUniverseSyncBatchSize,
276277
})
277278

278-
runtimeID := prand.Int63() // nolint:gosec
279+
var runtimeIDBytes [8]byte
280+
_, err = rand.Read(runtimeIDBytes[:])
281+
if err != nil {
282+
return nil, fmt.Errorf("unable to generate runtime ID: %v", err)
283+
}
284+
285+
runtimeID := int64(binary.BigEndian.Uint64(runtimeIDBytes[:]))
279286
universeFederation := universe.NewFederationEnvoy(
280287
universe.FederationConfig{
281288
FederationDB: federationDB,

0 commit comments

Comments
 (0)