mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
Merge pull request #5 from ShyftNetwork/get-all-blocks-function
Get all blocks function
This commit is contained in:
commit
d898236c11
2 changed files with 29 additions and 0 deletions
|
|
@ -910,6 +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
|
||||||
}
|
}
|
||||||
|
//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
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,17 @@ import (
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
"github.com/syndtr/goleveldb/leveldb/util"
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
type SBlock struct {
|
||||||
|
hash string
|
||||||
|
txes []string
|
||||||
|
}
|
||||||
|
|
||||||
type ShyftTxEntry struct {
|
type ShyftTxEntry struct {
|
||||||
TxHash common.Hash
|
TxHash common.Hash
|
||||||
To *common.Address
|
To *common.Address
|
||||||
|
|
@ -80,6 +87,27 @@ func WriteTransactions(db *leveldb.DB, tx *types.Transaction, blockHash common.H
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meant for internal tests
|
// 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 {
|
func GetBlock(db *leveldb.DB, block *types.Block) []byte {
|
||||||
hash := block.Header().Hash().Bytes()
|
hash := block.Header().Hash().Bytes()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue