Skip to content

Unit tests for mint anchor transaction pre-commitment output #1418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
70c1d2f
tapgarden: add MintingBatch.AddSeedling method
ffranr Jan 23, 2025
d65d319
tapgarden: add UniverseCommitments to MintingBatch with validation
ffranr Jan 23, 2025
7d8a471
tapgarden: set seedling delegation key during preparation
ffranr Feb 20, 2025
b71b144
tapgarden: set seedling metadata during preparation
ffranr Feb 20, 2025
c460a69
tapgarden: enforce batch-level delegation key validation
ffranr Feb 19, 2025
6af4e28
tapgarden: allow universe commitments for new minting tranches
ffranr Feb 13, 2025
53c6a96
tapgarden: fix doc: group internal key is not the default delegation key
ffranr Feb 13, 2025
2fa7fb8
proof: move SizableInteger closer to use
ffranr Feb 13, 2025
c87637b
rpcserver: remove seedling metadata validation
ffranr Feb 17, 2025
6694bab
proof: MetaReveal.Validate accounts for UniverseCommitments
ffranr Feb 17, 2025
f7a3c9a
tapgarden+tapcfg: populate chain params in ChainPlanter
ffranr Feb 4, 2025
2c069fc
tapgarden: ensure change output index is set after anchor funding
ffranr Feb 21, 2025
c8d053a
tapgarden: refactor fundGenesisPsbt to extract unfundedAnchorPsbt method
ffranr Feb 21, 2025
3625751
tapgarden: add pre-commitment output to mint anchor transaction
ffranr Feb 21, 2025
e372c2e
tapdb: modify BindMintingBatchWithTx to return batch ID
ffranr Feb 24, 2025
cecaeea
tapdb: add mint asset anchor output idx and universe commitments support
ffranr Feb 24, 2025
5fb69eb
tapgarden+tapdb: MintingBatch.GenesisPacket to FundedMintAnchorPsbt type
ffranr Feb 22, 2025
22bb6e3
tapdb: refactor BindMintingBatchWithTx into insertMintAnchorTx
ffranr Feb 25, 2025
d49576e
tapdb: add unit test for mint anchor uni commitment queries
ffranr Feb 28, 2025
74bd5d8
tapgarden: refactor fee rate calculation from fundGenesisPsbt
ffranr Mar 3, 2025
fbc9e29
tapgarden: refactor fundGenesisPsbt to pass wallet funding as closure
ffranr Mar 3, 2025
d5ac7d0
tapgarden: refactor fundGenesisPsbt to pass in pending batch
ffranr Mar 3, 2025
f62e65e
tapgarden: remove batch key argument from fundGenesisPsbt
ffranr Mar 3, 2025
01f23a0
tapgarden: call fundGenesisPsbt from RandSeedlingMintingBatch
ffranr Mar 3, 2025
8c70b0b
tapdb+tapgarden: refactor RandSeedlingMintingBatch
ffranr Mar 4, 2025
83ba31c
WIP
ffranr Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions proof/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@ type MetaReveal struct {
UnknownOddTypes tlv.TypeMap
}

// SizableInteger is a subset of Integer that excludes int8, since we never use
// it in practice.
type SizableInteger interface {
constraints.Unsigned | ~int | ~int16 | ~int32 | ~int64
}

// Validate validates the meta reveal.
func (m *MetaReveal) Validate() error {
// A meta reveal is allowed to be nil.
Expand Down Expand Up @@ -234,6 +228,13 @@ func (m *MetaReveal) Validate() error {
return err
}

// The asset metadata is invalid when the universe commitments feature
// is enabled but no delegation key is specified.
if m.UniverseCommitments && m.DelegationKey.IsNone() {
return fmt.Errorf("universe commitments enabled in asset " +
"metadata but delegation key is unspecified")
}

return fn.MapOptionZ(m.DelegationKey, func(key btcec.PublicKey) error {
if key == emptyKey {
return ErrDelegationKeyEmpty
Expand All @@ -247,6 +248,12 @@ func (m *MetaReveal) Validate() error {
})
}

// SizableInteger is a subset of Integer that excludes int8, since we never use
// it in practice.
type SizableInteger interface {
constraints.Unsigned | ~int | ~int16 | ~int32 | ~int64
}

// IsValidMetaType checks if the passed value is a valid meta type.
func IsValidMetaType[T SizableInteger](num T) (MetaType, error) {
switch {
Expand Down Expand Up @@ -288,6 +295,8 @@ func IsValidDecDisplay(decDisplay uint32) error {

// DecodeMetaJSON decodes bytes as a JSON object, after checking that the bytes
// could be valid metadata.
//
// TODO(ffranr): Add unit test for `jBytes := []byte{}`.
func DecodeMetaJSON(jBytes []byte) (map[string]interface{}, error) {
jMeta := make(map[string]interface{})

Expand Down
21 changes: 7 additions & 14 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,10 @@ func (r *rpcServer) MintAsset(ctx context.Context,
"collectibles")
}

var seedlingMeta *proof.MetaReveal
// TODO(ffranr): Move seedling MetaReveal construction into
// ChainPlanter. This will allow us to simplify delegation key
// management.
var seedlingMeta proof.MetaReveal
switch {
// If we have an explicit asset meta field, we parse the content.
case req.Asset.AssetMeta != nil:
Expand All @@ -520,7 +523,7 @@ func (r *rpcServer) MintAsset(ctx context.Context,

// If the asset meta field was specified, then the data inside
// must be valid. Let's check that now.
seedlingMeta = &proof.MetaReveal{
seedlingMeta = proof.MetaReveal{
Data: req.Asset.AssetMeta.Data,
Type: metaType,
}
Expand All @@ -542,15 +545,10 @@ func (r *rpcServer) MintAsset(ctx context.Context,
return nil, err
}

err = seedlingMeta.Validate()
if err != nil {
return nil, err
}

// If no asset meta field was specified, we create a default meta
// reveal with the decimal display set.
default:
seedlingMeta = &proof.MetaReveal{
seedlingMeta = proof.MetaReveal{
Type: proof.MetaOpaque,
}

Expand All @@ -560,11 +558,6 @@ func (r *rpcServer) MintAsset(ctx context.Context,
if err != nil {
return nil, err
}

err = seedlingMeta.Validate()
if err != nil {
return nil, err
}
}

// Parse the optional script key and group internal key. The group
Expand Down Expand Up @@ -607,7 +600,7 @@ func (r *rpcServer) MintAsset(ctx context.Context,
AssetName: req.Asset.Name,
Amount: req.Asset.Amount,
EnableEmission: req.Asset.NewGroupedAsset,
Meta: seedlingMeta,
Meta: &seedlingMeta,
UniverseCommitments: req.Asset.UniverseCommitments,
}

Expand Down
7 changes: 3 additions & 4 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,8 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
RuntimeID: runtimeID,
EnableChannelFeatures: enableChannelFeatures,
Lnd: lndServices,
ChainParams: address.ParamsForChain(
cfg.ActiveNetParams.Name,
),
ReOrgWatcher: reOrgWatcher,
ChainParams: tapChainParams,
ReOrgWatcher: reOrgWatcher,
AssetMinter: tapgarden.NewChainPlanter(tapgarden.PlanterConfig{
GardenKit: tapgarden.GardenKit{
Wallet: walletAnchor,
Expand All @@ -553,6 +551,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
ProofWatcher: reOrgWatcher,
UniversePushBatchSize: defaultUniverseSyncBatchSize,
},
ChainParams: tapChainParams,
ProofUpdates: proofArchive,
ErrChan: mainErrChan,
}),
Expand Down
Loading
Loading