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