Skip to content

Commit

Permalink
[#1232] Implement createAccount
Browse files Browse the repository at this point in the history
- create account draft

[#1232] Implement createAccount

- TODO for the recoverUntil parameter

[#1232] Implement createAccount

- force unwrap solved
  • Loading branch information
LukasKorba committed Sep 8, 2023
1 parent 7631810 commit e122d50
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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")"
}
Expand Down
10 changes: 9 additions & 1 deletion Sources/ZcashLightClientKit/Initializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ 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,
seed,
UInt(seed.count),
treeState,
UInt(treeState.count),
recoverUntil != nil ? Int64(recoverUntil!) : -1,
rUntil,
networkType.networkId
)

Expand Down

0 comments on commit e122d50

Please sign in to comment.