@@ -10,8 +10,10 @@ import (
1010 "time"
1111
1212 "github.com/btcsuite/btcd/btcec/v2"
13+ "github.com/btcsuite/btcd/chaincfg/chainhash"
1314 "github.com/btcsuite/btcd/wire"
1415 "github.com/lightninglabs/taproot-assets/asset"
16+ "github.com/lightninglabs/taproot-assets/fn"
1517 "github.com/lightninglabs/taproot-assets/mssmt"
1618 "github.com/lightninglabs/taproot-assets/proof"
1719 "github.com/lightninglabs/taproot-assets/tapdb/sqlc"
@@ -330,6 +332,41 @@ func (s *SupplyCommitMachine) SupplyCommit(ctx context.Context,
330332 err )
331333 }
332334
335+ // Parse block related data from row if present.
336+ var commitmentBlock fn.Option [supplycommit.CommitmentBlock ]
337+ if len (row .BlockHash ) > 0 {
338+ // Parse block height if present, otherwise return an
339+ // error as it must be set if block hash is set.
340+ if ! row .BlockHeight .Valid {
341+ return fmt .Errorf ("block height must be set " +
342+ "if block hash is set" )
343+ }
344+
345+ blockHeight := uint32 (row .BlockHeight .Int32 )
346+
347+ // Parse the block hash, which should be valid at this
348+ // point.
349+ blockHash , err := chainhash .NewHash (row .BlockHash )
350+ if err != nil {
351+ return fmt .Errorf ("parsing block hash: %w" , err )
352+ }
353+
354+ // Parse transaction block index which should be set
355+ // if the block height is set.
356+ if ! row .TxIndex .Valid {
357+ return fmt .Errorf ("transaction index must be " +
358+ "set if block height is set" )
359+ }
360+ txIndex := uint32 (row .TxIndex .Int32 )
361+
362+ commitmentBlock = fn .Some (supplycommit.CommitmentBlock {
363+ Hash : * blockHash ,
364+ Height : blockHeight ,
365+ TxIndex : txIndex ,
366+ ChainFees : row .ChainFees ,
367+ })
368+ }
369+
333370 // Construct the root node directly from the stored hash and
334371 // sum. Handle potential NULL values if the root wasn't set yet
335372 // (though FetchSupplyCommit filters for confirmed TX, so it
@@ -355,11 +392,12 @@ func (s *SupplyCommitMachine) SupplyCommit(ctx context.Context,
355392 }
356393
357394 rootCommitment := supplycommit.RootCommitment {
358- Txn : & commitTx ,
359- TxOutIdx : uint32 (row .OutputIndex .Int32 ),
360- InternalKey : internalKey ,
361- OutputKey : outputKey ,
362- SupplyRoot : rootNode ,
395+ Txn : & commitTx ,
396+ TxOutIdx : uint32 (row .OutputIndex .Int32 ),
397+ InternalKey : internalKey ,
398+ OutputKey : outputKey ,
399+ SupplyRoot : rootNode ,
400+ CommitmentBlock : commitmentBlock ,
363401 }
364402 rootCommitmentOpt = lfn .Some (rootCommitment )
365403
0 commit comments