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::path::Path;
|
||||
|
||||
#[cfg(feature = "directories")]
|
||||
use directories::BaseDirs;
|
||||
#[cfg(feature = "directories")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod circuit;
|
||||
mod hashreader;
|
||||
pub mod sapling;
|
||||
|
@ -20,6 +25,22 @@ pub mod sprout;
|
|||
#[cfg(feature = "local-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(
|
||||
spend_path: &Path,
|
||||
output_path: &Path,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! Abstractions over the proving system and parameters for ease of use.
|
||||
|
||||
use bellman::groth16::{Parameters, PreparedVerifyingKey};
|
||||
use directories::BaseDirs;
|
||||
use pairing::bls12_381::{Bls12, Fr};
|
||||
use std::path::Path;
|
||||
use zcash_primitives::{
|
||||
|
@ -17,7 +16,10 @@ use zcash_primitives::{
|
|||
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
|
||||
/// locally-accessible paths.
|
||||
|
@ -78,18 +80,11 @@ impl LocalTxProver {
|
|||
/// This function will panic if the parameters in the default local location do not
|
||||
/// have the expected hashes.
|
||||
pub fn with_default_location() -> Option<Self> {
|
||||
let base_dirs = BaseDirs::new()?;
|
||||
let unix_params_dir = base_dirs.home_dir().join(".zcash-params");
|
||||
let win_osx_params_dir = base_dirs.data_dir().join("ZcashParams");
|
||||
let (spend_path, output_path) = if unix_params_dir.exists() {
|
||||
let params_dir = default_params_folder()?;
|
||||
let (spend_path, output_path) = if params_dir.exists() {
|
||||
(
|
||||
unix_params_dir.join("sapling-spend.params"),
|
||||
unix_params_dir.join("sapling-output.params"),
|
||||
)
|
||||
} else if win_osx_params_dir.exists() {
|
||||
(
|
||||
win_osx_params_dir.join("sapling-spend.params"),
|
||||
win_osx_params_dir.join("sapling-output.params"),
|
||||
params_dir.join(SAPLING_SPEND_NAME),
|
||||
params_dir.join(SAPLING_OUTPUT_NAME),
|
||||
)
|
||||
} else {
|
||||
return None;
|
||||
|
|
Loading…
Reference in New Issue