github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/internal/qctapi/backend.go (about) 1 // Package qctapi implements the general Ethereum API functions. 2 package qctapi 3 4 import ( 5 "context" 6 "math/big" 7 8 "github.com/quickchainproject/quickchain/accounts" 9 "github.com/quickchainproject/quickchain/common" 10 "github.com/quickchainproject/quickchain/core" 11 "github.com/quickchainproject/quickchain/core/state" 12 "github.com/quickchainproject/quickchain/core/types" 13 "github.com/quickchainproject/quickchain/core/vm" 14 "github.com/quickchainproject/quickchain/event" 15 "github.com/quickchainproject/quickchain/qct/downloader" 16 "github.com/quickchainproject/quickchain/qctdb" 17 "github.com/quickchainproject/quickchain/params" 18 "github.com/quickchainproject/quickchain/rpc" 19 ) 20 21 // Backend interface provides the common API services (that are provided by 22 // both full and light clients) with access to necessary functions. 23 type Backend interface { 24 // General Ethereum API 25 Downloader() *downloader.Downloader 26 ProtocolVersion() int 27 SuggestPrice(ctx context.Context) (*big.Int, error) 28 ChainDb() qctdb.Database 29 EventMux() *event.TypeMux 30 AccountManager() *accounts.Manager 31 32 // BlockChain API 33 SetHead(number uint64) 34 HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) 35 BlockByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Block, error) 36 StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) 37 GetBlock(ctx context.Context, blockHash common.Hash) (*types.Block, error) 38 GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) 39 GetTd(blockHash common.Hash) *big.Int 40 GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmCfg vm.Config) (*vm.EVM, func() error, error) 41 SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription 42 SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription 43 SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription 44 45 // TxPool API 46 SendTx(ctx context.Context, signedTx *types.Transaction) error 47 GetPoolTransactions() (types.Transactions, error) 48 GetPoolTransaction(txHash common.Hash) *types.Transaction 49 GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) 50 Stats() (pending int, queued int) 51 TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions) 52 SubscribeTxPreEvent(chan<- core.TxPreEvent) event.Subscription 53 54 ChainConfig() *params.ChainConfig 55 CurrentBlock() *types.Block 56 } 57 58 func GetAPIs(apiBackend Backend) []rpc.API { 59 nonceLock := new(AddrLocker) 60 return []rpc.API{ 61 { 62 Namespace: "qct", 63 Version: "1.0", 64 Service: NewPublicEthereumAPI(apiBackend), 65 Public: true, 66 }, { 67 Namespace: "qct", 68 Version: "1.0", 69 Service: NewPublicBlockChainAPI(apiBackend), 70 Public: true, 71 }, { 72 Namespace: "qct", 73 Version: "1.0", 74 Service: NewPublicTransactionPoolAPI(apiBackend, nonceLock), 75 Public: true, 76 }, { 77 Namespace: "txpool", 78 Version: "1.0", 79 Service: NewPublicTxPoolAPI(apiBackend), 80 Public: true, 81 }, { 82 Namespace: "debug", 83 Version: "1.0", 84 Service: NewPublicDebugAPI(apiBackend), 85 Public: true, 86 }, { 87 Namespace: "debug", 88 Version: "1.0", 89 Service: NewPrivateDebugAPI(apiBackend), 90 }, { 91 Namespace: "qct", 92 Version: "1.0", 93 Service: NewPublicAccountAPI(apiBackend.AccountManager()), 94 Public: true, 95 }, { 96 Namespace: "personal", 97 Version: "1.0", 98 Service: NewPrivateAccountAPI(apiBackend, nonceLock), 99 Public: false, 100 }, 101 } 102 }