github.com/nitinawathare/ethereumassignment3@v0.0.0-20211021213010-f07344c2b868/go-ethereum/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/accounts" 25 "github.com/ethereum/go-ethereum/common" 26 "github.com/ethereum/go-ethereum/core" 27 "github.com/ethereum/go-ethereum/core/state" 28 "github.com/ethereum/go-ethereum/core/types" 29 "github.com/ethereum/go-ethereum/core/vm" 30 "github.com/ethereum/go-ethereum/eth/downloader" 31 "github.com/ethereum/go-ethereum/ethdb" 32 "github.com/ethereum/go-ethereum/event" 33 "github.com/ethereum/go-ethereum/params" 34 "github.com/ethereum/go-ethereum/rpc" 35 ) 36 37 // Backend interface provides the common API services (that are provided by 38 // both full and light clients) with access to necessary functions. 39 type Backend interface { 40 // General Ethereum API 41 Downloader() *downloader.Downloader 42 ProtocolVersion() int 43 SuggestPrice(ctx context.Context) (*big.Int, error) 44 ChainDb() ethdb.Database 45 EventMux() *event.TypeMux 46 AccountManager() *accounts.Manager 47 ExtRPCEnabled() bool 48 RPCGasCap() *big.Int // global gas cap for eth_call over rpc: DoS protection 49 50 // BlockChain API 51 SetHead(number uint64) 52 HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) 53 BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) 54 StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) 55 GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) 56 GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) 57 GetTd(blockHash common.Hash) *big.Int 58 GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) 59 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 60 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 61 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 62 63 // TxPool API 64 SendTx(ctx context.Context, signedTx *types.Transaction) error 65 GetPoolTransactions() (types.Transactions, error) 66 GetPoolTransaction(txHash common.Hash) *types.Transaction 67 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 68 Stats() (pending int, queued int) 69 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 70 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription 71 72 ChainConfig() *params.ChainConfig 73 CurrentBlock() *types.Block 74 } 75 76 func GetAPIs(apiBackend Backend) []rpc.API { 77 nonceLock := new(AddrLocker) 78 return []rpc.API{ 79 { 80 Namespace: "eth", 81 Version: "1.0", 82 Service: NewPublicEthereumAPI(apiBackend), 83 Public: true, 84 }, { 85 Namespace: "eth", 86 Version: "1.0", 87 Service: NewPublicBlockChainAPI(apiBackend), 88 Public: true, 89 }, { 90 Namespace: "eth", 91 Version: "1.0", 92 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 93 Public: true, 94 }, { 95 Namespace: "txpool", 96 Version: "1.0", 97 Service: NewPublicTxPoolAPI(apiBackend), 98 Public: true, 99 }, { 100 Namespace: "debug", 101 Version: "1.0", 102 Service: NewPublicDebugAPI(apiBackend), 103 Public: true, 104 }, { 105 Namespace: "debug", 106 Version: "1.0", 107 Service: NewPrivateDebugAPI(apiBackend), 108 }, { 109 Namespace: "eth", 110 Version: "1.0", 111 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 112 Public: true, 113 }, { 114 Namespace: "personal", 115 Version: "1.0", 116 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 117 Public: false, 118 }, 119 } 120 }