github.com/core-coin/go-core/v2@v2.1.9/internal/xcbapi/backend.go (about) 1 // Copyright 2015 by the Authors 2 // This file is part of the go-core library. 3 // 4 // The go-core 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-core 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-core library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package xcbapi implements the general Core API functions. 18 package xcbapi 19 20 import ( 21 "context" 22 "math/big" 23 24 "github.com/core-coin/go-core/v2/xcbdb" 25 26 "github.com/core-coin/go-core/v2/accounts" 27 "github.com/core-coin/go-core/v2/common" 28 "github.com/core-coin/go-core/v2/consensus" 29 "github.com/core-coin/go-core/v2/core" 30 "github.com/core-coin/go-core/v2/core/bloombits" 31 "github.com/core-coin/go-core/v2/core/state" 32 "github.com/core-coin/go-core/v2/core/types" 33 "github.com/core-coin/go-core/v2/core/vm" 34 "github.com/core-coin/go-core/v2/event" 35 "github.com/core-coin/go-core/v2/params" 36 "github.com/core-coin/go-core/v2/rpc" 37 "github.com/core-coin/go-core/v2/xcb/downloader" 38 ) 39 40 // Backend interface provides the common API services (that are provided by 41 // both full and light clients) with access to necessary functions. 42 type Backend interface { 43 // General Core API 44 Downloader() *downloader.Downloader 45 ProtocolVersion() int 46 SuggestPrice(ctx context.Context) (*big.Int, error) 47 ChainDb() xcbdb.Database 48 AccountManager() *accounts.Manager 49 ExtRPCEnabled() bool 50 RPCEnergyCap() uint64 // global energy cap for xcb_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 GetCVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.CVM, 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 82 // Filter API 83 BloomStatus() (uint64, uint64) 84 GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) 85 ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) 86 SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription 87 SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription 88 SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription 89 90 ChainConfig() *params.ChainConfig 91 Engine() consensus.Engine 92 } 93 94 func GetAPIs(apiBackend Backend) []rpc.API { 95 nonceLock := new(AddrLocker) 96 return []rpc.API{ 97 { 98 Namespace: "xcb", 99 Version: "1.0", 100 Service: NewPublicCoreAPI(apiBackend), 101 Public: true, 102 }, { 103 Namespace: "xcb", 104 Version: "1.0", 105 Service: NewPublicBlockChainAPI(apiBackend), 106 Public: true, 107 }, { 108 Namespace: "xcb", 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: "xcb", 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 } 138 }