Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/commands/pczt/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub(crate) struct Command {
/// A list of PCZT files to combine
#[arg(short, long)]
input: Vec<PathBuf>,

/// Path to a file to which to write the combined PCZT. If not provided, writes to stdout.
#[arg(short, long)]
output: Option<PathBuf>,
}

impl Command {
Expand All @@ -34,7 +38,16 @@ impl Command {
.combine()
.map_err(|e| anyhow!("Failed to combine PCZTs: {:?}", e))?;

stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
22 changes: 19 additions & 3 deletions src/commands/pczt/create.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#![allow(deprecated)]
use std::{num::NonZeroUsize, str::FromStr};
use std::{num::NonZeroUsize, path::PathBuf, str::FromStr};

use anyhow::anyhow;
use clap::Args;
use rand::rngs::OsRng;
use tokio::io::{stdout, AsyncWriteExt};
use tokio::{
fs::File,
io::{stdout, AsyncWriteExt},
};
use uuid::Uuid;

use zcash_address::ZcashAddress;
Expand Down Expand Up @@ -56,6 +59,10 @@ pub(crate) struct Command {
#[arg(long)]
#[arg(default_value_t = 10000000)]
min_split_output_value: u64,

/// Path to a file to which to write the PCZT. If not provided, writes to stdout.
#[arg(long)]
output: Option<PathBuf>,
}

impl Command {
Expand Down Expand Up @@ -115,7 +122,16 @@ impl Command {
)
.map_err(error::Error::from)?;

stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
22 changes: 19 additions & 3 deletions src/commands/pczt/create_manual.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#![allow(deprecated)]
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use anyhow::anyhow;
use clap::Args;
use pczt::roles::{creator::Creator, io_finalizer::IoFinalizer, updater::Updater};
use rand::rngs::OsRng;
use tokio::io::{stdout, AsyncWriteExt};
use tokio::{
fs::File,
io::{stdout, AsyncWriteExt},
};
use transparent::builder::TransparentInputInfo;

use zcash_address::ZcashAddress;
Expand Down Expand Up @@ -66,6 +69,10 @@ pub(crate) struct Command {

#[command(flatten)]
connection: ConnectionArgs,

/// Path to a file to which to write the PCZT. If not provided, writes to stdout.
#[arg(long)]
output: Option<PathBuf>,
}

impl Command {
Expand Down Expand Up @@ -254,7 +261,16 @@ impl Command {
)?
.finish();

stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
22 changes: 19 additions & 3 deletions src/commands/pczt/create_max.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::str::FromStr;
use std::{path::PathBuf, str::FromStr};

use clap::Args;
use rand::rngs::OsRng;
use tokio::io::{stdout, AsyncWriteExt};
use tokio::{
fs::File,
io::{stdout, AsyncWriteExt},
};
use uuid::Uuid;

use zcash_address::ZcashAddress;
Expand Down Expand Up @@ -44,6 +47,10 @@ pub(crate) struct Command {
/// wallet or if the wallet is not yet synced.
#[arg(long)]
only_spendable: bool,

/// Path to a file to which to write the PCZT. If not provided, writes to stdout.
#[arg(long)]
output: Option<PathBuf>,
}

impl Command {
Expand Down Expand Up @@ -91,7 +98,16 @@ impl Command {
)
.map_err(error::Error::from)?;

stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
16 changes: 13 additions & 3 deletions src/commands/pczt/inspect.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::collections::BTreeMap;
use std::{collections::BTreeMap, path::PathBuf};

use anyhow::anyhow;
use clap::Args;
use pczt::{roles::verifier::Verifier, Pczt};
use secrecy::ExposeSecret;
use tokio::io::{stdin, AsyncReadExt};
use tokio::{
fs::File,
io::{stdin, AsyncReadExt},
};

use ::transparent::sighash::SighashType;
use transparent::address::TransparentAddress;
Expand All @@ -27,6 +30,9 @@ pub(crate) struct Command {
/// age identity file to decrypt the mnemonic phrase with (if a wallet is provided)
#[arg(short, long)]
identity: Option<String>,

/// Path to a file from which to read the PCZT. If not provided, reads from stdin.
input: Option<PathBuf>,
}

impl Command {
Expand All @@ -39,7 +45,11 @@ impl Command {
}?;

let mut buf = vec![];
stdin().read_to_end(&mut buf).await?;
if let Some(input_path) = &self.input {
File::open(input_path).await?.read_to_end(&mut buf).await?;
} else {
stdin().read_to_end(&mut buf).await?;
}

let pczt = Pczt::parse(&buf).map_err(|e| anyhow!("Failed to read PCZT: {:?}", e))?;

Expand Down
22 changes: 19 additions & 3 deletions src/commands/pczt/pay_manual.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::{collections::BTreeMap, convert::Infallible};
use std::{collections::BTreeMap, convert::Infallible, path::PathBuf};

use anyhow::anyhow;
use clap::Args;
use pczt::roles::{creator::Creator, io_finalizer::IoFinalizer, updater::Updater};
use rand::rngs::OsRng;
use tokio::io::{stdout, AsyncWriteExt};
use tokio::{
fs::File,
io::{stdout, AsyncWriteExt},
};

use transparent::{builder::TransparentInputInfo, bundle::TxOut};
use zcash_client_backend::{
Expand Down Expand Up @@ -65,6 +68,10 @@ pub(crate) struct Command {

#[command(flatten)]
connection: ConnectionArgs,

/// Path to a file to which to write the PCZT. If not provided, writes to stdout.
#[arg(long)]
output: Option<PathBuf>,
}

impl Command {
Expand Down Expand Up @@ -351,7 +358,16 @@ impl Command {
}

let pczt = updater.finish();
stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
31 changes: 28 additions & 3 deletions src/commands/pczt/prove.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use anyhow::anyhow;
use clap::Args;
use pczt::{
Expand All @@ -6,7 +8,10 @@ use pczt::{
};
use sapling::ProofGenerationKey;
use secrecy::{ExposeSecret, SecretVec};
use tokio::io::{stdin, stdout, AsyncReadExt, AsyncWriteExt};
use tokio::{
fs::File,
io::{stdin, stdout, AsyncReadExt, AsyncWriteExt},
};
use zcash_keys::keys::UnifiedSpendingKey;
use zcash_proofs::prover::LocalTxProver;
use zcash_protocol::consensus::{NetworkConstants, Parameters};
Expand All @@ -25,12 +30,23 @@ pub(crate) struct Command {
/// age identity file to decrypt the mnemonic phrase with for deriving the Sapling proof generation key
#[arg(short, long)]
identity: Option<String>,

/// Path to a file from which to read the PCZT. If not provided, reads from stdin.
input: Option<PathBuf>,

/// Path to a file to which to write the PCZT. If not provided, writes to stdout.
#[arg(long)]
output: Option<PathBuf>,
}

impl Command {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let mut buf = vec![];
stdin().read_to_end(&mut buf).await?;
if let Some(input_path) = &self.input {
File::open(input_path).await?.read_to_end(&mut buf).await?;
} else {
stdin().read_to_end(&mut buf).await?;
}

let pczt = Pczt::parse(&buf).map_err(|e| anyhow!("Failed to read PCZT: {:?}", e))?;

Expand Down Expand Up @@ -179,7 +195,16 @@ impl Command {
.map_err(|e| anyhow!("Failed to create Sapling proofs: {:?}", e))?
.finish();

stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
31 changes: 27 additions & 4 deletions src/commands/pczt/qr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{path::PathBuf, time::Duration};

use anyhow::anyhow;
use clap::Args;
Expand All @@ -12,7 +12,10 @@ use nokhwa::{
};
use pczt::Pczt;
use qrcode::{render::unicode, QrCode};
use tokio::io::{stdin, stdout, AsyncReadExt, AsyncWriteExt, Stdout};
use tokio::{
fs::File,
io::{stdin, stdout, AsyncReadExt, AsyncWriteExt, Stdout},
};

use crate::ShutdownListener;

Expand All @@ -37,6 +40,9 @@ pub(crate) struct Send {
#[cfg(feature = "tui")]
#[arg(long)]
pub(crate) tui: bool,

/// Path to a file from which to read the PCZT. If not provided, reads from stdin.
input: Option<PathBuf>,
}

impl Send {
Expand All @@ -46,7 +52,11 @@ impl Send {
#[cfg(feature = "tui")] tui: Tui,
) -> Result<(), anyhow::Error> {
let mut buf = vec![];
stdin().read_to_end(&mut buf).await?;
if let Some(input_path) = &self.input {
File::open(input_path).await?.read_to_end(&mut buf).await?;
} else {
stdin().read_to_end(&mut buf).await?;
}

let pczt = Pczt::parse(&buf).map_err(|e| anyhow!("Failed to read PCZT: {:?}", e))?;

Expand Down Expand Up @@ -129,6 +139,10 @@ pub(crate) struct Receive {
#[arg(long)]
#[arg(default_value_t = 500)]
interval: u64,

/// Path to a file to which to write the PCZT. If not provided, writes to stdout.
#[arg(long)]
output: Option<PathBuf>,
}

impl Receive {
Expand Down Expand Up @@ -219,7 +233,16 @@ impl Receive {
)
.map_err(|e| anyhow!("Failed to read PCZT from QR codes: {:?}", e))?;

stdout().write_all(&pczt.serialize()).await?;
if let Some(output_path) = &self.output {
File::create(output_path)
.await?
.write_all(&pczt.serialize())
.await?;
} else {
let mut stdout = stdout();
stdout.write_all(&pczt.serialize()).await?;
stdout.flush().await?;
}

Ok(())
}
Expand Down
Loading