Skip to content

Commit 98a1237

Browse files
authored
Merge pull request #107 from pacu/propose-shield-fixes
Propose shield fixes
2 parents 8312ccb + e13eafa commit 98a1237

11 files changed

Lines changed: 46 additions & 30 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ zcash_primitives = { git = "https://github.com/ChainSafe/librustzcash", rev = "4
3939
zcash_address = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090" }
4040
zcash_proofs = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["bundled-prover", "multicore"] }
4141
zip321 = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090" }
42+
zip32 = { version = "0.1.3" }
4243
zcash_protocol = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false }
4344
pczt = { git = "https://github.com/ChainSafe/librustzcash", rev = "46e8ee0937b61fdbb417df7c663f62e6945d8090", default-features = false, features = ["orchard", "sapling", "transparent"] }
4445
sapling = { package = "sapling-crypto", version = "0.4", default-features = false }

crates/webzjs-common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ edition = "2021"
1111
serde.workspace = true
1212
zcash_primitives.workspace = true
1313
zcash_address.workspace = true
14+
zcash_protocol.workspace = true
1415
thiserror.workspace = true
1516
wasm-bindgen.workspace = true
1617
js-sys.workspace = true

crates/webzjs-common/src/network.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::error::Error;
55
use serde::{Deserialize, Serialize};
66
use std::str::FromStr;
7-
use zcash_primitives::consensus::{self, Parameters};
7+
use zcash_protocol::consensus::{self, Parameters};
88

99
/// Enum representing the network type
1010
/// This is used instead of the `consensus::Network` enum so we can derive
@@ -29,10 +29,10 @@ impl FromStr for Network {
2929
}
3030

3131
impl Parameters for Network {
32-
fn network_type(&self) -> zcash_address::Network {
32+
fn network_type(&self) -> zcash_protocol::consensus::NetworkType {
3333
match self {
34-
Network::MainNetwork => zcash_address::Network::Main,
35-
Network::TestNetwork => zcash_address::Network::Test,
34+
Network::MainNetwork => zcash_protocol::consensus::NetworkType::Main,
35+
Network::TestNetwork => zcash_protocol::consensus::NetworkType::Test,
3636
}
3737
}
3838

crates/webzjs-keys/src/pczt_sign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub async fn pczt_sign_inner(
131131
.finish();
132132
let mut signer = Signer::new(pczt).unwrap();
133133
//.map_err(|e| anyhow!("Failed to initialize Signer: {:?}", e))?;
134-
for (account_index, spends) in keys {
134+
for (_, spends) in keys {
135135
// let usk = UnifiedSpendingKey::from_seed(&params, seed, account_index)?;
136136
for keyref in spends {
137137
match keyref {

crates/webzjs-requests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ wasm-opt = ["-O4", "-O4"]
1616
[dependencies]
1717
wasm-bindgen.workspace = true
1818
js-sys.workspace = true
19-
19+
zcash_protocol.workspace = true
2020
zcash_address.workspace = true
2121
zcash_primitives.workspace = true
2222
zip321.workspace = true

crates/webzjs-requests/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use wasm_bindgen::JsValue;
33
#[derive(thiserror::Error, Debug)]
44
pub enum Error {
55
#[error("Error parsing zatoshi amount: {0}")]
6-
InvalidAmount(#[from] zcash_primitives::transaction::components::amount::BalanceError),
6+
InvalidAmount(#[from] zcash_protocol::value::BalanceError),
77
#[error("Attempted to create a transaction with a memo to an unsupported recipient. Only shielded addresses are supported.")]
88
UnsupportedMemoRecipient,
99
#[error("Error constructing ZIP321 transaction request: {0}")]

crates/webzjs-wallet/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ zcash_address = { workspace = true }
5454
zcash_protocol = { workspace = true, default-features = false }
5555
zcash_proofs = { workspace = true, default-features = false, features = ["bundled-prover", "multicore"] }
5656
zip321 = { workspace = true }
57+
zip32 = { workspace = true }
5758
pczt = { workspace = true, default-features = false, features = ["orchard", "sapling", "transparent"] }
5859
orchard = { version = "0.10.1", default-features = false }
5960
sapling = { workspace = true }

crates/webzjs-wallet/src/wallet.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::collections::BTreeMap;
2-
use std::convert::Infallible;
31
use std::num::{NonZeroU32, NonZeroUsize};
42

53
use bip0039::{English, Mnemonic};
@@ -16,13 +14,12 @@ use webzjs_common::Network;
1614

1715
use pczt::roles::combiner::Combiner;
1816
use pczt::roles::prover::Prover;
19-
use pczt::roles::signer::Signer;
17+
2018
use pczt::roles::updater::Updater;
21-
use pczt::roles::verifier::Verifier;
2219
use pczt::Pczt;
2320
use sapling::ProofGenerationKey;
2421
use serde::de::DeserializeOwned;
25-
use serde::{Deserialize, Serialize, Serializer};
22+
use serde::Serialize;
2623
use std::fmt::Debug;
2724
use std::hash::Hash;
2825
use std::sync::Arc;
@@ -39,32 +36,33 @@ use zcash_client_backend::data_api::{
3936
};
4037
use zcash_client_backend::data_api::{WalletCommitmentTrees, Zip32Derivation};
4138
use zcash_client_backend::fees::standard::MultiOutputChangeStrategy;
42-
use zcash_client_backend::fees::zip317::SingleOutputChangeStrategy;
4339
use zcash_client_backend::fees::{DustOutputPolicy, SplitPolicy, StandardFeeRule};
4440
use zcash_client_backend::proposal::Proposal;
4541
use zcash_client_backend::proto::service::{
4642
self, compact_tx_streamer_client::CompactTxStreamerClient,
4743
};
4844
use zcash_client_backend::wallet::OvkPolicy;
4945
use zcash_client_backend::zip321::{Payment, TransactionRequest};
50-
use zcash_client_backend::ShieldedProtocol;
5146
use zcash_client_memory::{MemBlockCache, MemoryWalletDb};
5247
use zcash_keys::keys::{UnifiedFullViewingKey, UnifiedSpendingKey};
53-
use zcash_primitives::transaction::components::amount::NonNegativeAmount;
5448
use zcash_primitives::transaction::fees::FeeRule;
5549
use zcash_primitives::transaction::TxId;
5650
use zcash_proofs::prover::LocalTxProver;
51+
use zcash_protocol::ShieldedProtocol;
5752

58-
use crate::error::Error::PcztCreate;
5953
use zcash_client_backend::sync::run;
60-
use zcash_primitives::legacy::keys::{NonHardenedChildIndex, TransparentKeyScope};
61-
use zcash_primitives::zip32;
62-
use zcash_primitives::zip32::fingerprint::SeedFingerprint;
63-
use zcash_protocol::consensus::{NetworkConstants, Parameters};
54+
55+
use zcash_protocol::consensus::Parameters;
6456
use zcash_protocol::value::Zatoshis;
57+
use zip32;
58+
use zip32::fingerprint::SeedFingerprint;
6559

6660
const BATCH_SIZE: u32 = 10000;
6761

62+
/// constant that signals what's the minimum transparent balance for proposing a
63+
/// shielding transaction
64+
const SHIELDING_THRESHOLD: Zatoshis = Zatoshis::const_from_u64(100000);
65+
6866
/// # A Zcash wallet
6967
///
7068
/// A wallet is a set of accounts that can be synchronized together with the blockchain.
@@ -323,7 +321,7 @@ where
323321
);
324322
let request = TransactionRequest::new(vec![Payment::without_memo(
325323
to_address,
326-
NonNegativeAmount::from_u64(value)?,
324+
Zatoshis::from_u64(value)?,
327325
)])?;
328326

329327
tracing::info!("Chain height: {:?}", self.db.read().await.chain_height()?);
@@ -469,10 +467,10 @@ where
469467
&self.network,
470468
&input_selector,
471469
&change_strategy,
472-
Zatoshis::ZERO,
470+
SHIELDING_THRESHOLD, // use a shielding threshold above a marginal fee transaction plus some value like Zashi does.
473471
&from_addrs,
474472
account_id,
475-
0,
473+
1, // librustzcash operates under the assumption of zero or one conf being the same but that could change.
476474
)
477475
.map_err(|e| Error::Generic(format!("Error when shielding: {:?}", e)))?;
478476

@@ -519,7 +517,7 @@ where
519517
let input_selector = GreedyInputSelector::new();
520518
let request = TransactionRequest::new(vec![Payment::without_memo(
521519
to_address,
522-
NonNegativeAmount::from_u64(value)?,
520+
Zatoshis::from_u64(value)?,
523521
)])?;
524522
let mut db = self.db.write().await;
525523
let proposal = propose_transfer::<_, _, _,_, <W as WalletCommitmentTrees>::Error>(
@@ -583,7 +581,7 @@ where
583581
.collect::<Vec<_>>();
584582

585583
// Assume all non-dummy spent notes are from the same account.
586-
for (index, derivation) in non_dummy_spends {
584+
for (index, _) in non_dummy_spends {
587585
updater.update_spend_with(index, |mut spend_updater| {
588586
spend_updater.set_proof_generation_key(sapling_proof_gen_key.clone())
589587
})?;

packages/web-wallet/src/components/Button/Button.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import cn from 'classnames';
33

44
type ButtonVariant = 'primary' | 'secondary';
55

6-
interface ButtonProps {
6+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
77
onClick: () => void;
88
label: string;
99
classNames?: string;
@@ -17,10 +17,12 @@ function Button({
1717
classNames = '',
1818
variant = 'primary',
1919
icon,
20+
...rest
2021
}: ButtonProps) {
2122
const buttonClasses = cn(
2223
'min-w-[228px] px-6 py-3 rounded-3xl text-base font-medium leading-normal',
23-
'cursor-pointer transition-all hover:transition-all',
24+
'transition-all hover:transition-all',
25+
{ 'cursor-not-allowed': rest.disabled, 'cursor-pointer': !rest.disabled },
2426
{
2527
'bg-[#0e0e0e] text-white border hover:bg-buttonBlackGradientHover':
2628
variant === 'primary',
@@ -31,7 +33,7 @@ function Button({
3133
);
3234

3335
return (
34-
<button onClick={onClick} className={buttonClasses}>
36+
<button onClick={onClick} className={buttonClasses} {...rest}>
3537
<div className="flex items-center justify-center">
3638
{icon && <span className="mr-2 flex items-center">{icon}</span>}
3739
<span>{label}</span>

0 commit comments

Comments
 (0)