github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/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 "time" 24 25 "github.com/unicornultrafoundation/go-helios/hash" 26 "github.com/unicornultrafoundation/go-helios/native/idx" 27 28 "github.com/unicornultrafoundation/go-u2u/accounts" 29 "github.com/unicornultrafoundation/go-u2u/common" 30 "github.com/unicornultrafoundation/go-u2u/core/state" 31 "github.com/unicornultrafoundation/go-u2u/core/types" 32 "github.com/unicornultrafoundation/go-u2u/core/vm" 33 "github.com/unicornultrafoundation/go-u2u/ethdb" 34 notify "github.com/unicornultrafoundation/go-u2u/event" 35 "github.com/unicornultrafoundation/go-u2u/evmcore" 36 "github.com/unicornultrafoundation/go-u2u/evmcore/txtracer" 37 "github.com/unicornultrafoundation/go-u2u/native" 38 "github.com/unicornultrafoundation/go-u2u/native/iblockproc" 39 "github.com/unicornultrafoundation/go-u2u/params" 40 "github.com/unicornultrafoundation/go-u2u/rpc" 41 ) 42 43 // PeerProgress is synchronization status of a peer 44 type PeerProgress struct { 45 CurrentEpoch idx.Epoch 46 CurrentBlock idx.Block 47 CurrentBlockHash hash.Event 48 CurrentBlockTime native.Timestamp 49 HighestBlock idx.Block 50 HighestEpoch idx.Epoch 51 } 52 53 // Backend interface provides the common API services (that are provided by 54 // both full and light clients) with access to necessary functions. 55 type Backend interface { 56 // General Ethereum API 57 Progress() PeerProgress 58 SuggestGasTipCap(ctx context.Context, certainty uint64) *big.Int 59 EffectiveMinGasPrice(ctx context.Context) *big.Int 60 ChainDb() ethdb.Database 61 AccountManager() *accounts.Manager 62 ExtRPCEnabled() bool 63 RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection 64 RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs 65 RPCTimeout() time.Duration 66 UnprotectedAllowed() bool // allows only for EIP155 transactions. 67 CalcBlockExtApi() bool 68 StateAtBlock(ctx context.Context, block *evmcore.EvmBlock, reexec uint64, base *state.StateDB, checkLive bool) (*state.StateDB, error) 69 StateAtTransaction(ctx context.Context, block *evmcore.EvmBlock, txIndex int, reexec uint64) (evmcore.Message, vm.BlockContext, *state.StateDB, error) 70 // Blockchain API 71 HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmHeader, error) 72 HeaderByHash(ctx context.Context, hash common.Hash) (*evmcore.EvmHeader, error) 73 BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmBlock, error) 74 StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *evmcore.EvmHeader, error) 75 ResolveRpcBlockNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (idx.Block, error) 76 BlockByHash(ctx context.Context, hash common.Hash) (*evmcore.EvmBlock, error) 77 GetReceiptsByNumber(ctx context.Context, number rpc.BlockNumber) (types.Receipts, error) 78 GetTd(hash common.Hash) *big.Int 79 GetEVM(ctx context.Context, msg evmcore.Message, state *state.StateDB, header *evmcore.EvmHeader, vmConfig *vm.Config) (*vm.EVM, func() error, error) 80 GetBlockContext(header *evmcore.EvmHeader) vm.BlockContext 81 MinGasPrice() *big.Int 82 MaxGasLimit() uint64 83 84 // Transaction trace API 85 TxTraceByHash(ctx context.Context, h common.Hash) (*[]txtracer.ActionTrace, error) 86 TxTraceSave(ctx context.Context, h common.Hash, traces []byte) error 87 88 // Transaction pool API 89 SendTx(ctx context.Context, signedTx *types.Transaction) error 90 GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, uint64, uint64, error) 91 GetPoolTransactions() (types.Transactions, error) 92 GetPoolTransaction(txHash common.Hash) *types.Transaction 93 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 94 Stats() (pending int, queued int) 95 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 96 TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions) 97 SubscribeNewTxsNotify(chan<- evmcore.NewTxsNotify) notify.Subscription 98 99 ChainConfig() *params.ChainConfig 100 CurrentBlock() *evmcore.EvmBlock 101 102 // Hashgraph DAG API 103 GetEventPayload(ctx context.Context, shortEventID string) (*native.EventPayload, error) 104 GetEvent(ctx context.Context, shortEventID string) (*native.Event, error) 105 GetHeads(ctx context.Context, epoch rpc.BlockNumber) (hash.Events, error) 106 CurrentEpoch(ctx context.Context) idx.Epoch 107 SealedEpochTiming(ctx context.Context) (start native.Timestamp, end native.Timestamp) 108 109 // Hashgraph aBFT API 110 GetEpochBlockState(ctx context.Context, epoch rpc.BlockNumber) (*iblockproc.BlockState, *iblockproc.EpochState, error) 111 GetDowntime(ctx context.Context, vid idx.ValidatorID) (idx.Block, native.Timestamp, error) 112 GetUptime(ctx context.Context, vid idx.ValidatorID) (*big.Int, error) 113 GetOriginatedFee(ctx context.Context, vid idx.ValidatorID) (*big.Int, error) 114 } 115 116 func GetAPIs(apiBackend Backend) []rpc.API { 117 nonceLock := new(AddrLocker) 118 orig := []rpc.API{ 119 { 120 Namespace: "eth", 121 Version: "1.0", 122 Service: NewPublicEthereumAPI(apiBackend), 123 Public: true, 124 }, { 125 Namespace: "eth", 126 Version: "1.0", 127 Service: NewPublicBlockChainAPI(apiBackend), 128 Public: true, 129 }, { 130 Namespace: "dag", 131 Version: "1.0", 132 Service: NewPublicDAGChainAPI(apiBackend), 133 Public: true, 134 }, { 135 Namespace: "eth", 136 Version: "1.0", 137 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 138 Public: true, 139 }, { 140 Namespace: "txpool", 141 Version: "1.0", 142 Service: NewPublicTxPoolAPI(apiBackend), 143 Public: true, 144 }, { 145 Namespace: "debug", 146 Version: "1.0", 147 Service: NewPublicDebugAPI(apiBackend), 148 Public: true, 149 }, { 150 Namespace: "debug", 151 Version: "1.0", 152 Service: NewPrivateDebugAPI(apiBackend), 153 }, { 154 Namespace: "eth", 155 Version: "1.0", 156 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 157 Public: true, 158 }, { 159 Namespace: "personal", 160 Version: "1.0", 161 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 162 Public: false, 163 }, { 164 Namespace: "abft", 165 Version: "1.0", 166 Service: NewPublicAbftAPI(apiBackend), 167 Public: true, 168 }, { 169 Namespace: "trace", 170 Version: "1.0", 171 Service: NewPublicTxTraceAPI(apiBackend), 172 Public: true, 173 }, 174 } 175 176 return append(orig) 177 }