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