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