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