Skip to content

Commit f4f9de7

Browse files
committed
tapcfg: add SupplyCommitManager field to config for RPC access
Populate the SupplyCommitManager field in the config so that the rpcserver can invoke methods on the supply commitment manager.
1 parent 3209e1e commit f4f9de7

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/taproot-assets/tapfreighter"
1818
"github.com/lightninglabs/taproot-assets/tapgarden"
1919
"github.com/lightninglabs/taproot-assets/universe"
20+
"github.com/lightninglabs/taproot-assets/universe/supplycommit"
2021
"github.com/lightningnetwork/lnd"
2122
"github.com/lightningnetwork/lnd/build"
2223
"github.com/lightningnetwork/lnd/signal"
@@ -186,6 +187,11 @@ type Config struct {
186187

187188
ChainPorter tapfreighter.Porter
188189

190+
// SupplyCommitManager is a service that is used to manage supply
191+
// commitments for assets. Supply commitments are issuer published
192+
// attestations of the total supply of an asset.
193+
SupplyCommitManager *supplycommit.MultiStateMachineManager
194+
189195
UniverseArchive *universe.Archive
190196

191197
UniverseSyncer universe.Syncer

server.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ func (s *Server) initialize(interceptorChain *rpcperms.InterceptorChain) error {
211211
return fmt.Errorf("unable to start RFQ manager: %w", err)
212212
}
213213

214+
// Start universe supply commitment manager.
215+
if err := s.cfg.SupplyCommitManager.Start(); err != nil {
216+
return fmt.Errorf("unable to start supply commit manager: %w",
217+
err)
218+
}
219+
214220
// Start the auxiliary components.
215221
if err := s.cfg.AuxLeafSigner.Start(); err != nil {
216222
return fmt.Errorf("unable to start aux leaf signer: %w", err)
@@ -691,6 +697,12 @@ func (s *Server) Stop() error {
691697
return err
692698
}
693699

700+
// Stop universe supply commitment manager.
701+
if err := s.cfg.SupplyCommitManager.Stop(); err != nil {
702+
return fmt.Errorf("unable to stop supply commit manager: %w",
703+
err)
704+
}
705+
694706
if err := s.cfg.AuxLeafSigner.Stop(); err != nil {
695707
return err
696708
}

tapcfg/server.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/lightninglabs/taproot-assets/tapgarden"
2424
"github.com/lightninglabs/taproot-assets/tapscript"
2525
"github.com/lightninglabs/taproot-assets/universe"
26+
"github.com/lightninglabs/taproot-assets/universe/supplycommit"
2627
"github.com/lightningnetwork/lnd"
2728
"github.com/lightningnetwork/lnd/clock"
2829
"github.com/lightningnetwork/lnd/signal"
@@ -161,6 +162,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
161162
groupVerifier := tapgarden.GenGroupVerifier(
162163
context.Background(), assetMintingStore,
163164
)
165+
164166
uniArchiveCfg := universe.ArchiveConfig{
165167
// nolint: lll
166168
NewBaseTree: func(id universe.Identifier) universe.StorageBackend {
@@ -583,6 +585,38 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
583585
"access status: %w", err)
584586
}
585587

588+
// Construct the supply commit manager, which is used to
589+
// formulate universe supply commitment transactions.
590+
//
591+
// Construct database backends for the supply commitment state machines.
592+
supplyCommitDb := tapdb.NewTransactionExecutor(
593+
db, func(tx *sql.Tx) tapdb.SupplyCommitStore {
594+
return db.WithTx(tx)
595+
},
596+
)
597+
supplyCommitStore := tapdb.NewSupplyCommitMachine(supplyCommitDb)
598+
599+
// Construct the supply tree database backend.
600+
supplyTreeDb := tapdb.NewTransactionExecutor(
601+
db, func(tx *sql.Tx) tapdb.BaseUniverseStore {
602+
return db.WithTx(tx)
603+
},
604+
)
605+
supplyTreeStore := tapdb.NewSupplyTreeStore(supplyTreeDb)
606+
607+
// Create the supply commitment state machine manager, which is used to
608+
// manage the supply commitment state machines for each asset group.
609+
supplyCommitManager := supplycommit.NewMultiStateMachineManager(
610+
supplycommit.MultiStateMachineManagerCfg{
611+
TreeView: supplyTreeStore,
612+
Commitments: supplyCommitStore,
613+
Wallet: walletAnchor,
614+
KeyRing: keyRing,
615+
Chain: chainBridge,
616+
StateLog: supplyCommitStore,
617+
},
618+
)
619+
586620
return &tap.Config{
587621
DebugLevel: cfg.DebugLevel,
588622
RuntimeID: runtimeID,
@@ -633,6 +667,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
633667
AssetWallet: assetWallet,
634668
CoinSelect: coinSelect,
635669
ChainPorter: chainPorter,
670+
SupplyCommitManager: supplyCommitManager,
636671
UniverseArchive: uniArchive,
637672
UniverseSyncer: universeSyncer,
638673
UniverseFederation: universeFederation,

0 commit comments

Comments
 (0)