split send_funds function into bindgen and pure rust impl
This commit is contained in:
parent
d1a099b26f
commit
228183af23
|
@ -429,7 +429,7 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equihash"
|
name = "equihash"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#dc99e1e130e859e5f17dbdbb55cb0f505ffb37e9"
|
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#d930860b2115de4e8415429498900d9abeb4ab4e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake2b_simd",
|
"blake2b_simd",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
@ -512,9 +512,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "funty"
|
name = "funty"
|
||||||
version = "1.0.1"
|
version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ba62103ce691c2fd80fbae2213dfdda9ce60804973ac6b6e97de818ea7f52c8"
|
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures"
|
name = "futures"
|
||||||
|
@ -626,9 +626,9 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.6"
|
version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
|
@ -1092,9 +1092,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.60"
|
version = "1.0.61"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779"
|
checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
@ -1222,9 +1222,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.55"
|
version = "1.0.56"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a571a711dddd09019ccc628e1b17fe87c59b09d513c06c026877aa708334f37a"
|
checksum = "a9802ddde94170d186eeee5005b798d9c159fa970403f1be19976d0cfb939b72"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -1462,7 +1462,7 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_client_backend"
|
name = "zcash_client_backend"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#dc99e1e130e859e5f17dbdbb55cb0f505ffb37e9"
|
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#d930860b2115de4e8415429498900d9abeb4ab4e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.12.3",
|
"base64 0.12.3",
|
||||||
"bech32",
|
"bech32",
|
||||||
|
@ -1485,7 +1485,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_client_sqlite"
|
name = "zcash_client_sqlite"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#dc99e1e130e859e5f17dbdbb55cb0f505ffb37e9"
|
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#d930860b2115de4e8415429498900d9abeb4ab4e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bech32",
|
"bech32",
|
||||||
"bs58",
|
"bs58",
|
||||||
|
@ -1503,7 +1503,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_primitives"
|
name = "zcash_primitives"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#dc99e1e130e859e5f17dbdbb55cb0f505ffb37e9"
|
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#d930860b2115de4e8415429498900d9abeb4ab4e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
"aes",
|
||||||
"bitvec",
|
"bitvec",
|
||||||
|
@ -1531,7 +1531,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zcash_proofs"
|
name = "zcash_proofs"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#dc99e1e130e859e5f17dbdbb55cb0f505ffb37e9"
|
source = "git+https://github.com/pacu/librustzcash?branch=autoshield-poc#d930860b2115de4e8415429498900d9abeb4ab4e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bellman",
|
"bellman",
|
||||||
"blake2b_simd",
|
"blake2b_simd",
|
||||||
|
|
|
@ -237,18 +237,6 @@ int32_t zcashlc_scan_blocks(const uint8_t *db_cache,
|
||||||
const uint8_t *db_data,
|
const uint8_t *db_data,
|
||||||
uintptr_t db_data_len);
|
uintptr_t db_data_len);
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* psst, hey I have a Major in Social Sciences. Consider using something else
|
|
||||||
* Creates a transaction paying the specified address from the given account.
|
|
||||||
*
|
|
||||||
* Returns the row index of the newly-created transaction in the `transactions` table
|
|
||||||
* within the data database. The caller can read the raw transaction bytes from the `raw`
|
|
||||||
* column in order to broadcast the transaction to the network.
|
|
||||||
*
|
|
||||||
* Do not call this multiple times in parallel, or you will generate transactions that
|
|
||||||
* double-spend the same notes.
|
|
||||||
*/
|
|
||||||
int64_t zcashlc_shield_funds(const uint8_t *db_data,
|
int64_t zcashlc_shield_funds(const uint8_t *db_data,
|
||||||
uintptr_t db_data_len,
|
uintptr_t db_data_len,
|
||||||
const uint8_t *db_cache,
|
const uint8_t *db_cache,
|
||||||
|
|
|
@ -1042,40 +1042,19 @@ pub fn double_sha256(payload: &[u8]) -> Vec<u8> {
|
||||||
///
|
///
|
||||||
/// Do not call this multiple times in parallel, or you will generate transactions that
|
/// Do not call this multiple times in parallel, or you will generate transactions that
|
||||||
/// double-spend the same notes.
|
/// double-spend the same notes.
|
||||||
#[no_mangle]
|
///
|
||||||
pub extern "C" fn zcashlc_shield_funds(
|
///
|
||||||
db_data: *const u8,
|
|
||||||
db_data_len: usize,
|
|
||||||
db_cache: *const u8,
|
|
||||||
db_cache_len: usize,
|
|
||||||
account: i32,
|
|
||||||
tsk: *const c_char,
|
|
||||||
extsk: *const c_char,
|
|
||||||
memo: *const c_char,
|
|
||||||
spend_params: *const u8,
|
|
||||||
spend_params_len: usize,
|
|
||||||
output_params: *const u8,
|
|
||||||
output_params_len: usize,
|
|
||||||
) -> i64 {
|
|
||||||
let res = catch_panic(|| {
|
|
||||||
|
|
||||||
let db_data = wallet_db(db_data, db_data_len)?;
|
|
||||||
let db_cache = block_db(db_cache, db_cache_len)?;
|
|
||||||
let account = if account >= 0 {
|
|
||||||
account as u32
|
|
||||||
} else {
|
|
||||||
return Err(format_err!("account argument must be positive"));
|
|
||||||
};
|
|
||||||
let tsk = unsafe { CStr::from_ptr(tsk) }.to_str()?;
|
|
||||||
let extsk = unsafe { CStr::from_ptr(extsk) }.to_str()?;
|
|
||||||
let memo = unsafe { CStr::from_ptr(memo) }.to_str()?;
|
|
||||||
let spend_params = Path::new(OsStr::from_bytes(unsafe {
|
|
||||||
slice::from_raw_parts(spend_params, spend_params_len)
|
|
||||||
}));
|
|
||||||
let output_params = Path::new(OsStr::from_bytes(unsafe {
|
|
||||||
slice::from_raw_parts(output_params, output_params_len)
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
fn shield_funds(
|
||||||
|
db_cache: &BlockDB,
|
||||||
|
db_data: &WalletDB,
|
||||||
|
account: u32,
|
||||||
|
tsk: &str,
|
||||||
|
extsk: &str,
|
||||||
|
memo: &str,
|
||||||
|
spend_params: &Path,
|
||||||
|
output_params: &Path,
|
||||||
|
) -> Result<i64,failure::Error> {
|
||||||
let anchor_and_height = match (&db_data).get_target_and_anchor_heights() {
|
let anchor_and_height = match (&db_data).get_target_and_anchor_heights() {
|
||||||
Ok(Some(h)) => h,
|
Ok(Some(h)) => h,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
|
@ -1262,6 +1241,42 @@ pub extern "C" fn zcashlc_shield_funds(
|
||||||
Ok(tx_ref)
|
Ok(tx_ref)
|
||||||
})
|
})
|
||||||
.map_err(|e| format_err!("error building updating data_db {}",e))
|
.map_err(|e| format_err!("error building updating data_db {}",e))
|
||||||
|
}
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn zcashlc_shield_funds(
|
||||||
|
db_data: *const u8,
|
||||||
|
db_data_len: usize,
|
||||||
|
db_cache: *const u8,
|
||||||
|
db_cache_len: usize,
|
||||||
|
account: i32,
|
||||||
|
tsk: *const c_char,
|
||||||
|
extsk: *const c_char,
|
||||||
|
memo: *const c_char,
|
||||||
|
spend_params: *const u8,
|
||||||
|
spend_params_len: usize,
|
||||||
|
output_params: *const u8,
|
||||||
|
output_params_len: usize,
|
||||||
|
) -> i64 {
|
||||||
|
let res = catch_panic(|| {
|
||||||
|
|
||||||
|
let db_data = wallet_db(db_data, db_data_len)?;
|
||||||
|
let db_cache = block_db(db_cache, db_cache_len)?;
|
||||||
|
let account = if account >= 0 {
|
||||||
|
account as u32
|
||||||
|
} else {
|
||||||
|
return Err(format_err!("account argument must be positive"));
|
||||||
|
};
|
||||||
|
let tsk = unsafe { CStr::from_ptr(tsk) }.to_str()?;
|
||||||
|
let extsk = unsafe { CStr::from_ptr(extsk) }.to_str()?;
|
||||||
|
let memo = unsafe { CStr::from_ptr(memo) }.to_str()?;
|
||||||
|
let spend_params = Path::new(OsStr::from_bytes(unsafe {
|
||||||
|
slice::from_raw_parts(spend_params, spend_params_len)
|
||||||
|
}));
|
||||||
|
let output_params = Path::new(OsStr::from_bytes(unsafe {
|
||||||
|
slice::from_raw_parts(output_params, output_params_len)
|
||||||
|
}));
|
||||||
|
|
||||||
|
shield_funds(&db_cache, &db_data, account, &tsk, &extsk, &memo, &spend_params, &output_params)
|
||||||
});
|
});
|
||||||
unwrap_exc_or(res, -1)
|
unwrap_exc_or(res, -1)
|
||||||
}
|
}
|
Loading…
Reference in New Issue