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.
- package/CHANGELOG.md +28 -0
- package/README.md +7 -3
- package/android/build.gradle +5 -4
- package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2240000.json +8 -0
- package/android/src/main/assets/co.electriccoin.zcash/checkpoint/mainnet/2250000.json +8 -0
- package/android/src/main/java/app/edge/rnzcash/RNZcashModule.kt +221 -169
- package/android/src/main/java/app/edge/rnzcash/RNZcashPackage.kt +1 -2
- package/ios/RNZcash.m +5 -8
- package/ios/RNZcash.swift +177 -137
- package/ios/ZCashLightClientKit/Block/Actions/Action.swift +98 -0
- package/ios/ZCashLightClientKit/Block/Actions/ClearAlreadyScannedBlocksAction.swift +35 -0
- package/ios/ZCashLightClientKit/Block/Actions/ClearCacheAction.swift +30 -0
- package/ios/ZCashLightClientKit/Block/Actions/DownloadAction.swift +67 -0
- package/ios/ZCashLightClientKit/Block/Actions/EnhanceAction.swift +97 -0
- package/ios/ZCashLightClientKit/Block/Actions/FetchUTXOsAction.swift +33 -0
- package/ios/ZCashLightClientKit/Block/Actions/MigrateLegacyCacheDBAction.swift +70 -0
- package/ios/ZCashLightClientKit/Block/Actions/ProcessSuggestedScanRangesAction.swift +59 -0
- package/ios/ZCashLightClientKit/Block/Actions/RewindAction.swift +48 -0
- package/ios/ZCashLightClientKit/Block/Actions/SaplingParamsAction.swift +33 -0
- package/ios/ZCashLightClientKit/Block/Actions/ScanAction.swift +95 -0
- package/ios/ZCashLightClientKit/Block/Actions/UpdateChainTipAction.swift +55 -0
- package/ios/ZCashLightClientKit/Block/Actions/UpdateSubtreeRootsAction.swift +58 -0
- package/ios/ZCashLightClientKit/Block/Actions/ValidateServerAction.swift +60 -0
- package/ios/ZCashLightClientKit/Block/CompactBlockProcessor.swift +421 -937
- package/ios/ZCashLightClientKit/Block/Download/BlockDownloader.swift +31 -17
- package/ios/ZCashLightClientKit/Block/Download/BlockDownloaderService.swift +2 -2
- package/ios/ZCashLightClientKit/Block/Enhance/BlockEnhancer.swift +46 -15
- package/ios/ZCashLightClientKit/Block/FetchUnspentTxOutputs/UTXOFetcher.swift +4 -15
- package/ios/ZCashLightClientKit/Block/FilesystemStorage/FSCompactBlockRepository.swift +4 -4
- package/ios/ZCashLightClientKit/Block/Scan/BlockScanner.swift +10 -35
- package/ios/ZCashLightClientKit/Block/Utils/CompactBlockProgress.swift +24 -0
- package/ios/ZCashLightClientKit/Block/Utils/SyncControlData.swift +25 -0
- package/ios/ZCashLightClientKit/ClosureSynchronizer.swift +1 -2
- package/ios/ZCashLightClientKit/CombineSynchronizer.swift +2 -5
- package/ios/ZCashLightClientKit/Constants/ZcashSDK.swift +7 -25
- package/ios/ZCashLightClientKit/DAO/TransactionDao.swift +40 -42
- package/ios/ZCashLightClientKit/DAO/UnspentTransactionOutputDao.swift +13 -4
- package/ios/ZCashLightClientKit/Entity/AccountEntity.swift +9 -0
- package/ios/ZCashLightClientKit/Entity/TransactionEntity.swift +7 -10
- package/ios/ZCashLightClientKit/Error/Sourcery/generateErrorCode.sh +1 -1
- package/ios/ZCashLightClientKit/Error/ZcashError.swift +121 -12
- package/ios/ZCashLightClientKit/Error/ZcashErrorCode.swift +43 -5
- package/ios/ZCashLightClientKit/Error/ZcashErrorCodeDefinition.swift +72 -6
- package/ios/ZCashLightClientKit/Extensions/Bool+ToData.swift +15 -0
- package/ios/ZCashLightClientKit/Extensions/Data+ToOtherTypes.swift +18 -0
- package/ios/ZCashLightClientKit/Extensions/Int+ToData.swift +15 -0
- package/ios/ZCashLightClientKit/Initializer.swift +47 -26
- package/ios/ZCashLightClientKit/Metrics/SDKMetrics.swift +0 -12
- package/ios/ZCashLightClientKit/Model/Checkpoint.swift +12 -0
- package/ios/ZCashLightClientKit/Model/ScanProgress.swift +29 -0
- package/ios/ZCashLightClientKit/Model/ScanRange.swift +31 -0
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/LightWalletGRPCService.swift +15 -0
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/compact_formats.pb.swift +150 -46
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/compact_formats.proto +30 -16
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/proto/service.proto +32 -6
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.grpc.swift +259 -22
- package/ios/ZCashLightClientKit/Modules/Service/GRPC/ProtoBuf/service.pb.swift +193 -7
- package/ios/ZCashLightClientKit/Modules/Service/LightWalletService.swift +8 -0
- package/ios/ZCashLightClientKit/Providers/LatestBlocksDataProvider.swift +18 -28
- package/ios/ZCashLightClientKit/Repository/CompactBlockRepository.swift +1 -1
- package/ios/ZCashLightClientKit/Repository/TransactionRepository.swift +2 -6
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2092500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2095000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2097500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2102500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2105000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2107500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2112500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2115000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2117500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2122500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2125000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2127500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2132500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2135000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2137500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2142500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2145000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2147500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2152500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2155000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2157500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2162500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2165000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2167500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2172500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2175000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2177500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2182500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2185000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2187500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2192500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2195000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2197500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2202500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2205000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2207500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2212500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2215000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2217500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2222500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2225000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2227500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2230000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2232500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2235000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2237500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2240000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2242500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2245000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2247500.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/mainnet/2250000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2350000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2360000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2370000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2380000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2390000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2400000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2410000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2420000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2430000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2440000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2450000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2460000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2470000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2480000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2490000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2500000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2510000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2520000.json +8 -0
- package/ios/ZCashLightClientKit/Resources/checkpoints/testnet/2530000.json +8 -0
- package/ios/ZCashLightClientKit/Rust/ZcashRustBackend.swift +293 -158
- package/ios/ZCashLightClientKit/Rust/ZcashRustBackendWelding.swift +58 -64
- package/ios/ZCashLightClientKit/Rust/zcashlc.h +618 -512
- package/ios/ZCashLightClientKit/Synchronizer/ClosureSDKSynchronizer.swift +2 -8
- package/ios/ZCashLightClientKit/Synchronizer/CombineSDKSynchronizer.swift +3 -15
- package/ios/ZCashLightClientKit/Synchronizer/Dependencies.swift +11 -30
- package/ios/ZCashLightClientKit/Synchronizer/SDKSynchronizer.swift +41 -50
- package/ios/ZCashLightClientKit/Synchronizer.swift +51 -65
- package/ios/ZCashLightClientKit/Transaction/TransactionEncoder.swift +2 -2
- package/ios/ZCashLightClientKit/Transaction/WalletTransactionEncoder.swift +7 -7
- package/ios/ZCashLightClientKit/Utils/OSLogger.swift +3 -3
- package/ios/ZCashLightClientKit/Utils/ZcashFileManager.swift +16 -0
- package/ios/libzcashlc.xcframework/Info.plist +4 -0
- package/ios/libzcashlc.xcframework/ios-arm64/libzcashlc.a +0 -0
- package/ios/libzcashlc.xcframework/ios-arm64_x86_64-simulator/libzcashlc.a +0 -0
- package/lib/rnzcash.rn.js +29 -29
- package/lib/rnzcash.rn.js.map +1 -1
- package/lib/src/react-native.d.ts +5 -5
- package/lib/src/types.d.ts +27 -15
- package/package.json +2 -1
- package/src/react-native.ts +40 -21
- package/src/types.ts +36 -24
- package/ios/ZCashLightClientKit/Block/Utils/InternalSyncProgress.swift +0 -200
- package/ios/ZCashLightClientKit/Block/Validate/BlockValidator.swift +0 -51
- package/ios/ZCashLightClientKit/DAO/BlockDao.swift +0 -112
- package/ios/ZCashLightClientKit/Entity/BlockProgress.swift +0 -24
|
@@ -42,13 +42,8 @@ public struct SynchronizerState: Equatable {
|
|
|
42
42
|
/// status of the whole sync process
|
|
43
43
|
var internalSyncStatus: InternalSyncStatus
|
|
44
44
|
public var syncStatus: SyncStatus
|
|
45
|
-
/// height of the latest scanned block known to this synchronizer.
|
|
46
|
-
public var latestScannedHeight: BlockHeight
|
|
47
45
|
/// height of the latest block on the blockchain known to this synchronizer.
|
|
48
46
|
public var latestBlockHeight: BlockHeight
|
|
49
|
-
/// timestamp of the latest scanned block on the blockchain known to this synchronizer.
|
|
50
|
-
/// The anchor point is timeIntervalSince1970
|
|
51
|
-
public var latestScannedTime: TimeInterval
|
|
52
47
|
|
|
53
48
|
/// Represents a synchronizer that has made zero progress hasn't done a sync attempt
|
|
54
49
|
public static var zero: SynchronizerState {
|
|
@@ -57,9 +52,7 @@ public struct SynchronizerState: Equatable {
|
|
|
57
52
|
shieldedBalance: .zero,
|
|
58
53
|
transparentBalance: .zero,
|
|
59
54
|
internalSyncStatus: .unprepared,
|
|
60
|
-
|
|
61
|
-
latestBlockHeight: .zero,
|
|
62
|
-
latestScannedTime: 0
|
|
55
|
+
latestBlockHeight: .zero
|
|
63
56
|
)
|
|
64
57
|
}
|
|
65
58
|
|
|
@@ -68,17 +61,13 @@ public struct SynchronizerState: Equatable {
|
|
|
68
61
|
shieldedBalance: WalletBalance,
|
|
69
62
|
transparentBalance: WalletBalance,
|
|
70
63
|
internalSyncStatus: InternalSyncStatus,
|
|
71
|
-
|
|
72
|
-
latestBlockHeight: BlockHeight,
|
|
73
|
-
latestScannedTime: TimeInterval
|
|
64
|
+
latestBlockHeight: BlockHeight
|
|
74
65
|
) {
|
|
75
66
|
self.syncSessionID = syncSessionID
|
|
76
67
|
self.shieldedBalance = shieldedBalance
|
|
77
68
|
self.transparentBalance = transparentBalance
|
|
78
69
|
self.internalSyncStatus = internalSyncStatus
|
|
79
|
-
self.latestScannedHeight = latestScannedHeight
|
|
80
70
|
self.latestBlockHeight = latestBlockHeight
|
|
81
|
-
self.latestScannedTime = latestScannedTime
|
|
82
71
|
self.syncStatus = internalSyncStatus.mapToSyncStatus()
|
|
83
72
|
}
|
|
84
73
|
}
|
|
@@ -119,7 +108,7 @@ public protocol Synchronizer: AnyObject {
|
|
|
119
108
|
|
|
120
109
|
/// An object that when enabled collects mertrics from the synchronizer
|
|
121
110
|
var metrics: SDKMetrics { get }
|
|
122
|
-
|
|
111
|
+
|
|
123
112
|
/// Initialize the wallet. The ZIP-32 seed bytes can optionally be passed to perform
|
|
124
113
|
/// database migrations. most of the times the seed won't be needed. If they do and are
|
|
125
114
|
/// not provided this will fail with `InitializationResult.seedRequired`. It could
|
|
@@ -131,9 +120,11 @@ public protocol Synchronizer: AnyObject {
|
|
|
131
120
|
/// do not already exist). These files can be given a prefix for scenarios where multiple wallets
|
|
132
121
|
///
|
|
133
122
|
/// - Parameters:
|
|
134
|
-
/// - seed: ZIP-32 Seed bytes for the wallet that will be initialized
|
|
135
|
-
/// - viewingKeys: Viewing key derived from seed.
|
|
123
|
+
/// - seed: ZIP-32 Seed bytes for the wallet that will be initialized
|
|
136
124
|
/// - walletBirthday: Birthday of wallet.
|
|
125
|
+
/// - for: [walletMode] Set `.newWallet` when preparing synchronizer for a brand new generated wallet,
|
|
126
|
+
/// `.restoreWallet` when wallet is about to be restored from a seed
|
|
127
|
+
/// and `.existingWallet` for all other scenarios.
|
|
137
128
|
/// - Throws:
|
|
138
129
|
/// - `aliasAlreadyInUse` if the Alias used to create this instance is already used by other instance.
|
|
139
130
|
/// - `cantUpdateURLWithAlias` if the updating of paths in `Initilizer` according to alias fails. When this happens it means that
|
|
@@ -142,8 +133,8 @@ public protocol Synchronizer: AnyObject {
|
|
|
142
133
|
/// - Some other `ZcashError` thrown by lower layer of the SDK.
|
|
143
134
|
func prepare(
|
|
144
135
|
with seed: [UInt8]?,
|
|
145
|
-
|
|
146
|
-
|
|
136
|
+
walletBirthday: BlockHeight,
|
|
137
|
+
for walletMode: WalletInitMode
|
|
147
138
|
) async throws -> Initializer.InitializationResult
|
|
148
139
|
|
|
149
140
|
/// Starts this synchronizer within the given scope.
|
|
@@ -199,9 +190,6 @@ public protocol Synchronizer: AnyObject {
|
|
|
199
190
|
shieldingThreshold: Zatoshi
|
|
200
191
|
) async throws -> ZcashTransaction.Overview
|
|
201
192
|
|
|
202
|
-
/// all outbound pending transactions that have been sent but are awaiting confirmations
|
|
203
|
-
var pendingTransactions: [ZcashTransaction.Overview] { get async }
|
|
204
|
-
|
|
205
193
|
/// all the transactions that are on the blockchain
|
|
206
194
|
var transactions: [ZcashTransaction.Overview] { get async }
|
|
207
195
|
|
|
@@ -242,10 +230,6 @@ public protocol Synchronizer: AnyObject {
|
|
|
242
230
|
/// - Returns: an array with the given Transactions or an empty array
|
|
243
231
|
func allTransactions(from transaction: ZcashTransaction.Overview, limit: Int) async throws -> [ZcashTransaction.Overview]
|
|
244
232
|
|
|
245
|
-
/// Fetch all pending transactions
|
|
246
|
-
/// - Returns: an array of transactions which are considered pending confirmation. can be empty
|
|
247
|
-
func allPendingTransactions() async throws -> [ZcashTransaction.Overview]
|
|
248
|
-
|
|
249
233
|
/// Returns the latest block height from the provided Lightwallet endpoint
|
|
250
234
|
func latestHeight() async throws -> BlockHeight
|
|
251
235
|
|
|
@@ -333,20 +317,32 @@ public enum SyncStatus: Equatable {
|
|
|
333
317
|
/// When set, a UI element may want to turn green.
|
|
334
318
|
case upToDate
|
|
335
319
|
|
|
320
|
+
/// Indicates that this Synchronizer was succesfully stopped via `stop()` method.
|
|
321
|
+
case stopped
|
|
322
|
+
|
|
336
323
|
case error(_ error: Error)
|
|
337
324
|
|
|
338
325
|
public var isSyncing: Bool {
|
|
339
|
-
|
|
326
|
+
if case .syncing = self {
|
|
327
|
+
return true
|
|
328
|
+
}
|
|
329
|
+
|
|
340
330
|
return false
|
|
341
331
|
}
|
|
342
332
|
|
|
343
333
|
public var isSynced: Bool {
|
|
344
|
-
|
|
334
|
+
if case .upToDate = self {
|
|
335
|
+
return true
|
|
336
|
+
}
|
|
337
|
+
|
|
345
338
|
return false
|
|
346
339
|
}
|
|
347
340
|
|
|
348
341
|
public var isPrepared: Bool {
|
|
349
|
-
|
|
342
|
+
if case .unprepared = self {
|
|
343
|
+
return false
|
|
344
|
+
}
|
|
345
|
+
|
|
350
346
|
return true
|
|
351
347
|
}
|
|
352
348
|
|
|
@@ -354,6 +350,7 @@ public enum SyncStatus: Equatable {
|
|
|
354
350
|
switch self {
|
|
355
351
|
case .unprepared: return "unprepared"
|
|
356
352
|
case .syncing: return "syncing"
|
|
353
|
+
case .stopped: return "stopped"
|
|
357
354
|
case .upToDate: return "up to date"
|
|
358
355
|
case .error: return "error"
|
|
359
356
|
}
|
|
@@ -366,15 +363,9 @@ enum InternalSyncStatus: Equatable {
|
|
|
366
363
|
/// taking other maintenance steps that need to occur after an upgrade.
|
|
367
364
|
case unprepared
|
|
368
365
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
/// with additional transaction details, fetched from the server.
|
|
373
|
-
case enhancing(_ progress: EnhancementProgress)
|
|
374
|
-
|
|
375
|
-
/// fetches the transparent balance and stores it locally
|
|
376
|
-
case fetching(_ progress: Float)
|
|
377
|
-
|
|
366
|
+
/// Indicates that this Synchronizer is actively processing new blocks (consists of fetch, scan and enhance operations)
|
|
367
|
+
case syncing(Float)
|
|
368
|
+
|
|
378
369
|
/// Indicates that this Synchronizer is fully up to date and ready for all wallet functions.
|
|
379
370
|
/// When set, a UI element may want to turn green.
|
|
380
371
|
case synced
|
|
@@ -389,35 +380,33 @@ enum InternalSyncStatus: Equatable {
|
|
|
389
380
|
case error(_ error: Error)
|
|
390
381
|
|
|
391
382
|
public var isSyncing: Bool {
|
|
392
|
-
|
|
393
|
-
case .syncing, .enhancing, .fetching:
|
|
383
|
+
if case .syncing = self {
|
|
394
384
|
return true
|
|
395
|
-
default:
|
|
396
|
-
return false
|
|
397
385
|
}
|
|
386
|
+
|
|
387
|
+
return false
|
|
398
388
|
}
|
|
399
389
|
|
|
400
390
|
public var isSynced: Bool {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
default: return false
|
|
391
|
+
if case .synced = self {
|
|
392
|
+
return true
|
|
404
393
|
}
|
|
394
|
+
|
|
395
|
+
return false
|
|
405
396
|
}
|
|
406
397
|
|
|
407
398
|
public var isPrepared: Bool {
|
|
408
399
|
if case .unprepared = self {
|
|
409
400
|
return false
|
|
410
|
-
} else {
|
|
411
|
-
return true
|
|
412
401
|
}
|
|
402
|
+
|
|
403
|
+
return true
|
|
413
404
|
}
|
|
414
405
|
|
|
415
406
|
public var briefDebugDescription: String {
|
|
416
407
|
switch self {
|
|
417
408
|
case .unprepared: return "unprepared"
|
|
418
409
|
case .syncing: return "syncing"
|
|
419
|
-
case .enhancing: return "enhancing"
|
|
420
|
-
case .fetching: return "fetching"
|
|
421
410
|
case .synced: return "synced"
|
|
422
411
|
case .stopped: return "stopped"
|
|
423
412
|
case .disconnected: return "disconnected"
|
|
@@ -426,6 +415,16 @@ enum InternalSyncStatus: Equatable {
|
|
|
426
415
|
}
|
|
427
416
|
}
|
|
428
417
|
|
|
418
|
+
/// Mode of the Synchronizer's initialization for the wallet.
|
|
419
|
+
public enum WalletInitMode: Equatable {
|
|
420
|
+
/// For brand new wallet - typically when users creates a new wallet.
|
|
421
|
+
case newWallet
|
|
422
|
+
/// For a wallet that is about to be restored. Typically when a user wants to restore a wallet from a seed.
|
|
423
|
+
case restoreWallet
|
|
424
|
+
/// All other cases - typically when clients just start the process e.g. every regular app start for mobile apps.
|
|
425
|
+
case existingWallet
|
|
426
|
+
}
|
|
427
|
+
|
|
429
428
|
/// Kind of transactions handled by a Synchronizer
|
|
430
429
|
public enum TransactionKind {
|
|
431
430
|
case sent
|
|
@@ -449,8 +448,6 @@ extension InternalSyncStatus {
|
|
|
449
448
|
switch (lhs, rhs) {
|
|
450
449
|
case (.unprepared, .unprepared): return true
|
|
451
450
|
case let (.syncing(lhsProgress), .syncing(rhsProgress)): return lhsProgress == rhsProgress
|
|
452
|
-
case let (.enhancing(lhsProgress), .enhancing(rhsProgress)): return lhsProgress == rhsProgress
|
|
453
|
-
case (.fetching, .fetching): return true
|
|
454
451
|
case (.synced, .synced): return true
|
|
455
452
|
case (.stopped, .stopped): return true
|
|
456
453
|
case (.disconnected, .disconnected): return true
|
|
@@ -461,15 +458,8 @@ extension InternalSyncStatus {
|
|
|
461
458
|
}
|
|
462
459
|
|
|
463
460
|
extension InternalSyncStatus {
|
|
464
|
-
init(_ blockProcessorProgress:
|
|
465
|
-
|
|
466
|
-
case .syncing(let progressReport):
|
|
467
|
-
self = .syncing(progressReport)
|
|
468
|
-
case .enhance(let enhancingReport):
|
|
469
|
-
self = .enhancing(enhancingReport)
|
|
470
|
-
case .fetch(let fetchingProgress):
|
|
471
|
-
self = .fetching(fetchingProgress)
|
|
472
|
-
}
|
|
461
|
+
init(_ blockProcessorProgress: Float) {
|
|
462
|
+
self = .syncing(blockProcessorProgress)
|
|
473
463
|
}
|
|
474
464
|
}
|
|
475
465
|
|
|
@@ -479,15 +469,11 @@ extension InternalSyncStatus {
|
|
|
479
469
|
case .unprepared:
|
|
480
470
|
return .unprepared
|
|
481
471
|
case .syncing(let progress):
|
|
482
|
-
return .syncing(
|
|
483
|
-
case .enhancing(let progress):
|
|
484
|
-
return .syncing(0.9 + 0.08 * progress.progress)
|
|
485
|
-
case .fetching(let progress):
|
|
486
|
-
return .syncing(0.98 + 0.02 * progress)
|
|
472
|
+
return .syncing(progress)
|
|
487
473
|
case .synced:
|
|
488
474
|
return .upToDate
|
|
489
475
|
case .stopped:
|
|
490
|
-
return .
|
|
476
|
+
return .stopped
|
|
491
477
|
case .disconnected:
|
|
492
478
|
return .error(ZcashError.synchronizerDisconnected)
|
|
493
479
|
case .error(let error):
|
|
@@ -10,8 +10,8 @@ import Foundation
|
|
|
10
10
|
typealias TransactionEncoderResultBlock = (_ result: Result<EncodedTransaction, Error>) -> Void
|
|
11
11
|
|
|
12
12
|
public enum TransactionEncoderError: Error {
|
|
13
|
-
case notFound(
|
|
14
|
-
case notEncoded(
|
|
13
|
+
case notFound(txId: Data)
|
|
14
|
+
case notEncoded(txId: Data)
|
|
15
15
|
case missingParams
|
|
16
16
|
case spendingKeyWrongNetwork
|
|
17
17
|
case couldNotExpand(txId: Data)
|
|
@@ -71,7 +71,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
71
71
|
)
|
|
72
72
|
|
|
73
73
|
logger.debug("transaction id: \(txId)")
|
|
74
|
-
return try await repository.find(
|
|
74
|
+
return try await repository.find(rawID: txId)
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
func createSpend(
|
|
@@ -80,7 +80,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
80
80
|
to address: String,
|
|
81
81
|
memoBytes: MemoBytes?,
|
|
82
82
|
from accountIndex: Int
|
|
83
|
-
) async throws ->
|
|
83
|
+
) async throws -> Data {
|
|
84
84
|
guard ensureParams(spend: self.spendParamsURL, output: self.outputParamsURL) else {
|
|
85
85
|
throw ZcashError.walletTransEncoderCreateTransactionMissingSaplingParams
|
|
86
86
|
}
|
|
@@ -92,7 +92,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
92
92
|
memo: memoBytes
|
|
93
93
|
)
|
|
94
94
|
|
|
95
|
-
return
|
|
95
|
+
return txId
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
func createShieldingTransaction(
|
|
@@ -109,7 +109,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
109
109
|
)
|
|
110
110
|
|
|
111
111
|
logger.debug("transaction id: \(txId)")
|
|
112
|
-
return try await repository.find(
|
|
112
|
+
return try await repository.find(rawID: txId)
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
func createShieldingSpend(
|
|
@@ -117,7 +117,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
117
117
|
shieldingThreshold: Zatoshi,
|
|
118
118
|
memo: MemoBytes?,
|
|
119
119
|
accountIndex: Int
|
|
120
|
-
) async throws ->
|
|
120
|
+
) async throws -> Data {
|
|
121
121
|
guard ensureParams(spend: self.spendParamsURL, output: self.outputParamsURL) else {
|
|
122
122
|
throw ZcashError.walletTransEncoderShieldFundsMissingSaplingParams
|
|
123
123
|
}
|
|
@@ -128,7 +128,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
128
128
|
shieldingThreshold: shieldingThreshold
|
|
129
129
|
)
|
|
130
130
|
|
|
131
|
-
return
|
|
131
|
+
return txId
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
func submit(
|
|
@@ -157,7 +157,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
|
|
157
157
|
extension ZcashTransaction.Overview {
|
|
158
158
|
func encodedTransaction() throws -> EncodedTransaction {
|
|
159
159
|
guard let raw else {
|
|
160
|
-
throw TransactionEncoderError.notEncoded(
|
|
160
|
+
throw TransactionEncoderError.notEncoded(txId: self.rawID)
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
return EncodedTransaction(transactionId: self.rawID, raw: raw)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ZcashFileManager.swift
|
|
3
|
+
//
|
|
4
|
+
//
|
|
5
|
+
// Created by Lukáš Korba on 23.05.2023.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
protocol ZcashFileManager {
|
|
11
|
+
func isReadableFile(atPath path: String) -> Bool
|
|
12
|
+
func removeItem(at URL: URL) throws
|
|
13
|
+
func isDeletableFile(atPath path: String) -> Bool
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
extension FileManager: ZcashFileManager { }
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
<key>AvailableLibraries</key>
|
|
6
6
|
<array>
|
|
7
7
|
<dict>
|
|
8
|
+
<key>BinaryPath</key>
|
|
9
|
+
<string>libzcashlc.a</string>
|
|
8
10
|
<key>LibraryIdentifier</key>
|
|
9
11
|
<string>ios-arm64_x86_64-simulator</string>
|
|
10
12
|
<key>LibraryPath</key>
|
|
@@ -20,6 +22,8 @@
|
|
|
20
22
|
<string>simulator</string>
|
|
21
23
|
</dict>
|
|
22
24
|
<dict>
|
|
25
|
+
<key>BinaryPath</key>
|
|
26
|
+
<string>libzcashlc.a</string>
|
|
23
27
|
<key>LibraryIdentifier</key>
|
|
24
28
|
<string>ios-arm64</string>
|
|
25
29
|
<key>LibraryPath</key>
|
|
Binary file
|
|
Binary file
|
package/lib/rnzcash.rn.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var biggystring = require('biggystring');
|
|
5
6
|
var reactNative = require('react-native');
|
|
6
7
|
|
|
7
8
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -109,7 +110,7 @@ var Synchronizer = /*#__PURE__*/function () {
|
|
|
109
110
|
|
|
110
111
|
_proto.initialize = /*#__PURE__*/function () {
|
|
111
112
|
var _initialize = _asyncToGenerator(function* (initializerConfig) {
|
|
112
|
-
yield RNZcash.initialize(initializerConfig.mnemonicSeed, initializerConfig.birthdayHeight, initializerConfig.alias, initializerConfig.networkName, initializerConfig.defaultHost, initializerConfig.defaultPort);
|
|
113
|
+
yield RNZcash.initialize(initializerConfig.mnemonicSeed, initializerConfig.birthdayHeight, initializerConfig.alias, initializerConfig.networkName, initializerConfig.defaultHost, initializerConfig.defaultPort, initializerConfig.newWallet);
|
|
113
114
|
});
|
|
114
115
|
|
|
115
116
|
function initialize(_x7) {
|
|
@@ -145,32 +146,6 @@ var Synchronizer = /*#__PURE__*/function () {
|
|
|
145
146
|
return getLatestNetworkHeight;
|
|
146
147
|
}();
|
|
147
148
|
|
|
148
|
-
_proto.getBalance = /*#__PURE__*/function () {
|
|
149
|
-
var _getBalance = _asyncToGenerator(function* () {
|
|
150
|
-
var result = yield RNZcash.getBalance(this.alias);
|
|
151
|
-
return result;
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
function getBalance() {
|
|
155
|
-
return _getBalance.apply(this, arguments);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return getBalance;
|
|
159
|
-
}();
|
|
160
|
-
|
|
161
|
-
_proto.getTransactions = /*#__PURE__*/function () {
|
|
162
|
-
var _getTransactions = _asyncToGenerator(function* (range) {
|
|
163
|
-
var result = yield RNZcash.getTransactions(this.alias, range.first, range.last);
|
|
164
|
-
return result;
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
function getTransactions(_x9) {
|
|
168
|
-
return _getTransactions.apply(this, arguments);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return getTransactions;
|
|
172
|
-
}();
|
|
173
|
-
|
|
174
149
|
_proto.rescan = function rescan() {
|
|
175
150
|
RNZcash.rescan(this.alias);
|
|
176
151
|
};
|
|
@@ -181,18 +156,43 @@ var Synchronizer = /*#__PURE__*/function () {
|
|
|
181
156
|
return result;
|
|
182
157
|
});
|
|
183
158
|
|
|
184
|
-
function sendToAddress(
|
|
159
|
+
function sendToAddress(_x9) {
|
|
185
160
|
return _sendToAddress.apply(this, arguments);
|
|
186
161
|
}
|
|
187
162
|
|
|
188
163
|
return sendToAddress;
|
|
164
|
+
}();
|
|
165
|
+
|
|
166
|
+
_proto.shieldFunds = /*#__PURE__*/function () {
|
|
167
|
+
var _shieldFunds = _asyncToGenerator(function* (shieldFundsInfo) {
|
|
168
|
+
var result = yield RNZcash.shieldFunds(this.alias, shieldFundsInfo.seed, shieldFundsInfo.memo, shieldFundsInfo.threshold);
|
|
169
|
+
return result;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
function shieldFunds(_x10) {
|
|
173
|
+
return _shieldFunds.apply(this, arguments);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return shieldFunds;
|
|
189
177
|
}() // Events
|
|
190
178
|
;
|
|
191
179
|
|
|
192
180
|
_proto.subscribe = function subscribe(_ref) {
|
|
193
|
-
var
|
|
181
|
+
var onBalanceChanged = _ref.onBalanceChanged,
|
|
182
|
+
onStatusChanged = _ref.onStatusChanged,
|
|
183
|
+
onTransactionsChanged = _ref.onTransactionsChanged,
|
|
194
184
|
onUpdate = _ref.onUpdate;
|
|
185
|
+
this.setListener('BalanceEvent', function (event) {
|
|
186
|
+
var transparentAvailableZatoshi = event.transparentAvailableZatoshi,
|
|
187
|
+
transparentTotalZatoshi = event.transparentTotalZatoshi,
|
|
188
|
+
saplingAvailableZatoshi = event.saplingAvailableZatoshi,
|
|
189
|
+
saplingTotalZatoshi = event.saplingTotalZatoshi;
|
|
190
|
+
event.availableZatoshi = biggystring.add(transparentAvailableZatoshi, saplingAvailableZatoshi);
|
|
191
|
+
event.totalZatoshi = biggystring.add(transparentTotalZatoshi, saplingTotalZatoshi);
|
|
192
|
+
onBalanceChanged(event);
|
|
193
|
+
});
|
|
195
194
|
this.setListener('StatusEvent', onStatusChanged);
|
|
195
|
+
this.setListener('TransactionEvent', onTransactionsChanged);
|
|
196
196
|
this.setListener('UpdateEvent', onUpdate);
|
|
197
197
|
};
|
|
198
198
|
|
package/lib/rnzcash.rn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rnzcash.rn.js","sources":["../src/react-native.ts"],"sourcesContent":["import {\n EventSubscription,\n NativeEventEmitter,\n NativeModules\n} from 'react-native'\n\nimport {\n Addresses,\n
|
|
1
|
+
{"version":3,"file":"rnzcash.rn.js","sources":["../src/react-native.ts"],"sourcesContent":["import { add } from 'biggystring'\nimport {\n EventSubscription,\n NativeEventEmitter,\n NativeModules\n} from 'react-native'\n\nimport {\n Addresses,\n InitializerConfig,\n Network,\n ShieldFundsInfo,\n SpendFailure,\n SpendInfo,\n SpendSuccess,\n SynchronizerCallbacks,\n Transaction,\n UnifiedViewingKey\n} from './types'\nexport * from './types'\n\nconst { RNZcash } = NativeModules\n\ntype Callback = (...args: any[]) => any\n\nexport const Tools = {\n deriveViewingKey: async (\n seedBytesHex: string,\n network: Network\n ): Promise<UnifiedViewingKey> => {\n const result = await RNZcash.deriveViewingKey(seedBytesHex, network)\n return result\n },\n getBirthdayHeight: async (host: string, port: number): Promise<number> => {\n const result = await RNZcash.getBirthdayHeight(host, port)\n return result\n },\n isValidAddress: async (\n address: string,\n network: Network = 'mainnet'\n ): Promise<boolean> => {\n const result = await RNZcash.isValidAddress(address, network)\n return result\n }\n}\n\nexport class Synchronizer {\n eventEmitter: NativeEventEmitter\n subscriptions: EventSubscription[]\n alias: string\n network: Network\n\n constructor(alias: string, network: Network) {\n this.eventEmitter = new NativeEventEmitter(RNZcash)\n this.subscriptions = []\n this.alias = alias\n this.network = network\n }\n\n async stop(): Promise<string> {\n this.unsubscribe()\n const result = await RNZcash.stop(this.alias)\n return result\n }\n\n async initialize(initializerConfig: InitializerConfig): Promise<void> {\n await RNZcash.initialize(\n initializerConfig.mnemonicSeed,\n initializerConfig.birthdayHeight,\n initializerConfig.alias,\n initializerConfig.networkName,\n initializerConfig.defaultHost,\n initializerConfig.defaultPort,\n initializerConfig.newWallet\n )\n }\n\n async deriveUnifiedAddress(): Promise<Addresses> {\n const result = await RNZcash.deriveUnifiedAddress(this.alias)\n return result\n }\n\n async getLatestNetworkHeight(alias: string): Promise<number> {\n const result = await RNZcash.getLatestNetworkHeight(alias)\n return result\n }\n\n rescan(): void {\n RNZcash.rescan(this.alias)\n }\n\n async sendToAddress(\n spendInfo: SpendInfo\n ): Promise<SpendSuccess | SpendFailure> {\n const result = await RNZcash.sendToAddress(\n this.alias,\n spendInfo.zatoshi,\n spendInfo.toAddress,\n spendInfo.memo,\n spendInfo.mnemonicSeed\n )\n return result\n }\n\n async shieldFunds(shieldFundsInfo: ShieldFundsInfo): Promise<Transaction> {\n const result = await RNZcash.shieldFunds(\n this.alias,\n shieldFundsInfo.seed,\n shieldFundsInfo.memo,\n shieldFundsInfo.threshold\n )\n return result\n }\n\n // Events\n\n subscribe({\n onBalanceChanged,\n onStatusChanged,\n onTransactionsChanged,\n onUpdate\n }: SynchronizerCallbacks): void {\n this.setListener('BalanceEvent', event => {\n const {\n transparentAvailableZatoshi,\n transparentTotalZatoshi,\n saplingAvailableZatoshi,\n saplingTotalZatoshi\n } = event\n\n event.availableZatoshi = add(\n transparentAvailableZatoshi,\n saplingAvailableZatoshi\n )\n event.totalZatoshi = add(transparentTotalZatoshi, saplingTotalZatoshi)\n onBalanceChanged(event)\n })\n this.setListener('StatusEvent', onStatusChanged)\n this.setListener('TransactionEvent', onTransactionsChanged)\n this.setListener('UpdateEvent', onUpdate)\n }\n\n private setListener<T>(\n eventName: string,\n callback: Callback = (t: any) => null\n ): void {\n this.subscriptions.push(\n this.eventEmitter.addListener(eventName, arg =>\n arg.alias === this.alias ? callback(arg) : null\n )\n )\n }\n\n unsubscribe(): void {\n this.subscriptions.forEach(subscription => {\n subscription.remove()\n })\n }\n}\n\nexport const makeSynchronizer = async (\n initializerConfig: InitializerConfig\n): Promise<Synchronizer> => {\n const synchronizer = new Synchronizer(\n initializerConfig.alias,\n initializerConfig.networkName\n )\n await synchronizer.initialize(initializerConfig)\n return synchronizer\n}\n"],"names":["RNZcash","NativeModules","Tools","deriveViewingKey","seedBytesHex","network","result","getBirthdayHeight","host","port","isValidAddress","address","Synchronizer","alias","eventEmitter","NativeEventEmitter","subscriptions","stop","unsubscribe","initialize","initializerConfig","mnemonicSeed","birthdayHeight","networkName","defaultHost","defaultPort","newWallet","deriveUnifiedAddress","getLatestNetworkHeight","rescan","sendToAddress","spendInfo","zatoshi","toAddress","memo","shieldFunds","shieldFundsInfo","seed","threshold","subscribe","onBalanceChanged","onStatusChanged","onTransactionsChanged","onUpdate","setListener","event","transparentAvailableZatoshi","transparentTotalZatoshi","saplingAvailableZatoshi","saplingTotalZatoshi","availableZatoshi","add","totalZatoshi","eventName","callback","t","push","addListener","arg","forEach","subscription","remove","makeSynchronizer","synchronizer"],"mappings":"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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventSubscription, NativeEventEmitter } from 'react-native';
|
|
2
|
-
import { Addresses,
|
|
2
|
+
import { Addresses, InitializerConfig, Network, ShieldFundsInfo, SpendFailure, SpendInfo, SpendSuccess, SynchronizerCallbacks, Transaction, UnifiedViewingKey } from './types';
|
|
3
|
+
export * from './types';
|
|
3
4
|
export declare const Tools: {
|
|
4
5
|
deriveViewingKey: (seedBytesHex: string, network: Network) => Promise<UnifiedViewingKey>;
|
|
5
6
|
getBirthdayHeight: (host: string, port: number) => Promise<number>;
|
|
@@ -11,15 +12,14 @@ export declare class Synchronizer {
|
|
|
11
12
|
alias: string;
|
|
12
13
|
network: Network;
|
|
13
14
|
constructor(alias: string, network: Network);
|
|
14
|
-
stop(): Promise<
|
|
15
|
+
stop(): Promise<string>;
|
|
15
16
|
initialize(initializerConfig: InitializerConfig): Promise<void>;
|
|
16
17
|
deriveUnifiedAddress(): Promise<Addresses>;
|
|
17
18
|
getLatestNetworkHeight(alias: string): Promise<number>;
|
|
18
|
-
getBalance(): Promise<WalletBalance>;
|
|
19
|
-
getTransactions(range: BlockRange): Promise<ConfirmedTransaction[]>;
|
|
20
19
|
rescan(): void;
|
|
21
20
|
sendToAddress(spendInfo: SpendInfo): Promise<SpendSuccess | SpendFailure>;
|
|
22
|
-
|
|
21
|
+
shieldFunds(shieldFundsInfo: ShieldFundsInfo): Promise<Transaction>;
|
|
22
|
+
subscribe({ onBalanceChanged, onStatusChanged, onTransactionsChanged, onUpdate }: SynchronizerCallbacks): void;
|
|
23
23
|
private setListener;
|
|
24
24
|
unsubscribe(): void;
|
|
25
25
|
}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export declare type Network = 'mainnet' | 'testnet';
|
|
2
|
-
export interface WalletBalance {
|
|
3
|
-
availableZatoshi: string;
|
|
4
|
-
totalZatoshi: string;
|
|
5
|
-
}
|
|
6
2
|
export interface InitializerConfig {
|
|
7
3
|
networkName: Network;
|
|
8
4
|
defaultHost: string;
|
|
@@ -10,6 +6,7 @@ export interface InitializerConfig {
|
|
|
10
6
|
mnemonicSeed: string;
|
|
11
7
|
alias: string;
|
|
12
8
|
birthdayHeight: number;
|
|
9
|
+
newWallet: boolean;
|
|
13
10
|
}
|
|
14
11
|
export interface SpendInfo {
|
|
15
12
|
zatoshi: string;
|
|
@@ -17,6 +14,11 @@ export interface SpendInfo {
|
|
|
17
14
|
memo?: string;
|
|
18
15
|
mnemonicSeed: string;
|
|
19
16
|
}
|
|
17
|
+
export interface ShieldFundsInfo {
|
|
18
|
+
seed: string;
|
|
19
|
+
memo: string;
|
|
20
|
+
threshold: string;
|
|
21
|
+
}
|
|
20
22
|
export interface SpendSuccess {
|
|
21
23
|
txId: string;
|
|
22
24
|
raw: string;
|
|
@@ -25,43 +27,53 @@ export interface SpendFailure {
|
|
|
25
27
|
errorMessage?: string;
|
|
26
28
|
errorCode?: string;
|
|
27
29
|
}
|
|
28
|
-
export interface SynchronizerStatus {
|
|
29
|
-
alias: string;
|
|
30
|
-
name: 'STOPPED' /** Indicates that [stop] has been called on this Synchronizer and it will no longer be used. */ | 'DISCONNECTED' /** Indicates that this Synchronizer is disconnected from its lightwalletd server. When set, a UI element may want to turn red. */ | 'DOWNLOADING' /** Indicates that this Synchronizer is actively downloading new blocks from the server. */ | 'VALIDATING' /** Indicates that this Synchronizer is actively validating new blocks that were downloaded from the server. Blocks need to be verified before they are scanned. This confirms that each block is chain-sequential, thereby detecting missing blocks and reorgs. */ | 'SCANNING' /** Indicates that this Synchronizer is actively decrypting new blocks that were downloaded from the server. */ | 'ENHANCING' /** Indicates that this Synchronizer is actively enhancing newly scanned blocks with additional transaction details, fetched from the server. */ | 'SYNCED'; /** Indicates that this Synchronizer is fully up to date and ready for all wallet functions. When set, a UI element may want to turn green. In this state, the balance can be trusted. */
|
|
31
|
-
}
|
|
32
30
|
export interface UnifiedViewingKey {
|
|
33
31
|
extfvk: string;
|
|
34
32
|
extpub: string;
|
|
35
33
|
}
|
|
34
|
+
export interface BalanceEvent {
|
|
35
|
+
transparentAvailableZatoshi: string;
|
|
36
|
+
transparentTotalZatoshi: string;
|
|
37
|
+
saplingAvailableZatoshi: string;
|
|
38
|
+
saplingTotalZatoshi: string;
|
|
39
|
+
/** @deprecated */
|
|
40
|
+
availableZatoshi: string;
|
|
41
|
+
totalZatoshi: string;
|
|
42
|
+
}
|
|
36
43
|
export interface StatusEvent {
|
|
37
44
|
alias: string;
|
|
38
|
-
name:
|
|
45
|
+
name: 'STOPPED' /** Indicates that [stop] has been called on this Synchronizer and it will no longer be used. */ | 'DISCONNECTED' /** Indicates that this Synchronizer is disconnected from its lightwalletd server. When set, a UI element may want to turn red. */ | 'SYNCING' /** Indicates that this Synchronizer is actively downloading and scanning new blocks */ | 'SYNCED'; /** Indicates that this Synchronizer is fully up to date and ready for all wallet functions. When set, a UI element may want to turn green. In this state, the balance can be trusted. */
|
|
46
|
+
}
|
|
47
|
+
export interface TransactionEvent {
|
|
48
|
+
transactions: Transaction[];
|
|
39
49
|
}
|
|
40
50
|
export interface UpdateEvent {
|
|
41
51
|
alias: string;
|
|
42
|
-
isDownloading: boolean;
|
|
43
|
-
isScanning: boolean;
|
|
44
|
-
lastDownloadedHeight: number;
|
|
45
|
-
lastScannedHeight: number;
|
|
46
52
|
scanProgress: number;
|
|
47
53
|
networkBlockHeight: number;
|
|
48
54
|
}
|
|
49
55
|
export interface SynchronizerCallbacks {
|
|
50
|
-
|
|
56
|
+
onBalanceChanged(balance: BalanceEvent): void;
|
|
57
|
+
onStatusChanged(status: StatusEvent): void;
|
|
58
|
+
onTransactionsChanged(transactions: TransactionEvent): void;
|
|
51
59
|
onUpdate(event: UpdateEvent): void;
|
|
52
60
|
}
|
|
53
61
|
export interface BlockRange {
|
|
54
62
|
first: number;
|
|
55
63
|
last: number;
|
|
56
64
|
}
|
|
57
|
-
export interface
|
|
65
|
+
export interface Transaction {
|
|
58
66
|
rawTransactionId: string;
|
|
67
|
+
raw?: string;
|
|
59
68
|
blockTimeInSeconds: number;
|
|
60
69
|
minedHeight: number;
|
|
61
70
|
value: string;
|
|
71
|
+
fee?: string;
|
|
62
72
|
toAddress?: string;
|
|
63
73
|
memos: string[];
|
|
64
74
|
}
|
|
75
|
+
/** @deprecated Renamed `Transaction` because the package can now return unconfirmed shielding transactions */
|
|
76
|
+
export declare type ConfirmedTransaction = Transaction;
|
|
65
77
|
export interface Addresses {
|
|
66
78
|
unifiedAddress: string;
|
|
67
79
|
saplingAddress: string;
|