gitlab.com/flarenetwork/coreth@v0.1.1/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 34 "github.com/ethereum/go-ethereum/common" 35 "github.com/ethereum/go-ethereum/eth/downloader" 36 "github.com/ethereum/go-ethereum/ethdb" 37 "github.com/ethereum/go-ethereum/event" 38 "gitlab.com/flarenetwork/coreth/accounts" 39 "gitlab.com/flarenetwork/coreth/consensus" 40 "gitlab.com/flarenetwork/coreth/core" 41 "gitlab.com/flarenetwork/coreth/core/bloombits" 42 "gitlab.com/flarenetwork/coreth/core/state" 43 "gitlab.com/flarenetwork/coreth/core/types" 44 "gitlab.com/flarenetwork/coreth/core/vm" 45 "gitlab.com/flarenetwork/coreth/params" 46 "gitlab.com/flarenetwork/coreth/rpc" 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 Downloader() *downloader.Downloader 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 // TODO(aaronbuchwald) uncomment after migrating v1.10.6 changes into gasprice package 58 // FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) 59 ChainDb() ethdb.Database 60 AccountManager() *accounts.Manager 61 ExtRPCEnabled() bool 62 RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection 63 RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs 64 UnprotectedAllowed() 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 GetTd(ctx context.Context, hash common.Hash) *big.Int 79 GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, 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 84 // Transaction pool API 85 SendTx(ctx context.Context, signedTx *types.Transaction) error 86 GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) 87 GetPoolTransactions() (types.Transactions, error) 88 GetPoolTransaction(txHash common.Hash) *types.Transaction 89 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 90 Stats() (pending int, queued int) 91 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 92 TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions) 93 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription 94 95 // Filter API 96 BloomStatus() (uint64, uint64) 97 GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) 98 ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) 99 SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription 100 SubscribeAcceptedLogsEvent(ch chan<- []*types.Log) event.Subscription 101 SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription 102 SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription 103 104 ChainConfig() *params.ChainConfig 105 Engine() consensus.Engine 106 LastAcceptedBlock() *types.Block 107 } 108 109 func GetAPIs(apiBackend Backend) []rpc.API { 110 nonceLock := new(AddrLocker) 111 return []rpc.API{ 112 { 113 Namespace: "eth", 114 Version: "1.0", 115 Service: NewPublicEthereumAPI(apiBackend), 116 Public: true, 117 }, { 118 Namespace: "eth", 119 Version: "1.0", 120 Service: NewPublicBlockChainAPI(apiBackend), 121 Public: true, 122 }, { 123 Namespace: "eth", 124 Version: "1.0", 125 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 126 Public: true, 127 }, { 128 Namespace: "txpool", 129 Version: "1.0", 130 Service: NewPublicTxPoolAPI(apiBackend), 131 Public: true, 132 }, { 133 Namespace: "debug", 134 Version: "1.0", 135 Service: NewPublicDebugAPI(apiBackend), 136 Public: true, 137 }, { 138 Namespace: "debug", 139 Version: "1.0", 140 Service: NewPrivateDebugAPI(apiBackend), 141 }, { 142 Namespace: "eth", 143 Version: "1.0", 144 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 145 Public: true, 146 }, { 147 Namespace: "personal", 148 Version: "1.0", 149 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 150 Public: false, 151 }, 152 } 153 }