react-native-zcash 0.8.1 → 0.9.1

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 (124) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/android/build.gradle +3 -3
  3. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2650000.json +8 -0
  4. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2660000.json +8 -0
  5. package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +15 -25
  6. package/ios/RNZcash.m +3 -5
  7. package/ios/RNZcash.swift +42 -23
  8. package/ios/RNZcash.xcodeproj/xcuserdata/samholmes.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  9. package/ios/RNZcash.xcworkspace/xcuserdata/samholmes.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  10. package/ios/ZCashLightClientKit/Block/Actions/Action.swift +1 -0
  11. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +1 -1
  12. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +1 -1
  13. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +1 -1
  14. package/ios/ZCashLightClientKit/Block/Actions/TxResubmissionAction.swift +75 -0
  15. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +1 -1
  16. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +3 -1
  17. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +14 -0
  18. package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
  19. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +54 -49
  20. package/ios/ZCashLightClientKit/Checkpoint/BundleCheckpointSource.swift +1 -6
  21. package/ios/ZCashLightClientKit/Checkpoint/CheckpointSourceFactory.swift +1 -1
  22. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +3 -1
  23. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +6 -2
  24. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +15 -0
  25. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +20 -4
  26. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +27 -24
  27. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +2 -2
  28. package/ios/ZCashLightClientKit/Error/ZcashError.swift +32 -1
  29. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +11 -1
  30. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +18 -0
  31. package/ios/ZCashLightClientKit/Initializer.swift +22 -14
  32. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +0 -1
  33. package/ios/ZCashLightClientKit/Model/FiatCurrencyResult.swift +25 -0
  34. package/ios/ZCashLightClientKit/Model/Proposal.swift +1 -1
  35. package/ios/ZCashLightClientKit/Model/TransactionDataRequest.swift +26 -0
  36. package/ios/ZCashLightClientKit/Model/WalletTypes.swift +39 -1
  37. package/ios/ZCashLightClientKit/Model/Zatoshi.swift +1 -1
  38. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +39 -2
  39. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +5 -4
  40. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +819 -3
  41. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +2 -2
  42. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +3 -1
  43. package/ios/ZCashLightClientKit/Providers/ResourceProvider.swift +10 -0
  44. package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +4 -0
  45. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2475000.json +8 -0
  46. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2477500.json +8 -0
  47. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2482500.json +8 -0
  48. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2485000.json +8 -0
  49. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2487500.json +8 -0
  50. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2492500.json +8 -0
  51. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2495000.json +8 -0
  52. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2497500.json +8 -0
  53. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2502500.json +8 -0
  54. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2505000.json +8 -0
  55. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2507500.json +8 -0
  56. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2512500.json +8 -0
  57. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2515000.json +8 -0
  58. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2517500.json +8 -0
  59. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2522500.json +8 -0
  60. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2525000.json +8 -0
  61. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2527500.json +8 -0
  62. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2532500.json +8 -0
  63. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2535000.json +8 -0
  64. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2537500.json +8 -0
  65. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2542500.json +8 -0
  66. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2545000.json +8 -0
  67. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2547500.json +8 -0
  68. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2552500.json +8 -0
  69. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2555000.json +8 -0
  70. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2557500.json +8 -0
  71. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2562500.json +8 -0
  72. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2565000.json +8 -0
  73. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2567500.json +8 -0
  74. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2572500.json +8 -0
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2575000.json +8 -0
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2577500.json +8 -0
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2582500.json +8 -0
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2585000.json +8 -0
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2587500.json +8 -0
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2592500.json +8 -0
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2595000.json +8 -0
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2597500.json +8 -0
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2602500.json +8 -0
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2605000.json +8 -0
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2607500.json +8 -0
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2612500.json +8 -0
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2615000.json +8 -0
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2617500.json +8 -0
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2622500.json +8 -0
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2625000.json +8 -0
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2627500.json +8 -0
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2632500.json +8 -0
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2635000.json +8 -0
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2637500.json +8 -0
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2642500.json +8 -0
  96. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2645000.json +8 -0
  97. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2647500.json +8 -0
  98. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2650000.json +8 -0
  99. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2660000.json +8 -0
  100. package/ios/ZCashLightClientKit/Rust/ZcashKeyDerivationBackend.swift +4 -24
  101. package/ios/ZCashLightClientKit/Rust/ZcashKeyDerivationBackendWelding.swift +0 -15
  102. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +133 -32
  103. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +18 -1
  104. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +4 -0
  105. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +5 -1
  106. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +53 -3
  107. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +236 -7
  108. package/ios/ZCashLightClientKit/Synchronizer.swift +28 -0
  109. package/ios/ZCashLightClientKit/Tool/DerivationTool.swift +29 -5
  110. package/ios/ZCashLightClientKit/Tor/TorClient.swift +57 -0
  111. package/ios/ZCashLightClientKit/Utils/LoggingProxy.swift +4 -0
  112. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +4 -0
  113. package/ios/lib/libzcashlc.a +0 -0
  114. package/ios/libzcashlc.xcframework/Info.plist +5 -5
  115. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  116. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  117. package/ios/zcashlc.h +287 -42
  118. package/lib/rnzcash.rn.js +8 -8
  119. package/lib/rnzcash.rn.js.map +1 -1
  120. package/lib/src/react-native.d.ts +3 -3
  121. package/lib/src/types.d.ts +4 -2
  122. package/package.json +1 -1
  123. package/src/react-native.ts +13 -18
  124. package/src/types.ts +5 -2
@@ -60,24 +60,8 @@ struct BlockEnhancerImpl {
60
60
  let rustBackend: ZcashRustBackendWelding
61
61
  let transactionRepository: TransactionRepository
62
62
  let metrics: SDKMetrics
63
+ let service: LightWalletService
63
64
  let logger: Logger
64
-
65
- private func enhance(transaction: ZcashTransaction.Overview) async throws -> ZcashTransaction.Overview {
66
- logger.debug("Zoom.... Enhance... Tx: \(transaction.rawID.toHexStringTxId())")
67
-
68
- let fetchedTransaction = try await blockDownloaderService.fetchTransaction(txId: transaction.rawID)
69
-
70
- let transactionID = fetchedTransaction.rawID.toHexStringTxId()
71
- let block = String(describing: transaction.minedHeight)
72
- logger.debug("Decrypting and storing transaction id: \(transactionID) block: \(block)")
73
-
74
- try await rustBackend.decryptAndStoreTransaction(
75
- txBytes: fetchedTransaction.raw.bytes,
76
- minedHeight: Int32(fetchedTransaction.minedHeight)
77
- )
78
-
79
- return try await transactionRepository.find(rawID: fetchedTransaction.rawID)
80
- }
81
65
  }
82
66
 
83
67
  extension BlockEnhancerImpl: BlockEnhancer {
@@ -91,54 +75,75 @@ extension BlockEnhancerImpl: BlockEnhancer {
91
75
 
92
76
  // fetch transactions
93
77
  do {
94
- let startTime = Date()
95
- let transactions = try await transactionRepository.find(in: range, limit: Int.max, kind: .all)
78
+ let transactionDataRequests = try await rustBackend.transactionDataRequests()
96
79
 
97
- guard !transactions.isEmpty else {
98
- logger.debug("no transactions detected on range: \(range.lowerBound)...\(range.upperBound)")
99
- logger.sync("No transactions detected on range: \(range.lowerBound)...\(range.upperBound)")
80
+ guard !transactionDataRequests.isEmpty else {
81
+ logger.debug("No transaction data requests detected.")
82
+ logger.sync("No transaction data requests detected.")
100
83
  return nil
101
84
  }
102
85
 
103
- let chainTipHeight = try await blockDownloaderService.latestBlockHeight()
104
-
105
- let newlyMinedLowerBound = chainTipHeight - ZcashSDK.expiryOffset
106
-
107
- let newlyMinedRange = newlyMinedLowerBound...chainTipHeight
108
-
109
- for index in 0 ..< transactions.count {
110
- let transaction = transactions[index]
86
+ for index in 0 ..< transactionDataRequests.count {
87
+ let transactionDataRequest = transactionDataRequests[index]
111
88
  var retry = true
112
-
89
+
113
90
  while retry && retries < maxRetries {
114
91
  try Task.checkCancellation()
115
92
  do {
116
- let confirmedTx = try await enhance(transaction: transaction)
117
- retry = false
118
-
119
- let progress = EnhancementProgress(
120
- totalTransactions: transactions.count,
121
- enhancedTransactions: index + 1,
122
- lastFoundTransaction: confirmedTx,
123
- range: range,
124
- newlyMined: confirmedTx.isSentTransaction && newlyMinedRange.contains(confirmedTx.minedHeight ?? 0)
125
- )
126
-
127
- await didEnhance(progress)
93
+ switch transactionDataRequest {
94
+ case .getStatus(let txId):
95
+ let response = try await blockDownloaderService.fetchTransaction(txId: txId.data)
96
+ retry = false
97
+
98
+ if let fetchedTransaction = response.tx {
99
+ try await rustBackend.setTransactionStatus(txId: fetchedTransaction.rawID, status: response.status)
100
+ }
101
+
102
+ case .enhancement(let txId):
103
+ let response = try await blockDownloaderService.fetchTransaction(txId: txId.data)
104
+ retry = false
105
+
106
+ if response.status == .txidNotRecognized {
107
+ try await rustBackend.setTransactionStatus(txId: txId.data, status: .txidNotRecognized)
108
+ } else if let fetchedTransaction = response.tx {
109
+ try await rustBackend.decryptAndStoreTransaction(
110
+ txBytes: fetchedTransaction.raw.bytes,
111
+ minedHeight: fetchedTransaction.minedHeight
112
+ )
113
+ }
114
+
115
+ case .spendsFromAddress(let sfa):
116
+ guard let blockRangeEnd = sfa.blockRangeEnd else {
117
+ logger.error("spendsFromAddress \(sfa) is missing blockRangeEnd, ignoring the request.")
118
+ continue
119
+ }
120
+
121
+ var filter = TransparentAddressBlockFilter()
122
+ filter.address = sfa.address
123
+ filter.range = BlockRange(startHeight: Int(sfa.blockRangeStart), endHeight: Int(blockRangeEnd - 1))
124
+
125
+ let stream = service.getTaddressTxids(filter)
126
+
127
+ for try await rawTransaction in stream {
128
+ let minedHeight = (rawTransaction.height == 0 || rawTransaction.height > UInt32.max)
129
+ ? nil : UInt32(rawTransaction.height)
130
+
131
+ try await rustBackend.decryptAndStoreTransaction(
132
+ txBytes: rawTransaction.data.bytes,
133
+ minedHeight: minedHeight
134
+ )
135
+ }
136
+ retry = false
137
+ }
128
138
  } catch {
129
139
  retries += 1
130
- logger.error("could not enhance txId \(transaction.rawID.toHexStringTxId()) - Error: \(error)")
140
+ logger.error("could not enhance transactionDataRequest \(transactionDataRequest) - Error: \(error)")
131
141
  if retries > maxRetries {
132
142
  throw error
133
143
  }
134
144
  }
135
145
  }
136
146
  }
137
-
138
- let endTime = Date()
139
- let logMsg = "Enhanced \(transactions.count) transaction(s) in \(endTime.timeIntervalSince1970 - startTime.timeIntervalSince1970) for range \(range.lowerBound)...\(range.upperBound)"
140
- logger.sync(logMsg)
141
- metrics.actionDetail(logMsg, for: .enhance)
142
147
  } catch {
143
148
  logger.error("error enhancing transactions! \(error)")
144
149
  throw error
@@ -14,12 +14,7 @@ struct BundleCheckpointSource: CheckpointSource {
14
14
 
15
15
  init(network: NetworkType) {
16
16
  self.network = network
17
- self.saplingActivation = switch network {
18
- case .mainnet:
19
- Checkpoint.mainnetMin
20
- case .testnet:
21
- Checkpoint.testnetMin
22
- }
17
+ self.saplingActivation = if network == .mainnet { Checkpoint.mainnetMin } else { Checkpoint.testnetMin }
23
18
  }
24
19
 
25
20
  func latestKnownCheckpoint() -> Checkpoint {
@@ -7,7 +7,7 @@
7
7
 
8
8
  import Foundation
9
9
 
10
- struct CheckpointSourceFactory {
10
+ enum CheckpointSourceFactory {
11
11
  static func fromBundle(for network: NetworkType) -> CheckpointSource {
12
12
  BundleCheckpointSource(network: network)
13
13
  }
@@ -128,7 +128,9 @@ public protocol ClosureSynchronizer {
128
128
  func refreshUTXOs(address: TransparentAddress, from height: BlockHeight, completion: @escaping (Result<RefreshedUTXOs, Error>) -> Void)
129
129
 
130
130
  func getAccountBalance(accountIndex: Int, completion: @escaping (Result<AccountBalance?, Error>) -> Void)
131
-
131
+
132
+ func refreshExchangeRateUSD()
133
+
132
134
  /*
133
135
  It can be missleading that these two methods are returning Publisher even this protocol is closure based. Reason is that Synchronizer doesn't
134
136
  provide different implementations for these two methods. So Combine it is even here.
@@ -97,7 +97,11 @@ public protocol CombineSynchronizer {
97
97
  memo: Memo?
98
98
  ) -> SinglePublisher<ZcashTransaction.Overview, Error>
99
99
 
100
- @available(*, deprecated, message: "Upcoming SDK 2.1 will create multiple transactions at once for some recipients. use `proposeShielding:` instead")
100
+ @available(
101
+ *,
102
+ deprecated,
103
+ message: "Upcoming SDK 2.1 will create multiple transactions at once for some recipients. use `proposeShielding:` instead"
104
+ )
101
105
  func shieldFunds(
102
106
  spendingKey: UnifiedSpendingKey,
103
107
  memo: Memo,
@@ -125,7 +129,7 @@ public protocol CombineSynchronizer {
125
129
 
126
130
  func refreshUTXOs(address: TransparentAddress, from height: BlockHeight) -> SinglePublisher<RefreshedUTXOs, Error>
127
131
 
128
- func getAccountBalance(accountIndex: Int) -> SinglePublisher<AccountBalance?, Error>
132
+ func refreshExchangeRateUSD()
129
133
 
130
134
  func rewind(_ policy: RewindPolicy) -> CompletablePublisher<Error>
131
135
  func wipe() -> CompletablePublisher<Error>
@@ -124,6 +124,9 @@ public enum ZcashSDK {
124
124
  /// Default Name for LibRustZcash data.db
125
125
  public static let defaultDataDbName = "data.db"
126
126
 
127
+ /// Default Name for Tor data directory
128
+ public static let defaultTorDirName = "tor"
129
+
127
130
  /// Default Name for Compact Block file system based db
128
131
  public static let defaultFsCacheName = "fs_cache"
129
132
 
@@ -144,6 +147,9 @@ public enum ZcashSDK {
144
147
  public static let outputParamFilename = "sapling-output.params"
145
148
  // swiftlint:disable:next force_unwrapping
146
149
  public static let outputParamFileURL = URL(string: cloudParameterURL)!.appendingPathComponent(outputParamFilename)
150
+
151
+ /// A constant that helps determine if a server’s chain tip is so far away from the estimated height that we consider the server out of sync
152
+ public static let syncedThresholdBlocks = UInt64(288)
147
153
  }
148
154
 
149
155
  public protocol NetworkConstants {
@@ -154,6 +160,9 @@ public protocol NetworkConstants {
154
160
  /// Default Name for LibRustZcash data.db
155
161
  static var defaultDataDbName: String { get }
156
162
 
163
+ /// Default Name for Tor data directory
164
+ static var defaultTorDirName: String { get }
165
+
157
166
  static var defaultFsBlockDbRootName: String { get }
158
167
 
159
168
  /// Default Name for Compact Block caches db
@@ -181,6 +190,9 @@ public enum ZcashSDKMainnetConstants: NetworkConstants {
181
190
  /// Default Name for LibRustZcash data.db
182
191
  public static let defaultDataDbName = "data.db"
183
192
 
193
+ /// Default Name for Tor data directory
194
+ public static let defaultTorDirName = "tor"
195
+
184
196
  public static let defaultFsBlockDbRootName = "fs_cache"
185
197
 
186
198
  /// Default Name for Compact Block caches db
@@ -197,6 +209,9 @@ public enum ZcashSDKTestnetConstants: NetworkConstants {
197
209
  /// Default Name for LibRustZcash data.db
198
210
  public static let defaultDataDbName = "data.db"
199
211
 
212
+ /// Default Name for Tor data directory
213
+ public static let defaultTorDirName = "tor"
214
+
200
215
  /// Default Name for Compact Block caches db
201
216
  public static let defaultCacheDbName = "caches.db"
202
217
 
@@ -10,8 +10,8 @@ import SQLite
10
10
 
11
11
  class TransactionSQLDAO: TransactionRepository {
12
12
  enum NotesTableStructure {
13
- static let transactionID = Expression<Int>("tx")
14
- static let memo = Expression<Blob>("memo")
13
+ static let transactionID = SQLite.Expression<Int>("tx")
14
+ static let memo = SQLite.Expression<Blob>("memo")
15
15
  }
16
16
 
17
17
  let dbProvider: ConnectionProvider
@@ -108,6 +108,18 @@ class TransactionSQLDAO: TransactionRepository {
108
108
  return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
109
109
  }
110
110
 
111
+ func findForResubmission(upTo: BlockHeight) async throws -> [ZcashTransaction.Overview] {
112
+ let query = transactionsView
113
+ .filter(
114
+ ZcashTransaction.Overview.Column.minedHeight == nil &&
115
+ ZcashTransaction.Overview.Column.expiryHeight > upTo
116
+ )
117
+ .filterQueryFor(kind: .sent)
118
+ .limit(Int.max)
119
+
120
+ return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
121
+ }
122
+
111
123
  func findReceived(offset: Int, limit: Int) async throws -> [ZcashTransaction.Overview] {
112
124
  let query = transactionsView
113
125
  .filterQueryFor(kind: .received)
@@ -135,14 +147,18 @@ class TransactionSQLDAO: TransactionRepository {
135
147
  return try await execute(query) { try ZcashTransaction.Overview(row: $0) }
136
148
  }
137
149
 
138
- func findMemos(for transaction: ZcashTransaction.Overview) async throws -> [Memo] {
150
+ func findMemos(for rawID: Data) async throws -> [Memo] {
139
151
  do {
140
- return try await getTransactionOutputs(for: transaction.rawID)
152
+ return try await getTransactionOutputs(for: rawID)
141
153
  .compactMap { $0.memo }
142
154
  } catch {
143
155
  throw ZcashError.transactionRepositoryFindMemos(error)
144
156
  }
145
157
  }
158
+
159
+ func findMemos(for transaction: ZcashTransaction.Overview) async throws -> [Memo] {
160
+ try await findMemos(for: transaction.rawID)
161
+ }
146
162
 
147
163
  func getTransactionOutputs(for rawID: Data) async throws -> [ZcashTransaction.Output] {
148
164
  let query = self.txOutputsView
@@ -50,6 +50,7 @@ public enum ZcashTransaction {
50
50
  public let fee: Zatoshi?
51
51
  public let index: Int?
52
52
  public var isSentTransaction: Bool { value < Zatoshi(0) }
53
+ public var isShielding: Bool
53
54
  public let hasChange: Bool
54
55
  public let memoCount: Int
55
56
  public let minedHeight: BlockHeight?
@@ -94,22 +95,22 @@ public enum ZcashTransaction {
94
95
  /// Used when fetching blocks from the lightwalletd
95
96
  struct Fetched {
96
97
  public let rawID: Data
97
- public let minedHeight: BlockHeight
98
+ public let minedHeight: UInt32?
98
99
  public let raw: Data
99
100
  }
100
101
  }
101
102
 
102
103
  extension ZcashTransaction.Output {
103
104
  enum Column {
104
- static let rawID = Expression<Blob>("txid")
105
- static let pool = Expression<Int>("output_pool")
106
- static let index = Expression<Int>("output_index")
107
- static let toAccount = Expression<Int?>("to_account_id")
108
- static let fromAccount = Expression<Int?>("from_account_id")
109
- static let toAddress = Expression<String?>("to_address")
110
- static let value = Expression<Int64>("value")
111
- static let isChange = Expression<Bool>("is_change")
112
- static let memo = Expression<Blob?>("memo")
105
+ static let rawID = SQLite.Expression<Blob>("txid")
106
+ static let pool = SQLite.Expression<Int>("output_pool")
107
+ static let index = SQLite.Expression<Int>("output_index")
108
+ static let toAccount = SQLite.Expression<Int?>("to_account_id")
109
+ static let fromAccount = SQLite.Expression<Int?>("from_account_id")
110
+ static let toAddress = SQLite.Expression<String?>("to_address")
111
+ static let value = SQLite.Expression<Int64>("value")
112
+ static let isChange = SQLite.Expression<Bool>("is_change")
113
+ static let memo = SQLite.Expression<Blob?>("memo")
113
114
  }
114
115
 
115
116
  init(row: Row) throws {
@@ -145,20 +146,21 @@ extension ZcashTransaction.Output {
145
146
 
146
147
  extension ZcashTransaction.Overview {
147
148
  enum Column {
148
- static let accountId = Expression<Int>("account_id")
149
- static let minedHeight = Expression<BlockHeight?>("mined_height")
150
- static let index = Expression<Int?>("tx_index")
151
- static let rawID = Expression<Blob>("txid")
152
- static let expiryHeight = Expression<BlockHeight?>("expiry_height")
153
- static let raw = Expression<Blob?>("raw")
154
- static let value = Expression<Int64>("account_balance_delta")
155
- static let fee = Expression<Int64?>("fee_paid")
156
- static let hasChange = Expression<Bool>("has_change")
157
- static let sentNoteCount = Expression<Int>("sent_note_count")
158
- static let receivedNoteCount = Expression<Int>("received_note_count")
159
- static let memoCount = Expression<Int>("memo_count")
160
- static let blockTime = Expression<Int64?>("block_time")
161
- static let expiredUnmined = Expression<Bool?>("expired_unmined")
149
+ static let accountId = SQLite.Expression<Int>("account_id")
150
+ static let minedHeight = SQLite.Expression<BlockHeight?>("mined_height")
151
+ static let index = SQLite.Expression<Int?>("tx_index")
152
+ static let rawID = SQLite.Expression<Blob>("txid")
153
+ static let expiryHeight = SQLite.Expression<BlockHeight?>("expiry_height")
154
+ static let raw = SQLite.Expression<Blob?>("raw")
155
+ static let value = SQLite.Expression<Int64>("account_balance_delta")
156
+ static let fee = SQLite.Expression<Int64?>("fee_paid")
157
+ static let hasChange = SQLite.Expression<Bool>("has_change")
158
+ static let sentNoteCount = SQLite.Expression<Int>("sent_note_count")
159
+ static let receivedNoteCount = SQLite.Expression<Int>("received_note_count")
160
+ static let isShielding = SQLite.Expression<Bool>("is_shielding")
161
+ static let memoCount = SQLite.Expression<Int>("memo_count")
162
+ static let blockTime = SQLite.Expression<Int64?>("block_time")
163
+ static let expiredUnmined = SQLite.Expression<Bool?>("expired_unmined")
162
164
  }
163
165
 
164
166
  init(row: Row) throws {
@@ -171,6 +173,7 @@ extension ZcashTransaction.Overview {
171
173
  self.minedHeight = try row.get(Column.minedHeight)
172
174
  self.rawID = Data(blob: try row.get(Column.rawID))
173
175
  self.receivedNoteCount = try row.get(Column.receivedNoteCount)
176
+ self.isShielding = try row.get(Column.isShielding)
174
177
  self.sentNoteCount = try row.get(Column.sentNoteCount)
175
178
  self.value = Zatoshi(try row.get(Column.value))
176
179
  self.isExpiredUmined = try row.get(Column.expiredUnmined)
@@ -3,11 +3,11 @@
3
3
  scriptDir=${0:a:h}
4
4
  cd "${scriptDir}"
5
5
 
6
- sourcery_version=2.1.7
6
+ sourcery_version=2.2.5
7
7
 
8
8
  if which sourcery >/dev/null; then
9
9
  if [[ $(sourcery --version) != $sourcery_version ]]; then
10
- echo "warning: Compatible sourcer version not installed. Install sourcer $sourcery_version. Currently installed version is $(sourcer --version)"
10
+ echo "warning: Compatible sourcery version not installed. Install sourcery $sourcery_version. Currently installed version is $(sourcery --version)"
11
11
  exit 1
12
12
  fi
13
13
 
@@ -1,4 +1,4 @@
1
- // Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
1
+ // Generated using Sourcery 2.2.5 — https://github.com/krzysztofzablocki/Sourcery
2
2
  // DO NOT EDIT
3
3
 
4
4
  /*
@@ -61,6 +61,9 @@ public enum ZcashError: Equatable, Error {
61
61
  /// LightWalletService.getSubtreeRoots failed.
62
62
  /// ZSRVC0009
63
63
  case serviceSubtreeRootsStreamFailed(_ error: LightWalletServiceError)
64
+ /// LightWalletService.getTaddressTxids failed.
65
+ /// ZSRVC0010
66
+ case serviceGetTaddressTxidsFailed(_ error: LightWalletServiceError)
64
67
  /// SimpleConnectionProvider init of Connection failed.
65
68
  /// ZSCPC0001
66
69
  case simpleConnectionProvider(_ error: Error)
@@ -342,6 +345,21 @@ public enum ZcashError: Equatable, Error {
342
345
  /// sourcery: code="ZRUST0061"
343
346
  /// ZRUST0061
344
347
  case rustPutOrchardSubtreeRoots(_ rustError: String)
348
+ /// Error from rust layer when calling TorClient.init
349
+ /// - `rustError` contains error generated by the rust layer.
350
+ /// sourcery: code="ZRUST0062"
351
+ /// ZRUST0062
352
+ case rustTorClientInit(_ rustError: String)
353
+ /// Error from rust layer when calling TorClient.get
354
+ /// - `rustError` contains error generated by the rust layer.
355
+ /// sourcery: code="ZRUST0063"
356
+ /// ZRUST0063
357
+ case rustTorClientGet(_ rustError: String)
358
+ /// Error from rust layer when calling ZcashRustBackend.transactionDataRequests
359
+ /// - `rustError` contains error generated by the rust layer.
360
+ /// sourcery: code="ZRUST0064"
361
+ /// ZRUST0064
362
+ case rustTransactionDataRequests(_ rustError: String)
345
363
  /// SQLite query failed when fetching all accounts from the database.
346
364
  /// - `sqliteError` is error produced by SQLite library.
347
365
  /// ZADAO0001
@@ -509,6 +527,9 @@ public enum ZcashError: Equatable, Error {
509
527
  /// Can't create `Recipient` because input is invalid.
510
528
  /// ZWLTP0007
511
529
  case recipientInvalidInput
530
+ /// Can't create `TexAddress` because input is invalid.
531
+ /// ZWLTP0008
532
+ case texAddressInvalidInput
512
533
  /// WalletTransactionEncoder wants to create transaction but files with sapling parameters are not present on disk.
513
534
  /// ZWLTE0001
514
535
  case walletTransEncoderCreateTransactionMissingSaplingParams
@@ -633,6 +654,7 @@ public enum ZcashError: Equatable, Error {
633
654
  case .serviceFetchUTXOsFailed: return "LightWalletService.fetchUTXOs failed."
634
655
  case .serviceBlockStreamFailed: return "LightWalletService.blockStream failed."
635
656
  case .serviceSubtreeRootsStreamFailed: return "LightWalletService.getSubtreeRoots failed."
657
+ case .serviceGetTaddressTxidsFailed: return "LightWalletService.getTaddressTxids failed."
636
658
  case .simpleConnectionProvider: return "SimpleConnectionProvider init of Connection failed."
637
659
  case .saplingParamsInvalidSpendParams: return "Downloaded file with sapling spending parameters isn't valid."
638
660
  case .saplingParamsInvalidOutputParams: return "Downloaded file with sapling output parameters isn't valid."
@@ -705,6 +727,9 @@ public enum ZcashError: Equatable, Error {
705
727
  case .rustIsSeedRelevantToAnyDerivedAccount: return "Error from rust layer when calling ZcashRustBackend.rustIsSeedRelevantToAnyDerivedAccount"
706
728
  case .rustPutOrchardSubtreeRootsAllocationProblem: return "Unable to allocate memory required to write blocks when calling ZcashRustBackend.putOrchardSubtreeRoots"
707
729
  case .rustPutOrchardSubtreeRoots: return "Error from rust layer when calling ZcashRustBackend.putOrchardSubtreeRoots"
730
+ case .rustTorClientInit: return "Error from rust layer when calling TorClient.init"
731
+ case .rustTorClientGet: return "Error from rust layer when calling TorClient.get"
732
+ case .rustTransactionDataRequests: return "Error from rust layer when calling ZcashRustBackend.transactionDataRequests"
708
733
  case .accountDAOGetAll: return "SQLite query failed when fetching all accounts from the database."
709
734
  case .accountDAOGetAllCantDecode: return "Fetched accounts from SQLite but can't decode them."
710
735
  case .accountDAOFindBy: return "SQLite query failed when seaching for accounts in the database."
@@ -757,6 +782,7 @@ public enum ZcashError: Equatable, Error {
757
782
  case .saplingAddressInvalidInput: return "Can't create `SaplingAddress` because input is invalid."
758
783
  case .unifiedAddressInvalidInput: return "Can't create `UnifiedAddress` because input is invalid."
759
784
  case .recipientInvalidInput: return "Can't create `Recipient` because input is invalid."
785
+ case .texAddressInvalidInput: return "Can't create `TexAddress` because input is invalid."
760
786
  case .walletTransEncoderCreateTransactionMissingSaplingParams: return "WalletTransactionEncoder wants to create transaction but files with sapling parameters are not present on disk."
761
787
  case .walletTransEncoderShieldFundsMissingSaplingParams: return "WalletTransactionEncoder wants to shield funds but files with sapling parameters are not present on disk."
762
788
  case .zatoshiDecode: return "Initiatilzation fo `Zatoshi` from a decoder failed."
@@ -813,6 +839,7 @@ public enum ZcashError: Equatable, Error {
813
839
  case .serviceFetchUTXOsFailed: return .serviceFetchUTXOsFailed
814
840
  case .serviceBlockStreamFailed: return .serviceBlockStreamFailed
815
841
  case .serviceSubtreeRootsStreamFailed: return .serviceSubtreeRootsStreamFailed
842
+ case .serviceGetTaddressTxidsFailed: return .serviceGetTaddressTxidsFailed
816
843
  case .simpleConnectionProvider: return .simpleConnectionProvider
817
844
  case .saplingParamsInvalidSpendParams: return .saplingParamsInvalidSpendParams
818
845
  case .saplingParamsInvalidOutputParams: return .saplingParamsInvalidOutputParams
@@ -885,6 +912,9 @@ public enum ZcashError: Equatable, Error {
885
912
  case .rustIsSeedRelevantToAnyDerivedAccount: return .rustIsSeedRelevantToAnyDerivedAccount
886
913
  case .rustPutOrchardSubtreeRootsAllocationProblem: return .rustPutOrchardSubtreeRootsAllocationProblem
887
914
  case .rustPutOrchardSubtreeRoots: return .rustPutOrchardSubtreeRoots
915
+ case .rustTorClientInit: return .rustTorClientInit
916
+ case .rustTorClientGet: return .rustTorClientGet
917
+ case .rustTransactionDataRequests: return .rustTransactionDataRequests
888
918
  case .accountDAOGetAll: return .accountDAOGetAll
889
919
  case .accountDAOGetAllCantDecode: return .accountDAOGetAllCantDecode
890
920
  case .accountDAOFindBy: return .accountDAOFindBy
@@ -937,6 +967,7 @@ public enum ZcashError: Equatable, Error {
937
967
  case .saplingAddressInvalidInput: return .saplingAddressInvalidInput
938
968
  case .unifiedAddressInvalidInput: return .unifiedAddressInvalidInput
939
969
  case .recipientInvalidInput: return .recipientInvalidInput
970
+ case .texAddressInvalidInput: return .texAddressInvalidInput
940
971
  case .walletTransEncoderCreateTransactionMissingSaplingParams: return .walletTransEncoderCreateTransactionMissingSaplingParams
941
972
  case .walletTransEncoderShieldFundsMissingSaplingParams: return .walletTransEncoderShieldFundsMissingSaplingParams
942
973
  case .zatoshiDecode: return .zatoshiDecode
@@ -1,4 +1,4 @@
1
- // Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery
1
+ // Generated using Sourcery 2.2.5 — https://github.com/krzysztofzablocki/Sourcery
2
2
  // DO NOT EDIT
3
3
 
4
4
  /*
@@ -41,6 +41,8 @@ public enum ZcashErrorCode: String {
41
41
  case serviceBlockStreamFailed = "ZSRVC0000"
42
42
  /// LightWalletService.getSubtreeRoots failed.
43
43
  case serviceSubtreeRootsStreamFailed = "ZSRVC0009"
44
+ /// LightWalletService.getTaddressTxids failed.
45
+ case serviceGetTaddressTxidsFailed = "ZSRVC0010"
44
46
  /// SimpleConnectionProvider init of Connection failed.
45
47
  case simpleConnectionProvider = "ZSCPC0001"
46
48
  /// Downloaded file with sapling spending parameters isn't valid.
@@ -185,6 +187,12 @@ public enum ZcashErrorCode: String {
185
187
  case rustPutOrchardSubtreeRootsAllocationProblem = "ZRUST0060"
186
188
  /// Error from rust layer when calling ZcashRustBackend.putOrchardSubtreeRoots
187
189
  case rustPutOrchardSubtreeRoots = "ZRUST0061"
190
+ /// Error from rust layer when calling TorClient.init
191
+ case rustTorClientInit = "ZRUST0062"
192
+ /// Error from rust layer when calling TorClient.get
193
+ case rustTorClientGet = "ZRUST0063"
194
+ /// Error from rust layer when calling ZcashRustBackend.transactionDataRequests
195
+ case rustTransactionDataRequests = "ZRUST0064"
188
196
  /// SQLite query failed when fetching all accounts from the database.
189
197
  case accountDAOGetAll = "ZADAO0001"
190
198
  /// Fetched accounts from SQLite but can't decode them.
@@ -289,6 +297,8 @@ public enum ZcashErrorCode: String {
289
297
  case unifiedAddressInvalidInput = "ZWLTP0006"
290
298
  /// Can't create `Recipient` because input is invalid.
291
299
  case recipientInvalidInput = "ZWLTP0007"
300
+ /// Can't create `TexAddress` because input is invalid.
301
+ case texAddressInvalidInput = "ZWLTP0008"
292
302
  /// WalletTransactionEncoder wants to create transaction but files with sapling parameters are not present on disk.
293
303
  case walletTransEncoderCreateTransactionMissingSaplingParams = "ZWLTE0001"
294
304
  /// WalletTransactionEncoder wants to shield funds but files with sapling parameters are not present on disk.
@@ -80,6 +80,9 @@ enum ZcashErrorDefinition {
80
80
  /// LightWalletService.getSubtreeRoots failed.
81
81
  // sourcery: code="ZSRVC0009"
82
82
  case serviceSubtreeRootsStreamFailed(_ error: LightWalletServiceError)
83
+ /// LightWalletService.getTaddressTxids failed.
84
+ // sourcery: code="ZSRVC0010"
85
+ case serviceGetTaddressTxidsFailed(_ error: LightWalletServiceError)
83
86
 
84
87
  // MARK: SQLite connection
85
88
 
@@ -367,6 +370,18 @@ enum ZcashErrorDefinition {
367
370
  /// - `rustError` contains error generated by the rust layer.
368
371
  /// sourcery: code="ZRUST0061"
369
372
  case rustPutOrchardSubtreeRoots(_ rustError: String)
373
+ /// Error from rust layer when calling TorClient.init
374
+ /// - `rustError` contains error generated by the rust layer.
375
+ /// sourcery: code="ZRUST0062"
376
+ case rustTorClientInit(_ rustError: String)
377
+ /// Error from rust layer when calling TorClient.get
378
+ /// - `rustError` contains error generated by the rust layer.
379
+ /// sourcery: code="ZRUST0063"
380
+ case rustTorClientGet(_ rustError: String)
381
+ /// Error from rust layer when calling ZcashRustBackend.transactionDataRequests
382
+ /// - `rustError` contains error generated by the rust layer.
383
+ /// sourcery: code="ZRUST0064"
384
+ case rustTransactionDataRequests(_ rustError: String)
370
385
 
371
386
  // MARK: - Account DAO
372
387
 
@@ -571,6 +586,9 @@ enum ZcashErrorDefinition {
571
586
  /// Can't create `Recipient` because input is invalid.
572
587
  // sourcery: code="ZWLTP0007"
573
588
  case recipientInvalidInput
589
+ /// Can't create `TexAddress` because input is invalid.
590
+ // sourcery: code="ZWLTP0008"
591
+ case texAddressInvalidInput
574
592
 
575
593
  // MARK: - WalletTransactionEncoder
576
594