mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
pre merge
This commit is contained in:
parent
651691f3c7
commit
815733e866
1 changed files with 37 additions and 2 deletions
|
|
@ -4,14 +4,25 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"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/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type txEntry struct {
|
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 {
|
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 {
|
func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error {
|
||||||
for _, tx := range transactions {
|
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()[:]...)
|
key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...)
|
||||||
if err := db.Put(key, []byte("Hello hello"), nil); err != nil {
|
if err := db.Put(key, []byte("Hello hello"), nil); err != nil {
|
||||||
log.Crit("Failed to store TX", "err", err)
|
log.Crit("Failed to store TX", "err", err)
|
||||||
|
|
@ -48,6 +71,18 @@ func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockH
|
||||||
return nil
|
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
|
// Meant for internal tests
|
||||||
|
|
||||||
func GetBlock(db *leveldb.DB, block *types.Block) {
|
func GetBlock(db *leveldb.DB, block *types.Block) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue