always add eth hash lookup key

pull/3566/head
Rongjian Lan 4 years ago
parent 3dcc92cee5
commit dbcebfaca5
  1. 10
      core/rawdb/accessors_indexes.go
  2. 14
      rpc/eth/types.go

@ -58,12 +58,10 @@ func WriteBlockTxLookUpEntries(db DatabaseWriter, block *types.Block) error {
if err := db.Put(key, val); err != nil { if err := db.Put(key, val); err != nil {
return err return err
} }
if tx.IsEthCompatible() { // Also put a lookup entry for eth transaction's hash
// Also put a lookup entry for eth transaction's hash key = txLookupKey(tx.ConvertToEth().Hash())
key := txLookupKey(tx.HashByType()) if err := db.Put(key, val); err != nil {
if err := db.Put(key, val); err != nil { return err
return err
}
} }
} }
return nil return nil

@ -214,8 +214,8 @@ func NewBlockWithFullTx(b *types.Block, blockArgs *rpc_common.BlockArgs, leader
Transactions: []*Transaction{}, Transactions: []*Transaction{},
} }
for _, tx := range b.Transactions() { for idx, _ := range b.Transactions() {
fmtTx, err := NewTransactionFromBlockHash(b, tx.Hash()) fmtTx, err := NewTransactionFromBlockIndex(b, uint64(idx))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -229,16 +229,6 @@ func NewBlockWithFullTx(b *types.Block, blockArgs *rpc_common.BlockArgs, leader
return blkWithTxs, nil return blkWithTxs, nil
} }
// NewTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
func NewTransactionFromBlockHash(b *types.Block, hash common.Hash) (*Transaction, error) {
for idx, tx := range b.Transactions() {
if tx.Hash() == hash {
return NewTransactionFromBlockIndex(b, uint64(idx))
}
}
return nil, fmt.Errorf("tx %v not found in block %v", hash, b.Hash().String())
}
// NewTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. // NewTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
func NewTransactionFromBlockIndex(b *types.Block, index uint64) (*Transaction, error) { func NewTransactionFromBlockIndex(b *types.Block, index uint64) (*Transaction, error) {
txs := b.Transactions() txs := b.Transactions()

Loading…
Cancel
Save