backend.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. // Package ethapi implements the general Ethereum API functions.
  17. package ethapi
  18. import (
  19. "context"
  20. "math/big"
  21. "time"
  22. "github.com/ethereum/go-ethereum/accounts"
  23. "github.com/ethereum/go-ethereum/common"
  24. "github.com/ethereum/go-ethereum/consensus"
  25. "github.com/ethereum/go-ethereum/core"
  26. "github.com/ethereum/go-ethereum/core/bloombits"
  27. "github.com/ethereum/go-ethereum/core/mps"
  28. "github.com/ethereum/go-ethereum/core/types"
  29. "github.com/ethereum/go-ethereum/core/vm"
  30. "github.com/ethereum/go-ethereum/eth/downloader"
  31. "github.com/ethereum/go-ethereum/ethdb"
  32. "github.com/ethereum/go-ethereum/event"
  33. "github.com/ethereum/go-ethereum/params"
  34. "github.com/ethereum/go-ethereum/rpc"
  35. "github.com/jpmorganchase/quorum-security-plugin-sdk-go/proto"
  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. SuggestPrice(ctx context.Context) (*big.Int, error)
  43. ChainDb() ethdb.Database
  44. AccountManager() *accounts.Manager
  45. ExtRPCEnabled() bool
  46. RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
  47. RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
  48. UnprotectedAllowed() bool // allows only for EIP155 transactions.
  49. // Blockchain API
  50. SetHead(number uint64)
  51. HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
  52. HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)
  53. HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
  54. CurrentHeader() *types.Header
  55. CurrentBlock() *types.Block
  56. BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
  57. BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
  58. BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
  59. StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (vm.MinimalApiState, *types.Header, error)
  60. StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (vm.MinimalApiState, *types.Header, error)
  61. GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
  62. GetTd(ctx context.Context, hash common.Hash) *big.Int
  63. GetEVM(ctx context.Context, msg core.Message, state vm.MinimalApiState, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error)
  64. SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
  65. SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
  66. SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
  67. // Transaction pool API
  68. SendTx(ctx context.Context, signedTx *types.Transaction) error
  69. GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
  70. GetPoolTransactions() (types.Transactions, error)
  71. GetPoolTransaction(txHash common.Hash) *types.Transaction
  72. GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)
  73. Stats() (pending int, queued int)
  74. TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
  75. SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
  76. // Filter API
  77. BloomStatus() (uint64, uint64)
  78. GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error)
  79. ServiceFilter(ctx context.Context, session *bloombits.MatcherSession)
  80. SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
  81. SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription
  82. SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
  83. ChainConfig() *params.ChainConfig
  84. Engine() consensus.Engine
  85. // Quorum
  86. CallTimeOut() time.Duration
  87. // AccountExtraDataStateGetterByNumber returns state getter at a given block height
  88. AccountExtraDataStateGetterByNumber(ctx context.Context, number rpc.BlockNumber) (vm.AccountExtraDataStateGetter, error)
  89. PSMR() mps.PrivateStateMetadataResolver
  90. SupportsMultitenancy(rpcCtx context.Context) (*proto.PreAuthenticatedAuthenticationToken, bool)
  91. // IsPrivacyMarkerTransactionCreationEnabled returns true if privacy marker transactions are enabled and should be created
  92. IsPrivacyMarkerTransactionCreationEnabled() bool
  93. }
  94. func GetAPIs(apiBackend Backend) []rpc.API {
  95. nonceLock := new(AddrLocker)
  96. return []rpc.API{
  97. {
  98. Namespace: "eth",
  99. Version: "1.0",
  100. Service: NewPublicEthereumAPI(apiBackend),
  101. Public: true,
  102. }, {
  103. Namespace: "eth",
  104. Version: "1.0",
  105. Service: NewPublicBlockChainAPI(apiBackend),
  106. Public: true,
  107. }, {
  108. Namespace: "eth",
  109. Version: "1.0",
  110. Service: NewPublicTransactionPoolProxyAPI(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: "eth",
  128. Version: "1.0",
  129. Service: NewPublicAccountAPI(apiBackend.AccountManager()),
  130. Public: true,
  131. }, {
  132. Namespace: "personal",
  133. Version: "1.0",
  134. Service: NewPrivateAccountProxyAPI(apiBackend, nonceLock),
  135. Public: false,
  136. },
  137. }
  138. }