[#1232] Implement createAccount

- create account draft

[#1232] Implement createAccount

- TODO for the recoverUntil parameter

[#1232] Implement createAccount

- force unwrap solved

[#1232] Implement createAccount

- ; removed
This commit is contained in:
Lukas Korba 2023-09-07 20:53:43 +02:00
parent 7631810979
commit b8b0f2927b
4 changed files with 27 additions and 6 deletions

View File

@ -28,7 +28,7 @@ enum DemoAppConfig {
static let defaultBirthdayHeight: BlockHeight = ZcashSDK.isMainnet ? 1935000 : 2170000
static let defaultSeed = try! Mnemonic.deterministicSeedBytes(from: """
kitchen renew wide common vague fold vacuum tilt amazing pear square gossip jewel month tree shock scan alpha just spot fluid toilet view dinner
wish puppy smile loan doll curve hole maze file ginger hair nose key relax knife witness cannon grab despair throw review deal slush frame
""")
static let otherSynchronizers: [SynchronizerInitData] = [

View File

@ -79,8 +79,7 @@ class SendViewController: UIViewController {
func setUp() {
Task { @MainActor in
balanceLabel.text = format(balance: (try? await synchronizer.getShieldedBalance(accountIndex: 0)) ?? .zero)
verifiedBalanceLabel.text = format(balance: (try? await synchronizer.getShieldedVerifiedBalance(accountIndex: 0)) ?? .zero)
await updateBalance()
await toggleSendButton()
}
memoField.text = ""
@ -93,12 +92,20 @@ class SendViewController: UIViewController {
.throttle(for: .seconds(0.2), scheduler: DispatchQueue.main, latest: true)
.sink(
receiveValue: { [weak self] state in
Task { @MainActor in
await self?.updateBalance()
}
self?.synchronizerStatusLabel.text = SDKSynchronizer.textFor(state: state.syncStatus)
}
)
.store(in: &cancellables)
}
func updateBalance() async {
balanceLabel.text = format(balance: (try? await synchronizer.getShieldedBalance(accountIndex: 0)) ?? .zero)
verifiedBalanceLabel.text = format(balance: (try? await synchronizer.getShieldedVerifiedBalance(accountIndex: 0)) ?? .zero)
}
func format(balance: Zatoshi = Zatoshi()) -> String {
"Zec \(balance.formattedString ?? "0.0")"
}

View File

@ -420,7 +420,15 @@ public class Initializer {
self.walletBirthday = checkpoint.height
// TODO: Initialize accounts if desired.
// If there are no accounts it must be created, the default amount of accounts is 1
if let seed, try accountRepository.getAll().isEmpty {
// TODO: [#1236] set the recoverUntil properly, https://github.com/zcash/ZcashLightClientKit/issues/1236
_ = try await rustBackend.createAccount(
seed: seed,
treeState: try checkpoint.treeState().serializedData(partial: false).bytes,
recoverUntil: nil
)
}
return .success
}

View File

@ -48,6 +48,12 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
}
func createAccount(seed: [UInt8], treeState: [UInt8], recoverUntil: UInt32?) async throws -> UnifiedSpendingKey {
var rUntil: Int64 = -1
if let recoverUntil {
rUntil = Int64(recoverUntil)
}
let ffiBinaryKeyPtr = zcashlc_create_account(
dbData.0,
dbData.1,
@ -55,7 +61,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
UInt(seed.count),
treeState,
UInt(treeState.count),
recoverUntil != nil ? Int64(recoverUntil!) : -1,
rUntil,
networkType.networkId
)
@ -521,7 +527,7 @@ actor ZcashRustBackend: ZcashRustBackendWelding {
if result.denominator == 0 {
switch result.numerator {
case 0:
return nil;
return nil
default:
throw ZcashError.rustGetScanProgress(lastErrorMessage(fallback: "`getScanProgress` failed with unknown error"))
}