github.com/halybang/go-ethereum@v1.0.5-0.20180325041310-3b262bc1367c/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/wanchain/go-wanchain/accounts" 25 "github.com/wanchain/go-wanchain/common" 26 "github.com/wanchain/go-wanchain/core" 27 "github.com/wanchain/go-wanchain/core/state" 28 "github.com/wanchain/go-wanchain/core/types" 29 "github.com/wanchain/go-wanchain/core/vm" 30 "github.com/wanchain/go-wanchain/eth/downloader" 31 "github.com/wanchain/go-wanchain/ethdb" 32 "github.com/wanchain/go-wanchain/event" 33 "github.com/wanchain/go-wanchain/params" 34 "github.com/wanchain/go-wanchain/rpc" 35 ) 36 37 // Backend interface provides the common API services (that are provided by 38 // both full and light clients) with access to necessary functions. 39 type Backend interface { 40 // general Ethereum API 41 Downloader() *downloader.Downloader 42 ProtocolVersion() int 43 SuggestPrice(ctx context.Context) (*big.Int, error) 44 ChainDb() ethdb.Database 45 EventMux() *event.TypeMux 46 AccountManager() *accounts.Manager 47 // BlockChain API 48 SetHead(number uint64) 49 HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) 50 BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) 51 StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) 52 GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) 53 GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) 54 GetTd(blockHash common.Hash) *big.Int 55 GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) 56 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 57 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 58 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 59 60 // TxPool API 61 SendTx(ctx context.Context, signedTx *types.Transaction) error 62 GetPoolTransactions() (types.Transactions, error) 63 GetPoolTransaction(txHash common.Hash) *types.Transaction 64 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 65 Stats() (pending int, queued int) 66 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 67 SubscribeTxPreEvent(chan<- core.TxPreEvent) event.Subscription 68 69 ChainConfig() *params.ChainConfig 70 CurrentBlock() *types.Block 71 } 72 73 func GetAPIs(apiBackend Backend) []rpc.API { 74 nonceLock := new(AddrLocker) 75 return []rpc.API{ 76 { 77 Namespace: "eth", 78 Version: "1.0", 79 Service: NewPublicEthereumAPI(apiBackend), 80 Public: true, 81 }, { 82 Namespace: "eth", 83 Version: "1.0", 84 Service: NewPublicBlockChainAPI(apiBackend), 85 Public: true, 86 }, { 87 Namespace: "wan", 88 Version: "1.0", 89 Service: NewPublicBlockChainAPI(apiBackend), 90 Public: true, 91 }, { 92 Namespace: "eth", 93 Version: "1.0", 94 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 95 Public: true, 96 }, { 97 Namespace: "wan", 98 Version: "1.0", 99 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 100 Public: true, 101 }, { 102 Namespace: "txpool", 103 Version: "1.0", 104 Service: NewPublicTxPoolAPI(apiBackend), 105 Public: true, 106 }, { 107 Namespace: "debug", 108 Version: "1.0", 109 Service: NewPublicDebugAPI(apiBackend), 110 Public: true, 111 }, { 112 Namespace: "debug", 113 Version: "1.0", 114 Service: NewPrivateDebugAPI(apiBackend), 115 }, { 116 Namespace: "eth", 117 Version: "1.0", 118 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 119 Public: true, 120 }, { 121 Namespace: "personal", 122 Version: "1.0", 123 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 124 Public: false, 125 }, 126 } 127 }