react-native-zcash 0.6.10 → 0.6.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2460000.json +8 -0
  3. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +937 -425
  4. package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +17 -31
  5. package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
  6. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +15 -46
  7. package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +15 -4
  8. package/ios/ZCashLightClientKit/Block/FilesystemStorage/FSCompactBlockRepository.swift +4 -4
  9. package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +35 -10
  10. package/ios/ZCashLightClientKit/Block/Utils/InternalSyncProgress.swift +200 -0
  11. package/ios/ZCashLightClientKit/Block/Validate/BlockValidator.swift +51 -0
  12. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +2 -1
  13. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +5 -2
  14. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +26 -13
  15. package/ios/ZCashLightClientKit/DAO/BlockDao.swift +112 -0
  16. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +42 -40
  17. package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +4 -13
  18. package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +0 -9
  19. package/ios/ZCashLightClientKit/Entity/BlockProgress.swift +24 -0
  20. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +10 -7
  21. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
  22. package/ios/ZCashLightClientKit/Error/ZcashError.swift +12 -121
  23. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +5 -43
  24. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +6 -72
  25. package/ios/ZCashLightClientKit/Initializer.swift +26 -47
  26. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +12 -0
  27. package/ios/ZCashLightClientKit/Model/Checkpoint.swift +0 -12
  28. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +0 -15
  29. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/compact_formats.pb.swift +46 -150
  30. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/compact_formats.proto +16 -30
  31. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +6 -32
  32. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +22 -259
  33. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +7 -193
  34. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +0 -8
  35. package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +28 -18
  36. package/ios/ZCashLightClientKit/Repository/CompactBlockRepository.swift +1 -1
  37. package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +6 -2
  38. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2460000.json +8 -0
  39. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +158 -293
  40. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +64 -58
  41. package/ios/ZCashLightClientKit/Rust/zcashlc.h +513 -619
  42. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +8 -2
  43. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +15 -3
  44. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +30 -11
  45. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +50 -41
  46. package/ios/ZCashLightClientKit/Synchronizer.swift +65 -51
  47. package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +2 -2
  48. package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +7 -7
  49. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +3 -3
  50. package/ios/libzcashlc.xcframework/Info.plist +0 -4
  51. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  52. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  53. package/package.json +1 -1
  54. package/ios/ZCashLightClientKit/Block/Actions/Action.swift +0 -98
  55. package/ios/ZCashLightClientKit/Block/Actions/ClearAlreadyScannedBlocksAction.swift +0 -35
  56. package/ios/ZCashLightClientKit/Block/Actions/ClearCacheAction.swift +0 -30
  57. package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +0 -67
  58. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +0 -97
  59. package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +0 -33
  60. package/ios/ZCashLightClientKit/Block/Actions/MigrateLegacyCacheDBAction.swift +0 -70
  61. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +0 -60
  62. package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +0 -48
  63. package/ios/ZCashLightClientKit/Block/Actions/SaplingParamsAction.swift +0 -33
  64. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +0 -95
  65. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +0 -55
  66. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +0 -58
  67. package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +0 -60
  68. package/ios/ZCashLightClientKit/Block/Utils/CompactBlockProgress.swift +0 -24
  69. package/ios/ZCashLightClientKit/Block/Utils/SyncControlData.swift +0 -25
  70. package/ios/ZCashLightClientKit/Extensions/Bool+ToData.swift +0 -15
  71. package/ios/ZCashLightClientKit/Extensions/Data+ToOtherTypes.swift +0 -18
  72. package/ios/ZCashLightClientKit/Extensions/Int+ToData.swift +0 -15
  73. package/ios/ZCashLightClientKit/Model/ScanProgress.swift +0 -29
  74. package/ios/ZCashLightClientKit/Model/ScanRange.swift +0 -31
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2092500.json +0 -8
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2095000.json +0 -8
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2097500.json +0 -8
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2102500.json +0 -8
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2105000.json +0 -8
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2107500.json +0 -8
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2112500.json +0 -8
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2115000.json +0 -8
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2117500.json +0 -8
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2122500.json +0 -8
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2125000.json +0 -8
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2127500.json +0 -8
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2132500.json +0 -8
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2135000.json +0 -8
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2137500.json +0 -8
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2142500.json +0 -8
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2145000.json +0 -8
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2147500.json +0 -8
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2152500.json +0 -8
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2155000.json +0 -8
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2157500.json +0 -8
  96. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2162500.json +0 -8
  97. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2165000.json +0 -8
  98. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2167500.json +0 -8
  99. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2172500.json +0 -8
  100. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2175000.json +0 -8
  101. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2177500.json +0 -8
  102. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2182500.json +0 -8
  103. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2185000.json +0 -8
  104. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2187500.json +0 -8
  105. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2192500.json +0 -8
  106. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2195000.json +0 -8
  107. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2197500.json +0 -8
  108. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2202500.json +0 -8
  109. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2205000.json +0 -8
  110. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2207500.json +0 -8
  111. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2212500.json +0 -8
  112. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2215000.json +0 -8
  113. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2217500.json +0 -8
  114. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2222500.json +0 -8
  115. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2225000.json +0 -8
  116. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2227500.json +0 -8
  117. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2232500.json +0 -8
  118. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2235000.json +0 -8
  119. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2237500.json +0 -8
  120. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2242500.json +0 -8
  121. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2245000.json +0 -8
  122. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2247500.json +0 -8
  123. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2252500.json +0 -8
  124. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2255000.json +0 -8
  125. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2257500.json +0 -8
  126. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2262500.json +0 -8
  127. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2265000.json +0 -8
  128. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2267500.json +0 -8
  129. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2350000.json +0 -8
  130. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2360000.json +0 -8
  131. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2370000.json +0 -8
  132. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2380000.json +0 -8
  133. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2390000.json +0 -8
  134. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2400000.json +0 -8
  135. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2410000.json +0 -8
  136. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2420000.json +0 -8
  137. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2430000.json +0 -8
  138. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2440000.json +0 -8
  139. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2450000.json +0 -8
  140. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2460000.json +0 -8
  141. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2470000.json +0 -8
  142. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2480000.json +0 -8
  143. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2490000.json +0 -8
  144. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2500000.json +0 -8
  145. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2510000.json +0 -8
  146. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2520000.json +0 -8
  147. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2530000.json +0 -8
  148. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2540000.json +0 -8
  149. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2550000.json +0 -8
  150. package/ios/ZCashLightClientKit/Utils/ZcashFileManager.swift +0 -16
@@ -33,12 +33,12 @@ extension ClosureSDKSynchronizer: ClosureSynchronizer {
33
33
 
34
34
  public func prepare(
35
35
  with seed: [UInt8]?,
36
+ viewingKeys: [UnifiedFullViewingKey],
36
37
  walletBirthday: BlockHeight,
37
- for walletMode: WalletInitMode,
38
38
  completion: @escaping (Result<Initializer.InitializationResult, Error>) -> Void
39
39
  ) {
40
40
  AsyncToClosureGateway.executeThrowingAction(completion) {
41
- return try await self.synchronizer.prepare(with: seed, walletBirthday: walletBirthday, for: walletMode)
41
+ return try await self.synchronizer.prepare(with: seed, viewingKeys: viewingKeys, walletBirthday: walletBirthday)
42
42
  }
43
43
  }
44
44
 
@@ -93,6 +93,12 @@ extension ClosureSDKSynchronizer: ClosureSynchronizer {
93
93
  }
94
94
  }
95
95
 
96
+ public func pendingTransactions(completion: @escaping ([ZcashTransaction.Overview]) -> Void) {
97
+ AsyncToClosureGateway.executeAction(completion) {
98
+ await self.synchronizer.pendingTransactions
99
+ }
100
+ }
101
+
96
102
  public func clearedTransactions(completion: @escaping ([ZcashTransaction.Overview]) -> Void) {
97
103
  AsyncToClosureGateway.executeAction(completion) {
98
104
  await self.synchronizer.transactions
@@ -33,11 +33,11 @@ extension CombineSDKSynchronizer: CombineSynchronizer {
33
33
 
34
34
  public func prepare(
35
35
  with seed: [UInt8]?,
36
- walletBirthday: BlockHeight,
37
- for walletMode: WalletInitMode
36
+ viewingKeys: [UnifiedFullViewingKey],
37
+ walletBirthday: BlockHeight
38
38
  ) -> SinglePublisher<Initializer.InitializationResult, Error> {
39
39
  AsyncToCombineGateway.executeThrowingAction() {
40
- return try await self.synchronizer.prepare(with: seed, walletBirthday: walletBirthday, for: walletMode)
40
+ return try await self.synchronizer.prepare(with: seed, viewingKeys: viewingKeys, walletBirthday: walletBirthday)
41
41
  }
42
42
  }
43
43
 
@@ -90,6 +90,12 @@ extension CombineSDKSynchronizer: CombineSynchronizer {
90
90
  }
91
91
  }
92
92
 
93
+ public var pendingTransactions: AnyPublisher<[ZcashTransaction.Overview], Never> {
94
+ AsyncToCombineGateway.executeAction() {
95
+ await self.synchronizer.pendingTransactions
96
+ }
97
+ }
98
+
93
99
  public var allTransactions: SinglePublisher<[ZcashTransaction.Overview], Never> {
94
100
  AsyncToCombineGateway.executeAction() {
95
101
  await self.synchronizer.transactions
@@ -122,6 +128,12 @@ extension CombineSDKSynchronizer: CombineSynchronizer {
122
128
  }
123
129
  }
124
130
 
131
+ public func allPendingTransactions() -> AnyPublisher<[ZcashTransaction.Overview], Error> {
132
+ AsyncToCombineGateway.executeThrowingAction() {
133
+ try await self.synchronizer.allPendingTransactions()
134
+ }
135
+ }
136
+
125
137
  public func allTransactions(from transaction: ZcashTransaction.Overview, limit: Int) -> SinglePublisher<[ZcashTransaction.Overview], Error> {
126
138
  AsyncToCombineGateway.executeThrowingAction() {
127
139
  try await self.synchronizer.allTransactions(from: transaction, limit: limit)
@@ -14,8 +14,7 @@ enum Dependencies {
14
14
  alias: ZcashSynchronizerAlias,
15
15
  networkType: NetworkType,
16
16
  endpoint: LightWalletEndpoint,
17
- loggingPolicy: Initializer.LoggingPolicy = .default(.debug),
18
- enableBackendTracing: Bool = false
17
+ loggingPolicy: Initializer.LoggingPolicy = .default(.debug)
19
18
  ) {
20
19
  container.register(type: Logger.self, isSingleton: true) { _ in
21
20
  let logger: Logger
@@ -37,8 +36,7 @@ enum Dependencies {
37
36
  fsBlockDbRoot: urls.fsBlockDbRoot,
38
37
  spendParamsPath: urls.spendParamsURL,
39
38
  outputParamsPath: urls.outputParamsURL,
40
- networkType: networkType,
41
- enableTracing: enableBackendTracing
39
+ networkType: networkType
42
40
  )
43
41
  }
44
42
 
@@ -80,17 +78,18 @@ enum Dependencies {
80
78
 
81
79
  container.register(type: LatestBlocksDataProvider.self, isSingleton: true) { di in
82
80
  let service = di.resolve(LightWalletService.self)
83
- let rustBackend = di.resolve(ZcashRustBackendWelding.self)
81
+ let transactionRepository = di.resolve(TransactionRepository.self)
84
82
 
85
- return LatestBlocksDataProviderImpl(service: service, rustBackend: rustBackend)
83
+ return LatestBlocksDataProviderImpl(service: service, transactionRepository: transactionRepository)
86
84
  }
87
85
 
88
86
  container.register(type: SyncSessionIDGenerator.self, isSingleton: false) { _ in
89
87
  UniqueSyncSessionIDGenerator()
90
88
  }
91
-
92
- container.register(type: ZcashFileManager.self, isSingleton: true) { _ in
93
- FileManager.default
89
+
90
+ container.register(type: InternalSyncProgress.self, isSingleton: true) { di in
91
+ let logger = di.resolve(Logger.self)
92
+ return InternalSyncProgress(alias: alias, storage: UserDefaults.standard, logger: logger)
94
93
  }
95
94
  }
96
95
 
@@ -103,6 +102,7 @@ enum Dependencies {
103
102
  let service = di.resolve(LightWalletService.self)
104
103
  let blockDownloaderService = di.resolve(BlockDownloaderService.self)
105
104
  let storage = di.resolve(CompactBlockRepository.self)
105
+ let internalSyncProgress = di.resolve(InternalSyncProgress.self)
106
106
  let metrics = di.resolve(SDKMetrics.self)
107
107
  let logger = di.resolve(Logger.self)
108
108
 
@@ -110,6 +110,19 @@ enum Dependencies {
110
110
  service: service,
111
111
  downloaderService: blockDownloaderService,
112
112
  storage: storage,
113
+ internalSyncProgress: internalSyncProgress,
114
+ metrics: metrics,
115
+ logger: logger
116
+ )
117
+ }
118
+
119
+ container.register(type: BlockValidator.self, isSingleton: true) { di in
120
+ let rustBackend = di.resolve(ZcashRustBackendWelding.self)
121
+ let metrics = di.resolve(SDKMetrics.self)
122
+ let logger = di.resolve(Logger.self)
123
+
124
+ return BlockValidatorImpl(
125
+ rustBackend: rustBackend,
113
126
  metrics: metrics,
114
127
  logger: logger
115
128
  )
@@ -120,10 +133,11 @@ enum Dependencies {
120
133
  let transactionRepository = di.resolve(TransactionRepository.self)
121
134
  let metrics = di.resolve(SDKMetrics.self)
122
135
  let logger = di.resolve(Logger.self)
136
+ let latestBlocksDataProvider = di.resolve(LatestBlocksDataProvider.self)
123
137
 
124
138
  let blockScannerConfig = BlockScannerConfig(
125
139
  networkType: config.network.networkType,
126
- scanningBatchSize: config.batchSize
140
+ scanningBatchSize: config.scanningBatchSize
127
141
  )
128
142
 
129
143
  return BlockScannerImpl(
@@ -131,12 +145,14 @@ enum Dependencies {
131
145
  rustBackend: rustBackend,
132
146
  transactionRepository: transactionRepository,
133
147
  metrics: metrics,
134
- logger: logger
148
+ logger: logger,
149
+ latestBlocksDataProvider: latestBlocksDataProvider
135
150
  )
136
151
  }
137
152
 
138
153
  container.register(type: BlockEnhancer.self, isSingleton: true) { di in
139
154
  let blockDownloaderService = di.resolve(BlockDownloaderService.self)
155
+ let internalSyncProgress = di.resolve(InternalSyncProgress.self)
140
156
  let rustBackend = di.resolve(ZcashRustBackendWelding.self)
141
157
  let transactionRepository = di.resolve(TransactionRepository.self)
142
158
  let metrics = di.resolve(SDKMetrics.self)
@@ -144,6 +160,7 @@ enum Dependencies {
144
160
 
145
161
  return BlockEnhancerImpl(
146
162
  blockDownloaderService: blockDownloaderService,
163
+ internalSyncProgress: internalSyncProgress,
147
164
  rustBackend: rustBackend,
148
165
  transactionRepository: transactionRepository,
149
166
  metrics: metrics,
@@ -154,6 +171,7 @@ enum Dependencies {
154
171
  container.register(type: UTXOFetcher.self, isSingleton: true) { di in
155
172
  let blockDownloaderService = di.resolve(BlockDownloaderService.self)
156
173
  let utxoFetcherConfig = UTXOFetcherConfig(walletBirthdayProvider: config.walletBirthdayProvider)
174
+ let internalSyncProgress = di.resolve(InternalSyncProgress.self)
157
175
  let rustBackend = di.resolve(ZcashRustBackendWelding.self)
158
176
  let metrics = di.resolve(SDKMetrics.self)
159
177
  let logger = di.resolve(Logger.self)
@@ -162,6 +180,7 @@ enum Dependencies {
162
180
  accountRepository: accountRepository,
163
181
  blockDownloaderService: blockDownloaderService,
164
182
  config: utxoFetcherConfig,
183
+ internalSyncProgress: internalSyncProgress,
165
184
  rustBackend: rustBackend,
166
185
  metrics: metrics,
167
186
  logger: logger
@@ -24,7 +24,7 @@ public class SDKSynchronizer: Synchronizer {
24
24
 
25
25
  public let metrics: SDKMetrics
26
26
  public let logger: Logger
27
-
27
+
28
28
  // Don't read this variable directly. Use `status` instead. And don't update this variable directly use `updateStatus()` methods instead.
29
29
  private var underlyingStatus: GenericActor<InternalSyncStatus>
30
30
  var status: InternalSyncStatus {
@@ -102,9 +102,9 @@ public class SDKSynchronizer: Synchronizer {
102
102
  }
103
103
  }
104
104
 
105
- func updateStatus(_ newValue: InternalSyncStatus, updateExternalStatus: Bool = true) async {
105
+ func updateStatus(_ newValue: InternalSyncStatus) async {
106
106
  let oldValue = await underlyingStatus.update(newValue)
107
- await notify(oldStatus: oldValue, newStatus: newValue, updateExternalStatus: updateExternalStatus)
107
+ await notify(oldStatus: oldValue, newStatus: newValue)
108
108
  }
109
109
 
110
110
  func throwIfUnprepared() throws {
@@ -127,8 +127,8 @@ public class SDKSynchronizer: Synchronizer {
127
127
 
128
128
  public func prepare(
129
129
  with seed: [UInt8]?,
130
- walletBirthday: BlockHeight,
131
- for walletMode: WalletInitMode
130
+ viewingKeys: [UnifiedFullViewingKey],
131
+ walletBirthday: BlockHeight
132
132
  ) async throws -> Initializer.InitializationResult {
133
133
  guard await status == .unprepared else { return .success }
134
134
 
@@ -138,14 +138,14 @@ public class SDKSynchronizer: Synchronizer {
138
138
 
139
139
  try await utxoRepository.initialise()
140
140
 
141
- if case .seedRequired = try await self.initializer.initialize(with: seed, walletBirthday: walletBirthday, for: walletMode) {
141
+ if case .seedRequired = try await self.initializer.initialize(with: seed, viewingKeys: viewingKeys, walletBirthday: walletBirthday) {
142
142
  return .seedRequired
143
143
  }
144
-
144
+
145
145
  await latestBlocksDataProvider.updateWalletBirthday(initializer.walletBirthday)
146
146
  await latestBlocksDataProvider.updateScannedData()
147
147
 
148
- await updateStatus(.disconnected, updateExternalStatus: false)
148
+ await updateStatus(.disconnected)
149
149
 
150
150
  return .success
151
151
  }
@@ -157,14 +157,14 @@ public class SDKSynchronizer: Synchronizer {
157
157
  case .unprepared:
158
158
  throw ZcashError.synchronizerNotPrepared
159
159
 
160
- case .syncing:
160
+ case .syncing, .enhancing, .fetching:
161
161
  logger.warn("warning: Synchronizer started when already running. Next sync process will be started when the current one stops.")
162
162
  /// This may look strange but `CompactBlockProcessor` has mechanisms which can handle this situation. So we are fine with calling
163
163
  /// it's start here.
164
164
  await blockProcessor.start(retry: retry)
165
165
 
166
166
  case .stopped, .synced, .disconnected, .error:
167
- await updateStatus(.syncing(0))
167
+ await updateStatus(.syncing(.nullProgress))
168
168
  syncStartDate = Date()
169
169
  await blockProcessor.start(retry: retry)
170
170
  }
@@ -197,14 +197,15 @@ public class SDKSynchronizer: Synchronizer {
197
197
 
198
198
  // MARK: Handle CompactBlockProcessor.Flow
199
199
 
200
+ // swiftlint:disable:next cyclomatic_complexity
200
201
  private func subscribeToProcessorEvents(_ processor: CompactBlockProcessor) async {
201
202
  let eventClosure: CompactBlockProcessor.EventClosure = { [weak self] event in
202
203
  switch event {
203
204
  case let .failed(error):
204
205
  await self?.failed(error: error)
205
206
 
206
- case let .finished(height):
207
- await self?.finished(lastScannedHeight: height)
207
+ case let .finished(height, foundBlocks):
208
+ await self?.finished(lastScannedHeight: height, foundBlocks: foundBlocks)
208
209
 
209
210
  case let .foundTransactions(transactions, range):
210
211
  self?.foundTransactions(transactions: transactions, in: range)
@@ -216,14 +217,17 @@ public class SDKSynchronizer: Synchronizer {
216
217
  case let .progressUpdated(progress):
217
218
  await self?.progressUpdated(progress: progress)
218
219
 
219
- case .syncProgress:
220
- break
221
-
222
220
  case let .storedUTXOs(utxos):
223
221
  self?.storedUTXOs(utxos: utxos)
224
222
 
225
- case .startedEnhancing, .startedFetching, .startedSyncing:
226
- break
223
+ case .startedEnhancing:
224
+ await self?.updateStatus(.enhancing(.zero))
225
+
226
+ case .startedFetching:
227
+ await self?.updateStatus(.fetching(0))
228
+
229
+ case .startedSyncing:
230
+ await self?.updateStatus(.syncing(.nullProgress))
227
231
 
228
232
  case .stopped:
229
233
  await self?.updateStatus(.stopped)
@@ -240,7 +244,7 @@ public class SDKSynchronizer: Synchronizer {
240
244
  await updateStatus(.error(error))
241
245
  }
242
246
 
243
- private func finished(lastScannedHeight: BlockHeight) async {
247
+ private func finished(lastScannedHeight: BlockHeight, foundBlocks: Bool) async {
244
248
  await latestBlocksDataProvider.updateScannedData()
245
249
 
246
250
  await updateStatus(.synced)
@@ -259,7 +263,7 @@ public class SDKSynchronizer: Synchronizer {
259
263
  }
260
264
  }
261
265
 
262
- private func progressUpdated(progress: Float) async {
266
+ private func progressUpdated(progress: CompactBlockProgress) async {
263
267
  let newStatus = InternalSyncStatus(progress)
264
268
  await updateStatus(newStatus)
265
269
  }
@@ -311,8 +315,8 @@ public class SDKSynchronizer: Synchronizer {
311
315
  let accountIndex = Int(spendingKey.account)
312
316
  let tBalance = try await self.getTransparentBalance(accountIndex: accountIndex)
313
317
 
314
- // Verify that at least there are funds for the fee. Ideally this logic will be improved by the shielding wallet.
315
- guard tBalance.verified >= self.network.constants.defaultFee() else {
318
+ // Verify that at least there are funds for the fee. Ideally this logic will be improved by the shielding wallet.
319
+ guard tBalance.verified >= self.network.constants.defaultFee(for: await self.latestBlocksDataProvider.latestScannedHeight) else {
316
320
  throw ZcashError.synchronizerShieldFundsInsuficientTransparentFunds
317
321
  }
318
322
 
@@ -365,6 +369,12 @@ public class SDKSynchronizer: Synchronizer {
365
369
  try await transactionRepository.findReceived(offset: 0, limit: Int.max)
366
370
  }
367
371
 
372
+ public func allPendingTransactions() async throws -> [ZcashTransaction.Overview] {
373
+ let latestScannedHeight = self.latestState.latestScannedHeight
374
+
375
+ return try await transactionRepository.findPendingTransactions(latestHeight: latestScannedHeight, offset: 0, limit: .max)
376
+ }
377
+
368
378
  public func allTransactions() async throws -> [ZcashTransaction.Overview] {
369
379
  return try await transactionRepository.find(offset: 0, limit: Int.max, kind: .all)
370
380
  }
@@ -386,15 +396,15 @@ public class SDKSynchronizer: Synchronizer {
386
396
  }
387
397
 
388
398
  public func getRecipients(for transaction: ZcashTransaction.Overview) async -> [TransactionRecipient] {
389
- return (try? await transactionRepository.getRecipients(for: transaction.rawID)) ?? []
399
+ return (try? await transactionRepository.getRecipients(for: transaction.id)) ?? []
390
400
  }
391
401
 
392
402
  public func getTransactionOutputs(for transaction: ZcashTransaction.Overview) async -> [ZcashTransaction.Output] {
393
- return (try? await transactionRepository.getTransactionOutputs(for: transaction.rawID)) ?? []
403
+ return (try? await transactionRepository.getTransactionOutputs(for: transaction.id)) ?? []
394
404
  }
395
405
 
396
406
  public func latestHeight() async throws -> BlockHeight {
397
- try await blockProcessor.latestHeight()
407
+ try await blockProcessor.blockDownloaderService.latestBlockHeight()
398
408
  }
399
409
 
400
410
  public func latestUTXOs(address: String) async throws -> [UnspentTransactionOutputEntity] {
@@ -493,11 +503,7 @@ public class SDKSynchronizer: Synchronizer {
493
503
  }
494
504
  )
495
505
 
496
- do {
497
- try await blockProcessor.rewind(context: context)
498
- } catch {
499
- subject.send(completion: .failure(error))
500
- }
506
+ await blockProcessor.rewind(context: context)
501
507
  }
502
508
  return subject.eraseToAnyPublisher()
503
509
  }
@@ -527,16 +533,12 @@ public class SDKSynchronizer: Synchronizer {
527
533
  }
528
534
  )
529
535
 
530
- do {
531
- try await blockProcessor.wipe(context: context)
532
- } catch {
533
- subject.send(completion: .failure(error))
534
- }
536
+ await blockProcessor.wipe(context: context)
535
537
  }
536
538
 
537
539
  return subject.eraseToAnyPublisher()
538
540
  }
539
-
541
+
540
542
  // MARK: notify state
541
543
 
542
544
  private func snapshotState(status: InternalSyncStatus) async -> SynchronizerState {
@@ -548,11 +550,13 @@ public class SDKSynchronizer: Synchronizer {
548
550
  ),
549
551
  transparentBalance: (try? await blockProcessor.getTransparentBalance(accountIndex: 0)) ?? .zero,
550
552
  internalSyncStatus: status,
551
- latestBlockHeight: latestBlocksDataProvider.latestBlockHeight
553
+ latestScannedHeight: latestBlocksDataProvider.latestScannedHeight,
554
+ latestBlockHeight: latestBlocksDataProvider.latestBlockHeight,
555
+ latestScannedTime: latestBlocksDataProvider.latestScannedTime
552
556
  )
553
557
  }
554
558
 
555
- private func notify(oldStatus: InternalSyncStatus, newStatus: InternalSyncStatus, updateExternalStatus: Bool = true) async {
559
+ private func notify(oldStatus: InternalSyncStatus, newStatus: InternalSyncStatus) async {
556
560
  guard oldStatus != newStatus else { return }
557
561
 
558
562
  let newState: SynchronizerState
@@ -575,10 +579,7 @@ public class SDKSynchronizer: Synchronizer {
575
579
  }
576
580
 
577
581
  latestState = newState
578
-
579
- if updateExternalStatus {
580
- updateStateStream(with: latestState)
581
- }
582
+ updateStateStream(with: latestState)
582
583
  }
583
584
 
584
585
  private func updateStateStream(with newState: SynchronizerState) {
@@ -612,6 +613,12 @@ extension SDKSynchronizer {
612
613
  (try? await allReceivedTransactions()) ?? []
613
614
  }
614
615
  }
616
+
617
+ public var pendingTransactions: [ZcashTransaction.Overview] {
618
+ get async {
619
+ (try? await allPendingTransactions()) ?? []
620
+ }
621
+ }
615
622
  }
616
623
 
617
624
  extension InternalSyncStatus {
@@ -619,6 +626,8 @@ extension InternalSyncStatus {
619
626
  switch (self, otherStatus) {
620
627
  case (.unprepared, .unprepared): return false
621
628
  case (.syncing, .syncing): return false
629
+ case (.enhancing, .enhancing): return false
630
+ case (.fetching, .fetching): return false
622
631
  case (.synced, .synced): return false
623
632
  case (.stopped, .stopped): return false
624
633
  case (.disconnected, .disconnected): return false