Add ability to populate missing blocks
* The command populates up to the highest known block number
* The anticipated use case is that the listener will be running
in parallel to the populateBlocks command
* This will mean that the listener is responsible for picking up
new blocks, and the populateBlocks command is reposible for
historical blocks
* Reformat SQL statements
This commit is contained in:
@@ -3,6 +3,8 @@ package geth
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"math/big"
|
||||
|
||||
"github.com/8thlight/vulcanizedb/pkg/core"
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
@@ -17,6 +19,11 @@ type GethBlockchain struct {
|
||||
newHeadSubscription ethereum.Subscription
|
||||
}
|
||||
|
||||
func (blockchain *GethBlockchain) GetBlockByNumber(blockNumber int64) core.Block {
|
||||
gethBlock, _ := blockchain.client.BlockByNumber(context.Background(), big.NewInt(blockNumber))
|
||||
return GethBlockToCoreBlock(gethBlock)
|
||||
}
|
||||
|
||||
func NewGethBlockchain(ipcPath string) *GethBlockchain {
|
||||
fmt.Printf("Creating Geth Blockchain to: %s\n", ipcPath)
|
||||
blockchain := GethBlockchain{}
|
||||
@@ -36,10 +43,8 @@ func (blockchain *GethBlockchain) SubscribeToBlocks(blocks chan core.Block) {
|
||||
}
|
||||
|
||||
func (blockchain *GethBlockchain) StartListening() {
|
||||
myContext := context.Background()
|
||||
for header := range blockchain.readGethHeaders {
|
||||
gethBlock, _ := blockchain.client.BlockByNumber(myContext, header.Number)
|
||||
block := GethBlockToCoreBlock(gethBlock)
|
||||
block := blockchain.GetBlockByNumber(header.Number.Int64())
|
||||
blockchain.outputBlocks <- block
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user