github.com/ebakus/go-ebakus@v1.0.5-0.20200520105415-dbccef9ec421/internal/ethapi/backend.go (about)

     1  // Copyright 2019 The ebakus/go-ebakus Authors
     2  // This file is part of the ebakus/go-ebakus library.
     3  //
     4  // The ebakus/go-ebakus 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 ebakus/go-ebakus 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 ebakus/go-ebakus library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Package ethapi implements the general Ebakus API functions.
    18  package ethapi
    19  
    20  import (
    21  	"context"
    22  	"math/big"
    23  
    24  	"github.com/ebakus/ebakusdb"
    25  	"github.com/ebakus/go-ebakus/accounts"
    26  	"github.com/ebakus/go-ebakus/common"
    27  	"github.com/ebakus/go-ebakus/core"
    28  	"github.com/ebakus/go-ebakus/core/bloombits"
    29  	"github.com/ebakus/go-ebakus/core/state"
    30  	"github.com/ebakus/go-ebakus/core/types"
    31  	"github.com/ebakus/go-ebakus/core/vm"
    32  	"github.com/ebakus/go-ebakus/eth/downloader"
    33  	"github.com/ebakus/go-ebakus/ethdb"
    34  	"github.com/ebakus/go-ebakus/event"
    35  	"github.com/ebakus/go-ebakus/params"
    36  	"github.com/ebakus/go-ebakus/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 Ebakus API
    43  	Downloader() *downloader.Downloader
    44  	ProtocolVersion() int
    45  	SuggestPrice(ctx context.Context) (*float64, error)
    46  	ChainDb() ethdb.Database
    47  	EventMux() *event.TypeMux
    48  	AccountManager() *accounts.Manager
    49  	ExtRPCEnabled() bool
    50  	RPCGasCap() *big.Int // global gas cap for eth_call over rpc: DoS protection
    51  	MinGasPrice() float64
    52  	EbakusdbMaxActiveIterators() uint64
    53  
    54  	// Blockchain API
    55  	SetHead(number uint64)
    56  	HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error)
    57  	HeaderByHash(ctx context.Context, blockHash common.Hash) (*types.Header, error)
    58  	HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
    59  	BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error)
    60  	BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
    61  	BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
    62  	StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error)
    63  	StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
    64  	EbakusStateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*ebakusdb.Snapshot, *types.Header, error)
    65  	EbakusStateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*ebakusdb.Snapshot, *types.Header, error)
    66  	GetBlockAuthor(header *types.Header) (common.Address, error)
    67  	GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error)
    68  	GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, ebakusState *ebakusdb.Snapshot, header *types.Header) (*vm.EVM, func() error, error)
    69  	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
    70  	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
    71  	SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
    72  
    73  	// Transaction pool API
    74  	SendTx(ctx context.Context, signedTx *types.Transaction) error
    75  	GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
    76  	GetPoolTransactions() (types.Transactions, error)
    77  	GetPoolTransaction(txHash common.Hash) *types.Transaction
    78  	GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
    79  	Stats() (pending int, queued int)
    80  	TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]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  	SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
    89  
    90  	ChainConfig() *params.ChainConfig
    91  	CurrentBlock() *types.Block
    92  }
    93  
    94  func GetAPIs(apiBackend Backend) []rpc.API {
    95  	nonceLock := new(AddrLocker)
    96  	return []rpc.API{
    97  		{
    98  			Namespace: "eth",
    99  			Version:   "1.0",
   100  			Service:   NewPublicEbakusAPI(apiBackend),
   101  			Public:    true,
   102  		}, {
   103  			Namespace: "eth",
   104  			Version:   "1.0",
   105  			Service:   NewPublicBlockChainAPI(apiBackend),
   106  			Public:    true,
   107  		}, {
   108  			Namespace: "eth",
   109  			Version:   "1.0",
   110  			Service:   NewPublicTransactionPoolAPI(apiBackend, nonceLock),
   111  			Public:    true,
   112  		}, {
   113  			Namespace: "txpool",
   114  			Version:   "1.0",
   115  			Service:   NewPublicTxPoolAPI(apiBackend),
   116  			Public:    true,
   117  		}, {
   118  			Namespace: "debug",
   119  			Version:   "1.0",
   120  			Service:   NewPublicDebugAPI(apiBackend),
   121  			Public:    true,
   122  		}, {
   123  			Namespace: "debug",
   124  			Version:   "1.0",
   125  			Service:   NewPrivateDebugAPI(apiBackend),
   126  		}, {
   127  			Namespace: "eth",
   128  			Version:   "1.0",
   129  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   130  			Public:    true,
   131  		}, {
   132  			Namespace: "personal",
   133  			Version:   "1.0",
   134  			Service:   NewPrivateAccountAPI(apiBackend, nonceLock),
   135  			Public:    false,
   136  		}, {
   137  			Namespace: "db",
   138  			Version:   "1.0",
   139  			Service:   NewPublicDBAPI(apiBackend),
   140  			Public:    true,
   141  		},
   142  	}
   143  }