From 815733e8661cc47808b052531c15f98825bf0e39 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 16 Apr 2018 12:19:27 -0400 Subject: [PATCH] pre merge --- shyftdb/shyft_database_util.go | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 8c70cea88e..cf17414ec6 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -4,14 +4,25 @@ import ( "fmt" "bytes" "encoding/gob" + "math/big" + "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/util" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/common" ) type txEntry struct { - To + TxHash common.Hash + To *common.Address + From *common.Address + BlockHash []byte + Amount *big.Int + GasPrice *big.Int + Gas uint64 + Nonce uint64 + Data []byte } func WriteBlock(db *leveldb.DB, block *types.Block) error { @@ -37,7 +48,19 @@ func WriteBlock(db *leveldb.DB, block *types.Block) error { func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error { for _, tx := range transactions { - + var from = GenerateFromAddr() + txData := txEntry{ + TxHash: tx.Hash(), + To: tx.To(), + From: from, + BlockHash: blockHash, + Amount: tx.Value(), + GasPrice: tx.GasPrice(), + Gas: tx.Gas(), + Nonce: tx.Nonce(), + Data: tx.Data(), + } + fmt.Println(txData) key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...) if err := db.Put(key, []byte("Hello hello"), nil); err != nil { log.Crit("Failed to store TX", "err", err) @@ -48,6 +71,18 @@ func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockH return nil } +// Helper functions + +func GenerateFromAddr(tx *types.Transaction) *common.Address { + var from *common.Address + signer := deriveSigner(tx.data.V) + if f, err := Sender(signer, tx); err != nil { // derive but don't cache + from = "[invalid sender: invalid sig]" + } else { + from = fmt.Sprintf("%x", f[:]) + } +} + // Meant for internal tests func GetBlock(db *leveldb.DB, block *types.Block) {