|
|
|
@ -20,26 +20,203 @@
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
import Foundation
|
|
|
|
|
import GRPC
|
|
|
|
|
import NIO
|
|
|
|
|
import NIOHTTP1
|
|
|
|
|
import SwiftProtobuf
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Usage: instantiate CompactTxStreamerClient, then call methods of this protocol to make API calls.
|
|
|
|
|
internal protocol CompactTxStreamerClientProtocol {
|
|
|
|
|
func getLatestBlock(_ request: ChainSpec, callOptions: CallOptions?) -> UnaryCall<ChainSpec, BlockID>
|
|
|
|
|
func getBlock(_ request: BlockID, callOptions: CallOptions?) -> UnaryCall<BlockID, CompactBlock>
|
|
|
|
|
func getBlockRange(_ request: BlockRange, callOptions: CallOptions?, handler: @escaping (CompactBlock) -> Void) -> ServerStreamingCall<BlockRange, CompactBlock>
|
|
|
|
|
func getTransaction(_ request: TxFilter, callOptions: CallOptions?) -> UnaryCall<TxFilter, RawTransaction>
|
|
|
|
|
func sendTransaction(_ request: RawTransaction, callOptions: CallOptions?) -> UnaryCall<RawTransaction, SendResponse>
|
|
|
|
|
func getAddressTxids(_ request: TransparentAddressBlockFilter, callOptions: CallOptions?, handler: @escaping (RawTransaction) -> Void) -> ServerStreamingCall<TransparentAddressBlockFilter, RawTransaction>
|
|
|
|
|
func getLightdInfo(_ request: Empty, callOptions: CallOptions?) -> UnaryCall<Empty, LightdInfo>
|
|
|
|
|
func ping(_ request: Duration, callOptions: CallOptions?) -> UnaryCall<Duration, PingResponse>
|
|
|
|
|
internal protocol CompactTxStreamerClientProtocol: GRPCClient {
|
|
|
|
|
func getLatestBlock(
|
|
|
|
|
_ request: ChainSpec,
|
|
|
|
|
callOptions: CallOptions?
|
|
|
|
|
) -> UnaryCall<ChainSpec, BlockID>
|
|
|
|
|
|
|
|
|
|
func getBlock(
|
|
|
|
|
_ request: BlockID,
|
|
|
|
|
callOptions: CallOptions?
|
|
|
|
|
) -> UnaryCall<BlockID, CompactBlock>
|
|
|
|
|
|
|
|
|
|
func getBlockRange(
|
|
|
|
|
_ request: BlockRange,
|
|
|
|
|
callOptions: CallOptions?,
|
|
|
|
|
handler: @escaping (CompactBlock) -> Void
|
|
|
|
|
) -> ServerStreamingCall<BlockRange, CompactBlock>
|
|
|
|
|
|
|
|
|
|
func getTransaction(
|
|
|
|
|
_ request: TxFilter,
|
|
|
|
|
callOptions: CallOptions?
|
|
|
|
|
) -> UnaryCall<TxFilter, RawTransaction>
|
|
|
|
|
|
|
|
|
|
func sendTransaction(
|
|
|
|
|
_ request: RawTransaction,
|
|
|
|
|
callOptions: CallOptions?
|
|
|
|
|
) -> UnaryCall<RawTransaction, SendResponse>
|
|
|
|
|
|
|
|
|
|
func getAddressTxids(
|
|
|
|
|
_ request: TransparentAddressBlockFilter,
|
|
|
|
|
callOptions: CallOptions?,
|
|
|
|
|
handler: @escaping (RawTransaction) -> Void
|
|
|
|
|
) -> ServerStreamingCall<TransparentAddressBlockFilter, RawTransaction>
|
|
|
|
|
|
|
|
|
|
func getLightdInfo(
|
|
|
|
|
_ request: Empty,
|
|
|
|
|
callOptions: CallOptions?
|
|
|
|
|
) -> UnaryCall<Empty, LightdInfo>
|
|
|
|
|
|
|
|
|
|
func ping(
|
|
|
|
|
_ request: Duration,
|
|
|
|
|
callOptions: CallOptions?
|
|
|
|
|
) -> UnaryCall<Duration, PingResponse>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal final class CompactTxStreamerClient: GRPCClient, CompactTxStreamerClientProtocol {
|
|
|
|
|
extension CompactTxStreamerClientProtocol {
|
|
|
|
|
|
|
|
|
|
/// Return the height of the tip of the best chain
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetLatestBlock.
|
|
|
|
|
/// - callOptions: Call options.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getLatestBlock(
|
|
|
|
|
_ request: ChainSpec,
|
|
|
|
|
callOptions: CallOptions? = nil
|
|
|
|
|
) -> UnaryCall<ChainSpec, BlockID> {
|
|
|
|
|
return self.makeUnaryCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetLatestBlock",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the compact block corresponding to the given block identifier
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetBlock.
|
|
|
|
|
/// - callOptions: Call options.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getBlock(
|
|
|
|
|
_ request: BlockID,
|
|
|
|
|
callOptions: CallOptions? = nil
|
|
|
|
|
) -> UnaryCall<BlockID, CompactBlock> {
|
|
|
|
|
return self.makeUnaryCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetBlock",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return a list of consecutive compact blocks
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetBlockRange.
|
|
|
|
|
/// - 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 getBlockRange(
|
|
|
|
|
_ request: BlockRange,
|
|
|
|
|
callOptions: CallOptions? = nil,
|
|
|
|
|
handler: @escaping (CompactBlock) -> Void
|
|
|
|
|
) -> ServerStreamingCall<BlockRange, CompactBlock> {
|
|
|
|
|
return self.makeServerStreamingCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetBlockRange",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions,
|
|
|
|
|
handler: handler
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the requested full (not compact) transaction (as from zcashd)
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetTransaction.
|
|
|
|
|
/// - callOptions: Call options.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getTransaction(
|
|
|
|
|
_ request: TxFilter,
|
|
|
|
|
callOptions: CallOptions? = nil
|
|
|
|
|
) -> UnaryCall<TxFilter, RawTransaction> {
|
|
|
|
|
return self.makeUnaryCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetTransaction",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Submit the given transaction to the zcash network
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to SendTransaction.
|
|
|
|
|
/// - callOptions: Call options.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func sendTransaction(
|
|
|
|
|
_ request: RawTransaction,
|
|
|
|
|
callOptions: CallOptions? = nil
|
|
|
|
|
) -> UnaryCall<RawTransaction, SendResponse> {
|
|
|
|
|
return self.makeUnaryCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/SendTransaction",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the txids corresponding to the given t-address within the given block range
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetAddressTxids.
|
|
|
|
|
/// - 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 getAddressTxids(
|
|
|
|
|
_ request: TransparentAddressBlockFilter,
|
|
|
|
|
callOptions: CallOptions? = nil,
|
|
|
|
|
handler: @escaping (RawTransaction) -> Void
|
|
|
|
|
) -> ServerStreamingCall<TransparentAddressBlockFilter, RawTransaction> {
|
|
|
|
|
return self.makeServerStreamingCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetAddressTxids",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions,
|
|
|
|
|
handler: handler
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return information about this lightwalletd instance and the blockchain
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetLightdInfo.
|
|
|
|
|
/// - callOptions: Call options.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getLightdInfo(
|
|
|
|
|
_ request: Empty,
|
|
|
|
|
callOptions: CallOptions? = nil
|
|
|
|
|
) -> UnaryCall<Empty, LightdInfo> {
|
|
|
|
|
return self.makeUnaryCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetLightdInfo",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Testing-only
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to Ping.
|
|
|
|
|
/// - callOptions: Call options.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func ping(
|
|
|
|
|
_ request: Duration,
|
|
|
|
|
callOptions: CallOptions? = nil
|
|
|
|
|
) -> UnaryCall<Duration, PingResponse> {
|
|
|
|
|
return self.makeUnaryCall(
|
|
|
|
|
path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/Ping",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal final class CompactTxStreamerClient: CompactTxStreamerClientProtocol {
|
|
|
|
|
internal let channel: GRPCChannel
|
|
|
|
|
internal var defaultCallOptions: CallOptions
|
|
|
|
|
|
|
|
|
@ -52,120 +229,5 @@ internal final class CompactTxStreamerClient: GRPCClient, CompactTxStreamerClien
|
|
|
|
|
self.channel = channel
|
|
|
|
|
self.defaultCallOptions = defaultCallOptions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the height of the tip of the best chain
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetLatestBlock.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getLatestBlock(_ request: ChainSpec, callOptions: CallOptions? = nil) -> UnaryCall<ChainSpec, BlockID> {
|
|
|
|
|
return self.makeUnaryCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetLatestBlock",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the compact block corresponding to the given block identifier
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetBlock.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getBlock(_ request: BlockID, callOptions: CallOptions? = nil) -> UnaryCall<BlockID, CompactBlock> {
|
|
|
|
|
return self.makeUnaryCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetBlock",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return a list of consecutive compact blocks
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetBlockRange.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - handler: A closure called when each response is received from the server.
|
|
|
|
|
/// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
|
|
|
|
|
internal func getBlockRange(_ request: BlockRange, callOptions: CallOptions? = nil, handler: @escaping (CompactBlock) -> Void) -> ServerStreamingCall<BlockRange, CompactBlock> {
|
|
|
|
|
return self.makeServerStreamingCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetBlockRange",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions,
|
|
|
|
|
handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the requested full (not compact) transaction (as from zcashd)
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetTransaction.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getTransaction(_ request: TxFilter, callOptions: CallOptions? = nil) -> UnaryCall<TxFilter, RawTransaction> {
|
|
|
|
|
return self.makeUnaryCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetTransaction",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Submit the given transaction to the zcash network
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to SendTransaction.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func sendTransaction(_ request: RawTransaction, callOptions: CallOptions? = nil) -> UnaryCall<RawTransaction, SendResponse> {
|
|
|
|
|
return self.makeUnaryCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/SendTransaction",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return the txids corresponding to the given t-address within the given block range
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetAddressTxids.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - handler: A closure called when each response is received from the server.
|
|
|
|
|
/// - Returns: A `ServerStreamingCall` with futures for the metadata and status.
|
|
|
|
|
internal func getAddressTxids(_ request: TransparentAddressBlockFilter, callOptions: CallOptions? = nil, handler: @escaping (RawTransaction) -> Void) -> ServerStreamingCall<TransparentAddressBlockFilter, RawTransaction> {
|
|
|
|
|
return self.makeServerStreamingCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetAddressTxids",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions,
|
|
|
|
|
handler: handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Return information about this lightwalletd instance and the blockchain
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to GetLightdInfo.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func getLightdInfo(_ request: Empty, callOptions: CallOptions? = nil) -> UnaryCall<Empty, LightdInfo> {
|
|
|
|
|
return self.makeUnaryCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetLightdInfo",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Testing-only
|
|
|
|
|
///
|
|
|
|
|
/// - Parameters:
|
|
|
|
|
/// - request: Request to send to Ping.
|
|
|
|
|
/// - callOptions: Call options; `self.defaultCallOptions` is used if `nil`.
|
|
|
|
|
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
|
|
|
|
|
internal func ping(_ request: Duration, callOptions: CallOptions? = nil) -> UnaryCall<Duration, PingResponse> {
|
|
|
|
|
return self.makeUnaryCall(path: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/Ping",
|
|
|
|
|
request: request,
|
|
|
|
|
callOptions: callOptions ?? self.defaultCallOptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Provides conformance to `GRPCPayload` for request and response messages
|
|
|
|
|
extension ChainSpec: GRPCProtobufPayload {}
|
|
|
|
|
extension BlockID: GRPCProtobufPayload {}
|
|
|
|
|
extension CompactBlock: GRPCProtobufPayload {}
|
|
|
|
|
extension BlockRange: GRPCProtobufPayload {}
|
|
|
|
|
extension TxFilter: GRPCProtobufPayload {}
|
|
|
|
|
extension SendResponse: GRPCProtobufPayload {}
|
|
|
|
|
extension TransparentAddressBlockFilter: GRPCProtobufPayload {}
|
|
|
|
|
extension LightdInfo: GRPCProtobufPayload {}
|
|
|
|
|
extension Duration: GRPCProtobufPayload {}
|
|
|
|
|
extension PingResponse: GRPCProtobufPayload {}
|
|
|
|
|
extension RawTransaction: GRPCProtobufPayload {}
|
|
|
|
|
extension Empty: GRPCProtobufPayload {}
|
|
|
|
|