From a2d713137c77383375e1b4fffc858587f5361b31 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 15 Apr 2018 16:29:22 -0400 Subject: [PATCH 1/3] Removed logs --- core/database_util.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/database_util.go b/core/database_util.go index 6c5980062b..18a1e3ff57 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -447,14 +447,6 @@ func WriteTd(db ethdb.Putter, hash common.Hash, number uint64, td *big.Int) erro // WriteBlock serializes a block into the database, header and body separately. func WriteBlock(db ethdb.Putter, block *types.Block) error { - // Store the body first to retain database consistency - fmt.Println("\t\t ~~~~~BLOCK~~~~~") - fmt.Println(block.Transactions()) - if block.Transactions().Len() > 0 { - for _, tx := range block.Transactions() { - fmt.Println(tx.To().Hex()) - } - } if err := WriteBody(db, block.Hash(), block.NumberU64(), block.Body()); err != nil { return err } From 309c57d39e0d599ca279508a87d9c07deedac613 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 15 Apr 2018 17:20:47 -0400 Subject: [PATCH 2/3] Tx succesfully stored to db --- core/blockchain.go | 1 - shyftdb/shyft_database_util.go | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 63ac0a2498..d3fb32e847 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -908,7 +908,6 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. if err := shyftdb.WriteBlock(bc.blockExplorerDb, block); err != nil { return NonStatTy, err } - shyftdb.GetBlock(bc.blockExplorerDb, block) root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) if err != nil { diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 470531259e..c14be73f1f 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -5,6 +5,7 @@ import ( "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" ) func GetBlock(db *leveldb.DB, block *types.Block) { @@ -20,8 +21,34 @@ func GetBlock(db *leveldb.DB, block *types.Block) { func WriteBlock(db *leveldb.DB, block *types.Block) error { hash := block.Header().Hash().Bytes() fmt.Println(hash) - err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil) - fmt.Println("the error is: ++++++++++++++") - fmt.Println(err) + if err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil); err != nil { + log.Crit("Failed to store block", "err", err) + } + // If the block was not succesfully stored we will not store the tx data + if block.Transactions().Len() > 0 { + WriteTransactions(db, block.Transactions(), hash) + } return nil +} + +func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error { + for _, tx := range transactions { + txHash := tx.Hash().Bytes() + if err := db.Put(txHash, []byte("Hello hello"), nil); err != nil { + log.Crit("Failed to store TX", "err", err) + } + GetTransaction(db, tx) + } + return nil +} + +func GetTransaction(db *leveldb.DB, tx *types.Transaction) { + data, err := db.Get(tx.Hash().Bytes(), nil) + if err != nil { + log.Crit("Could not retrieve data") + } + if len(data) > 0 { + fmt.Println("\n\t\t\t DATA \n") + fmt.Println(data) + } } \ No newline at end of file From abd663a6b773b1623108d21cc41a740c3c497ed8 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 15 Apr 2018 21:15:40 -0400 Subject: [PATCH 3/3] Succesfully get ALL TX from the db --- core/types/transaction.go | 2 -- shyftdb/shyft_database_util.go | 47 +++++++++++++++++++++------------ simulations/sendTransactions.js | 2 +- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/core/types/transaction.go b/core/types/transaction.go index 8d1ea4fa46..5660582baf 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -94,8 +94,6 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit if len(data) > 0 { data = common.CopyBytes(data) } - fmt.Println("DASas") - fmt.Println(to) d := txdata{ AccountNonce: nonce, Recipient: to, diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index c14be73f1f..4b30cd615d 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -4,20 +4,11 @@ import ( "fmt" "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/util" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" ) -func GetBlock(db *leveldb.DB, block *types.Block) { - hash := block.Header().Hash().Bytes() - bar, err := db.Get(hash, nil) - fmt.Println("Our error is ") - fmt.Println(err) - fmt.Println("Our result is ") - fmt.Println(bar) - -} - func WriteBlock(db *leveldb.DB, block *types.Block) error { hash := block.Header().Hash().Bytes() fmt.Println(hash) @@ -33,22 +24,44 @@ func WriteBlock(db *leveldb.DB, block *types.Block) error { func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error { for _, tx := range transactions { - txHash := tx.Hash().Bytes() - if err := db.Put(txHash, []byte("Hello hello"), nil); err != nil { + key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...) + if err := db.Put(key, []byte("Hello hello"), nil); err != nil { log.Crit("Failed to store TX", "err", err) } GetTransaction(db, tx) } + GetAllTransactions(db) return nil } -func GetTransaction(db *leveldb.DB, tx *types.Transaction) { - data, err := db.Get(tx.Hash().Bytes(), nil) +// Meant for internal tests + +func GetBlock(db *leveldb.DB, block *types.Block) { + hash := block.Header().Hash().Bytes() + bar, err := db.Get(hash, nil) + fmt.Println("Our error is ") + fmt.Println(err) + fmt.Println("Our result is ") + fmt.Println(bar) + +} + +func GetAllTransactions(db *leveldb.DB) { + //iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil) + iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil) + for iter.Next() { + fmt.Println(iter.Key()) + fmt.Println(iter.Value()) + } + iter.Release() +} +func GetTransaction (db *leveldb.DB, tx *types.Transaction) { + key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...) + value, err := db.Get(key, nil) if err != nil { log.Crit("Could not retrieve data") } - if len(data) > 0 { - fmt.Println("\n\t\t\t DATA \n") - fmt.Println(data) + if len(value) > 0 { + fmt.Println(value) } } \ No newline at end of file diff --git a/simulations/sendTransactions.js b/simulations/sendTransactions.js index 09d39b6b85..9f01473ee7 100644 --- a/simulations/sendTransactions.js +++ b/simulations/sendTransactions.js @@ -2,7 +2,7 @@ var firstAccount = web3.eth.accounts[0] var secondAccount = web3.eth.accounts[1] var thirdAccount = web3.eth.accounts[2] -for (var i = 0; i < 3; i++) { +for (var i = 0; i < 1; i++) { console.log('\t\t' + (i + 1) + ' - Transactions') web3.eth.sendTransaction({ from: web3.eth.accounts[0],