getallblocks now returns a data structure

This commit is contained in:
Tim Williams 2018-04-16 14:37:08 -04:00
parent 0f7c72f669
commit 37f48c0f73
2 changed files with 13 additions and 9 deletions

View file

@ -910,7 +910,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
if err := shyftdb.WriteBlock(bc.blockExplorerDb, block); err != nil { if err := shyftdb.WriteBlock(bc.blockExplorerDb, block); err != nil {
return NonStatTy, err return NonStatTy, err
} }
//shyftdb.GetAllBlocks(bc.blockExplorerDb) //fmt.Println(shyftdb.GetAllBlocks(bc.blockExplorerDb))
//result := shyftdb.GetBlock(bc.blockExplorerDb, block) //result := shyftdb.GetBlock(bc.blockExplorerDb, block)
// this is WIP for decoding bytes rather than hex strings // this is WIP for decoding bytes rather than hex strings

View file

@ -11,6 +11,11 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
type SBlock struct {
hash string
txes []string
}
func WriteBlock(db *leveldb.DB, block *types.Block) error { func WriteBlock(db *leveldb.DB, block *types.Block) error {
leng := block.Transactions().Len() leng := block.Transactions().Len()
var tx_strs = make([]string, leng) var tx_strs = make([]string, leng)
@ -59,27 +64,26 @@ func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockH
} }
// Meant for internal tests // Meant for internal tests
func GetAllBlocks(db *leveldb.DB) { func GetAllBlocks(db *leveldb.DB) []SBlock{
var arr []SBlock
iter := db.NewIterator(util.BytesPrefix([]byte("bk-")), nil) iter := db.NewIterator(util.BytesPrefix([]byte("bk-")), nil)
for iter.Next() { for iter.Next() {
result := iter.Value() result := iter.Value()
buf := bytes.NewBuffer(result) buf := bytes.NewBuffer(result)
strs2 := []string{} strs2 := []string{}
gob.NewDecoder(buf).Decode(&strs2) gob.NewDecoder(buf).Decode(&strs2)
fmt.Println("the key is") //fmt.Println("the key is")
hash := common.BytesToHash(iter.Key()) hash := common.BytesToHash(iter.Key())
hex := hash.Hex() hex := hash.Hex()
fmt.Println(hex) //fmt.Println(hex)
if(len(strs2) > 0){ sblock := SBlock{hex, strs2}
fmt.Println("ALL TRANSACTIONS:") arr = append(arr, sblock)
fmt.Printf("%v", strs2)
fmt.Println("")
}
//fmt.Println("\n ALL BK BK VALUE" + string(result)) //fmt.Println("\n ALL BK BK VALUE" + string(result))
} }
iter.Release() iter.Release()
return arr
} }
func GetBlock(db *leveldb.DB, block *types.Block) []byte { func GetBlock(db *leveldb.DB, block *types.Block) []byte {