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