Skip to content

Commit

Permalink
Merge pull request #954 from fluidvanadium/add_latest_proposal_3
Browse files Browse the repository at this point in the history
Add latest proposal 3
  • Loading branch information
zancas authored Apr 18, 2024
2 parents 6e33792 + 41c0b0e commit bc0b438
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
3 changes: 2 additions & 1 deletion zingolib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

All notable changes to this project will be documented in this file.
All notable changes to this crate will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
Expand All @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `commands`:
- `ProposeCommand` struct and methods behind "zip317" feature
- `QuickSendCommand` struct and methods behind "zip317" feature
- `data::proposal` mod

- `test_framework` mod behind "test-features" feature

Expand Down
4 changes: 2 additions & 2 deletions zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ impl Command for ProposeCommand {
};
RT.block_on(async move {
match lightclient
.do_propose(
.do_propose_spend(
send_inputs
.iter()
.map(|(address, amount, memo)| (address.as_str(), *amount, memo.clone()))
Expand Down Expand Up @@ -963,7 +963,7 @@ impl Command for QuickSendCommand {
};
RT.block_on(async move {
if let Err(e) = lightclient
.do_propose(
.do_propose_spend(
send_inputs
.iter()
.map(|(address, amount, memo)| (address.as_str(), *amount, memo.clone()))
Expand Down
5 changes: 3 additions & 2 deletions zingolib/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! TODO: Add Mod Description Here!
//! This is a mod for data structs that will be used across all sections of zingolib.
#[cfg(feature = "zip317")]
pub mod proposal;
pub mod witness_trees;
29 changes: 29 additions & 0 deletions zingolib/src/data/proposal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! The types of transaction Proposal that Zingo! uses.
use std::convert::Infallible;

use zcash_client_backend::proposal::Proposal;
use zcash_primitives::transaction::fees::zip317::FeeRule;

use crate::wallet::notes::NoteRecordIdentifier;

/// A proposed send to addresses.
/// Identifies the notes to spend by txid, pool, and output_index.
pub(crate) type TransferProposal = Proposal<FeeRule, NoteRecordIdentifier>;
/// A proposed shielding.
/// The zcash_client_backend Proposal type exposes a "NoteRef" generic
/// parameter to track Shielded inputs to the proposal these are
/// disallowed in Zingo ShieldedProposals
pub(crate) type ShieldProposal = Proposal<FeeRule, Infallible>;

/// The LightClient holds one proposal at a time while the user decides whether to accept the fee.
#[derive(Clone)]
pub(crate) enum ZingoProposal {
/// Destination somewhere else.
/// Can propose any valid recipient.
#[allow(dead_code)] // TOdo use it
Transfer(TransferProposal),
/// For now this is constrained by lrz zcash_client_backend transaction construction
/// to send to the proposing capability's receiver for its fanciest shielded pool
#[allow(dead_code)] // TOdo construct it
Shield(ShieldProposal),
}
11 changes: 10 additions & 1 deletion zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use crate::{
wallet::{keys::unified::ReceiverSelection, message::Message, LightWallet, SendProgress},
};

#[cfg(feature = "zip317")]
use crate::data::proposal::ZingoProposal;

/// TODO: Add Doc Comment Here!
#[derive(Clone, Debug, Default)]
pub struct SyncResult {
Expand Down Expand Up @@ -232,6 +235,9 @@ pub struct LightClient {
bsync_data: Arc<RwLock<BlazeSyncData>>,
interrupt_sync: Arc<RwLock<bool>>,

#[cfg(feature = "zip317")]
latest_proposal: Arc<RwLock<Option<ZingoProposal>>>,

save_buffer: ZingoSaveBuffer,
}

Expand All @@ -256,8 +262,9 @@ pub mod instantiation {
};

impl LightClient {
/// this is the standard initializer for a LightClient.
// toDo rework ZingoConfig.

/// This is the fundamental invocation of a LightClient. It lives in an asyncronous runtime.
pub async fn create_from_wallet_async(
wallet: LightWallet,
config: ZingoConfig,
Expand All @@ -271,6 +278,8 @@ pub mod instantiation {
sync_lock: Mutex::new(()),
bsync_data: Arc::new(RwLock::new(BlazeSyncData::new(&config))),
interrupt_sync: Arc::new(RwLock::new(false)),
#[cfg(feature = "zip317")]
latest_proposal: Arc::new(RwLock::new(None)),
save_buffer: ZingoSaveBuffer::new(buffer),
})
}
Expand Down
42 changes: 32 additions & 10 deletions zingolib/src/lightclient/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ use super::{LightClient, LightWalletSendProgress};
use crate::wallet::Pool;

#[cfg(feature = "zip317")]
use {
crate::wallet::notes::NoteRecordIdentifier,
zcash_client_backend::proposal::Proposal,
zcash_primitives::transaction::{fees::zip317::FeeRule, TxId},
};
use zcash_primitives::transaction::TxId;

impl LightClient {
async fn get_submission_height(&self) -> Result<BlockHeight, String> {
Expand Down Expand Up @@ -63,23 +59,49 @@ impl LightClient {
}

/// Unstable function to expose the zip317 interface for development
// TODO: add correct functionality and doc comments / tests
// TOdo: add correct functionality and doc comments / tests
// TODO: Add migrate_sapling_to_orchard argument
#[cfg(feature = "zip317")]
pub async fn do_propose(
pub async fn do_propose_spend(
&self,
_address_amount_memo_tuples: Vec<(&str, u64, Option<MemoBytes>)>,
) -> Result<Proposal<FeeRule, NoteRecordIdentifier>, String> {
) -> Result<crate::data::proposal::TransferProposal, String> {
use crate::test_framework::mocks::ProposalBuilder;

Ok(ProposalBuilder::default().build())
let proposal = ProposalBuilder::default().build();
let mut latest_proposal_lock = self.latest_proposal.write().await;
*latest_proposal_lock = Some(crate::data::proposal::ZingoProposal::Transfer(
proposal.clone(),
));
Ok(proposal)
}

/// Unstable function to expose the zip317 interface for development
// TOdo: add correct functionality and doc comments / tests
#[cfg(feature = "zip317")]
pub async fn do_propose_shield(
&self,
_address_amount_memo_tuples: Vec<(&str, u64, Option<MemoBytes>)>,
) -> Result<crate::data::proposal::ShieldProposal, String> {
todo!()
}

/// Unstable function to expose the zip317 interface for development
// TODO: add correct functionality and doc comments / tests
#[cfg(feature = "zip317")]
pub async fn do_send_proposal(&self) -> Result<Vec<TxId>, String> {
Ok(vec![TxId::from_bytes([0u8; 32])])
if let Some(proposal) = self.latest_proposal.read().await.as_ref() {
match proposal {
crate::lightclient::ZingoProposal::Transfer(_) => {
Ok(vec![TxId::from_bytes([1u8; 32])])
}
crate::lightclient::ZingoProposal::Shield(_) => {
Ok(vec![TxId::from_bytes([222u8; 32])])
}
}
} else {
Err("No proposal. Call do_propose first.".to_string())
}
}

/// TODO: Add migrate_sapling_to_orchard argument
Expand Down

0 comments on commit bc0b438

Please sign in to comment.