forked from cerc-io/ipld-eth-server
review fixes
This commit is contained in:
parent
197f98c93d
commit
5dcf534b2c
@ -3,15 +3,15 @@ CREATE TABLE public.blocks (
|
|||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
difficulty BIGINT,
|
difficulty BIGINT,
|
||||||
extra_data VARCHAR,
|
extra_data VARCHAR,
|
||||||
gaslimit BIGINT,
|
gas_limit BIGINT,
|
||||||
gasused BIGINT,
|
gas_used BIGINT,
|
||||||
hash VARCHAR(66),
|
hash VARCHAR(66),
|
||||||
miner VARCHAR(42),
|
miner VARCHAR(42),
|
||||||
nonce VARCHAR(20),
|
nonce VARCHAR(20),
|
||||||
"number" BIGINT,
|
"number" BIGINT,
|
||||||
parenthash VARCHAR(66),
|
parent_hash VARCHAR(66),
|
||||||
reward DOUBLE PRECISION,
|
reward NUMERIC,
|
||||||
uncles_reward DOUBLE PRECISION,
|
uncles_reward NUMERIC,
|
||||||
"size" VARCHAR,
|
"size" VARCHAR,
|
||||||
"time" BIGINT,
|
"time" BIGINT,
|
||||||
is_final BOOLEAN,
|
is_final BOOLEAN,
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
CREATE TABLE full_sync_transactions (
|
CREATE TABLE full_sync_transactions (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
block_id INTEGER NOT NULL REFERENCES blocks(id) ON DELETE CASCADE,
|
block_id INTEGER NOT NULL REFERENCES blocks(id) ON DELETE CASCADE,
|
||||||
gaslimit NUMERIC,
|
gas_limit NUMERIC,
|
||||||
gasprice NUMERIC,
|
gas_price NUMERIC,
|
||||||
hash VARCHAR(66),
|
hash VARCHAR(66),
|
||||||
input_data BYTEA,
|
input_data BYTEA,
|
||||||
nonce NUMERIC,
|
nonce NUMERIC,
|
||||||
|
@ -5,11 +5,8 @@ CREATE TABLE public.headers (
|
|||||||
block_number BIGINT,
|
block_number BIGINT,
|
||||||
raw JSONB,
|
raw JSONB,
|
||||||
block_timestamp NUMERIC,
|
block_timestamp NUMERIC,
|
||||||
eth_node_id INTEGER,
|
eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE,
|
||||||
eth_node_fingerprint VARCHAR(128),
|
eth_node_fingerprint VARCHAR(128)
|
||||||
CONSTRAINT eth_nodes_fk FOREIGN KEY (eth_node_id)
|
|
||||||
REFERENCES eth_nodes (id)
|
|
||||||
ON DELETE CASCADE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Index is removed when table is
|
-- Index is removed when table is
|
||||||
|
@ -3,8 +3,8 @@ CREATE TABLE light_sync_transactions (
|
|||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
header_id INTEGER NOT NULL REFERENCES headers(id) ON DELETE CASCADE,
|
header_id INTEGER NOT NULL REFERENCES headers(id) ON DELETE CASCADE,
|
||||||
hash TEXT,
|
hash TEXT,
|
||||||
gaslimit NUMERIC,
|
gas_limit NUMERIC,
|
||||||
gasprice NUMERIC,
|
gas_price NUMERIC,
|
||||||
input_data BYTEA,
|
input_data BYTEA,
|
||||||
nonce NUMERIC,
|
nonce NUMERIC,
|
||||||
raw BYTEA,
|
raw BYTEA,
|
||||||
|
@ -3,16 +3,12 @@ CREATE TABLE public.uncles (
|
|||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
hash VARCHAR(66) NOT NULL,
|
hash VARCHAR(66) NOT NULL,
|
||||||
block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE,
|
block_id INTEGER NOT NULL REFERENCES blocks (id) ON DELETE CASCADE,
|
||||||
block_hash VARCHAR(66) NOT NULL,
|
|
||||||
reward NUMERIC NOT NULL,
|
reward NUMERIC NOT NULL,
|
||||||
miner VARCHAR(42) NOT NULL,
|
miner VARCHAR(42) NOT NULL,
|
||||||
raw JSONB,
|
raw JSONB,
|
||||||
block_timestamp NUMERIC,
|
block_timestamp NUMERIC,
|
||||||
eth_node_id INTEGER,
|
eth_node_id INTEGER NOT NULL REFERENCES eth_nodes (id) ON DELETE CASCADE,
|
||||||
eth_node_fingerprint VARCHAR(128),
|
eth_node_fingerprint VARCHAR(128),
|
||||||
CONSTRAINT eth_nodes_fk FOREIGN KEY (eth_node_id)
|
|
||||||
REFERENCES eth_nodes (id)
|
|
||||||
ON DELETE CASCADE,
|
|
||||||
UNIQUE (block_id, hash)
|
UNIQUE (block_id, hash)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
-- +goose Up
|
|
||||||
ALTER TABLE blocks
|
|
||||||
ALTER COLUMN uncles_reward TYPE NUMERIC USING uncles_reward::NUMERIC,
|
|
||||||
ALTER COLUMN reward TYPE NUMERIC USING reward::NUMERIC;
|
|
||||||
|
|
||||||
-- +goose Down
|
|
||||||
ALTER TABLE blocks
|
|
||||||
ALTER COLUMN uncles_reward TYPE DOUBLE PRECISION USING uncles_reward::DOUBLE PRECISION,
|
|
||||||
ALTER COLUMN reward TYPE DOUBLE PRECISION USING reward::DOUBLE PRECISION;
|
|
@ -20,14 +20,14 @@ type Block struct {
|
|||||||
Reward string `db:"reward"`
|
Reward string `db:"reward"`
|
||||||
Difficulty int64 `db:"difficulty"`
|
Difficulty int64 `db:"difficulty"`
|
||||||
ExtraData string `db:"extra_data"`
|
ExtraData string `db:"extra_data"`
|
||||||
GasLimit uint64 `db:"gaslimit"`
|
GasLimit uint64 `db:"gas_limit"`
|
||||||
GasUsed uint64 `db:"gasused"`
|
GasUsed uint64 `db:"gas_used"`
|
||||||
Hash string `db:"hash"`
|
Hash string `db:"hash"`
|
||||||
IsFinal bool `db:"is_final"`
|
IsFinal bool `db:"is_final"`
|
||||||
Miner string `db:"miner"`
|
Miner string `db:"miner"`
|
||||||
Nonce string `db:"nonce"`
|
Nonce string `db:"nonce"`
|
||||||
Number int64 `db:"number"`
|
Number int64 `db:"number"`
|
||||||
ParentHash string `db:"parenthash"`
|
ParentHash string `db:"parent_hash"`
|
||||||
Size string `db:"size"`
|
Size string `db:"size"`
|
||||||
Time int64 `db:"time"`
|
Time int64 `db:"time"`
|
||||||
Transactions []TransactionModel
|
Transactions []TransactionModel
|
||||||
|
@ -19,8 +19,8 @@ package core
|
|||||||
type TransactionModel struct {
|
type TransactionModel struct {
|
||||||
Data []byte `db:"input_data"`
|
Data []byte `db:"input_data"`
|
||||||
From string `db:"tx_from"`
|
From string `db:"tx_from"`
|
||||||
GasLimit uint64
|
GasLimit uint64 `db:"gas_limit"`
|
||||||
GasPrice int64
|
GasPrice int64 `db:"gas_price"`
|
||||||
Hash string
|
Hash string
|
||||||
Nonce uint64
|
Nonce uint64
|
||||||
Raw []byte
|
Raw []byte
|
||||||
|
@ -19,7 +19,6 @@ package core
|
|||||||
type Uncle struct {
|
type Uncle struct {
|
||||||
Id int64
|
Id int64
|
||||||
Miner string
|
Miner string
|
||||||
BlockHash string `db:"block_hash"`
|
|
||||||
Reward string
|
Reward string
|
||||||
Hash string
|
Hash string
|
||||||
Timestamp string `db:"block_timestamp"`
|
Timestamp string `db:"block_timestamp"`
|
||||||
|
@ -90,13 +90,13 @@ func (blockRepository BlockRepository) GetBlock(blockNumber int64) (core.Block,
|
|||||||
blockRows := blockRepository.database.QueryRowx(
|
blockRows := blockRepository.database.QueryRowx(
|
||||||
`SELECT id,
|
`SELECT id,
|
||||||
number,
|
number,
|
||||||
gaslimit,
|
gas_limit,
|
||||||
gasused,
|
gas_used,
|
||||||
time,
|
time,
|
||||||
difficulty,
|
difficulty,
|
||||||
hash,
|
hash,
|
||||||
nonce,
|
nonce,
|
||||||
parenthash,
|
parent_hash,
|
||||||
size,
|
size,
|
||||||
uncle_hash,
|
uncle_hash,
|
||||||
is_final,
|
is_final,
|
||||||
@ -127,7 +127,7 @@ func (blockRepository BlockRepository) insertBlock(block core.Block) (int64, err
|
|||||||
}
|
}
|
||||||
insertBlockErr := tx.QueryRow(
|
insertBlockErr := tx.QueryRow(
|
||||||
`INSERT INTO blocks
|
`INSERT INTO blocks
|
||||||
(eth_node_id, number, gaslimit, gasused, time, difficulty, hash, nonce, parenthash, size, uncle_hash, is_final, miner, extra_data, reward, uncles_reward, eth_node_fingerprint)
|
(eth_node_id, number, gas_limit, gas_used, time, difficulty, hash, nonce, parent_hash, size, uncle_hash, is_final, miner, extra_data, reward, uncles_reward, eth_node_fingerprint)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
||||||
RETURNING id `,
|
RETURNING id `,
|
||||||
blockRepository.database.NodeID,
|
blockRepository.database.NodeID,
|
||||||
@ -196,10 +196,10 @@ func (blockRepository BlockRepository) createUncles(tx *sqlx.Tx, blockId int64,
|
|||||||
func (blockRepository BlockRepository) createUncle(tx *sqlx.Tx, blockId int64, uncle core.Uncle) error {
|
func (blockRepository BlockRepository) createUncle(tx *sqlx.Tx, blockId int64, uncle core.Uncle) error {
|
||||||
_, err := tx.Exec(
|
_, err := tx.Exec(
|
||||||
`INSERT INTO uncles
|
`INSERT INTO uncles
|
||||||
(hash, block_id, block_hash, reward, miner, raw, block_timestamp, eth_node_id, eth_node_fingerprint)
|
(hash, block_id, reward, miner, raw, block_timestamp, eth_node_id, eth_node_fingerprint)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7::NUMERIC, $8, $9)
|
VALUES ($1, $2, $3, $4, $5, $6, $7::NUMERIC, $8)
|
||||||
RETURNING id`,
|
RETURNING id`,
|
||||||
uncle.Hash, blockId, uncle.BlockHash, utilities.NullToZero(uncle.Reward), uncle.Miner, uncle.Raw, uncle.Timestamp, blockRepository.database.NodeID, blockRepository.database.Node.ID)
|
uncle.Hash, blockId, utilities.NullToZero(uncle.Reward), uncle.Miner, uncle.Raw, uncle.Timestamp, blockRepository.database.NodeID, blockRepository.database.Node.ID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ func nullStringToZero(s string) string {
|
|||||||
func (blockRepository BlockRepository) createTransaction(tx *sqlx.Tx, blockId int64, transaction core.TransactionModel) error {
|
func (blockRepository BlockRepository) createTransaction(tx *sqlx.Tx, blockId int64, transaction core.TransactionModel) error {
|
||||||
_, err := tx.Exec(
|
_, err := tx.Exec(
|
||||||
`INSERT INTO full_sync_transactions
|
`INSERT INTO full_sync_transactions
|
||||||
(block_id, gaslimit, gasprice, hash, input_data, nonce, raw, tx_from, tx_index, tx_to, "value")
|
(block_id, gas_limit, gas_price, hash, input_data, nonce, raw, tx_from, tx_index, tx_to, "value")
|
||||||
VALUES ($1, $2::NUMERIC, $3::NUMERIC, $4, $5, $6::NUMERIC, $7, $8, $9::NUMERIC, $10, $11::NUMERIC)
|
VALUES ($1, $2::NUMERIC, $3::NUMERIC, $4, $5, $6::NUMERIC, $7, $8, $9::NUMERIC, $10, $11::NUMERIC)
|
||||||
RETURNING id`, blockId, transaction.GasLimit, transaction.GasPrice, transaction.Hash, transaction.Data,
|
RETURNING id`, blockId, transaction.GasLimit, transaction.GasPrice, transaction.Hash, transaction.Data,
|
||||||
transaction.Nonce, transaction.Raw, transaction.From, transaction.TxIndex, transaction.To, nullStringToZero(transaction.Value))
|
transaction.Nonce, transaction.Raw, transaction.From, transaction.TxIndex, transaction.To, nullStringToZero(transaction.Value))
|
||||||
@ -325,8 +325,8 @@ func (blockRepository BlockRepository) loadBlock(blockRows *sqlx.Row) (core.Bloc
|
|||||||
}
|
}
|
||||||
transactionRows, err := blockRepository.database.Queryx(`
|
transactionRows, err := blockRepository.database.Queryx(`
|
||||||
SELECT hash,
|
SELECT hash,
|
||||||
gaslimit,
|
gas_limit,
|
||||||
gasprice,
|
gas_price,
|
||||||
input_data,
|
input_data,
|
||||||
nonce,
|
nonce,
|
||||||
raw,
|
raw,
|
||||||
|
@ -176,7 +176,7 @@ var _ = Describe("Saving blocks", func() {
|
|||||||
Expect(savedBlock.UnclesReward).To(Equal(big.NewInt(0).Div(big.NewInt(5000000000000000000), big.NewInt(32)).String()))
|
Expect(savedBlock.UnclesReward).To(Equal(big.NewInt(0).Div(big.NewInt(5000000000000000000), big.NewInt(32)).String()))
|
||||||
|
|
||||||
var uncleModel core.Uncle
|
var uncleModel core.Uncle
|
||||||
err := db.Get(&uncleModel, `SELECT hash, block_hash, reward, miner, raw, block_timestamp FROM uncles
|
err := db.Get(&uncleModel, `SELECT hash, reward, miner, raw, block_timestamp FROM uncles
|
||||||
WHERE block_id = $1 AND hash = $2`, id, common.BytesToHash([]byte{1, 2, 3}).Hex())
|
WHERE block_id = $1 AND hash = $2`, id, common.BytesToHash([]byte{1, 2, 3}).Hex())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(uncleModel.Hash).To(Equal(common.BytesToHash([]byte{1, 2, 3}).Hex()))
|
Expect(uncleModel.Hash).To(Equal(common.BytesToHash([]byte{1, 2, 3}).Hex()))
|
||||||
@ -185,7 +185,7 @@ var _ = Describe("Saving blocks", func() {
|
|||||||
Expect(uncleModel.Timestamp).To(Equal("111111111"))
|
Expect(uncleModel.Timestamp).To(Equal("111111111"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("saves one uncle associated to the block", func() {
|
It("saves two uncles associated to the block", func() {
|
||||||
block := core.Block{
|
block := core.Block{
|
||||||
Hash: fakes.FakeHash.String(),
|
Hash: fakes.FakeHash.String(),
|
||||||
Number: 123,
|
Number: 123,
|
||||||
@ -207,7 +207,7 @@ var _ = Describe("Saving blocks", func() {
|
|||||||
Expect(savedBlock.UnclesReward).To(Equal(big.NewInt(0).Div(b, big.NewInt(32)).String()))
|
Expect(savedBlock.UnclesReward).To(Equal(big.NewInt(0).Div(b, big.NewInt(32)).String()))
|
||||||
|
|
||||||
var uncleModel core.Uncle
|
var uncleModel core.Uncle
|
||||||
err := db.Get(&uncleModel, `SELECT hash, block_hash, reward, miner, raw, block_timestamp FROM uncles
|
err := db.Get(&uncleModel, `SELECT hash, reward, miner, raw, block_timestamp FROM uncles
|
||||||
WHERE block_id = $1 AND hash = $2`, id, common.BytesToHash([]byte{1, 2, 3}).Hex())
|
WHERE block_id = $1 AND hash = $2`, id, common.BytesToHash([]byte{1, 2, 3}).Hex())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(uncleModel.Hash).To(Equal(common.BytesToHash([]byte{1, 2, 3}).Hex()))
|
Expect(uncleModel.Hash).To(Equal(common.BytesToHash([]byte{1, 2, 3}).Hex()))
|
||||||
@ -215,7 +215,7 @@ var _ = Describe("Saving blocks", func() {
|
|||||||
Expect(uncleModel.Miner).To(Equal(fakes.FakeAddress.Hex()))
|
Expect(uncleModel.Miner).To(Equal(fakes.FakeAddress.Hex()))
|
||||||
Expect(uncleModel.Timestamp).To(Equal("111111111"))
|
Expect(uncleModel.Timestamp).To(Equal("111111111"))
|
||||||
|
|
||||||
err = db.Get(&uncleModel, `SELECT hash, block_hash, reward, miner, raw, block_timestamp FROM uncles
|
err = db.Get(&uncleModel, `SELECT hash, reward, miner, raw, block_timestamp FROM uncles
|
||||||
WHERE block_id = $1 AND hash = $2`, id, common.BytesToHash([]byte{3, 2, 1}).Hex())
|
WHERE block_id = $1 AND hash = $2`, id, common.BytesToHash([]byte{3, 2, 1}).Hex())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(uncleModel.Hash).To(Equal(common.BytesToHash([]byte{3, 2, 1}).Hex()))
|
Expect(uncleModel.Hash).To(Equal(common.BytesToHash([]byte{3, 2, 1}).Hex()))
|
||||||
|
@ -82,8 +82,8 @@ func (contractRepository ContractRepository) addTransactions(contract core.Contr
|
|||||||
nonce,
|
nonce,
|
||||||
tx_to,
|
tx_to,
|
||||||
tx_from,
|
tx_from,
|
||||||
gaslimit,
|
gas_limit,
|
||||||
gasprice,
|
gas_price,
|
||||||
value,
|
value,
|
||||||
input_data
|
input_data
|
||||||
FROM full_sync_transactions
|
FROM full_sync_transactions
|
||||||
|
@ -52,7 +52,7 @@ func (repository HeaderRepository) CreateOrUpdateHeader(header core.Header) (int
|
|||||||
func (repository HeaderRepository) CreateTransactions(headerID int64, transactions []core.TransactionModel) error {
|
func (repository HeaderRepository) CreateTransactions(headerID int64, transactions []core.TransactionModel) error {
|
||||||
for _, transaction := range transactions {
|
for _, transaction := range transactions {
|
||||||
_, err := repository.database.Exec(`INSERT INTO public.light_sync_transactions
|
_, err := repository.database.Exec(`INSERT INTO public.light_sync_transactions
|
||||||
(header_id, hash, gaslimit, gasprice, input_data, nonce, raw, tx_from, tx_index, tx_to, "value")
|
(header_id, hash, gas_limit, gas_price, input_data, nonce, raw, tx_from, tx_index, tx_to, "value")
|
||||||
VALUES ($1, $2, $3::NUMERIC, $4::NUMERIC, $5, $6::NUMERIC, $7, $8, $9::NUMERIC, $10, $11::NUMERIC)
|
VALUES ($1, $2, $3::NUMERIC, $4::NUMERIC, $5, $6::NUMERIC, $7, $8, $9::NUMERIC, $10, $11::NUMERIC)
|
||||||
ON CONFLICT DO NOTHING`, headerID, transaction.Hash, transaction.GasLimit, transaction.GasPrice,
|
ON CONFLICT DO NOTHING`, headerID, transaction.Hash, transaction.GasLimit, transaction.GasPrice,
|
||||||
transaction.Data, transaction.Nonce, transaction.Raw, transaction.From, transaction.TxIndex, transaction.To,
|
transaction.Data, transaction.Nonce, transaction.Raw, transaction.From, transaction.TxIndex, transaction.To,
|
||||||
|
@ -226,7 +226,7 @@ var _ = Describe("Block header repository", func() {
|
|||||||
It("adds transactions", func() {
|
It("adds transactions", func() {
|
||||||
var dbTransactions []core.TransactionModel
|
var dbTransactions []core.TransactionModel
|
||||||
err = db.Select(&dbTransactions,
|
err = db.Select(&dbTransactions,
|
||||||
`SELECT hash, gaslimit, gasprice, input_data, nonce, raw, tx_from, tx_index, tx_to, "value"
|
`SELECT hash, gas_limit, gas_price, input_data, nonce, raw, tx_from, tx_index, tx_to, "value"
|
||||||
FROM public.light_sync_transactions WHERE header_id = $1`, headerID)
|
FROM public.light_sync_transactions WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(dbTransactions).To(ConsistOf(transactions))
|
Expect(dbTransactions).To(ConsistOf(transactions))
|
||||||
@ -238,7 +238,7 @@ var _ = Describe("Block header repository", func() {
|
|||||||
|
|
||||||
var dbTransactions []core.TransactionModel
|
var dbTransactions []core.TransactionModel
|
||||||
err = db.Select(&dbTransactions,
|
err = db.Select(&dbTransactions,
|
||||||
`SELECT hash, gaslimit, gasprice, input_data, nonce, raw, tx_from, tx_index, tx_to, "value"
|
`SELECT hash, gas_limit, gas_price, input_data, nonce, raw, tx_from, tx_index, tx_to, "value"
|
||||||
FROM public.light_sync_transactions WHERE header_id = $1`, headerID)
|
FROM public.light_sync_transactions WHERE header_id = $1`, headerID)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(dbTransactions)).To(Equal(2))
|
Expect(len(dbTransactions)).To(Equal(2))
|
||||||
|
@ -94,7 +94,6 @@ func GetFakeUncle(hash, reward string) core.Uncle {
|
|||||||
return core.Uncle{
|
return core.Uncle{
|
||||||
Miner: FakeAddress.String(),
|
Miner: FakeAddress.String(),
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
BlockHash: FakeHash.String(),
|
|
||||||
Reward: reward,
|
Reward: reward,
|
||||||
Raw: rawFakeHeader,
|
Raw: rawFakeHeader,
|
||||||
Timestamp: strconv.FormatInt(fakeTimestamp, 10),
|
Timestamp: strconv.FormatInt(fakeTimestamp, 10),
|
||||||
|
@ -45,9 +45,7 @@ type MockBlockChain struct {
|
|||||||
lastBlock *big.Int
|
lastBlock *big.Int
|
||||||
node core.Node
|
node core.Node
|
||||||
Transactions []core.TransactionModel
|
Transactions []core.TransactionModel
|
||||||
passedAccountAddress common.Address
|
accountBalanceReturnValue *big.Int
|
||||||
passedBlockNumer *big.Int
|
|
||||||
passedAccountBalance *big.Int
|
|
||||||
getAccountBalanceErr error
|
getAccountBalanceErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,11 +149,9 @@ func (blockChain *MockBlockChain) SetGetAccountBalanceErr(err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (blockChain *MockBlockChain) SetGetAccountBalance(balance *big.Int) {
|
func (blockChain *MockBlockChain) SetGetAccountBalance(balance *big.Int) {
|
||||||
blockChain.passedAccountBalance = balance
|
blockChain.accountBalanceReturnValue = balance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (blockChain *MockBlockChain) GetAccountBalance(address common.Address, blockNumber *big.Int) (*big.Int, error) {
|
func (blockChain *MockBlockChain) GetAccountBalance(address common.Address, blockNumber *big.Int) (*big.Int, error) {
|
||||||
blockChain.passedAccountAddress = address
|
return blockChain.accountBalanceReturnValue, blockChain.getAccountBalanceErr
|
||||||
blockChain.passedBlockNumer = blockNumber
|
|
||||||
return blockChain.passedAccountBalance, blockChain.getAccountBalanceErr
|
|
||||||
}
|
}
|
||||||
|
@ -74,17 +74,10 @@ func (bc BlockConverter) ToCoreUncle(block core.Block, uncles []*types.Header) (
|
|||||||
totalUncleRewards := new(big.Int)
|
totalUncleRewards := new(big.Int)
|
||||||
coreUncles := make([]core.Uncle, 0, len(uncles))
|
coreUncles := make([]core.Uncle, 0, len(uncles))
|
||||||
for _, uncle := range uncles {
|
for _, uncle := range uncles {
|
||||||
staticBlockReward := staticRewardByBlockNumber(block.Number)
|
thisUncleReward := calcUncleMinerReward(block.Number, uncle.Number.Int64())
|
||||||
rewardDiv8 := staticBlockReward.Div(staticBlockReward, big.NewInt(8))
|
|
||||||
mainBlock := big.NewInt(block.Number)
|
|
||||||
uncleBlock := big.NewInt(uncle.Number.Int64())
|
|
||||||
uncleBlockPlus8 := uncleBlock.Add(uncleBlock, big.NewInt(8))
|
|
||||||
uncleBlockPlus8MinusMainBlock := uncleBlockPlus8.Sub(uncleBlockPlus8, mainBlock)
|
|
||||||
thisUncleReward := rewardDiv8.Mul(rewardDiv8, uncleBlockPlus8MinusMainBlock)
|
|
||||||
raw, _ := json.Marshal(uncle)
|
raw, _ := json.Marshal(uncle)
|
||||||
coreUncle := core.Uncle{
|
coreUncle := core.Uncle{
|
||||||
Miner: uncle.Coinbase.Hex(),
|
Miner: uncle.Coinbase.Hex(),
|
||||||
BlockHash: block.Hash,
|
|
||||||
Hash: uncle.Hash().Hex(),
|
Hash: uncle.Hash().Hex(),
|
||||||
Raw: raw,
|
Raw: raw,
|
||||||
Reward: thisUncleReward.String(),
|
Reward: thisUncleReward.String(),
|
||||||
|
@ -31,6 +31,16 @@ func CalcBlockReward(block core.Block, uncles []*types.Header) *big.Int {
|
|||||||
return tmp.Add(tmp, staticBlockReward)
|
return tmp.Add(tmp, staticBlockReward)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calcUncleMinerReward(blockNumber, uncleBlockNumber int64) *big.Int {
|
||||||
|
staticBlockReward := staticRewardByBlockNumber(blockNumber)
|
||||||
|
rewardDiv8 := staticBlockReward.Div(staticBlockReward, big.NewInt(8))
|
||||||
|
mainBlock := big.NewInt(blockNumber)
|
||||||
|
uncleBlock := big.NewInt(uncleBlockNumber)
|
||||||
|
uncleBlockPlus8 := uncleBlock.Add(uncleBlock, big.NewInt(8))
|
||||||
|
uncleBlockPlus8MinusMainBlock := uncleBlockPlus8.Sub(uncleBlockPlus8, mainBlock)
|
||||||
|
return rewardDiv8.Mul(rewardDiv8, uncleBlockPlus8MinusMainBlock)
|
||||||
|
}
|
||||||
|
|
||||||
func calcTransactionFees(block core.Block) *big.Int {
|
func calcTransactionFees(block core.Block) *big.Int {
|
||||||
transactionFees := new(big.Int)
|
transactionFees := new(big.Int)
|
||||||
for _, transaction := range block.Transactions {
|
for _, transaction := range block.Transactions {
|
||||||
@ -56,7 +66,9 @@ func calcUncleInclusionRewards(block core.Block, uncles []*types.Header) *big.In
|
|||||||
func staticRewardByBlockNumber(blockNumber int64) *big.Int {
|
func staticRewardByBlockNumber(blockNumber int64) *big.Int {
|
||||||
staticBlockReward := new(big.Int)
|
staticBlockReward := new(big.Int)
|
||||||
//https://blog.ethereum.org/2017/10/12/byzantium-hf-announcement/
|
//https://blog.ethereum.org/2017/10/12/byzantium-hf-announcement/
|
||||||
if blockNumber >= 4370000 {
|
if blockNumber >= 7280000 {
|
||||||
|
staticBlockReward.SetString("2000000000000000000", 10)
|
||||||
|
} else if blockNumber >= 4370000 {
|
||||||
staticBlockReward.SetString("3000000000000000000", 10)
|
staticBlockReward.SetString("3000000000000000000", 10)
|
||||||
} else {
|
} else {
|
||||||
staticBlockReward.SetString("5000000000000000000", 10)
|
staticBlockReward.SetString("5000000000000000000", 10)
|
||||||
|
Loading…
Reference in New Issue
Block a user