-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
859 additions
and
27 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use gumdrop::Options; | ||
|
||
pub(crate) mod combine; | ||
pub(crate) mod create; | ||
pub(crate) mod prove; | ||
pub(crate) mod send; | ||
pub(crate) mod sign; | ||
|
||
#[derive(Debug, Options)] | ||
pub(crate) enum Command { | ||
#[options(help = "create a PCZT")] | ||
Create(create::Command), | ||
#[options(help = "create proofs for a PCZT")] | ||
Prove(prove::Command), | ||
#[options(help = "apply signatures to a PCZT")] | ||
Sign(sign::Command), | ||
#[options(help = "combine two PCZTs")] | ||
Combine(combine::Command), | ||
#[options(help = "extract a finished transaction and send it")] | ||
Send(send::Command), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::anyhow; | ||
use gumdrop::Options; | ||
use pczt::{roles::combiner::Combiner, Pczt}; | ||
use tokio::{ | ||
fs::File, | ||
io::{stdout, AsyncReadExt, AsyncWriteExt}, | ||
}; | ||
|
||
// Options accepted for the `pczt combine` command | ||
#[derive(Debug, Options)] | ||
pub(crate) struct Command { | ||
#[options(help = "a list of PCZT files to combine")] | ||
input: Vec<PathBuf>, | ||
} | ||
|
||
impl Command { | ||
pub(crate) async fn run(self) -> Result<(), anyhow::Error> { | ||
let mut pczts = vec![]; | ||
for f in self.input { | ||
let mut f = File::open(f).await?; | ||
|
||
let mut buf = vec![]; | ||
f.read_to_end(&mut buf).await?; | ||
|
||
let pczt = Pczt::parse(&buf).map_err(|e| anyhow!("Failed to read PCZT: {:?}", e))?; | ||
|
||
pczts.push(pczt); | ||
} | ||
|
||
let pczt = Combiner::new(pczts) | ||
.combine() | ||
.map_err(|e| anyhow!("Failed to combine PCZTs: {:?}", e))?; | ||
|
||
stdout().write_all(&pczt.serialize()).await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#![allow(deprecated)] | ||
use std::{num::NonZeroUsize, str::FromStr}; | ||
|
||
use anyhow::anyhow; | ||
use gumdrop::Options; | ||
|
||
use tokio::io::{stdout, AsyncWriteExt}; | ||
use zcash_address::ZcashAddress; | ||
use zcash_client_backend::{ | ||
data_api::{ | ||
wallet::{ | ||
create_pczt_from_proposal, input_selection::GreedyInputSelector, propose_transfer, | ||
}, | ||
WalletRead, | ||
}, | ||
fees::{standard::MultiOutputChangeStrategy, DustOutputPolicy, SplitPolicy, StandardFeeRule}, | ||
wallet::OvkPolicy, | ||
ShieldedProtocol, | ||
}; | ||
use zcash_client_sqlite::WalletDb; | ||
use zcash_protocol::{ | ||
memo::{Memo, MemoBytes}, | ||
value::Zatoshis, | ||
}; | ||
use zip321::{Payment, TransactionRequest}; | ||
|
||
use crate::{config::WalletConfig, data::get_db_paths, error, MIN_CONFIRMATIONS}; | ||
|
||
// Options accepted for the `pczt create` command | ||
#[derive(Debug, Options)] | ||
pub(crate) struct Command { | ||
#[options( | ||
required, | ||
help = "the recipient's Unified, Sapling or transparent address" | ||
)] | ||
address: String, | ||
|
||
#[options(required, help = "the amount in zatoshis")] | ||
value: u64, | ||
|
||
#[options(help = "a memo to send to the recipient")] | ||
memo: Option<String>, | ||
|
||
#[options( | ||
help = "note management: the number of notes to maintain in the wallet", | ||
default = "4" | ||
)] | ||
target_note_count: usize, | ||
|
||
#[options( | ||
help = "note management: the minimum allowed value for split change amounts", | ||
default = "10000000" | ||
)] | ||
min_split_output_value: u64, | ||
} | ||
|
||
impl Command { | ||
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> { | ||
let config = WalletConfig::read(wallet_dir.as_ref())?; | ||
let params = config.network(); | ||
|
||
let (_, db_data) = get_db_paths(wallet_dir.as_ref()); | ||
let mut db_data = WalletDb::for_path(db_data, params)?; | ||
let account_id = *db_data | ||
.get_account_ids()? | ||
.first() | ||
.ok_or(anyhow!("Wallet has no accounts"))?; | ||
|
||
// Create the PCZT. | ||
let change_strategy = MultiOutputChangeStrategy::new( | ||
StandardFeeRule::Zip317, | ||
None, | ||
ShieldedProtocol::Orchard, | ||
DustOutputPolicy::default(), | ||
SplitPolicy::with_min_output_value( | ||
NonZeroUsize::new(self.target_note_count) | ||
.ok_or(anyhow!("target note count must be nonzero"))?, | ||
Zatoshis::from_u64(self.min_split_output_value)?, | ||
), | ||
); | ||
let input_selector = GreedyInputSelector::new(); | ||
|
||
let request = TransactionRequest::new(vec![Payment::new( | ||
ZcashAddress::from_str(&self.address).map_err(|_| error::Error::InvalidRecipient)?, | ||
Zatoshis::from_u64(self.value).map_err(|_| error::Error::InvalidAmount)?, | ||
self.memo | ||
.map(|memo| Memo::from_str(&memo)) | ||
.transpose()? | ||
.map(MemoBytes::from), | ||
None, | ||
None, | ||
vec![], | ||
) | ||
.ok_or_else(|| anyhow!("Invalid memo"))?]) | ||
.map_err(error::Error::from)?; | ||
|
||
let proposal = propose_transfer( | ||
&mut db_data, | ||
¶ms, | ||
account_id, | ||
&input_selector, | ||
&change_strategy, | ||
request, | ||
MIN_CONFIRMATIONS, | ||
) | ||
.map_err(error::Error::from)?; | ||
|
||
let pczt = create_pczt_from_proposal( | ||
&mut db_data, | ||
¶ms, | ||
account_id, | ||
OvkPolicy::Sender, | ||
&proposal, | ||
) | ||
.map_err(error::Error::from)?; | ||
|
||
stdout().write_all(&pczt.serialize()).await?; | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.