diff --git a/Example/ZcashLightClientSample/Podfile b/Example/ZcashLightClientSample/Podfile index 6961840d..f726482c 100644 --- a/Example/ZcashLightClientSample/Podfile +++ b/Example/ZcashLightClientSample/Podfile @@ -10,6 +10,7 @@ target 'ZcashLightClientSample' do pod 'PaginatedTableView' pod 'NotificationBubbles' pod 'MnemonicSwift' + pod 'gRPC-Swift-Plugins', '= 1.0.0-alpha.19' target 'ZcashLightClientSampleTests' do use_frameworks! inherit! :search_paths @@ -39,7 +40,7 @@ post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| - + config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' if target.name == 'ZcashLightClientKit-Unit-Tests' config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "13.0" end diff --git a/Example/ZcashLightClientSample/Podfile.lock b/Example/ZcashLightClientSample/Podfile.lock index 39f4d9f1..3d68165d 100644 --- a/Example/ZcashLightClientSample/Podfile.lock +++ b/Example/ZcashLightClientSample/Podfile.lock @@ -16,6 +16,8 @@ PODS: - SwiftNIOSSL (< 3, >= 2.8.0) - SwiftNIOTransportServices (< 2, >= 1.6.0) - SwiftProtobuf (< 2, >= 1.9.0) + - gRPC-Swift-Plugins (1.0.0-alpha.19): + - gRPC-Swift (= 1.0.0-alpha.19) - KRActivityIndicatorView (3.0.5) - KRProgressHUD (3.4.5): - KRActivityIndicatorView (= 3.0.5) @@ -64,15 +66,16 @@ PODS: - SwiftNIOFoundationCompat (< 3, >= 2.22.0) - SwiftNIOTLS (< 3, >= 2.22.0) - SwiftProtobuf (1.12.0) - - ZcashLightClientKit (0.6.3): + - ZcashLightClientKit (0.6.4): - gRPC-Swift (= 1.0.0-alpha.19) - SQLite.swift (~> 0.12.2) - - ZcashLightClientKit/Tests (0.6.3): + - ZcashLightClientKit/Tests (0.6.4): - gRPC-Swift (= 1.0.0-alpha.19) - SQLite.swift (~> 0.12.2) DEPENDENCIES: - gRPC-Swift (= 1.0.0-alpha.19) + - gRPC-Swift-Plugins (= 1.0.0-alpha.19) - KRProgressHUD - MnemonicSwift - NotificationBubbles @@ -91,6 +94,7 @@ SPEC REPOS: - CNIOLinux - CNIOSHA1 - gRPC-Swift + - gRPC-Swift-Plugins - KRActivityIndicatorView - KRProgressHUD - Logging @@ -123,6 +127,7 @@ SPEC CHECKSUMS: CNIOLinux: 11f69f76c12087a0752fa8a53f32f9853ef3f4f2 CNIOSHA1: ff4d77269adcb89f9a962abcbee55256a29b8a36 gRPC-Swift: 75a7a8d7cd08177165ef971159afb84e5130cfc9 + gRPC-Swift-Plugins: 5827cb75fe1f6e24423635fa1ec85fd67a529aef KRActivityIndicatorView: 912bc0413d98340f384b12a4e1e6aa8f42fb377d KRProgressHUD: df4cdc3a1baf708d4276a089ee34d133fa9a6f3e Logging: beeb016c9c80cf77042d62e83495816847ef108b @@ -140,8 +145,8 @@ SPEC CHECKSUMS: SwiftNIOTLS: 46bb3a0ff37d6b52ae6baf5207ec3cd411da327c SwiftNIOTransportServices: 801923921fbecdcde1e1c1ff38e812167d01ead1 SwiftProtobuf: 4ef85479c18ca85b5482b343df9c319c62bda699 - ZcashLightClientKit: 6a7a724d5c249bc15983327157fe5ade6600dbcb + ZcashLightClientKit: da23702d76723911cd52fbd033db240ea0b4e3a4 -PODFILE CHECKSUM: 712888df93841f6c9ab12b3b6db3edf7c2cac776 +PODFILE CHECKSUM: dc66de93ef2abbd39ca1595dd3020a5fbd62c9bd COCOAPODS: 1.9.3 diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Example/ZcashLightClientSample/ZcashLightClientSample.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings index 6b30c745..f9b0d7c5 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ b/Example/ZcashLightClientSample/ZcashLightClientSample.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -2,8 +2,6 @@ - BuildSystemType - Original PreviewsEnabled diff --git a/ZcashLightClientKit/Service/LightWalletGRPCService.swift b/ZcashLightClientKit/Service/LightWalletGRPCService.swift index bc7a76a4..1f7014b6 100644 --- a/ZcashLightClientKit/Service/LightWalletGRPCService.swift +++ b/ZcashLightClientKit/Service/LightWalletGRPCService.swift @@ -12,7 +12,6 @@ import NIO import NIOHPACK public typealias Channel = GRPC.GRPCChannel - extension TimeAmount { static let singleCallTimeout = TimeAmount.seconds(10) static let streamingCallTimeout = TimeAmount.seconds(90) @@ -151,8 +150,6 @@ extension LightWalletGRPCService: LightWalletService { default: throw LightWalletServiceError.mapCode(status) } - - } public func latestBlockHeight(result: @escaping (Result) -> Void) { diff --git a/ZcashLightClientKit/Service/LightWalletService.swift b/ZcashLightClientKit/Service/LightWalletService.swift index e2988b8b..7a170b28 100644 --- a/ZcashLightClientKit/Service/LightWalletService.swift +++ b/ZcashLightClientKit/Service/LightWalletService.swift @@ -50,9 +50,9 @@ extension LightWalletServiceError: Equatable { default: return false } - case .sentFailed(_): + case .sentFailed: switch rhs { - case .sentFailed(_): + case .sentFailed: return true default: return false diff --git a/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift b/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift index 0d1200b9..8897fd3b 100644 --- a/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift +++ b/ZcashLightClientKit/Service/ProtoBuf/compact_formats.pb.swift @@ -1,4 +1,5 @@ // DO NOT EDIT. +// swift-format-ignore-file // // Generated by the Swift generator plugin for the protocol buffer compiler. // Source: compact_formats.proto diff --git a/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift b/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift index 0418adf9..c7954f4e 100644 --- a/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift +++ b/ZcashLightClientKit/Service/ProtoBuf/service.grpc.swift @@ -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 - func getBlock(_ request: BlockID, callOptions: CallOptions?) -> UnaryCall - func getBlockRange(_ request: BlockRange, callOptions: CallOptions?, handler: @escaping (CompactBlock) -> Void) -> ServerStreamingCall - func getTransaction(_ request: TxFilter, callOptions: CallOptions?) -> UnaryCall - func sendTransaction(_ request: RawTransaction, callOptions: CallOptions?) -> UnaryCall - func getAddressTxids(_ request: TransparentAddressBlockFilter, callOptions: CallOptions?, handler: @escaping (RawTransaction) -> Void) -> ServerStreamingCall - func getLightdInfo(_ request: Empty, callOptions: CallOptions?) -> UnaryCall - func ping(_ request: Duration, callOptions: CallOptions?) -> UnaryCall +internal protocol CompactTxStreamerClientProtocol: GRPCClient { + func getLatestBlock( + _ request: ChainSpec, + callOptions: CallOptions? + ) -> UnaryCall + + func getBlock( + _ request: BlockID, + callOptions: CallOptions? + ) -> UnaryCall + + func getBlockRange( + _ request: BlockRange, + callOptions: CallOptions?, + handler: @escaping (CompactBlock) -> Void + ) -> ServerStreamingCall + + func getTransaction( + _ request: TxFilter, + callOptions: CallOptions? + ) -> UnaryCall + + func sendTransaction( + _ request: RawTransaction, + callOptions: CallOptions? + ) -> UnaryCall + + func getAddressTxids( + _ request: TransparentAddressBlockFilter, + callOptions: CallOptions?, + handler: @escaping (RawTransaction) -> Void + ) -> ServerStreamingCall + + func getLightdInfo( + _ request: Empty, + callOptions: CallOptions? + ) -> UnaryCall + + func ping( + _ request: Duration, + callOptions: CallOptions? + ) -> UnaryCall + } -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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 {} diff --git a/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift b/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift index 5d09e052..b9f1d48d 100644 --- a/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift +++ b/ZcashLightClientKit/Service/ProtoBuf/service.pb.swift @@ -1,4 +1,5 @@ // DO NOT EDIT. +// swift-format-ignore-file // // Generated by the Swift generator plugin for the protocol buffer compiler. // Source: service.proto diff --git a/ZcashLightClientKit/UIKit/Synchronizer/SDKSynchronizer.swift b/ZcashLightClientKit/UIKit/Synchronizer/SDKSynchronizer.swift index f465f085..72e4d78d 100644 --- a/ZcashLightClientKit/UIKit/Synchronizer/SDKSynchronizer.swift +++ b/ZcashLightClientKit/UIKit/Synchronizer/SDKSynchronizer.swift @@ -368,11 +368,7 @@ public class SDKSynchronizer: Synchronizer { @objc func applicationDidEnterBackground(_ notification: Notification) { if !self.isBackgroundAllowed { - do { - try self.stop() - } catch { - self.status = .disconnected - } + self.stop() } }