Skip to content

Commit 873f236

Browse files
committed
compiles now
1 parent 7217c84 commit 873f236

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
use serde::{Deserialize, Serialize};
2-
31
pub mod proposal;
42
pub mod wallet;

crates/webzjs-wallet/src/bindgen/wallet.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::num::NonZeroU32;
22
use std::str::FromStr;
33

44
use nonempty::NonEmpty;
5-
use prost::Message;
65
use serde::{Deserialize, Serialize};
76
use wasm_bindgen::prelude::*;
87

@@ -13,15 +12,16 @@ use crate::wallet::usk_from_seed_str;
1312
use crate::{bindgen::proposal::Proposal, Wallet, PRUNING_DEPTH};
1413
use wasm_thread as thread;
1514
use webzjs_common::{Network, Pczt};
16-
use webzjs_keys::{ProofGenerationKey, SeedFingerprint, UnifiedSpendingKey};
15+
use webzjs_keys::{ProofGenerationKey, SeedFingerprint};
1716
use zcash_address::ZcashAddress;
17+
use zcash_client_backend::data_api::wallet::ConfirmationsPolicy;
1818
use zcash_client_backend::data_api::{AccountPurpose, InputSource, WalletRead, Zip32Derivation};
1919
use zcash_client_backend::proto::service::{
2020
compact_tx_streamer_client::CompactTxStreamerClient, ChainSpec,
2121
};
2222
use zcash_client_memory::MemoryWalletDb;
2323
use zcash_keys::encoding::AddressCodec;
24-
use zcash_keys::keys::UnifiedFullViewingKey;
24+
use zcash_keys::keys::{UnifiedAddressRequest, UnifiedFullViewingKey};
2525
use zcash_primitives::transaction::TxId;
2626

2727
pub type MemoryWallet<T> = Wallet<MemoryWalletDb<Network>, T>;
@@ -129,12 +129,19 @@ impl WebWallet {
129129
pub fn new(
130130
network: &str,
131131
lightwalletd_url: &str,
132-
min_confirmations: u32,
132+
min_confirmations_trusted: u32,
133+
min_confirmations_untrusted: u32,
133134
db_bytes: Option<Box<[u8]>>,
134135
) -> Result<WebWallet, Error> {
135136
let network = Network::from_str(network)?;
136-
let min_confirmations = NonZeroU32::try_from(min_confirmations)
137-
.map_err(|_| Error::InvalidMinConformations(min_confirmations))?;
137+
let min_confirmations_trusted = NonZeroU32::try_from(min_confirmations_trusted)
138+
.map_err(|_| Error::InvalidMinConformations)?;
139+
let min_confirmations_untrusted = NonZeroU32::try_from(min_confirmations_untrusted)
140+
.map_err(|_| Error::InvalidMinConformations)?;
141+
142+
let min_confirmations =
143+
ConfirmationsPolicy::new(min_confirmations_trusted, min_confirmations_untrusted, true)
144+
.map_err(|_| Error::InvalidMinConformations)?;
138145
let client = Client::new(lightwalletd_url.to_string());
139146

140147
let db = match db_bytes {
@@ -431,7 +438,10 @@ impl WebWallet {
431438
///
432439
pub async fn get_current_address(&self, account_id: u32) -> Result<String, Error> {
433440
let db = self.inner.db.read().await;
434-
if let Some(address) = db.get_current_address(account_id.into())? {
441+
if let Some(address) = db.get_last_generated_address_matching(
442+
account_id.into(),
443+
UnifiedAddressRequest::ALLOW_ALL,
444+
)? {
435445
Ok(address.encode(&self.inner.network))
436446
} else {
437447
Err(Error::AccountNotFound(account_id))
@@ -517,7 +527,10 @@ impl WebWallet {
517527
///
518528
pub async fn get_current_address_transparent(&self, account_id: u32) -> Result<String, Error> {
519529
let db = self.inner.db.read().await;
520-
if let Some(address) = db.get_current_address(account_id.into())? {
530+
if let Some(address) = db.get_last_generated_address_matching(
531+
account_id.into(),
532+
UnifiedAddressRequest::ALLOW_ALL,
533+
)? {
521534
Ok(address.transparent().unwrap().encode(&self.inner.network))
522535
} else {
523536
Err(Error::AccountNotFound(account_id))

crates/webzjs-wallet/src/error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ pub enum Error {
4141
Scan(zcash_client_backend::scanning::ScanError),
4242
#[error("IO Error: {0}")]
4343
Io(#[from] std::io::Error),
44-
#[error(
45-
"Error parsing min_confirmations argument {0}. Must be an integer > 0 (e.g. at least 1)"
46-
)]
47-
InvalidMinConformations(u32),
44+
#[error("Error parsing min_confirmations. Must be an integer > 0 (e.g. at least 1)")]
45+
InvalidMinConformations,
4846
#[error("Error parsing zatoshi amount: {0}")]
4947
InvalidAmount(#[from] zcash_protocol::value::BalanceError),
5048
#[error("Failed to send transaction")]

crates/webzjs-wallet/src/wallet.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::num::{NonZeroU32, NonZeroUsize};
1+
use std::num::NonZeroUsize;
22

33
use bip0039::{English, Mnemonic};
44
use nonempty::NonEmpty;
@@ -29,7 +29,7 @@ use zcash_address::ZcashAddress;
2929
use zcash_client_backend::data_api::wallet::{
3030
create_pczt_from_proposal, create_proposed_transactions,
3131
extract_and_store_transaction_from_pczt, input_selection::GreedyInputSelector,
32-
propose_shielding, propose_transfer,
32+
propose_shielding, propose_transfer, ConfirmationsPolicy, SpendingKeys,
3333
};
3434
use zcash_client_backend::data_api::{
3535
Account, AccountBirthday, AccountPurpose, InputSource, WalletRead, WalletSummary, WalletWrite,
@@ -88,7 +88,7 @@ pub struct Wallet<W, T> {
8888
// gRPC client used to connect to a lightwalletd instance for network data
8989
pub(crate) client: CompactTxStreamerClient<T>,
9090
pub(crate) network: Network,
91-
pub(crate) min_confirmations: NonZeroU32,
91+
pub(crate) min_confirmations: ConfirmationsPolicy,
9292
/// Note management: the number of notes to maintain in the wallet
9393
pub(crate) target_note_count: usize,
9494
/// Note management: the minimum allowed value for split change amounts
@@ -154,7 +154,7 @@ where
154154
db: W,
155155
client: T,
156156
network: Network,
157-
min_confirmations: NonZeroU32,
157+
min_confirmations: ConfirmationsPolicy,
158158
) -> Result<Self, Error> {
159159
Ok(Wallet {
160160
db: Arc::new(RwLock::new(db)),
@@ -294,7 +294,7 @@ where
294294
.db
295295
.read()
296296
.await
297-
.get_wallet_summary(self.min_confirmations.into())?)
297+
.get_wallet_summary(self.min_confirmations)?)
298298
}
299299

300300
///
@@ -330,7 +330,7 @@ where
330330
self.db
331331
.read()
332332
.await
333-
.get_target_and_anchor_heights(self.min_confirmations)?
333+
.get_target_and_anchor_heights(self.min_confirmations.trusted())?
334334
);
335335
let mut db = self.db.write().await;
336336
let proposal = propose_transfer::<_, _, _,_, <W as WalletCommitmentTrees>::Error>(
@@ -372,7 +372,7 @@ where
372372
&self.network,
373373
&prover,
374374
&prover,
375-
usk,
375+
&SpendingKeys::from_unified_spending_key(usk.clone()),
376376
OvkPolicy::Sender,
377377
&proposal,
378378
)
@@ -459,7 +459,8 @@ where
459459
}
460460
};
461461

462-
let transparent_balances = db.get_transparent_balances(account_id, max_height)?;
462+
let transparent_balances =
463+
db.get_transparent_balances(account_id, max_height.into(), self.min_confirmations)?;
463464
let from_addrs = transparent_balances.into_keys().collect::<Vec<_>>();
464465

465466
let proposal = propose_shielding::<_, _, _, _, <W as WalletCommitmentTrees>::Error>(
@@ -470,7 +471,7 @@ where
470471
SHIELDING_THRESHOLD, // use a shielding threshold above a marginal fee transaction plus some value like Zashi does.
471472
&from_addrs,
472473
account_id,
473-
1, // librustzcash operates under the assumption of zero or one conf being the same but that could change.
474+
self.min_confirmations, // librustzcash operates under the assumption of zero or one conf being the same but that could change.
474475
)
475476
.map_err(|e| Error::Generic(format!("Error when shielding: {:?}", e)))?;
476477

@@ -617,9 +618,8 @@ where
617618
let txid = extract_and_store_transaction_from_pczt::<_, ()>(
618619
&mut *db,
619620
pczt,
620-
&spend_vk,
621-
&output_vk,
622-
&orchard::circuit::VerifyingKey::build(),
621+
Some((&spend_vk, &output_vk)),
622+
Some(&orchard::circuit::VerifyingKey::build()),
623623
)
624624
.map_err(|e| {
625625
Error::PcztSend(format!(

0 commit comments

Comments
 (0)