Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Type safe address api #491

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions Sources/ZcashLightClientKit/Rust/ZcashRustBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
return false
}

guard zcashlc_is_valid_sapling_extended_spending_key(key, networkType.networkId) else {
guard zcashlc_is_valid_sapling_extended_spending_key([CChar](key.utf8CString), networkType.networkId) else {
if let error = lastError() {
throw error
}
Expand Down Expand Up @@ -755,11 +755,6 @@ class ZcashRustBackend: ZcashRustBackendWelding {
}
}

private struct UFVK {
var account: UInt32
var encoding: String
}

private extension ZcashRustBackend {
static func throwDataDbError(_ error: RustWeldingError) -> Error {
if case RustWeldingError.genericError(let message) = error, message.contains("is not empty") {
Expand All @@ -785,11 +780,3 @@ extension String {
self.utf8CString.firstIndex(of: 0) != (self.utf8CString.count - 1)
}
}


fileprivate extension UnifiedFullViewingKey {
init(ufvk: UFVK) {
self.account = ufvk.account
self.encoding = ufvk.encoding
}
}
13 changes: 9 additions & 4 deletions Sources/ZcashLightClientKit/Synchronizer/SDKSynchronizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ public class SDKSynchronizer: Synchronizer {
let derivationTool = DerivationTool(networkType: self.network.networkType)

do {
let tAddr = try derivationTool.deriveTransparentAddressFromAccountPrivateKey(transparentAccountPrivateKey, index: 0) // TODO: FIX
let tAddr = try derivationTool.deriveTransparentAddressFromAccountPrivateKey(transparentAccountPrivateKey, index: 0)

let tBalance = try utxoRepository.balance(address: tAddr.stringEncoded, latestHeight: self.latestDownloadedHeight())

// Verify that at least there are funds for the fee. Ideally this logic will be improved by the shielding wallet.
Expand All @@ -528,10 +529,14 @@ public class SDKSynchronizer: Synchronizer {
return
}

// TODO: this should be a UA
let zAddr = "fasdfasdfa"
// FIXME: Define who's the recipient of a shielding transaction #521
// https://github.com/zcash/ZcashLightClientKit/issues/521
guard let uAddr = self.getUnifiedAddress(accountIndex: accountIndex) else {
nuttycom marked this conversation as resolved.
Show resolved Hide resolved
resultBlock(.failure(ShieldFundsError.shieldingFailed(underlyingError: KeyEncodingError.invalidEncoding)))
return
}

let shieldingSpend = try transactionManager.initSpend(zatoshi: tBalance.verified, toAddress: zAddr, memo: memo, from: 0)
let shieldingSpend = try transactionManager.initSpend(zatoshi: tBalance.verified, toAddress: uAddr.stringEncoded, memo: memo, from: accountIndex)

transactionManager.encodeShieldingTransaction(
xprv: transparentAccountPrivateKey,
Expand Down