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