github.com/jpmorganchase/quorum@v21.1.0+incompatible/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 "time" 24 25 "github.com/ethereum/go-ethereum/accounts" 26 "github.com/ethereum/go-ethereum/common" 27 "github.com/ethereum/go-ethereum/core" 28 "github.com/ethereum/go-ethereum/core/bloombits" 29 "github.com/ethereum/go-ethereum/core/types" 30 "github.com/ethereum/go-ethereum/core/vm" 31 "github.com/ethereum/go-ethereum/eth/downloader" 32 "github.com/ethereum/go-ethereum/ethdb" 33 "github.com/ethereum/go-ethereum/event" 34 "github.com/ethereum/go-ethereum/multitenancy" 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 multitenancy.AuthorizationProvider 43 // General Ethereum API 44 Downloader() *downloader.Downloader 45 ProtocolVersion() int 46 SuggestPrice(ctx context.Context) (*big.Int, error) 47 ChainDb() ethdb.Database 48 EventMux() *event.TypeMux 49 AccountManager() *accounts.Manager 50 ExtRPCEnabled() bool 51 CallTimeOut() time.Duration 52 RPCGasCap() *big.Int // global gas cap for eth_call over rpc: DoS protection 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 BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) 60 BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) 61 BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) 62 StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (vm.MinimalApiState, *types.Header, error) 63 StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (vm.MinimalApiState, *types.Header, error) 64 GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) 65 GetTd(hash common.Hash) *big.Int 66 GetEVM(ctx context.Context, msg core.Message, state vm.MinimalApiState, header *types.Header) (*vm.EVM, func() error, error) 67 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 68 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 69 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 70 71 // Transaction pool API 72 SendTx(ctx context.Context, signedTx *types.Transaction) error 73 GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) 74 GetPoolTransactions() (types.Transactions, error) 75 GetPoolTransaction(txHash common.Hash) *types.Transaction 76 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 77 Stats() (pending int, queued int) 78 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 79 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription 80 81 // Filter API 82 BloomStatus() (uint64, uint64) 83 GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) 84 ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) 85 SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription 86 SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription 87 88 ChainConfig() *params.ChainConfig 89 CurrentBlock() *types.Block 90 91 // AccountExtraDataStateGetterByNumber returns state getter at a given block height 92 AccountExtraDataStateGetterByNumber(ctx context.Context, number rpc.BlockNumber) (vm.AccountExtraDataStateGetter, error) 93 } 94 95 func GetAPIs(apiBackend Backend) []rpc.API { 96 nonceLock := new(AddrLocker) 97 return []rpc.API{ 98 { 99 Namespace: "eth", 100 Version: "1.0", 101 Service: NewPublicEthereumAPI(apiBackend), 102 Public: true, 103 }, { 104 Namespace: "eth", 105 Version: "1.0", 106 Service: NewPublicBlockChainAPI(apiBackend), 107 Public: true, 108 }, { 109 Namespace: "eth", 110 Version: "1.0", 111 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 112 Public: true, 113 }, { 114 Namespace: "txpool", 115 Version: "1.0", 116 Service: NewPublicTxPoolAPI(apiBackend), 117 Public: true, 118 }, { 119 Namespace: "debug", 120 Version: "1.0", 121 Service: NewPublicDebugAPI(apiBackend), 122 Public: true, 123 }, { 124 Namespace: "debug", 125 Version: "1.0", 126 Service: NewPrivateDebugAPI(apiBackend), 127 }, { 128 Namespace: "eth", 129 Version: "1.0", 130 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 131 Public: true, 132 }, { 133 Namespace: "personal", 134 Version: "1.0", 135 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 136 Public: false, 137 }, 138 } 139 }