Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fb6432b
Refactor: Replace `Vec<u8>` with `KeyHash` and introduce type-safe `H…
lowhung Oct 27, 2025
a4887c4
Merge branch 'main' into lowhung/unify-hash-types
lowhung Oct 27, 2025
5f65e4f
Continue coercing types and defining clearer names for the keys in use
lowhung Oct 28, 2025
df95809
Refactor: Replace `KeyHash` with `PoolId` for stronger type safety ac…
lowhung Oct 28, 2025
fe2b0d6
Fix epochs state / update rest handlers
lowhung Oct 28, 2025
41681ea
Refactor: Introduce type-safe `Hash` conversion utilities, replace ma…
lowhung Oct 28, 2025
a7cfb00
Delete unused `byte_array` module and remove associated references fo…
lowhung Oct 28, 2025
727ffee
Refactor: Replace `VRFKey` with `VrfKeyHash` across modules for consi…
lowhung Oct 28, 2025
f77d2dc
Merge in main
lowhung Oct 29, 2025
fb77f49
Refactor: Replace manual key hash conversions with type-safe utilitie…
lowhung Oct 29, 2025
5a49952
Refactor: Replace manual key hash conversions with type-safe utilitie…
lowhung Oct 29, 2025
6d0ad83
Refactor: Consolidate `declare_hash_type_with_bech32!` macros, remove…
lowhung Oct 29, 2025
8dcddf4
Merge remote-tracking branch 'origin/lowhung/unify-hash-types' into l…
lowhung Oct 29, 2025
4e9c167
Merge branch 'main' into lowhung/unify-hash-types
lowhung Oct 29, 2025
28cbe9d
Refactor: Format imports for readability, add `#[ignore]` to `test_vo…
lowhung Oct 29, 2025
0432374
Merge branch 'main' into lowhung/unify-hash-types
lowhung Oct 29, 2025
b2cd604
Merge branch 'lowhung/introduce-combined-hash-file' into lowhung/unif…
lowhung Oct 29, 2025
87b2ea6
Refactor: Replace `PoolId::new` and `KeyHash::new` with `.into()` for…
lowhung Oct 29, 2025
119426f
Refactor: Replace `KeyHash::try_from` with `.try_into()` for consiste…
lowhung Oct 30, 2025
2f61e83
Merge branch 'main' into lowhung/unify-hash-types
lowhung Oct 30, 2025
a3dd388
Use as_ref in immutable_historical_account_store.rs vs into_inner()
lowhung Oct 30, 2025
af62ad8
Refactor: Consolidate hash type definitions and unify conversions acr…
lowhung Oct 30, 2025
d181f1c
Refactor: Update hash type definitions and align associated conversions
lowhung Oct 30, 2025
0dc9c03
Refactor: Update `GenesisKeyhash` to use consistent hash types and im…
lowhung Oct 31, 2025
0f551f9
Refactor: Replace gen_delegs `Vec<u8>` with `PoolId`
lowhung Oct 31, 2025
064e38b
Refactor: Replace `Vec<u8>` with `PoolId` and add Bech32 (de)serializ…
lowhung Oct 31, 2025
68a5d59
Merge branch 'main' into lowhung/unify-hash-types
lowhung Oct 31, 2025
dc38a71
Refactor: Replace `KeyHash` with `PoolId` for verifier.rs
lowhung Oct 31, 2025
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
6 changes: 3 additions & 3 deletions codec/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use acropolis_common::{
GenesisDelegate, HeavyDelegate, crypto::keyhash_224, queries::blocks::BlockIssuer,
GenesisDelegate, HeavyDelegate, PoolId, crypto::keyhash_224, queries::blocks::BlockIssuer,
};
use pallas_primitives::byron::BlockSig::DlgSig;
use pallas_traverse::MultiEraHeader;
use std::collections::HashMap;

pub fn map_to_block_issuer(
header: &MultiEraHeader,
byron_heavy_delegates: &HashMap<Vec<u8>, HeavyDelegate>,
shelley_genesis_delegates: &HashMap<Vec<u8>, GenesisDelegate>,
byron_heavy_delegates: &HashMap<PoolId, HeavyDelegate>,
shelley_genesis_delegates: &HashMap<PoolId, GenesisDelegate>,
) -> Option<BlockIssuer> {
match header.issuer_vkey() {
Some(vkey) => match header {
Expand Down
97 changes: 63 additions & 34 deletions codec/src/map_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use pallas::ledger::{
*,
};

use acropolis_common::hash::Hash;
use acropolis_common::{
protocol_params::{Nonce, NonceVariant, ProtocolVersion},
rational_number::RationalNumber,
Expand All @@ -28,6 +29,34 @@ pub fn map_network(network: addresses::Network) -> Result<NetworkId> {
}
}

/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
/// Works for any hash size N
pub fn to_hash<const N: usize>(pallas_hash: &pallas_primitives::Hash<N>) -> Hash<N> {
Hash::try_from(pallas_hash.as_ref()).unwrap()
}

/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
/// Works for any hash size N
pub fn genesis_to_hash(pallas_hash: &pallas_primitives::Genesishash) -> Hash<32> {
Hash::try_from(pallas_hash.as_ref()).unwrap()
}

/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
/// Works for any hash size N
pub fn genesis_delegate_to_hash(pallas_hash: &pallas_primitives::GenesisDelegateHash) -> PoolId {
PoolId::try_from(pallas_hash.as_ref()).unwrap()
}

/// Convert a Pallas Hash<28> reference to an Acropolis PoolId
pub fn to_pool_id(pallas_hash: &pallas_primitives::Hash<28>) -> PoolId {
to_hash(pallas_hash).into()
}

/// Convert a Pallas Hash<32> reference to an Acropolis VRFKey
pub fn to_vrf_key(pallas_hash: &pallas_primitives::Hash<32>) -> VrfKeyHash {
VrfKeyHash::try_from(pallas_hash.as_ref()).unwrap()
}

/// Derive our Address from a Pallas address
// This is essentially a 1:1 mapping but makes the Message definitions independent
// of Pallas
Expand All @@ -42,20 +71,20 @@ pub fn map_address(address: &addresses::Address) -> Result<Address> {

payment: match shelley_address.payment() {
addresses::ShelleyPaymentPart::Key(hash) => {
ShelleyAddressPaymentPart::PaymentKeyHash(hash.to_vec())
ShelleyAddressPaymentPart::PaymentKeyHash(to_hash(hash))
}
addresses::ShelleyPaymentPart::Script(hash) => {
ShelleyAddressPaymentPart::ScriptHash(hash.to_vec())
ShelleyAddressPaymentPart::ScriptHash(to_hash(hash))
}
},

delegation: match shelley_address.delegation() {
addresses::ShelleyDelegationPart::Null => ShelleyAddressDelegationPart::None,
addresses::ShelleyDelegationPart::Key(hash) => {
ShelleyAddressDelegationPart::StakeKeyHash(hash.to_vec())
ShelleyAddressDelegationPart::StakeKeyHash(to_hash(hash))
}
addresses::ShelleyDelegationPart::Script(hash) => {
ShelleyAddressDelegationPart::ScriptHash(hash.to_vec())
ShelleyAddressDelegationPart::ScriptHash(to_hash(hash))
}
addresses::ShelleyDelegationPart::Pointer(pointer) => {
ShelleyAddressDelegationPart::Pointer(ShelleyAddressPointer {
Expand All @@ -70,8 +99,8 @@ pub fn map_address(address: &addresses::Address) -> Result<Address> {
addresses::Address::Stake(stake_address) => Ok(Address::Stake(StakeAddress {
network: map_network(stake_address.network())?,
credential: match stake_address.payload() {
addresses::StakePayload::Stake(hash) => StakeCredential::AddrKeyHash(hash.to_vec()),
addresses::StakePayload::Script(hash) => StakeCredential::ScriptHash(hash.to_vec()),
addresses::StakePayload::Stake(hash) => StakeCredential::AddrKeyHash(to_hash(hash)),
addresses::StakePayload::Script(hash) => StakeCredential::ScriptHash(to_hash(hash)),
},
})),
}
Expand All @@ -81,10 +110,10 @@ pub fn map_address(address: &addresses::Address) -> Result<Address> {
pub fn map_stake_credential(cred: &PallasStakeCredential) -> StakeCredential {
match cred {
PallasStakeCredential::AddrKeyhash(key_hash) => {
StakeCredential::AddrKeyHash(key_hash.to_vec())
StakeCredential::AddrKeyHash(to_hash(key_hash))
}
PallasStakeCredential::ScriptHash(script_hash) => {
StakeCredential::ScriptHash(script_hash.to_vec())
StakeCredential::ScriptHash(to_hash(script_hash))
}
}
}
Expand All @@ -93,10 +122,10 @@ pub fn map_stake_credential(cred: &PallasStakeCredential) -> StakeCredential {
pub fn map_stake_address(cred: &PallasStakeCredential, network_id: NetworkId) -> StakeAddress {
let payload = match cred {
PallasStakeCredential::AddrKeyhash(key_hash) => {
StakeCredential::AddrKeyHash(key_hash.to_vec())
StakeCredential::AddrKeyHash(to_hash(key_hash))
}
PallasStakeCredential::ScriptHash(script_hash) => {
StakeCredential::ScriptHash(script_hash.to_vec())
StakeCredential::ScriptHash(to_hash(script_hash))
}
};

Expand All @@ -106,8 +135,8 @@ pub fn map_stake_address(cred: &PallasStakeCredential, network_id: NetworkId) ->
/// Map a Pallas DRep to our DRepChoice
pub fn map_drep(drep: &conway::DRep) -> DRepChoice {
match drep {
conway::DRep::Key(key_hash) => DRepChoice::Key(key_hash.to_vec()),
conway::DRep::Script(script_hash) => DRepChoice::Script(script_hash.to_vec()),
conway::DRep::Key(key_hash) => DRepChoice::Key(to_hash(key_hash)),
conway::DRep::Script(script_hash) => DRepChoice::Script(to_hash(script_hash)),
conway::DRep::Abstain => DRepChoice::Abstain,
conway::DRep::NoConfidence => DRepChoice::NoConfidence,
}
Expand Down Expand Up @@ -169,7 +198,7 @@ pub fn map_nullable_gov_action_id(
fn map_constitution(constitution: &conway::Constitution) -> Constitution {
Constitution {
anchor: map_anchor(&constitution.anchor),
guardrail_script: map_nullable(|x| x.to_vec(), &constitution.guardrail_script),
guardrail_script: map_nullable(|x| to_hash(x), &constitution.guardrail_script),
}
}

Expand Down Expand Up @@ -231,7 +260,7 @@ pub fn map_certificate(
alonzo::Certificate::StakeDelegation(cred, pool_key_hash) => Ok(TxCertificateWithPos {
cert: TxCertificate::StakeDelegation(StakeDelegation {
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
}),
tx_identifier,
cert_index: cert_index.try_into().unwrap(),
Expand All @@ -248,8 +277,8 @@ pub fn map_certificate(
pool_metadata,
} => Ok(TxCertificateWithPos {
cert: TxCertificate::PoolRegistration(PoolRegistration {
operator: operator.to_vec(),
vrf_key_hash: vrf_keyhash.to_vec(),
operator: to_pool_id(operator),
vrf_key_hash: to_vrf_key(vrf_keyhash),
pledge: *pledge,
cost: *cost,
margin: Ratio {
Expand All @@ -261,7 +290,7 @@ pub fn map_certificate(
.iter()
.map(|v| {
StakeAddress::new(
StakeCredential::AddrKeyHash(v.to_vec()),
StakeCredential::AddrKeyHash(to_hash(v)),
network_id.clone(),
)
})
Expand All @@ -280,7 +309,7 @@ pub fn map_certificate(
}),
alonzo::Certificate::PoolRetirement(pool_key_hash, epoch) => Ok(TxCertificateWithPos {
cert: TxCertificate::PoolRetirement(PoolRetirement {
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
epoch: *epoch,
}),
tx_identifier,
Expand All @@ -292,9 +321,9 @@ pub fn map_certificate(
vrf_key_hash,
) => Ok(TxCertificateWithPos {
cert: TxCertificate::GenesisKeyDelegation(GenesisKeyDelegation {
genesis_hash: genesis_hash.to_vec(),
genesis_delegate_hash: genesis_delegate_hash.to_vec(),
vrf_key_hash: vrf_key_hash.to_vec(),
genesis_hash: genesis_to_hash(genesis_hash),
genesis_delegate_hash: genesis_delegate_to_hash(genesis_delegate_hash),
vrf_key_hash: to_vrf_key(vrf_key_hash),
}),
tx_identifier,
cert_index: cert_index as u64,
Expand Down Expand Up @@ -348,7 +377,7 @@ pub fn map_certificate(
Ok(TxCertificateWithPos {
cert: TxCertificate::StakeDelegation(StakeDelegation {
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
}),
tx_identifier,
cert_index: cert_index.try_into().unwrap(),
Expand All @@ -368,8 +397,8 @@ pub fn map_certificate(
pool_metadata,
} => Ok(TxCertificateWithPos {
cert: TxCertificate::PoolRegistration(PoolRegistration {
operator: operator.to_vec(),
vrf_key_hash: vrf_keyhash.to_vec(),
operator: to_pool_id(operator),
vrf_key_hash: to_vrf_key(vrf_keyhash),
pledge: *pledge,
cost: *cost,
margin: Ratio {
Expand All @@ -388,7 +417,7 @@ pub fn map_certificate(
.into_iter()
.map(|v| {
StakeAddress::new(
StakeCredential::AddrKeyHash(v.to_vec()),
StakeCredential::AddrKeyHash(to_hash(v)),
network_id.clone(),
)
})
Expand All @@ -408,7 +437,7 @@ pub fn map_certificate(
conway::Certificate::PoolRetirement(pool_key_hash, epoch) => {
Ok(TxCertificateWithPos {
cert: TxCertificate::PoolRetirement(PoolRetirement {
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
epoch: *epoch,
}),
tx_identifier,
Expand Down Expand Up @@ -447,7 +476,7 @@ pub fn map_certificate(
Ok(TxCertificateWithPos {
cert: TxCertificate::StakeAndVoteDelegation(StakeAndVoteDelegation {
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
drep: map_drep(drep),
}),
tx_identifier,
Expand All @@ -460,7 +489,7 @@ pub fn map_certificate(
cert: TxCertificate::StakeRegistrationAndDelegation(
StakeRegistrationAndDelegation {
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
deposit: *coin,
},
),
Expand All @@ -486,7 +515,7 @@ pub fn map_certificate(
cert: TxCertificate::StakeRegistrationAndStakeAndVoteDelegation(
StakeRegistrationAndStakeAndVoteDelegation {
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
operator: to_pool_id(pool_key_hash),
drep: map_drep(drep),
deposit: *coin,
},
Expand Down Expand Up @@ -881,14 +910,14 @@ pub fn map_governance_proposals_procedures(
fn map_voter(voter: &conway::Voter) -> Voter {
match voter {
conway::Voter::ConstitutionalCommitteeKey(key_hash) => {
Voter::ConstitutionalCommitteeKey(key_hash.to_vec())
Voter::ConstitutionalCommitteeKey(to_hash(key_hash).into())
}
conway::Voter::ConstitutionalCommitteeScript(script_hash) => {
Voter::ConstitutionalCommitteeScript(script_hash.to_vec())
Voter::ConstitutionalCommitteeScript(to_hash(script_hash).into())
}
conway::Voter::DRepKey(addr_key_hash) => Voter::DRepKey(addr_key_hash.to_vec()),
conway::Voter::DRepScript(script_hash) => Voter::DRepScript(script_hash.to_vec()),
conway::Voter::StakePoolKey(key_hash) => Voter::StakePoolKey(key_hash.to_vec()),
conway::Voter::DRepKey(addr_key_hash) => Voter::DRepKey(to_hash(addr_key_hash).into()),
conway::Voter::DRepScript(script_hash) => Voter::DRepScript(to_hash(script_hash).into()),
conway::Voter::StakePoolKey(key_hash) => Voter::StakePoolKey(to_pool_id(key_hash)),
}
}

Expand Down
Loading