Skip to content

Commit

Permalink
Merge pull request #846 from Oscar-Pepper/update_to_lrz_2e0a300
Browse files Browse the repository at this point in the history
updated to latest librustzcash plus protoc build changes
  • Loading branch information
zancas authored Mar 14, 2024
2 parents 1be3f86 + 77a3f5d commit 2fab808
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 133 deletions.
35 changes: 25 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ resolver = "2"

[workspace.dependencies]
clap = "4.4"
sapling-crypto = "0.1.0"
zcash_address = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_backend.0.11.1" }
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_backend.0.11.1", features = ["lightwalletd-tonic"] }
zcash_encoding = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_backend.0.11.1" }
zcash_keys = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_backend.0.11.1", features = ["orchard"] }
sapling-crypto = "0.1.2"
zcash_address = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838" } # git tag -s $(git describe --dirty)
zcash_client_backend = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838", features = ["lightwalletd-tonic"] }
zcash_encoding = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838" }
zcash_keys = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838", features = ["orchard"] }
zcash_note_encryption = "0.4"
zcash_primitives = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_backend.0.11.1" }
zcash_proofs = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zingo_backend.0.11.1" }
orchard = "0.7"
zcash_primitives = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838" }
zcash_proofs = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838" }
zcash_protocol = { git = "https://github.com/zingolabs/librustzcash.git", tag = "zcash_address-0.3.2-128-g11bcb838" }
orchard = "0.7.1"
tonic-build = "0.10"
tempdir = "0.3"
portpicker = "0.1"
Expand Down
6 changes: 4 additions & 2 deletions integration-tests/tests/integrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,13 @@ mod fast {
}

let ufvk = wc.ufvk().unwrap();
let ufvk_string = ufvk.encode(&config.chain.to_zcash_address_network());
let ufvk_string = ufvk.encode(&config.chain.network_type());
let ufvk_base = WalletBase::Ufvk(ufvk_string.clone());
let view_wallet =
LightWallet::new(config.clone(), ufvk_base, wallet.get_birthday().await).unwrap();
let v_wc = view_wallet.wallet_capability();
let vv = v_wc.ufvk().unwrap();
let vv_string = vv.encode(&config.chain.to_zcash_address_network());
let vv_string = vv.encode(&config.chain.network_type());
assert_eq!(ufvk_string, vv_string);

let client = LightClient::create_from_wallet_async(wallet, config)
Expand Down Expand Up @@ -642,6 +642,8 @@ mod fast {
}
}
mod slow {
use zcash_primitives::consensus::NetworkConstants;

use super::*;

#[tokio::test]
Expand Down
111 changes: 20 additions & 91 deletions zingoconfig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use log4rs::{
filter::threshold::ThresholdFilter,
Config,
};
use zcash_primitives::{
consensus::{BlockHeight, NetworkUpgrade, Parameters, MAIN_NETWORK, TEST_NETWORK},
constants,
use zcash_primitives::consensus::{
BlockHeight, NetworkConstants, NetworkType, NetworkUpgrade, Parameters, MAIN_NETWORK,
TEST_NETWORK,
};

pub const DEFAULT_LIGHTWALLETD_SERVER: &str = "https://mainnet.lightwalletd.com:9067";
Expand Down Expand Up @@ -397,30 +397,37 @@ impl ZingoConfig {
/// so that HD wallets can manage multiple currencies.
/// <https://github.com/satoshilabs/slips/blob/master/slip-0044.md>
/// ZEC is registered as 133 (0x80000085) for MainNet and 1 (0x80000001) for TestNet (all coins)
#[deprecated(since = "0.1.0", note = "obsolete due to `Parameter` trait methods")]
pub fn get_coin_type(&self) -> u32 {
self.chain.coin_type()
}

#[deprecated(since = "0.1.0", note = "obsolete due to `Parameter` trait methods")]
pub fn hrp_sapling_address(&self) -> &str {
self.chain.hrp_sapling_payment_address()
}

#[deprecated(since = "0.1.0", note = "obsolete due to `Parameter` trait methods")]
pub fn hrp_sapling_private_key(&self) -> &str {
self.chain.hrp_sapling_extended_spending_key()
}

#[deprecated(since = "0.1.0", note = "obsolete due to `Parameter` trait methods")]
pub fn hrp_sapling_viewing_key(&self) -> &str {
self.chain.hrp_sapling_extended_full_viewing_key()
}

#[deprecated(since = "0.1.0", note = "obsolete due to `Parameter` trait methods")]
pub fn base58_pubkey_address(&self) -> [u8; 2] {
self.chain.b58_pubkey_address_prefix()
}

#[deprecated(since = "0.1.0", note = "obsolete due to `Parameter` trait methods")]
pub fn base58_script_address(&self) -> [u8; 2] {
self.chain.b58_script_address_prefix()
}

#[deprecated(since = "0.1.0", note = "prefix not known to be used")]
pub fn base58_secretkey_prefix(&self) -> [u8; 1] {
match self.chain {
ChainType::Testnet | ChainType::Regtest(_) | ChainType::FakeMainnet => [0xEF],
Expand Down Expand Up @@ -453,13 +460,6 @@ impl ChainType {
ChainType::FakeMainnet => "uview",
}
}
pub fn to_zcash_address_network(&self) -> zcash_address::Network {
match self {
Mainnet | FakeMainnet => zcash_address::Network::Main,
Testnet => zcash_address::Network::Test,
Regtest(_) => RegtestNetwork::address_network().unwrap(),
}
}
}

impl std::fmt::Display for ChainType {
Expand All @@ -475,68 +475,25 @@ impl std::fmt::Display for ChainType {
}
}

use ChainType::*;
impl Parameters for ChainType {
fn network_type(&self) -> NetworkType {
use ChainType::*;
match self {
Mainnet | FakeMainnet => NetworkType::Main,
Testnet => NetworkType::Test,
Regtest(_) => NetworkType::Regtest,
}
}

fn activation_height(&self, nu: NetworkUpgrade) -> Option<BlockHeight> {
use ChainType::*;
match self {
Mainnet => MAIN_NETWORK.activation_height(nu),
Testnet => TEST_NETWORK.activation_height(nu),
Regtest(regtest_network) => regtest_network.activation_height(nu),
FakeMainnet => Some(BlockHeight::from_u32(1)),
}
}

fn coin_type(&self) -> u32 {
match self {
Mainnet | FakeMainnet => constants::mainnet::COIN_TYPE,
Testnet => constants::testnet::COIN_TYPE,
Regtest(_) => RegtestNetwork::coin_type(),
}
}

fn hrp_sapling_extended_spending_key(&self) -> &str {
match self {
Mainnet | FakeMainnet => constants::mainnet::HRP_SAPLING_EXTENDED_SPENDING_KEY,
Testnet => constants::testnet::HRP_SAPLING_EXTENDED_SPENDING_KEY,
Regtest(_) => RegtestNetwork::hrp_sapling_extended_spending_key(),
}
}

fn hrp_sapling_extended_full_viewing_key(&self) -> &str {
match self {
Mainnet | FakeMainnet => constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
Testnet => constants::testnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY,
Regtest(_) => RegtestNetwork::hrp_sapling_extended_full_viewing_key(),
}
}

fn hrp_sapling_payment_address(&self) -> &str {
match self {
Mainnet | FakeMainnet => constants::mainnet::HRP_SAPLING_PAYMENT_ADDRESS,
Testnet => constants::testnet::HRP_SAPLING_PAYMENT_ADDRESS,
Regtest(_) => RegtestNetwork::hrp_sapling_payment_address(),
}
}

fn b58_pubkey_address_prefix(&self) -> [u8; 2] {
match self {
Mainnet | FakeMainnet => constants::mainnet::B58_PUBKEY_ADDRESS_PREFIX,
Testnet => constants::testnet::B58_PUBKEY_ADDRESS_PREFIX,
Regtest(_) => RegtestNetwork::b58_pubkey_address_prefix(),
}
}

fn b58_script_address_prefix(&self) -> [u8; 2] {
match self {
Mainnet | FakeMainnet => constants::mainnet::B58_SCRIPT_ADDRESS_PREFIX,
Testnet => constants::testnet::B58_SCRIPT_ADDRESS_PREFIX,
Regtest(_) => RegtestNetwork::b58_script_address_prefix(),
}
}

fn address_network(&self) -> Option<zcash_address::Network> {
Some(self.to_zcash_address_network())
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down Expand Up @@ -603,34 +560,6 @@ impl RegtestNetwork {
),
}
}

fn coin_type() -> u32 {
constants::regtest::COIN_TYPE
}

fn address_network() -> Option<zcash_address::Network> {
Some(zcash_address::Network::Regtest)
}

fn hrp_sapling_extended_spending_key() -> &'static str {
constants::regtest::HRP_SAPLING_EXTENDED_SPENDING_KEY
}

fn hrp_sapling_extended_full_viewing_key() -> &'static str {
constants::regtest::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY
}

fn hrp_sapling_payment_address() -> &'static str {
constants::regtest::HRP_SAPLING_PAYMENT_ADDRESS
}

fn b58_pubkey_address_prefix() -> [u8; 2] {
constants::regtest::B58_PUBKEY_ADDRESS_PREFIX
}

fn b58_script_address_prefix() -> [u8; 2] {
constants::regtest::B58_SCRIPT_ADDRESS_PREFIX
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down
3 changes: 2 additions & 1 deletion zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::str::FromStr;
use tokio::runtime::Runtime;
use zcash_address::unified::{Container, Encoding, Ufvk};
use zcash_client_backend::address::Address;
use zcash_primitives::consensus::Parameters;
use zcash_primitives::transaction::fees::zip317::MINIMUM_FEE;

lazy_static! {
Expand Down Expand Up @@ -620,7 +621,7 @@ impl Command for ExportUfvkCommand {
Ok(ufvk) => {
use zcash_address::unified::Encoding as _;
object! {
"ufvk" => ufvk.encode(&lightclient.config().chain.to_zcash_address_network()),
"ufvk" => ufvk.encode(&lightclient.config().chain.network_type()),
"birthday" => RT.block_on(lightclient.wallet.get_birthday())
}
.pretty(2)
Expand Down
Loading

0 comments on commit 2fab808

Please sign in to comment.