Fix compile errors

This commit is contained in:
Francisco Gindre 2021-02-15 16:15:50 -03:00
parent 4999622478
commit 2d76c96b42
7 changed files with 89 additions and 65 deletions

91
Cargo.lock generated
View File

@ -93,9 +93,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "backtrace"
version = "0.3.55"
version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598"
checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
dependencies = [
"addr2line",
"cfg-if 1.0.0",
@ -271,9 +271,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.4.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820"
checksum = "099e596ef14349721d9016f6b80dd3419ea1bf289ab9b44df8e4dfd3a005d5d9"
[[package]]
name = "byte-tools"
@ -429,7 +429,6 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "equihash"
version = "0.1.0"
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#921d50a0096090461d8bc0489078496e48ea91ad"
dependencies = [
"blake2b_simd",
"byteorder",
@ -560,7 +559,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.1+wasi-snapshot-preview1",
"wasi 0.10.2+wasi-snapshot-preview1",
]
[[package]]
@ -643,9 +642,9 @@ checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "js-sys"
version = "0.3.46"
version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175"
checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65"
dependencies = [
"wasm-bindgen",
]
@ -685,9 +684,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.82"
version = "0.2.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929"
checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
[[package]]
name = "libsqlite3-sys"
@ -713,7 +712,7 @@ dependencies = [
"hex",
"ripemd160",
"secp256k1 0.19.0",
"sha2 0.9.2",
"sha2 0.9.3",
"time",
"zcash_client_backend",
"zcash_client_sqlite",
@ -723,11 +722,11 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.13"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if 0.1.10",
"cfg-if 1.0.0",
]
[[package]]
@ -789,9 +788,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.22.0"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397"
checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
[[package]]
name = "opaque-debug"
@ -903,9 +902,9 @@ dependencies = [
[[package]]
name = "rand"
version = "0.8.2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18519b42a40024d661e1714153e9ad0c3de27cd495760ceb09710920f1098b1e"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"libc",
"rand_chacha 0.3.0",
@ -1132,18 +1131,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.120"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab"
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.120"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775"
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
dependencies = [
"proc-macro2",
"quote",
@ -1181,9 +1180,9 @@ dependencies = [
[[package]]
name = "sha2"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8"
checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
@ -1282,9 +1281,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2"
[[package]]
name = "syn"
version = "1.0.58"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5"
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
@ -1311,7 +1310,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [
"cfg-if 1.0.0",
"libc",
"rand 0.8.2",
"rand 0.8.3",
"redox_syscall 0.2.4",
"remove_dir_all",
"winapi",
@ -1328,9 +1327,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.2.24"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "273d3ed44dca264b0d6b3665e8d48fb515042d42466fad93d2a45b90ec4058f7"
checksum = "1195b046942c221454c2539395f85413b33383a067449d78aab2b7b052a142f7"
dependencies = [
"const_fn",
"libc",
@ -1429,15 +1428,15 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.1+wasi-snapshot-preview1"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93c6c3420963c5c64bca373b25e77acb562081b9bb4dd5bb864187742186cea9"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
@ -1445,9 +1444,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62"
checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7"
dependencies = [
"bumpalo",
"lazy_static",
@ -1460,9 +1459,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1470,9 +1469,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385"
dependencies = [
"proc-macro2",
"quote",
@ -1483,15 +1482,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.69"
version = "0.2.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158"
checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64"
[[package]]
name = "web-sys"
version = "0.3.46"
version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3"
checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -1528,7 +1527,6 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
[[package]]
name = "zcash_client_backend"
version = "0.4.0"
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#921d50a0096090461d8bc0489078496e48ea91ad"
dependencies = [
"base64 0.12.3",
"bech32",
@ -1551,7 +1549,6 @@ dependencies = [
[[package]]
name = "zcash_client_sqlite"
version = "0.2.1"
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#921d50a0096090461d8bc0489078496e48ea91ad"
dependencies = [
"bech32",
"bs58",
@ -1569,7 +1566,6 @@ dependencies = [
[[package]]
name = "zcash_primitives"
version = "0.4.0"
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#921d50a0096090461d8bc0489078496e48ea91ad"
dependencies = [
"aes",
"bitvec",
@ -1590,14 +1586,13 @@ dependencies = [
"rand_core 0.5.1",
"ripemd160",
"secp256k1 0.19.0",
"sha2 0.9.2",
"sha2 0.9.3",
"subtle",
]
[[package]]
name = "zcash_proofs"
version = "0.4.0"
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#921d50a0096090461d8bc0489078496e48ea91ad"
dependencies = [
"bellman",
"blake2b_simd",

View File

@ -43,10 +43,15 @@ crate-type = ["staticlib"]
lto = true
[patch.crates-io]
zcash_client_backend = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
zcash_client_sqlite = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
zcash_primitives = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
zcash_proofs = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
#zcash_client_backend = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
#zcash_client_sqlite = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
#zcash_primitives = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
#zcash_proofs = {git = "https://github.com/pacu/librustzcash", branch = "autoshield-poc" }
zcash_client_backend = { path = "/Users/pacu/Repos/ECC/pacu-librustzcash/zcash_client_backend" }
zcash_client_sqlite = { path = "/Users/pacu/Repos/ECC/pacu-librustzcash/zcash_client_sqlite" }
zcash_primitives = { path = "/Users/pacu/Repos/ECC/pacu-librustzcash/zcash_primitives" }
zcash_proofs = { path = "/Users/pacu/Repos/ECC/pacu-librustzcash/zcash_proofs" }
[features]
mainnet = ["zcash_client_sqlite/mainnet"]

View File

@ -130,9 +130,10 @@ class UnspentTransactionOutputSQLDAO: UnspentTransactionOutputRepository {
table.select(TableColumns.valueZat.sum)
.filter(TableColumns.address == address)
.filter(TableColumns.height <= latestHeight - ZcashSDK.DEFAULT_STALE_TOLERANCE)) ?? 0
let unconfirmed = try dbProvider.connection().scalar(
let total = try dbProvider.connection().scalar(
table.select(TableColumns.valueZat.sum)
.filter(TableColumns.address == address)) ?? 0
let unconfirmed = max(total - confirmed, 0)
return TransparentBalance(confirmed: Int64(confirmed), unconfirmed: Int64(unconfirmed), address: address)
} catch {

View File

@ -16,7 +16,7 @@ public extension ZcashSDK {
Returns the default fee at the time of that blockheight.
*/
func defaultFee(for height: BlockHeight) -> Int64 {
static func defaultFee(for height: BlockHeight = BlockHeight.max) -> Int64 {
guard height >= feeChangeHeight else { return 10_000 }
return 1_000
@ -24,7 +24,12 @@ public extension ZcashSDK {
/**
Estimated height where wallets are supposed to change the fee
*/
private var feeChangeHeight: BlockHeight {
ZcashSDK.isMainnet ? 1_046_400 : 1_028_500
private static var feeChangeHeight: BlockHeight {
ZcashSDK.isMainnet ? 1_077_550 : 1_028_500
}
/**
minimum balance needed to do a shielding transaction
*/
public static let shieldingThreshold: Int64 = 10000
}

View File

@ -30,6 +30,20 @@ public enum ShieldFundsError: Error {
case shieldingFailed(underlyingError: Error)
}
extension ShieldFundsError: LocalizedError {
public var errorDescription: String? {
switch self {
case .noUTXOFound:
return "Could not find UTXOs for the given t-address"
case .insuficientTransparentFunds:
return "You don't have enough confirmed transparent funds to perform a shielding transaction."
case .shieldingFailed(let underlyingError):
return "Shielding transaction failed. Reason: \(underlyingError)"
}
}
}
/**
Primary interface for interacting with the SDK. Defines the contract that specific
@ -88,9 +102,8 @@ public protocol Synchronizer {
Sends zatoshi.
- Parameter spendingKey: the key that allows spends to occur.
- Parameter transparentSecretKey: the key that allows to spend transaprent funds
- Parameter zatoshi: the amount of zatoshi to send.
- Parameter memo: the optional memo to include as part of the transaction.
- Parameter accountIndex: the optional account id to use. By default, the first account is used.
- Parameter accountIndex: the optional account id that will be used to shield your funds to. By default, the first account is used.
*/
func shieldFunds(spendingKey: String, transparentSecretKey: String, memo: String?, from accountIndex: Int, resultBlock: @escaping (_ result: Result<PendingTransactionEntity, Error>) -> Void)

View File

@ -79,8 +79,6 @@ public class SDKSynchronizer: Synchronizer {
public static let error = "SDKSynchronizer.error"
}
private static let shieldingThreshold: Int = 10000
public private(set) var status: Status {
didSet {
notify(status: status)
@ -357,7 +355,7 @@ public class SDKSynchronizer: Synchronizer {
let tAddr = try derivationTool.deriveTransparentAddressFromPrivateKey(transparentSecretKey)
let tBalance = try utxoRepository.balance(address: tAddr, latestHeight: self.latestDownloadedHeight())
guard tBalance.confirmed > Self.shieldingThreshold else {
guard tBalance.confirmed >= ZcashSDK.shieldingThreshold else {
resultBlock(.failure(ShieldFundsError.insuficientTransparentFunds))
return
}
@ -520,7 +518,14 @@ public class SDKSynchronizer: Synchronizer {
public func getUnshieldedBalance(address: String) throws -> UnshieldedBalance {
do {
let latestHeight = try self.latestDownloadedHeight()
return try utxoRepository.balance(address: address, latestHeight: latestHeight)
let cachedBalance = try utxoRepository.balance(address: address, latestHeight: latestHeight)
let pendingShieldingTxValue = try self.allPendingTransactions().filter({ (p) -> Bool in
p.isPending(currentHeight: try self.latestDownloadedHeight()) && p.toAddress == address
}).reduce(0, { (r, p) -> Int in
r + p.value
})
return TransparentBalance(confirmed: max(0,cachedBalance.confirmed - Int64(pendingShieldingTxValue)), unconfirmed: cachedBalance.unconfirmed, address: address)
} catch {
throw SynchronizerError.uncategorized(underlyingError: error)
}

View File

@ -25,7 +25,7 @@ use zcash_client_backend::{
use zcash_client_sqlite::{
error::SqliteClientError,
wallet::{
init::{init_accounts_table, init_blocks_table, init_wallet_db},
init::{init_accounts_table, init_blocks_table, init_wallet_db}
},
BlockDB, NoteId, WalletDB,
chain::get_confirmed_utxos_for_address,
@ -616,7 +616,7 @@ pub extern "C" fn zcashlc_get_received_memo_as_utf8(
let res = catch_panic(|| {
let db_data = wallet_db(NETWORK, db_data, db_data_len)?;
let memo = match (&db_data).get_received_memo_as_utf8(NoteId(id_note)) {
let memo = match (&db_data).get_memo_as_utf8(NoteId::ReceivedNoteId(id_note)) {
Ok(memo) => memo.unwrap_or_default(),
Err(e) => return Err(format_err!("Error while fetching memo: {}", e)),
};
@ -642,7 +642,7 @@ pub extern "C" fn zcashlc_get_sent_memo_as_utf8(
let db_data = wallet_db(NETWORK, db_data, db_data_len)?;
let memo = (&db_data)
.get_sent_memo_as_utf8(NoteId(id_note))
.get_memo_as_utf8(NoteId::SentNoteId(id_note))
.map(|memo| memo.unwrap_or_default())
.map_err(|e| format_err!("Error while fetching memo: {}", e))?;