// // DO NOT EDIT. // swift-format-ignore-file // // Generated by the protocol buffer compiler. // Source: darkside.proto // import GRPC import NIO import NIOConcurrencyHelpers import SwiftProtobuf @testable import ZcashLightClientKit /// Darksidewalletd maintains two staging areas, blocks and transactions. The /// Stage*() gRPCs add items to the staging area; ApplyStaged() "applies" everything /// in the staging area to the working (operational) state that the mock zcashd /// serves; transactions are placed into their corresponding blocks (by height). /// /// Usage: instantiate `DarksideStreamerClient`, then call methods of this protocol to make API calls. internal protocol DarksideStreamerClientProtocol: GRPCClient { var serviceName: String { get } var interceptors: DarksideStreamerClientInterceptorFactoryProtocol? { get } func reset( _ request: DarksideMetaState, callOptions: CallOptions? ) -> UnaryCall func stageBlocksStream( callOptions: CallOptions? ) -> ClientStreamingCall func stageBlocks( _ request: DarksideBlocksURL, callOptions: CallOptions? ) -> UnaryCall func stageBlocksCreate( _ request: DarksideEmptyBlocks, callOptions: CallOptions? ) -> UnaryCall func stageTransactionsStream( callOptions: CallOptions? ) -> ClientStreamingCall func stageTransactions( _ request: DarksideTransactionsURL, callOptions: CallOptions? ) -> UnaryCall func applyStaged( _ request: DarksideHeight, callOptions: CallOptions? ) -> UnaryCall func getIncomingTransactions( _ request: Empty, callOptions: CallOptions?, handler: @escaping (RawTransaction) -> Void ) -> ServerStreamingCall func clearIncomingTransactions( _ request: Empty, callOptions: CallOptions? ) -> UnaryCall func addAddressUtxo( _ request: GetAddressUtxosReply, callOptions: CallOptions? ) -> UnaryCall func clearAddressUtxo( _ request: Empty, callOptions: CallOptions? ) -> UnaryCall func addTreeState( _ request: TreeState, callOptions: CallOptions? ) -> UnaryCall func removeTreeState( _ request: BlockID, callOptions: CallOptions? ) -> UnaryCall func clearAllTreeStates( _ request: Empty, callOptions: CallOptions? ) -> UnaryCall func setSubtreeRoots( _ request: DarksideSubtreeRoots, callOptions: CallOptions? ) -> UnaryCall } extension DarksideStreamerClientProtocol { internal var serviceName: String { return "cash.z.wallet.sdk.rpc.DarksideStreamer" } /// Reset reverts all darksidewalletd state (active block range, latest height, /// staged blocks and transactions) and lightwalletd state (cache) to empty, /// the same as the initial state. This occurs synchronously and instantaneously; /// no reorg happens in lightwalletd. This is good to do before each independent /// test so that no state leaks from one test to another. /// Also sets (some of) the values returned by GetLightdInfo(). The Sapling /// activation height specified here must be where the block range starts. /// /// - Parameters: /// - request: Request to send to Reset. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func reset( _ request: DarksideMetaState, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.reset.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeResetInterceptors() ?? [] ) } /// StageBlocksStream accepts a list of blocks and saves them into the blocks /// staging area until ApplyStaged() is called; there is no immediate effect on /// the mock zcashd. Blocks are hex-encoded. Order is important, see ApplyStaged. /// /// Callers should use the `send` method on the returned object to send messages /// to the server. The caller should send an `.end` after the final message has been sent. /// /// - Parameters: /// - callOptions: Call options. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response. internal func stageBlocksStream( callOptions: CallOptions? = nil ) -> ClientStreamingCall { return self.makeClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksStream.path, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksStreamInterceptors() ?? [] ) } /// StageBlocks is the same as StageBlocksStream() except the blocks are fetched /// from the given URL. Blocks are one per line, hex-encoded (not JSON). /// /// - Parameters: /// - request: Request to send to StageBlocks. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func stageBlocks( _ request: DarksideBlocksURL, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageBlocks.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksInterceptors() ?? [] ) } /// StageBlocksCreate is like the previous two, except it creates 'count' /// empty blocks at consecutive heights starting at height 'height'. The /// 'nonce' is part of the header, so it contributes to the block hash; this /// lets you create identical blocks (same transactions and height), but with /// different hashes. /// /// - Parameters: /// - request: Request to send to StageBlocksCreate. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func stageBlocksCreate( _ request: DarksideEmptyBlocks, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksCreate.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksCreateInterceptors() ?? [] ) } /// StageTransactionsStream stores the given transaction-height pairs in the /// staging area until ApplyStaged() is called. Note that these transactions /// are not returned by the production GetTransaction() gRPC until they /// appear in a "mined" block (contained in the active blockchain presented /// by the mock zcashd). /// /// Callers should use the `send` method on the returned object to send messages /// to the server. The caller should send an `.end` after the final message has been sent. /// /// - Parameters: /// - callOptions: Call options. /// - Returns: A `ClientStreamingCall` with futures for the metadata, status and response. internal func stageTransactionsStream( callOptions: CallOptions? = nil ) -> ClientStreamingCall { return self.makeClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageTransactionsStream.path, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsStreamInterceptors() ?? [] ) } /// StageTransactions is the same except the transactions are fetched from /// the given url. They are all staged into the block at the given height. /// Staging transactions to different heights requires multiple calls. /// /// - Parameters: /// - request: Request to send to StageTransactions. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func stageTransactions( _ request: DarksideTransactionsURL, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsInterceptors() ?? [] ) } /// ApplyStaged iterates the list of blocks that were staged by the /// StageBlocks*() gRPCs, in the order they were staged, and "merges" each /// into the active, working blocks list that the mock zcashd is presenting /// to lightwalletd. Even as each block is applied, the active list can't /// have gaps; if the active block range is 1000-1006, and the staged block /// range is 1003-1004, the resulting range is 1000-1004, with 1000-1002 /// unchanged, blocks 1003-1004 from the new range, and 1005-1006 dropped. /// /// After merging all blocks, ApplyStaged() appends staged transactions (in /// the order received) into each one's corresponding (by height) block /// The staging area is then cleared. /// /// The argument specifies the latest block height that mock zcashd reports /// (i.e. what's returned by GetLatestBlock). Note that ApplyStaged() can /// also be used to simply advance the latest block height presented by mock /// zcashd. That is, there doesn't need to be anything in the staging area. /// /// - Parameters: /// - request: Request to send to ApplyStaged. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func applyStaged( _ request: DarksideHeight, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.applyStaged.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeApplyStagedInterceptors() ?? [] ) } /// Calls to the production gRPC SendTransaction() store the transaction in /// a separate area (not the staging area); this method returns all transactions /// in this separate area, which is then cleared. The height returned /// with each transaction is -1 (invalid) since these transactions haven't /// been mined yet. The intention is that the transactions returned here can /// then, for example, be given to StageTransactions() to get them "mined" /// into a specified block on the next ApplyStaged(). /// /// - Parameters: /// - request: Request to send to GetIncomingTransactions. /// - callOptions: Call options. /// - handler: A closure called when each response is received from the server. /// - Returns: A `ServerStreamingCall` with futures for the metadata and status. internal func getIncomingTransactions( _ request: Empty, callOptions: CallOptions? = nil, handler: @escaping (RawTransaction) -> Void ) -> ServerStreamingCall { return self.makeServerStreamingCall( path: DarksideStreamerClientMetadata.Methods.getIncomingTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeGetIncomingTransactionsInterceptors() ?? [], handler: handler ) } /// Clear the incoming transaction pool. /// /// - Parameters: /// - request: Request to send to ClearIncomingTransactions. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func clearIncomingTransactions( _ request: Empty, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearIncomingTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearIncomingTransactionsInterceptors() ?? [] ) } /// Add a GetAddressUtxosReply entry to be returned by GetAddressUtxos(). /// There is no staging or applying for these, very simple. /// /// - Parameters: /// - request: Request to send to AddAddressUtxo. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func addAddressUtxo( _ request: GetAddressUtxosReply, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.addAddressUtxo.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeAddAddressUtxoInterceptors() ?? [] ) } /// Clear the list of GetAddressUtxos entries (can't fail) /// /// - Parameters: /// - request: Request to send to ClearAddressUtxo. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func clearAddressUtxo( _ request: Empty, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearAddressUtxo.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearAddressUtxoInterceptors() ?? [] ) } /// Adds a GetTreeState to the tree state cache /// /// - Parameters: /// - request: Request to send to AddTreeState. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func addTreeState( _ request: TreeState, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.addTreeState.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeAddTreeStateInterceptors() ?? [] ) } /// Removes a GetTreeState for the given height from cache if present (can't fail) /// /// - Parameters: /// - request: Request to send to RemoveTreeState. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func removeTreeState( _ request: BlockID, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.removeTreeState.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeRemoveTreeStateInterceptors() ?? [] ) } /// Clear the list of GetTreeStates entries (can't fail) /// /// - Parameters: /// - request: Request to send to ClearAllTreeStates. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func clearAllTreeStates( _ request: Empty, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearAllTreeStates.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearAllTreeStatesInterceptors() ?? [] ) } /// Sets the subtree roots cache (for GetSubtreeRoots), /// replacing any existing entries /// /// - Parameters: /// - request: Request to send to SetSubtreeRoots. /// - callOptions: Call options. /// - Returns: A `UnaryCall` with futures for the metadata, status and response. internal func setSubtreeRoots( _ request: DarksideSubtreeRoots, callOptions: CallOptions? = nil ) -> UnaryCall { return self.makeUnaryCall( path: DarksideStreamerClientMetadata.Methods.setSubtreeRoots.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeSetSubtreeRootsInterceptors() ?? [] ) } } @available(*, deprecated) extension DarksideStreamerClient: @unchecked Sendable {} @available(*, deprecated, renamed: "DarksideStreamerNIOClient") internal final class DarksideStreamerClient: DarksideStreamerClientProtocol { private let lock = Lock() private var _defaultCallOptions: CallOptions private var _interceptors: DarksideStreamerClientInterceptorFactoryProtocol? internal let channel: GRPCChannel internal var defaultCallOptions: CallOptions { get { self.lock.withLock { return self._defaultCallOptions } } set { self.lock.withLockVoid { self._defaultCallOptions = newValue } } } internal var interceptors: DarksideStreamerClientInterceptorFactoryProtocol? { get { self.lock.withLock { return self._interceptors } } set { self.lock.withLockVoid { self._interceptors = newValue } } } /// Creates a client for the cash.z.wallet.sdk.rpc.DarksideStreamer service. /// /// - Parameters: /// - channel: `GRPCChannel` to the service host. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. /// - interceptors: A factory providing interceptors for each RPC. internal init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), interceptors: DarksideStreamerClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self._defaultCallOptions = defaultCallOptions self._interceptors = interceptors } } internal struct DarksideStreamerNIOClient: DarksideStreamerClientProtocol { internal var channel: GRPCChannel internal var defaultCallOptions: CallOptions internal var interceptors: DarksideStreamerClientInterceptorFactoryProtocol? /// Creates a client for the cash.z.wallet.sdk.rpc.DarksideStreamer service. /// /// - Parameters: /// - channel: `GRPCChannel` to the service host. /// - defaultCallOptions: Options to use for each service call if the user doesn't provide them. /// - interceptors: A factory providing interceptors for each RPC. internal init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), interceptors: DarksideStreamerClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self.defaultCallOptions = defaultCallOptions self.interceptors = interceptors } } /// Darksidewalletd maintains two staging areas, blocks and transactions. The /// Stage*() gRPCs add items to the staging area; ApplyStaged() "applies" everything /// in the staging area to the working (operational) state that the mock zcashd /// serves; transactions are placed into their corresponding blocks (by height). @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) internal protocol DarksideStreamerAsyncClientProtocol: GRPCClient { static var serviceDescriptor: GRPCServiceDescriptor { get } var interceptors: DarksideStreamerClientInterceptorFactoryProtocol? { get } func makeResetCall( _ request: DarksideMetaState, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeStageBlocksStreamCall( callOptions: CallOptions? ) -> GRPCAsyncClientStreamingCall func makeStageBlocksCall( _ request: DarksideBlocksURL, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeStageBlocksCreateCall( _ request: DarksideEmptyBlocks, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeStageTransactionsStreamCall( callOptions: CallOptions? ) -> GRPCAsyncClientStreamingCall func makeStageTransactionsCall( _ request: DarksideTransactionsURL, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeApplyStagedCall( _ request: DarksideHeight, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeGetIncomingTransactionsCall( _ request: Empty, callOptions: CallOptions? ) -> GRPCAsyncServerStreamingCall func makeClearIncomingTransactionsCall( _ request: Empty, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeAddAddressUtxoCall( _ request: GetAddressUtxosReply, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeClearAddressUtxoCall( _ request: Empty, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeAddTreeStateCall( _ request: TreeState, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeRemoveTreeStateCall( _ request: BlockID, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeClearAllTreeStatesCall( _ request: Empty, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall func makeSetSubtreeRootsCall( _ request: DarksideSubtreeRoots, callOptions: CallOptions? ) -> GRPCAsyncUnaryCall } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) extension DarksideStreamerAsyncClientProtocol { internal static var serviceDescriptor: GRPCServiceDescriptor { return DarksideStreamerClientMetadata.serviceDescriptor } internal var interceptors: DarksideStreamerClientInterceptorFactoryProtocol? { return nil } internal func makeResetCall( _ request: DarksideMetaState, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.reset.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeResetInterceptors() ?? [] ) } internal func makeStageBlocksStreamCall( callOptions: CallOptions? = nil ) -> GRPCAsyncClientStreamingCall { return self.makeAsyncClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksStream.path, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksStreamInterceptors() ?? [] ) } internal func makeStageBlocksCall( _ request: DarksideBlocksURL, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageBlocks.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksInterceptors() ?? [] ) } internal func makeStageBlocksCreateCall( _ request: DarksideEmptyBlocks, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksCreate.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksCreateInterceptors() ?? [] ) } internal func makeStageTransactionsStreamCall( callOptions: CallOptions? = nil ) -> GRPCAsyncClientStreamingCall { return self.makeAsyncClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageTransactionsStream.path, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsStreamInterceptors() ?? [] ) } internal func makeStageTransactionsCall( _ request: DarksideTransactionsURL, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsInterceptors() ?? [] ) } internal func makeApplyStagedCall( _ request: DarksideHeight, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.applyStaged.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeApplyStagedInterceptors() ?? [] ) } internal func makeGetIncomingTransactionsCall( _ request: Empty, callOptions: CallOptions? = nil ) -> GRPCAsyncServerStreamingCall { return self.makeAsyncServerStreamingCall( path: DarksideStreamerClientMetadata.Methods.getIncomingTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeGetIncomingTransactionsInterceptors() ?? [] ) } internal func makeClearIncomingTransactionsCall( _ request: Empty, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearIncomingTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearIncomingTransactionsInterceptors() ?? [] ) } internal func makeAddAddressUtxoCall( _ request: GetAddressUtxosReply, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.addAddressUtxo.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeAddAddressUtxoInterceptors() ?? [] ) } internal func makeClearAddressUtxoCall( _ request: Empty, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearAddressUtxo.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearAddressUtxoInterceptors() ?? [] ) } internal func makeAddTreeStateCall( _ request: TreeState, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.addTreeState.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeAddTreeStateInterceptors() ?? [] ) } internal func makeRemoveTreeStateCall( _ request: BlockID, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.removeTreeState.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeRemoveTreeStateInterceptors() ?? [] ) } internal func makeClearAllTreeStatesCall( _ request: Empty, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearAllTreeStates.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearAllTreeStatesInterceptors() ?? [] ) } internal func makeSetSubtreeRootsCall( _ request: DarksideSubtreeRoots, callOptions: CallOptions? = nil ) -> GRPCAsyncUnaryCall { return self.makeAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.setSubtreeRoots.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeSetSubtreeRootsInterceptors() ?? [] ) } } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) extension DarksideStreamerAsyncClientProtocol { internal func reset( _ request: DarksideMetaState, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.reset.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeResetInterceptors() ?? [] ) } internal func stageBlocksStream( _ requests: RequestStream, callOptions: CallOptions? = nil ) async throws -> Empty where RequestStream: Sequence, RequestStream.Element == DarksideBlock { return try await self.performAsyncClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksStream.path, requests: requests, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksStreamInterceptors() ?? [] ) } internal func stageBlocksStream( _ requests: RequestStream, callOptions: CallOptions? = nil ) async throws -> Empty where RequestStream: AsyncSequence & Sendable, RequestStream.Element == DarksideBlock { return try await self.performAsyncClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksStream.path, requests: requests, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksStreamInterceptors() ?? [] ) } internal func stageBlocks( _ request: DarksideBlocksURL, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageBlocks.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksInterceptors() ?? [] ) } internal func stageBlocksCreate( _ request: DarksideEmptyBlocks, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageBlocksCreate.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageBlocksCreateInterceptors() ?? [] ) } internal func stageTransactionsStream( _ requests: RequestStream, callOptions: CallOptions? = nil ) async throws -> Empty where RequestStream: Sequence, RequestStream.Element == RawTransaction { return try await self.performAsyncClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageTransactionsStream.path, requests: requests, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsStreamInterceptors() ?? [] ) } internal func stageTransactionsStream( _ requests: RequestStream, callOptions: CallOptions? = nil ) async throws -> Empty where RequestStream: AsyncSequence & Sendable, RequestStream.Element == RawTransaction { return try await self.performAsyncClientStreamingCall( path: DarksideStreamerClientMetadata.Methods.stageTransactionsStream.path, requests: requests, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsStreamInterceptors() ?? [] ) } internal func stageTransactions( _ request: DarksideTransactionsURL, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.stageTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeStageTransactionsInterceptors() ?? [] ) } internal func applyStaged( _ request: DarksideHeight, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.applyStaged.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeApplyStagedInterceptors() ?? [] ) } internal func getIncomingTransactions( _ request: Empty, callOptions: CallOptions? = nil ) -> GRPCAsyncResponseStream { return self.performAsyncServerStreamingCall( path: DarksideStreamerClientMetadata.Methods.getIncomingTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeGetIncomingTransactionsInterceptors() ?? [] ) } internal func clearIncomingTransactions( _ request: Empty, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearIncomingTransactions.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearIncomingTransactionsInterceptors() ?? [] ) } internal func addAddressUtxo( _ request: GetAddressUtxosReply, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.addAddressUtxo.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeAddAddressUtxoInterceptors() ?? [] ) } internal func clearAddressUtxo( _ request: Empty, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearAddressUtxo.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearAddressUtxoInterceptors() ?? [] ) } internal func addTreeState( _ request: TreeState, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.addTreeState.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeAddTreeStateInterceptors() ?? [] ) } internal func removeTreeState( _ request: BlockID, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.removeTreeState.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeRemoveTreeStateInterceptors() ?? [] ) } internal func clearAllTreeStates( _ request: Empty, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.clearAllTreeStates.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeClearAllTreeStatesInterceptors() ?? [] ) } internal func setSubtreeRoots( _ request: DarksideSubtreeRoots, callOptions: CallOptions? = nil ) async throws -> Empty { return try await self.performAsyncUnaryCall( path: DarksideStreamerClientMetadata.Methods.setSubtreeRoots.path, request: request, callOptions: callOptions ?? self.defaultCallOptions, interceptors: self.interceptors?.makeSetSubtreeRootsInterceptors() ?? [] ) } } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) internal struct DarksideStreamerAsyncClient: DarksideStreamerAsyncClientProtocol { internal var channel: GRPCChannel internal var defaultCallOptions: CallOptions internal var interceptors: DarksideStreamerClientInterceptorFactoryProtocol? internal init( channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions(), interceptors: DarksideStreamerClientInterceptorFactoryProtocol? = nil ) { self.channel = channel self.defaultCallOptions = defaultCallOptions self.interceptors = interceptors } } internal protocol DarksideStreamerClientInterceptorFactoryProtocol: Sendable { /// - Returns: Interceptors to use when invoking 'reset'. func makeResetInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'stageBlocksStream'. func makeStageBlocksStreamInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'stageBlocks'. func makeStageBlocksInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'stageBlocksCreate'. func makeStageBlocksCreateInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'stageTransactionsStream'. func makeStageTransactionsStreamInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'stageTransactions'. func makeStageTransactionsInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'applyStaged'. func makeApplyStagedInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'getIncomingTransactions'. func makeGetIncomingTransactionsInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'clearIncomingTransactions'. func makeClearIncomingTransactionsInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'addAddressUtxo'. func makeAddAddressUtxoInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'clearAddressUtxo'. func makeClearAddressUtxoInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'addTreeState'. func makeAddTreeStateInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'removeTreeState'. func makeRemoveTreeStateInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'clearAllTreeStates'. func makeClearAllTreeStatesInterceptors() -> [ClientInterceptor] /// - Returns: Interceptors to use when invoking 'setSubtreeRoots'. func makeSetSubtreeRootsInterceptors() -> [ClientInterceptor] } internal enum DarksideStreamerClientMetadata { internal static let serviceDescriptor = GRPCServiceDescriptor( name: "DarksideStreamer", fullName: "cash.z.wallet.sdk.rpc.DarksideStreamer", methods: [ DarksideStreamerClientMetadata.Methods.reset, DarksideStreamerClientMetadata.Methods.stageBlocksStream, DarksideStreamerClientMetadata.Methods.stageBlocks, DarksideStreamerClientMetadata.Methods.stageBlocksCreate, DarksideStreamerClientMetadata.Methods.stageTransactionsStream, DarksideStreamerClientMetadata.Methods.stageTransactions, DarksideStreamerClientMetadata.Methods.applyStaged, DarksideStreamerClientMetadata.Methods.getIncomingTransactions, DarksideStreamerClientMetadata.Methods.clearIncomingTransactions, DarksideStreamerClientMetadata.Methods.addAddressUtxo, DarksideStreamerClientMetadata.Methods.clearAddressUtxo, DarksideStreamerClientMetadata.Methods.addTreeState, DarksideStreamerClientMetadata.Methods.removeTreeState, DarksideStreamerClientMetadata.Methods.clearAllTreeStates, DarksideStreamerClientMetadata.Methods.setSubtreeRoots, ] ) internal enum Methods { internal static let reset = GRPCMethodDescriptor( name: "Reset", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/Reset", type: GRPCCallType.unary ) internal static let stageBlocksStream = GRPCMethodDescriptor( name: "StageBlocksStream", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocksStream", type: GRPCCallType.clientStreaming ) internal static let stageBlocks = GRPCMethodDescriptor( name: "StageBlocks", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocks", type: GRPCCallType.unary ) internal static let stageBlocksCreate = GRPCMethodDescriptor( name: "StageBlocksCreate", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocksCreate", type: GRPCCallType.unary ) internal static let stageTransactionsStream = GRPCMethodDescriptor( name: "StageTransactionsStream", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageTransactionsStream", type: GRPCCallType.clientStreaming ) internal static let stageTransactions = GRPCMethodDescriptor( name: "StageTransactions", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageTransactions", type: GRPCCallType.unary ) internal static let applyStaged = GRPCMethodDescriptor( name: "ApplyStaged", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ApplyStaged", type: GRPCCallType.unary ) internal static let getIncomingTransactions = GRPCMethodDescriptor( name: "GetIncomingTransactions", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/GetIncomingTransactions", type: GRPCCallType.serverStreaming ) internal static let clearIncomingTransactions = GRPCMethodDescriptor( name: "ClearIncomingTransactions", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ClearIncomingTransactions", type: GRPCCallType.unary ) internal static let addAddressUtxo = GRPCMethodDescriptor( name: "AddAddressUtxo", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/AddAddressUtxo", type: GRPCCallType.unary ) internal static let clearAddressUtxo = GRPCMethodDescriptor( name: "ClearAddressUtxo", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ClearAddressUtxo", type: GRPCCallType.unary ) internal static let addTreeState = GRPCMethodDescriptor( name: "AddTreeState", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/AddTreeState", type: GRPCCallType.unary ) internal static let removeTreeState = GRPCMethodDescriptor( name: "RemoveTreeState", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/RemoveTreeState", type: GRPCCallType.unary ) internal static let clearAllTreeStates = GRPCMethodDescriptor( name: "ClearAllTreeStates", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ClearAllTreeStates", type: GRPCCallType.unary ) internal static let setSubtreeRoots = GRPCMethodDescriptor( name: "SetSubtreeRoots", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/SetSubtreeRoots", type: GRPCCallType.unary ) } } /// Darksidewalletd maintains two staging areas, blocks and transactions. The /// Stage*() gRPCs add items to the staging area; ApplyStaged() "applies" everything /// in the staging area to the working (operational) state that the mock zcashd /// serves; transactions are placed into their corresponding blocks (by height). /// /// To build a server, implement a class that conforms to this protocol. internal protocol DarksideStreamerProvider: CallHandlerProvider { var interceptors: DarksideStreamerServerInterceptorFactoryProtocol? { get } /// Reset reverts all darksidewalletd state (active block range, latest height, /// staged blocks and transactions) and lightwalletd state (cache) to empty, /// the same as the initial state. This occurs synchronously and instantaneously; /// no reorg happens in lightwalletd. This is good to do before each independent /// test so that no state leaks from one test to another. /// Also sets (some of) the values returned by GetLightdInfo(). The Sapling /// activation height specified here must be where the block range starts. func reset(request: DarksideMetaState, context: StatusOnlyCallContext) -> EventLoopFuture /// StageBlocksStream accepts a list of blocks and saves them into the blocks /// staging area until ApplyStaged() is called; there is no immediate effect on /// the mock zcashd. Blocks are hex-encoded. Order is important, see ApplyStaged. func stageBlocksStream(context: UnaryResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> /// StageBlocks is the same as StageBlocksStream() except the blocks are fetched /// from the given URL. Blocks are one per line, hex-encoded (not JSON). func stageBlocks(request: DarksideBlocksURL, context: StatusOnlyCallContext) -> EventLoopFuture /// StageBlocksCreate is like the previous two, except it creates 'count' /// empty blocks at consecutive heights starting at height 'height'. The /// 'nonce' is part of the header, so it contributes to the block hash; this /// lets you create identical blocks (same transactions and height), but with /// different hashes. func stageBlocksCreate(request: DarksideEmptyBlocks, context: StatusOnlyCallContext) -> EventLoopFuture /// StageTransactionsStream stores the given transaction-height pairs in the /// staging area until ApplyStaged() is called. Note that these transactions /// are not returned by the production GetTransaction() gRPC until they /// appear in a "mined" block (contained in the active blockchain presented /// by the mock zcashd). func stageTransactionsStream(context: UnaryResponseCallContext) -> EventLoopFuture<(StreamEvent) -> Void> /// StageTransactions is the same except the transactions are fetched from /// the given url. They are all staged into the block at the given height. /// Staging transactions to different heights requires multiple calls. func stageTransactions(request: DarksideTransactionsURL, context: StatusOnlyCallContext) -> EventLoopFuture /// ApplyStaged iterates the list of blocks that were staged by the /// StageBlocks*() gRPCs, in the order they were staged, and "merges" each /// into the active, working blocks list that the mock zcashd is presenting /// to lightwalletd. Even as each block is applied, the active list can't /// have gaps; if the active block range is 1000-1006, and the staged block /// range is 1003-1004, the resulting range is 1000-1004, with 1000-1002 /// unchanged, blocks 1003-1004 from the new range, and 1005-1006 dropped. /// /// After merging all blocks, ApplyStaged() appends staged transactions (in /// the order received) into each one's corresponding (by height) block /// The staging area is then cleared. /// /// The argument specifies the latest block height that mock zcashd reports /// (i.e. what's returned by GetLatestBlock). Note that ApplyStaged() can /// also be used to simply advance the latest block height presented by mock /// zcashd. That is, there doesn't need to be anything in the staging area. func applyStaged(request: DarksideHeight, context: StatusOnlyCallContext) -> EventLoopFuture /// Calls to the production gRPC SendTransaction() store the transaction in /// a separate area (not the staging area); this method returns all transactions /// in this separate area, which is then cleared. The height returned /// with each transaction is -1 (invalid) since these transactions haven't /// been mined yet. The intention is that the transactions returned here can /// then, for example, be given to StageTransactions() to get them "mined" /// into a specified block on the next ApplyStaged(). func getIncomingTransactions(request: Empty, context: StreamingResponseCallContext) -> EventLoopFuture /// Clear the incoming transaction pool. func clearIncomingTransactions(request: Empty, context: StatusOnlyCallContext) -> EventLoopFuture /// Add a GetAddressUtxosReply entry to be returned by GetAddressUtxos(). /// There is no staging or applying for these, very simple. func addAddressUtxo(request: GetAddressUtxosReply, context: StatusOnlyCallContext) -> EventLoopFuture /// Clear the list of GetAddressUtxos entries (can't fail) func clearAddressUtxo(request: Empty, context: StatusOnlyCallContext) -> EventLoopFuture /// Adds a GetTreeState to the tree state cache func addTreeState(request: TreeState, context: StatusOnlyCallContext) -> EventLoopFuture /// Removes a GetTreeState for the given height from cache if present (can't fail) func removeTreeState(request: BlockID, context: StatusOnlyCallContext) -> EventLoopFuture /// Clear the list of GetTreeStates entries (can't fail) func clearAllTreeStates(request: Empty, context: StatusOnlyCallContext) -> EventLoopFuture /// Sets the subtree roots cache (for GetSubtreeRoots), /// replacing any existing entries func setSubtreeRoots(request: DarksideSubtreeRoots, context: StatusOnlyCallContext) -> EventLoopFuture } extension DarksideStreamerProvider { internal var serviceName: Substring { return DarksideStreamerServerMetadata.serviceDescriptor.fullName[...] } /// Determines, calls and returns the appropriate request handler, depending on the request's method. /// Returns nil for methods not handled by this service. internal func handle( method name: Substring, context: CallHandlerContext ) -> GRPCServerHandlerProtocol? { switch name { case "Reset": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeResetInterceptors() ?? [], userFunction: self.reset(request:context:) ) case "StageBlocksStream": return ClientStreamingServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageBlocksStreamInterceptors() ?? [], observerFactory: self.stageBlocksStream(context:) ) case "StageBlocks": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageBlocksInterceptors() ?? [], userFunction: self.stageBlocks(request:context:) ) case "StageBlocksCreate": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageBlocksCreateInterceptors() ?? [], userFunction: self.stageBlocksCreate(request:context:) ) case "StageTransactionsStream": return ClientStreamingServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageTransactionsStreamInterceptors() ?? [], observerFactory: self.stageTransactionsStream(context:) ) case "StageTransactions": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageTransactionsInterceptors() ?? [], userFunction: self.stageTransactions(request:context:) ) case "ApplyStaged": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeApplyStagedInterceptors() ?? [], userFunction: self.applyStaged(request:context:) ) case "GetIncomingTransactions": return ServerStreamingServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeGetIncomingTransactionsInterceptors() ?? [], userFunction: self.getIncomingTransactions(request:context:) ) case "ClearIncomingTransactions": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeClearIncomingTransactionsInterceptors() ?? [], userFunction: self.clearIncomingTransactions(request:context:) ) case "AddAddressUtxo": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeAddAddressUtxoInterceptors() ?? [], userFunction: self.addAddressUtxo(request:context:) ) case "ClearAddressUtxo": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeClearAddressUtxoInterceptors() ?? [], userFunction: self.clearAddressUtxo(request:context:) ) case "AddTreeState": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeAddTreeStateInterceptors() ?? [], userFunction: self.addTreeState(request:context:) ) case "RemoveTreeState": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeRemoveTreeStateInterceptors() ?? [], userFunction: self.removeTreeState(request:context:) ) case "ClearAllTreeStates": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeClearAllTreeStatesInterceptors() ?? [], userFunction: self.clearAllTreeStates(request:context:) ) case "SetSubtreeRoots": return UnaryServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeSetSubtreeRootsInterceptors() ?? [], userFunction: self.setSubtreeRoots(request:context:) ) default: return nil } } } /// Darksidewalletd maintains two staging areas, blocks and transactions. The /// Stage*() gRPCs add items to the staging area; ApplyStaged() "applies" everything /// in the staging area to the working (operational) state that the mock zcashd /// serves; transactions are placed into their corresponding blocks (by height). /// /// To implement a server, implement an object which conforms to this protocol. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) internal protocol DarksideStreamerAsyncProvider: CallHandlerProvider, Sendable { static var serviceDescriptor: GRPCServiceDescriptor { get } var interceptors: DarksideStreamerServerInterceptorFactoryProtocol? { get } /// Reset reverts all darksidewalletd state (active block range, latest height, /// staged blocks and transactions) and lightwalletd state (cache) to empty, /// the same as the initial state. This occurs synchronously and instantaneously; /// no reorg happens in lightwalletd. This is good to do before each independent /// test so that no state leaks from one test to another. /// Also sets (some of) the values returned by GetLightdInfo(). The Sapling /// activation height specified here must be where the block range starts. func reset( request: DarksideMetaState, context: GRPCAsyncServerCallContext ) async throws -> Empty /// StageBlocksStream accepts a list of blocks and saves them into the blocks /// staging area until ApplyStaged() is called; there is no immediate effect on /// the mock zcashd. Blocks are hex-encoded. Order is important, see ApplyStaged. func stageBlocksStream( requestStream: GRPCAsyncRequestStream, context: GRPCAsyncServerCallContext ) async throws -> Empty /// StageBlocks is the same as StageBlocksStream() except the blocks are fetched /// from the given URL. Blocks are one per line, hex-encoded (not JSON). func stageBlocks( request: DarksideBlocksURL, context: GRPCAsyncServerCallContext ) async throws -> Empty /// StageBlocksCreate is like the previous two, except it creates 'count' /// empty blocks at consecutive heights starting at height 'height'. The /// 'nonce' is part of the header, so it contributes to the block hash; this /// lets you create identical blocks (same transactions and height), but with /// different hashes. func stageBlocksCreate( request: DarksideEmptyBlocks, context: GRPCAsyncServerCallContext ) async throws -> Empty /// StageTransactionsStream stores the given transaction-height pairs in the /// staging area until ApplyStaged() is called. Note that these transactions /// are not returned by the production GetTransaction() gRPC until they /// appear in a "mined" block (contained in the active blockchain presented /// by the mock zcashd). func stageTransactionsStream( requestStream: GRPCAsyncRequestStream, context: GRPCAsyncServerCallContext ) async throws -> Empty /// StageTransactions is the same except the transactions are fetched from /// the given url. They are all staged into the block at the given height. /// Staging transactions to different heights requires multiple calls. func stageTransactions( request: DarksideTransactionsURL, context: GRPCAsyncServerCallContext ) async throws -> Empty /// ApplyStaged iterates the list of blocks that were staged by the /// StageBlocks*() gRPCs, in the order they were staged, and "merges" each /// into the active, working blocks list that the mock zcashd is presenting /// to lightwalletd. Even as each block is applied, the active list can't /// have gaps; if the active block range is 1000-1006, and the staged block /// range is 1003-1004, the resulting range is 1000-1004, with 1000-1002 /// unchanged, blocks 1003-1004 from the new range, and 1005-1006 dropped. /// /// After merging all blocks, ApplyStaged() appends staged transactions (in /// the order received) into each one's corresponding (by height) block /// The staging area is then cleared. /// /// The argument specifies the latest block height that mock zcashd reports /// (i.e. what's returned by GetLatestBlock). Note that ApplyStaged() can /// also be used to simply advance the latest block height presented by mock /// zcashd. That is, there doesn't need to be anything in the staging area. func applyStaged( request: DarksideHeight, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Calls to the production gRPC SendTransaction() store the transaction in /// a separate area (not the staging area); this method returns all transactions /// in this separate area, which is then cleared. The height returned /// with each transaction is -1 (invalid) since these transactions haven't /// been mined yet. The intention is that the transactions returned here can /// then, for example, be given to StageTransactions() to get them "mined" /// into a specified block on the next ApplyStaged(). func getIncomingTransactions( request: Empty, responseStream: GRPCAsyncResponseStreamWriter, context: GRPCAsyncServerCallContext ) async throws /// Clear the incoming transaction pool. func clearIncomingTransactions( request: Empty, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Add a GetAddressUtxosReply entry to be returned by GetAddressUtxos(). /// There is no staging or applying for these, very simple. func addAddressUtxo( request: GetAddressUtxosReply, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Clear the list of GetAddressUtxos entries (can't fail) func clearAddressUtxo( request: Empty, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Adds a GetTreeState to the tree state cache func addTreeState( request: TreeState, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Removes a GetTreeState for the given height from cache if present (can't fail) func removeTreeState( request: BlockID, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Clear the list of GetTreeStates entries (can't fail) func clearAllTreeStates( request: Empty, context: GRPCAsyncServerCallContext ) async throws -> Empty /// Sets the subtree roots cache (for GetSubtreeRoots), /// replacing any existing entries func setSubtreeRoots( request: DarksideSubtreeRoots, context: GRPCAsyncServerCallContext ) async throws -> Empty } @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) extension DarksideStreamerAsyncProvider { internal static var serviceDescriptor: GRPCServiceDescriptor { return DarksideStreamerServerMetadata.serviceDescriptor } internal var serviceName: Substring { return DarksideStreamerServerMetadata.serviceDescriptor.fullName[...] } internal var interceptors: DarksideStreamerServerInterceptorFactoryProtocol? { return nil } internal func handle( method name: Substring, context: CallHandlerContext ) -> GRPCServerHandlerProtocol? { switch name { case "Reset": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeResetInterceptors() ?? [], wrapping: { try await self.reset(request: $0, context: $1) } ) case "StageBlocksStream": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageBlocksStreamInterceptors() ?? [], wrapping: { try await self.stageBlocksStream(requestStream: $0, context: $1) } ) case "StageBlocks": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageBlocksInterceptors() ?? [], wrapping: { try await self.stageBlocks(request: $0, context: $1) } ) case "StageBlocksCreate": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageBlocksCreateInterceptors() ?? [], wrapping: { try await self.stageBlocksCreate(request: $0, context: $1) } ) case "StageTransactionsStream": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageTransactionsStreamInterceptors() ?? [], wrapping: { try await self.stageTransactionsStream(requestStream: $0, context: $1) } ) case "StageTransactions": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeStageTransactionsInterceptors() ?? [], wrapping: { try await self.stageTransactions(request: $0, context: $1) } ) case "ApplyStaged": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeApplyStagedInterceptors() ?? [], wrapping: { try await self.applyStaged(request: $0, context: $1) } ) case "GetIncomingTransactions": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeGetIncomingTransactionsInterceptors() ?? [], wrapping: { try await self.getIncomingTransactions(request: $0, responseStream: $1, context: $2) } ) case "ClearIncomingTransactions": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeClearIncomingTransactionsInterceptors() ?? [], wrapping: { try await self.clearIncomingTransactions(request: $0, context: $1) } ) case "AddAddressUtxo": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeAddAddressUtxoInterceptors() ?? [], wrapping: { try await self.addAddressUtxo(request: $0, context: $1) } ) case "ClearAddressUtxo": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeClearAddressUtxoInterceptors() ?? [], wrapping: { try await self.clearAddressUtxo(request: $0, context: $1) } ) case "AddTreeState": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeAddTreeStateInterceptors() ?? [], wrapping: { try await self.addTreeState(request: $0, context: $1) } ) case "RemoveTreeState": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeRemoveTreeStateInterceptors() ?? [], wrapping: { try await self.removeTreeState(request: $0, context: $1) } ) case "ClearAllTreeStates": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeClearAllTreeStatesInterceptors() ?? [], wrapping: { try await self.clearAllTreeStates(request: $0, context: $1) } ) case "SetSubtreeRoots": return GRPCAsyncServerHandler( context: context, requestDeserializer: ProtobufDeserializer(), responseSerializer: ProtobufSerializer(), interceptors: self.interceptors?.makeSetSubtreeRootsInterceptors() ?? [], wrapping: { try await self.setSubtreeRoots(request: $0, context: $1) } ) default: return nil } } } internal protocol DarksideStreamerServerInterceptorFactoryProtocol: Sendable { /// - Returns: Interceptors to use when handling 'reset'. /// Defaults to calling `self.makeInterceptors()`. func makeResetInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'stageBlocksStream'. /// Defaults to calling `self.makeInterceptors()`. func makeStageBlocksStreamInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'stageBlocks'. /// Defaults to calling `self.makeInterceptors()`. func makeStageBlocksInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'stageBlocksCreate'. /// Defaults to calling `self.makeInterceptors()`. func makeStageBlocksCreateInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'stageTransactionsStream'. /// Defaults to calling `self.makeInterceptors()`. func makeStageTransactionsStreamInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'stageTransactions'. /// Defaults to calling `self.makeInterceptors()`. func makeStageTransactionsInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'applyStaged'. /// Defaults to calling `self.makeInterceptors()`. func makeApplyStagedInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'getIncomingTransactions'. /// Defaults to calling `self.makeInterceptors()`. func makeGetIncomingTransactionsInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'clearIncomingTransactions'. /// Defaults to calling `self.makeInterceptors()`. func makeClearIncomingTransactionsInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'addAddressUtxo'. /// Defaults to calling `self.makeInterceptors()`. func makeAddAddressUtxoInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'clearAddressUtxo'. /// Defaults to calling `self.makeInterceptors()`. func makeClearAddressUtxoInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'addTreeState'. /// Defaults to calling `self.makeInterceptors()`. func makeAddTreeStateInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'removeTreeState'. /// Defaults to calling `self.makeInterceptors()`. func makeRemoveTreeStateInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'clearAllTreeStates'. /// Defaults to calling `self.makeInterceptors()`. func makeClearAllTreeStatesInterceptors() -> [ServerInterceptor] /// - Returns: Interceptors to use when handling 'setSubtreeRoots'. /// Defaults to calling `self.makeInterceptors()`. func makeSetSubtreeRootsInterceptors() -> [ServerInterceptor] } internal enum DarksideStreamerServerMetadata { internal static let serviceDescriptor = GRPCServiceDescriptor( name: "DarksideStreamer", fullName: "cash.z.wallet.sdk.rpc.DarksideStreamer", methods: [ DarksideStreamerServerMetadata.Methods.reset, DarksideStreamerServerMetadata.Methods.stageBlocksStream, DarksideStreamerServerMetadata.Methods.stageBlocks, DarksideStreamerServerMetadata.Methods.stageBlocksCreate, DarksideStreamerServerMetadata.Methods.stageTransactionsStream, DarksideStreamerServerMetadata.Methods.stageTransactions, DarksideStreamerServerMetadata.Methods.applyStaged, DarksideStreamerServerMetadata.Methods.getIncomingTransactions, DarksideStreamerServerMetadata.Methods.clearIncomingTransactions, DarksideStreamerServerMetadata.Methods.addAddressUtxo, DarksideStreamerServerMetadata.Methods.clearAddressUtxo, DarksideStreamerServerMetadata.Methods.addTreeState, DarksideStreamerServerMetadata.Methods.removeTreeState, DarksideStreamerServerMetadata.Methods.clearAllTreeStates, DarksideStreamerServerMetadata.Methods.setSubtreeRoots, ] ) internal enum Methods { internal static let reset = GRPCMethodDescriptor( name: "Reset", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/Reset", type: GRPCCallType.unary ) internal static let stageBlocksStream = GRPCMethodDescriptor( name: "StageBlocksStream", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocksStream", type: GRPCCallType.clientStreaming ) internal static let stageBlocks = GRPCMethodDescriptor( name: "StageBlocks", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocks", type: GRPCCallType.unary ) internal static let stageBlocksCreate = GRPCMethodDescriptor( name: "StageBlocksCreate", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageBlocksCreate", type: GRPCCallType.unary ) internal static let stageTransactionsStream = GRPCMethodDescriptor( name: "StageTransactionsStream", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageTransactionsStream", type: GRPCCallType.clientStreaming ) internal static let stageTransactions = GRPCMethodDescriptor( name: "StageTransactions", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/StageTransactions", type: GRPCCallType.unary ) internal static let applyStaged = GRPCMethodDescriptor( name: "ApplyStaged", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ApplyStaged", type: GRPCCallType.unary ) internal static let getIncomingTransactions = GRPCMethodDescriptor( name: "GetIncomingTransactions", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/GetIncomingTransactions", type: GRPCCallType.serverStreaming ) internal static let clearIncomingTransactions = GRPCMethodDescriptor( name: "ClearIncomingTransactions", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ClearIncomingTransactions", type: GRPCCallType.unary ) internal static let addAddressUtxo = GRPCMethodDescriptor( name: "AddAddressUtxo", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/AddAddressUtxo", type: GRPCCallType.unary ) internal static let clearAddressUtxo = GRPCMethodDescriptor( name: "ClearAddressUtxo", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ClearAddressUtxo", type: GRPCCallType.unary ) internal static let addTreeState = GRPCMethodDescriptor( name: "AddTreeState", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/AddTreeState", type: GRPCCallType.unary ) internal static let removeTreeState = GRPCMethodDescriptor( name: "RemoveTreeState", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/RemoveTreeState", type: GRPCCallType.unary ) internal static let clearAllTreeStates = GRPCMethodDescriptor( name: "ClearAllTreeStates", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/ClearAllTreeStates", type: GRPCCallType.unary ) internal static let setSubtreeRoots = GRPCMethodDescriptor( name: "SetSubtreeRoots", path: "/cash.z.wallet.sdk.rpc.DarksideStreamer/SetSubtreeRoots", type: GRPCCallType.unary ) } }