github.com/ava-labs/subnet-evm@v0.6.4/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/ava-labs/subnet-evm/accounts" 36 "github.com/ava-labs/subnet-evm/commontype" 37 "github.com/ava-labs/subnet-evm/consensus" 38 "github.com/ava-labs/subnet-evm/core" 39 "github.com/ava-labs/subnet-evm/core/bloombits" 40 "github.com/ava-labs/subnet-evm/core/state" 41 "github.com/ava-labs/subnet-evm/core/types" 42 "github.com/ava-labs/subnet-evm/core/vm" 43 "github.com/ava-labs/subnet-evm/params" 44 "github.com/ava-labs/subnet-evm/rpc" 45 "github.com/ethereum/go-ethereum/common" 46 "github.com/ethereum/go-ethereum/ethdb" 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 uint64, 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 65 UnprotectedAllowed(tx *types.Transaction) bool // allows only for EIP155 transactions. 66 67 // Blockchain API 68 HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) 69 HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) 70 HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error) 71 CurrentHeader() *types.Header 72 CurrentBlock() *types.Header 73 BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) 74 BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) 75 BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) 76 StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) 77 StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) 78 GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) 79 GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) (*vm.EVM, func() error) 80 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 81 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 82 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 83 GetFeeConfigAt(parent *types.Header) (commontype.FeeConfig, *big.Int, error) 84 BadBlocks() ([]*types.Block, []*core.BadBlockReason) 85 86 // Transaction pool API 87 SendTx(ctx context.Context, signedTx *types.Transaction) error 88 GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) 89 GetPoolTransactions() (types.Transactions, error) 90 GetPoolTransaction(txHash common.Hash) *types.Transaction 91 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 92 Stats() (pending int, queued int) 93 TxPoolContent() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction) 94 TxPoolContentFrom(addr common.Address) ([]*types.Transaction, []*types.Transaction) 95 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription 96 97 ChainConfig() *params.ChainConfig 98 Engine() consensus.Engine 99 LastAcceptedBlock() *types.Block 100 101 // This is copied from filters.Backend 102 // eth/filters needs to be initialized from this backend type, so methods needed by 103 // it must also be included here. 104 GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) 105 GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error) 106 SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription 107 SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription 108 SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription 109 BloomStatus() (uint64, uint64) 110 ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) 111 } 112 113 func GetAPIs(apiBackend Backend) []rpc.API { 114 nonceLock := new(AddrLocker) 115 return []rpc.API{ 116 { 117 Namespace: "eth", 118 Service: NewEthereumAPI(apiBackend), 119 Name: "internal-eth", 120 }, { 121 Namespace: "eth", 122 Service: NewBlockChainAPI(apiBackend), 123 Name: "internal-blockchain", 124 }, { 125 Namespace: "eth", 126 Service: NewTransactionAPI(apiBackend, nonceLock), 127 Name: "internal-transaction", 128 }, { 129 Namespace: "txpool", 130 Service: NewTxPoolAPI(apiBackend), 131 Name: "internal-tx-pool", 132 }, { 133 Namespace: "debug", 134 Service: NewDebugAPI(apiBackend), 135 Name: "internal-debug", 136 }, { 137 Namespace: "eth", 138 Service: NewEthereumAccountAPI(apiBackend.AccountManager()), 139 Name: "internal-account", 140 }, { 141 Namespace: "personal", 142 Service: NewPersonalAccountAPI(apiBackend, nonceLock), 143 Name: "internal-personal", 144 }, 145 } 146 }