Skip to content

Commit

Permalink
solved conflicts with dev 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar-Pepper committed Feb 3, 2025
2 parents 43cfee8 + b82fbe1 commit 026d9d6
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 317 deletions.
460 changes: 246 additions & 214 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libtonode-tests/tests/chain_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use zingolib::testutils::{

proptest::proptest! {
#![proptest_config(proptest::test_runner::Config::with_cases(4))]
#[ignore = "hangs"]
#[test]
fn single_sufficient_send_libtonode(send_value in 0..50_000u64, change_value in 0..10_000u64, sender_protocol in 1..2, receiver_pool in 0..2) {
Runtime::new().unwrap().block_on(async {
Expand Down
12 changes: 7 additions & 5 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ mod fast {
lightclient::from_inputs,
},
wallet::data::summaries::{SelfSendValueTransfer, SentValueTransfer, ValueTransferKind},
UAReceivers,
};

use super::*;
Expand Down Expand Up @@ -995,7 +996,7 @@ mod fast {
for code in ["o", "zo", "z"] {
recipient.do_new_address(code).await.unwrap();
}
let addresses = recipient.do_addresses().await;
let addresses = recipient.do_addresses(UAReceivers::All).await;
let address_5000_nonememo_tuples = addresses
.members()
.map(|ua| (ua["address"].as_str().unwrap(), 5_000, None))
Expand Down Expand Up @@ -1058,7 +1059,7 @@ mod fast {

//Verify that 1 increment of diversification with a tz receiver set produces uregtest1m8un60u... UA
let new_address = recipient1.do_new_address("tzo").await.unwrap();
let ua_index_1 = recipient1.do_addresses().await[1].clone();
let ua_index_1 = recipient1.do_addresses(UAReceivers::All).await[1].clone();
let ua_address_index_1 = ua_index_1["address"].clone().to_string();
assert_eq!(&new_address[0].to_string(), &ua_address_index_1);
let sapling_index_1 = ua_index_1["receivers"]["sapling"].clone().to_string();
Expand Down Expand Up @@ -1272,6 +1273,7 @@ mod slow {
assert_transaction_summary_exists,
lightclient::{from_inputs, get_fees_paid_by_client},
};
use zingolib::UAReceivers;

use super::*;

Expand Down Expand Up @@ -1676,7 +1678,7 @@ mod slow {
// let list = recipient.do_list_transactions().await;
// assert_eq!(list[0]["block_height"].as_u64().unwrap(), 4);
// assert_eq!(
// recipient.do_addresses().await[0]["receivers"]["transparent"].to_string(),
// recipient.do_addresses(UAReceivers::All).await[0]["receivers"]["transparent"].to_string(),
// recipient_taddr
// );
// assert_eq!(list[0]["amount"].as_u64().unwrap(), value);
Expand Down Expand Up @@ -2456,7 +2458,7 @@ mod slow {

// // 3. Check the balance is correct, and we received the incoming transaction from ?outside?
// let b = recipient.do_balance().await;
// let addresses = recipient.do_addresses().await;
// let addresses = recipient.do_addresses(UAReceivers::All).await;
// assert_eq!(b.sapling_balance.unwrap(), value);
// assert_eq!(b.unverified_sapling_balance.unwrap(), 0);
// assert_eq!(b.spendable_sapling_balance.unwrap(), value);
Expand Down Expand Up @@ -3098,7 +3100,7 @@ mod slow {
.await;
let seed_of_recipient_restored = {
recipient_restored.do_sync(true).await.unwrap();
let restored_addresses = recipient_restored.do_addresses().await;
let restored_addresses = recipient_restored.do_addresses(UAReceivers::All).await;
assert_eq!(
&restored_addresses[0]["address"],
&original_recipient_address
Expand Down
1 change: 1 addition & 0 deletions libtonode-tests/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn sync_status() {
}

// temporary test for sync development
#[ignore = "hangs"]
#[tokio::test]
async fn sync_test() {
tracing_subscriber::fmt().init();
Expand Down
2 changes: 1 addition & 1 deletion zingo-sync/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
utils,
};

/// Block height and txid of relevant transactions that have yet to be scanned. These may be added due transparent
/// Block height and txid of relevant transactions that have yet to be scanned. These may be added due to transparent
/// output/spend discovery or for targetted rescan.
pub type Locator = (BlockHeight, TxId);

Expand Down
2 changes: 1 addition & 1 deletion zingo-sync/src/scan/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ where
///
/// Creates a new scan task and sends to batcher if it's idle.
/// The batcher will stream compact blocks into the scan task, splitting the scan task when the maximum number of
/// outputs is reached. When a scan task is ready is it stored in the batcher ready to be taken by an idle scan
/// outputs is reached. When a scan task is ready it is stored in the batcher ready to be taken by an idle scan
/// worker for scanning.
/// When verification is still in progress, only scan tasks with `Verify` scan priority are created.
/// When all ranges are scanned, the batcher, idle workers and mempool are shutdown.
Expand Down
2 changes: 1 addition & 1 deletion zingo-sync/src/sync/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ where
}
}

/// Creates block ranges that contain all outputs for the shards associated with `subtree_roots` and adds the to
/// Creates block ranges that contain all outputs for the shards associated with `subtree_roots` and adds them to
/// `sync_state`.
///
/// The network upgrade activation height for the `shielded_protocol` is the first shard start height for the case
Expand Down
174 changes: 105 additions & 69 deletions zingolib/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Command for ParseAddressCommand {
indoc! {r#"
Parse an address
Usage:
parse_address [address]
parse_address <address>
Example
parse_address tmSwk8bjXdCgBvpS8Kybk5nUyE21QFcDqre
Expand All @@ -234,71 +234,86 @@ impl Command for ParseAddressCommand {
}

fn exec(&self, args: &[&str], _lightclient: &LightClient) -> String {
match args.len() {
1 => json::stringify_pretty(
[
crate::config::ChainType::Mainnet,
crate::config::ChainType::Testnet,
crate::config::ChainType::Regtest(
crate::config::RegtestNetwork::all_upgrades_active(),
),
]
.iter()
.find_map(|chain| Address::decode(chain, args[0]).zip(Some(chain)))
.map_or(
object! {
"status" => "Invalid address",
"chain_name" => json::JsonValue::Null,
"address_kind" => json::JsonValue::Null,
},
|(recipient_address, chain_name)| {
let chain_name_string = match chain_name {
crate::config::ChainType::Mainnet => "main",
crate::config::ChainType::Testnet => "test",
crate::config::ChainType::Regtest(_) => "regtest",
};
match recipient_address {
Address::Sapling(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "sapling",
},
Address::Transparent(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "transparent",
},
Address::Unified(ua) => {
let mut receivers_available = vec![];
if ua.orchard().is_some() {
receivers_available.push("orchard")
}
if ua.sapling().is_some() {
receivers_available.push("sapling")
}
if ua.transparent().is_some() {
receivers_available.push("transparent")
}
object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "unified",
"receivers_available" => receivers_available,
}
}
Address::Tex(_) => {
object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "tex",
}
}
}
},
if args.len() > 1 || args.is_empty() {
return self.help().to_string();
}
fn make_decoded_chain_pair(
address: &str,
) -> Option<(
zcash_client_backend::address::Address,
crate::config::ChainType,
)> {
[
crate::config::ChainType::Mainnet,
crate::config::ChainType::Testnet,
crate::config::ChainType::Regtest(
crate::config::RegtestNetwork::all_upgrades_active(),
),
4,
),
_ => self.help().to_string(),
]
.iter()
.find_map(|chain| Address::decode(chain, address).zip(Some(*chain)))
}
if let Some((recipient_address, chain_name)) = make_decoded_chain_pair(args[0]) {
let chain_name_string = match chain_name {
crate::config::ChainType::Mainnet => "main",
crate::config::ChainType::Testnet => "test",
crate::config::ChainType::Regtest(_) => "regtest",
};
match recipient_address {
Address::Sapling(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "sapling",
}
.to_string(),
Address::Transparent(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "transparent",
}
.to_string(),
Address::Tex(_) => object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "tex",
}
.to_string(),
Address::Unified(ua) => {
let mut receivers_available = vec![];
if ua.sapling().is_some() {
receivers_available.push("sapling")
}
if ua.transparent().is_some() {
receivers_available.push("transparent")
}
if ua.orchard().is_some() {
receivers_available.push("orchard");
object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "unified",
"receivers_available" => receivers_available,
"only_orchard_ua" => zcash_keys::address::UnifiedAddress::from_receivers(ua.orchard().cloned(), None, None).expect("To construct UA").encode(&chain_name),
}
.to_string()
} else {
object! {
"status" => "success",
"chain_name" => chain_name_string,
"address_kind" => "unified",
"receivers_available" => receivers_available,
}
.to_string()
}
}
}
} else {
object! {
"status" => "Invalid address",
"chain_name" => json::JsonValue::Null,
"address_kind" => json::JsonValue::Null,
}
.to_string()
}
}
}
Expand Down Expand Up @@ -694,9 +709,9 @@ struct AddressCommand {}
impl Command for AddressCommand {
fn help(&self) -> &'static str {
indoc! {r#"
List current addresses in the wallet
List current addresses in the wallet, shielded excludes t-addresses.
Usage:
address
addresses [shielded|orchard]
"#}
}
Expand All @@ -705,8 +720,29 @@ impl Command for AddressCommand {
"List all addresses in the wallet"
}

fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String {
RT.block_on(async move { lightclient.do_addresses().await.pretty(2) })
fn exec(&self, args: &[&str], lightclient: &LightClient) -> String {
use crate::lightclient::describe::UAReceivers;
match args.len() {
0 => RT.block_on(
async move { lightclient.do_addresses(UAReceivers::All).await.pretty(2) },
),
1 => match args[0] {
"shielded" => RT.block_on(async move {
lightclient
.do_addresses(UAReceivers::Shielded)
.await
.pretty(2)
}),
"orchard" => RT.block_on(async move {
lightclient
.do_addresses(UAReceivers::Orchard)
.await
.pretty(2)
}),
_ => self.help().to_string(),
},
_ => self.help().to_string(),
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions zingolib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use zcash_client_backend::ShieldedProtocol;

pub use lightclient::describe::UAReceivers;

#[macro_use]
extern crate rust_embed;

Expand Down
7 changes: 5 additions & 2 deletions zingolib/src/lightclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,10 @@ async fn get_recent_median_price_from_gemini() -> Result<f64, PriceFetchError> {

#[cfg(test)]
mod tests {
use crate::config::{ChainType, RegtestNetwork, ZingoConfig};
use crate::{
config::{ChainType, RegtestNetwork, ZingoConfig},
lightclient::describe::UAReceivers,
};
use testvectors::seeds::CHIMNEY_BETTER_SEED;
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -727,7 +730,7 @@ mod tests {

// The first t address and z address should be derived
Runtime::new().unwrap().block_on(async move {
let addresses = lc.do_addresses().await;
let addresses = lc.do_addresses(UAReceivers::All).await;
assert_eq!(
"zregtestsapling1etnl5s47cqves0g5hk2dx5824rme4xv4aeauwzp4d6ys3qxykt5sw5rnaqh9syxry8vgxr7x3x4"
.to_string(),
Expand Down
Loading

0 comments on commit 026d9d6

Please sign in to comment.