Skip to content

Commit d181f1c

Browse files
committed
Refactor: Update hash type definitions and align associated conversions
1 parent af62ad8 commit d181f1c

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

codec/src/map_parameters.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ pub fn to_hash<const N: usize>(pallas_hash: &pallas_primitives::Hash<N>) -> Hash
3737

3838
/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
3939
/// Works for any hash size N
40-
pub fn genesis_to_hash<const N: usize>(pallas_hash: &pallas_primitives::Genesishash) -> Hash<N> {
41-
Hash::try_from(pallas_hash.as_ref()).unwrap()
40+
pub fn genesis_to_hash(pallas_hash: &pallas_primitives::Genesishash) -> GenesisKeyhash {
41+
GenesisKeyhash::try_from(pallas_hash.as_ref()).unwrap()
4242
}
4343

4444
/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
4545
/// Works for any hash size N
46-
pub fn genesis_delegate_to_hash<const N: usize>(
47-
pallas_hash: &pallas_primitives::GenesisDelegateHash,
48-
) -> Hash<N> {
49-
Hash::try_from(pallas_hash.as_ref()).unwrap()
46+
pub fn genesis_delegate_to_hash(pallas_hash: &pallas_primitives::GenesisDelegateHash) -> PoolId {
47+
PoolId::try_from(pallas_hash.as_ref()).unwrap()
5048
}
5149

5250
/// Convert a Pallas Hash<28> reference to an Acropolis PoolId

common/src/types.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub type ScriptHash = KeyHash;
450450
pub type AddrKeyhash = KeyHash;
451451

452452
/// Script identifier
453-
pub type GenesisKeyhash = Vec<u8>;
453+
pub type GenesisKeyhash = Hash<32>;
454454

455455
declare_hash_type!(BlockHash, 32);
456456
declare_hash_type!(TxHash, 32);
@@ -982,10 +982,10 @@ pub struct SPORewards {
982982
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
983983
pub struct GenesisKeyDelegation {
984984
/// Genesis hash
985-
pub genesis_hash: KeyHash,
985+
pub genesis_hash: GenesisKeyhash,
986986

987987
/// Genesis delegate hash
988-
pub genesis_delegate_hash: KeyHash,
988+
pub genesis_delegate_hash: PoolId,
989989

990990
/// VRF key hash
991991
pub vrf_key_hash: VrfKeyHash,
@@ -1678,19 +1678,23 @@ pub enum Voter {
16781678
StakePoolKey(PoolId),
16791679
}
16801680

1681-
impl Display for Voter {
1682-
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1683-
let bech32 = match self {
1681+
impl Voter {
1682+
pub fn to_bech32(&self) -> Result<String, Error> {
1683+
match self {
16841684
Voter::ConstitutionalCommitteeKey(h) => h.to_bech32(),
16851685
Voter::ConstitutionalCommitteeScript(s) => s.to_bech32(),
16861686
Voter::DRepKey(k) => k.to_bech32(),
16871687
Voter::DRepScript(s) => s.to_bech32(),
16881688
Voter::StakePoolKey(k) => k.to_bech32(),
1689-
};
1689+
}
1690+
}
1691+
}
16901692

1691-
match bech32 {
1692-
Ok(s) => write!(f, "{}", s),
1693-
Err(e) => write!(f, "<invalid: {}>", e),
1693+
impl Display for Voter {
1694+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1695+
match self.to_bech32() {
1696+
Ok(addr) => write!(f, "{}", addr),
1697+
Err(e) => write!(f, "<invalid voter: {}>", e),
16941698
}
16951699
}
16961700
}

modules/stake_delta_filter/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ mod test {
429429
}
430430
}
431431

432-
pub fn script_to_hash<const N: usize>(pallas_hash: ScriptHash) -> Hash<N> {
432+
pub fn script_to_hash(pallas_hash: ScriptHash) -> Hash<28> {
433433
pallas_hash.as_ref().try_into().unwrap()
434434
}
435435

436-
pub fn stake_to_hash<const N: usize>(pallas_hash: StakeKeyHash) -> Hash<N> {
436+
pub fn stake_to_hash(pallas_hash: StakeKeyHash) -> Hash<28> {
437437
pallas_hash.as_ref().try_into().unwrap()
438438
}
439439

440-
pub fn payment_to_hash<const N: usize>(pallas_hash: PaymentKeyHash) -> Hash<N> {
440+
pub fn payment_to_hash(pallas_hash: PaymentKeyHash) -> Hash<28> {
441441
pallas_hash.as_ref().try_into().unwrap()
442442
}
443443

0 commit comments

Comments
 (0)