review fixes

This commit is contained in:
Ian Norden 2019-03-27 12:41:15 -05:00
parent 185f4c0e93
commit fd407825c1
4 changed files with 8 additions and 7 deletions

View File

@ -186,9 +186,9 @@ func (blockRepository BlockRepository) insertBlock(block core.Block) (int64, err
} }
func (blockRepository BlockRepository) createUncleRewards(tx *sqlx.Tx, blockId int64, blockHash string, mappedUncleRewards map[string]map[string]*big.Int) error { func (blockRepository BlockRepository) createUncleRewards(tx *sqlx.Tx, blockId int64, blockHash string, mappedUncleRewards map[string]map[string]*big.Int) error {
for miner, uncleRewards := range mappedUncleRewards { for minerAddr, uncleRewards := range mappedUncleRewards {
for uncleHash, reward := range uncleRewards { for uncleHash, reward := range uncleRewards {
err := blockRepository.createUncleReward(tx, blockId, blockHash, miner, uncleHash, reward.String()) err := blockRepository.createUncleReward(tx, blockId, blockHash, minerAddr, uncleHash, reward.String())
if err != nil { if err != nil {
return err return err
} }
@ -197,13 +197,13 @@ func (blockRepository BlockRepository) createUncleRewards(tx *sqlx.Tx, blockId i
return nil return nil
} }
func (blockRepository BlockRepository) createUncleReward(tx *sqlx.Tx, blockId int64, blockHash, miner, uncleHash, amount string) error { func (blockRepository BlockRepository) createUncleReward(tx *sqlx.Tx, blockId int64, blockHash, minerAddr, uncleHash, amount string) error {
_, err := tx.Exec( _, err := tx.Exec(
`INSERT INTO uncle_rewards `INSERT INTO uncle_rewards
(block_id, block_hash, uncle_hash, uncle_reward, miner_address) (block_id, block_hash, miner_address, uncle_hash, uncle_reward)
VALUES ($1, $2, $3, $4, $5) VALUES ($1, $2, $3, $4, $5)
RETURNING id`, RETURNING id`,
blockId, blockHash, miner, uncleHash, utilities.NullToZero(amount)) blockId, blockHash, minerAddr, uncleHash, utilities.NullToZero(amount))
return err return err
} }

View File

@ -1 +0,0 @@
package repositories

View File

@ -1 +0,0 @@
package repositories

View File

@ -24,6 +24,9 @@ import (
) )
// (U_n + 8 - B_n) * R / 8 // (U_n + 8 - B_n) * R / 8
// https://github.com/ethereum/go-ethereum/issues/1591
// https://ethereum.stackexchange.com/questions/27172/different-uncles-reward
// https://github.com/ethereum/homestead-guide/issues/399
// Returns a map of miner addresses to a map of the uncles they mined (hashes) to the rewards received for that uncle // Returns a map of miner addresses to a map of the uncles they mined (hashes) to the rewards received for that uncle
func CalcUnclesReward(block core.Block, uncles []*types.Header) (*big.Int, map[string]map[string]*big.Int) { func CalcUnclesReward(block core.Block, uncles []*types.Header) (*big.Int, map[string]map[string]*big.Int) {
uncleRewards := new(big.Int) uncleRewards := new(big.Int)