react-native-zcash 0.5.0 → 0.6.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 (157) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +7 -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 +221 -169
  7. package/android/src/main/java/app/edge/rnzcash/RNZcashPackage.kt +1 -2
  8. package/ios/RNZcash.m +5 -8
  9. package/ios/RNZcash.swift +177 -137
  10. package/ios/ZCashLightClientKit/Block/Actions/Action.swift +98 -0
  11. package/ios/ZCashLightClientKit/Block/Actions/ClearAlreadyScannedBlocksAction.swift +35 -0
  12. package/ios/ZCashLightClientKit/Block/Actions/ClearCacheAction.swift +30 -0
  13. package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +67 -0
  14. package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +97 -0
  15. package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +33 -0
  16. package/ios/ZCashLightClientKit/Block/Actions/MigrateLegacyCacheDBAction.swift +70 -0
  17. package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +59 -0
  18. package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +48 -0
  19. package/ios/ZCashLightClientKit/Block/Actions/SaplingParamsAction.swift +33 -0
  20. package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +95 -0
  21. package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +55 -0
  22. package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +58 -0
  23. package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +60 -0
  24. package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +421 -937
  25. package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +31 -17
  26. package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
  27. package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +46 -15
  28. package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +4 -15
  29. package/ios/ZCashLightClientKit/Block/FilesystemStorage/FSCompactBlockRepository.swift +4 -4
  30. package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +10 -35
  31. package/ios/ZCashLightClientKit/Block/Utils/CompactBlockProgress.swift +24 -0
  32. package/ios/ZCashLightClientKit/Block/Utils/SyncControlData.swift +25 -0
  33. package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +1 -2
  34. package/ios/ZCashLightClientKit/CombineSynchronizer.swift +2 -5
  35. package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +7 -25
  36. package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +40 -42
  37. package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +13 -4
  38. package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +9 -0
  39. package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +7 -10
  40. package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
  41. package/ios/ZCashLightClientKit/Error/ZcashError.swift +121 -12
  42. package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +43 -5
  43. package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +72 -6
  44. package/ios/ZCashLightClientKit/Extensions/Bool+ToData.swift +15 -0
  45. package/ios/ZCashLightClientKit/Extensions/Data+ToOtherTypes.swift +18 -0
  46. package/ios/ZCashLightClientKit/Extensions/Int+ToData.swift +15 -0
  47. package/ios/ZCashLightClientKit/Initializer.swift +47 -26
  48. package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +0 -12
  49. package/ios/ZCashLightClientKit/Model/Checkpoint.swift +12 -0
  50. package/ios/ZCashLightClientKit/Model/ScanProgress.swift +29 -0
  51. package/ios/ZCashLightClientKit/Model/ScanRange.swift +31 -0
  52. package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +15 -0
  53. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/compact_formats.pb.swift +150 -46
  54. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/compact_formats.proto +30 -16
  55. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +32 -6
  56. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +259 -22
  57. package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +193 -7
  58. package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +8 -0
  59. package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +18 -28
  60. package/ios/ZCashLightClientKit/Repository/CompactBlockRepository.swift +1 -1
  61. package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +2 -6
  62. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2092500.json +8 -0
  63. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2095000.json +8 -0
  64. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2097500.json +8 -0
  65. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2102500.json +8 -0
  66. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2105000.json +8 -0
  67. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2107500.json +8 -0
  68. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2112500.json +8 -0
  69. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2115000.json +8 -0
  70. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2117500.json +8 -0
  71. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2122500.json +8 -0
  72. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2125000.json +8 -0
  73. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2127500.json +8 -0
  74. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2132500.json +8 -0
  75. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2135000.json +8 -0
  76. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2137500.json +8 -0
  77. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2142500.json +8 -0
  78. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2145000.json +8 -0
  79. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2147500.json +8 -0
  80. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2152500.json +8 -0
  81. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2155000.json +8 -0
  82. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2157500.json +8 -0
  83. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2162500.json +8 -0
  84. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2165000.json +8 -0
  85. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2167500.json +8 -0
  86. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2172500.json +8 -0
  87. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2175000.json +8 -0
  88. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2177500.json +8 -0
  89. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2182500.json +8 -0
  90. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2185000.json +8 -0
  91. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2187500.json +8 -0
  92. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2192500.json +8 -0
  93. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2195000.json +8 -0
  94. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2197500.json +8 -0
  95. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2202500.json +8 -0
  96. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2205000.json +8 -0
  97. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2207500.json +8 -0
  98. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2212500.json +8 -0
  99. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2215000.json +8 -0
  100. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2217500.json +8 -0
  101. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2222500.json +8 -0
  102. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2225000.json +8 -0
  103. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2227500.json +8 -0
  104. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2230000.json +8 -0
  105. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2232500.json +8 -0
  106. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2235000.json +8 -0
  107. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2237500.json +8 -0
  108. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2240000.json +8 -0
  109. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2242500.json +8 -0
  110. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2245000.json +8 -0
  111. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2247500.json +8 -0
  112. package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2250000.json +8 -0
  113. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2350000.json +8 -0
  114. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2360000.json +8 -0
  115. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2370000.json +8 -0
  116. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2380000.json +8 -0
  117. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2390000.json +8 -0
  118. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2400000.json +8 -0
  119. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2410000.json +8 -0
  120. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2420000.json +8 -0
  121. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2430000.json +8 -0
  122. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2440000.json +8 -0
  123. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2450000.json +8 -0
  124. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2460000.json +8 -0
  125. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2470000.json +8 -0
  126. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2480000.json +8 -0
  127. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2490000.json +8 -0
  128. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2500000.json +8 -0
  129. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2510000.json +8 -0
  130. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2520000.json +8 -0
  131. package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2530000.json +8 -0
  132. package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +293 -158
  133. package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +58 -64
  134. package/ios/ZCashLightClientKit/Rust/zcashlc.h +618 -512
  135. package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +2 -8
  136. package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +3 -15
  137. package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +11 -30
  138. package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +41 -50
  139. package/ios/ZCashLightClientKit/Synchronizer.swift +51 -65
  140. package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +2 -2
  141. package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +7 -7
  142. package/ios/ZCashLightClientKit/Utils/OSLogger.swift +3 -3
  143. package/ios/ZCashLightClientKit/Utils/ZcashFileManager.swift +16 -0
  144. package/ios/libzcashlc.xcframework/Info.plist +4 -0
  145. package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
  146. package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
  147. package/lib/rnzcash.rn.js +29 -29
  148. package/lib/rnzcash.rn.js.map +1 -1
  149. package/lib/src/react-native.d.ts +5 -5
  150. package/lib/src/types.d.ts +27 -15
  151. package/package.json +2 -1
  152. package/src/react-native.ts +40 -21
  153. package/src/types.ts +36 -24
  154. package/ios/ZCashLightClientKit/Block/Utils/InternalSyncProgress.swift +0 -200
  155. package/ios/ZCashLightClientKit/Block/Validate/BlockValidator.swift +0 -51
  156. package/ios/ZCashLightClientKit/DAO/BlockDao.swift +0 -112
  157. package/ios/ZCashLightClientKit/Entity/BlockProgress.swift +0 -24
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # React Native Zcash
2
2
 
3
+ ## 0.6.1 (2023-10-11)
4
+
5
+ - added: Add `shieldFunds` support
6
+ - changed: Package now exports types
7
+ - deprecated: Balance event fields `availableZatoshi` and `totalZatoshi`
8
+
9
+ Android
10
+
11
+ - changed: Various syntax cleanups
12
+ - fixed: Transactions event now returns confirmed and pending (<10 confirmations) transactions
13
+
14
+ ## 0.6.0 (2023-10-10)
15
+
16
+ - added: Balances and transactions are no longer queryable and are now emitted as updates are found
17
+ - changed: Upgrade zcash-android-sdk to v2.0.1
18
+ - changed: Upgrade ZcashLightClientKit to v2.0.1
19
+ - changed: Return `raw` and `fee` with transactions
20
+ - removed: `getBalance` and `getTransactions`
21
+
22
+ Android:
23
+
24
+ - changed: Various syntax cleanups
25
+
26
+ iOS:
27
+
28
+ - fixed: Restart synchronizer on rescan
29
+ - fixed: Txid parsing
30
+
3
31
  ## 0.5.0 (2023-09-20)
4
32
 
5
33
  - changed: `deriveUnifiedAddress` will now return all three address types
package/README.md CHANGED
@@ -41,12 +41,16 @@ buildscript {
41
41
  - `stop`
42
42
  - `rescan`
43
43
  - `getLatestNetworkHeight`
44
- - `getBalance`
45
- - `getTransactions`
46
44
  - `sendToAddress`
45
+ - `shieldFunds`
47
46
  - `deriveUnifiedAddress`
48
47
 
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).
48
+ `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:
49
+
50
+ - `BalanceEvent`- available and total transparent and shielded balances
51
+ - `StatusEvent` - current synchronizer activity (`STOPPED`, `DISCONNECTED`, `SYNCING`, and `SYNCED`)
52
+ - `TransactionEvent`- confirmed transactions
53
+ - `UpdateEvent` - syncing progress and network height
50
54
 
51
55
  ## Developing
52
56
 
@@ -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.*
@@ -14,166 +15,197 @@ import co.electriccoin.lightwallet.client.model.Response
14
15
  import co.electriccoin.lightwallet.client.new
15
16
  import com.facebook.react.bridge.*
16
17
  import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
17
- import kotlinx.coroutines.async
18
18
  import kotlinx.coroutines.CoroutineScope
19
- import kotlinx.coroutines.cancel
19
+ import kotlinx.coroutines.Dispatchers
20
+ import kotlinx.coroutines.async
20
21
  import kotlinx.coroutines.flow.*
21
22
  import kotlinx.coroutines.launch
22
- import kotlin.coroutines.EmptyCoroutineContext
23
23
 
24
24
  class RNZcashModule(private val reactContext: ReactApplicationContext) :
25
25
  ReactContextBaseJavaModule(reactContext) {
26
-
27
26
  /**
28
27
  * Scope for anything that out-lives the synchronizer, meaning anything that can be used before
29
28
  * the synchronizer starts or after it stops. Everything else falls within the scope of the
30
29
  * 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
30
  */
34
- var moduleScope: CoroutineScope = CoroutineScope(EmptyCoroutineContext)
35
- var synchronizerMap = mutableMapOf<String, SdkSynchronizer>()
31
+ private var moduleScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
32
+ private var synchronizerMap = mutableMapOf<String, SdkSynchronizer>()
36
33
 
37
- val networks = mapOf("mainnet" to ZcashNetwork.Mainnet, "testnet" to ZcashNetwork.Testnet)
34
+ private val networks = mapOf("mainnet" to ZcashNetwork.Mainnet, "testnet" to ZcashNetwork.Testnet)
38
35
 
39
36
  override fun getName() = "RNZcash"
40
37
 
41
38
  @ReactMethod
42
- fun initialize(seed: String, birthdayHeight: Int, alias: String, networkName: String = "mainnet", defaultHost: String = "mainnet.lightwalletd.com", defaultPort: Int = 9067, promise: Promise) =
43
- moduleScope.launch {
44
- promise.wrap {
45
- var network = networks.getOrDefault(networkName, ZcashNetwork.Mainnet)
46
- var endpoint = LightWalletEndpoint(defaultHost, defaultPort, true)
47
- var seedPhrase = SeedPhrase.new(seed)
48
- if (!synchronizerMap.containsKey(alias)) {
49
- synchronizerMap.set(alias, Synchronizer.new(reactApplicationContext, network, alias, endpoint, seedPhrase.toByteArray(), BlockHeight.new(network, birthdayHeight.toLong())) as SdkSynchronizer)
39
+ fun initialize(
40
+ seed: String,
41
+ birthdayHeight: Int,
42
+ alias: String,
43
+ networkName: String = "mainnet",
44
+ defaultHost: String = "mainnet.lightwalletd.com",
45
+ defaultPort: Int = 9067,
46
+ newWallet: Boolean,
47
+ promise: Promise,
48
+ ) = moduleScope.launch {
49
+ promise.wrap {
50
+ val network = networks.getOrDefault(networkName, ZcashNetwork.Mainnet)
51
+ val endpoint = LightWalletEndpoint(defaultHost, defaultPort, true)
52
+ val seedPhrase = SeedPhrase.new(seed)
53
+ val initMode = if (newWallet) WalletInitMode.NewWallet else WalletInitMode.ExistingWallet
54
+ if (!synchronizerMap.containsKey(alias)) {
55
+ synchronizerMap[alias] =
56
+ Synchronizer.new(
57
+ reactApplicationContext, network, alias, endpoint, seedPhrase.toByteArray(),
58
+ BlockHeight.new(network, birthdayHeight.toLong()), initMode,
59
+ ) as SdkSynchronizer
60
+ }
61
+ val wallet = getWallet(alias)
62
+ val scope = wallet.coroutineScope
63
+ combine(wallet.progress, wallet.networkHeight) { progress, networkHeight ->
64
+ return@combine mapOf("progress" to progress, "networkHeight" to networkHeight)
65
+ }.collectWith(scope) { map ->
66
+ val progress = map["progress"] as PercentDecimal
67
+ var networkBlockHeight = map["networkHeight"] as BlockHeight?
68
+ if (networkBlockHeight == null) networkBlockHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
69
+
70
+ sendEvent("UpdateEvent") { args ->
71
+ args.putString("alias", alias)
72
+ args.putInt(
73
+ "scanProgress",
74
+ progress.toPercentage(),
75
+ )
76
+ args.putInt("networkBlockHeight", networkBlockHeight.value.toInt())
50
77
  }
51
- val wallet = getWallet(alias)
52
- val scope = wallet.coroutineScope
53
- wallet.processorInfo.collectWith(scope, { update ->
54
- 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())
60
-
61
- var networkBlockHeight = update.networkBlockHeight
62
- if (networkBlockHeight == null) networkBlockHeight = BlockHeight.new(wallet.network, birthdayHeight.toLong())
63
-
64
- sendEvent("UpdateEvent") { args ->
65
- 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())
78
+ }
79
+ wallet.status.collectWith(scope) { status ->
80
+ sendEvent("StatusEvent") { args ->
81
+ args.putString("alias", alias)
82
+ args.putString("name", status.toString())
83
+ }
84
+ }
85
+ wallet.transactions.collectWith(scope) { txList ->
86
+ scope.launch {
87
+ val nativeArray = Arguments.createArray()
88
+ txList.filter { tx -> tx.transactionState != TransactionState.Expired }.map { tx ->
89
+ launch {
90
+ val parsedTx = parseTx(wallet, tx)
91
+ nativeArray.pushMap(parsedTx)
70
92
  }
71
- }
72
- })
73
- wallet.status.collectWith(scope, { status ->
74
- sendEvent("StatusEvent") { args ->
93
+ }.forEach { it.join() }
94
+
95
+ sendEvent("TransactionEvent") { args ->
75
96
  args.putString("alias", alias)
76
- args.putString("name", status.toString())
97
+ args.putArray(
98
+ "transactions",
99
+ nativeArray,
100
+ )
77
101
  }
78
- })
79
- return@wrap null
102
+ }
80
103
  }
104
+ combine(
105
+ wallet.transparentBalances,
106
+ wallet.saplingBalances,
107
+ ) { transparentBalances, saplingBalances ->
108
+ return@combine mapOf(
109
+ "transparentBalances" to transparentBalances,
110
+ "saplingBalances" to saplingBalances,
111
+ )
112
+ }.collectWith(scope) { map ->
113
+ val transparentBalances = map["transparentBalances"]
114
+ val saplingBalances = map["saplingBalances"]
115
+
116
+ val transparentAvailableZatoshi = transparentBalances?.available ?: Zatoshi(0L)
117
+ val transparentTotalZatoshi = transparentBalances?.total ?: Zatoshi(0L)
118
+
119
+ val saplingAvailableZatoshi = saplingBalances?.available ?: Zatoshi(0L)
120
+ val saplingTotalZatoshi = saplingBalances?.total ?: Zatoshi(0L)
121
+
122
+ sendEvent("BalanceEvent") { args ->
123
+ args.putString("alias", alias)
124
+ args.putString("transparentAvailableZatoshi", transparentAvailableZatoshi.value.toString())
125
+ args.putString("transparentTotalZatoshi", transparentTotalZatoshi.value.toString())
126
+ args.putString("saplingAvailableZatoshi", saplingAvailableZatoshi.value.toString())
127
+ args.putString("saplingTotalZatoshi", saplingTotalZatoshi.value.toString())
128
+ }
129
+ }
130
+ return@wrap null
81
131
  }
132
+ }
82
133
 
83
134
  @ReactMethod
84
- fun stop(alias: String, promise: Promise) {
135
+ fun stop(
136
+ alias: String,
137
+ promise: Promise,
138
+ ) {
85
139
  val wallet = getWallet(alias)
86
140
  wallet.close()
87
141
  synchronizerMap.remove(alias)
88
142
  promise.resolve(null)
89
143
  }
90
144
 
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)
145
+ private suspend fun parseTx(
146
+ wallet: SdkSynchronizer,
147
+ tx: TransactionOverview,
148
+ ): WritableMap {
149
+ val map = Arguments.createMap()
150
+ val job =
151
+ wallet.coroutineScope.launch {
152
+ map.putString("value", tx.netValue.value.toString())
153
+ if (tx.feePaid != null) {
154
+ map.putString("fee", tx.feePaid!!.value.toString())
104
155
  }
105
- if (allTxs.size == limit) {
106
- cancel()
156
+ map.putInt("minedHeight", tx.minedHeight?.value?.toInt() ?: 0)
157
+ map.putInt("blockTimeInSeconds", tx.blockTimeEpochSeconds?.toInt() ?: 0)
158
+ map.putString("rawTransactionId", tx.rawId.byteArray.toHexReversed())
159
+ if (tx.raw != null) {
160
+ map.putString("raw", tx.raw!!.byteArray.toHex())
107
161
  }
108
- }
109
- }
110
- job.join()
111
-
112
- return allTxs
113
- }
114
-
115
- suspend fun parseTx(wallet: SdkSynchronizer, tx: TransactionOverview): WritableMap {
116
- val map = Arguments.createMap()
117
- val job = wallet.coroutineScope.launch {
118
- map.putString("value", tx.netValue.value.toString())
119
- map.putInt("minedHeight", tx.minedHeight!!.value.toInt())
120
- map.putInt("blockTimeInSeconds", tx.blockTimeEpochSeconds.toInt())
121
- map.putString("rawTransactionId", tx.rawId.byteArray.toHexReversed())
122
- if (tx.isSentTransaction) {
123
- val recipient = wallet.getRecipients(tx).first()
124
- if (recipient is TransactionRecipient.Address) {
125
- map.putString("toAddress", recipient.addressValue)
162
+ if (tx.isSentTransaction) {
163
+ try {
164
+ val recipient = wallet.getRecipients(tx).first()
165
+ if (recipient is TransactionRecipient.Address) {
166
+ map.putString("toAddress", recipient.addressValue)
167
+ }
168
+ } catch (t: Throwable) {
169
+ // Error is OK. SDK limitation means we cannot find recipient for shielding transactions
170
+ }
171
+ }
172
+ if (tx.memoCount > 0) {
173
+ val memos = wallet.getMemos(tx).take(tx.memoCount).toList()
174
+ map.putArray("memos", Arguments.fromList(memos))
175
+ } else {
176
+ map.putArray("memos", Arguments.createArray())
126
177
  }
127
178
  }
128
- if (tx.memoCount > 0) {
129
- val memos = wallet.getMemos(tx).take(tx.memoCount).toList()
130
- map.putArray("memos", Arguments.fromList(memos))
131
- } else {
132
- map.putArray("memos", Arguments.createArray())
133
- }
134
- }
135
179
  job.join()
136
180
  return map
137
181
  }
138
182
 
139
183
  @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
- @ReactMethod
164
- fun rescan(alias: String, promise: Promise) {
184
+ fun rescan(
185
+ alias: String,
186
+ promise: Promise,
187
+ ) {
165
188
  val wallet = getWallet(alias)
166
189
  wallet.coroutineScope.launch {
167
- wallet.coroutineScope.async { wallet.rewindToNearestHeight(wallet.latestBirthdayHeight, true) }.await()
190
+ wallet.rewindToNearestHeight(wallet.latestBirthdayHeight)
168
191
  promise.resolve(null)
169
192
  }
170
193
  }
171
194
 
172
195
  @ReactMethod
173
- fun deriveViewingKey(seed: String, network: String = "mainnet", promise: Promise) {
174
- var seedPhrase = SeedPhrase.new(seed)
196
+ fun deriveViewingKey(
197
+ seed: String,
198
+ network: String = "mainnet",
199
+ promise: Promise,
200
+ ) {
201
+ val seedPhrase = SeedPhrase.new(seed)
175
202
  moduleScope.launch {
176
- var keys = moduleScope.async { DerivationTool.getInstance().deriveUnifiedFullViewingKeys(seedPhrase.toByteArray(), networks.getOrDefault(network, ZcashNetwork.Mainnet), DerivationTool.DEFAULT_NUMBER_OF_ACCOUNTS)[0] }.await()
203
+ val keys =
204
+ DerivationTool.getInstance().deriveUnifiedFullViewingKeys(
205
+ seedPhrase.toByteArray(),
206
+ networks.getOrDefault(network, ZcashNetwork.Mainnet),
207
+ DerivationTool.DEFAULT_NUMBER_OF_ACCOUNTS,
208
+ )[0]
177
209
  promise.resolve(keys.encoding)
178
210
  }
179
211
  }
@@ -183,17 +215,24 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
183
215
  //
184
216
 
185
217
  @ReactMethod
186
- fun getLatestNetworkHeight(alias: String, promise: Promise) = promise.wrap {
218
+ fun getLatestNetworkHeight(
219
+ alias: String,
220
+ promise: Promise,
221
+ ) = promise.wrap {
187
222
  val wallet = getWallet(alias)
188
223
  return@wrap wallet.latestHeight
189
224
  }
190
225
 
191
226
  @ReactMethod
192
- fun getBirthdayHeight(host: String, port: Int, promise: Promise) {
227
+ fun getBirthdayHeight(
228
+ host: String,
229
+ port: Int,
230
+ promise: Promise,
231
+ ) {
193
232
  moduleScope.launch {
194
233
  promise.wrap {
195
- var endpoint = LightWalletEndpoint(host, port, true)
196
- var lightwalletService = LightWalletClient.new(reactApplicationContext, endpoint)
234
+ val endpoint = LightWalletEndpoint(host, port, true)
235
+ val lightwalletService = LightWalletClient.new(reactApplicationContext, endpoint)
197
236
  return@wrap when (val response = lightwalletService.getLatestBlockHeight()) {
198
237
  is Response.Success -> {
199
238
  response.result.value.toInt()
@@ -211,32 +250,6 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
211
250
  }
212
251
  }
213
252
 
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
-
240
253
  @ReactMethod
241
254
  fun sendToAddress(
242
255
  alias: String,
@@ -248,18 +261,17 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
248
261
  ) {
249
262
  val wallet = getWallet(alias)
250
263
  wallet.coroutineScope.launch {
251
- var seedPhrase = SeedPhrase.new(seed)
252
- val usk = wallet.coroutineScope.async { DerivationTool.getInstance().deriveUnifiedSpendingKey(seedPhrase.toByteArray(), wallet.network, Account.DEFAULT) }.await()
264
+ val seedPhrase = SeedPhrase.new(seed)
265
+ val usk = DerivationTool.getInstance().deriveUnifiedSpendingKey(seedPhrase.toByteArray(), wallet.network, Account.DEFAULT)
253
266
  try {
254
- val internalId = wallet.sendToAddress(
255
- usk,
256
- Zatoshi(zatoshi.toLong()),
257
- toAddress,
258
- memo,
259
- )
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
-
267
+ val internalId =
268
+ wallet.sendToAddress(
269
+ usk,
270
+ Zatoshi(zatoshi.toLong()),
271
+ toAddress,
272
+ memo,
273
+ )
274
+ val tx = wallet.coroutineScope.async { wallet.transactions.first().first() }.await()
263
275
  val map = Arguments.createMap()
264
276
  map.putString("txId", tx.rawId.byteArray.toHexReversed())
265
277
  if (tx.raw != null) map.putString("raw", tx.raw?.byteArray?.toHex())
@@ -270,28 +282,67 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
270
282
  }
271
283
  }
272
284
 
285
+ @ReactMethod
286
+ fun shieldFunds(
287
+ alias: String,
288
+ seed: String,
289
+ memo: String,
290
+ threshold: String,
291
+ promise: Promise,
292
+ ) {
293
+ val wallet = getWallet(alias)
294
+ wallet.coroutineScope.launch {
295
+ val seedPhrase = SeedPhrase.new(seed)
296
+ val usk = DerivationTool.getInstance().deriveUnifiedSpendingKey(seedPhrase.toByteArray(), wallet.network, Account.DEFAULT)
297
+ try {
298
+ val internalId =
299
+ wallet.shieldFunds(
300
+ usk,
301
+ memo,
302
+ )
303
+ val tx = wallet.coroutineScope.async { wallet.transactions.first().first() }.await()
304
+ val parsedTx = parseTx(wallet, tx)
305
+
306
+ // Hack: Memos aren't ready to be queried right after broadcast
307
+ val memos = Arguments.createArray()
308
+ memos.pushString(memo)
309
+ parsedTx.putArray("memos", memos)
310
+ promise.resolve(parsedTx)
311
+ } catch (t: Throwable) {
312
+ promise.reject("Err", t)
313
+ }
314
+ }
315
+ }
316
+
273
317
  //
274
318
  // AddressTool
275
319
  //
276
320
 
277
321
  @ReactMethod
278
- fun deriveUnifiedAddress(alias: String, promise: Promise) {
322
+ fun deriveUnifiedAddress(
323
+ alias: String,
324
+ promise: Promise,
325
+ ) {
279
326
  val wallet = getWallet(alias)
280
327
  wallet.coroutineScope.launch {
281
- var unifiedAddress = wallet.coroutineScope.async { wallet.getUnifiedAddress(Account(0)) }.await()
282
- val saplingAddress = wallet.coroutineScope.async { wallet.getSaplingAddress(Account(0)) }.await()
283
- val transparentAddress = wallet.coroutineScope.async { wallet.getTransparentAddress(Account(0)) }.await()
328
+ val unifiedAddress = wallet.getUnifiedAddress(Account(0))
329
+ val saplingAddress = wallet.getSaplingAddress(Account(0))
330
+ val transparentAddress = wallet.getTransparentAddress(Account(0))
284
331
 
285
- val map = Arguments.createMap()
286
- map.putString("unifiedAddress", unifiedAddress)
287
- map.putString("saplingAddress", saplingAddress)
288
- map.putString("transparentAddress", transparentAddress)
289
- promise.resolve(map)
332
+ val map = Arguments.createMap()
333
+ map.putString("unifiedAddress", unifiedAddress)
334
+ map.putString("saplingAddress", saplingAddress)
335
+ map.putString("transparentAddress", transparentAddress)
336
+ promise.resolve(map)
290
337
  }
291
338
  }
292
339
 
293
340
  @ReactMethod
294
- fun isValidAddress(address: String, network: String, promise: Promise) {
341
+ fun isValidAddress(
342
+ address: String,
343
+ network: String,
344
+ promise: Promise,
345
+ ) {
295
346
  moduleScope.launch {
296
347
  promise.wrap {
297
348
  var isValid = false
@@ -315,9 +366,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
315
366
  * Retrieve wallet object from synchronizer map
316
367
  */
317
368
  private fun getWallet(alias: String): SdkSynchronizer {
318
- val wallet = synchronizerMap.get(alias)
319
- if (wallet == null) throw Exception("Wallet not found")
320
- return wallet
369
+ return synchronizerMap[alias] ?: throw Exception("Wallet not found")
321
370
  }
322
371
 
323
372
  /**
@@ -331,7 +380,10 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
331
380
  }
332
381
  }
333
382
 
334
- private fun sendEvent(eventName: String, putArgs: (WritableMap) -> Unit) {
383
+ private fun sendEvent(
384
+ eventName: String,
385
+ putArgs: (WritableMap) -> Unit,
386
+ ) {
335
387
  val args = Arguments.createMap()
336
388
  putArgs(args)
337
389
  reactApplicationContext
@@ -339,7 +391,7 @@ class RNZcashModule(private val reactContext: ReactApplicationContext) :
339
391
  .emit(eventName, args)
340
392
  }
341
393
 
342
- inline fun ByteArray.toHexReversed(): String {
394
+ private fun ByteArray.toHexReversed(): String {
343
395
  val sb = StringBuilder(size * 2)
344
396
  var i = size - 1
345
397
  while (i >= 0)
@@ -12,6 +12,5 @@ class RNZcashPackage : ReactPackage {
12
12
  RNZcashModule(reactContext),
13
13
  )
14
14
 
15
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
16
- emptyList()
15
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> = emptyList()
17
16
  }
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,14 +45,10 @@ 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
48
+ RCT_EXTERN_METHOD(shieldFunds:(NSString *)alias
49
+ :(NSString *)seed
50
+ :(NSString *)memo
51
+ :(NSString *)threshold
55
52
  resolver:(RCTPromiseResolveBlock)resolve
56
53
  rejecter:(RCTPromiseRejectBlock)reject
57
54
  )