github.com/FusionFoundation/efsn/v4@v4.2.0/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 ethereum "github.com/FusionFoundation/efsn/v4" 23 "math/big" 24 "time" 25 26 "github.com/FusionFoundation/efsn/v4/accounts" 27 "github.com/FusionFoundation/efsn/v4/common" 28 "github.com/FusionFoundation/efsn/v4/consensus" 29 "github.com/FusionFoundation/efsn/v4/core" 30 "github.com/FusionFoundation/efsn/v4/core/state" 31 "github.com/FusionFoundation/efsn/v4/core/types" 32 "github.com/FusionFoundation/efsn/v4/core/vm" 33 "github.com/FusionFoundation/efsn/v4/ethdb" 34 "github.com/FusionFoundation/efsn/v4/event" 35 "github.com/FusionFoundation/efsn/v4/params" 36 "github.com/FusionFoundation/efsn/v4/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 SyncProgress() ethereum.SyncProgress 44 45 SuggestGasTipCap(ctx context.Context) (*big.Int, error) 46 ChainDb() ethdb.Database 47 AccountManager() *accounts.Manager 48 RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection 49 RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection 50 RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs 51 52 // BlockChain API 53 SetHead(number uint64) 54 HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) 55 HeaderByHash(ctx context.Context, hash common.Hash) (*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, blockHash 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, vmConfig *vm.Config) (*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 // TxPool 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 GetPoolTransactionByPredicate(predicate func(*types.Transaction) bool) *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 AddBlacklist(addr common.Address) 82 RemoveBlacklist(addr common.Address) 83 GetBlacklist() []common.Address 84 85 // Filter API 86 SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription 87 SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription 88 89 ChainConfig() *params.ChainConfig 90 Engine() consensus.Engine 91 92 IsMining() bool 93 Coinbase() (common.Address, error) 94 } 95 96 func GetAPIs(apiBackend Backend) []rpc.API { 97 nonceLock := new(AddrLocker) 98 ppapi := NewPrivateAccountAPI(apiBackend, nonceLock) 99 txapi := NewPublicTransactionPoolAPI(apiBackend, nonceLock) 100 return []rpc.API{ 101 { 102 Namespace: "eth", 103 Version: "1.0", 104 Service: NewPublicEthereumAPI(apiBackend), 105 Public: true, 106 }, { 107 Namespace: "eth", 108 Version: "1.0", 109 Service: NewPublicBlockChainAPI(apiBackend), 110 Public: true, 111 }, { 112 Namespace: "eth", 113 Version: "1.0", 114 Service: txapi, 115 Public: true, 116 }, { 117 Namespace: "txpool", 118 Version: "1.0", 119 Service: NewPublicTxPoolAPI(apiBackend), 120 Public: true, 121 }, { 122 Namespace: "debug", 123 Version: "1.0", 124 Service: NewPublicDebugAPI(apiBackend), 125 Public: true, 126 }, { 127 Namespace: "debug", 128 Version: "1.0", 129 Service: NewPrivateDebugAPI(apiBackend), 130 }, { 131 Namespace: "eth", 132 Version: "1.0", 133 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 134 Public: true, 135 }, { 136 Namespace: "personal", 137 Version: "1.0", 138 Service: ppapi, 139 Public: false, 140 }, { 141 Namespace: "fsn", 142 Version: "1.0", 143 Service: NewPublicFusionAPI(apiBackend), 144 Public: true, 145 }, { 146 Namespace: "fsn", 147 Version: "1.0", 148 Service: NewPrivateFusionAPI(apiBackend, nonceLock, ppapi), 149 Public: false, 150 }, { 151 Namespace: "fsntx", 152 Version: "1.0", 153 Service: NewFusionTransactionAPI(apiBackend, nonceLock, txapi), 154 Public: false, 155 }, { 156 Namespace: "fsnbt", 157 Version: "1.0", 158 Service: NewPublicFusionAPI(apiBackend), 159 Public: true, 160 }, 161 } 162 }