diff --git a/core/blockchain.go b/core/blockchain.go index d3ff0ce2e5..2f94166fec 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -910,6 +910,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. if err := shyftdb.WriteBlock(bc.blockExplorerDb, block); err != nil { return NonStatTy, err } + //fmt.Println(shyftdb.GetAllBlocks(bc.blockExplorerDb)) //result := shyftdb.GetBlock(bc.blockExplorerDb, block) // this is WIP for decoding bytes rather than hex strings diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 8c36b51731..bd338dfa5b 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -9,10 +9,17 @@ import ( "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/util" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/common" ) + +type SBlock struct { + hash string + txes []string +} + type ShyftTxEntry struct { TxHash common.Hash To *common.Address @@ -80,6 +87,27 @@ func WriteTransactions(db *leveldb.DB, tx *types.Transaction, blockHash common.H } // Meant for internal tests +func GetAllBlocks(db *leveldb.DB) []SBlock{ + var arr []SBlock + iter := db.NewIterator(util.BytesPrefix([]byte("bk-")), nil) + for iter.Next() { + result := iter.Value() + buf := bytes.NewBuffer(result) + strs2 := []string{} + gob.NewDecoder(buf).Decode(&strs2) + //fmt.Println("the key is") + hash := common.BytesToHash(iter.Key()) + hex := hash.Hex() + //fmt.Println(hex) + sblock := SBlock{hex, strs2} + arr = append(arr, sblock) + + //fmt.Println("\n ALL BK BK VALUE" + string(result)) + } + + iter.Release() + return arr +} func GetBlock(db *leveldb.DB, block *types.Block) []byte { hash := block.Header().Hash().Bytes()