@@ -58,6 +58,10 @@ type (
5858
5959 // UpsertUniverseSupplyLeaf is used to upsert a universe supply leaf.
6060 UpsertUniverseSupplyLeaf = sqlc.UpsertUniverseSupplyLeafParams
61+
62+ // QuerySupplyLeavesByHeightParams is used to query for supply leaves
63+ // by height.
64+ QuerySupplyLeavesByHeightParams = sqlc.QuerySupplyLeavesByHeightParams
6165)
6266
6367// BaseUniverseStore is the main interface for the Taproot Asset universe store.
@@ -128,6 +132,12 @@ type BaseUniverseStore interface {
128132 // supply tree for a given asset.
129133 UpsertUniverseSupplyRoot (ctx context.Context ,
130134 arg UpsertUniverseSupplyRoot ) (int64 , error )
135+
136+ // QuerySupplyLeavesByHeight is used to query for supply leaves by
137+ // height.
138+ QuerySupplyLeavesByHeight (ctx context.Context ,
139+ arg QuerySupplyLeavesByHeightParams ) (
140+ []sqlc.QuerySupplyLeavesByHeightRow , error )
131141}
132142
133143// getUniverseTreeSum retrieves the sum of a universe tree specified by its
@@ -570,9 +580,17 @@ func (b *BaseUniverseTree) UpsertProofLeaf(ctx context.Context,
570580 )
571581 dbErr := b .db .ExecTx (ctx , & writeTx , func (dbTx BaseUniverseStore ) error {
572582 namespace := b .id .String ()
583+
584+ // We don't need to decode the whole proof, we just need the
585+ // block height.
586+ blockHeight , err := SparseDecodeBlockHeight (leaf .RawProof )
587+ if err != nil {
588+ return err
589+ }
590+
573591 issuanceProof , err := universeUpsertProofLeaf (
574592 ctx , dbTx , namespace , b .id .ProofType .String (),
575- b .id .GroupKey , key , leaf , metaReveal ,
593+ b .id .GroupKey , key , leaf , metaReveal , blockHeight ,
576594 )
577595 if err != nil {
578596 return fmt .Errorf ("failed universe upsert: %w" , err )
@@ -701,8 +719,8 @@ func upsertMultiverseLeafEntry(ctx context.Context, dbTx BaseUniverseStore,
701719// broader DB updates.
702720func universeUpsertProofLeaf (ctx context.Context , dbTx BaseUniverseStore ,
703721 namespace string , proofTypeStr string , groupKey * btcec.PublicKey ,
704- key universe.LeafKey , leaf * universe.Leaf ,
705- metaReveal * proof. MetaReveal ) (* universe.Proof , error ) {
722+ key universe.LeafKey , leaf * universe.Leaf , metaReveal * proof. MetaReveal ,
723+ blockHeight lfn. Option [ uint32 ] ) (* universe.Proof , error ) {
706724
707725 // With the tree store created, we'll now obtain byte representation of
708726 // the minting key, as that'll be the key in the SMT itself.
@@ -773,6 +791,21 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore,
773791 return nil , err
774792 }
775793
794+ // If the block height isn't specified, then we'll attempt to extract it
795+ // from the proof itself.
796+ if blockHeight .IsNone () && leafProof .BlockHeight > 0 {
797+ blockHeight = lfn .Some (leafProof .BlockHeight )
798+ }
799+
800+ sqlBlockHeight := lfn .MapOptionZ (
801+ blockHeight , func (num uint32 ) sql.NullInt32 {
802+ return sql.NullInt32 {
803+ Int32 : int32 (num ),
804+ Valid : true ,
805+ }
806+ },
807+ )
808+
776809 scriptKey := key .LeafScriptKey ()
777810 scriptKeyBytes := schnorr .SerializePubKey (scriptKey .PubKey )
778811 err = dbTx .UpsertUniverseLeaf (ctx , UpsertUniverseLeaf {
@@ -782,6 +815,7 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore,
782815 LeafNodeKey : smtKey [:],
783816 LeafNodeNamespace : namespace ,
784817 MintingPoint : mintingPointBytes ,
818+ BlockHeight : sqlBlockHeight ,
785819 })
786820 if err != nil {
787821 return nil , err
0 commit comments