github.com/phillinzzz/newBsc@v1.1.6/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/phillinzzz/newBsc/accounts" 25 "github.com/phillinzzz/newBsc/common" 26 "github.com/phillinzzz/newBsc/consensus" 27 "github.com/phillinzzz/newBsc/core" 28 "github.com/phillinzzz/newBsc/core/bloombits" 29 "github.com/phillinzzz/newBsc/core/state" 30 "github.com/phillinzzz/newBsc/core/types" 31 "github.com/phillinzzz/newBsc/core/vm" 32 "github.com/phillinzzz/newBsc/eth/downloader" 33 "github.com/phillinzzz/newBsc/ethdb" 34 "github.com/phillinzzz/newBsc/event" 35 "github.com/phillinzzz/newBsc/params" 36 "github.com/phillinzzz/newBsc/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 Downloader() *downloader.Downloader 44 SuggestPrice(ctx context.Context) (*big.Int, error) 45 Chain() *core.BlockChain 46 ChainDb() ethdb.Database 47 AccountManager() *accounts.Manager 48 ExtRPCEnabled() bool 49 RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection 50 RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs 51 UnprotectedAllowed() bool // allows only for EIP155 transactions. 52 53 // Blockchain API 54 SetHead(number uint64) 55 HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) 56 HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) 57 HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error) 58 CurrentHeader() *types.Header 59 CurrentBlock() *types.Block 60 BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) 61 BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) 62 BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) 63 StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) 64 StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) 65 GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) 66 GetTd(ctx context.Context, hash common.Hash) *big.Int 67 GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) 68 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 69 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 70 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 71 72 // Transaction pool API 73 SendTx(ctx context.Context, signedTx *types.Transaction) error 74 GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) 75 GetPoolTransactions() (types.Transactions, error) 76 GetPoolTransaction(txHash common.Hash) *types.Transaction 77 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 78 Stats() (pending int, queued int) 79 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 80 SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription 81 82 // Filter API 83 BloomStatus() (uint64, uint64) 84 GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) 85 ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) 86 SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription 87 SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription 88 SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription 89 90 ChainConfig() *params.ChainConfig 91 Engine() consensus.Engine 92 } 93 94 func GetAPIs(apiBackend Backend) []rpc.API { 95 nonceLock := new(AddrLocker) 96 return []rpc.API{ 97 { 98 Namespace: "eth", 99 Version: "1.0", 100 Service: NewPublicEthereumAPI(apiBackend), 101 Public: true, 102 }, { 103 Namespace: "eth", 104 Version: "1.0", 105 Service: NewPublicBlockChainAPI(apiBackend), 106 Public: true, 107 }, { 108 Namespace: "eth", 109 Version: "1.0", 110 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 111 Public: true, 112 }, { 113 Namespace: "txpool", 114 Version: "1.0", 115 Service: NewPublicTxPoolAPI(apiBackend), 116 Public: true, 117 }, { 118 Namespace: "debug", 119 Version: "1.0", 120 Service: NewPublicDebugAPI(apiBackend), 121 Public: true, 122 }, { 123 Namespace: "debug", 124 Version: "1.0", 125 Service: NewPrivateDebugAPI(apiBackend), 126 }, { 127 Namespace: "eth", 128 Version: "1.0", 129 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 130 Public: true, 131 }, { 132 Namespace: "personal", 133 Version: "1.0", 134 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 135 Public: false, 136 }, 137 } 138 }