zcash_proofs: Extract default params folder logic
This commit is contained in:
parent
0a61db0317
commit
e910788e8e
|
@ -12,6 +12,11 @@ use std::fs::File;
|
||||||
use std::io::{self, BufReader};
|
use std::io::{self, BufReader};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[cfg(feature = "directories")]
|
||||||
|
use directories::BaseDirs;
|
||||||
|
#[cfg(feature = "directories")]
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub mod circuit;
|
pub mod circuit;
|
||||||
mod hashreader;
|
mod hashreader;
|
||||||
pub mod sapling;
|
pub mod sapling;
|
||||||
|
@ -20,6 +25,22 @@ pub mod sprout;
|
||||||
#[cfg(feature = "local-prover")]
|
#[cfg(feature = "local-prover")]
|
||||||
pub mod prover;
|
pub mod prover;
|
||||||
|
|
||||||
|
// Circuit names
|
||||||
|
const SAPLING_SPEND_NAME: &str = "sapling-spend.params";
|
||||||
|
const SAPLING_OUTPUT_NAME: &str = "sapling-output.params";
|
||||||
|
|
||||||
|
/// Returns the default folder that the Zcash proving parameters are located in.
|
||||||
|
#[cfg(feature = "directories")]
|
||||||
|
fn default_params_folder() -> Option<PathBuf> {
|
||||||
|
BaseDirs::new().map(|base_dirs| {
|
||||||
|
if cfg!(any(windows, target_os = "macos")) {
|
||||||
|
base_dirs.data_dir().join("ZcashParams")
|
||||||
|
} else {
|
||||||
|
base_dirs.home_dir().join(".zcash-params")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_parameters(
|
pub fn load_parameters(
|
||||||
spend_path: &Path,
|
spend_path: &Path,
|
||||||
output_path: &Path,
|
output_path: &Path,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Abstractions over the proving system and parameters for ease of use.
|
//! Abstractions over the proving system and parameters for ease of use.
|
||||||
|
|
||||||
use bellman::groth16::{Parameters, PreparedVerifyingKey};
|
use bellman::groth16::{Parameters, PreparedVerifyingKey};
|
||||||
use directories::BaseDirs;
|
|
||||||
use pairing::bls12_381::{Bls12, Fr};
|
use pairing::bls12_381::{Bls12, Fr};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use zcash_primitives::{
|
use zcash_primitives::{
|
||||||
|
@ -17,7 +16,10 @@ use zcash_primitives::{
|
||||||
JUBJUB,
|
JUBJUB,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{load_parameters, sapling::SaplingProvingContext};
|
use crate::{
|
||||||
|
default_params_folder, load_parameters, sapling::SaplingProvingContext, SAPLING_OUTPUT_NAME,
|
||||||
|
SAPLING_SPEND_NAME,
|
||||||
|
};
|
||||||
|
|
||||||
/// An implementation of [`TxProver`] using Sapling Spend and Output parameters from
|
/// An implementation of [`TxProver`] using Sapling Spend and Output parameters from
|
||||||
/// locally-accessible paths.
|
/// locally-accessible paths.
|
||||||
|
@ -78,18 +80,11 @@ impl LocalTxProver {
|
||||||
/// This function will panic if the parameters in the default local location do not
|
/// This function will panic if the parameters in the default local location do not
|
||||||
/// have the expected hashes.
|
/// have the expected hashes.
|
||||||
pub fn with_default_location() -> Option<Self> {
|
pub fn with_default_location() -> Option<Self> {
|
||||||
let base_dirs = BaseDirs::new()?;
|
let params_dir = default_params_folder()?;
|
||||||
let unix_params_dir = base_dirs.home_dir().join(".zcash-params");
|
let (spend_path, output_path) = if params_dir.exists() {
|
||||||
let win_osx_params_dir = base_dirs.data_dir().join("ZcashParams");
|
|
||||||
let (spend_path, output_path) = if unix_params_dir.exists() {
|
|
||||||
(
|
(
|
||||||
unix_params_dir.join("sapling-spend.params"),
|
params_dir.join(SAPLING_SPEND_NAME),
|
||||||
unix_params_dir.join("sapling-output.params"),
|
params_dir.join(SAPLING_OUTPUT_NAME),
|
||||||
)
|
|
||||||
} else if win_osx_params_dir.exists() {
|
|
||||||
(
|
|
||||||
win_osx_params_dir.join("sapling-spend.params"),
|
|
||||||
win_osx_params_dir.join("sapling-output.params"),
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
|
|
Loading…
Reference in New Issue