Skip to content

Commit

Permalink
Merge pull request #103 from DefiantLabs/pharr117/indexed-block-added…
Browse files Browse the repository at this point in the history
…-to-post-dataset

feat/Add block with chain attached to the indexed dataset for easier access
  • Loading branch information
pharr117 authored May 8, 2024
2 parents 2c29f98 + c334e60 commit 77398c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func IndexNewBlock(db *gorm.DB, block models.Block, txs []TxDBWrapper, indexerCo
block.ProposerConsAddress = consAddress
block.TxIndexed = true
if err := dbTransaction.
Preload("Chain").
Where(models.Block{Height: block.Height, ChainID: block.ChainID}).
Assign(models.Block{TxIndexed: true, TimeStamp: block.TimeStamp}).
FirstOrCreate(&block).Error; err != nil {
Expand Down
9 changes: 7 additions & 2 deletions indexer/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ func (indexer *Indexer) DoDBUpdates(wg *sync.WaitGroup, txDataChan chan *DBData,
dbWrites++
// While debugging we'll sometimes want to turn off INSERTS to the DB
// Note that this does not turn off certain reads or DB connections.
indexedBlock := data.block
indexedDataset := data.txDBWrappers

if !indexer.DryRun {
var err error
config.Log.Info(fmt.Sprintf("Indexing %v TXs from block %d", len(data.txDBWrappers), data.block.Height))
_, indexedDataset, err := dbTypes.IndexNewBlock(indexer.DB, data.block, data.txDBWrappers, *indexer.Config)
indexedBlock, indexedDataset, err = dbTypes.IndexNewBlock(indexer.DB, data.block, data.txDBWrappers, *indexer.Config)
if err != nil {
// Do a single reattempt on failure
dbReattempts++
Expand Down Expand Up @@ -67,8 +71,9 @@ func (indexer *Indexer) DoDBUpdates(wg *sync.WaitGroup, txDataChan chan *DBData,
Config: *indexer.Config,
DB: indexer.DB,
DryRun: indexer.DryRun,
IndexedDataset: &data.txDBWrappers,
IndexedDataset: &indexedDataset,
MessageParser: indexer.CustomMessageParserTrackers,
IndexedBlock: indexedBlock,
}

err := indexer.PostIndexCustomMessageFunction(dataset)
Expand Down
1 change: 1 addition & 0 deletions indexer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type PostIndexCustomMessageDataset struct {
DryRun bool
IndexedDataset *[]dbTypes.TxDBWrapper
MessageParser map[string]models.MessageParser
IndexedBlock models.Block
}

type Indexer struct {
Expand Down

0 comments on commit 77398c3

Please sign in to comment.