4
4
"context"
5
5
"crypto/sha256"
6
6
"fmt"
7
+ "net/url"
7
8
8
9
"github.com/btcsuite/btcd/btcec/v2"
9
10
"github.com/btcsuite/btcd/btcutil"
@@ -100,6 +101,39 @@ type SupplyLeaves struct {
100
101
IgnoreLeafEntries []NewIgnoreEvent
101
102
}
102
103
104
+ // NewSupplyLeavesFromEvents creates a SupplyLeaves instance from a slice of
105
+ // SupplyUpdateEvent instances.
106
+ func NewSupplyLeavesFromEvents (events []SupplyUpdateEvent ) (SupplyLeaves ,
107
+ error ) {
108
+
109
+ var leaves SupplyLeaves
110
+ for idx := range events {
111
+ event := events [idx ]
112
+
113
+ switch e := event .(type ) {
114
+ case * NewMintEvent :
115
+ leaves .IssuanceLeafEntries = append (
116
+ leaves .IssuanceLeafEntries , * e ,
117
+ )
118
+
119
+ case * NewBurnEvent :
120
+ leaves .BurnLeafEntries = append (
121
+ leaves .BurnLeafEntries , * e ,
122
+ )
123
+
124
+ case * NewIgnoreEvent :
125
+ leaves .IgnoreLeafEntries = append (
126
+ leaves .IgnoreLeafEntries , * e ,
127
+ )
128
+
129
+ default :
130
+ return leaves , fmt .Errorf ("unknown event type: %T" , e )
131
+ }
132
+ }
133
+
134
+ return leaves , nil
135
+ }
136
+
103
137
// AssetLookup is an interface that allows us to query for asset
104
138
// information, such as asset groups and asset metadata.
105
139
type AssetLookup interface {
@@ -498,6 +532,17 @@ type StateMachineStore interface {
498
532
asset.Specifier ) ([]SupplyUpdateEvent , error )
499
533
}
500
534
535
+ // SupplySyncer is an interface that allows the state machine to insert
536
+ // supply commitments into the remote universe server.
537
+ type SupplySyncer interface {
538
+ // PushSupplyCommitment pushes a supply commitment to the remote
539
+ // universe server. This function should block until the sync insertion
540
+ // is complete.
541
+ PushSupplyCommitment (ctx context.Context , assetSpec asset.Specifier ,
542
+ commitment RootCommitment , updateLeaves SupplyLeaves ,
543
+ chainProof ChainProof , canonicalUniverses []url.URL ) error
544
+ }
545
+
501
546
// Environment is a set of dependencies that a state machine may need to carry
502
547
// out the logic for a given state transition. All fields are to be considered
503
548
// immutable, and will be fixed for the lifetime of the state machine.
@@ -518,6 +563,10 @@ type Environment struct {
518
563
// Wallet is the main wallet interface used to managed PSBT packets.
519
564
Wallet Wallet
520
565
566
+ // AssetLookup is used to look up asset information such as asset groups
567
+ // and asset metadata.
568
+ AssetLookup AssetLookup
569
+
521
570
// KeyRing is the main key ring interface used to manage keys.
522
571
KeyRing KeyRing
523
572
@@ -526,6 +575,10 @@ type Environment struct {
526
575
// TODO(roasbeef): can make a slimmer version of
527
576
Chain tapgarden.ChainBridge
528
577
578
+ // SupplySyncer is used to insert supply commitments into the remote
579
+ // universe server.
580
+ SupplySyncer SupplySyncer
581
+
529
582
// StateLog is the main state log that is used to track the state of the
530
583
// state machine. This is used to persist the state of the state machine
531
584
// across restarts.
0 commit comments