1355271011
- Only syncs block headers (excludes block bodies, transactions, receipts, and logs) - Modifies validation window to include the most recent block - Isolates validation window to the variable defined in the cmd directory (blocks have a separate variable defined in the block_repository for determining when to set a block as final)
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package common
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
"strings"
|
|
)
|
|
|
|
type BlockConverter struct {
|
|
transactionConverter TransactionConverter
|
|
}
|
|
|
|
func NewBlockConverter(transactionConverter TransactionConverter) BlockConverter {
|
|
return BlockConverter{transactionConverter: transactionConverter}
|
|
}
|
|
|
|
func (bc BlockConverter) ToCoreBlock(gethBlock *types.Block) (core.Block, error) {
|
|
transactions, err := bc.transactionConverter.ConvertTransactionsToCore(gethBlock)
|
|
if err != nil {
|
|
return core.Block{}, err
|
|
}
|
|
|
|
coreBlock := core.Block{
|
|
Difficulty: gethBlock.Difficulty().Int64(),
|
|
ExtraData: hexutil.Encode(gethBlock.Extra()),
|
|
GasLimit: gethBlock.GasLimit(),
|
|
GasUsed: gethBlock.GasUsed(),
|
|
Hash: gethBlock.Hash().Hex(),
|
|
Miner: strings.ToLower(gethBlock.Coinbase().Hex()),
|
|
Nonce: hexutil.Encode(gethBlock.Header().Nonce[:]),
|
|
Number: gethBlock.Number().Int64(),
|
|
ParentHash: gethBlock.ParentHash().Hex(),
|
|
Size: gethBlock.Size().String(),
|
|
Time: gethBlock.Time().Int64(),
|
|
Transactions: transactions,
|
|
UncleHash: gethBlock.UncleHash().Hex(),
|
|
}
|
|
coreBlock.Reward = CalcBlockReward(coreBlock, gethBlock.Uncles())
|
|
coreBlock.UnclesReward = CalcUnclesReward(coreBlock, gethBlock.Uncles())
|
|
return coreBlock, nil
|
|
}
|