github.com/RobustRoundRobin/quorum@v20.10.0+incompatible/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  	"time"
    24  
    25  	"github.com/ethereum/go-ethereum/accounts"
    26  	"github.com/ethereum/go-ethereum/common"
    27  	"github.com/ethereum/go-ethereum/core"
    28  	"github.com/ethereum/go-ethereum/core/bloombits"
    29  	"github.com/ethereum/go-ethereum/core/types"
    30  	"github.com/ethereum/go-ethereum/core/vm"
    31  	"github.com/ethereum/go-ethereum/eth/downloader"
    32  	"github.com/ethereum/go-ethereum/ethdb"
    33  	"github.com/ethereum/go-ethereum/event"
    34  	"github.com/ethereum/go-ethereum/params"
    35  	"github.com/ethereum/go-ethereum/rpc"
    36  )
    37  
    38  // Backend interface provides the common API services (that are provided by
    39  // both full and light clients) with access to necessary functions.
    40  type Backend interface {
    41  	// General Ethereum API
    42  	Downloader() *downloader.Downloader
    43  	ProtocolVersion() int
    44  	SuggestPrice(ctx context.Context) (*big.Int, error)
    45  	ChainDb() ethdb.Database
    46  	EventMux() *event.TypeMux
    47  	AccountManager() *accounts.Manager
    48  	ExtRPCEnabled() bool
    49  	CallTimeOut() time.Duration
    50  	RPCGasCap() *big.Int // global gas cap for eth_call over rpc: DoS protection
    51  
    52  	// Blockchain API
    53  	SetHead(number uint64)
    54  	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
    55  	HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
    56  	HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
    57  	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
    58  	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
    59  	BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
    60  	StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (vm.MinimalApiState, *types.Header, error)
    61  	StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (vm.MinimalApiState, *types.Header, error)
    62  	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
    63  	GetTd(hash common.Hash) *big.Int
    64  	GetEVM(ctx context.Context, msg core.Message, state vm.MinimalApiState, header *types.Header) (*vm.EVM, func() error, error)
    65  	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
    66  	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
    67  	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
    68  
    69  	// Transaction pool API
    70  	SendTx(ctx context.Context, signedTx *types.Transaction) error
    71  	GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
    72  	GetPoolTransactions() (types.Transactions, error)
    73  	GetPoolTransaction(txHash common.Hash) *types.Transaction
    74  	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
    75  	Stats() (pending int, queued int)
    76  	TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
    77  	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
    78  
    79  	// Filter API
    80  	BloomStatus() (uint64, uint64)
    81  	GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error)
    82  	ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
    83  	SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
    84  	SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
    85  
    86  	ChainConfig() *params.ChainConfig
    87  	CurrentBlock() *types.Block
    88  }
    89  
    90  func GetAPIs(apiBackend Backend) []rpc.API {
    91  	nonceLock := new(AddrLocker)
    92  	return []rpc.API{
    93  		{
    94  			Namespace: "eth",
    95  			Version:   "1.0",
    96  			Service:   NewPublicEthereumAPI(apiBackend),
    97  			Public:    true,
    98  		}, {
    99  			Namespace: "eth",
   100  			Version:   "1.0",
   101  			Service:   NewPublicBlockChainAPI(apiBackend),
   102  			Public:    true,
   103  		}, {
   104  			Namespace: "eth",
   105  			Version:   "1.0",
   106  			Service:   NewPublicTransactionPoolAPI(apiBackend, nonceLock),
   107  			Public:    true,
   108  		}, {
   109  			Namespace: "txpool",
   110  			Version:   "1.0",
   111  			Service:   NewPublicTxPoolAPI(apiBackend),
   112  			Public:    true,
   113  		}, {
   114  			Namespace: "debug",
   115  			Version:   "1.0",
   116  			Service:   NewPublicDebugAPI(apiBackend),
   117  			Public:    true,
   118  		}, {
   119  			Namespace: "debug",
   120  			Version:   "1.0",
   121  			Service:   NewPrivateDebugAPI(apiBackend),
   122  		}, {
   123  			Namespace: "eth",
   124  			Version:   "1.0",
   125  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   126  			Public:    true,
   127  		}, {
   128  			Namespace: "personal",
   129  			Version:   "1.0",
   130  			Service:   NewPrivateAccountAPI(apiBackend, nonceLock),
   131  			Public:    false,
   132  		},
   133  	}
   134  }