react-native-zcash 0.5.0 → 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.
Files changed (156) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +6 -3
  3. package/android/build.gradle +5 -4
  4. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2240000.json +8 -0
  5. package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2250000.json +8 -0
  6. package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +94 -121
  7. package/ios/RNZcash.m +1 -12
  8. package/ios/RNZcash.swift +119 -152
  9. package/ios/ZCashLightClientKit/Block/Actions/Action.swift +98 -0
  10. package/ios/ZCashLightClientKit/Block/Actions/ClearAlreadyScannedBlocksAction.swift +35 -0
  11. package/ios/ZCashLightClientKit/Block/Actions/ClearCacheAction.swift +30 -0
  12. package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +67 -0
  13. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +97 -0
  14. package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +33 -0
  15. package/ios/ZCashLightClientKit/Block/Actions/MigrateLegacyCacheDBAction.swift +70 -0
  16. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +59 -0
  17. package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +48 -0
  18. package/ios/ZCashLightClientKit/Block/Actions/SaplingParamsAction.swift +33 -0
  19. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +95 -0
  20. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +55 -0
  21. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +58 -0
  22. package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +60 -0
  23. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +421 -937
  24. package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +31 -17
  25. package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
  26. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +46 -15
  27. package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +4 -15
  28. package/ios/ZCashLightClientKit/Block/FilesystemStorage/FSCompactBlockRepository.swift +4 -4
  29. package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +10 -35
  30. package/ios/ZCashLightClientKit/Block/Utils/CompactBlockProgress.swift +24 -0
  31. package/ios/ZCashLightClientKit/Block/Utils/SyncControlData.swift +25 -0
  32. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +1 -2
  33. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +2 -5
  34. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +7 -25
  35. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +40 -42
  36. package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +13 -4
  37. package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +9 -0
  38. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +7 -10
  39. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
  40. package/ios/ZCashLightClientKit/Error/ZcashError.swift +121 -12
  41. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +43 -5
  42. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +72 -6
  43. package/ios/ZCashLightClientKit/Extensions/Bool+ToData.swift +15 -0
  44. package/ios/ZCashLightClientKit/Extensions/Data+ToOtherTypes.swift +18 -0
  45. package/ios/ZCashLightClientKit/Extensions/Int+ToData.swift +15 -0
  46. package/ios/ZCashLightClientKit/Initializer.swift +47 -26
  47. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +0 -12
  48. package/ios/ZCashLightClientKit/Model/Checkpoint.swift +12 -0
  49. package/ios/ZCashLightClientKit/Model/ScanProgress.swift +29 -0
  50. package/ios/ZCashLightClientKit/Model/ScanRange.swift +31 -0
  51. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +15 -0
  52. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/compact_formats.pb.swift +150 -46
  53. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/compact_formats.proto +30 -16
  54. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +32 -6
  55. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +259 -22
  56. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +193 -7
  57. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +8 -0
  58. package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +18 -28
  59. package/ios/ZCashLightClientKit/Repository/CompactBlockRepository.swift +1 -1
  60. package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +2 -6
  61. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2092500.json +8 -0
  62. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2095000.json +8 -0
  63. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2097500.json +8 -0
  64. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2102500.json +8 -0
  65. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2105000.json +8 -0
  66. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2107500.json +8 -0
  67. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2112500.json +8 -0
  68. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2115000.json +8 -0
  69. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2117500.json +8 -0
  70. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2122500.json +8 -0
  71. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2125000.json +8 -0
  72. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2127500.json +8 -0
  73. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2132500.json +8 -0
  74. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2135000.json +8 -0
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2137500.json +8 -0
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2142500.json +8 -0
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2145000.json +8 -0
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2147500.json +8 -0
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2152500.json +8 -0
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2155000.json +8 -0
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2157500.json +8 -0
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2162500.json +8 -0
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2165000.json +8 -0
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2167500.json +8 -0
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2172500.json +8 -0
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2175000.json +8 -0
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2177500.json +8 -0
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2182500.json +8 -0
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2185000.json +8 -0
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2187500.json +8 -0
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2192500.json +8 -0
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2195000.json +8 -0
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2197500.json +8 -0
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2202500.json +8 -0
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2205000.json +8 -0
  96. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2207500.json +8 -0
  97. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2212500.json +8 -0
  98. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2215000.json +8 -0
  99. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2217500.json +8 -0
  100. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2222500.json +8 -0
  101. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2225000.json +8 -0
  102. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2227500.json +8 -0
  103. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2230000.json +8 -0
  104. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2232500.json +8 -0
  105. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2235000.json +8 -0
  106. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2237500.json +8 -0
  107. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2240000.json +8 -0
  108. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2242500.json +8 -0
  109. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2245000.json +8 -0
  110. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2247500.json +8 -0
  111. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2250000.json +8 -0
  112. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2350000.json +8 -0
  113. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2360000.json +8 -0
  114. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2370000.json +8 -0
  115. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2380000.json +8 -0
  116. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2390000.json +8 -0
  117. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2400000.json +8 -0
  118. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2410000.json +8 -0
  119. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2420000.json +8 -0
  120. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2430000.json +8 -0
  121. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2440000.json +8 -0
  122. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2450000.json +8 -0
  123. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2460000.json +8 -0
  124. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2470000.json +8 -0
  125. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2480000.json +8 -0
  126. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2490000.json +8 -0
  127. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2500000.json +8 -0
  128. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2510000.json +8 -0
  129. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2520000.json +8 -0
  130. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2530000.json +8 -0
  131. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +293 -158
  132. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +58 -64
  133. package/ios/ZCashLightClientKit/Rust/zcashlc.h +618 -512
  134. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +2 -8
  135. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +3 -15
  136. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +11 -30
  137. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +41 -50
  138. package/ios/ZCashLightClientKit/Synchronizer.swift +51 -65
  139. package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +2 -2
  140. package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +7 -7
  141. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +3 -3
  142. package/ios/ZCashLightClientKit/Utils/ZcashFileManager.swift +16 -0
  143. package/ios/libzcashlc.xcframework/Info.plist +9 -5
  144. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  145. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  146. package/lib/rnzcash.rn.js +8 -30
  147. package/lib/rnzcash.rn.js.map +1 -1
  148. package/lib/src/react-native.d.ts +2 -4
  149. package/lib/src/types.d.ts +14 -14
  150. package/package.json +1 -1
  151. package/src/react-native.ts +11 -20
  152. package/src/types.ts +20 -23
  153. package/ios/ZCashLightClientKit/Block/Utils/InternalSyncProgress.swift +0 -200
  154. package/ios/ZCashLightClientKit/Block/Validate/BlockValidator.swift +0 -51
  155. package/ios/ZCashLightClientKit/DAO/BlockDao.swift +0 -112
  156. package/ios/ZCashLightClientKit/Entity/BlockProgress.swift +0 -24
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # React Native Zcash
2
2
 
3
+ ## 0.6.0 (2023-10-10)
4
+
5
+ - added: Balances and transactions are no longer queryable and are now emitted as updates are found
6
+ - changed: Upgrade zcash-android-sdk to v2.0.1
7
+ - changed: Upgrade ZcashLightClientKit to v2.0.1
8
+ - changed: Return `raw` and `fee` with transactions
9
+ - removed: `getBalance` and `getTransactions`
10
+
11
+ Android:
12
+
13
+ - changed: Various syntax cleanups
14
+
15
+ iOS:
16
+
17
+ - fixed: Restart synchronizer on rescan
18
+ - fixed: Txid parsing
19
+
3
20
  ## 0.5.0 (2023-09-20)
4
21
 
5
22
  - changed: `deriveUnifiedAddress` will now return all three address types
package/README.md CHANGED
@@ -41,12 +41,15 @@ buildscript {
41
41
  - `stop`
42
42
  - `rescan`
43
43
  - `getLatestNetworkHeight`
44
- - `getBalance`
45
- - `getTransactions`
46
44
  - `sendToAddress`
47
45
  - `deriveUnifiedAddress`
48
46
 
49
- `Tools` contains methods that don't require a running synchronizer (with one exception, `isValidAddress` on Android which does requires any synchronizer connected to the requested network).
47
+ `Tools` contains methods that don't require a running synchronizer (with one exception, `isValidAddress` on Android which does requires any synchronizer connected to the requested network). In addition to the methods above, the following events can be subscribed to:
48
+
49
+ - `BalanceEvent`- aggregate total and available balances
50
+ - `StatusEvent` - current synchronizer activity (`STOPPED`, `DISCONNECTED`, `SYNCING`, and `SYNCED`)
51
+ - `TransactionEvent`- confirmed transactions
52
+ - `UpdateEvent` - syncing progress and network height
50
53
 
51
54
  ## Developing
52
55
 
@@ -30,6 +30,7 @@ android {
30
30
  lintOptions {
31
31
  abortOnError false
32
32
  }
33
+ namespace 'app.edge.rnzcash'
33
34
  }
34
35
 
35
36
  repositories {
@@ -48,8 +49,8 @@ dependencies {
48
49
 
49
50
  implementation 'androidx.appcompat:appcompat:1.4.1'
50
51
  implementation 'androidx.paging:paging-runtime-ktx:2.1.2'
51
- implementation 'cash.z.ecc.android:zcash-android-sdk:1.20.0-beta01'
52
- implementation 'cash.z.ecc.android:zcash-android-sdk-incubator:1.20.0-beta01'
53
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
54
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
52
+ implementation 'cash.z.ecc.android:zcash-android-sdk:2.0.1'
53
+ implementation 'cash.z.ecc.android:zcash-android-sdk-incubator:2.0.1'
54
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
55
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
55
56
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "network": "main",
3
+ "height": "2240000",
4
+ "hash": "000000000069a67c9ef4829f0b5742cbd27fdf2ae5cdec365c91c3b04d309647",
5
+ "time": 1695696312,
6
+ "saplingTree": "012d11971e09b4bbc63e78277847849e4843736aeff18a135a19ae200fe1970766012421255c867e37da2db4a3f9fbaa18084aca9816a621e2f8b3103787782c81291a018507b35ac4792682f3189c01f91f8479815c654eea791e6ab8e67f1822bcd1480163dcf884428127f8cd206316abb345d30bd4d3eeeca49145276cf7565787c83c0120900a176f78b83e32730da21f559ae18a98797d1a032c00438b6f192ac5f34a017d758ec17f8ff744218b78468d0d88259bfe1b4139eaa78b3c9268e2fdf54b1801bab9674e72ec2c946ec5ab3da729e6190d4c49bdac30b69ceee0e28d82ac464600017cd0f0d9198e1a3d140f4f40efddc64fb40d7443ba65deda6b3aa3c9a4322b0c0001f0cf9a379500ee4e71bced9683ff1e2b8483379faea159d63637febbfe5a1f1b0128a132203057c9e99c4090ff766658573ba170affa85b9237ccb5927b5ae1336012657f8a0a10c175b231460849cc1fbcff1e8bf7e668e0319f4ed13be1d3e0f5f01b19192921006a181a583899542df7bb68359c482e658142e42241d8a6c3e511e019a757058b6e952ffa49663a800cdef1d06b7a7ffd7c56e55355f2ad9f89b00140194bd4a72af1bf73b690a8129b9db24a508f7052d570f1d48657c72a0d4dc421b00000182ac7ebe2f7e9d8084a38aa8be56b1bd86292babf05f98882a6959cf9d318c110001d8ccea507421a590ed38116b834189cdc22421b4764179fa4e364803dfa66d56018cf6f5034a55fed59d1d832620916a43c756d2379e50ef9440fc4c3e7a29aa2300011619f99023a69bb647eab2d2aa1a73c3673c74bb033c3c4930eacda19e6fd93b0000000160272b134ca494b602137d89e528c751c06d3ef4a87a45f33af343c15060cc1e",
7
+ "orchardTree": "010a2edceb81a84b9fa465de87a9c3701c8a5f109dfac1bd9f7ac82eff5f291405015c75544f79cc861f1b401a8ee726adf63736f51d636609504ba99cd51ac513291f000170b0286597e58d725cd67e5845575bd4a5c6c9d91eb9d956c1b5662589ebb80100000199f76442c47c3e319a90c8e2f71ed243cf1e0115d3b962413e310f2cc4edd51c000112bcfce07875062a5ad577e2c97d67d7f6a000dc65aef03a0e520e21f12a8f1c01c114ee14f4296876cfb428aaccffa1091b13db6ffff5c1a2027c58b102b5530d00017abfa6e9773177d75a8006efe4868cbcafaf292d48e852ee06f519c5bf6667200162f63c4527bf1c0d7e4728649cbfd93cfe3d79d0834e0f5f548870d6df43671200000001dd3e61f3e1d497d923486bd000737ea0ffac885fa481316727d0d8f7fc2138100001cf3bf92f69798e68555548afcce1648add1fb2548d64fa9a1ec22a3e26e7890101e637281deb58dff0c44ba13149b784a95da1b493005efd057e6f4ac20ef5d81d000001cc2dcaa338b312112db04b435a706d63244dd435238f0aa1e9e1598d35470810012dcc4273c8a0ed2337ecf7879380a07e7d427c7f9d82e538002bd1442978402c01daf63debf5b40df902dae98dadc029f281474d190cddecef1b10653248a234150001e2bca6a8d987d668defba89dc082196a922634ed88e065c669e526bb8815ee1b000000000000"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "network": "main",
3
+ "height": "2250000",
4
+ "hash": "00000000012b3fe412a00b795a282135c30abd4b46d2bf2e7d0168e5c947ebf5",
5
+ "time": 1696451387,
6
+ "saplingTree": "01bf2a311d6302f905762ff13823d1dcff0fb9e68674059a7121f2f19b9c27882101575df84d954625511d141479c09bd602af93ed7cfca6e45cd9ac483beaf72d611a000001ee73c0c892f582faeb7690f1629ef9024b4ca8cff0bcd2226a43f896be3b275f000001cf2bbcec921924a0afd09235555b0a346d76081b45255d57ce2d691fd5c4175501f55cea93a7061448481c950ed26cfbabf9ace934177e39c2b78570385f413c35000001f45efd0bd694a391cd6d3773ae3e75c9251c68a8281469db451521bb3359004c00013f453edf224bb61a9c0b3d703fc97c5082dabde0bd78429f0798dbe8b6046f0c00018cdd71abb1799bfd51405067ea43033bf0a5253d3536b4b241e866a257b7916c01e055cec06072c1c4c7381264864f21db313d32511ef89fc09a6a60e41e0d0c2a000182ac7ebe2f7e9d8084a38aa8be56b1bd86292babf05f98882a6959cf9d318c110001d8ccea507421a590ed38116b834189cdc22421b4764179fa4e364803dfa66d56018cf6f5034a55fed59d1d832620916a43c756d2379e50ef9440fc4c3e7a29aa2300011619f99023a69bb647eab2d2aa1a73c3673c74bb033c3c4930eacda19e6fd93b0000000160272b134ca494b602137d89e528c751c06d3ef4a87a45f33af343c15060cc1e",
7
+ "orchardTree": "0108d0c8b7890fdfb38c4ba60d9c66da45cc2fb23e6698a0a0eaeb4508c5b37d39001f01c1782f10a594f13095cae37809ac3c2dd43e8029d62ef1282039429ab758ad2700010b5a16f6a11fc79b21f36c55261931cef68d6b00d4210ce90cc447e5ba656724014ffd7c660201b4c82c01b832a3153a8295197fa8945a12a79ca5d9a1aafcac1800015e0ad0bc0cd859186f456f1be54e8c6992f4cc61507b23e59d7fa3df8ec8d62b01e2aed22800fa2e21ce1ed9b89e84ef7161c6cc25f6653964bf5c4e134a030e2f0166e704cc940f0e24abfa2dfe74e94f6f1545a94c1f5114ba90c32a29cb2ec50701a0889c7b1f704d82004c6cfd6d91fe3115db60b121464b5237b49240d421cd3e015a85dd41ba7341c7d10885ea2add0b09c72b22f2fc398f0c8ba11123f27e9713000125529c4352762dea55de0005e0efadaadd1a6b55084f0ca7beac54f78c2af304000001dd3e61f3e1d497d923486bd000737ea0ffac885fa481316727d0d8f7fc2138100001cf3bf92f69798e68555548afcce1648add1fb2548d64fa9a1ec22a3e26e7890101e637281deb58dff0c44ba13149b784a95da1b493005efd057e6f4ac20ef5d81d000001cc2dcaa338b312112db04b435a706d63244dd435238f0aa1e9e1598d35470810012dcc4273c8a0ed2337ecf7879380a07e7d427c7f9d82e538002bd1442978402c01daf63debf5b40df902dae98dadc029f281474d190cddecef1b10653248a234150001e2bca6a8d987d668defba89dc082196a922634ed88e065c669e526bb8815ee1b000000000000"
8
+ }
@@ -2,6 +2,7 @@ package app.edge.rnzcash
2
2
 
3
3
  import cash.z.ecc.android.sdk.SdkSynchronizer
4
4
  import cash.z.ecc.android.sdk.Synchronizer
5
+ import cash.z.ecc.android.sdk.WalletInitMode
5
6
  import cash.z.ecc.android.sdk.exception.LightWalletException
6
7
  import cash.z.ecc.android.sdk.ext.*
7
8
  import cash.z.ecc.android.sdk.internal.*
@@ -16,10 +17,10 @@ import com.facebook.react.bridge.*
16
17
  import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
17
18
  import kotlinx.coroutines.async
18
19
  import kotlinx.coroutines.CoroutineScope
19
- import kotlinx.coroutines.cancel
20
+ import kotlinx.coroutines.Dispatchers
21
+ import kotlinx.coroutines.ExperimentalCoroutinesApi
20
22
  import kotlinx.coroutines.flow.*
21
23
  import kotlinx.coroutines.launch
22
- import kotlin.coroutines.EmptyCoroutineContext
23
24
 
24
25
  class RNZcashModule(private val reactContext: ReactApplicationContext) :
25
26
  ReactContextBaseJavaModule(reactContext) {
@@ -28,54 +29,97 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
28
29
  * Scope for anything that out-lives the synchronizer, meaning anything that can be used before
29
30
  * the synchronizer starts or after it stops. Everything else falls within the scope of the
30
31
  * synchronizer and should use `synchronizer.coroutineScope` whenever a scope is needed.
31
- *
32
- * In a real production app, we'd use the scope of the parent activity
33
32
  */
34
- var moduleScope: CoroutineScope = CoroutineScope(EmptyCoroutineContext)
35
- var synchronizerMap = mutableMapOf<String, SdkSynchronizer>()
33
+ private var moduleScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
34
+ private var synchronizerMap = mutableMapOf<String, SdkSynchronizer>()
36
35
 
37
- val networks = mapOf("mainnet" to ZcashNetwork.Mainnet, "testnet" to ZcashNetwork.Testnet)
36
+ private val networks = mapOf("mainnet" to ZcashNetwork.Mainnet, "testnet" to ZcashNetwork.Testnet)
38
37
 
39
38
  override fun getName() = "RNZcash"
40
39
 
41
40
  @ReactMethod
42
- fun initialize(seed: String, birthdayHeight: Int, alias: String, networkName: String = "mainnet", defaultHost: String = "mainnet.lightwalletd.com", defaultPort: Int = 9067, promise: Promise) =
41
+ fun initialize(seed: String, birthdayHeight: Int, alias: String, networkName: String = "mainnet", defaultHost: String = "mainnet.lightwalletd.com", defaultPort: Int = 9067, newWallet: Boolean, promise: Promise) =
43
42
  moduleScope.launch {
44
43
  promise.wrap {
45
- var network = networks.getOrDefault(networkName, ZcashNetwork.Mainnet)
46
- var endpoint = LightWalletEndpoint(defaultHost, defaultPort, true)
47
- var seedPhrase = SeedPhrase.new(seed)
44
+ val network = networks.getOrDefault(networkName, ZcashNetwork.Mainnet)
45
+ val endpoint = LightWalletEndpoint(defaultHost, defaultPort, true)
46
+ val seedPhrase = SeedPhrase.new(seed)
47
+ val initMode = if (newWallet) WalletInitMode.NewWallet else WalletInitMode.ExistingWallet
48
48
  if (!synchronizerMap.containsKey(alias)) {
49
- synchronizerMap.set(alias, Synchronizer.new(reactApplicationContext, network, alias, endpoint, seedPhrase.toByteArray(), BlockHeight.new(network, birthdayHeight.toLong())) as SdkSynchronizer)
49
+ synchronizerMap[alias] = Synchronizer.new(reactApplicationContext, network, alias, endpoint, seedPhrase.toByteArray(), BlockHeight.new(network, birthdayHeight.toLong()), initMode) as SdkSynchronizer
50
50
  }
51
51
  val wallet = getWallet(alias)
52
52
  val scope = wallet.coroutineScope
53
- wallet.processorInfo.collectWith(scope, { update ->
53
+ combine(wallet.progress, wallet.networkHeight) { progress, networkHeight ->
54
+ return@combine mapOf("progress" to progress, "networkHeight" to networkHeight)
55
+ }.collectWith(scope) { map ->
56
+ val progress = map["progress"] as PercentDecimal
57
+ var networkBlockHeight = map["networkHeight"] as BlockHeight?
58
+ if (networkBlockHeight == null) networkBlockHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
59
+
60
+ sendEvent("UpdateEvent") { args ->
61
+ args.putString("alias", alias)
62
+ args.putInt(
63
+ "scanProgress",
64
+ progress.toPercentage()
65
+ )
66
+ args.putInt("networkBlockHeight", networkBlockHeight.value.toInt())
67
+ }
68
+ }
69
+ wallet.status.collectWith(scope) { status ->
70
+ sendEvent("StatusEvent") { args ->
71
+ args.putString("alias", alias)
72
+ args.putString("name", status.toString())
73
+ }
74
+ }
75
+ wallet.transactions.collectWith(scope) { txList ->
54
76
  scope.launch {
55
- var lastDownloadedHeight = this.async { wallet.processor.downloader.getLastDownloadedHeight() }.await()
56
- if (lastDownloadedHeight == null) lastDownloadedHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
57
-
58
- var lastScannedHeight = update.lastSyncedHeight
59
- if (lastScannedHeight == null) lastScannedHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
77
+ val nativeArray = Arguments.createArray()
78
+ txList.filter { tx -> tx.transactionState == TransactionState.Confirmed }.map { tx -> launch {
79
+ val parsedTx = parseTx(wallet, tx)
80
+ nativeArray.pushMap(parsedTx)
81
+ } }.forEach { it.join() }
60
82
 
61
- var networkBlockHeight = update.networkBlockHeight
62
- if (networkBlockHeight == null) networkBlockHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
63
-
64
- sendEvent("UpdateEvent") { args ->
83
+ sendEvent("TransactionEvent") { args ->
65
84
  args.putString("alias", alias)
66
- args.putInt("lastDownloadedHeight", lastDownloadedHeight.value.toInt())
67
- args.putInt("lastScannedHeight", lastScannedHeight.value.toInt())
68
- args.putInt("scanProgress", wallet.processor.progress.value.toPercentage())
69
- args.putInt("networkBlockHeight", networkBlockHeight.value.toInt())
85
+ args.putArray(
86
+ "transactions",
87
+ nativeArray
88
+ )
70
89
  }
71
90
  }
72
- })
73
- wallet.status.collectWith(scope, { status ->
74
- sendEvent("StatusEvent") { args ->
91
+ }
92
+ combine(wallet.transparentBalances, wallet.saplingBalances, wallet.orchardBalances) { transparentBalances, saplingBalances, orchardBalances ->
93
+ return@combine mapOf("transparentBalances" to transparentBalances, "saplingBalances" to saplingBalances, "orchardBalances" to orchardBalances)
94
+ }.collectWith(scope) { map ->
95
+ val transparentBalances = map["transparentBalances"]
96
+ val saplingBalances = map["saplingBalances"]
97
+ val orchardBalances = map["orchardBalances"]
98
+
99
+ var availableZatoshi = Zatoshi(0L)
100
+ var totalZatoshi = Zatoshi(0L)
101
+
102
+ availableZatoshi = availableZatoshi.plus(transparentBalances?.available ?: Zatoshi(0L))
103
+ totalZatoshi = totalZatoshi.plus(transparentBalances?.total ?: Zatoshi(0L))
104
+
105
+ availableZatoshi = availableZatoshi.plus(saplingBalances?.available ?: Zatoshi(0L))
106
+ totalZatoshi = totalZatoshi.plus(saplingBalances?.total ?: Zatoshi(0L))
107
+
108
+ availableZatoshi = availableZatoshi.plus(orchardBalances?.available ?: Zatoshi(0L))
109
+ totalZatoshi = totalZatoshi.plus(orchardBalances?.total ?: Zatoshi(0L))
110
+
111
+ sendEvent("BalanceEvent") { args ->
75
112
  args.putString("alias", alias)
76
- args.putString("name", status.toString())
113
+ args.putString(
114
+ "totalZatoshi",
115
+ totalZatoshi.value.toString()
116
+ )
117
+ args.putString(
118
+ "availableZatoshi",
119
+ availableZatoshi.value.toString()
120
+ )
77
121
  }
78
- })
122
+ }
79
123
  return@wrap null
80
124
  }
81
125
  }
@@ -88,37 +132,19 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
88
132
  promise.resolve(null)
89
133
  }
90
134
 
91
- fun inRange(tx: TransactionOverview, first: Int, last: Int): Boolean {
92
- if (tx.minedHeight != null && tx.minedHeight!!.value >= first.toLong() && tx.minedHeight!!.value <= last.toLong()) {
93
- return true
94
- }
95
- return false
96
- }
97
-
98
- suspend fun collectTxs(wallet: SdkSynchronizer, limit: Int): List<TransactionOverview> {
99
- val allTxs = mutableListOf<TransactionOverview>()
100
- val job = wallet.coroutineScope.launch {
101
- wallet.transactions.collect { txList ->
102
- txList.forEach { tx ->
103
- allTxs.add(tx)
104
- }
105
- if (allTxs.size == limit) {
106
- cancel()
107
- }
108
- }
109
- }
110
- job.join()
111
-
112
- return allTxs
113
- }
114
-
115
- suspend fun parseTx(wallet: SdkSynchronizer, tx: TransactionOverview): WritableMap {
135
+ private suspend fun parseTx(wallet: SdkSynchronizer, tx: TransactionOverview): WritableMap {
116
136
  val map = Arguments.createMap()
117
137
  val job = wallet.coroutineScope.launch {
118
138
  map.putString("value", tx.netValue.value.toString())
139
+ if (tx.feePaid != null) {
140
+ map.putString("fee", tx.feePaid!!.value.toString())
141
+ }
119
142
  map.putInt("minedHeight", tx.minedHeight!!.value.toInt())
120
- map.putInt("blockTimeInSeconds", tx.blockTimeEpochSeconds.toInt())
143
+ map.putInt("blockTimeInSeconds", tx.blockTimeEpochSeconds!!.toInt())
121
144
  map.putString("rawTransactionId", tx.rawId.byteArray.toHexReversed())
145
+ if (tx.raw != null) {
146
+ map.putString("raw", tx.raw!!.byteArray.toHex())
147
+ }
122
148
  if (tx.isSentTransaction) {
123
149
  val recipient = wallet.getRecipients(tx).first()
124
150
  if (recipient is TransactionRecipient.Address) {
@@ -136,44 +162,20 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
136
162
  return map
137
163
  }
138
164
 
139
- @ReactMethod
140
- fun getTransactions(alias: String, first: Int, last: Int, promise: Promise) {
141
- val wallet = getWallet(alias)
142
-
143
- wallet.coroutineScope.launch {
144
- val numTxs = async { wallet.getTransactionCount() }.await()
145
- val nativeArray = Arguments.createArray()
146
- if (numTxs == 0) {
147
- promise.resolve(nativeArray)
148
- return@launch
149
- }
150
-
151
- val allTxs = async { collectTxs(wallet, numTxs) }.await()
152
- val filteredTxs = allTxs.filter { tx -> inRange(tx, first, last) }
153
-
154
- filteredTxs.map { tx -> launch {
155
- val parsedTx = parseTx(wallet, tx)
156
- nativeArray.pushMap(parsedTx)
157
- } }.forEach { it.join() }
158
-
159
- promise.resolve(nativeArray)
160
- }
161
- }
162
-
163
165
  @ReactMethod
164
166
  fun rescan(alias: String, promise: Promise) {
165
167
  val wallet = getWallet(alias)
166
168
  wallet.coroutineScope.launch {
167
- wallet.coroutineScope.async { wallet.rewindToNearestHeight(wallet.latestBirthdayHeight, true) }.await()
169
+ wallet.coroutineScope.async { wallet.rewindToNearestHeight(wallet.latestBirthdayHeight) }.await()
168
170
  promise.resolve(null)
169
171
  }
170
172
  }
171
173
 
172
174
  @ReactMethod
173
175
  fun deriveViewingKey(seed: String, network: String = "mainnet", promise: Promise) {
174
- var seedPhrase = SeedPhrase.new(seed)
176
+ val seedPhrase = SeedPhrase.new(seed)
175
177
  moduleScope.launch {
176
- var keys = moduleScope.async { DerivationTool.getInstance().deriveUnifiedFullViewingKeys(seedPhrase.toByteArray(), networks.getOrDefault(network, ZcashNetwork.Mainnet), DerivationTool.DEFAULT_NUMBER_OF_ACCOUNTS)[0] }.await()
178
+ val keys = moduleScope.async { DerivationTool.getInstance().deriveUnifiedFullViewingKeys(seedPhrase.toByteArray(), networks.getOrDefault(network, ZcashNetwork.Mainnet), DerivationTool.DEFAULT_NUMBER_OF_ACCOUNTS)[0] }.await()
177
179
  promise.resolve(keys.encoding)
178
180
  }
179
181
  }
@@ -192,8 +194,8 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
192
194
  fun getBirthdayHeight(host: String, port: Int, promise: Promise) {
193
195
  moduleScope.launch {
194
196
  promise.wrap {
195
- var endpoint = LightWalletEndpoint(host, port, true)
196
- var lightwalletService = LightWalletClient.new(reactApplicationContext, endpoint)
197
+ val endpoint = LightWalletEndpoint(host, port, true)
198
+ val lightwalletService = LightWalletClient.new(reactApplicationContext, endpoint)
197
199
  return@wrap when (val response = lightwalletService.getLatestBlockHeight()) {
198
200
  is Response.Success -> {
199
201
  response.result.value.toInt()
@@ -211,32 +213,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
211
213
  }
212
214
  }
213
215
 
214
- @ReactMethod
215
- fun getBalance(alias: String, promise: Promise) {
216
- val wallet = getWallet(alias)
217
- var availableZatoshi = Zatoshi(0L)
218
- var totalZatoshi = Zatoshi(0L)
219
-
220
- wallet.coroutineScope.launch {
221
- wallet.coroutineScope.async { wallet.refreshAllBalances() }.await()
222
-
223
- val transparentBalances = wallet.transparentBalances.value
224
- availableZatoshi = availableZatoshi.plus(transparentBalances?.available ?: Zatoshi(0L))
225
- totalZatoshi = totalZatoshi.plus(transparentBalances?.total ?: Zatoshi(0L))
226
- val saplingBalances = wallet.saplingBalances.value
227
- availableZatoshi = availableZatoshi.plus(saplingBalances?.available ?: Zatoshi(0L))
228
- totalZatoshi = totalZatoshi.plus(saplingBalances?.total ?: Zatoshi(0L))
229
- val orchardBalances = wallet.orchardBalances.value
230
- availableZatoshi = availableZatoshi.plus(orchardBalances?.available ?: Zatoshi(0L))
231
- totalZatoshi = totalZatoshi.plus(orchardBalances?.total ?: Zatoshi(0L))
232
-
233
- val map = Arguments.createMap()
234
- map.putString("totalZatoshi", totalZatoshi.value.toString())
235
- map.putString("availableZatoshi", availableZatoshi.value.toString())
236
- promise.resolve(map)
237
- }
238
- }
239
-
216
+ @OptIn(ExperimentalCoroutinesApi::class)
240
217
  @ReactMethod
241
218
  fun sendToAddress(
242
219
  alias: String,
@@ -248,7 +225,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
248
225
  ) {
249
226
  val wallet = getWallet(alias)
250
227
  wallet.coroutineScope.launch {
251
- var seedPhrase = SeedPhrase.new(seed)
228
+ val seedPhrase = SeedPhrase.new(seed)
252
229
  val usk = wallet.coroutineScope.async { DerivationTool.getInstance().deriveUnifiedSpendingKey(seedPhrase.toByteArray(), wallet.network, Account.DEFAULT) }.await()
253
230
  try {
254
231
  val internalId = wallet.sendToAddress(
@@ -257,9 +234,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
257
234
  toAddress,
258
235
  memo,
259
236
  )
260
- val tx = wallet.coroutineScope.async { wallet.transactions.flatMapConcat { list -> flowOf(*list.toTypedArray()) } }.await().firstOrNull { item -> item.id == internalId }
261
- if (tx == null) throw Exception("transaction failed")
262
-
237
+ val tx = wallet.coroutineScope.async { wallet.transactions.first().first() }.await()
263
238
  val map = Arguments.createMap()
264
239
  map.putString("txId", tx.rawId.byteArray.toHexReversed())
265
240
  if (tx.raw != null) map.putString("raw", tx.raw?.byteArray?.toHex())
@@ -278,7 +253,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
278
253
  fun deriveUnifiedAddress(alias: String, promise: Promise) {
279
254
  val wallet = getWallet(alias)
280
255
  wallet.coroutineScope.launch {
281
- var unifiedAddress = wallet.coroutineScope.async { wallet.getUnifiedAddress(Account(0)) }.await()
256
+ val unifiedAddress = wallet.coroutineScope.async { wallet.getUnifiedAddress(Account(0)) }.await()
282
257
  val saplingAddress = wallet.coroutineScope.async { wallet.getSaplingAddress(Account(0)) }.await()
283
258
  val transparentAddress = wallet.coroutineScope.async { wallet.getTransparentAddress(Account(0)) }.await()
284
259
 
@@ -315,9 +290,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
315
290
  * Retrieve wallet object from synchronizer map
316
291
  */
317
292
  private fun getWallet(alias: String): SdkSynchronizer {
318
- val wallet = synchronizerMap.get(alias)
319
- if (wallet == null) throw Exception("Wallet not found")
320
- return wallet
293
+ return synchronizerMap[alias] ?: throw Exception("Wallet not found")
321
294
  }
322
295
 
323
296
  /**
@@ -339,7 +312,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
339
312
  .emit(eventName, args)
340
313
  }
341
314
 
342
- inline fun ByteArray.toHexReversed(): String {
315
+ private fun ByteArray.toHexReversed(): String {
343
316
  val sb = StringBuilder(size * 2)
344
317
  var i = size - 1
345
318
  while (i >= 0)
package/ios/RNZcash.m CHANGED
@@ -10,6 +10,7 @@ RCT_EXTERN_METHOD(initialize:(NSString *)seed
10
10
  :(NSString *)networkName
11
11
  :(NSString *)defaultHost
12
12
  :(NSInteger *)defaultPort
13
+ :(BOOL *)newWallet
13
14
  resolver:(RCTPromiseResolveBlock)resolve
14
15
  rejecter:(RCTPromiseRejectBlock)reject
15
16
  )
@@ -44,18 +45,6 @@ resolver:(RCTPromiseResolveBlock)resolve
44
45
  rejecter:(RCTPromiseRejectBlock)reject
45
46
  )
46
47
 
47
- RCT_EXTERN_METHOD(getTransactions:(NSString *)alias
48
- :(NSInteger *)first
49
- :(NSInteger *)last
50
- resolver:(RCTPromiseResolveBlock)resolve
51
- rejecter:(RCTPromiseRejectBlock)reject
52
- )
53
-
54
- RCT_EXTERN_METHOD(getBalance:(NSString *)alias
55
- resolver:(RCTPromiseResolveBlock)resolve
56
- rejecter:(RCTPromiseRejectBlock)reject
57
- )
58
-
59
48
  RCT_EXTERN_METHOD(rescan:(NSString *)alias
60
49
  resolver:(RCTPromiseResolveBlock)resolve
61
50
  rejecter:(RCTPromiseRejectBlock)reject