Point to same librustzcash fork as android sdk

This commit is contained in:
Francisco Gindre 2021-11-29 13:34:26 -03:00
parent 115762bf7b
commit 582030ff59
4 changed files with 343 additions and 667 deletions

913
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,26 +12,27 @@ failure = "0.1"
ffi_helpers = "0.2"
hex = "0.4"
zcash_client_backend = "0.5"
zcash_client_sqlite = "0.3.0"
zcash_client_sqlite = "0.3"
zcash_primitives = "0.5"
zcash_note_encryption = "0.0.0"
zcash_proofs = "0.5"
#### Temporary additions: ####################################
bitvec = "0.22"
#bitvec = "0.22"
base58 = "0.1.0"
sha2 = "0.9"
bs58 = { version = "0.3", features = ["check"] }
hdwallet = "0.3.0"
ripemd160 = "0.9"
#sha2 = "0.9"
#bs58 = { version = "0.3", features = ["check"] }
#hdwallet = "0.3.0"
#ripemd160 = "0.9"
hdwallet = { git = "https://github.com/nuttycom/hdwallet", rev = "72f1f7a56c114eed484cefd6d402b7ef28158712"}
secp256k1 = "0.19"
time = "0.2"
funty = "=1.2.0"
num-bigint = "0.3.3"
##############################################################
[dependencies.zcash_proofs]
version = "0.5"
default-features = false
features = ["local-prover"]
#[dependencies.zcash_proofs]
#version = "0.5"
#default-features = false
#features = ["local-prover"]
[build-dependencies]
cbindgen = "0.14"
@ -45,20 +46,10 @@ crate-type = ["staticlib"]
lto = true
[patch.crates-io]
zcash_client_backend = {git = "https://github.com/nuttycom/librustzcash", rev = "7d819b68a3da3ad568629bc6f51a63e39c2d7d6a" }
zcash_client_sqlite = {git = "https://github.com/nuttycom/librustzcash", rev = "7d819b68a3da3ad568629bc6f51a63e39c2d7d6a" }
zcash_primitives = {git = "https://github.com/nuttycom/librustzcash", rev = "7d819b68a3da3ad568629bc6f51a63e39c2d7d6a" }
zcash_proofs = {git = "https://github.com/nuttycom/librustzcash", rev = "7d819b68a3da3ad568629bc6f51a63e39c2d7d6a" }
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "13b023387bafdc7b5712c933dc0e16ee94b96a6a" }
# In development.
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "27c4187673a9c6ade13fbdbd4f20955530c22d7f" }
orchard = { git = "https://github.com/zcash/orchard.git", rev = "d0baa18fc6105df4a7847de2b6dc50c5919b3123" }
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
# Unreleased
jubjub = { git = "https://github.com/zkcrypto/jubjub.git", rev = "96ab4162b83303378eae32a326b54d88b75bffc2" }
zcash_client_backend = {git = "https://github.com/gmale/librustzcash", branch = "autoshield-poc-daa-taddr3"}
zcash_client_sqlite = {git = "https://github.com/gmale/librustzcash", branch = "autoshield-poc-daa-taddr3"}
zcash_primitives = {git = "https://github.com/gmale/librustzcash", branch = "autoshield-poc-daa-taddr3"}
zcash_proofs = {git = "https://github.com/gmale/librustzcash", branch = "autoshield-poc-daa-taddr3"}
[features]
mainnet = ["zcash_client_sqlite/mainnet"]

View File

@ -53,7 +53,7 @@ int32_t zcashlc_decrypt_and_store_transaction(const uint8_t *db_data,
uintptr_t db_data_len,
const uint8_t *tx,
uintptr_t tx_len,
uint32_t mined_height,
uint32_t _mined_height,
uint32_t network_id);
/**

View File

@ -53,8 +53,6 @@ use zcash_primitives::consensus::Network::{MainNetwork, TestNetwork};
use zcash_proofs::prover::LocalTxProver;
use std::convert::{TryFrom, TryInto};
use base58::ToBase58;
use sha2::{Digest, Sha256};
use secp256k1::key::{SecretKey, PublicKey};
const ANCHOR_OFFSET: u32 = 10;
@ -729,7 +727,7 @@ pub extern "C" fn zcashlc_get_verified_balance(
let db_data = wallet_db(db_data, db_data_len, network)?;
if account >= 0 {
(&db_data)
.get_target_and_anchor_heights(ANCHOR_OFFSET)
.get_target_and_anchor_heights()
.map_err(|e| format_err!("Error while fetching anchor height: {}", e))
.and_then(|opt_anchor| {
opt_anchor
@ -764,7 +762,7 @@ pub extern "C" fn zcashlc_get_verified_transparent_balance(
let addr = unsafe { CStr::from_ptr(address).to_str()? };
let taddr = TransparentAddress::decode(&network, &addr).unwrap();
let amount = (&db_data)
.get_target_and_anchor_heights(ANCHOR_OFFSET)
.get_target_and_anchor_heights()
.map_err(|e| format_err!("Error while fetching anchor height: {}", e))
.and_then(|opt_anchor| {
opt_anchor
@ -778,7 +776,7 @@ pub extern "C" fn zcashlc_get_verified_transparent_balance(
})?
.iter()
.map(|utxo| utxo.value)
.sum::<Option<Amount>>().unwrap();
.sum::<Amount>();
Ok(amount.into())
});
@ -800,7 +798,7 @@ pub extern "C" fn zcashlc_get_total_transparent_balance(
let addr = unsafe { CStr::from_ptr(address).to_str()? };
let taddr = TransparentAddress::decode(&network, &addr).unwrap();
let amount = (&db_data)
.get_target_and_anchor_heights(ANCHOR_OFFSET)
.get_target_and_anchor_heights()
.map_err(|e| format_err!("Error while fetching anchor height: {}", e))
.and_then(|opt_anchor| {
opt_anchor
@ -814,7 +812,7 @@ pub extern "C" fn zcashlc_get_total_transparent_balance(
})?
.iter()
.map(|utxo| utxo.value)
.sum::<Option<Amount>>().unwrap();
.sum::<Amount>();
Ok(amount.into())
});
@ -1103,17 +1101,15 @@ pub extern "C" fn zcashlc_decrypt_and_store_transaction(
db_data_len: usize,
tx: *const u8,
tx_len: usize,
mined_height: u32,
_mined_height: u32,
network_id: u32,
) -> i32 {
let res = catch_panic(|| {
let network = parse_network(network_id)?;
let db_read = wallet_db(db_data, db_data_len, network)?;
let mut db_data = db_read.get_update_ops()?;
let block_height = BlockHeight::from_u32(mined_height);
let branch_id = BranchId::for_height(&network,block_height);
let tx_bytes = unsafe { slice::from_raw_parts(tx, tx_len) };
let tx = Transaction::read(&tx_bytes[..],branch_id)?;
let tx = Transaction::read(&tx_bytes[..])?;
match decrypt_and_store_transaction(&network, &mut db_data, &tx) {
Ok(()) => Ok(1),
@ -1209,8 +1205,8 @@ pub extern "C" fn zcashlc_create_to_address(
&to,
value,
memo,
OvkPolicy::Sender,
ANCHOR_OFFSET)
OvkPolicy::Sender
)
.map_err(|e| format_err!("Error while sending funds: {}", e))
});
unwrap_exc_or(res, -1)
@ -1420,34 +1416,4 @@ fn parse_network(value: u32) -> Result<Network, failure::Error> {
1 => Ok(MainNetwork),
_ => Err(format_err!("Invalid network type: {}. Expected either 0 or 1 for Testnet or Mainnet, respectively.", value))
}
}
//
// Helper code from: https://github.com/adityapk00/zecwallet-light-cli/blob/master/lib/src/lightwallet.rs
//
/// A trait for converting a [u8] to base58 encoded string.
pub trait ToBase58Check {
/// Converts a value of `self` to a base58 value, returning the owned string.
/// The version is a coin-specific prefix that is added.
/// The suffix is any bytes that we want to add at the end (like the "iscompressed" flag for
/// Secret key encoding)
fn to_base58check(&self, version: &[u8], suffix: &[u8]) -> String;
}
impl ToBase58Check for [u8] {
fn to_base58check(&self, version: &[u8], suffix: &[u8]) -> String {
let mut payload: Vec<u8> = Vec::new();
payload.extend_from_slice(version);
payload.extend_from_slice(self);
payload.extend_from_slice(suffix);
let checksum = double_sha256(&payload);
payload.append(&mut checksum[..4].to_vec());
payload.to_base58()
}
}
pub fn double_sha256(payload: &[u8]) -> Vec<u8> {
let h1 = Sha256::digest(&payload);
let h2 = Sha256::digest(&h1);
h2.to_vec()
}