github.com/dim4egster/coreth@v0.10.2/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/dim4egster/coreth/accounts" 36 "github.com/dim4egster/coreth/consensus" 37 "github.com/dim4egster/coreth/core" 38 "github.com/dim4egster/coreth/core/state" 39 "github.com/dim4egster/coreth/core/types" 40 "github.com/dim4egster/coreth/core/vm" 41 "github.com/dim4egster/coreth/eth/filters" 42 "github.com/dim4egster/coreth/ethdb" 43 "github.com/dim4egster/coreth/params" 44 "github.com/dim4egster/coreth/rpc" 45 "github.com/ethereum/go-ethereum/common" 46 "github.com/ethereum/go-ethereum/event" 47 ) 48 49 // Backend interface provides the common API services (that are provided by 50 // both full and light clients) with access to necessary functions. 51 type Backend interface { 52 // General Ethereum API 53 EstimateBaseFee(ctx context.Context) (*big.Int, error) 54 SuggestPrice(ctx context.Context) (*big.Int, error) 55 SuggestGasTipCap(ctx context.Context) (*big.Int, error) 56 FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) 57 ChainDb() ethdb.Database 58 AccountManager() *accounts.Manager 59 ExtRPCEnabled() bool 60 RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection 61 RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection 62 RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs 63 UnprotectedAllowed() bool // allows only for EIP155 transactions. 64 65 // Blockchain API 66 HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) 67 HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) 68 HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error) 69 CurrentHeader() *types.Header 70 CurrentBlock() *types.Block 71 BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) 72 BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) 73 BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) 74 StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) 75 StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) 76 GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) 77 GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) 78 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 79 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 80 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 81 BadBlocks() ([]*types.Block, []*core.BadBlockReason) 82 83 // Transaction pool API 84 SendTx(ctx context.Context, signedTx *types.Transaction) error 85 GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) 86 GetPoolTransactions() (types.Transactions, error) 87 GetPoolTransaction(txHash common.Hash) *types.Transaction 88 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 89 Stats() (pending int, queued int) 90 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 91 TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions) 92 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription 93 94 ChainConfig() *params.ChainConfig 95 Engine() consensus.Engine 96 LastAcceptedBlock() *types.Block 97 98 // eth/filters needs to be initialized from this backend type, so methods needed by 99 // it must also be included here. 100 filters.Backend 101 } 102 103 func GetAPIs(apiBackend Backend) []rpc.API { 104 nonceLock := new(AddrLocker) 105 return []rpc.API{ 106 { 107 Namespace: "eth", 108 Service: NewEthereumAPI(apiBackend), 109 Name: "internal-eth", 110 }, { 111 Namespace: "eth", 112 Service: NewBlockChainAPI(apiBackend), 113 Name: "internal-blockchain", 114 }, { 115 Namespace: "eth", 116 Service: NewTransactionAPI(apiBackend, nonceLock), 117 Name: "internal-transaction", 118 }, { 119 Namespace: "txpool", 120 Service: NewTxPoolAPI(apiBackend), 121 Name: "internal-tx-pool", 122 }, { 123 Namespace: "debug", 124 Service: NewDebugAPI(apiBackend), 125 Name: "internal-debug", 126 }, { 127 Namespace: "eth", 128 Service: NewEthereumAccountAPI(apiBackend.AccountManager()), 129 Name: "internal-account", 130 }, { 131 Namespace: "personal", 132 Service: NewPersonalAccountAPI(apiBackend, nonceLock), 133 Name: "internal-personal", 134 }, 135 } 136 }