From ab8d98ad913638a190ce0de5d4dfdffd18a6e23d Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 26 Jul 2018 17:03:50 -0400 Subject: [PATCH] updating accounts from internal txs --- core/genesis.go | 21 +++++++++++++++------ core/shyft_database_util.go | 24 ++++++++++++++++++++++++ eth/tracers/tracer.go | 26 +++++++++++++++----------- 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 84a449b971..c9d049d4fc 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -190,7 +190,7 @@ func WriteShyftGen(gen *Genesis, block *types.Block) { InsertTx(sqldb, txData) default: - log.Info("Found Genesis Block") + log.Info("Found Genesis Block") }} } @@ -259,11 +259,20 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig log.Info("Writing custom genesis block") } block, err := genesis.Commit(db) - //@NOTE:SHYFT WRITE TO BLOCK ZERO DB - WriteShyftBlockZero(block, genesis) - //@NOTE:SHYFT WRITE TO DB - WriteShyftGen(genesis, block) - + //@NOTE:SHYFT SWITCH CASE ENSURES SHYFT GENESIS FUNCTIONS ARE ONLY CALLED ONCE + sqldb, _ := DBConnection() + serror := BlockExists(sqldb, block.Hash().String()) + switch { + case serror == sql.ErrNoRows: + //@NOTE:SHYFT WRITE TO BLOCK ZERO DB + WriteShyftBlockZero(block, genesis) + //@NOTE:SHYFT WRITE TO DB + WriteShyftGen(genesis, block) + case serror != nil: + panic(serror) + default: + log.Info("Genesis Block Written") + } return genesis.Config, block.Hash(), err } diff --git a/core/shyft_database_util.go b/core/shyft_database_util.go index 6f5c5484be..ecf318db67 100644 --- a/core/shyft_database_util.go +++ b/core/shyft_database_util.go @@ -12,6 +12,7 @@ import ( Rewards "github.com/ShyftNetwork/go-empyrean/consensus/ethash" "github.com/ShyftNetwork/go-empyrean/shyfttracerinterface" "strings" + "fmt" ) var IShyftTracer shyfttracerinterface.IShyftTracer @@ -40,6 +41,19 @@ type SBlock struct { Blocks []SBlock } +type InteralWrite struct { + Hash string + Type string + From string + To string + Value string + Gas uint64 + GasUsed uint64 + Input string + Output string + Time string +} + //blockRes struct type blockRes struct { hash string @@ -482,4 +496,14 @@ func InsertTx (sqldb *sql.DB, txData ShyftTxEntryPretty) { } } +func InsertInternalTx(sqldb *sql.DB, i InteralWrite) { + var returnValue string + sqlStatement := `INSERT INTO internaltxs(type, txhash, from_addr, to_addr, amount, gas, gasUsed, time, input, output) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING txHash` + qerr := sqldb.QueryRow(sqlStatement, i.Type, i.Hash, i.From, i.To, i.Value, i.Gas, i.GasUsed, i.Time, i.Input, i.Output).Scan(&returnValue) + if qerr != nil { + fmt.Println(qerr) + panic(qerr) + } +} + diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go index 6ca7bc95de..f419834a37 100644 --- a/eth/tracers/tracer.go +++ b/eth/tracers/tracer.go @@ -603,18 +603,22 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) { value, _ := hexutil.DecodeUint64(i.Value) amount := strconv.FormatUint(value, 10) - //@TODO WRITE OVER TRANSACTION STRUCT - - core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount) - - var returnValue string - sqlStatement := `INSERT INTO internaltxs(type, txhash, from_addr, to_addr, amount, gas, gasUsed, time, input, output) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING txHash` - qerr := sqldb.QueryRow(sqlStatement, i.Type, hash.Hex(), i.From, i.To, amount, gas, gasUsed, i.Time, i.Input, i.Output).Scan(&returnValue) - - if qerr != nil { - fmt.Println(qerr) - panic(qerr) + iTx := core.InteralWrite{ + Hash: hash.Hex(), + Type: i.Type, + From: i.From, + To: i.To, + Value: amount, + Gas: gas, + GasUsed: gasUsed, + Input: i.Input, + Output: i.Output, + Time: i.Time, } + + //@TODO WRITE OVER TRANSACTION STRUCT + core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount) + core.InsertInternalTx(sqldb, iTx) } //@NOTE:SHYFT