Skip to content

Commit

Permalink
Merge pull request #75 from zcash/remove_deprecated_api_usage
Browse files Browse the repository at this point in the history
Remove uses of `zcash_primitives` public reexports.
  • Loading branch information
nuttycom authored Dec 20, 2024
2 parents 33541fe + 977a310 commit 825e969
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 105 deletions.
9 changes: 6 additions & 3 deletions src/commands/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ use bech32::Bech32;
use clap::Args;
use lazy_static::lazy_static;
use secrecy::Zeroize;

use zcash_address::{
unified::{self, Encoding},
ZcashAddress,
};
use zcash_primitives::{block::BlockHeader, consensus::BranchId, transaction::Transaction};
use zcash_primitives::{block::BlockHeader, transaction::Transaction};
use zcash_proofs::{default_params_folder, load_parameters, ZcashParameters};
use zcash_protocol::consensus::NetworkType;
use zcash_protocol::{
consensus::{BranchId, NetworkType},
constants,
};

mod context;
use context::{Context, ZUint256};
use zcash_protocol::constants;

mod address;
mod block;
Expand Down
29 changes: 18 additions & 11 deletions src/commands/inspect/address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use zcash_address::{
unified::{self, Container, Encoding},
ConversionError, Network, ToAddress, ZcashAddress,
ConversionError, ToAddress, ZcashAddress,
};
use zcash_protocol::consensus::NetworkType;

#[allow(dead_code)]
enum AddressKind {
Expand All @@ -14,22 +15,25 @@ enum AddressKind {
}

struct Address {
net: Network,
net: NetworkType,
kind: AddressKind,
}

impl zcash_address::TryFromAddress for Address {
type Error = ();

fn try_from_sprout(net: Network, data: [u8; 64]) -> Result<Self, ConversionError<Self::Error>> {
fn try_from_sprout(
net: NetworkType,
data: [u8; 64],
) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address {
net,
kind: AddressKind::Sprout(data),
})
}

fn try_from_sapling(
net: Network,
net: NetworkType,
data: [u8; 43],
) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address {
Expand All @@ -39,7 +43,7 @@ impl zcash_address::TryFromAddress for Address {
}

fn try_from_unified(
net: Network,
net: NetworkType,
data: unified::Address,
) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address {
Expand All @@ -49,7 +53,7 @@ impl zcash_address::TryFromAddress for Address {
}

fn try_from_transparent_p2pkh(
net: Network,
net: NetworkType,
data: [u8; 20],
) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address {
Expand All @@ -59,7 +63,7 @@ impl zcash_address::TryFromAddress for Address {
}

fn try_from_transparent_p2sh(
net: Network,
net: NetworkType,
data: [u8; 20],
) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address {
Expand All @@ -68,7 +72,10 @@ impl zcash_address::TryFromAddress for Address {
})
}

fn try_from_tex(net: Network, data: [u8; 20]) -> Result<Self, ConversionError<Self::Error>> {
fn try_from_tex(
net: NetworkType,
data: [u8; 20],
) -> Result<Self, ConversionError<Self::Error>> {
Ok(Address {
net,
kind: AddressKind::Tex(data),
Expand All @@ -87,9 +94,9 @@ pub(crate) fn inspect(addr: ZcashAddress) {
eprintln!(
" - Network: {}",
match addr.net {
Network::Main => "main",
Network::Test => "testnet",
Network::Regtest => "regtest",
NetworkType::Main => "main",
NetworkType::Test => "testnet",
NetworkType::Regtest => "regtest",
}
);
eprintln!(
Expand Down
9 changes: 3 additions & 6 deletions src/commands/inspect/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
#![allow(clippy::assign_op_pattern)]
#![allow(clippy::ptr_offset_with_cast)]

use sha2::{Digest, Sha256};
use std::cmp;
use std::convert::{TryFrom, TryInto};
use std::io::{self, Read};

use sha2::{Digest, Sha256};
use zcash_encoding::Vector;
use zcash_primitives::{
block::BlockHeader,
consensus::{BlockHeight, BranchId, Network, NetworkUpgrade, Parameters},
transaction::Transaction,
};
use zcash_primitives::{block::BlockHeader, transaction::Transaction};
use zcash_protocol::consensus::{BlockHeight, BranchId, Network, NetworkUpgrade, Parameters};

use super::{
transaction::{extract_height_from_coinbase, is_coinbase},
Expand Down
21 changes: 11 additions & 10 deletions src/commands/inspect/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ use serde::{
de::{Unexpected, Visitor},
Deserialize, Serialize, Serializer,
};
use zcash_primitives::{
consensus::Network,
legacy::Script,
transaction::components::{amount::NonNegativeAmount, transparent, TxOut},
zip32::AccountId,

use ::transparent::{address::Script, bundle as transparent, bundle::TxOut};
use zcash_protocol::{
consensus::{Network, NetworkType},
value::Zatoshis,
};
use zip32::AccountId;

#[derive(Clone, Copy, Debug)]
pub(crate) struct JsonNetwork(Network);
Expand Down Expand Up @@ -170,7 +171,7 @@ impl fmt::Display for ZUint256 {
}

#[derive(Clone, Debug)]
struct ZOutputValue(NonNegativeAmount);
struct ZOutputValue(Zatoshis);

struct ZOutputValueVisitor;

Expand All @@ -185,7 +186,7 @@ impl Visitor<'_> for ZOutputValueVisitor {
where
E: serde::de::Error,
{
NonNegativeAmount::from_u64(v)
Zatoshis::from_u64(v)
.map(ZOutputValue)
.map_err(|e| match e {
zcash_protocol::value::BalanceError::Overflow => serde::de::Error::invalid_type(
Expand Down Expand Up @@ -297,10 +298,10 @@ impl Context {
self.network.map(|n| n.0)
}

pub(crate) fn addr_network(&self) -> Option<zcash_address::Network> {
pub(crate) fn addr_network(&self) -> Option<NetworkType> {
self.network().map(|params| match params {
Network::MainNetwork => zcash_address::Network::Main,
Network::TestNetwork => zcash_address::Network::Test,
Network::MainNetwork => NetworkType::Main,
Network::TestNetwork => NetworkType::Test,
})
}

Expand Down
12 changes: 5 additions & 7 deletions src/commands/inspect/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ use std::iter;

use bech32::{Bech32, Hrp};
use secrecy::Zeroize;

use ::transparent::{
address::TransparentAddress,
keys::{AccountPrivKey, IncomingViewingKey},
};
use zcash_address::{
unified::{self, Encoding},
ToAddress, ZcashAddress,
};
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::{
legacy::{
keys::{AccountPrivKey, IncomingViewingKey},
TransparentAddress,
},
zip32,
};
use zcash_protocol::{
consensus::{Network, NetworkConstants, NetworkType},
local_consensus::LocalNetwork,
Expand Down
29 changes: 18 additions & 11 deletions src/commands/inspect/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ use std::{
convert::{TryFrom, TryInto},
};

use ::transparent::sighash::SighashType;
use bellman::groth16;
use group::GroupEncoding;
use orchard::note_encryption::OrchardDomain;
use sapling::{note_encryption::SaplingDomain, SaplingVerificationContext};
use secp256k1::{Secp256k1, VerifyOnly};

#[allow(deprecated)]
use ::transparent::keys::pubkey_to_address;
use ::transparent::{
address::{Script, TransparentAddress},
bundle as transparent,
sighash::{SighashType, TransparentAuthorizingContext},
};
use orchard::note_encryption::OrchardDomain;
use zcash_address::{
unified::{self, Encoding},
ToAddress, ZcashAddress,
};
use zcash_note_encryption::try_output_recovery_with_ovk;
#[allow(deprecated)]
use zcash_primitives::{
use zcash_primitives::transaction::{
components::sapling as sapling_serialization,
sighash::{signature_hash, SignableInput},
txid::TxIdDigester,
Authorization, Transaction, TransactionData, TxId, TxVersion,
};
use zcash_protocol::{
consensus::BlockHeight,
legacy::{keys::pubkey_to_address, Script, TransparentAddress},
memo::{Memo, MemoBytes},
transaction::{
components::{amount::NonNegativeAmount, sapling as sapling_serialization, transparent},
sighash::{signature_hash, SignableInput, TransparentAuthorizingContext},
txid::TxIdDigester,
Authorization, Transaction, TransactionData, TxId, TxVersion,
},
value::Zatoshis,
};

use super::{
Expand Down Expand Up @@ -106,7 +113,7 @@ impl transparent::Authorization for TransparentAuth {
}

impl TransparentAuthorizingContext for TransparentAuth {
fn input_amounts(&self) -> Vec<NonNegativeAmount> {
fn input_amounts(&self) -> Vec<Zatoshis> {
self.all_prev_outputs
.iter()
.map(|prevout| prevout.value)
Expand Down
3 changes: 2 additions & 1 deletion src/commands/pczt/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use anyhow::anyhow;
use clap::Args;
use tokio::io::{stdout, AsyncWriteExt};
use uuid::Uuid;

use zcash_address::ZcashAddress;
use zcash_client_backend::{
data_api::{
Expand All @@ -15,12 +16,12 @@ use zcash_client_backend::{
},
fees::{standard::MultiOutputChangeStrategy, DustOutputPolicy, SplitPolicy, StandardFeeRule},
wallet::OvkPolicy,
ShieldedProtocol,
};
use zcash_client_sqlite::WalletDb;
use zcash_protocol::{
memo::{Memo, MemoBytes},
value::Zatoshis,
ShieldedProtocol,
};
use zip321::{Payment, TransactionRequest};

Expand Down
4 changes: 3 additions & 1 deletion src/commands/pczt/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use clap::Args;
use pczt::{roles::verifier::Verifier, Pczt};
use secrecy::ExposeSecret;
use tokio::io::{stdin, AsyncReadExt};

use ::transparent::sighash::SighashType;
use zcash_primitives::transaction::{
sighash::{SighashType, SignableInput},
sighash::SignableInput,
sighash_v5::v5_signature_hash,
txid::{to_txid, TxIdDigester},
TxVersion,
Expand Down
7 changes: 2 additions & 5 deletions src/commands/pczt/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,8 @@ impl<'b, C> minicbor::Decode<'b, C> for ZcashPczt {
cbor_map(d, &mut result, |key, obj, d| {
let key =
u8::try_from(key).map_err(|e| minicbor::decode::Error::message(e.to_string()))?;
match key {
DATA => {
obj.data = d.bytes()?.to_vec();
}
_ => {}
if key == DATA {
obj.data = d.bytes()?.to_vec();
}
Ok(())
})?;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/pczt/shield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use zcash_client_backend::{
},
fees::{standard::MultiOutputChangeStrategy, DustOutputPolicy, SplitPolicy, StandardFeeRule},
wallet::OvkPolicy,
ShieldedProtocol,
};
use zcash_client_sqlite::WalletDb;
use zcash_protocol::value::Zatoshis;
use zcash_protocol::{value::Zatoshis, ShieldedProtocol};

use crate::{commands::select_account, config::WalletConfig, data::get_db_paths, error};

Expand Down
3 changes: 2 additions & 1 deletion src/commands/pczt/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use pczt::{
};
use secrecy::ExposeSecret;
use tokio::io::{stdin, stdout, AsyncReadExt, AsyncWriteExt};

use ::transparent::keys::{NonHardenedChildIndex, TransparentKeyScope};
use zcash_keys::keys::UnifiedSpendingKey;
use zcash_primitives::legacy::keys::{NonHardenedChildIndex, TransparentKeyScope};
use zcash_protocol::consensus::{NetworkConstants, Parameters};
use zip32::fingerprint::SeedFingerprint;

Expand Down
3 changes: 2 additions & 1 deletion src/commands/wallet/import_ufvk.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use anyhow::anyhow;
use clap::Args;

use zcash_address::unified::{self, Encoding};
use zcash_client_backend::{
data_api::{AccountBirthday, AccountPurpose, WalletWrite, Zip32Derivation},
proto::service,
};
use zcash_client_sqlite::WalletDb;
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::consensus;
use zcash_protocol::consensus;
use zip32::fingerprint::SeedFingerprint;

use crate::{
Expand Down
3 changes: 1 addition & 2 deletions src/commands/wallet/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use zcash_client_backend::{
data_api::{AccountBirthday, WalletWrite},
proto::service::{self, compact_tx_streamer_client::CompactTxStreamerClient},
};
use zcash_primitives::consensus::{self, Parameters};
use zcash_protocol::consensus::BlockHeight;
use zcash_protocol::consensus::{self, BlockHeight, Parameters};

use crate::{
config::WalletConfig,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/wallet/init_fvk.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::anyhow;
use clap::Args;

use zcash_address::unified::{Encoding, Ufvk};
use zcash_client_backend::{
data_api::{AccountPurpose, WalletWrite, Zip32Derivation},
proto::service,
};
use zcash_keys::{encoding::decode_extfvk_with_network, keys::UnifiedFullViewingKey};
use zcash_primitives::consensus::NetworkType;
use zcash_protocol::consensus;
use zcash_protocol::consensus::{self, NetworkType};
use zip32::fingerprint::SeedFingerprint;

use crate::{
Expand Down
Loading

0 comments on commit 825e969

Please sign in to comment.