-
Notifications
You must be signed in to change notification settings - Fork 25
APIs for disbursement #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| use std::str::FromStr; | ||
|
|
||
| use clap::Args; | ||
| use rand::rngs::OsRng; | ||
| use tokio::io::{stdout, AsyncWriteExt}; | ||
| use uuid::Uuid; | ||
|
|
||
| use zcash_address::ZcashAddress; | ||
| use zcash_client_backend::{ | ||
| data_api::{ | ||
| wallet::{create_pczt_from_proposal, propose_send_max_transfer, ConfirmationsPolicy}, | ||
| Account as _, MaxSpendMode, | ||
| }, | ||
| fees::StandardFeeRule, | ||
| wallet::OvkPolicy, | ||
| }; | ||
| use zcash_client_sqlite::{util::SystemClock, WalletDb}; | ||
| use zcash_protocol::{ | ||
| memo::{Memo, MemoBytes}, | ||
| ShieldedProtocol, | ||
| }; | ||
|
|
||
| use crate::{commands::select_account, config::WalletConfig, data::get_db_paths, error}; | ||
|
|
||
| // Options accepted for the `pczt create-max` command | ||
| #[derive(Debug, Args)] | ||
| pub(crate) struct Command { | ||
| /// The UUID of the account to send funds from | ||
| account_id: Option<Uuid>, | ||
|
|
||
| /// The recipient's Unified, Sapling or transparent address | ||
| #[arg(long)] | ||
| address: String, | ||
|
|
||
| /// A memo to send to the recipient | ||
| #[arg(long)] | ||
| memo: Option<String>, | ||
|
|
||
| /// Spend all _currently_ spendable funds where it could be the case that the wallet | ||
| /// has received other funds that are not confirmed and therefore not spendable yet | ||
| /// and the caller evaluates that as an acceptable scenario. | ||
| /// | ||
| /// Default is to spend **all funds**, failing if there are unspendable funds in the | ||
| /// wallet or if the wallet is not yet synced. | ||
| #[arg(long)] | ||
| only_spendable: bool, | ||
| } | ||
|
|
||
| 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, SystemClock, OsRng)?; | ||
| let account = select_account(&db_data, self.account_id)?; | ||
|
|
||
| let recipient = | ||
| ZcashAddress::from_str(&self.address).map_err(|_| error::Error::InvalidRecipient)?; | ||
| let memo = self | ||
| .memo | ||
| .map(|memo| Memo::from_str(&memo)) | ||
| .transpose()? | ||
| .map(MemoBytes::from); | ||
| let mode = if self.only_spendable { | ||
| MaxSpendMode::MaxSpendable | ||
| } else { | ||
| MaxSpendMode::Everything | ||
| }; | ||
|
|
||
| // Create the PCZT. | ||
| let proposal = propose_send_max_transfer( | ||
| &mut db_data, | ||
| ¶ms, | ||
| account.id(), | ||
| &[ShieldedProtocol::Sapling, ShieldedProtocol::Orchard], | ||
| &StandardFeeRule::Zip317, | ||
| recipient, | ||
| memo, | ||
| mode, | ||
| ConfirmationsPolicy::default(), | ||
| ) | ||
| .map_err(error::Error::SendMax)?; | ||
|
|
||
| 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(()) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume that this is required for the shielding operation? Does
propose_send_max_transferspend transparent UTXOs?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, actually, I guess it's for the spend that's required to return the shielded UTXO to the transparent multisig address?