Skip to content

Commit

Permalink
Merge pull request #589 from lightninglabs/multi-fixes
Browse files Browse the repository at this point in the history
Fix runtime ID, check amount when minting collectibles, rebase GetInfo RPC fixes commit
  • Loading branch information
Roasbeef authored Oct 17, 2023
2 parents 75a67e5 + 17b2574 commit c8dc6c5
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 200 deletions.
48 changes: 40 additions & 8 deletions cmd/tapcli/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,18 @@ var mintAssetCommand = cli.Command{
},
}

func parseAssetType(ctx *cli.Context) taprpc.AssetType {
assetType := taprpc.AssetType_NORMAL
if ctx.String(assetTypeName) == "collectible" {
assetType = taprpc.AssetType_COLLECTIBLE
}
func parseAssetType(ctx *cli.Context) (taprpc.AssetType, error) {
switch ctx.String(assetTypeName) {
case "normal":
return taprpc.AssetType_NORMAL, nil

case "collectible":
return taprpc.AssetType_COLLECTIBLE, nil

return assetType
default:
return 0, fmt.Errorf("unknown asset type '%v'",
ctx.String(assetTypeName))
}
}

func mintAsset(ctx *cli.Context) error {
Expand Down Expand Up @@ -178,16 +183,43 @@ func mintAsset(ctx *cli.Context) error {
}
}

assetType, err := parseAssetType(ctx)
if err != nil {
return err
}

var (
amount = ctx.Uint64(assetSupplyName)
isCollectible = assetType == taprpc.AssetType_COLLECTIBLE
)
switch {
// If the user did not specify the supply, we can silently assume they
// are aware that the collectible amount is always 1.
case isCollectible && !ctx.IsSet(assetSupplyName):
amount = 1

// If the user explicitly supplied a supply that is incorrect, we must
// inform them instead of silently changing the value to 1, otherwise
// there will be surprises later.
case isCollectible && amount != 1:
return fmt.Errorf("supply must be 1 for collectibles")

// Check that the amount is greater than 0 for normal assets. This is
// also checked in the RPC server, but we can avoid the round trip.
case !isCollectible && amount == 0:
return fmt.Errorf("supply must be set for normal assets")
}

ctxc := getContext()
client, cleanUp := getMintClient(ctx)
defer cleanUp()

resp, err := client.MintAsset(ctxc, &mintrpc.MintAssetRequest{
Asset: &mintrpc.MintAsset{
AssetType: parseAssetType(ctx),
AssetType: assetType,
Name: ctx.String(assetTagName),
AssetMeta: assetMeta,
Amount: ctx.Uint64(assetSupplyName),
Amount: amount,
GroupKey: groupKey,
GroupAnchor: ctx.String(assetGroupAnchorName),
AssetVersion: taprpc.AssetVersion(
Expand Down
27 changes: 22 additions & 5 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,30 @@ func (r *rpcServer) DebugLevel(ctx context.Context,

// GetInfo returns general information relating to the active daemon. For
// example: its version, network, and lnd version.
func (r *rpcServer) GetInfo(context.Context,
*taprpc.GetInfoRequest) (*taprpc.GetInfoResponse, error) {
func (r *rpcServer) GetInfo(ctx context.Context,
_ *taprpc.GetInfoRequest) (*taprpc.GetInfoResponse, error) {

// Retrieve the best block hash and height from the chain backend.
blockHash, blockHeight, err := r.cfg.Lnd.ChainKit.GetBestBlock(ctx)
if err != nil {
return nil, err
}

// Retrieve the current lnd node's info.
info, err := r.cfg.Lnd.Client.GetInfo(context.Background())
if err != nil {
return nil, err
}

return &taprpc.GetInfoResponse{
Version: Version(),
LndVersion: r.cfg.Lnd.Version.Version,
Network: r.cfg.ChainParams.Name,
Version: Version(),
LndVersion: r.cfg.Lnd.Version.Version,
Network: r.cfg.ChainParams.Name,
LndIdentityPubkey: r.cfg.Lnd.NodePubkey.String(),
NodeAlias: info.Alias,
BlockHeight: uint32(blockHeight),
BlockHash: blockHash.String(),
SyncToChain: info.SyncedToChain,
}, nil
}

Expand Down
11 changes: 9 additions & 2 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package tapcfg

import (
"context"
"crypto/rand"
"database/sql"
"encoding/binary"
"fmt"
prand "math/rand"

"github.com/btcsuite/btclog"
"github.com/lightninglabs/lndclient"
Expand Down Expand Up @@ -275,7 +276,13 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
SyncBatchSize: defaultUniverseSyncBatchSize,
})

runtimeID := prand.Int63() // nolint:gosec
var runtimeIDBytes [8]byte
_, err = rand.Read(runtimeIDBytes[:])
if err != nil {
return nil, fmt.Errorf("unable to generate runtime ID: %v", err)
}

runtimeID := int64(binary.BigEndian.Uint64(runtimeIDBytes[:]))
universeFederation := universe.NewFederationEnvoy(
universe.FederationConfig{
FederationDB: federationDB,
Expand Down
Loading

0 comments on commit c8dc6c5

Please sign in to comment.