react-native-zcash 0.6.14 → 0.7.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.
Files changed (163) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/android/build.gradle +4 -4
  3. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2470000.json +8 -0
  4. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2480000.json +8 -0
  5. package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +51 -9
  6. package/ios/RNZcash.m +8 -0
  7. package/ios/RNZcash.swift +66 -16
  8. package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +1 -1
  9. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +3 -1
  10. package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +1 -1
  11. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +11 -2
  12. package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +2 -2
  13. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +28 -11
  14. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +4 -4
  15. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +36 -7
  16. package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +1 -1
  17. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +93 -51
  18. package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +0 -26
  19. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +5 -6
  20. package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +1 -11
  21. package/ios/ZCashLightClientKit/Block/SaplingParameters/SaplingParametersHandler.swift +6 -4
  22. package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +10 -12
  23. package/ios/ZCashLightClientKit/Checkpoint/BundleCheckpointSource.swift +38 -0
  24. package/ios/ZCashLightClientKit/Checkpoint/BundleCheckpointURLProvider.swift +40 -0
  25. package/ios/ZCashLightClientKit/{Constants/Checkpoint+Constants.swift → Checkpoint/Checkpoint+helpers.swift} +1 -33
  26. package/ios/ZCashLightClientKit/Checkpoint/CheckpointSource.swift +34 -0
  27. package/ios/ZCashLightClientKit/Checkpoint/CheckpointSourceFactory.swift +14 -0
  28. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +61 -6
  29. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +63 -4
  30. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +4 -0
  31. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +21 -33
  32. package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +0 -182
  33. package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +0 -173
  34. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +5 -2
  35. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
  36. package/ios/ZCashLightClientKit/Error/ZcashError.swift +53 -1
  37. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +19 -1
  38. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +32 -0
  39. package/ios/ZCashLightClientKit/Initializer.swift +8 -17
  40. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +103 -217
  41. package/ios/ZCashLightClientKit/Model/Proposal.swift +45 -0
  42. package/ios/ZCashLightClientKit/Model/ScanSummary.swift +14 -0
  43. package/ios/ZCashLightClientKit/Model/WalletSummary.swift +58 -0
  44. package/ios/ZCashLightClientKit/Model/WalletTypes.swift +0 -16
  45. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +5 -3
  46. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proposal.pb.swift +934 -0
  47. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/proposal.proto +138 -0
  48. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +2 -4
  49. package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +9 -1
  50. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2272500.json +8 -0
  51. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2275000.json +8 -0
  52. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2277500.json +8 -0
  53. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2282500.json +8 -0
  54. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2285000.json +8 -0
  55. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2287500.json +8 -0
  56. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2292500.json +8 -0
  57. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2295000.json +8 -0
  58. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2297500.json +8 -0
  59. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2302500.json +8 -0
  60. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2305000.json +8 -0
  61. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2307500.json +8 -0
  62. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2312500.json +8 -0
  63. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2315000.json +8 -0
  64. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2317500.json +8 -0
  65. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2322500.json +8 -0
  66. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2325000.json +8 -0
  67. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2327500.json +8 -0
  68. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2332500.json +8 -0
  69. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2335000.json +8 -0
  70. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2337500.json +8 -0
  71. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2342500.json +8 -0
  72. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2345000.json +8 -0
  73. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2347500.json +8 -0
  74. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2352500.json +8 -0
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2355000.json +8 -0
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2357500.json +8 -0
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2362500.json +8 -0
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2365000.json +8 -0
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2367500.json +8 -0
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2372500.json +8 -0
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2375000.json +8 -0
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2377500.json +8 -0
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2382500.json +8 -0
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2385000.json +8 -0
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2387500.json +8 -0
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2392500.json +8 -0
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2395000.json +8 -0
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2397500.json +8 -0
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2402500.json +8 -0
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2405000.json +8 -0
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2407500.json +8 -0
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2412500.json +8 -0
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2415000.json +8 -0
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2417500.json +8 -0
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2422500.json +8 -0
  96. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2425000.json +8 -0
  97. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2427500.json +8 -0
  98. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2432500.json +8 -0
  99. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2435000.json +8 -0
  100. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2437500.json +8 -0
  101. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2442500.json +8 -0
  102. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2445000.json +8 -0
  103. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2447500.json +8 -0
  104. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2452500.json +8 -0
  105. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2455000.json +8 -0
  106. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2457500.json +8 -0
  107. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2462500.json +8 -0
  108. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2465000.json +8 -0
  109. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2467500.json +8 -0
  110. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2470000.json +8 -0
  111. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2472500.json +8 -0
  112. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2480000.json +8 -0
  113. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2560000.json +8 -0
  114. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2570000.json +8 -0
  115. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2580000.json +8 -0
  116. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2590000.json +8 -0
  117. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2600000.json +8 -0
  118. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2610000.json +8 -0
  119. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2620000.json +8 -0
  120. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2630000.json +8 -0
  121. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2640000.json +8 -0
  122. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2650000.json +8 -0
  123. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2660000.json +8 -0
  124. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2670000.json +8 -0
  125. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2680000.json +8 -0
  126. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2690000.json +8 -0
  127. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2700000.json +8 -0
  128. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2710000.json +8 -0
  129. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2720000.json +8 -0
  130. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2730000.json +8 -0
  131. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2740000.json +8 -0
  132. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2750000.json +8 -0
  133. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2760000.json +8 -0
  134. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2770000.json +8 -0
  135. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2780000.json +8 -0
  136. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2790000.json +8 -0
  137. package/ios/ZCashLightClientKit/Rust/ZcashKeyDerivationBackend.swift +1 -5
  138. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +327 -153
  139. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +78 -36
  140. package/ios/ZCashLightClientKit/Rust/zcashlc.h +402 -118
  141. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +43 -14
  142. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +52 -14
  143. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +10 -6
  144. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +220 -70
  145. package/ios/ZCashLightClientKit/Synchronizer.swift +105 -29
  146. package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +61 -32
  147. package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +52 -61
  148. package/ios/ZCashLightClientKit/Utils/DBActor.swift +21 -0
  149. package/ios/ZCashLightClientKit/Utils/LoggingProxy.swift +5 -0
  150. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +71 -14
  151. package/ios/libzcashlc.xcframework/Info.plist +5 -5
  152. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  153. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  154. package/lib/rnzcash.rn.js +21 -6
  155. package/lib/rnzcash.rn.js.map +1 -1
  156. package/lib/src/react-native.d.ts +2 -1
  157. package/lib/src/types.d.ts +9 -1
  158. package/package.json +1 -1
  159. package/src/react-native.ts +23 -4
  160. package/src/types.ts +10 -1
  161. package/ios/ZCashLightClientKit/Model/ScanProgress.swift +0 -29
  162. package/ios/ZCashLightClientKit/Repository/UnspentTransactionOutputRepository.swift +0 -16
  163. /package/ios/ZCashLightClientKit/{Model → Checkpoint}/Checkpoint.swift +0 -0
@@ -7,252 +7,138 @@
7
7
 
8
8
  import Foundation
9
9
 
10
- /// SDK's tool for the measurement of metrics.
11
- /// The barebone API of the `SDKMetrics` is all about turning it on/off, pushing new reports in and popping RAW data out.
12
- /// The processing of data is either left to the user of `SDKMetrics` or anybody can take an advantage of extension APIs
13
- /// providing useful structs and reports.
14
- ///
15
- /// Usage:
16
- /// The `SDKMetrics` API has been designed so it has the lowest impact possible on the SDK itself.
17
- /// Reporting of the metrics is already in place but ignored until `enableMetrics()` is called. Once turned on, the data is collected
18
- /// and cumulated to the in memory structural storage until `disableMetrics()` is called.
19
- /// `disableMetrics()` also clears out the in memory storage.
20
- ///
21
- /// To collect data and process it there are 2 ways:
22
- ///
23
- /// 1.
24
- /// Get RAW data by calling either `popBlock` or `popAllBlockReports`. The post-processing of data is then delegated to the caller.
25
- ///
26
- /// 2.
27
- /// Get cumulated data by using an extension APIs. For the summarized collection, call `cumulativeSummary()`.
28
- /// Sometimes, typically when you want to run several iterations, the `cumulateReportsAndStartNewSet()` automatically computes
29
- /// cumulativeSummary, stores it and starts to collect a new set. All summaries can be either processed by a caller,
30
- /// accessing the collection `cumulativeSummaries` directly or values can be merged into one final summary by calling `summarizedCumulativeReports()`.
31
- ///
32
- /// We encourage you to check`SDKMetricsTests` and other tests in the Test/PerformanceTests/ folder.
33
- public class SDKMetrics {
34
- public struct BlockMetricReport: Equatable {
35
- public let batchSize: Int
36
- public let startTime: TimeInterval
37
- public let endTime: TimeInterval
38
- public var duration: TimeInterval { endTime - startTime }
39
- }
40
-
41
- public enum Operation {
42
- case downloadBlocks
43
- case scanBlocks
44
- case enhancement
45
- case fetchUTXOs
46
- }
47
-
48
- public struct SyncReport: Equatable {
49
- public let startTime: TimeInterval
50
- public let endTime: TimeInterval
51
- public var duration: TimeInterval { endTime - startTime }
52
- }
53
-
54
- public var cumulativeSummaries: [CumulativeSummary] = []
55
- public var syncReport: SyncReport?
56
- var isEnabled = false
57
- var reports: [Operation: [BlockMetricReport]] = [:]
10
+ protocol SDKMetrics {
11
+ func cbpStart()
12
+ func actionStart(_ action: CBPState)
13
+ func actionDetail(_ detail: String, `for` action: CBPState)
14
+ func actionStop()
15
+ func logCBPOverviewReport(_ logger: Logger, walletSummary: WalletSummary?) async
16
+ }
58
17
 
59
- public init() { }
60
-
61
- /// `SDKMetrics` is disabled by default. Any pushed data are simply ignored until `enableMetrics()` is called.
62
- public func enableMetrics() {
63
- isEnabled = true
18
+ final class SDKMetricsImpl: SDKMetrics {
19
+ public struct CBPStateMetricReport: Equatable {
20
+ static let zero = Self(runs: 0, startTime: 0, cummulativeTime: 0, maxTime: 0, avgTime: 0)
21
+
22
+ var runs: Int
23
+ var startTime: TimeInterval
24
+ var cummulativeTime: TimeInterval
25
+ var minTime: TimeInterval = .infinity
26
+ var maxTime: TimeInterval
27
+ var avgTime: TimeInterval
28
+
29
+ var details: [String] = []
64
30
  }
31
+
32
+ // Compact Block Processor Metrics
33
+ var syncs = 0
34
+ var cbpStartTime: TimeInterval = 0
35
+ var cbpOverview: [CBPState: CBPStateMetricReport] = [:]
36
+ var lastActionInRun: CBPState?
65
37
 
66
- public func disableMetrics() {
67
- isEnabled = false
68
- clearAll()
38
+ public init() { }
39
+
40
+ func cbpStart() {
41
+ syncs += 1
42
+ cbpStartTime = Date().timeIntervalSince1970
43
+
44
+ // reset of previous values
45
+ cbpOverview.removeAll()
69
46
  }
70
-
71
- /// `SDKMetrics` focuses deeply on sync process and metrics related to it. By default there are reports around
72
- /// block operations like download, validate, etc. This method pushes data on a stack for the specific operation.
73
- func pushProgressReport(
74
- start: Date,
75
- end: Date,
76
- batchSize: Int,
77
- operation: Operation
78
- ) {
79
- guard isEnabled else { return }
80
47
 
81
- let blockMetricReport = BlockMetricReport(
82
- batchSize: batchSize,
83
- startTime: start.timeIntervalSinceReferenceDate,
84
- endTime: end.timeIntervalSinceReferenceDate
85
- )
48
+ func actionStart(_ action: CBPState) {
49
+ actionStop()
86
50
 
87
- guard reports[operation] != nil else {
88
- reports[operation] = [blockMetricReport]
89
- return
51
+ lastActionInRun = action
52
+
53
+ var report = CBPStateMetricReport.zero
54
+
55
+ if let reportFound = cbpOverview[action] {
56
+ report = reportFound
90
57
  }
58
+
59
+ report.runs += 1
60
+ report.startTime = Date().timeIntervalSince1970
91
61
 
92
- reports[operation]?.append(blockMetricReport)
62
+ cbpOverview[action] = report
93
63
  }
94
64
 
95
- /// Block synchronisation consists of operations but the whole process is measured also, represented by
96
- /// different struct `SyncReport`, missing specifics for the operations like batch size, etc.
97
- /// Used for the total syncing time report in the first place.
98
- func pushSyncReport(
99
- start: Date,
100
- end: Date
101
- ) {
102
- guard isEnabled else { return }
65
+ func actionDetail(_ detail: String, `for` action: CBPState) {
66
+ guard var report = cbpOverview[action] else {
67
+ return
68
+ }
103
69
 
104
- let syncReport = SyncReport(
105
- startTime: start.timeIntervalSinceReferenceDate,
106
- endTime: end.timeIntervalSinceReferenceDate
107
- )
70
+ report.details.append(detail)
108
71
 
109
- self.syncReport = syncReport
72
+ cbpOverview[action] = report
110
73
  }
111
74
 
112
- /// A method allowing users of the `SDKMetrics` to pop the RAW data out of the system. For the specific `operation`
113
- /// with option to either leave data in the storage or flushing it out and start the next batch of collecting new ones.
114
- public func popBlock(operation: Operation, flush: Bool = false) -> [BlockMetricReport]? {
115
- defer {
116
- if flush { clearReport(operation) }
75
+ func actionStop() {
76
+ guard let lastActionInRun else {
77
+ return
117
78
  }
118
79
 
119
- return reports[operation]
120
- }
121
-
122
- /// A method allowing users of the `SDKMetrics` to pop the RAW data out of the system. This time for all measured operations
123
- /// with option to either leave data in the storage or flushing it out and start the next batch of collecting new ones.
124
- public func popAllBlockReports(flush: Bool = false) -> [Operation: [BlockMetricReport]] {
125
- defer {
126
- if flush { clearAllBlockReports() }
80
+ guard var report = cbpOverview[lastActionInRun] else {
81
+ return
127
82
  }
128
-
129
- return reports
130
- }
131
-
132
- func clearReport(_ operation: Operation) {
133
- reports.removeValue(forKey: operation)
134
- }
135
-
136
- func clearAllBlockReports() {
137
- reports.removeAll()
138
- cumulativeSummaries.removeAll()
139
- }
140
-
141
- func clearAll() {
142
- clearAllBlockReports()
143
- syncReport = nil
144
- }
145
- }
146
83
 
147
- /// This extension provides an API that provides the summary and accumulated reports.
148
- /// The RAW data can pulled out and be processed without this extension but we
149
- /// wanted to provide a way how to get essential summaries right from the SDK.
150
- extension SDKMetrics {
151
- public struct CumulativeSummary: Equatable {
152
- public let downloadedBlocksReport: ReportSummary?
153
- public let scannedBlocksReport: ReportSummary?
154
- public let enhancementReport: ReportSummary?
155
- public let fetchUTXOsReport: ReportSummary?
156
- public let totalSyncReport: ReportSummary?
157
- }
158
-
159
- public struct ReportSummary: Equatable {
160
- public let minTime: TimeInterval
161
- public let maxTime: TimeInterval
162
- public let avgTime: TimeInterval
84
+ let endTime = Date().timeIntervalSince1970
85
+ let runTime = endTime - report.startTime
163
86
 
164
- public static let zero = Self(minTime: 0, maxTime: 0, avgTime: 0)
165
- }
166
-
167
- /// This method takes all the RAW data and computes a `CumulativeSummary` for every `operation`
168
- /// independently. A `ReportSummary` is the result per `operation`, providing min, max and avg times.
169
- public func cumulativeSummary() -> CumulativeSummary {
170
- let downloadReport = summaryFor(reports: reports[.downloadBlocks])
171
- let scanReport = summaryFor(reports: reports[.scanBlocks])
172
- let enhancementReport = summaryFor(reports: reports[.enhancement])
173
- let fetchUTXOsReport = summaryFor(reports: reports[.fetchUTXOs])
174
- var totalSyncReport: ReportSummary?
87
+ report.cummulativeTime += runTime
175
88
 
176
- if let duration = syncReport?.duration {
177
- totalSyncReport = ReportSummary(minTime: duration, maxTime: duration, avgTime: duration)
89
+ if runTime < report.minTime {
90
+ report.minTime = runTime
178
91
  }
179
-
180
- return CumulativeSummary(
181
- downloadedBlocksReport: downloadReport,
182
- scannedBlocksReport: scanReport,
183
- enhancementReport: enhancementReport,
184
- fetchUTXOsReport: fetchUTXOsReport,
185
- totalSyncReport: totalSyncReport
186
- )
187
- }
188
-
189
- /// This method computes the `CumulativeSummary` for the RAW data already in the system, stores it
190
- /// and leave room for collecting new RAW data. Typical use case is when some code is expected to run several times
191
- /// and every run is expected to be a new data collection.
192
- /// Usage of this API is then typically followed by calling `summarizedCumulativeReports()` which merges all stored
193
- /// cumulative reports into one final report.
194
- public func cumulateReportsAndStartNewSet() {
195
- cumulativeSummaries.append(cumulativeSummary())
196
- reports.removeAll()
197
- syncReport = nil
198
- }
199
92
 
200
- /// This method takes all `CumulativeSummary` reports and merge them all together, providing
201
- /// final `CumulativeSummary` per `operation`, ensuring right min and max values are in the place
202
- /// as well as computes final avg time per `operation`.
203
- public func summarizedCumulativeReports() -> CumulativeSummary? {
204
- var finalSummary: CumulativeSummary?
205
-
206
- cumulativeSummaries.forEach { summary in
207
- finalSummary = CumulativeSummary(
208
- downloadedBlocksReport: accumulate(left: finalSummary?.downloadedBlocksReport, right: summary.downloadedBlocksReport),
209
- scannedBlocksReport: accumulate(left: finalSummary?.scannedBlocksReport, right: summary.scannedBlocksReport),
210
- enhancementReport: accumulate(left: finalSummary?.enhancementReport, right: summary.enhancementReport),
211
- fetchUTXOsReport: accumulate(left: finalSummary?.fetchUTXOsReport, right: summary.fetchUTXOsReport),
212
- totalSyncReport: accumulate(left: finalSummary?.totalSyncReport, right: summary.totalSyncReport)
213
- )
93
+ if runTime > report.maxTime {
94
+ report.maxTime = runTime
214
95
  }
215
96
 
216
- return finalSummary
97
+ if report.runs > 0 {
98
+ report.avgTime = report.cummulativeTime / Double(report.runs)
99
+ }
100
+
101
+ cbpOverview[lastActionInRun] = report
217
102
  }
218
103
 
219
- /// Internal helper method that accumulates `ReportSummary` times.
220
- func accumulate(left: ReportSummary?, right: ReportSummary?) -> ReportSummary? {
221
- guard let left, let right else {
222
- if let right {
223
- return ReportSummary(
224
- minTime: right.minTime,
225
- maxTime: right.maxTime,
226
- avgTime: right.avgTime
227
- )
228
- }
229
- return nil
230
- }
231
-
232
- return ReportSummary(
233
- minTime: min(left.minTime, right.minTime),
234
- maxTime: max(left.maxTime, right.maxTime),
235
- avgTime: (left.avgTime + right.avgTime) * 0.5
104
+ // swiftlint:disable string_concatenation
105
+ func logCBPOverviewReport(_ logger: Logger, walletSummary: WalletSummary?) async {
106
+ actionStop()
107
+
108
+ let accountBalance = walletSummary?.accountBalances[0]
109
+ logger.sync(
110
+ """
111
+ SYNC (\(syncs)) REPORT
112
+ finished in: \(Date().timeIntervalSince1970 - cbpStartTime)
113
+ verified balance: \(accountBalance?.saplingBalance.spendableValue.amount ?? 0)
114
+ total balance: \(accountBalance?.saplingBalance.total().amount ?? 0)
115
+ """
236
116
  )
237
- }
238
117
 
239
- /// Internal helper method that computes min, max and avg times for the `BlockMetricReport` collection.
240
- func summaryFor(reports: [BlockMetricReport]?) -> ReportSummary? {
241
- guard let reports, !reports.isEmpty else { return nil }
242
-
243
- var min: TimeInterval = 99999999.0
244
- var max: TimeInterval = 0.0
245
- var avg: TimeInterval = 0.0
118
+ try? await Task.sleep(nanoseconds: 100_000)
119
+
120
+ for action in cbpOverview {
246
121
 
247
- reports.forEach { report in
248
- let duration = report.duration
249
- avg += duration
250
- if duration > max { max = duration }
251
- if duration < min { min = duration }
122
+ let report = action.value
123
+
124
+ var resText = """
125
+ action: \(action.key)
126
+ runs: \(report.runs)
127
+ cummulativeTime: \(report.cummulativeTime)
128
+ minTime: \(report.minTime)
129
+ maxTime: \(report.maxTime)
130
+ avgTime: \(report.avgTime)
131
+ """
132
+
133
+ if !report.details.isEmpty {
134
+ resText += "\ndetails:\n"
135
+
136
+ for detail in report.details {
137
+ resText += "\t\(detail)\n"
138
+ }
139
+ }
140
+
141
+ logger.sync(resText)
252
142
  }
253
- // reports.count is guarded to never be a zero
254
- avg /= TimeInterval(reports.count)
255
-
256
- return ReportSummary(minTime: min, maxTime: max, avgTime: avg)
257
143
  }
258
144
  }
@@ -0,0 +1,45 @@
1
+ //
2
+ // Proposal.swift
3
+ //
4
+ //
5
+ // Created by Jack Grigg on 20/02/2024.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ /// A data structure that describes a series of transactions to be created.
11
+ public struct Proposal: Equatable {
12
+ let inner: FfiProposal
13
+
14
+ /// Returns the number of transactions that this proposal will create.
15
+ ///
16
+ /// This is equal to the number of `TransactionSubmitResult`s that will be returned
17
+ /// from `Synchronizer.createProposedTransactions`.
18
+ ///
19
+ /// Proposals always create at least one transaction.
20
+ public func transactionCount() -> Int {
21
+ inner.steps.count
22
+ }
23
+
24
+ /// Returns the total fee to be paid across all proposed transactions, in zatoshis.
25
+ public func totalFeeRequired() -> Zatoshi {
26
+ inner.steps.reduce(Zatoshi.zero) { acc, step in
27
+ acc + Zatoshi(Int64(step.balance.feeRequired))
28
+ }
29
+ }
30
+ }
31
+
32
+ public extension Proposal {
33
+ /// IMPORTANT: This function is for testing purposes only. It produces fake invalid
34
+ /// data that can be used to check UI elements, but will always produce an error when
35
+ /// passed to `Synchronizer.createProposedTransactions`. It should never be called in
36
+ /// production code.
37
+ static func testOnlyFakeProposal(totalFee: UInt64) -> Self {
38
+ var ffiProposal = FfiProposal()
39
+ var balance = FfiTransactionBalance()
40
+
41
+ balance.feeRequired = totalFee
42
+
43
+ return Self(inner: ffiProposal)
44
+ }
45
+ }
@@ -0,0 +1,14 @@
1
+ //
2
+ // ScanSummary.swift
3
+ //
4
+ //
5
+ // Created by Jack Grigg on 26/01/2024.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ struct ScanSummary: Equatable {
11
+ let scannedRange: Range<BlockHeight>
12
+ let spentSaplingNoteCount: UInt64
13
+ let receivedSaplingNoteCount: UInt64
14
+ }
@@ -0,0 +1,58 @@
1
+ //
2
+ // WalletSummary.swift
3
+ //
4
+ //
5
+ // Created by Jack Grigg on 06/09/2023.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ public struct PoolBalance: Equatable {
11
+ public let spendableValue: Zatoshi
12
+ public let changePendingConfirmation: Zatoshi
13
+ public let valuePendingSpendability: Zatoshi
14
+
15
+ static let zero = PoolBalance(spendableValue: .zero, changePendingConfirmation: .zero, valuePendingSpendability: .zero)
16
+
17
+ public func total() -> Zatoshi {
18
+ self.spendableValue + self.changePendingConfirmation + self.valuePendingSpendability
19
+ }
20
+ }
21
+
22
+ public struct AccountBalance: Equatable {
23
+ public let saplingBalance: PoolBalance
24
+ public let orchardBalance: PoolBalance
25
+ public let unshielded: Zatoshi
26
+
27
+ static let zero = AccountBalance(saplingBalance: .zero, orchardBalance: .zero, unshielded: .zero)
28
+ }
29
+
30
+ struct ScanProgress: Equatable {
31
+ let numerator: UInt64
32
+ let denominator: UInt64
33
+
34
+ func progress() throws -> Float {
35
+ guard denominator != 0 else {
36
+ // this shouldn't happen but if it does, we need to get notified by clients and work on a fix
37
+ throw ZcashError.rustScanProgressOutOfRange("\(numerator)/\(denominator)")
38
+ }
39
+
40
+ let value = Float(numerator) / Float(denominator)
41
+
42
+ // this shouldn't happen but if it does, we need to get notified by clients and work on a fix
43
+ if value > 1.0 {
44
+ throw ZcashError.rustScanProgressOutOfRange("\(value)")
45
+ }
46
+
47
+ return value
48
+ }
49
+ }
50
+
51
+ struct WalletSummary: Equatable {
52
+ let accountBalances: [UInt32: AccountBalance]
53
+ let chainTipHeight: BlockHeight
54
+ let fullyScannedHeight: BlockHeight
55
+ let scanProgress: ScanProgress?
56
+ let nextSaplingSubtreeIndex: UInt32
57
+ let nextOrchardSubtreeIndex: UInt32
58
+ }
@@ -263,19 +263,3 @@ public enum Recipient: Equatable, StringEncoded {
263
263
  }
264
264
  }
265
265
  }
266
-
267
- public struct WalletBalance: Equatable {
268
- public let verified: Zatoshi
269
- public let total: Zatoshi
270
-
271
- public init(verified: Zatoshi, total: Zatoshi) {
272
- self.verified = verified
273
- self.total = total
274
- }
275
- }
276
-
277
- public extension WalletBalance {
278
- static var zero: WalletBalance {
279
- Self(verified: .zero, total: .zero)
280
- }
281
- }
@@ -223,14 +223,12 @@ extension LightWalletGRPCService: LightWalletService {
223
223
  do {
224
224
  guard let reply = try await iterator.next() else { return nil }
225
225
  return UTXO(
226
- id: nil,
227
226
  address: reply.address,
228
227
  prevoutTxId: reply.txid,
229
228
  prevoutIndex: Int(reply.index),
230
229
  script: reply.script,
231
230
  valueZat: Int(reply.valueZat),
232
- height: Int(reply.height),
233
- spentInTx: nil
231
+ height: Int(reply.height)
234
232
  )
235
233
  } catch {
236
234
  let serviceError = error.mapToServiceError()
@@ -278,6 +276,10 @@ extension LightWalletGRPCService: LightWalletService {
278
276
  }
279
277
  }
280
278
 
279
+ func getTreeState(_ id: BlockID) async throws -> TreeState {
280
+ try await compactTxStreamer.getTreeState(id)
281
+ }
282
+
281
283
  func closeConnection() {
282
284
  _ = channel.close()
283
285
  }