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