mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
chore(interfaces): use upstream code
- import interfaces from github.com/ava-labs/libevm directly - import `NotFound` error from github.com/ava-labs/libevm directly - Keep our two subnet-evm-specific interfaces at interfaces/interfaces.go See original PR https://github.com/ava-labs/coreth/pull/883
This commit is contained in:
committed by
Quentin Mc Gaw
parent
4f86a8c129
commit
d353bbff3e
@@ -31,9 +31,9 @@ import (
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -64,7 +64,7 @@ type ContractCaller interface {
|
||||
|
||||
// CallContract executes an Ethereum contract call with the specified data as the
|
||||
// input.
|
||||
CallContract(ctx context.Context, call interfaces.CallMsg, blockNumber *big.Int) ([]byte, error)
|
||||
CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
|
||||
}
|
||||
|
||||
// AcceptedContractCaller defines methods to perform contract calls on the pending state.
|
||||
@@ -75,7 +75,7 @@ type AcceptedContractCaller interface {
|
||||
AcceptedCodeAt(ctx context.Context, contract common.Address) ([]byte, error)
|
||||
|
||||
// AcceptedCallContract executes an Ethereum contract call against the accepted state.
|
||||
AcceptedCallContract(ctx context.Context, call interfaces.CallMsg) ([]byte, error)
|
||||
AcceptedCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
|
||||
}
|
||||
|
||||
// BlockHashContractCaller defines methods to perform contract calls on a specific block hash.
|
||||
@@ -86,7 +86,7 @@ type BlockHashContractCaller interface {
|
||||
CodeAtHash(ctx context.Context, contract common.Address, blockHash common.Hash) ([]byte, error)
|
||||
|
||||
// CallContractAtHash executes an Ethereum contract call against the state at the specified block hash.
|
||||
CallContractAtHash(ctx context.Context, call interfaces.CallMsg, blockHash common.Hash) ([]byte, error)
|
||||
CallContractAtHash(ctx context.Context, call ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
|
||||
}
|
||||
|
||||
// ContractTransactor defines the methods needed to allow operating with a contract
|
||||
@@ -94,10 +94,10 @@ type BlockHashContractCaller interface {
|
||||
// used when the user does not provide some needed values, but rather leaves it up
|
||||
// to the transactor to decide.
|
||||
type ContractTransactor interface {
|
||||
interfaces.GasEstimator
|
||||
interfaces.GasPricer
|
||||
interfaces.GasPricer1559
|
||||
interfaces.TransactionSender
|
||||
ethereum.GasEstimator
|
||||
ethereum.GasPricer
|
||||
ethereum.GasPricer1559
|
||||
ethereum.TransactionSender
|
||||
|
||||
// HeaderByNumber returns a block header from the current canonical chain. If
|
||||
// number is nil, the latest known header is returned.
|
||||
@@ -119,7 +119,7 @@ type DeployBackend interface {
|
||||
// ContractFilterer defines the methods needed to access log events using one-off
|
||||
// queries or continuous event subscriptions.
|
||||
type ContractFilterer interface {
|
||||
interfaces.LogFilterer
|
||||
ethereum.LogFilterer
|
||||
}
|
||||
|
||||
// ContractBackend defines the methods needed to work with contracts on a read-write basis.
|
||||
|
||||
@@ -29,6 +29,7 @@ package backends
|
||||
import (
|
||||
"context"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
|
||||
@@ -42,14 +43,14 @@ var (
|
||||
_ bind.ContractBackend = (*SimulatedBackend)(nil)
|
||||
_ bind.DeployBackend = (*SimulatedBackend)(nil)
|
||||
|
||||
_ interfaces.ChainReader = (*SimulatedBackend)(nil)
|
||||
_ interfaces.ChainStateReader = (*SimulatedBackend)(nil)
|
||||
_ interfaces.TransactionReader = (*SimulatedBackend)(nil)
|
||||
_ interfaces.TransactionSender = (*SimulatedBackend)(nil)
|
||||
_ interfaces.ContractCaller = (*SimulatedBackend)(nil)
|
||||
_ interfaces.GasEstimator = (*SimulatedBackend)(nil)
|
||||
_ interfaces.GasPricer = (*SimulatedBackend)(nil)
|
||||
_ interfaces.LogFilterer = (*SimulatedBackend)(nil)
|
||||
_ ethereum.ChainReader = (*SimulatedBackend)(nil)
|
||||
_ ethereum.ChainStateReader = (*SimulatedBackend)(nil)
|
||||
_ ethereum.TransactionReader = (*SimulatedBackend)(nil)
|
||||
_ ethereum.TransactionSender = (*SimulatedBackend)(nil)
|
||||
_ ethereum.ContractCaller = (*SimulatedBackend)(nil)
|
||||
_ ethereum.GasEstimator = (*SimulatedBackend)(nil)
|
||||
_ ethereum.GasPricer = (*SimulatedBackend)(nil)
|
||||
_ ethereum.LogFilterer = (*SimulatedBackend)(nil)
|
||||
_ interfaces.AcceptedStateReader = (*SimulatedBackend)(nil)
|
||||
_ interfaces.AcceptedContractCaller = (*SimulatedBackend)(nil)
|
||||
)
|
||||
|
||||
@@ -34,12 +34,12 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/libevm/crypto"
|
||||
"github.com/ava-labs/libevm/event"
|
||||
"github.com/ava-labs/subnet-evm/accounts/abi"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/rpc"
|
||||
)
|
||||
|
||||
@@ -179,7 +179,7 @@ func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method stri
|
||||
return err
|
||||
}
|
||||
var (
|
||||
msg = interfaces.CallMsg{From: opts.From, To: &c.address, Data: input}
|
||||
msg = ethereum.CallMsg{From: opts.From, To: &c.address, Data: input}
|
||||
ctx = ensureContext(opts.Context)
|
||||
code []byte
|
||||
output []byte
|
||||
@@ -374,7 +374,7 @@ func (c *BoundContract) estimateGasLimit(opts *TransactOpts, contract *common.Ad
|
||||
return 0, ErrNoCode
|
||||
}
|
||||
}
|
||||
msg := interfaces.CallMsg{
|
||||
msg := ethereum.CallMsg{
|
||||
From: opts.From,
|
||||
To: contract,
|
||||
GasPrice: gasPrice,
|
||||
@@ -458,7 +458,7 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int
|
||||
// Start the background filtering
|
||||
logs := make(chan types.Log, 128)
|
||||
|
||||
config := interfaces.FilterQuery{
|
||||
config := ethereum.FilterQuery{
|
||||
Addresses: []common.Address{c.address},
|
||||
Topics: topics,
|
||||
FromBlock: new(big.Int).SetUint64(opts.Start),
|
||||
@@ -507,7 +507,7 @@ func (c *BoundContract) WatchLogs(opts *WatchOpts, name string, query ...[]inter
|
||||
// Start the background filtering
|
||||
logs := make(chan types.Log, 128)
|
||||
|
||||
config := interfaces.FilterQuery{
|
||||
config := ethereum.FilterQuery{
|
||||
Addresses: []common.Address{c.address},
|
||||
Topics: topics,
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/common/hexutil"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
@@ -41,7 +42,6 @@ import (
|
||||
"github.com/ava-labs/libevm/rlp"
|
||||
"github.com/ava-labs/subnet-evm/accounts/abi"
|
||||
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -77,7 +77,7 @@ func (mt *mockTransactor) SuggestGasTipCap(ctx context.Context) (*big.Int, error
|
||||
return mt.gasTipCap, nil
|
||||
}
|
||||
|
||||
func (mt *mockTransactor) EstimateGas(ctx context.Context, call interfaces.CallMsg) (gas uint64, err error) {
|
||||
func (mt *mockTransactor) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (mc *mockCaller) CodeAt(ctx context.Context, contract common.Address, block
|
||||
return mc.codeAtBytes, mc.codeAtErr
|
||||
}
|
||||
|
||||
func (mc *mockCaller) CallContract(ctx context.Context, call interfaces.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
||||
func (mc *mockCaller) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
||||
mc.callContractBlockNumber = blockNumber
|
||||
return mc.callContractBytes, mc.callContractErr
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (mc *mockAcceptedCaller) AcceptedCodeAt(ctx context.Context, contract commo
|
||||
return mc.acceptedCodeAtBytes, mc.acceptedCodeAtErr
|
||||
}
|
||||
|
||||
func (mc *mockAcceptedCaller) AcceptedCallContract(ctx context.Context, call interfaces.CallMsg) ([]byte, error) {
|
||||
func (mc *mockAcceptedCaller) AcceptedCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error) {
|
||||
mc.acceptedCallContractCalled = true
|
||||
return mc.acceptedCallContractBytes, mc.acceptedCallContractErr
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func (mc *mockBlockHashCaller) CodeAtHash(ctx context.Context, contract common.A
|
||||
return mc.codeAtHashBytes, mc.codeAtHashErr
|
||||
}
|
||||
|
||||
func (mc *mockBlockHashCaller) CallContractAtHash(ctx context.Context, call interfaces.CallMsg, hash common.Hash) ([]byte, error) {
|
||||
func (mc *mockBlockHashCaller) CallContractAtHash(ctx context.Context, call ethereum.CallMsg, hash common.Hash) ([]byte, error) {
|
||||
mc.callContractAtHashCalled = true
|
||||
return mc.callContractAtHashBytes, mc.callContractAtHashErr
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ import (
|
||||
"github.com/ava-labs/subnet-evm/accounts/abi"
|
||||
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/event"
|
||||
)
|
||||
@@ -114,7 +114,7 @@ var (
|
||||
_ = errors.New
|
||||
_ = big.NewInt
|
||||
_ = strings.NewReader
|
||||
_ = interfaces.NotFound
|
||||
_ = ethereum.NotFound
|
||||
_ = bind.Bind
|
||||
_ = common.Big1
|
||||
_ = types.BloomLookup
|
||||
@@ -443,7 +443,7 @@ var (
|
||||
event string // Event name to use for unpacking event data
|
||||
|
||||
logs chan types.Log // Log channel receiving the found contract events
|
||||
sub interfaces.Subscription // Subscription for errors, completion and termination
|
||||
sub ethereum.Subscription // Subscription for errors, completion and termination
|
||||
done bool // Whether the subscription completed delivering logs
|
||||
fail error // Occurred error to stop iteration
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/libevm/log"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
)
|
||||
|
||||
// WaitMined waits for tx to be mined on the blockchain.
|
||||
@@ -50,7 +50,7 @@ func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*ty
|
||||
return receipt, nil
|
||||
}
|
||||
|
||||
if errors.Is(err, interfaces.NotFound) {
|
||||
if errors.Is(err, ethereum.NotFound) {
|
||||
logger.Trace("Transaction not yet mined")
|
||||
} else {
|
||||
logger.Trace("Receipt retrieval failed", "err", err)
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/libevm/log"
|
||||
"github.com/ava-labs/subnet-evm/ethclient"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
)
|
||||
|
||||
type ethereumTxWorker struct {
|
||||
@@ -21,7 +21,7 @@ type ethereumTxWorker struct {
|
||||
acceptedNonce uint64
|
||||
address common.Address
|
||||
|
||||
sub interfaces.Subscription
|
||||
sub ethereum.Subscription
|
||||
newHeads chan *types.Header
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -35,11 +35,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/common/hexutil"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/libevm/event"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/internal/ethapi"
|
||||
"github.com/ava-labs/subnet-evm/rpc"
|
||||
)
|
||||
@@ -333,12 +333,12 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
|
||||
)
|
||||
|
||||
if api.sys.backend.IsAllowUnfinalizedQueries() {
|
||||
logsSub, err = api.events.SubscribeLogs(interfaces.FilterQuery(crit), matchedLogs)
|
||||
logsSub, err = api.events.SubscribeLogs(ethereum.FilterQuery(crit), matchedLogs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
logsSub, err = api.events.SubscribeAcceptedLogs(interfaces.FilterQuery(crit), matchedLogs)
|
||||
logsSub, err = api.events.SubscribeAcceptedLogs(ethereum.FilterQuery(crit), matchedLogs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -364,8 +364,8 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
|
||||
}
|
||||
|
||||
// FilterCriteria represents a request to create a new filter.
|
||||
// Same as interfaces.FilterQuery but with UnmarshalJSON() method.
|
||||
type FilterCriteria interfaces.FilterQuery
|
||||
// Same as [ethereum.FilterQuery] with the method [FilterCriteria.UnmarshalJSON].
|
||||
type FilterCriteria ethereum.FilterQuery
|
||||
|
||||
// NewFilter creates a new filter and returns the filter id. It can be
|
||||
// used to retrieve logs when the state changes. This method cannot be
|
||||
@@ -386,12 +386,12 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
|
||||
)
|
||||
|
||||
if api.sys.backend.IsAllowUnfinalizedQueries() {
|
||||
logsSub, err = api.events.SubscribeLogs(interfaces.FilterQuery(crit), logs)
|
||||
logsSub, err = api.events.SubscribeLogs(ethereum.FilterQuery(crit), logs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
logsSub, err = api.events.SubscribeAcceptedLogs(interfaces.FilterQuery(crit), logs)
|
||||
logsSub, err = api.events.SubscribeAcceptedLogs(ethereum.FilterQuery(crit), logs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/libevm/ethdb"
|
||||
@@ -41,7 +42,6 @@ import (
|
||||
"github.com/ava-labs/libevm/log"
|
||||
"github.com/ava-labs/subnet-evm/core"
|
||||
"github.com/ava-labs/subnet-evm/core/bloombits"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/params"
|
||||
"github.com/ava-labs/subnet-evm/rpc"
|
||||
)
|
||||
@@ -162,7 +162,7 @@ type subscription struct {
|
||||
id rpc.ID
|
||||
typ Type
|
||||
created time.Time
|
||||
logsCrit interfaces.FilterQuery
|
||||
logsCrit ethereum.FilterQuery
|
||||
logs chan []*types.Log
|
||||
txs chan []*types.Transaction
|
||||
headers chan *types.Header
|
||||
@@ -288,7 +288,7 @@ func (es *EventSystem) subscribe(sub *subscription) *Subscription {
|
||||
// SubscribeLogs creates a subscription that will write all logs matching the
|
||||
// given criteria to the given logs channel. Default value for the from and to
|
||||
// block is "latest". If the fromBlock > toBlock an error is returned.
|
||||
func (es *EventSystem) SubscribeLogs(crit interfaces.FilterQuery, logs chan []*types.Log) (*Subscription, error) {
|
||||
func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*types.Log) (*Subscription, error) {
|
||||
if len(crit.Topics) > maxTopics {
|
||||
return nil, errExceedMaxTopics
|
||||
}
|
||||
@@ -327,7 +327,7 @@ func (es *EventSystem) SubscribeLogs(crit interfaces.FilterQuery, logs chan []*t
|
||||
return nil, errInvalidBlockRange
|
||||
}
|
||||
|
||||
func (es *EventSystem) SubscribeAcceptedLogs(crit interfaces.FilterQuery, logs chan []*types.Log) (*Subscription, error) {
|
||||
func (es *EventSystem) SubscribeAcceptedLogs(crit ethereum.FilterQuery, logs chan []*types.Log) (*Subscription, error) {
|
||||
var from, to rpc.BlockNumber
|
||||
if crit.FromBlock == nil {
|
||||
from = rpc.LatestBlockNumber
|
||||
@@ -352,7 +352,7 @@ func (es *EventSystem) SubscribeAcceptedLogs(crit interfaces.FilterQuery, logs c
|
||||
return nil, fmt.Errorf("invalid from and to block combination: from > to")
|
||||
}
|
||||
|
||||
func (es *EventSystem) subscribeAcceptedLogs(crit interfaces.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
func (es *EventSystem) subscribeAcceptedLogs(crit ethereum.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
sub := &subscription{
|
||||
id: rpc.NewID(),
|
||||
typ: AcceptedLogsSubscription,
|
||||
@@ -369,7 +369,7 @@ func (es *EventSystem) subscribeAcceptedLogs(crit interfaces.FilterQuery, logs c
|
||||
|
||||
// subscribeMinedPendingLogs creates a subscription that returned mined and
|
||||
// pending logs that match the given criteria.
|
||||
func (es *EventSystem) subscribeMinedPendingLogs(crit interfaces.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
func (es *EventSystem) subscribeMinedPendingLogs(crit ethereum.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
sub := &subscription{
|
||||
id: rpc.NewID(),
|
||||
typ: MinedAndPendingLogsSubscription,
|
||||
@@ -386,7 +386,7 @@ func (es *EventSystem) subscribeMinedPendingLogs(crit interfaces.FilterQuery, lo
|
||||
|
||||
// subscribeLogs creates a subscription that will write all logs matching the
|
||||
// given criteria to the given logs channel.
|
||||
func (es *EventSystem) subscribeLogs(crit interfaces.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
func (es *EventSystem) subscribeLogs(crit ethereum.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
sub := &subscription{
|
||||
id: rpc.NewID(),
|
||||
typ: LogsSubscription,
|
||||
@@ -403,7 +403,7 @@ func (es *EventSystem) subscribeLogs(crit interfaces.FilterQuery, logs chan []*t
|
||||
|
||||
// subscribePendingLogs creates a subscription that writes contract event logs for
|
||||
// transactions that enter the transaction pool.
|
||||
func (es *EventSystem) subscribePendingLogs(crit interfaces.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
func (es *EventSystem) subscribePendingLogs(crit ethereum.FilterQuery, logs chan []*types.Log) *Subscription {
|
||||
sub := &subscription{
|
||||
id: rpc.NewID(),
|
||||
typ: PendingLogsSubscription,
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/rawdb"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
@@ -45,7 +46,6 @@ import (
|
||||
"github.com/ava-labs/subnet-evm/consensus/dummy"
|
||||
"github.com/ava-labs/subnet-evm/core"
|
||||
"github.com/ava-labs/subnet-evm/core/bloombits"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/internal/ethapi"
|
||||
"github.com/ava-labs/subnet-evm/params"
|
||||
"github.com/ava-labs/subnet-evm/plugin/evm/customrawdb"
|
||||
@@ -659,7 +659,7 @@ func TestPendingLogsSubscription(t *testing.T) {
|
||||
pendingBlockNumber = big.NewInt(rpc.PendingBlockNumber.Int64())
|
||||
|
||||
testCases = []struct {
|
||||
crit interfaces.FilterQuery
|
||||
crit ethereum.FilterQuery
|
||||
expected []*types.Log
|
||||
c chan []*types.Log
|
||||
sub *Subscription
|
||||
@@ -667,67 +667,67 @@ func TestPendingLogsSubscription(t *testing.T) {
|
||||
}{
|
||||
// match all
|
||||
{
|
||||
interfaces.FilterQuery{FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
flattenLogs(allLogs),
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match none due to no matching addresses
|
||||
{
|
||||
interfaces.FilterQuery{Addresses: []common.Address{{}, notUsedAddress}, Topics: [][]common.Hash{nil}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{Addresses: []common.Address{{}, notUsedAddress}, Topics: [][]common.Hash{nil}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
nil,
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match logs based on addresses, ignore topics
|
||||
{
|
||||
interfaces.FilterQuery{Addresses: []common.Address{firstAddr}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{Addresses: []common.Address{firstAddr}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
append(flattenLogs(allLogs[:2]), allLogs[5][3]),
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match none due to no matching topics (match with address)
|
||||
{
|
||||
interfaces.FilterQuery{Addresses: []common.Address{secondAddr}, Topics: [][]common.Hash{{notUsedTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{Addresses: []common.Address{secondAddr}, Topics: [][]common.Hash{{notUsedTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
nil,
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match logs based on addresses and topics
|
||||
{
|
||||
interfaces.FilterQuery{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{{firstTopic, secondTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{{firstTopic, secondTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
append(flattenLogs(allLogs[3:5]), allLogs[5][0]),
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match logs based on multiple addresses and "or" topics
|
||||
{
|
||||
interfaces.FilterQuery{Addresses: []common.Address{secondAddr, thirdAddress}, Topics: [][]common.Hash{{firstTopic, secondTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{Addresses: []common.Address{secondAddr, thirdAddress}, Topics: [][]common.Hash{{firstTopic, secondTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
append(flattenLogs(allLogs[2:5]), allLogs[5][0]),
|
||||
nil, nil, nil,
|
||||
},
|
||||
// multiple pending logs, should match only 2 topics from the logs in block 5
|
||||
{
|
||||
interfaces.FilterQuery{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{{firstTopic, fourthTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
ethereum.FilterQuery{Addresses: []common.Address{thirdAddress}, Topics: [][]common.Hash{{firstTopic, fourthTopic}}, FromBlock: pendingBlockNumber, ToBlock: pendingBlockNumber},
|
||||
[]*types.Log{allLogs[5][0], allLogs[5][2]},
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match none due to only matching new mined logs
|
||||
{
|
||||
interfaces.FilterQuery{},
|
||||
ethereum.FilterQuery{},
|
||||
nil,
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match none due to only matching mined logs within a specific block range
|
||||
{
|
||||
interfaces.FilterQuery{FromBlock: big.NewInt(1), ToBlock: big.NewInt(2)},
|
||||
ethereum.FilterQuery{FromBlock: big.NewInt(1), ToBlock: big.NewInt(2)},
|
||||
nil,
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match all due to matching mined and pending logs
|
||||
{
|
||||
interfaces.FilterQuery{FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64()), ToBlock: big.NewInt(rpc.PendingBlockNumber.Int64())},
|
||||
ethereum.FilterQuery{FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64()), ToBlock: big.NewInt(rpc.PendingBlockNumber.Int64())},
|
||||
flattenLogs(allLogs),
|
||||
nil, nil, nil,
|
||||
},
|
||||
// match none due to matching logs from a specific block number to new mined blocks
|
||||
{
|
||||
interfaces.FilterQuery{FromBlock: big.NewInt(1), ToBlock: big.NewInt(rpc.LatestBlockNumber.Int64())},
|
||||
ethereum.FilterQuery{FromBlock: big.NewInt(1), ToBlock: big.NewInt(rpc.LatestBlockNumber.Int64())},
|
||||
nil,
|
||||
nil, nil, nil,
|
||||
},
|
||||
|
||||
+39
-38
@@ -34,6 +34,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/common/hexutil"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
@@ -54,14 +55,14 @@ var (
|
||||
_ bind.ContractTransactor = (*client)(nil)
|
||||
_ bind.DeployBackend = (*client)(nil)
|
||||
|
||||
_ interfaces.ChainReader = (*client)(nil)
|
||||
_ interfaces.ChainStateReader = (*client)(nil)
|
||||
_ interfaces.TransactionReader = (*client)(nil)
|
||||
_ interfaces.TransactionSender = (*client)(nil)
|
||||
_ interfaces.ContractCaller = (*client)(nil)
|
||||
_ interfaces.GasEstimator = (*client)(nil)
|
||||
_ interfaces.GasPricer = (*client)(nil)
|
||||
_ interfaces.LogFilterer = (*client)(nil)
|
||||
_ ethereum.ChainReader = (*client)(nil)
|
||||
_ ethereum.ChainStateReader = (*client)(nil)
|
||||
_ ethereum.TransactionReader = (*client)(nil)
|
||||
_ ethereum.TransactionSender = (*client)(nil)
|
||||
_ ethereum.ContractCaller = (*client)(nil)
|
||||
_ ethereum.GasEstimator = (*client)(nil)
|
||||
_ ethereum.GasPricer = (*client)(nil)
|
||||
_ ethereum.LogFilterer = (*client)(nil)
|
||||
_ interfaces.AcceptedStateReader = (*client)(nil)
|
||||
_ interfaces.AcceptedContractCaller = (*client)(nil)
|
||||
|
||||
@@ -86,9 +87,9 @@ type Client interface {
|
||||
TransactionInBlock(context.Context, common.Hash, uint) (*types.Transaction, error)
|
||||
TransactionReceipt(context.Context, common.Hash) (*types.Receipt, error)
|
||||
SyncProgress(ctx context.Context) error
|
||||
SubscribeNewAcceptedTransactions(context.Context, chan<- *common.Hash) (interfaces.Subscription, error)
|
||||
SubscribeNewPendingTransactions(context.Context, chan<- *common.Hash) (interfaces.Subscription, error)
|
||||
SubscribeNewHead(context.Context, chan<- *types.Header) (interfaces.Subscription, error)
|
||||
SubscribeNewAcceptedTransactions(context.Context, chan<- *common.Hash) (ethereum.Subscription, error)
|
||||
SubscribeNewPendingTransactions(context.Context, chan<- *common.Hash) (ethereum.Subscription, error)
|
||||
SubscribeNewHead(context.Context, chan<- *types.Header) (ethereum.Subscription, error)
|
||||
NetworkID(context.Context) (*big.Int, error)
|
||||
BalanceAt(context.Context, common.Address, *big.Int) (*big.Int, error)
|
||||
BalanceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (*big.Int, error)
|
||||
@@ -98,17 +99,17 @@ type Client interface {
|
||||
CodeAtHash(ctx context.Context, account common.Address, blockHash common.Hash) ([]byte, error)
|
||||
NonceAt(context.Context, common.Address, *big.Int) (uint64, error)
|
||||
NonceAtHash(ctx context.Context, account common.Address, blockHash common.Hash) (uint64, error)
|
||||
FilterLogs(context.Context, interfaces.FilterQuery) ([]types.Log, error)
|
||||
SubscribeFilterLogs(context.Context, interfaces.FilterQuery, chan<- types.Log) (interfaces.Subscription, error)
|
||||
FilterLogs(context.Context, ethereum.FilterQuery) ([]types.Log, error)
|
||||
SubscribeFilterLogs(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)
|
||||
AcceptedCodeAt(context.Context, common.Address) ([]byte, error)
|
||||
AcceptedNonceAt(context.Context, common.Address) (uint64, error)
|
||||
AcceptedCallContract(context.Context, interfaces.CallMsg) ([]byte, error)
|
||||
CallContract(context.Context, interfaces.CallMsg, *big.Int) ([]byte, error)
|
||||
CallContractAtHash(ctx context.Context, msg interfaces.CallMsg, blockHash common.Hash) ([]byte, error)
|
||||
AcceptedCallContract(context.Context, ethereum.CallMsg) ([]byte, error)
|
||||
CallContract(context.Context, ethereum.CallMsg, *big.Int) ([]byte, error)
|
||||
CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error)
|
||||
SuggestGasPrice(context.Context) (*big.Int, error)
|
||||
SuggestGasTipCap(context.Context) (*big.Int, error)
|
||||
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*interfaces.FeeHistory, error)
|
||||
EstimateGas(context.Context, interfaces.CallMsg) (uint64, error)
|
||||
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)
|
||||
EstimateGas(context.Context, ethereum.CallMsg) (uint64, error)
|
||||
EstimateBaseFee(context.Context) (*big.Int, error)
|
||||
SendTransaction(context.Context, *types.Transaction) error
|
||||
}
|
||||
@@ -198,7 +199,7 @@ func (ec *client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumb
|
||||
var r []*types.Receipt
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getBlockReceipts", blockNrOrHash.String())
|
||||
if err == nil && r == nil {
|
||||
return nil, interfaces.NotFound
|
||||
return nil, ethereum.NotFound
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
@@ -225,7 +226,7 @@ func (ec *client) getBlock(ctx context.Context, method string, args ...interface
|
||||
}
|
||||
// When the block is not found, the API returns JSON null.
|
||||
if head == nil {
|
||||
return nil, interfaces.NotFound
|
||||
return nil, ethereum.NotFound
|
||||
}
|
||||
|
||||
var body rpcBlock
|
||||
@@ -289,7 +290,7 @@ func (ec *client) HeaderByHash(ctx context.Context, hash common.Hash) (*types.He
|
||||
var head *types.Header
|
||||
err := ec.c.CallContext(ctx, &head, "eth_getBlockByHash", hash, false)
|
||||
if err == nil && head == nil {
|
||||
err = interfaces.NotFound
|
||||
err = ethereum.NotFound
|
||||
}
|
||||
return head, err
|
||||
}
|
||||
@@ -300,7 +301,7 @@ func (ec *client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.H
|
||||
var head *types.Header
|
||||
err := ec.c.CallContext(ctx, &head, "eth_getBlockByNumber", ToBlockNumArg(number), false)
|
||||
if err == nil && head == nil {
|
||||
err = interfaces.NotFound
|
||||
err = ethereum.NotFound
|
||||
}
|
||||
return head, err
|
||||
}
|
||||
@@ -330,7 +331,7 @@ func (ec *client) TransactionByHash(ctx context.Context, hash common.Hash) (tx *
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
} else if json == nil {
|
||||
return nil, false, interfaces.NotFound
|
||||
return nil, false, ethereum.NotFound
|
||||
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
|
||||
return nil, false, errors.New("server returned transaction without signature")
|
||||
}
|
||||
@@ -382,7 +383,7 @@ func (ec *client) TransactionInBlock(ctx context.Context, blockHash common.Hash,
|
||||
return nil, err
|
||||
}
|
||||
if json == nil {
|
||||
return nil, interfaces.NotFound
|
||||
return nil, ethereum.NotFound
|
||||
} else if _, r, _ := json.tx.RawSignatureValues(); r == nil {
|
||||
return nil, errors.New("server returned transaction without signature")
|
||||
}
|
||||
@@ -398,7 +399,7 @@ func (ec *client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*
|
||||
var r *types.Receipt
|
||||
err := ec.c.CallContext(ctx, &r, "eth_getTransactionReceipt", txHash)
|
||||
if err == nil && r == nil {
|
||||
return nil, interfaces.NotFound
|
||||
return nil, ethereum.NotFound
|
||||
}
|
||||
return r, err
|
||||
}
|
||||
@@ -422,7 +423,7 @@ func (ec *client) SyncProgress(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// SubscribeNewAcceptedTransactions subscribes to notifications about the accepted transaction hashes on the given channel.
|
||||
func (ec *client) SubscribeNewAcceptedTransactions(ctx context.Context, ch chan<- *common.Hash) (interfaces.Subscription, error) {
|
||||
func (ec *client) SubscribeNewAcceptedTransactions(ctx context.Context, ch chan<- *common.Hash) (ethereum.Subscription, error) {
|
||||
sub, err := ec.c.EthSubscribe(ctx, ch, "newAcceptedTransactions")
|
||||
if err != nil {
|
||||
// Defensively prefer returning nil interface explicitly on error-path, instead
|
||||
@@ -434,7 +435,7 @@ func (ec *client) SubscribeNewAcceptedTransactions(ctx context.Context, ch chan<
|
||||
}
|
||||
|
||||
// SubscribeNewPendingTransactions subscribes to notifications about the pending transaction hashes on the given channel.
|
||||
func (ec *client) SubscribeNewPendingTransactions(ctx context.Context, ch chan<- *common.Hash) (interfaces.Subscription, error) {
|
||||
func (ec *client) SubscribeNewPendingTransactions(ctx context.Context, ch chan<- *common.Hash) (ethereum.Subscription, error) {
|
||||
sub, err := ec.c.EthSubscribe(ctx, ch, "newPendingTransactions")
|
||||
if err != nil {
|
||||
// Defensively prefer returning nil interface explicitly on error-path, instead
|
||||
@@ -447,7 +448,7 @@ func (ec *client) SubscribeNewPendingTransactions(ctx context.Context, ch chan<-
|
||||
|
||||
// SubscribeNewHead subscribes to notifications about the current blockchain head
|
||||
// on the given channel.
|
||||
func (ec *client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (interfaces.Subscription, error) {
|
||||
func (ec *client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) {
|
||||
sub, err := ec.c.EthSubscribe(ctx, ch, "newHeads")
|
||||
if err != nil {
|
||||
// Defensively prefer returning nil interface explicitly on error-path, instead
|
||||
@@ -536,7 +537,7 @@ func (ec *client) NonceAtHash(ctx context.Context, account common.Address, block
|
||||
// Filters
|
||||
|
||||
// FilterLogs executes a filter query.
|
||||
func (ec *client) FilterLogs(ctx context.Context, q interfaces.FilterQuery) ([]types.Log, error) {
|
||||
func (ec *client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error) {
|
||||
var result []types.Log
|
||||
arg, err := toFilterArg(q)
|
||||
if err != nil {
|
||||
@@ -547,7 +548,7 @@ func (ec *client) FilterLogs(ctx context.Context, q interfaces.FilterQuery) ([]t
|
||||
}
|
||||
|
||||
// SubscribeFilterLogs subscribes to the results of a streaming filter query.
|
||||
func (ec *client) SubscribeFilterLogs(ctx context.Context, q interfaces.FilterQuery, ch chan<- types.Log) (interfaces.Subscription, error) {
|
||||
func (ec *client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) {
|
||||
arg, err := toFilterArg(q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -562,7 +563,7 @@ func (ec *client) SubscribeFilterLogs(ctx context.Context, q interfaces.FilterQu
|
||||
return sub, nil
|
||||
}
|
||||
|
||||
func toFilterArg(q interfaces.FilterQuery) (interface{}, error) {
|
||||
func toFilterArg(q ethereum.FilterQuery) (interface{}, error) {
|
||||
arg := map[string]interface{}{
|
||||
"address": q.Addresses,
|
||||
"topics": q.Topics,
|
||||
@@ -596,7 +597,7 @@ func (ec *client) AcceptedNonceAt(ctx context.Context, account common.Address) (
|
||||
|
||||
// AcceptedCallContract executes a message call transaction in the accepted
|
||||
// state.
|
||||
func (ec *client) AcceptedCallContract(ctx context.Context, msg interfaces.CallMsg) ([]byte, error) {
|
||||
func (ec *client) AcceptedCallContract(ctx context.Context, msg ethereum.CallMsg) ([]byte, error) {
|
||||
return ec.CallContract(ctx, msg, nil)
|
||||
}
|
||||
|
||||
@@ -608,7 +609,7 @@ func (ec *client) AcceptedCallContract(ctx context.Context, msg interfaces.CallM
|
||||
// blockNumber selects the block height at which the call runs. It can be nil, in which
|
||||
// case the code is taken from the latest known block. Note that state from very old
|
||||
// blocks might not be available.
|
||||
func (ec *client) CallContract(ctx context.Context, msg interfaces.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
||||
func (ec *client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) {
|
||||
var hex hexutil.Bytes
|
||||
err := ec.c.CallContext(ctx, &hex, "eth_call", toCallArg(msg), ToBlockNumArg(blockNumber))
|
||||
if err != nil {
|
||||
@@ -619,7 +620,7 @@ func (ec *client) CallContract(ctx context.Context, msg interfaces.CallMsg, bloc
|
||||
|
||||
// CallContractAtHash is almost the same as CallContract except that it selects
|
||||
// the block by block hash instead of block height.
|
||||
func (ec *client) CallContractAtHash(ctx context.Context, msg interfaces.CallMsg, blockHash common.Hash) ([]byte, error) {
|
||||
func (ec *client) CallContractAtHash(ctx context.Context, msg ethereum.CallMsg, blockHash common.Hash) ([]byte, error) {
|
||||
var hex hexutil.Bytes
|
||||
err := ec.c.CallContext(ctx, &hex, "eth_call", toCallArg(msg), rpc.BlockNumberOrHashWithHash(blockHash, false))
|
||||
if err != nil {
|
||||
@@ -656,7 +657,7 @@ type feeHistoryResultMarshaling struct {
|
||||
}
|
||||
|
||||
// FeeHistory retrieves the fee market history.
|
||||
func (ec *client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*interfaces.FeeHistory, error) {
|
||||
func (ec *client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) {
|
||||
var res feeHistoryResultMarshaling
|
||||
if err := ec.c.CallContext(ctx, &res, "eth_feeHistory", hexutil.Uint(blockCount), ToBlockNumArg(lastBlock), rewardPercentiles); err != nil {
|
||||
return nil, err
|
||||
@@ -672,7 +673,7 @@ func (ec *client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *
|
||||
for i, b := range res.BaseFee {
|
||||
baseFee[i] = (*big.Int)(b)
|
||||
}
|
||||
return &interfaces.FeeHistory{
|
||||
return ðereum.FeeHistory{
|
||||
OldestBlock: (*big.Int)(res.OldestBlock),
|
||||
Reward: reward,
|
||||
BaseFee: baseFee,
|
||||
@@ -684,7 +685,7 @@ func (ec *client) FeeHistory(ctx context.Context, blockCount uint64, lastBlock *
|
||||
// the current pending state of the backend blockchain. There is no guarantee that this is
|
||||
// the true gas limit requirement as other transactions may be added or removed by miners,
|
||||
// but it should provide a basis for setting a reasonable default.
|
||||
func (ec *client) EstimateGas(ctx context.Context, msg interfaces.CallMsg) (uint64, error) {
|
||||
func (ec *client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) {
|
||||
var hex hexutil.Uint64
|
||||
err := ec.c.CallContext(ctx, &hex, "eth_estimateGas", toCallArg(msg))
|
||||
if err != nil {
|
||||
@@ -732,7 +733,7 @@ func ToBlockNumArg(number *big.Int) string {
|
||||
return fmt.Sprintf("<invalid %d>", number)
|
||||
}
|
||||
|
||||
func toCallArg(msg interfaces.CallMsg) interface{} {
|
||||
func toCallArg(msg ethereum.CallMsg) interface{} {
|
||||
arg := map[string]interface{}{
|
||||
"from": msg.From,
|
||||
"to": msg.To,
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ava-labs/avalanchego/utils/timer/mockable"
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/rawdb"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
@@ -45,20 +46,20 @@ func (*fakePushGossiper) Add(*types.Transaction) {}
|
||||
|
||||
// Client exposes the methods provided by the Ethereum RPC client.
|
||||
type Client interface {
|
||||
interfaces.BlockNumberReader
|
||||
interfaces.ChainReader
|
||||
interfaces.ChainStateReader
|
||||
interfaces.ContractCaller
|
||||
interfaces.GasEstimator
|
||||
interfaces.GasPricer
|
||||
interfaces.GasPricer1559
|
||||
interfaces.FeeHistoryReader
|
||||
interfaces.LogFilterer
|
||||
ethereum.BlockNumberReader
|
||||
ethereum.ChainReader
|
||||
ethereum.ChainStateReader
|
||||
ethereum.ContractCaller
|
||||
ethereum.GasEstimator
|
||||
ethereum.GasPricer
|
||||
ethereum.GasPricer1559
|
||||
ethereum.FeeHistoryReader
|
||||
ethereum.LogFilterer
|
||||
interfaces.AcceptedStateReader
|
||||
interfaces.AcceptedContractCaller
|
||||
interfaces.TransactionReader
|
||||
interfaces.TransactionSender
|
||||
interfaces.ChainIDReader
|
||||
ethereum.TransactionReader
|
||||
ethereum.TransactionSender
|
||||
ethereum.ChainIDReader
|
||||
}
|
||||
|
||||
// simClient wraps ethclient. This exists to prevent extracting ethclient.Client
|
||||
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/subnet-evm/core"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/params"
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ func TestWithCallGasLimitOption(t *testing.T) {
|
||||
defer sim.Close()
|
||||
|
||||
client := sim.Client()
|
||||
_, err := client.CallContract(context.Background(), interfaces.CallMsg{
|
||||
_, err := client.CallContract(context.Background(), ethereum.CallMsg{
|
||||
From: testAddr,
|
||||
To: &testAddr,
|
||||
Gas: 21000,
|
||||
|
||||
@@ -33,11 +33,11 @@ import (
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/common/hexutil"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/subnet-evm/ethclient"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/rpc"
|
||||
)
|
||||
|
||||
@@ -55,7 +55,7 @@ func New(c *rpc.Client) *Client {
|
||||
|
||||
// CreateAccessList tries to create an access list for a specific transaction based on the
|
||||
// current pending state of the blockchain.
|
||||
func (ec *Client) CreateAccessList(ctx context.Context, msg interfaces.CallMsg) (*types.AccessList, uint64, string, error) {
|
||||
func (ec *Client) CreateAccessList(ctx context.Context, msg ethereum.CallMsg) (*types.AccessList, uint64, string, error) {
|
||||
type accessListResult struct {
|
||||
Accesslist *types.AccessList `json:"accessList"`
|
||||
Error string `json:"error,omitempty"`
|
||||
@@ -152,7 +152,7 @@ type OverrideAccount struct {
|
||||
// overrides specifies a map of contract states that should be overwritten before executing
|
||||
// the message call.
|
||||
// Please use ethclient.CallContract instead if you don't need the override functionality.
|
||||
func (ec *Client) CallContract(ctx context.Context, msg interfaces.CallMsg, blockNumber *big.Int, overrides *map[common.Address]OverrideAccount) ([]byte, error) {
|
||||
func (ec *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int, overrides *map[common.Address]OverrideAccount) ([]byte, error) {
|
||||
var hex hexutil.Bytes
|
||||
err := ec.c.CallContext(
|
||||
ctx, &hex, "eth_call", toCallArg(msg),
|
||||
@@ -180,7 +180,7 @@ func (ec *Client) SubscribePendingTransactions(ctx context.Context, ch chan<- co
|
||||
return ec.c.EthSubscribe(ctx, ch, "newPendingTransactions")
|
||||
}
|
||||
|
||||
func toCallArg(msg interfaces.CallMsg) interface{} {
|
||||
func toCallArg(msg ethereum.CallMsg) interface{} {
|
||||
arg := map[string]interface{}{
|
||||
"from": msg.From,
|
||||
"to": msg.To,
|
||||
|
||||
+3
-210
@@ -1,198 +1,15 @@
|
||||
// (c) 2019-2020, Ava Labs, Inc.
|
||||
//
|
||||
// This file is a derived work, based on the go-ethereum library whose original
|
||||
// notices appear below.
|
||||
//
|
||||
// It is distributed under a license compatible with the licensing terms of the
|
||||
// original code from which it is derived.
|
||||
//
|
||||
// Much love to the original authors for their work.
|
||||
// **********
|
||||
// Copyright 2016 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
// (c) 2025, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
// Package ethereum defines interfaces for interacting with Ethereum.
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/big"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/common"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
)
|
||||
|
||||
// NotFound is returned by API methods if the requested item does not exist.
|
||||
var NotFound = errors.New("not found")
|
||||
|
||||
// Subscription represents an event subscription where events are
|
||||
// delivered on a data channel.
|
||||
type Subscription interface {
|
||||
// Unsubscribe cancels the sending of events to the data channel
|
||||
// and closes the error channel.
|
||||
Unsubscribe()
|
||||
// Err returns the subscription error channel. The error channel receives
|
||||
// a value if there is an issue with the subscription (e.g. the network connection
|
||||
// delivering the events has been closed). Only one value will ever be sent.
|
||||
// The error channel is closed by Unsubscribe.
|
||||
Err() <-chan error
|
||||
}
|
||||
|
||||
// ChainReader provides access to the blockchain. The methods in this interface access raw
|
||||
// data from either the canonical chain (when requesting by block number) or any
|
||||
// blockchain fork that was previously downloaded and processed by the node. The block
|
||||
// number argument can be nil to select the latest canonical block. Reading block headers
|
||||
// should be preferred over full blocks whenever possible.
|
||||
//
|
||||
// The returned error is NotFound if the requested item does not exist.
|
||||
type ChainReader interface {
|
||||
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
|
||||
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
|
||||
HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
|
||||
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
|
||||
TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
|
||||
TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*types.Transaction, error)
|
||||
|
||||
// This method subscribes to notifications about changes of the head block of
|
||||
// the canonical chain.
|
||||
SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (Subscription, error)
|
||||
}
|
||||
|
||||
// TransactionReader provides access to past transactions and their receipts.
|
||||
// Implementations may impose arbitrary restrictions on the transactions and receipts that
|
||||
// can be retrieved. Historic transactions may not be available.
|
||||
//
|
||||
// Avoid relying on this interface if possible. Contract logs (through the LogFilterer
|
||||
// interface) are more reliable and usually safer in the presence of chain
|
||||
// reorganisations.
|
||||
//
|
||||
// The returned error is NotFound if the requested item does not exist.
|
||||
type TransactionReader interface {
|
||||
// TransactionByHash checks the pool of pending transactions in addition to the
|
||||
// blockchain. The isPending return value indicates whether the transaction has been
|
||||
// mined yet. Note that the transaction may not be part of the canonical chain even if
|
||||
// it's not pending.
|
||||
TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)
|
||||
// TransactionReceipt returns the receipt of a mined transaction. Note that the
|
||||
// transaction may not be included in the current canonical chain even if a receipt
|
||||
// exists.
|
||||
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
|
||||
}
|
||||
|
||||
// ChainStateReader wraps access to the state trie of the canonical blockchain. Note that
|
||||
// implementations of the interface may be unable to return state values for old blocks.
|
||||
// In many cases, using CallContract can be preferable to reading raw contract storage.
|
||||
type ChainStateReader = ethereum.ChainStateReader
|
||||
|
||||
// CallMsg contains parameters for contract calls.
|
||||
type CallMsg struct {
|
||||
From common.Address // the sender of the 'transaction'
|
||||
To *common.Address // the destination contract (nil for contract creation)
|
||||
Gas uint64 // if 0, the call executes with near-infinite gas
|
||||
GasPrice *big.Int // wei <-> gas exchange ratio
|
||||
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
|
||||
GasTipCap *big.Int // EIP-1559 tip per gas.
|
||||
Value *big.Int // amount of wei sent along with the call
|
||||
Data []byte // input data, usually an ABI-encoded contract method invocation
|
||||
|
||||
AccessList types.AccessList // EIP-2930 access list.
|
||||
|
||||
// For BlobTxType
|
||||
BlobGasFeeCap *big.Int
|
||||
BlobHashes []common.Hash
|
||||
}
|
||||
|
||||
// A ContractCaller provides contract calls, essentially transactions that are executed by
|
||||
// the EVM but not mined into the blockchain. ContractCall is a low-level method to
|
||||
// execute such calls. For applications which are structured around specific contracts,
|
||||
// the abigen tool provides a nicer, properly typed way to perform calls.
|
||||
type ContractCaller interface {
|
||||
CallContract(ctx context.Context, call CallMsg, blockNumber *big.Int) ([]byte, error)
|
||||
}
|
||||
|
||||
// FilterQuery contains options for contract log filtering.
|
||||
type FilterQuery struct {
|
||||
BlockHash *common.Hash // used by eth_getLogs, return logs only from block with this hash
|
||||
FromBlock *big.Int // beginning of the queried range, nil means genesis block
|
||||
ToBlock *big.Int // end of the range, nil means latest block
|
||||
Addresses []common.Address // restricts matches to events created by specific contracts
|
||||
|
||||
// The Topic list restricts matches to particular event topics. Each event has a list
|
||||
// of topics. Topics matches a prefix of that list. An empty element slice matches any
|
||||
// topic. Non-empty elements represent an alternative that matches any of the
|
||||
// contained topics.
|
||||
//
|
||||
// Examples:
|
||||
// {} or nil matches any topic list
|
||||
// {{A}} matches topic A in first position
|
||||
// {{}, {B}} matches any topic in first position AND B in second position
|
||||
// {{A}, {B}} matches topic A in first position AND B in second position
|
||||
// {{A, B}, {C, D}} matches topic (A OR B) in first position AND (C OR D) in second position
|
||||
Topics [][]common.Hash
|
||||
}
|
||||
|
||||
// LogFilterer provides access to contract log events using a one-off query or continuous
|
||||
// event subscription.
|
||||
//
|
||||
// Logs received through a streaming query subscription may have Removed set to true,
|
||||
// indicating that the log was reverted due to a chain reorganisation.
|
||||
type LogFilterer interface {
|
||||
FilterLogs(ctx context.Context, q FilterQuery) ([]types.Log, error)
|
||||
SubscribeFilterLogs(ctx context.Context, q FilterQuery, ch chan<- types.Log) (Subscription, error)
|
||||
}
|
||||
|
||||
// TransactionSender wraps transaction sending. The SendTransaction method injects a
|
||||
// signed transaction into the pending transaction pool for execution. If the transaction
|
||||
// was a contract creation, the TransactionReceipt method can be used to retrieve the
|
||||
// contract address after the transaction has been mined.
|
||||
//
|
||||
// The transaction must be signed and have a valid nonce to be included. Consumers of the
|
||||
// API can use package accounts to maintain local private keys and need can retrieve the
|
||||
// next available nonce using AcceptedNonceAt.
|
||||
type TransactionSender interface {
|
||||
SendTransaction(ctx context.Context, tx *types.Transaction) error
|
||||
}
|
||||
|
||||
// GasPricer wraps the gas price oracle, which monitors the blockchain to determine the
|
||||
// optimal gas price given current fee market conditions.
|
||||
type GasPricer interface {
|
||||
SuggestGasPrice(ctx context.Context) (*big.Int, error)
|
||||
}
|
||||
|
||||
// GasPricer1559 provides access to the EIP-1559 gas price oracle.
|
||||
type GasPricer1559 interface {
|
||||
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
|
||||
}
|
||||
|
||||
// FeeHistoryReader provides access to the fee history oracle.
|
||||
type FeeHistoryReader interface {
|
||||
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*FeeHistory, error)
|
||||
}
|
||||
|
||||
// FeeHistory provides recent fee market data that consumers can use to determine
|
||||
// a reasonable maxPriorityFeePerGas value.
|
||||
type FeeHistory struct {
|
||||
OldestBlock *big.Int // block corresponding to first response value
|
||||
Reward [][]*big.Int // list every txs priority fee per block
|
||||
BaseFee []*big.Int // list of each block's base fee
|
||||
GasUsedRatio []float64 // ratio of gas used out of the total available limit
|
||||
}
|
||||
|
||||
// An AcceptedStateReceiver provides access to the accepted state ie. the state of the
|
||||
// most recently accepted block.
|
||||
type AcceptedStateReader interface {
|
||||
@@ -202,29 +19,5 @@ type AcceptedStateReader interface {
|
||||
|
||||
// AcceptedContractCaller can be used to perform calls against the accepted state.
|
||||
type AcceptedContractCaller interface {
|
||||
AcceptedCallContract(ctx context.Context, call CallMsg) ([]byte, error)
|
||||
}
|
||||
|
||||
// GasEstimator wraps EstimateGas, which tries to estimate the gas needed to execute a
|
||||
// specific transaction based on the pending state. There is no guarantee that this is the
|
||||
// true gas limit requirement as other transactions may be added or removed by miners, but
|
||||
// it should provide a basis for setting a reasonable default.
|
||||
type GasEstimator interface {
|
||||
EstimateGas(ctx context.Context, call CallMsg) (uint64, error)
|
||||
}
|
||||
|
||||
// A PendingStateEventer provides access to real time notifications about changes to the
|
||||
// pending state.
|
||||
type PendingStateEventer interface {
|
||||
SubscribePendingTransactions(ctx context.Context, ch chan<- *types.Transaction) (Subscription, error)
|
||||
}
|
||||
|
||||
// BlockNumberReader provides access to the current block number.
|
||||
type BlockNumberReader interface {
|
||||
BlockNumber(ctx context.Context) (uint64, error)
|
||||
}
|
||||
|
||||
// ChainIDReader provides access to the chain ID.
|
||||
type ChainIDReader interface {
|
||||
ChainID(ctx context.Context) (*big.Int, error)
|
||||
AcceptedCallContract(ctx context.Context, call ethereum.CallMsg) ([]byte, error)
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ import (
|
||||
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
|
||||
"github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
|
||||
|
||||
ethereum "github.com/ava-labs/libevm"
|
||||
"github.com/ava-labs/libevm/core/types"
|
||||
"github.com/ava-labs/subnet-evm/cmd/simulator/key"
|
||||
"github.com/ava-labs/subnet-evm/cmd/simulator/load"
|
||||
"github.com/ava-labs/subnet-evm/cmd/simulator/metrics"
|
||||
"github.com/ava-labs/subnet-evm/cmd/simulator/txs"
|
||||
"github.com/ava-labs/subnet-evm/ethclient"
|
||||
"github.com/ava-labs/subnet-evm/interfaces"
|
||||
"github.com/ava-labs/subnet-evm/params"
|
||||
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
|
||||
"github.com/ava-labs/subnet-evm/predicate"
|
||||
@@ -345,7 +345,7 @@ func (w *warpTest) sendMessageFromSendingSubnet() {
|
||||
require.NoError(err)
|
||||
|
||||
log.Info("Fetching relevant warp logs from the newly produced block")
|
||||
logs, err := client.FilterLogs(ctx, interfaces.FilterQuery{
|
||||
logs, err := client.FilterLogs(ctx, ethereum.FilterQuery{
|
||||
BlockHash: &blockHash,
|
||||
Addresses: []common.Address{warp.Module.Address},
|
||||
})
|
||||
@@ -507,7 +507,7 @@ func (w *warpTest) deliverAddressedCallToReceivingSubnet() {
|
||||
blockHash, _ := w.getBlockHashAndNumberFromTxReceipt(receiptCtx, client, signedTx)
|
||||
|
||||
log.Info("Fetching relevant warp logs and receipts from new block")
|
||||
logs, err := client.FilterLogs(ctx, interfaces.FilterQuery{
|
||||
logs, err := client.FilterLogs(ctx, ethereum.FilterQuery{
|
||||
BlockHash: &blockHash,
|
||||
Addresses: []common.Address{warp.Module.Address},
|
||||
})
|
||||
@@ -562,7 +562,7 @@ func (w *warpTest) deliverBlockHashPayload() {
|
||||
defer cancel()
|
||||
blockHash, _ := w.getBlockHashAndNumberFromTxReceipt(receiptCtx, client, signedTx)
|
||||
log.Info("Fetching relevant warp logs and receipts from new block")
|
||||
logs, err := client.FilterLogs(ctx, interfaces.FilterQuery{
|
||||
logs, err := client.FilterLogs(ctx, ethereum.FilterQuery{
|
||||
BlockHash: &blockHash,
|
||||
Addresses: []common.Address{warp.Module.Address},
|
||||
})
|
||||
@@ -639,7 +639,7 @@ func (w *warpTest) warpLoad() {
|
||||
|
||||
log.Info("Subscribing to warp send events on sending subnet")
|
||||
logs := make(chan types.Log, numWorkers*int(txsPerWorker))
|
||||
sub, err := sendingClient.SubscribeFilterLogs(ctx, interfaces.FilterQuery{
|
||||
sub, err := sendingClient.SubscribeFilterLogs(ctx, ethereum.FilterQuery{
|
||||
Addresses: []common.Address{warp.Module.Address},
|
||||
}, logs)
|
||||
require.NoError(err)
|
||||
|
||||
Reference in New Issue
Block a user