github.com/aswedchain/aswed@v1.0.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  
    24  	"github.com/aswedchain/aswed/accounts"
    25  	"github.com/aswedchain/aswed/common"
    26  	"github.com/aswedchain/aswed/consensus"
    27  	"github.com/aswedchain/aswed/core"
    28  	"github.com/aswedchain/aswed/core/bloombits"
    29  	"github.com/aswedchain/aswed/core/state"
    30  	"github.com/aswedchain/aswed/core/types"
    31  	"github.com/aswedchain/aswed/core/vm"
    32  	"github.com/aswedchain/aswed/eth/downloader"
    33  	"github.com/aswedchain/aswed/ethdb"
    34  	"github.com/aswedchain/aswed/event"
    35  	"github.com/aswedchain/aswed/params"
    36  	"github.com/aswedchain/aswed/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  	ProtocolVersion() int
    45  	SuggestPrice(ctx context.Context) (*big.Int, error)
    46  	PricePrediction(ctx context.Context) ([]uint, error)
    47  	ChainDb() ethdb.Database
    48  	AccountManager() *accounts.Manager
    49  	ExtRPCEnabled() bool
    50  	RPCGasCap() uint64    // global gas cap for eth_call over rpc: DoS protection
    51  	RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
    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) (*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  	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
    81  	JamIndex() int
    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  	// Trace
    94  	TraceBlock(ctx context.Context, block *types.Block, tracer string) ([]*TxTraceResult, error)
    95  }
    96  
    97  type TxTraceResult struct {
    98  	Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer
    99  	Error  string      `json:"error,omitempty"`  // Trace failure produced by the tracer
   100  }
   101  
   102  func GetAPIs(apiBackend Backend) []rpc.API {
   103  	nonceLock := new(AddrLocker)
   104  	return []rpc.API{
   105  		{
   106  			Namespace: "eth",
   107  			Version:   "1.0",
   108  			Service:   NewPublicEthereumAPI(apiBackend),
   109  			Public:    true,
   110  		}, {
   111  			Namespace: "eth",
   112  			Version:   "1.0",
   113  			Service:   NewPublicBlockChainAPI(apiBackend),
   114  			Public:    true,
   115  		}, {
   116  			Namespace: "eth",
   117  			Version:   "1.0",
   118  			Service:   NewPublicTransactionPoolAPI(apiBackend, nonceLock),
   119  			Public:    true,
   120  		}, {
   121  			Namespace: "txpool",
   122  			Version:   "1.0",
   123  			Service:   NewPublicTxPoolAPI(apiBackend),
   124  			Public:    true,
   125  		}, {
   126  			Namespace: "debug",
   127  			Version:   "1.0",
   128  			Service:   NewPublicDebugAPI(apiBackend),
   129  			Public:    true,
   130  		}, {
   131  			Namespace: "debug",
   132  			Version:   "1.0",
   133  			Service:   NewPrivateDebugAPI(apiBackend),
   134  		}, {
   135  			Namespace: "eth",
   136  			Version:   "1.0",
   137  			Service:   NewPublicAccountAPI(apiBackend.AccountManager()),
   138  			Public:    true,
   139  		}, {
   140  			Namespace: "personal",
   141  			Version:   "1.0",
   142  			Service:   NewPrivateAccountAPI(apiBackend, nonceLock),
   143  			Public:    false,
   144  		},
   145  	}
   146  }