Skip to content

Commit

Permalink
WIP: universe: add RegisterIssuance to universe forest
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Jun 9, 2023
1 parent 06efc8f commit b5942f7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
36 changes: 36 additions & 0 deletions tapdb/universe_forest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/lightninglabs/taproot-assets/asset"
"github.com/lightninglabs/taproot-assets/mssmt"
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
"github.com/lightninglabs/taproot-assets/universe"
)
Expand All @@ -18,6 +19,8 @@ type (
// BaseUniverseForestStore is used to interact with a set of base universe
// roots, also known as a universe forest.
type BaseUniverseForestStore interface {
BaseUniverseStore

UniverseRoots(ctx context.Context) ([]BaseUniverseRoot, error)
}

Expand Down Expand Up @@ -125,3 +128,36 @@ func (b *BaseUniverseForest) RootNodes(

return uniRoots, nil
}

// RegisterIssuance inserts a new minting leaf within the universe
// tree, stored at the base key.
func (b *BaseUniverseForest) RegisterIssuance(ctx context.Context,
id universe.Identifier, key universe.BaseKey,
leaf *universe.MintingLeaf,
metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) {

var (
writeTx BaseUniverseStoreOptions

err error
issuanceProof *universe.IssuanceProof
)

dbErr := b.db.ExecTx(
ctx, &writeTx, func(dbTx BaseUniverseForestStore) error {
issuanceProof, err = universeRegisterIssuance(
ctx, dbTx, id, key, leaf, metaReveal,
)

// TODO(ffranr): update universe forest

return err
},
)

if dbErr != nil {
return nil, dbErr
}

return issuanceProof, nil
}
4 changes: 4 additions & 0 deletions universe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ type BaseForest interface {
// of assets tracked in the base Universe.
RootNodes(ctx context.Context) ([]BaseRoot, error)

RegisterIssuance(ctx context.Context, id Identifier, key BaseKey,
leaf *MintingLeaf,
metaReveal *proof.MetaReveal) (*IssuanceProof, error)

// TODO(roasbeef): other stats stuff here, like total number of assets, etc
// * also eventually want pull/fetch stats, can be pulled out into another instance
}
Expand Down
4 changes: 2 additions & 2 deletions universe/minting_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier,

// Now that we know the proof is valid, we'll insert it into the base
// universe backend, and return the new issuance proof.
issuanceProof, err := baseUni.RegisterIssuance(
ctx, key, leaf, assetSnapshot.MetaReveal,
issuanceProof, err := a.cfg.UniverseForest.RegisterIssuance(
ctx, id, key, leaf, assetSnapshot.MetaReveal,
)
if err != nil {
return nil, fmt.Errorf("unable to register new "+
Expand Down

0 comments on commit b5942f7

Please sign in to comment.