Tx succesfully stored to db

This commit is contained in:
greg 2018-04-15 17:20:47 -04:00
parent a2d713137c
commit 309c57d39e
2 changed files with 30 additions and 4 deletions

View file

@ -908,7 +908,6 @@ 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.GetBlock(bc.blockExplorerDb, block)
root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number())) root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number()))
if err != nil { if err != nil {

View file

@ -5,6 +5,7 @@ import (
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
) )
func GetBlock(db *leveldb.DB, block *types.Block) { 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 { func WriteBlock(db *leveldb.DB, block *types.Block) error {
hash := block.Header().Hash().Bytes() hash := block.Header().Hash().Bytes()
fmt.Println(hash) fmt.Println(hash)
err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil) if err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil); err != nil {
fmt.Println("the error is: ++++++++++++++") log.Crit("Failed to store block", "err", err)
fmt.Println(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 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)
}
}