mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-02-01 08:12:14 +00:00
Merge pull request #98 from paracetamolo/optional-sprout-parameters
Make initialization of sprout validation key optional
This commit is contained in:
commit
724e822d2d
@ -143,9 +143,13 @@ pub extern "system" fn librustzcash_init_zksnark_params(
|
|||||||
let output_path = Path::new(OsStr::from_bytes(unsafe {
|
let output_path = Path::new(OsStr::from_bytes(unsafe {
|
||||||
slice::from_raw_parts(output_path, output_path_len)
|
slice::from_raw_parts(output_path, output_path_len)
|
||||||
}));
|
}));
|
||||||
let sprout_path = Path::new(OsStr::from_bytes(unsafe {
|
let sprout_path = if sprout_path.is_null() {
|
||||||
slice::from_raw_parts(sprout_path, sprout_path_len)
|
None
|
||||||
}));
|
} else {
|
||||||
|
Some(Path::new(OsStr::from_bytes(unsafe {
|
||||||
|
slice::from_raw_parts(sprout_path, sprout_path_len)
|
||||||
|
})))
|
||||||
|
};
|
||||||
|
|
||||||
init_zksnark_params(
|
init_zksnark_params(
|
||||||
spend_path,
|
spend_path,
|
||||||
@ -174,8 +178,13 @@ pub extern "system" fn librustzcash_init_zksnark_params(
|
|||||||
OsString::from_wide(unsafe { slice::from_raw_parts(spend_path, spend_path_len) });
|
OsString::from_wide(unsafe { slice::from_raw_parts(spend_path, spend_path_len) });
|
||||||
let output_path =
|
let output_path =
|
||||||
OsString::from_wide(unsafe { slice::from_raw_parts(output_path, output_path_len) });
|
OsString::from_wide(unsafe { slice::from_raw_parts(output_path, output_path_len) });
|
||||||
let sprout_path =
|
let sprout_path = if sprout_path.is_null() {
|
||||||
OsString::from_wide(unsafe { slice::from_raw_parts(sprout_path, sprout_path_len) });
|
None
|
||||||
|
} else {
|
||||||
|
Some(OsStr::from_wide(unsafe {
|
||||||
|
slice::from_raw_parts(sprout_path, sprout_path_len)
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
|
||||||
init_zksnark_params(
|
init_zksnark_params(
|
||||||
Path::new(&spend_path),
|
Path::new(&spend_path),
|
||||||
@ -192,7 +201,7 @@ fn init_zksnark_params(
|
|||||||
spend_hash: *const c_char,
|
spend_hash: *const c_char,
|
||||||
output_path: &Path,
|
output_path: &Path,
|
||||||
output_hash: *const c_char,
|
output_hash: *const c_char,
|
||||||
sprout_path: &Path,
|
sprout_path: Option<&Path>,
|
||||||
sprout_hash: *const c_char,
|
sprout_hash: *const c_char,
|
||||||
) {
|
) {
|
||||||
// Initialize jubjub parameters here
|
// Initialize jubjub parameters here
|
||||||
@ -206,9 +215,15 @@ fn init_zksnark_params(
|
|||||||
.to_str()
|
.to_str()
|
||||||
.expect("hash should be a valid string");
|
.expect("hash should be a valid string");
|
||||||
|
|
||||||
let sprout_hash = unsafe { CStr::from_ptr(sprout_hash) }
|
let sprout_hash = if sprout_path.is_none() {
|
||||||
.to_str()
|
None
|
||||||
.expect("hash should be a valid string");
|
} else {
|
||||||
|
Some(
|
||||||
|
unsafe { CStr::from_ptr(sprout_hash) }
|
||||||
|
.to_str()
|
||||||
|
.expect("hash should be a valid string"),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
// Load params
|
// Load params
|
||||||
let (spend_params, spend_vk, output_params, output_vk, sprout_vk) = load_parameters(
|
let (spend_params, spend_vk, output_params, output_vk, sprout_vk) = load_parameters(
|
||||||
@ -216,8 +231,8 @@ fn init_zksnark_params(
|
|||||||
spend_hash,
|
spend_hash,
|
||||||
output_path,
|
output_path,
|
||||||
output_hash,
|
output_hash,
|
||||||
Some(sprout_path),
|
sprout_path,
|
||||||
Some(sprout_hash),
|
sprout_hash,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Caller is responsible for calling this function once, so
|
// Caller is responsible for calling this function once, so
|
||||||
@ -225,11 +240,11 @@ fn init_zksnark_params(
|
|||||||
unsafe {
|
unsafe {
|
||||||
SAPLING_SPEND_PARAMS = Some(spend_params);
|
SAPLING_SPEND_PARAMS = Some(spend_params);
|
||||||
SAPLING_OUTPUT_PARAMS = Some(output_params);
|
SAPLING_OUTPUT_PARAMS = Some(output_params);
|
||||||
SPROUT_GROTH16_PARAMS_PATH = Some(sprout_path.to_owned());
|
SPROUT_GROTH16_PARAMS_PATH = sprout_path.map(|p| p.to_owned());
|
||||||
|
|
||||||
SAPLING_SPEND_VK = Some(spend_vk);
|
SAPLING_SPEND_VK = Some(spend_vk);
|
||||||
SAPLING_OUTPUT_VK = Some(output_vk);
|
SAPLING_OUTPUT_VK = Some(output_vk);
|
||||||
SPROUT_GROTH16_VK = Some(sprout_vk.unwrap());
|
SPROUT_GROTH16_VK = sprout_vk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user