Skip to content

Commit 01cc383

Browse files
authored
refactor: move tests to the bottom of the file, remove redundant parentheses
1 parent 15e7742 commit 01cc383

File tree

1 file changed

+76
-76
lines changed
  • toolkit/sidechain/domain/src

1 file changed

+76
-76
lines changed

toolkit/sidechain/domain/src/lib.rs

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,82 @@ pub struct AdaBasedStaking {
14161416
pub signature: MainchainSignature,
14171417
}
14181418

1419+
#[derive(
1420+
Clone,
1421+
PartialEq,
1422+
Eq,
1423+
Ord,
1424+
PartialOrd,
1425+
TypeInfo,
1426+
MaxEncodedLen,
1427+
Encode,
1428+
Decode,
1429+
DecodeWithMemTracking,
1430+
)]
1431+
/// Represents a Cardano ADA delegator
1432+
pub enum DelegatorKey {
1433+
/// Represents a staking address that is controlled by a user delegator
1434+
StakeKeyHash([u8; 28]),
1435+
/// Represents a staking address that is locked by a Plutus script
1436+
ScriptKeyHash {
1437+
/// Raw stake address hash
1438+
hash_raw: [u8; 28],
1439+
/// Hash of the Plutus script controlling the staking address
1440+
script_hash: [u8; 28],
1441+
},
1442+
}
1443+
1444+
impl alloc::fmt::Debug for DelegatorKey {
1445+
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
1446+
let s = match self {
1447+
Self::ScriptKeyHash { hash_raw, script_hash } => alloc::format!(
1448+
"ScriptKeyHash{{ hash_raw: {}, script_hash: {} }}",
1449+
hex::encode(hash_raw),
1450+
hex::encode(script_hash)
1451+
),
1452+
Self::StakeKeyHash(hash) => alloc::format!("StakeKeyHash({})", hex::encode(hash)),
1453+
};
1454+
1455+
f.write_str(&s)
1456+
}
1457+
}
1458+
1459+
/// Amount of Lovelace staked by a Cardano delegator to a single stake pool
1460+
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
1461+
pub struct DelegatorStakeAmount(pub u64);
1462+
1463+
impl<T: Into<u64>> From<T> for DelegatorStakeAmount {
1464+
fn from(value: T) -> Self {
1465+
Self(value.into())
1466+
}
1467+
}
1468+
1469+
/// A mapping between Cardano SPOs and the information about ADA delegation of their stake pools
1470+
///
1471+
/// This mapping can be used to calculate relative share of the total delegation for the
1472+
/// purpose of weighing during block producer selection.
1473+
#[derive(Debug, Clone, Default)]
1474+
pub struct StakeDistribution(pub BTreeMap<MainchainKeyHash, PoolDelegation>);
1475+
1476+
/// ADA delegation data for a single Cardano SPO
1477+
#[derive(Debug, Clone, Default, PartialEq)]
1478+
pub struct PoolDelegation {
1479+
/// Total amount delegated to the stake pool
1480+
pub total_stake: StakeDelegation,
1481+
/// Delegated amount for each delegator of the stake pool
1482+
pub delegators: BTreeMap<DelegatorKey, DelegatorStakeAmount>,
1483+
}
1484+
1485+
/// [FromStr] trait with [FromStr::Err] fixed to a type compatible with `clap`'s `value_parser` macro.
1486+
pub trait FromStrStdErr:
1487+
FromStr<Err: Into<alloc::boxed::Box<dyn core::error::Error + Send + Sync + 'static>>>
1488+
{
1489+
}
1490+
impl<T: FromStr<Err: Into<alloc::boxed::Box<dyn core::error::Error + Send + Sync + 'static>>>>
1491+
FromStrStdErr for T
1492+
{
1493+
}
1494+
14191495
#[cfg(test)]
14201496
mod tests {
14211497
use super::*;
@@ -1534,79 +1610,3 @@ mod tests {
15341610
assert_eq!(keys, decoded)
15351611
}
15361612
}
1537-
1538-
#[derive(
1539-
Clone,
1540-
PartialEq,
1541-
Eq,
1542-
Ord,
1543-
PartialOrd,
1544-
TypeInfo,
1545-
MaxEncodedLen,
1546-
Encode,
1547-
Decode,
1548-
DecodeWithMemTracking,
1549-
)]
1550-
/// Represents a Cardano ADA delegator
1551-
pub enum DelegatorKey {
1552-
/// Represents a staking address that is controlled by a user delegator
1553-
StakeKeyHash([u8; 28]),
1554-
/// Represents a staking address that is locked by a Plutus script
1555-
ScriptKeyHash {
1556-
/// Raw stake address hash
1557-
hash_raw: [u8; 28],
1558-
/// Hash of the Plutus script controlling the staking address
1559-
script_hash: [u8; 28],
1560-
},
1561-
}
1562-
1563-
impl alloc::fmt::Debug for DelegatorKey {
1564-
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
1565-
let s = match self {
1566-
Self::ScriptKeyHash { hash_raw, script_hash } => alloc::format!(
1567-
"ScriptKeyHash{{ hash_raw: {}, script_hash: {} }}",
1568-
hex::encode(hash_raw),
1569-
hex::encode(script_hash)
1570-
),
1571-
Self::StakeKeyHash(hash) => alloc::format!("StakeKeyHash({})", hex::encode(hash)),
1572-
};
1573-
1574-
f.write_str(&s)
1575-
}
1576-
}
1577-
1578-
/// Amount of Lovelace staked by a Cardano delegator to a single stake pool
1579-
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
1580-
pub struct DelegatorStakeAmount(pub u64);
1581-
1582-
impl<T: Into<u64>> From<T> for DelegatorStakeAmount {
1583-
fn from(value: T) -> Self {
1584-
Self(value.into())
1585-
}
1586-
}
1587-
1588-
/// A mapping between Cardano SPOs and the information about ADA delegation of their stake pools
1589-
///
1590-
/// This mapping can be used to calculate relative share of the total delegation for the
1591-
/// purpose of weighing during block producer selection.
1592-
#[derive(Debug, Clone, Default)]
1593-
pub struct StakeDistribution(pub BTreeMap<MainchainKeyHash, PoolDelegation>);
1594-
1595-
/// ADA delegation data for a single Cardano SPO
1596-
#[derive(Debug, Clone, Default, PartialEq)]
1597-
pub struct PoolDelegation {
1598-
/// Total amount delegated to the stake pool
1599-
pub total_stake: StakeDelegation,
1600-
/// Delegated amount for each delegator of the stake pool
1601-
pub delegators: BTreeMap<DelegatorKey, DelegatorStakeAmount>,
1602-
}
1603-
1604-
/// [FromStr] trait with [FromStr::Err] fixed to a type compatible with `clap`'s `value_parser` macro.
1605-
pub trait FromStrStdErr:
1606-
FromStr<Err: Into<alloc::boxed::Box<(dyn core::error::Error + Send + Sync + 'static)>>>
1607-
{
1608-
}
1609-
impl<T: FromStr<Err: Into<alloc::boxed::Box<(dyn core::error::Error + Send + Sync + 'static)>>>>
1610-
FromStrStdErr for T
1611-
{
1612-
}

0 commit comments

Comments
 (0)