Skip to content

Commit

Permalink
Split out Addresses and KeysCollector into separate crates (#325)
Browse files Browse the repository at this point in the history
Split out module `Addresses` & `KeysCollector` into new crates
  • Loading branch information
CyonAlexRDX authored Dec 30, 2024
1 parent fe4adac commit 7178fe5
Show file tree
Hide file tree
Showing 93 changed files with 723 additions and 504 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

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

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ members = [
"crates/sargon-core",
"crates/sargon-hierarchical-deterministic",
"crates/sargon-factors",
"crates/sargon-addresses",
"crates/sargon-keys-collector",

"crates/sargon", # to be split

Expand All @@ -34,18 +36,24 @@ radix-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1
"serde",
"secp256k1_sign_and_validate",
] }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0" }
radix-rust = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0", features = [
"serde",
] }
radix-transactions = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v1.3.0" }

radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "2ab5b35a6cb96c9faeb98ed8df67b870336e6873" }

# ===== EXTERNAL DEPENDENCIES ========
arraystring = { git = "https://github.com/paulocsanz/arraystring", rev = "ebd7d8ba94fa0d5068fe048d5445f6b1af56035d", features = [
"serde-traits",
] }

# actix-rt = "3.3.0"
actix-rt = { git = "https://github.com/actix/actix-net", rev = "57fd6ea8098d1f2d281c305fc331216c4fe1992e" }

async-trait = { git = "https://github.com/dtolnay/async-trait", rev = "1eb21ed8bd87029bf4dcbea41ff309f2b2220c43" }

# hkdf = "0.12.4"
hkdf = { git = "https://github.com/RustCrypto/KDFs/", rev = "1ac16e8b9d4ee7a67613c9396c6cc1327652eaba" }
# thiserror = "1.0.50"
Expand Down Expand Up @@ -116,6 +124,7 @@ paste = { git = "https://github.com/dtolnay/paste", rev = "1e0cc1025af5388397c67

# pretty_assertions = "1.4.0"
pretty_assertions = { git = "https://github.com/rust-pretty-assertions/rust-pretty-assertions", rev = "3f1ebc0cac5f88e875f036bf16636e15fa935c8d" }

serde = { version = "1.0.193", features = ["derive", "rc", "std"] }

# serde_json = "1.0.108"
Expand Down
27 changes: 27 additions & 0 deletions crates/sargon-addresses/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "sargon-addresses"
version = "1.2.1"
edition = "2021"

[dependencies]
sargon-core = { path = "../sargon-core" }
sargon-factors = { path = "../sargon-factors" }
sargon-hierarchical-deterministic = { path = "../sargon-hierarchical-deterministic" }

# ==== RADIX DEPENDENCIES ====
radix-common = { workspace = true }
radix-engine-interface = { workspace = true }
radix-engine = { workspace = true }
radix-rust = { workspace = true }
radix-transactions = { workspace = true }

radix-engine-toolkit = { workspace = true }

# ==== EXTERNAL DEPENDENCIES ====
derive_more = { workspace = true }
enum-iterator = { workspace = true }
log = { workspace = true }
pretty_assertions = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl HasSampleValues for AccountAddress {
}
}

impl From<AccountAddress> for ScryptoComponentAddress {
fn from(value: AccountAddress) -> ScryptoComponentAddress {
ScryptoComponentAddress::new_or_panic(value.node_id().0)
}
}

impl AccountAddress {
/// A sample used to facilitate unit tests.
pub fn sample_mainnet() -> Self {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::*;
use crate::{address_union, prelude::*};

address_union!(
/// A tagged union of addresses of either an Account or a Persona (IdentityAddress)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::prelude::*;

#[macro_export]
macro_rules! address_union {
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub trait IsEntityAddress:
{
/// Creates a new address from `public_key` and `network_id` by bech32 encoding
/// it.
#[cfg(not(tarpaulin_include))] // false negative
fn from_public_key<P>(public_key: P, network_id: NetworkID) -> Self
where
P: Into<ScryptoPublicKey> + Clone,
Expand All @@ -39,7 +38,6 @@ pub trait IsEntityAddress:
Self::new(node_id, network_id).expect("To always be able to create a address from public key and network id.")
}

#[cfg(not(tarpaulin_include))] // false negative
fn from_hd_factor_instance_virtual_entity_creation<E: IsEntityPath>(
hd_factor_instance_virtual_entity_creation: HDFactorInstanceTransactionSigning<E>,
) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ mod access_controller_address;
mod account_address;
mod address;
mod address_format;
mod address_of_account_or_persona;

#[macro_use]
mod address_union;

mod component_address;
mod entity_address;
mod identity_address;
Expand All @@ -13,6 +18,7 @@ mod non_fungible_local_id_string;
mod non_fungible_resource_address;
mod package_address;
mod pool_address;
mod public_key_hash;
mod resource_address;
mod validator_address;
mod vault_address;
Expand All @@ -22,6 +28,7 @@ pub use access_controller_address::*;
pub use account_address::*;
pub use address::*;
pub use address_format::*;
pub use address_of_account_or_persona::*;
pub use component_address::*;
pub use entity_address::*;
pub use identity_address::*;
Expand All @@ -33,6 +40,7 @@ pub use non_fungible_local_id_string::*;
pub use non_fungible_resource_address::*;
pub use package_address::*;
pub use pool_address::*;
pub use public_key_hash::*;
pub use resource_address::*;
pub use validator_address::*;
pub use vault_address::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl NonFungibleLocalId {
}

impl NonFungibleLocalId {
pub(crate) fn derives_account_address(
pub fn derives_account_address(
&self,
account_address: AccountAddress,
) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ impl ResourceAddress {
.expect("valid sample value")
}

#[allow(unused)]
pub(crate) fn sample_sim_xrd() -> Self {
pub fn sample_sim_xrd() -> Self {
"resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3"
.parse()
.expect("valid sample value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ pub(crate) trait FromRetAddress {
type RetAddress;
}

pub(crate) fn format_string(
s: impl AsRef<str>,
start: usize,
end: usize,
) -> String {
let s = s.as_ref();
let prefix = &s[0..start];
let suffix = suffix_str(end, s);
format!("{}...{}", prefix, suffix)
}

pub trait IntoScryptoAddress: IsNetworkAware {
fn scrypto(&self) -> ScryptoGlobalAddress;
}
Expand Down Expand Up @@ -92,6 +81,14 @@ macro_rules! decl_ret_wrapped_address {
}
}

impl Identifiable for [< $address_type:camel Address >] {
type ID = Self;

fn id(&self) -> Self::ID {
*self
}
}

#[cfg(test)]
impl From<&str> for [< $address_type:camel Address >] {
/// TEST ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,51 +140,6 @@ impl From<ResourceOrNonFungible> for ScryptoResourceOrNonFungible {
}
}

#[cfg(not(tarpaulin_include))] // false negative, tested.
pub(crate) fn to_vec_network_aware<T, U>(
values: impl IntoIterator<Item = T>,
network_id: NetworkID,
) -> Vec<U>
where
U: From<(T, NetworkID)>,
{
values
.into_iter()
.map(|x| (x, network_id))
.map(U::from)
.collect_vec()
}

pub(crate) fn to_hashmap_network_aware_key<K, V, L, U>(
values: impl IntoIterator<Item = (K, V)>,
network_id: NetworkID,
) -> HashMap<L, U>
where
L: Eq + std::hash::Hash + From<(K, NetworkID)>,
U: From<V>,
{
values
.into_iter()
.map(|(k, v)| (L::from((k, network_id)), U::from(v)))
.collect::<HashMap<L, U>>()
}

#[cfg(not(tarpaulin_include))] // false negative, tested.
pub(crate) fn filter_try_to_vec_network_aware<T, U>(
values: impl IntoIterator<Item = T>,
network_id: NetworkID,
) -> Vec<U>
where
U: TryFrom<(T, NetworkID)>,
{
values
.into_iter()
.map(|x| (x, network_id))
.map(U::try_from)
.filter_map(Result::ok)
.collect_vec()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 2 additions & 0 deletions crates/sargon-addresses/src/address_conversion/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod addresses_manifest_builder_support;
mod resource_address_from;
Loading

0 comments on commit 7178fe5

Please sign in to comment.