fix merge

This commit is contained in:
greg 2018-06-08 14:11:27 -04:00
commit c5b3b93fb4
10 changed files with 80 additions and 89 deletions

View file

@ -38,7 +38,6 @@ import (
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
"database/sql"
) )
var ( var (
@ -169,13 +168,7 @@ func initGenesis(ctx *cli.Context) error {
if err != nil { if err != nil {
utils.Fatalf("Failed to open database: %v", err) utils.Fatalf("Failed to open database: %v", err)
} }
// @NOTE:shyft instantiate BlockExplorerDB here _, hash, err := core.SetupGenesisBlock(chaindb, genesis)
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, err := sql.Open("postgres", connStr)
if err != nil {
return nil
}
_, hash, err := core.SetupGenesisBlock(chaindb, genesis, blockExplorerDb)
if err != nil { if err != nil {
utils.Fatalf("Failed to write genesis block: %v", err) utils.Fatalf("Failed to write genesis block: %v", err)
} }
@ -321,6 +314,7 @@ func copyDb(ctx *cli.Context) error {
syncmode := *utils.GlobalTextMarshaler(ctx, utils.SyncModeFlag.Name).(*downloader.SyncMode) syncmode := *utils.GlobalTextMarshaler(ctx, utils.SyncModeFlag.Name).(*downloader.SyncMode)
dl := downloader.New(syncmode, chainDb, new(event.TypeMux), chain, nil, nil) dl := downloader.New(syncmode, chainDb, new(event.TypeMux), chain, nil, nil)
// Create a source peer to satisfy downloader requests from // Create a source peer to satisfy downloader requests from
db, err := ethdb.NewLDBDatabase(ctx.Args().First(), ctx.GlobalInt(utils.CacheFlag.Name), 256) db, err := ethdb.NewLDBDatabase(ctx.Args().First(), ctx.GlobalInt(utils.CacheFlag.Name), 256)
if err != nil { if err != nil {

View file

@ -57,9 +57,6 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5" whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
// @shyft
"database/sql"
) )
var ( var (
@ -1219,7 +1216,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
var err error var err error
chainDb = MakeChainDatabase(ctx, stack) chainDb = MakeChainDatabase(ctx, stack)
config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx), nil) config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx))
if err != nil { if err != nil {
Fatalf("%v", err) Fatalf("%v", err)
} }
@ -1252,14 +1249,8 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
} }
vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)} vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)}
// @NOTE:shyft instantiate BlockExplorerDB here?
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, err := sql.Open("postgres", connStr)
if err != nil {
return nil, nil
}
fmt.Println("Calling NewBlock CHAIN in flags.go ******************************") fmt.Println("Calling NewBlock CHAIN in flags.go ******************************")
chain, err = core.NewBlockChain(chainDb, blockExplorerDb,cache, config, engine, vmcfg) chain, err = core.NewBlockChain(chainDb,cache, config, engine, vmcfg)
if err != nil { if err != nil {
Fatalf("Can't create BlockChain: %v", err) Fatalf("Can't create BlockChain: %v", err)
} }

View file

@ -31,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/log"
set "gopkg.in/fatih/set.v0" set "gopkg.in/fatih/set.v0"
) )

View file

@ -46,9 +46,6 @@ import (
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru" "github.com/hashicorp/golang-lru"
"gopkg.in/karalabe/cookiejar.v2/collections/prque" "gopkg.in/karalabe/cookiejar.v2/collections/prque"
// @shyft
"database/sql"
) )
var ( var (
@ -96,7 +93,6 @@ type BlockChain struct {
cacheConfig *CacheConfig // Cache configuration for pruning cacheConfig *CacheConfig // Cache configuration for pruning
db ethdb.Database // Low level persistent database to store final content in db ethdb.Database // Low level persistent database to store final content in
blockExplorerDb *sql.DB
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping gcproc time.Duration // Accumulates canonical block processing for trie dumping
@ -141,7 +137,7 @@ type BlockChain struct {
// NewBlockChain returns a fully initialised block chain using information // NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator and // available in the database. It initialises the default Ethereum Validator and
// Processor. // Processor.
func NewBlockChain(db ethdb.Database, blockExplorerDb *sql.DB, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) { func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) {
if cacheConfig == nil { if cacheConfig == nil {
cacheConfig = &CacheConfig{ cacheConfig = &CacheConfig{
TrieNodeLimit: 256 * 1024 * 1024, TrieNodeLimit: 256 * 1024 * 1024,
@ -158,7 +154,6 @@ func NewBlockChain(db ethdb.Database, blockExplorerDb *sql.DB, cacheConfig *Cach
chainConfig: chainConfig, chainConfig: chainConfig,
cacheConfig: cacheConfig, cacheConfig: cacheConfig,
db: db, db: db,
blockExplorerDb: blockExplorerDb,
triegc: prque.New(), triegc: prque.New(),
stateCache: state.NewDatabase(db), stateCache: state.NewDatabase(db),
quit: make(chan struct{}), quit: make(chan struct{}),
@ -907,7 +902,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
return NonStatTy, err return NonStatTy, err
} }
// @NOTE:SHYFT - Write block data for block explorer // @NOTE:SHYFT - Write block data for block explorer
if err := shyftdb.WriteBlock(bc.blockExplorerDb, block, receipts); err != nil { if err := shyftdb.WriteBlock(block, receipts); err != nil {
return NonStatTy, err return NonStatTy, err
} }

View file

@ -28,9 +28,6 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
// @shyft
"database/sql"
) )
// So we can deterministically seed different blockchains // So we can deterministically seed different blockchains
@ -169,9 +166,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) { genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) {
// TODO(karalabe): This is needed for clique, which depends on multiple blocks. // TODO(karalabe): This is needed for clique, which depends on multiple blocks.
// It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow. // It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow.
connStr := "user=postgres dbname=shyftdb sslmode=disable" blockchain, _ := NewBlockChain(db, nil, config, engine, vm.Config{})
blockExplorerDb, _ := sql.Open("postgres", connStr)
blockchain, _ := NewBlockChain(db, blockExplorerDb,nil, config, engine, vm.Config{})
defer blockchain.Stop() defer blockchain.Stop()
b := &BlockGen{i: i, parent: parent, chain: blocks, chainReader: blockchain, statedb: statedb, config: config, engine: engine} b := &BlockGen{i: i, parent: parent, chain: blocks, chainReader: blockchain, statedb: statedb, config: config, engine: engine}
@ -253,9 +248,7 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
gspec := new(Genesis) gspec := new(Genesis)
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
genesis := gspec.MustCommit(db) genesis := gspec.MustCommit(db)
connStr := "user=postgres dbname=shyftdb sslmode=disable" blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
blockExplorerDb, _ := sql.Open("postgres", connStr)
blockchain, _ := NewBlockChain(db, blockExplorerDb, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
// Create and inject the requested chain // Create and inject the requested chain
if n == 0 { if n == 0 {
return db, blockchain, nil return db, blockchain, nil

View file

@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/shyftdb"
"database/sql" "database/sql"
"strconv" "strconv"
"time" "time"
@ -142,13 +143,9 @@ func (e *GenesisMismatchError) Error() string {
//WriteShyftGen writes the genesis block to Shyft db //WriteShyftGen writes the genesis block to Shyft db
//@NOTE:SHYFT //@NOTE:SHYFT
func WriteShyftGen(sqldb *sql.DB, gen *Genesis, block *types.Block) { func WriteShyftGen(gen *Genesis, block *types.Block) {
if sqldb == nil {
log.Info("Initializing Shyft Postgres DB") sqldb, _ := shyftdb.DBConnection()
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, _ := sql.Open("postgres", connStr)
sqldb = blockExplorerDb
}
for k := range gen.Alloc { for k := range gen.Alloc {
addr := k.String() addr := k.String()
@ -196,13 +193,9 @@ func WriteShyftGen(sqldb *sql.DB, gen *Genesis, block *types.Block) {
log.Info("Found Genesis Block") log.Info("Found Genesis Block")
}}} }}}
func WriteShyftBlockZero(sqldb *sql.DB, block *types.Block, gen *Genesis) error { func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
if sqldb == nil {
log.Info("Initializing Shyft Postgres DB") sqldb, _ := shyftdb.DBConnection()
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, _ := sql.Open("postgres", connStr)
sqldb = blockExplorerDb
}
coinbase := block.Header().Coinbase.String() coinbase := block.Header().Coinbase.String()
number := block.Header().Number.String() number := block.Header().Number.String()
@ -252,7 +245,7 @@ func WriteShyftBlockZero(sqldb *sql.DB, block *types.Block, gen *Genesis) error
// error is a *params.ConfigCompatError and the new, unwritten config is returned. // error is a *params.ConfigCompatError and the new, unwritten config is returned.
// //
// The returned chain configuration is never nil. // The returned chain configuration is never nil.
func SetupGenesisBlock(db ethdb.Database, genesis *Genesis, sqldb *sql.DB) (*params.ChainConfig, common.Hash, error) { func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
if genesis != nil && genesis.Config == nil { if genesis != nil && genesis.Config == nil {
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
} }
@ -267,9 +260,9 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis, sqldb *sql.DB) (*par
} }
block, err := genesis.Commit(db) block, err := genesis.Commit(db)
//@NOTE:SHYFT WRITE TO BLOCK ZERO DB //@NOTE:SHYFT WRITE TO BLOCK ZERO DB
WriteShyftBlockZero(sqldb, block, genesis) WriteShyftBlockZero(block, genesis)
//@NOTE:SHYFT WRITE TO DB //@NOTE:SHYFT WRITE TO DB
WriteShyftGen(sqldb, genesis, block) WriteShyftGen(genesis, block)
return genesis.Config, block.Hash(), err return genesis.Config, block.Hash(), err
} }

View file

@ -47,9 +47,6 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
// @shyft
"database/sql"
) )
type LesServer interface { type LesServer interface {
@ -76,7 +73,6 @@ type Ethereum struct {
// DB interfaces // DB interfaces
chainDb ethdb.Database // Block chain database chainDb ethdb.Database // Block chain database
blockExplorerDb *sql.DB
eventMux *event.TypeMux eventMux *event.TypeMux
engine consensus.Engine engine consensus.Engine
@ -116,16 +112,10 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return nil, err return nil, err
} }
// @NOTE:shyft instantiate BlockExplorerDB here
// @TODO: Create Genesis Block // @TODO: Create Genesis Block
// @NOTE:shyft instantiate BlockExplorerDB here?
connStr := "user=postgres dbname=shyftdb sslmode=disable"
blockExplorerDb, err := sql.Open("postgres", connStr)
if err != nil {
return nil, err
}
stopDbUpgrade := upgradeDeduplicateData(chainDb) stopDbUpgrade := upgradeDeduplicateData(chainDb)
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis, blockExplorerDb) chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis)
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
return nil, genesisErr return nil, genesisErr
} }
@ -134,7 +124,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth := &Ethereum{ eth := &Ethereum{
config: config, config: config,
chainDb: chainDb, chainDb: chainDb,
blockExplorerDb: blockExplorerDb,
chainConfig: chainConfig, chainConfig: chainConfig,
eventMux: ctx.EventMux, eventMux: ctx.EventMux,
accountManager: ctx.AccountManager, accountManager: ctx.AccountManager,
@ -161,7 +150,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording} vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording}
cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieNodeLimit: config.TrieCache, TrieTimeLimit: config.TrieTimeout} cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieNodeLimit: config.TrieCache, TrieTimeLimit: config.TrieTimeout}
) )
eth.blockchain, err = core.NewBlockChain(chainDb, blockExplorerDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig) eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -84,7 +84,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis, nil) chainConfig, genesisHash, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis)
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat { if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {
return nil, genesisErr return nil, genesisErr
} }

31
shyftDb/db.go Normal file
View file

@ -0,0 +1,31 @@
package shyftdb
import (
"fmt"
"database/sql"
)
var blockExplorerDb *sql.DB
func InitDB() (*sql.DB, error){
connStr := "user=postgres dbname=shyftdb sslmode=disable"
db, err := sql.Open("postgres", connStr)
if err != nil {
fmt.Println("ERROR OPENING DB, NOT INITIALIZING")
fmt.Println(err)
return nil, err
} else {
blockExplorerDb = db
return blockExplorerDb, nil
}
}
func DBConnection() (*sql.DB, error) {
if (blockExplorerDb == nil) {
_, err := InitDB()
if(err != nil) {
return nil, err
}
}
return blockExplorerDb, nil
}

View file

@ -104,8 +104,14 @@ type SendAndReceive struct {
} }
//WriteBlock writes to block info to sql db //WriteBlock writes to block info to sql db
func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) error { func WriteBlock(block *types.Block, receipts []*types.Receipt) error {
rewards := WriteMinerRewards(sqldb,block)
sqldb, err := DBConnection()
if (err != nil) {
panic(err)
}
rewards := writeMinerRewards(sqldb,block)
coinbase := block.Header().Coinbase.String() coinbase := block.Header().Coinbase.String()
number := block.Header().Number.String() number := block.Header().Number.String()
gasUsed := block.Header().GasUsed gasUsed := block.Header().GasUsed
@ -132,21 +138,21 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er
if block.Transactions().Len() > 0 { if block.Transactions().Len() > 0 {
for _, tx := range block.Transactions() { for _, tx := range block.Transactions() {
WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit) writeTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit)
if block.Transactions()[0].To() != nil { if block.Transactions()[0].To() != nil {
WriteFromBalance(sqldb, tx) writeFromBalance(sqldb, tx)
} }
if block.Transactions()[0].To() == nil { if block.Transactions()[0].To() == nil {
WriteContractBalance(sqldb, tx) writeContractBalance(sqldb, tx)
WriteContractsTxHashReferences(sqldb, tx) writeContractsTxHashReferences(sqldb, tx)
} }
} }
} }
return nil return nil
} }
//WriteTransactions writes to sqldb //writeTransactions writes to sqldb
func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt, age time.Time, gasLimit uint64) error { func writeTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt, age time.Time, gasLimit uint64) error {
txData := ShyftTxEntry{ txData := ShyftTxEntry{
TxHash: tx.Hash(), TxHash: tx.Hash(),
From: tx.From(), From: tx.From(),
@ -217,7 +223,7 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
return nil return nil
} }
func WriteContractsTxHashReferences(sqldb *sql.DB, tx *types.Transaction) error { func writeContractsTxHashReferences(sqldb *sql.DB, tx *types.Transaction) error {
txHash := tx.Hash().Hex() txHash := tx.Hash().Hex()
sqlStatement := `INSERT INTO contracts(txHash) VALUES(($1)) RETURNING txHash` sqlStatement := `INSERT INTO contracts(txHash) VALUES(($1)) RETURNING txHash`
@ -228,8 +234,8 @@ func WriteContractsTxHashReferences(sqldb *sql.DB, tx *types.Transaction) error
return nil return nil
} }
func WriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error { func writeContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
sendAndReceiveData,balanceSen,accountNonceSen := WriteContractBalanceHelper(sqldb, tx) sendAndReceiveData,balanceSen,accountNonceSen := writeContractBalanceHelper(sqldb, tx)
fromAddr := sendAndReceiveData.From fromAddr := sendAndReceiveData.From
amount := sendAndReceiveData.Amount amount := sendAndReceiveData.Amount
balanceSender := balanceSen balanceSender := balanceSen
@ -275,7 +281,7 @@ func WriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
return nil return nil
} }
func WriteContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string) { func writeContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string) {
sendAndReceiveData := SendAndReceive{ sendAndReceiveData := SendAndReceive{
From: tx.From().Hex(), From: tx.From().Hex(),
Amount: tx.Value().String(), Amount: tx.Value().String(),
@ -294,9 +300,9 @@ func WriteContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndRe
return sendAndReceiveData, balanceSender, accountNonceSender return sendAndReceiveData, balanceSender, accountNonceSender
} }
//WriteFromBalance writes senders balance to accounts db //writeFromBalance writes senders balance to accounts db
func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error { func writeFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := WriteBalanceHelper(sqldb, tx) sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := writeBalanceHelper(sqldb, tx)
toAddr := sendAndReceiveData.To toAddr := sendAndReceiveData.To
fromAddr := sendAndReceiveData.From fromAddr := sendAndReceiveData.From
amount := sendAndReceiveData.Amount amount := sendAndReceiveData.Amount
@ -370,7 +376,7 @@ func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
return nil return nil
} }
func WriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string, string, string) { func writeBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string, string, string) {
sendAndReceiveData := SendAndReceive{ sendAndReceiveData := SendAndReceive{
To: tx.To().Hex(), To: tx.To().Hex(),
From: tx.From().Hex(), From: tx.From().Hex(),
@ -406,7 +412,7 @@ func WriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, s
// uncle blocks, account balance updates based on reorgs, diverges that get dropped. // uncle blocks, account balance updates based on reorgs, diverges that get dropped.
// Reason for this is because the accounts are not deterministic like the block and tx hashes. // Reason for this is because the accounts are not deterministic like the block and tx hashes.
// @TODO: Calculate reorg // @TODO: Calculate reorg
func WriteMinerRewards(sqldb *sql.DB, block *types.Block) string { func writeMinerRewards(sqldb *sql.DB, block *types.Block) string {
minerAddr := block.Coinbase().String() minerAddr := block.Coinbase().String()
shyftConduitAddress := Rewards.ShyftNetworkConduitAddress.String() shyftConduitAddress := Rewards.ShyftNetworkConduitAddress.String()
// Calculate the total gas used in the block // Calculate the total gas used in the block
@ -436,13 +442,13 @@ func WriteMinerRewards(sqldb *sql.DB, block *types.Block) string {
uncleAddrs = append(uncleAddrs, uncle.Coinbase.String()) uncleAddrs = append(uncleAddrs, uncle.Coinbase.String())
} }
StoreReward(sqldb, minerAddr, totalMinerReward) storeReward(sqldb, minerAddr, totalMinerReward)
StoreReward(sqldb, shyftConduitAddress, Rewards.ShyftNetworkBlockReward) storeReward(sqldb, shyftConduitAddress, Rewards.ShyftNetworkBlockReward)
var uncRewards = new(big.Int) var uncRewards = new(big.Int)
for i := 0; i < len(uncleAddrs); i++ { for i := 0; i < len(uncleAddrs); i++ {
uncRewards := uncleRewards[i] uncRewards := uncleRewards[i]
fmt.Println(uncRewards) fmt.Println(uncRewards)
StoreReward(sqldb, uncleAddrs[i], uncleRewards[i]) storeReward(sqldb, uncleAddrs[i], uncleRewards[i])
} }
fullRewardValue := new(big.Int) fullRewardValue := new(big.Int)
@ -452,7 +458,7 @@ func WriteMinerRewards(sqldb *sql.DB, block *types.Block) string {
return fullRewardValue.String() return fullRewardValue.String()
} }
func StoreReward(sqldb *sql.DB, address string, reward *big.Int) { func storeReward(sqldb *sql.DB, address string, reward *big.Int) {
// Check if address exists // Check if address exists
var addressBalance string var addressBalance string
addressExistsStatement := `SELECT balance from accounts WHERE addr = ($1)` addressExistsStatement := `SELECT balance from accounts WHERE addr = ($1)`