Skip to content

Commit a76b238

Browse files
Follow up modifications to wrappers
1 parent d63ef3e commit a76b238

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

plugins/wrappers/backendwrapper/backendwrapper.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package backendwrapper
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"math/big"
89
"reflect"
@@ -44,10 +45,16 @@ type Backend struct {
4445
removedLogsOnce sync.Once
4546
chainConfig *params.ChainConfig
4647
}
47-
// TODO AR review addition of db to backend type
4848

4949
func NewBackend(b ethapi.Backend) *Backend {
50-
return &Backend{b: b}
50+
state, _, err := b.StateAndHeaderByNumber(context.Background(), 0)
51+
if err != nil {
52+
panic(err.Error())
53+
}
54+
return &Backend{
55+
b: b,
56+
db: state.Database(),
57+
}
5158
}
5259

5360
func (b *Backend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
@@ -125,14 +132,16 @@ func (b *Backend) SendTx(ctx context.Context, signedTx []byte) error {
125132
return b.b.SendTx(ctx, tx)
126133
}
127134
func (b *Backend) GetTransaction(ctx context.Context, txHash core.Hash) ([]byte, core.Hash, uint64, uint64, error) { // RLP Encoded transaction {
128-
_, tx, blockHash, blockNumber, index, err := b.b.GetTransaction(ctx, common.Hash(txHash))
135+
found, tx, blockHash, blockNumber, index, err := b.b.GetTransaction(ctx, common.Hash(txHash))
129136
if err != nil {
130137
return nil, core.Hash(blockHash), blockNumber, index, err
131138
}
139+
if !found {
140+
return nil, core.Hash(blockHash), blockNumber, index, errors.New("not found returned from GetTransaction")
141+
}
132142
enc, err := tx.MarshalBinary()
133143
return enc, core.Hash(blockHash), blockNumber, index, err
134144
}
135-
// TODO AR the above internal function signature needs review
136145
func (b *Backend) GetPoolTransactions() ([][]byte, error) {
137146
txs, err := b.b.GetPoolTransactions()
138147
if err != nil {

plugins/wrappers/backendwrapper/triewrapper.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package backendwrapper
22

33
import (
4-
"math/big"
5-
64
"github.com/ethereum/go-ethereum/common"
75
"github.com/ethereum/go-ethereum/core/state"
86
"github.com/ethereum/go-ethereum/log"
@@ -30,7 +28,7 @@ func (t *WrappedTrie) GetAccount(address core.Address) (*core.StateAccount, erro
3028
}
3129
return &core.StateAccount{
3230
Nonce: act.Nonce,
33-
Balance: new(big.Int).SetBytes(act.Balance.Bytes()),
31+
Balance: act.Balance.ToBig(),
3432
Root: core.Hash(act.Root),
3533
CodeHash: act.CodeHash,
3634
}, nil

plugins/wrappers/wrappers.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewWrappedStateDB(d *state.StateDB) *WrappedStateDB {
2121

2222
// GetBalance(Address) *big.Int
2323
func (w *WrappedStateDB) GetBalance(addr core.Address) *big.Int {
24-
return new(big.Int).SetBytes(w.s.GetBalance(common.Address(addr)).Bytes())
24+
return w.s.GetBalance(common.Address(addr)).ToBig()
2525
}
2626

2727
// GetNonce(Address) uint64
@@ -97,7 +97,6 @@ func (w *WrappedStateDB) AddBalance(addr core.Address, amount *big.Int) {
9797
castAmount := new(uint256.Int)
9898
w.s.AddBalance(common.Address(addr), castAmount.SetBytes(amount.Bytes()), 0)
9999
}
100-
// TODO AR the above internal function signature needs review
101100

102101
type Node struct {
103102
n *node.Node

0 commit comments

Comments
 (0)