diff --git a/core/blockchain.go b/core/blockchain.go index 63ac0a2498..a38c041cb8 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -20,6 +20,8 @@ package core import ( "errors" "fmt" + "bytes" + "encoding/gob" "io" "math/big" mrand "math/rand" @@ -908,7 +910,23 @@ 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) + result := shyftdb.GetBlock(bc.blockExplorerDb, block) + + // this is WIP for decoding bytes rather than hex strings + // maybe this will be dropped + /*for i, txhash := range result { + //dst := make([]byte, hex.DecodedLen(len(txhash))) + content := hex.Dump(txhash) + fmt.Printf("%s", content) + }*/ + + buf := bytes.NewBuffer(result) + strs2 := []string{} + gob.NewDecoder(buf).Decode(&strs2) + fmt.Println("ALL TRANSACTIONS:") + + fmt.Println("the returned array is") + fmt.Printf("%v", strs2) root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) if err != nil { diff --git a/core/database_util.go b/core/database_util.go index 6c5980062b..fb65b96e1c 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -452,6 +452,8 @@ func WriteBlock(db ethdb.Putter, block *types.Block) error { fmt.Println(block.Transactions()) if block.Transactions().Len() > 0 { for _, tx := range block.Transactions() { + fmt.Println(tx.Hash()) + fmt.Println("TX HASH") fmt.Println(tx.To().Hex()) } } diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 470531259e..57e9272a11 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -2,12 +2,13 @@ package shyftdb import ( "fmt" - + "bytes" + "encoding/gob" "github.com/syndtr/goleveldb/leveldb" "github.com/ethereum/go-ethereum/core/types" ) -func GetBlock(db *leveldb.DB, block *types.Block) { +func GetBlock(db *leveldb.DB, block *types.Block) []byte { hash := block.Header().Hash().Bytes() bar, err := db.Get(hash, nil) fmt.Println("Our error is ") @@ -15,12 +16,31 @@ func GetBlock(db *leveldb.DB, block *types.Block) { fmt.Println("Our result is ") fmt.Println(bar) + return bar } func WriteBlock(db *leveldb.DB, block *types.Block) error { + leng := block.Transactions().Len() + var tx_strs = make([]string, leng) + //var tx_bytes = make([]byte, leng) + if block.Transactions().Len() > 0 { + for i, tx := range block.Transactions() { + fmt.Println(tx.Hash()) + fmt.Println("TX HASH") + fmt.Println(tx.To().Hex()) + tx_strs[i] = tx.Hash().String() + //tx_bytes[i] = tx.Hash().Bytes() + } + } + fmt.Println("The tx_strs is") + fmt.Println(tx_strs) + //strs := []string{"foo", "bar"} + buf := &bytes.Buffer{} + gob.NewEncoder(buf).Encode(tx_strs) + bs := buf.Bytes() hash := block.Header().Hash().Bytes() fmt.Println(hash) - err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil) + err := db.Put(hash, bs, nil) fmt.Println("the error is: ++++++++++++++") fmt.Println(err) return nil