github.com/MetalBlockchain/subnet-evm@v0.4.9/internal/ethapi/backend.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc.
     2  //
     3  // This file is a derived work, based on the go-ethereum library whose original
     4  // notices appear below.
     5  //
     6  // It is distributed under a license compatible with the licensing terms of the
     7  // original code from which it is derived.
     8  //
     9  // Much love to the original authors for their work.
    10  // **********
    11  // Copyright 2015 The go-ethereum Authors
    12  // This file is part of the go-ethereum library.
    13  //
    14  // The go-ethereum library is free software: you can redistribute it and/or modify
    15  // it under the terms of the GNU Lesser General Public License as published by
    16  // the Free Software Foundation, either version 3 of the License, or
    17  // (at your option) any later version.
    18  //
    19  // The go-ethereum library is distributed in the hope that it will be useful,
    20  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    22  // GNU Lesser General Public License for more details.
    23  //
    24  // You should have received a copy of the GNU Lesser General Public License
    25  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    26  
    27  // Package ethapi implements the general Ethereum API functions.
    28  package ethapi
    29  
    30  import (
    31  	"context"
    32  	"math/big"
    33  	"time"
    34  
    35  	"github.com/MetalBlockchain/subnet-evm/accounts"
    36  	"github.com/MetalBlockchain/subnet-evm/commontype"
    37  	"github.com/MetalBlockchain/subnet-evm/consensus"
    38  	"github.com/MetalBlockchain/subnet-evm/core"
    39  	"github.com/MetalBlockchain/subnet-evm/core/state"
    40  	"github.com/MetalBlockchain/subnet-evm/core/types"
    41  	"github.com/MetalBlockchain/subnet-evm/core/vm"
    42  	"github.com/MetalBlockchain/subnet-evm/eth/filters"
    43  	"github.com/MetalBlockchain/subnet-evm/ethdb"
    44  	"github.com/MetalBlockchain/subnet-evm/params"
    45  	"github.com/MetalBlockchain/subnet-evm/rpc"
    46  	"github.com/ethereum/go-ethereum/common"
    47  	"github.com/ethereum/go-ethereum/event"
    48  )
    49  
    50  // Backend interface provides the common API services (that are provided by
    51  // both full and light clients) with access to necessary functions.
    52  type Backend interface {
    53  	// General Ethereum API
    54  	EstimateBaseFee(ctx context.Context) (*big.Int, error)
    55  	SuggestPrice(ctx context.Context) (*big.Int, error)
    56  	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
    57  	FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
    58  	ChainDb() ethdb.Database
    59  	AccountManager() *accounts.Manager
    60  	ExtRPCEnabled() bool
    61  	RPCGasCap() uint64                             // global gas cap for eth_call over rpc: DoS protection
    62  	RPCEVMTimeout() time.Duration                  // global timeout for eth_call over rpc: DoS protection
    63  	RPCTxFeeCap() float64                          // global tx fee cap for all transaction related APIs
    64  	UnprotectedAllowed(tx *types.Transaction) bool // allows only for EIP155 transactions.
    65  
    66  	// Blockchain API
    67  	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
    68  	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
    69  	HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
    70  	CurrentHeader() *types.Header
    71  	CurrentBlock() *types.Block
    72  	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
    73  	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
    74  	BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
    75  	StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
    76  	StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
    77  	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
    78  	GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error)
    79  	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
    80  	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
    81  	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
    82  	GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig, *big.Int, error)
    83  	BadBlocks() ([]*types.Block, []*core.BadBlockReason)
    84  
    85  	// Transaction pool API
    86  	SendTx(ctx context.Context, signedTx *types.Transaction) error
    87  	GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
    88  	GetPoolTransactions() (types.Transactions, error)
    89  	GetPoolTransaction(txHash common.Hash) *types.Transaction
    90  	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
    91  	Stats() (pending int, queued int)
    92  	TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
    93  	TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions)
    94  	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
    95  
    96  	ChainConfig() *params.ChainConfig
    97  	Engine() consensus.Engine
    98  	LastAcceptedBlock() *types.Block
    99  
   100  	// eth/filters needs to be initialized from this backend type, so methods needed by
   101  	// it must also be included here.
   102  	filters.Backend
   103  }
   104  
   105  func GetAPIs(apiBackend Backend) []rpc.API {
   106  	nonceLock := new(AddrLocker)
   107  	return []rpc.API{
   108  		{
   109  			Namespace: "eth",
   110  			Service:   NewEthereumAPI(apiBackend),
   111  			Name:      "internal-eth",
   112  		}, {
   113  			Namespace: "eth",
   114  			Service:   NewBlockChainAPI(apiBackend),
   115  			Name:      "internal-blockchain",
   116  		}, {
   117  			Namespace: "eth",
   118  			Service:   NewTransactionAPI(apiBackend, nonceLock),
   119  			Name:      "internal-transaction",
   120  		}, {
   121  			Namespace: "txpool",
   122  			Service:   NewTxPoolAPI(apiBackend),
   123  			Name:      "internal-tx-pool",
   124  		}, {
   125  			Namespace: "debug",
   126  			Service:   NewDebugAPI(apiBackend),
   127  			Name:      "internal-debug",
   128  		}, {
   129  			Namespace: "eth",
   130  			Service:   NewEthereumAccountAPI(apiBackend.AccountManager()),
   131  			Name:      "internal-account",
   132  		}, {
   133  			Namespace: "personal",
   134  			Service:   NewPersonalAccountAPI(apiBackend, nonceLock),
   135  			Name:      "internal-personal",
   136  		},
   137  	}
   138  }