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.
- package/CHANGELOG.md +4 -0
- package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2460000.json +8 -0
- package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +937 -425
- package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +17 -31
- package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
- package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +15 -46
- package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +15 -4
- package/ios/ZCashLightClientKit/Block/FilesystemStorage/FSCompactBlockRepository.swift +4 -4
- package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +35 -10
- package/ios/ZCashLightClientKit/Block/Utils/InternalSyncProgress.swift +200 -0
- package/ios/ZCashLightClientKit/Block/Validate/BlockValidator.swift +51 -0
- package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +2 -1
- package/ios/ZCashLightClientKit/CombineSynchronizer.swift +5 -2
- package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +26 -13
- package/ios/ZCashLightClientKit/DAO/BlockDao.swift +112 -0
- package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +42 -40
- package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +4 -13
- package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +0 -9
- package/ios/ZCashLightClientKit/Entity/BlockProgress.swift +24 -0
- package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +10 -7
- package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
- package/ios/ZCashLightClientKit/Error/ZcashError.swift +12 -121
- package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +5 -43
- package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +6 -72
- package/ios/ZCashLightClientKit/Initializer.swift +26 -47
- package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +12 -0
- package/ios/ZCashLightClientKit/Model/Checkpoint.swift +0 -12
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +0 -15
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/compact_formats.pb.swift +46 -150
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/compact_formats.proto +16 -30
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +6 -32
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +22 -259
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +7 -193
- package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +0 -8
- package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +28 -18
- package/ios/ZCashLightClientKit/Repository/CompactBlockRepository.swift +1 -1
- package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +6 -2
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2460000.json +8 -0
- package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +158 -293
- package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +64 -58
- package/ios/ZCashLightClientKit/Rust/zcashlc.h +513 -619
- package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +8 -2
- package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +15 -3
- package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +30 -11
- package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +50 -41
- package/ios/ZCashLightClientKit/Synchronizer.swift +65 -51
- package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +2 -2
- package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +7 -7
- package/ios/ZCashLightClientKit/Utils/OSLogger.swift +3 -3
- package/ios/libzcashlc.xcframework/Info.plist +0 -4
- package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
- package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
- package/package.json +1 -1
- package/ios/ZCashLightClientKit/Block/Actions/Action.swift +0 -98
- package/ios/ZCashLightClientKit/Block/Actions/ClearAlreadyScannedBlocksAction.swift +0 -35
- package/ios/ZCashLightClientKit/Block/Actions/ClearCacheAction.swift +0 -30
- package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +0 -67
- package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +0 -97
- package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +0 -33
- package/ios/ZCashLightClientKit/Block/Actions/MigrateLegacyCacheDBAction.swift +0 -70
- package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +0 -60
- package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +0 -48
- package/ios/ZCashLightClientKit/Block/Actions/SaplingParamsAction.swift +0 -33
- package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +0 -95
- package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +0 -55
- package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +0 -58
- package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +0 -60
- package/ios/ZCashLightClientKit/Block/Utils/CompactBlockProgress.swift +0 -24
- package/ios/ZCashLightClientKit/Block/Utils/SyncControlData.swift +0 -25
- package/ios/ZCashLightClientKit/Extensions/Bool+ToData.swift +0 -15
- package/ios/ZCashLightClientKit/Extensions/Data+ToOtherTypes.swift +0 -18
- package/ios/ZCashLightClientKit/Extensions/Int+ToData.swift +0 -15
- package/ios/ZCashLightClientKit/Model/ScanProgress.swift +0 -29
- package/ios/ZCashLightClientKit/Model/ScanRange.swift +0 -31
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2092500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2095000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2097500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2102500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2105000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2107500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2112500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2115000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2117500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2122500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2125000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2127500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2132500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2135000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2137500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2142500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2145000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2147500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2152500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2155000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2157500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2162500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2165000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2167500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2172500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2175000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2177500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2182500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2185000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2187500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2192500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2195000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2197500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2202500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2205000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2207500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2212500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2215000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2217500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2222500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2225000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2227500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2232500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2235000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2237500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2242500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2245000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2247500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2252500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2255000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2257500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2262500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2265000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2267500.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2350000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2360000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2370000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2380000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2390000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2400000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2410000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2420000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2430000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2440000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2450000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2460000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2470000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2480000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2490000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2500000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2510000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2520000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2530000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2540000.json +0 -8
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2550000.json +0 -8
- package/ios/ZCashLightClientKit/Utils/ZcashFileManager.swift +0 -16
|
@@ -42,8 +42,13 @@ public struct SynchronizerState: Equatable {
|
|
|
42
42
|
/// status of the whole sync process
|
|
43
43
|
var internalSyncStatus: InternalSyncStatus
|
|
44
44
|
public var syncStatus: SyncStatus
|
|
45
|
+
/// height of the latest scanned block known to this synchronizer.
|
|
46
|
+
public var latestScannedHeight: BlockHeight
|
|
45
47
|
/// height of the latest block on the blockchain known to this synchronizer.
|
|
46
48
|
public var latestBlockHeight: BlockHeight
|
|
49
|
+
/// timestamp of the latest scanned block on the blockchain known to this synchronizer.
|
|
50
|
+
/// The anchor point is timeIntervalSince1970
|
|
51
|
+
public var latestScannedTime: TimeInterval
|
|
47
52
|
|
|
48
53
|
/// Represents a synchronizer that has made zero progress hasn't done a sync attempt
|
|
49
54
|
public static var zero: SynchronizerState {
|
|
@@ -52,7 +57,9 @@ public struct SynchronizerState: Equatable {
|
|
|
52
57
|
shieldedBalance: .zero,
|
|
53
58
|
transparentBalance: .zero,
|
|
54
59
|
internalSyncStatus: .unprepared,
|
|
55
|
-
|
|
60
|
+
latestScannedHeight: .zero,
|
|
61
|
+
latestBlockHeight: .zero,
|
|
62
|
+
latestScannedTime: 0
|
|
56
63
|
)
|
|
57
64
|
}
|
|
58
65
|
|
|
@@ -61,13 +68,17 @@ public struct SynchronizerState: Equatable {
|
|
|
61
68
|
shieldedBalance: WalletBalance,
|
|
62
69
|
transparentBalance: WalletBalance,
|
|
63
70
|
internalSyncStatus: InternalSyncStatus,
|
|
64
|
-
|
|
71
|
+
latestScannedHeight: BlockHeight,
|
|
72
|
+
latestBlockHeight: BlockHeight,
|
|
73
|
+
latestScannedTime: TimeInterval
|
|
65
74
|
) {
|
|
66
75
|
self.syncSessionID = syncSessionID
|
|
67
76
|
self.shieldedBalance = shieldedBalance
|
|
68
77
|
self.transparentBalance = transparentBalance
|
|
69
78
|
self.internalSyncStatus = internalSyncStatus
|
|
79
|
+
self.latestScannedHeight = latestScannedHeight
|
|
70
80
|
self.latestBlockHeight = latestBlockHeight
|
|
81
|
+
self.latestScannedTime = latestScannedTime
|
|
71
82
|
self.syncStatus = internalSyncStatus.mapToSyncStatus()
|
|
72
83
|
}
|
|
73
84
|
}
|
|
@@ -108,7 +119,7 @@ public protocol Synchronizer: AnyObject {
|
|
|
108
119
|
|
|
109
120
|
/// An object that when enabled collects mertrics from the synchronizer
|
|
110
121
|
var metrics: SDKMetrics { get }
|
|
111
|
-
|
|
122
|
+
|
|
112
123
|
/// Initialize the wallet. The ZIP-32 seed bytes can optionally be passed to perform
|
|
113
124
|
/// database migrations. most of the times the seed won't be needed. If they do and are
|
|
114
125
|
/// not provided this will fail with `InitializationResult.seedRequired`. It could
|
|
@@ -120,11 +131,9 @@ public protocol Synchronizer: AnyObject {
|
|
|
120
131
|
/// do not already exist). These files can be given a prefix for scenarios where multiple wallets
|
|
121
132
|
///
|
|
122
133
|
/// - Parameters:
|
|
123
|
-
/// - seed: ZIP-32 Seed bytes for the wallet that will be initialized
|
|
134
|
+
/// - seed: ZIP-32 Seed bytes for the wallet that will be initialized.
|
|
135
|
+
/// - viewingKeys: Viewing key derived from seed.
|
|
124
136
|
/// - walletBirthday: Birthday of wallet.
|
|
125
|
-
/// - for: [walletMode] Set `.newWallet` when preparing synchronizer for a brand new generated wallet,
|
|
126
|
-
/// `.restoreWallet` when wallet is about to be restored from a seed
|
|
127
|
-
/// and `.existingWallet` for all other scenarios.
|
|
128
137
|
/// - Throws:
|
|
129
138
|
/// - `aliasAlreadyInUse` if the Alias used to create this instance is already used by other instance.
|
|
130
139
|
/// - `cantUpdateURLWithAlias` if the updating of paths in `Initilizer` according to alias fails. When this happens it means that
|
|
@@ -133,8 +142,8 @@ public protocol Synchronizer: AnyObject {
|
|
|
133
142
|
/// - Some other `ZcashError` thrown by lower layer of the SDK.
|
|
134
143
|
func prepare(
|
|
135
144
|
with seed: [UInt8]?,
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
viewingKeys: [UnifiedFullViewingKey],
|
|
146
|
+
walletBirthday: BlockHeight
|
|
138
147
|
) async throws -> Initializer.InitializationResult
|
|
139
148
|
|
|
140
149
|
/// Starts this synchronizer within the given scope.
|
|
@@ -190,6 +199,9 @@ public protocol Synchronizer: AnyObject {
|
|
|
190
199
|
shieldingThreshold: Zatoshi
|
|
191
200
|
) async throws -> ZcashTransaction.Overview
|
|
192
201
|
|
|
202
|
+
/// all outbound pending transactions that have been sent but are awaiting confirmations
|
|
203
|
+
var pendingTransactions: [ZcashTransaction.Overview] { get async }
|
|
204
|
+
|
|
193
205
|
/// all the transactions that are on the blockchain
|
|
194
206
|
var transactions: [ZcashTransaction.Overview] { get async }
|
|
195
207
|
|
|
@@ -230,6 +242,10 @@ public protocol Synchronizer: AnyObject {
|
|
|
230
242
|
/// - Returns: an array with the given Transactions or an empty array
|
|
231
243
|
func allTransactions(from transaction: ZcashTransaction.Overview, limit: Int) async throws -> [ZcashTransaction.Overview]
|
|
232
244
|
|
|
245
|
+
/// Fetch all pending transactions
|
|
246
|
+
/// - Returns: an array of transactions which are considered pending confirmation. can be empty
|
|
247
|
+
func allPendingTransactions() async throws -> [ZcashTransaction.Overview]
|
|
248
|
+
|
|
233
249
|
/// Returns the latest block height from the provided Lightwallet endpoint
|
|
234
250
|
func latestHeight() async throws -> BlockHeight
|
|
235
251
|
|
|
@@ -317,32 +333,20 @@ public enum SyncStatus: Equatable {
|
|
|
317
333
|
/// When set, a UI element may want to turn green.
|
|
318
334
|
case upToDate
|
|
319
335
|
|
|
320
|
-
/// Indicates that this Synchronizer was succesfully stopped via `stop()` method.
|
|
321
|
-
case stopped
|
|
322
|
-
|
|
323
336
|
case error(_ error: Error)
|
|
324
337
|
|
|
325
338
|
public var isSyncing: Bool {
|
|
326
|
-
|
|
327
|
-
return true
|
|
328
|
-
}
|
|
329
|
-
|
|
339
|
+
guard case .syncing = self else { return true }
|
|
330
340
|
return false
|
|
331
341
|
}
|
|
332
342
|
|
|
333
343
|
public var isSynced: Bool {
|
|
334
|
-
|
|
335
|
-
return true
|
|
336
|
-
}
|
|
337
|
-
|
|
344
|
+
guard case .upToDate = self else { return true }
|
|
338
345
|
return false
|
|
339
346
|
}
|
|
340
347
|
|
|
341
348
|
public var isPrepared: Bool {
|
|
342
|
-
|
|
343
|
-
return false
|
|
344
|
-
}
|
|
345
|
-
|
|
349
|
+
guard case .unprepared = self else { return false }
|
|
346
350
|
return true
|
|
347
351
|
}
|
|
348
352
|
|
|
@@ -350,7 +354,6 @@ public enum SyncStatus: Equatable {
|
|
|
350
354
|
switch self {
|
|
351
355
|
case .unprepared: return "unprepared"
|
|
352
356
|
case .syncing: return "syncing"
|
|
353
|
-
case .stopped: return "stopped"
|
|
354
357
|
case .upToDate: return "up to date"
|
|
355
358
|
case .error: return "error"
|
|
356
359
|
}
|
|
@@ -363,9 +366,15 @@ enum InternalSyncStatus: Equatable {
|
|
|
363
366
|
/// taking other maintenance steps that need to occur after an upgrade.
|
|
364
367
|
case unprepared
|
|
365
368
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
case syncing(_ progress: BlockProgress)
|
|
370
|
+
|
|
371
|
+
/// Indicates that this Synchronizer is actively enhancing newly scanned blocks
|
|
372
|
+
/// with additional transaction details, fetched from the server.
|
|
373
|
+
case enhancing(_ progress: EnhancementProgress)
|
|
374
|
+
|
|
375
|
+
/// fetches the transparent balance and stores it locally
|
|
376
|
+
case fetching(_ progress: Float)
|
|
377
|
+
|
|
369
378
|
/// Indicates that this Synchronizer is fully up to date and ready for all wallet functions.
|
|
370
379
|
/// When set, a UI element may want to turn green.
|
|
371
380
|
case synced
|
|
@@ -380,33 +389,35 @@ enum InternalSyncStatus: Equatable {
|
|
|
380
389
|
case error(_ error: Error)
|
|
381
390
|
|
|
382
391
|
public var isSyncing: Bool {
|
|
383
|
-
|
|
392
|
+
switch self {
|
|
393
|
+
case .syncing, .enhancing, .fetching:
|
|
384
394
|
return true
|
|
395
|
+
default:
|
|
396
|
+
return false
|
|
385
397
|
}
|
|
386
|
-
|
|
387
|
-
return false
|
|
388
398
|
}
|
|
389
399
|
|
|
390
400
|
public var isSynced: Bool {
|
|
391
|
-
|
|
392
|
-
|
|
401
|
+
switch self {
|
|
402
|
+
case .synced: return true
|
|
403
|
+
default: return false
|
|
393
404
|
}
|
|
394
|
-
|
|
395
|
-
return false
|
|
396
405
|
}
|
|
397
406
|
|
|
398
407
|
public var isPrepared: Bool {
|
|
399
408
|
if case .unprepared = self {
|
|
400
409
|
return false
|
|
410
|
+
} else {
|
|
411
|
+
return true
|
|
401
412
|
}
|
|
402
|
-
|
|
403
|
-
return true
|
|
404
413
|
}
|
|
405
414
|
|
|
406
415
|
public var briefDebugDescription: String {
|
|
407
416
|
switch self {
|
|
408
417
|
case .unprepared: return "unprepared"
|
|
409
418
|
case .syncing: return "syncing"
|
|
419
|
+
case .enhancing: return "enhancing"
|
|
420
|
+
case .fetching: return "fetching"
|
|
410
421
|
case .synced: return "synced"
|
|
411
422
|
case .stopped: return "stopped"
|
|
412
423
|
case .disconnected: return "disconnected"
|
|
@@ -415,16 +426,6 @@ enum InternalSyncStatus: Equatable {
|
|
|
415
426
|
}
|
|
416
427
|
}
|
|
417
428
|
|
|
418
|
-
/// Mode of the Synchronizer's initialization for the wallet.
|
|
419
|
-
public enum WalletInitMode: Equatable {
|
|
420
|
-
/// For brand new wallet - typically when users creates a new wallet.
|
|
421
|
-
case newWallet
|
|
422
|
-
/// For a wallet that is about to be restored. Typically when a user wants to restore a wallet from a seed.
|
|
423
|
-
case restoreWallet
|
|
424
|
-
/// All other cases - typically when clients just start the process e.g. every regular app start for mobile apps.
|
|
425
|
-
case existingWallet
|
|
426
|
-
}
|
|
427
|
-
|
|
428
429
|
/// Kind of transactions handled by a Synchronizer
|
|
429
430
|
public enum TransactionKind {
|
|
430
431
|
case sent
|
|
@@ -448,6 +449,8 @@ extension InternalSyncStatus {
|
|
|
448
449
|
switch (lhs, rhs) {
|
|
449
450
|
case (.unprepared, .unprepared): return true
|
|
450
451
|
case let (.syncing(lhsProgress), .syncing(rhsProgress)): return lhsProgress == rhsProgress
|
|
452
|
+
case let (.enhancing(lhsProgress), .enhancing(rhsProgress)): return lhsProgress == rhsProgress
|
|
453
|
+
case (.fetching, .fetching): return true
|
|
451
454
|
case (.synced, .synced): return true
|
|
452
455
|
case (.stopped, .stopped): return true
|
|
453
456
|
case (.disconnected, .disconnected): return true
|
|
@@ -458,8 +461,15 @@ extension InternalSyncStatus {
|
|
|
458
461
|
}
|
|
459
462
|
|
|
460
463
|
extension InternalSyncStatus {
|
|
461
|
-
init(_ blockProcessorProgress:
|
|
462
|
-
|
|
464
|
+
init(_ blockProcessorProgress: CompactBlockProgress) {
|
|
465
|
+
switch blockProcessorProgress {
|
|
466
|
+
case .syncing(let progressReport):
|
|
467
|
+
self = .syncing(progressReport)
|
|
468
|
+
case .enhance(let enhancingReport):
|
|
469
|
+
self = .enhancing(enhancingReport)
|
|
470
|
+
case .fetch(let fetchingProgress):
|
|
471
|
+
self = .fetching(fetchingProgress)
|
|
472
|
+
}
|
|
463
473
|
}
|
|
464
474
|
}
|
|
465
475
|
|
|
@@ -469,11 +479,15 @@ extension InternalSyncStatus {
|
|
|
469
479
|
case .unprepared:
|
|
470
480
|
return .unprepared
|
|
471
481
|
case .syncing(let progress):
|
|
472
|
-
return .syncing(progress)
|
|
482
|
+
return .syncing(0.9 * progress.progress)
|
|
483
|
+
case .enhancing(let progress):
|
|
484
|
+
return .syncing(0.9 + 0.08 * progress.progress)
|
|
485
|
+
case .fetching(let progress):
|
|
486
|
+
return .syncing(0.98 + 0.02 * progress)
|
|
473
487
|
case .synced:
|
|
474
488
|
return .upToDate
|
|
475
489
|
case .stopped:
|
|
476
|
-
return .
|
|
490
|
+
return .upToDate
|
|
477
491
|
case .disconnected:
|
|
478
492
|
return .error(ZcashError.synchronizerDisconnected)
|
|
479
493
|
case .error(let error):
|
|
@@ -10,8 +10,8 @@ import Foundation
|
|
|
10
10
|
typealias TransactionEncoderResultBlock = (_ result: Result<EncodedTransaction, Error>) -> Void
|
|
11
11
|
|
|
12
12
|
public enum TransactionEncoderError: Error {
|
|
13
|
-
case notFound(
|
|
14
|
-
case notEncoded(
|
|
13
|
+
case notFound(transactionId: Int)
|
|
14
|
+
case notEncoded(transactionId: Int)
|
|
15
15
|
case missingParams
|
|
16
16
|
case spendingKeyWrongNetwork
|
|
17
17
|
case couldNotExpand(txId: Data)
|
|
@@ -71,7 +71,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
logger.debug("transaction id: \(txId)")
|
|
74
|
-
return try await repository.find(
|
|
74
|
+
return try await repository.find(id: txId)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
func createSpend(
|
|
@@ -80,7 +80,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
80
80
|
to address: String,
|
|
81
81
|
memoBytes: MemoBytes?,
|
|
82
82
|
from accountIndex: Int
|
|
83
|
-
) async throws ->
|
|
83
|
+
) async throws -> Int {
|
|
84
84
|
guard ensureParams(spend: self.spendParamsURL, output: self.outputParamsURL) else {
|
|
85
85
|
throw ZcashError.walletTransEncoderCreateTransactionMissingSaplingParams
|
|
86
86
|
}
|
|
@@ -92,7 +92,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
92
92
|
memo: memoBytes
|
|
93
93
|
)
|
|
94
94
|
|
|
95
|
-
return txId
|
|
95
|
+
return Int(txId)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
func createShieldingTransaction(
|
|
@@ -109,7 +109,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
109
109
|
)
|
|
110
110
|
|
|
111
111
|
logger.debug("transaction id: \(txId)")
|
|
112
|
-
return try await repository.find(
|
|
112
|
+
return try await repository.find(id: txId)
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
func createShieldingSpend(
|
|
@@ -117,7 +117,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
117
117
|
shieldingThreshold: Zatoshi,
|
|
118
118
|
memo: MemoBytes?,
|
|
119
119
|
accountIndex: Int
|
|
120
|
-
) async throws ->
|
|
120
|
+
) async throws -> Int {
|
|
121
121
|
guard ensureParams(spend: self.spendParamsURL, output: self.outputParamsURL) else {
|
|
122
122
|
throw ZcashError.walletTransEncoderShieldFundsMissingSaplingParams
|
|
123
123
|
}
|
|
@@ -128,7 +128,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
128
128
|
shieldingThreshold: shieldingThreshold
|
|
129
129
|
)
|
|
130
130
|
|
|
131
|
-
return txId
|
|
131
|
+
return Int(txId)
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
func submit(
|
|
@@ -157,7 +157,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
157
157
|
extension ZcashTransaction.Overview {
|
|
158
158
|
func encodedTransaction() throws -> EncodedTransaction {
|
|
159
159
|
guard let raw else {
|
|
160
|
-
throw TransactionEncoderError.notEncoded(
|
|
160
|
+
throw TransactionEncoderError.notEncoded(transactionId: self.id)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
return EncodedTransaction(transactionId: self.rawID, raw: raw)
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
<key>AvailableLibraries</key>
|
|
6
6
|
<array>
|
|
7
7
|
<dict>
|
|
8
|
-
<key>BinaryPath</key>
|
|
9
|
-
<string>libzcashlc.a</string>
|
|
10
8
|
<key>LibraryIdentifier</key>
|
|
11
9
|
<string>ios-arm64</string>
|
|
12
10
|
<key>LibraryPath</key>
|
|
@@ -19,8 +17,6 @@
|
|
|
19
17
|
<string>ios</string>
|
|
20
18
|
</dict>
|
|
21
19
|
<dict>
|
|
22
|
-
<key>BinaryPath</key>
|
|
23
|
-
<string>libzcashlc.a</string>
|
|
24
20
|
<key>LibraryIdentifier</key>
|
|
25
21
|
<string>ios-arm64_x86_64-simulator</string>
|
|
26
22
|
<key>LibraryPath</key>
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Action.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Michal Fousek on 05.05.2023.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
|
-
protocol ActionContext {
|
|
11
|
-
var state: CBPState { get async }
|
|
12
|
-
var prevState: CBPState? { get async }
|
|
13
|
-
var syncControlData: SyncControlData { get async }
|
|
14
|
-
var requestedRewindHeight: BlockHeight? { get async }
|
|
15
|
-
var processedHeight: BlockHeight { get async }
|
|
16
|
-
var lastChainTipUpdateTime: TimeInterval { get async }
|
|
17
|
-
var lastScannedHeight: BlockHeight? { get async }
|
|
18
|
-
var lastEnhancedHeight: BlockHeight? { get async }
|
|
19
|
-
|
|
20
|
-
func update(state: CBPState) async
|
|
21
|
-
func update(syncControlData: SyncControlData) async
|
|
22
|
-
func update(processedHeight: BlockHeight) async
|
|
23
|
-
func update(lastChainTipUpdateTime: TimeInterval) async
|
|
24
|
-
func update(lastScannedHeight: BlockHeight) async
|
|
25
|
-
func update(lastDownloadedHeight: BlockHeight) async
|
|
26
|
-
func update(lastEnhancedHeight: BlockHeight?) async
|
|
27
|
-
func update(requestedRewindHeight: BlockHeight) async
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
actor ActionContextImpl: ActionContext {
|
|
31
|
-
var state: CBPState
|
|
32
|
-
var prevState: CBPState?
|
|
33
|
-
var syncControlData: SyncControlData
|
|
34
|
-
var requestedRewindHeight: BlockHeight?
|
|
35
|
-
/// Amount of blocks that have been processed so far
|
|
36
|
-
var processedHeight: BlockHeight = 0
|
|
37
|
-
/// Update chain tip must be called repeatadly, this value stores the previous update and help to decide when to call it again
|
|
38
|
-
var lastChainTipUpdateTime: TimeInterval = 0.0
|
|
39
|
-
var lastScannedHeight: BlockHeight?
|
|
40
|
-
var lastDownloadedHeight: BlockHeight?
|
|
41
|
-
var lastEnhancedHeight: BlockHeight?
|
|
42
|
-
|
|
43
|
-
init(state: CBPState) {
|
|
44
|
-
self.state = state
|
|
45
|
-
syncControlData = SyncControlData.empty
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
func update(state: CBPState) async {
|
|
49
|
-
prevState = self.state
|
|
50
|
-
self.state = state
|
|
51
|
-
}
|
|
52
|
-
func update(syncControlData: SyncControlData) async { self.syncControlData = syncControlData }
|
|
53
|
-
func update(processedHeight: BlockHeight) async { self.processedHeight = processedHeight }
|
|
54
|
-
func update(lastChainTipUpdateTime: TimeInterval) async { self.lastChainTipUpdateTime = lastChainTipUpdateTime }
|
|
55
|
-
func update(lastScannedHeight: BlockHeight) async { self.lastScannedHeight = lastScannedHeight }
|
|
56
|
-
func update(lastDownloadedHeight: BlockHeight) async { self.lastDownloadedHeight = lastDownloadedHeight }
|
|
57
|
-
func update(lastEnhancedHeight: BlockHeight?) async { self.lastEnhancedHeight = lastEnhancedHeight }
|
|
58
|
-
func update(requestedRewindHeight: BlockHeight) async { self.requestedRewindHeight = requestedRewindHeight }
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
enum CBPState: CaseIterable {
|
|
62
|
-
case idle
|
|
63
|
-
case migrateLegacyCacheDB
|
|
64
|
-
case validateServer
|
|
65
|
-
case updateSubtreeRoots
|
|
66
|
-
case updateChainTip
|
|
67
|
-
case processSuggestedScanRanges
|
|
68
|
-
case rewind
|
|
69
|
-
case download
|
|
70
|
-
case scan
|
|
71
|
-
case clearAlreadyScannedBlocks
|
|
72
|
-
case enhance
|
|
73
|
-
case fetchUTXO
|
|
74
|
-
case handleSaplingParams
|
|
75
|
-
case clearCache
|
|
76
|
-
case finished
|
|
77
|
-
case failed
|
|
78
|
-
case stopped
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
protocol Action {
|
|
82
|
-
/// If this is true and action fails with error then blocks cache is cleared.
|
|
83
|
-
var removeBlocksCacheWhenFailed: Bool { get }
|
|
84
|
-
|
|
85
|
-
// When any action is created it can get `DIContainer` and resolve any depedencies it requires.
|
|
86
|
-
// Every action uses `context` to get some informartion like download range.
|
|
87
|
-
//
|
|
88
|
-
// `didUpdate` is closure that action use to tell CBP that some part of the work is done. For example if download action would like to
|
|
89
|
-
// update progress on every block downloaded it can use this closure. Also if action doesn't need to update progress on partial work it doesn't
|
|
90
|
-
// need to use this closure at all.
|
|
91
|
-
//
|
|
92
|
-
// Each action updates context accordingly. It should at least set new state. Reason for this is that action can return different states for
|
|
93
|
-
// different conditions. And action is the thing that knows these conditions.
|
|
94
|
-
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext
|
|
95
|
-
|
|
96
|
-
// Should be called on each existing action when processor wants to stop. Some actions may do it's own background work.
|
|
97
|
-
func stop() async
|
|
98
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ClearCacheForLastScannedBatch.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Michal Fousek on 08.05.2023.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
|
-
final class ClearAlreadyScannedBlocksAction {
|
|
11
|
-
let storage: CompactBlockRepository
|
|
12
|
-
let transactionRepository: TransactionRepository
|
|
13
|
-
|
|
14
|
-
init(container: DIContainer) {
|
|
15
|
-
storage = container.resolve(CompactBlockRepository.self)
|
|
16
|
-
transactionRepository = container.resolve(TransactionRepository.self)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
extension ClearAlreadyScannedBlocksAction: Action {
|
|
21
|
-
var removeBlocksCacheWhenFailed: Bool { false }
|
|
22
|
-
|
|
23
|
-
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext {
|
|
24
|
-
guard let lastScannedHeight = await context.lastScannedHeight else {
|
|
25
|
-
throw ZcashError.compactBlockProcessorLastScannedHeight
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try await storage.clear(upTo: lastScannedHeight)
|
|
29
|
-
|
|
30
|
-
await context.update(state: .enhance)
|
|
31
|
-
return context
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
func stop() async { }
|
|
35
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// ClearCacheAction.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Michal Fousek on 05.05.2023.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
|
-
final class ClearCacheAction {
|
|
11
|
-
let storage: CompactBlockRepository
|
|
12
|
-
|
|
13
|
-
init(container: DIContainer) {
|
|
14
|
-
storage = container.resolve(CompactBlockRepository.self)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
extension ClearCacheAction: Action {
|
|
19
|
-
var removeBlocksCacheWhenFailed: Bool { false }
|
|
20
|
-
|
|
21
|
-
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext {
|
|
22
|
-
try await storage.clear()
|
|
23
|
-
|
|
24
|
-
await context.update(state: .processSuggestedScanRanges)
|
|
25
|
-
|
|
26
|
-
return context
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
func stop() async { }
|
|
30
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// DownloadAction.swift
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// Created by Michal Fousek on 05.05.2023.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
|
|
10
|
-
final class DownloadAction {
|
|
11
|
-
let configProvider: CompactBlockProcessor.ConfigProvider
|
|
12
|
-
let downloader: BlockDownloader
|
|
13
|
-
let transactionRepository: TransactionRepository
|
|
14
|
-
let logger: Logger
|
|
15
|
-
|
|
16
|
-
init(container: DIContainer, configProvider: CompactBlockProcessor.ConfigProvider) {
|
|
17
|
-
self.configProvider = configProvider
|
|
18
|
-
downloader = container.resolve(BlockDownloader.self)
|
|
19
|
-
transactionRepository = container.resolve(TransactionRepository.self)
|
|
20
|
-
logger = container.resolve(Logger.self)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
private func update(context: ActionContext) async -> ActionContext {
|
|
24
|
-
await context.update(state: .scan)
|
|
25
|
-
return context
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
extension DownloadAction: Action {
|
|
30
|
-
var removeBlocksCacheWhenFailed: Bool { true }
|
|
31
|
-
|
|
32
|
-
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext {
|
|
33
|
-
guard let lastScannedHeight = await context.lastScannedHeight else {
|
|
34
|
-
return await update(context: context)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let config = await configProvider.config
|
|
38
|
-
let latestBlockHeight = await context.syncControlData.latestBlockHeight
|
|
39
|
-
// This action is executed for each batch (batch size is 100 blocks by default) until all the blocks in whole `downloadRange` are downloaded.
|
|
40
|
-
// So the right range for this batch must be computed.
|
|
41
|
-
let batchRangeStart = lastScannedHeight
|
|
42
|
-
let batchRangeEnd = min(latestBlockHeight, batchRangeStart + config.batchSize)
|
|
43
|
-
|
|
44
|
-
guard batchRangeStart <= batchRangeEnd else {
|
|
45
|
-
return await update(context: context)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let batchRange = batchRangeStart...batchRangeEnd
|
|
49
|
-
let potentialDownloadLimit = batchRange.upperBound + (2 * config.batchSize)
|
|
50
|
-
let downloadLimit = await context.syncControlData.latestBlockHeight >= potentialDownloadLimit ? potentialDownloadLimit : batchRangeEnd
|
|
51
|
-
|
|
52
|
-
logger.debug("Starting download with range: \(batchRangeStart)...\(batchRangeEnd)")
|
|
53
|
-
|
|
54
|
-
await downloader.update(latestDownloadedBlockHeight: batchRangeStart, force: true)
|
|
55
|
-
try await downloader.setSyncRange(lastScannedHeight...latestBlockHeight, batchSize: config.batchSize)
|
|
56
|
-
await downloader.setDownloadLimit(downloadLimit)
|
|
57
|
-
await downloader.startDownload(maxBlockBufferSize: config.downloadBufferSize)
|
|
58
|
-
|
|
59
|
-
try await downloader.waitUntilRequestedBlocksAreDownloaded(in: batchRange)
|
|
60
|
-
|
|
61
|
-
return await update(context: context)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
func stop() async {
|
|
65
|
-
await downloader.stopDownload()
|
|
66
|
-
}
|
|
67
|
-
}
|