From ba48ad13e9fc99a702c0e81d997ea0e2724dcbf2 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Tue, 7 Aug 2018 16:48:08 -0400 Subject: [PATCH] updating balances working correctly, test suite incomplete for accounts --- core/blockchain.go | 7 +++---- core/database_util.go | 9 +-------- core/shyft_database_util.go | 8 +------- eth/api_tracer.go | 4 +--- eth/shyft_tracer.go | 20 +++++++++++--------- eth/tracers/tracer.go | 24 ++++++++++++------------ shyftDb/shyft_database_util_test.go | 3 ++- 7 files changed, 31 insertions(+), 44 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 36d7a0a120..d7a8f65aff 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -29,7 +29,6 @@ import ( "sync/atomic" "time" - "github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/common/mclock" "github.com/ShyftNetwork/go-empyrean/consensus" @@ -92,10 +91,10 @@ type BlockChain struct { chainConfig *params.ChainConfig // Chain & network configuration 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 - triegc *prque.Prque // Priority queue mapping block numbers to tries to gc - gcproc time.Duration // Accumulates canonical block processing for trie dumping + triegc *prque.Prque // Priority queue mapping block numbers to tries to gc + gcproc time.Duration // Accumulates canonical block processing for trie dumping hc *HeaderChain rmLogsFeed event.Feed diff --git a/core/database_util.go b/core/database_util.go index 256a2edd5d..9eea4863b4 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -21,8 +21,8 @@ import ( "encoding/binary" "encoding/json" "errors" - "math/big" "fmt" + "math/big" "github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/core/types" @@ -283,14 +283,7 @@ func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, // its added positional metadata. func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { // Retrieve the lookup metadata and resolve the transaction from the body - //fmt.Println("INSIDE GET TRANSACTION ++++++++") - //fmt.Println("The hash and db reader are") - //fmt.Println(hash) - //fmt.Println(db) blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash) - //fmt.Println(blockHash) - //fmt.Println(blockNumber) - if blockHash != (common.Hash{}) { body := GetBody(db, blockHash, blockNumber) if body == nil || len(body.Transactions) <= int(txIndex) { diff --git a/core/shyft_database_util.go b/core/shyft_database_util.go index 5fdb04ae67..ad6f6872cc 100644 --- a/core/shyft_database_util.go +++ b/core/shyft_database_util.go @@ -146,12 +146,6 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error { if block.Transactions().Len() > 0 { for _, tx := range block.Transactions() { swriteTransactions(sqldb, tx, block.Header().Hash(), blockData.Number, receipts, age, blockData.GasLimit) - // if block.Transactions()[0].To() != nil { - // swriteBalance(sqldb, tx) - // } - // if block.Transactions()[0].To() == nil { - // swriteContractBalance(sqldb, tx) - // } } } return nil @@ -243,7 +237,7 @@ func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) { fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From) switch { case err == sql.ErrNoRows: - fmt.Println("wtf", s.From) + fmt.Println("Need to write From", s.From) } if err != nil { log.Fatal(err) diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 983f5913a9..13ca84fcf1 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -631,8 +631,6 @@ func (api *PrivateDebugAPI) StraceTx(ctx context.Context, message core.Message, } } - - // traceTx configures a new tracer according to the provided configuration, and // executes the given message in the provided environment. The return value will // be tracer dependent. @@ -646,7 +644,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v case config != nil && config.Tracer != nil: // Define a meaningful timeout of a single transaction trace - timeout := defaultTraceTimeout + timeout := defaultTraceTimeout if config.Timeout != nil { if timeout, err = time.ParseDuration(*config.Timeout); err != nil { diff --git a/eth/shyft_tracer.go b/eth/shyft_tracer.go index 550062c7b2..bfcc9ad653 100644 --- a/eth/shyft_tracer.go +++ b/eth/shyft_tracer.go @@ -1,15 +1,16 @@ package eth - import ( + "context" + "fmt" + "github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/params" - "context" ) var EthereumObject interface{} -type ShyftTracer struct {} +type ShyftTracer struct{} var PrivateAPI *PrivateDebugAPI var Context context.Context @@ -23,21 +24,22 @@ func InitTracerEnv() { Context = ctx2 config := &TraceConfig{ LogConfig: nil, - Tracer: &jsTracer, // needs to be non-nil - Timeout: nil, - Reexec: nil, + Tracer: &jsTracer, // needs to be non-nil + Timeout: nil, + Reexec: nil, } TracerConfig = config fullNode, _ := SNew(Global_config) + fmt.Println("FULL NODE", fullNode) privateAPI := NewPrivateDebugAPI(config2, fullNode) PrivateAPI = privateAPI } -func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) { +func (st ShyftTracer) GetTracerToRun(hash common.Hash) (interface{}, error) { return PrivateAPI.STraceTransaction(Context, hash, TracerConfig) } -func setEthObject(ethobj interface{}){ +func setEthObject(ethobj interface{}) { EthereumObject = ethobj } @@ -45,4 +47,4 @@ var Global_config *Config func SetGlobalConfig(c *Config) { Global_config = c -} \ No newline at end of file +} diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go index f419834a37..4b81984a35 100644 --- a/eth/tracers/tracer.go +++ b/eth/tracers/tracer.go @@ -25,6 +25,8 @@ import ( "time" "unsafe" + "strconv" + "github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/common/hexutil" "github.com/ShyftNetwork/go-empyrean/core" @@ -32,7 +34,6 @@ import ( "github.com/ShyftNetwork/go-empyrean/crypto" "github.com/ShyftNetwork/go-empyrean/log" "gopkg.in/olebedev/go-duktape.v3" - "strconv" ) // bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js. @@ -604,18 +605,17 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) { amount := strconv.FormatUint(value, 10) 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, + 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) diff --git a/shyftDb/shyft_database_util_test.go b/shyftDb/shyft_database_util_test.go index d1ef772a4f..3151c00505 100644 --- a/shyftDb/shyft_database_util_test.go +++ b/shyftDb/shyft_database_util_test.go @@ -2,6 +2,7 @@ package shyftdb import ( "encoding/json" + "fmt" "math/big" "strconv" "strings" @@ -318,13 +319,13 @@ func TestBlock(t *testing.T) { t.Fatalf("isContract [%v]: isContract bool is incorrect", isContract) } } - if getAllTx := core.SGetAllTransactions(sqldb); len(getAllTx) == 0 { t.Fatalf("GetAllTransactions [%v]: GetAllTransactions did not return correctly", getAllTx) } }) t.Run("TestAccountsToReturnAccounts", func(t *testing.T) { for _, tx := range txs { + fmt.Println("test account", tx.To().String()) accountAddrTo := core.SGetAccount(sqldb, tx.To().String()) byts := []byte(accountAddrTo) var accountDataTo core.SAccounts