mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
Tx succesfully stored to db
This commit is contained in:
parent
a2d713137c
commit
309c57d39e
2 changed files with 30 additions and 4 deletions
|
|
@ -908,7 +908,6 @@ 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)
|
||||
|
||||
root, err := state.Commit(bc.chainConfig.IsEIP158(block.Number()))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
||||
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 {
|
||||
hash := block.Header().Hash().Bytes()
|
||||
fmt.Println(hash)
|
||||
err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil)
|
||||
fmt.Println("the error is: ++++++++++++++")
|
||||
fmt.Println(err)
|
||||
if err := db.Put(hash, []byte("GOOD MORNING WORLD"), nil); err != nil {
|
||||
log.Crit("Failed to store block", "err", 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
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue