github.com/MikyChow/arbitrum-go-ethereum@v0.0.0-20230306102812-078da49636de/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/MikyChow/arbitrum-go-ethereum"
    23  	"math/big"
    24  	"time"
    25  
    26  	"github.com/MikyChow/arbitrum-go-ethereum/accounts"
    27  	"github.com/MikyChow/arbitrum-go-ethereum/common"
    28  	"github.com/MikyChow/arbitrum-go-ethereum/consensus"
    29  	"github.com/MikyChow/arbitrum-go-ethereum/core"
    30  	"github.com/MikyChow/arbitrum-go-ethereum/core/state"
    31  	"github.com/MikyChow/arbitrum-go-ethereum/core/types"
    32  	"github.com/MikyChow/arbitrum-go-ethereum/core/vm"
    33  	"github.com/MikyChow/arbitrum-go-ethereum/eth/filters"
    34  	"github.com/MikyChow/arbitrum-go-ethereum/ethdb"
    35  	"github.com/MikyChow/arbitrum-go-ethereum/event"
    36  	"github.com/MikyChow/arbitrum-go-ethereum/params"
    37  	"github.com/MikyChow/arbitrum-go-ethereum/rpc"
    38  )
    39  
    40  // Backend interface provides the common API services (that are provided by
    41  // both full and light clients) with access to necessary functions.
    42  type Backend interface {
    43  	FallbackClient() types.FallbackClient
    44  
    45  	// General Ethereum API
    46  	SyncProgress() ethereum.SyncProgress
    47  	SyncProgressMap() map[string]interface{}
    48  
    49  	SuggestGasTipCap(ctx context.Context) (*big.Int, error)
    50  	FeeHistory(ctx context.Context, blockCount int, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
    51  	ChainDb() ethdb.Database
    52  	AccountManager() *accounts.Manager
    53  	ExtRPCEnabled() bool
    54  	RPCGasCap() uint64            // global gas cap for eth_call over rpc: DoS protection
    55  	RPCEVMTimeout() time.Duration // global timeout for eth_call over rpc: DoS protection
    56  	RPCTxFeeCap() float64         // global tx fee cap for all transaction related APIs
    57  	UnprotectedAllowed() bool     // allows only for EIP155 transactions.
    58  
    59  	// Blockchain API
    60  	SetHead(number uint64)
    61  	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
    62  	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
    63  	HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
    64  	CurrentHeader() *types.Header
    65  	CurrentBlock() *types.Block
    66  	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
    67  	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
    68  	BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
    69  	StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
    70  	StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
    71  	PendingBlockAndReceipts() (*types.Block, types.Receipts)
    72  	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
    73  	GetTd(ctx context.Context, hash common.Hash) *big.Int
    74  	GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error)
    75  	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
    76  	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
    77  	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
    78  
    79  	// Transaction pool API
    80  	SendTx(ctx context.Context, signedTx *types.Transaction) error
    81  	GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
    82  	GetPoolTransactions() (types.Transactions, error)
    83  	GetPoolTransaction(txHash common.Hash) *types.Transaction
    84  	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
    85  	Stats() (pending int, queued int)
    86  	TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
    87  	TxPoolContentFrom(addr common.Address) (types.Transactions, types.Transactions)
    88  	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
    89  
    90  	ChainConfig() *params.ChainConfig
    91  	Engine() consensus.Engine
    92  
    93  	// eth/filters needs to be initialized from this backend type, so methods needed by
    94  	// it must also be included here.
    95  	filters.Backend
    96  }
    97  
    98  func GetAPIs(apiBackend Backend) []rpc.API {
    99  	nonceLock := new(AddrLocker)
   100  	return []rpc.API{
   101  		{
   102  			Namespace: "eth",
   103  			Service:   NewEthereumAPI(apiBackend),
   104  		}, {
   105  			Namespace: "eth",
   106  			Service:   NewBlockChainAPI(apiBackend),
   107  		}, {
   108  			Namespace: "eth",
   109  			Service:   NewTransactionAPI(apiBackend, nonceLock),
   110  		}, {
   111  			Namespace: "txpool",
   112  			Service:   NewTxPoolAPI(apiBackend),
   113  		}, {
   114  			Namespace: "debug",
   115  			Service:   NewDebugAPI(apiBackend),
   116  		}, {
   117  			Namespace: "eth",
   118  			Service:   NewEthereumAccountAPI(apiBackend.AccountManager()),
   119  		}, {
   120  			Namespace: "personal",
   121  			Service:   NewPersonalAccountAPI(apiBackend, nonceLock),
   122  		},
   123  	}
   124  }