Skip to content

Commit

Permalink
Follow up modifications to wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-morlier committed Oct 24, 2024
1 parent d63ef3e commit a76b238
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
17 changes: 13 additions & 4 deletions plugins/wrappers/backendwrapper/backendwrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package backendwrapper
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
"reflect"
Expand Down Expand Up @@ -44,10 +45,16 @@ type Backend struct {
removedLogsOnce sync.Once
chainConfig *params.ChainConfig
}
// TODO AR review addition of db to backend type

func NewBackend(b ethapi.Backend) *Backend {
return &Backend{b: b}
state, _, err := b.StateAndHeaderByNumber(context.Background(), 0)
if err != nil {
panic(err.Error())
}
return &Backend{
b: b,
db: state.Database(),
}
}

func (b *Backend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
Expand Down Expand Up @@ -125,14 +132,16 @@ func (b *Backend) SendTx(ctx context.Context, signedTx []byte) error {
return b.b.SendTx(ctx, tx)
}
func (b *Backend) GetTransaction(ctx context.Context, txHash core.Hash) ([]byte, core.Hash, uint64, uint64, error) { // RLP Encoded transaction {
_, tx, blockHash, blockNumber, index, err := b.b.GetTransaction(ctx, common.Hash(txHash))
found, tx, blockHash, blockNumber, index, err := b.b.GetTransaction(ctx, common.Hash(txHash))
if err != nil {
return nil, core.Hash(blockHash), blockNumber, index, err
}
if !found {
return nil, core.Hash(blockHash), blockNumber, index, errors.New("not found returned from GetTransaction")
}
enc, err := tx.MarshalBinary()
return enc, core.Hash(blockHash), blockNumber, index, err
}
// TODO AR the above internal function signature needs review
func (b *Backend) GetPoolTransactions() ([][]byte, error) {
txs, err := b.b.GetPoolTransactions()
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions plugins/wrappers/backendwrapper/triewrapper.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package backendwrapper

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -30,7 +28,7 @@ func (t *WrappedTrie) GetAccount(address core.Address) (*core.StateAccount, erro
}
return &core.StateAccount{
Nonce: act.Nonce,
Balance: new(big.Int).SetBytes(act.Balance.Bytes()),
Balance: act.Balance.ToBig(),
Root: core.Hash(act.Root),
CodeHash: act.CodeHash,
}, nil
Expand Down
3 changes: 1 addition & 2 deletions plugins/wrappers/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewWrappedStateDB(d *state.StateDB) *WrappedStateDB {

// GetBalance(Address) *big.Int
func (w *WrappedStateDB) GetBalance(addr core.Address) *big.Int {
return new(big.Int).SetBytes(w.s.GetBalance(common.Address(addr)).Bytes())
return w.s.GetBalance(common.Address(addr)).ToBig()
}

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

type Node struct {
n *node.Node
Expand Down

0 comments on commit a76b238

Please sign in to comment.