mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
add custom tx method From()
This commit is contained in:
parent
75e452e2d9
commit
c697b3d097
2 changed files with 34 additions and 42 deletions
|
|
@ -195,6 +195,22 @@ func (tx *Transaction) To() *common.Address {
|
||||||
return &to
|
return &to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@NOTE:SHYFT - Custom function to require FROM
|
||||||
|
func (tx *Transaction) From() *common.Address {
|
||||||
|
if tx.data.V != nil {
|
||||||
|
// make a best guess about the signer and use that to derive
|
||||||
|
// the sender.
|
||||||
|
signer := deriveSigner(tx.data.V)
|
||||||
|
if from, err := Sender(signer, tx); err != nil { // derive but don't cache
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return &from
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hash hashes the RLP encoding of tx.
|
// Hash hashes the RLP encoding of tx.
|
||||||
// It uniquely identifies the transaction.
|
// It uniquely identifies the transaction.
|
||||||
func (tx *Transaction) Hash() common.Hash {
|
func (tx *Transaction) Hash() common.Hash {
|
||||||
|
|
|
||||||
|
|
@ -32,15 +32,8 @@ func WriteBlock(db *leveldb.DB, block *types.Block) error {
|
||||||
|
|
||||||
hash := block.Header().Hash().Bytes()
|
hash := block.Header().Hash().Bytes()
|
||||||
if block.Transactions().Len() > 0 {
|
if block.Transactions().Len() > 0 {
|
||||||
// this is inefficient, there are 2 loops over
|
|
||||||
// block.Transactions
|
|
||||||
// TODO: Fix this so there is only one loop
|
|
||||||
WriteTransactions(db, block.Transactions(), hash)
|
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
fmt.Println(tx.Hash())
|
tx_strs[i] = WriteTransactions(db, tx, hash)
|
||||||
fmt.Println("TX HASH")
|
|
||||||
fmt.Println(tx.To().Hex())
|
|
||||||
tx_strs[i] = tx.Hash().String()
|
|
||||||
//tx_bytes[i] = tx.Hash().Bytes()
|
//tx_bytes[i] = tx.Hash().Bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,13 +53,11 @@ func WriteBlock(db *leveldb.DB, block *types.Block) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockHash []byte) error {
|
func WriteTransactions(db *leveldb.DB, tx *types.Transaction, blockHash []byte) string {
|
||||||
for _, tx := range transactions {
|
|
||||||
var from = GenerateFromAddr()
|
|
||||||
txData := txEntry{
|
txData := txEntry{
|
||||||
TxHash: tx.Hash(),
|
TxHash: tx.Hash(),
|
||||||
To: tx.To(),
|
To: tx.To(),
|
||||||
From: from,
|
From: tx.From(),
|
||||||
BlockHash: blockHash,
|
BlockHash: blockHash,
|
||||||
Amount: tx.Value(),
|
Amount: tx.Value(),
|
||||||
GasPrice: tx.GasPrice(),
|
GasPrice: tx.GasPrice(),
|
||||||
|
|
@ -79,22 +70,7 @@ func WriteTransactions(db *leveldb.DB, transactions []*types.Transaction, blockH
|
||||||
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)
|
||||||
}
|
}
|
||||||
GetTransaction(db, tx)
|
return tx.Hash().String()
|
||||||
}
|
|
||||||
GetAllTransactions(db)
|
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue