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