Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chain/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod h256;
mod heap_address;
mod heap_h256;
mod shard_config;
mod shard_id;
mod time;

pub use address::Address;
Expand All @@ -17,5 +18,6 @@ pub use flags::*;
pub use h256::H256;
pub use heap_address::HeapAddress;
pub use heap_h256::HeapH256;
pub use shard_config::{ShardConfig, ShardId};
pub use shard_config::ShardConfig;
pub use shard_id::ShardId;
pub use time::*;
45 changes: 11 additions & 34 deletions chain/core/src/types/shard_config.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
use super::Address;

/// Identifies a shard by its numeric index.
///
/// Regular shards are numbered from `0` to `number_of_shards - 1`.
/// The special value [`ShardId::METACHAIN_ID`] (`u32::MAX`) identifies the metachain.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
pub struct ShardId(u32);

impl ShardId {
/// Shard ID reserved for the metachain.
pub const METACHAIN_ID: ShardId = ShardId(u32::MAX);

pub fn as_u32(&self) -> u32 {
self.0
}
}

impl From<u32> for ShardId {
fn from(value: u32) -> Self {
ShardId(value)
}
}
use super::{Address, shard_id::ShardId};

/// Precomputed configuration for shard assignment.
/// Mirrors the Go `multiShardCoordinator` struct.
Expand Down Expand Up @@ -95,7 +68,7 @@ impl ShardConfig {
shard = val & self.mask_low;
}

ShardId(shard)
ShardId::from(shard)
}

/// Returns true if both addresses belong to the same shard.
Expand Down Expand Up @@ -176,9 +149,9 @@ mod tests {
let addr = address_from_u32(i);
let shard_id = sr.compute_id(&addr);
assert!(
shard_id.0 < sr.number_of_shards,
shard_id.as_u32() < sr.number_of_shards,
"i={i}: shard {} >= {num_of_shards}",
shard_id.0
shard_id.as_u32()
);
}
}
Expand Down Expand Up @@ -208,7 +181,7 @@ mod tests {
let addr = address_from_u32(address);
assert_eq!(
sr.compute_id(&addr),
ShardId(expected_shard),
ShardId::from(expected_shard),
"address={address}"
);
}
Expand Down Expand Up @@ -285,7 +258,11 @@ mod tests {
];
for &(hex, expected_shard) in dataset {
let addr = address_from_hex(hex);
assert_eq!(sr.compute_id(&addr), ShardId(expected_shard), "hex={hex}");
assert_eq!(
sr.compute_id(&addr),
ShardId::from(expected_shard),
"hex={hex}"
);
}
}

Expand All @@ -308,7 +285,7 @@ mod tests {
let addr = address_from_u32(address);
assert_eq!(
sr.compute_id(&addr),
ShardId(expected_shard),
ShardId::from(expected_shard),
"address={address}"
);
}
Expand Down
36 changes: 36 additions & 0 deletions chain/core/src/types/shard_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// Identifies a shard by its numeric index.
///
/// Regular shards are numbered from `0` to `number_of_shards - 1`.
/// The special value [`ShardId::METACHAIN_ID`] (`u32::MAX`) identifies the metachain.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(transparent)
)]
pub struct ShardId(u32);

impl ShardId {
/// Shard ID reserved for the metachain.
pub const METACHAIN_ID: ShardId = ShardId(u32::MAX);

pub fn as_u32(&self) -> u32 {
self.0
}
}

impl From<u32> for ShardId {
fn from(value: u32) -> Self {
ShardId(value)
}
}

impl core::fmt::Display for ShardId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if *self == ShardId::METACHAIN_ID {
write!(f, "metachain")
} else {
write!(f, "{}", self.0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@ wegld_address = 'erd1qqqqqqqqqqqqqpgqmuk0q2saj0mgutxm4teywre6dl8wqf58xamqdrukln'
pair_address = 'erd1qqqqqqqqqqqqqpgqeel2kumf0r8ffyhth7pqdujjat9nx0862jpsg2pqaq'
wegld_token_id = 'WEGLD-bd4d79'
usdc_token_id = 'USDC-c76f1f'

# Optional: list of PEM file paths, one per wallet to use.
# Relative paths are resolved from the workspace root.
# If absent or empty, all operations are skipped with a warning.
wallet_pem_paths = [
'../../../../../sdk/core/src/test_wallets/s0phie.pem',
'../../../../../sdk/core/src/test_wallets/s1mon.pem',
'../../../../../sdk/core/src/test_wallets/s2onja.pem',
]

contract_addresses = [
"erd1qqqqqqqqqqqqqpgqe8jtrfmj5f6jcmn605r5t8950p3wu63gqqqqedcx6q",
"erd1qqqqqqqqqqqqqpgq5zrl4gg8mvhka724l88gst0r3csscqv6qqqsh8ljxe",
"erd1qqqqqqqqqqqqqpgqqkq5a4au3t5ydws4y7eq86wwxz8d8pe0qqpqcyl6cg",
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub struct Config {
pub pair_address: Bech32Address,
pub wegld_token_id: String,
pub usdc_token_id: String,
/// Optional list of PEM file paths, one per wallet.
/// If absent or empty, the built-in test wallets (sophie/simon/szonja) are used.
Comment thread
andrei-marinica marked this conversation as resolved.
Outdated
#[serde(default)]
pub wallet_pem_paths: Vec<String>,
/// Forwarder contract addresses to target for all swap transactions.
#[serde(default)]
pub contract_addresses: Vec<Bech32Address>,
}

impl Config {
Expand Down
Loading
Loading