Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a4f6552
Refactor reward account handling to use `StakeAddress`
lowhung Oct 14, 2025
db99390
Refactor `StakeAddress` usage and clean up redundant annotations
lowhung Oct 14, 2025
97f38c2
Refactor `StakeAddress` usage to simplify `reward_account` initializa…
lowhung Oct 15, 2025
f76615f
Simplify `StakeAddress::from_binary` error handling in `reward_accoun…
lowhung Oct 15, 2025
5948f36
Refactor reward account handling to use `StakeAddress`
lowhung Oct 14, 2025
d033ba7
Refactor `StakeAddress` usage and clean up redundant annotations
lowhung Oct 14, 2025
add6d5d
Refactor `StakeAddress` usage to simplify `reward_account` initializa…
lowhung Oct 15, 2025
3e45097
Simplify `StakeAddress::from_binary` error handling in `reward_accoun…
lowhung Oct 15, 2025
bc0a981
Refactor `reward_account` handling to use `get_hash` method
lowhung Oct 15, 2025
19580f0
Merge remote-tracking branch 'origin/lowhung/163-replace-reward-accou…
lowhung Oct 15, 2025
c90a1c1
Replace `RewardAccount` with `StakeAddress` for consistency and simpl…
lowhung Oct 15, 2025
f625171
- Eliminate the `RewardAccount` type definition as it is no longer ne…
lowhung Oct 15, 2025
d4e7163
Add encode/decod, add comprehensive test cases for encoding, decoding
lowhung Oct 15, 2025
37a5334
Add encode/decod, add comprehensive test cases for encoding, decoding
lowhung Oct 15, 2025
6ee41c8
Update common/src/address.rs
lowhung Oct 15, 2025
1ae4fea
Add encode/decod, add comprehensive test cases for encoding, decoding
lowhung Oct 15, 2025
6d757e5
- Add `from_stake_key_hash` constructor for `StakeAddress` to simplif…
lowhung Oct 17, 2025
cb6b823
Merge remote-tracking branch 'origin/lowhung/163-replace-reward-accou…
lowhung Oct 17, 2025
497214e
Replace `KeyHash` with `StakeAddress` for consistency and unified han…
lowhung Oct 17, 2025
f503455
Refactor `stake_addresses` module: API improvements, test coverage ex…
lowhung Oct 18, 2025
529bc07
Replace hex-encoded reward account logging with direct `StakeAddress`…
lowhung Oct 20, 2025
1d8aacc
Refactor: Replace `KeyHash` with `Credential` across modules for unif…
lowhung Oct 21, 2025
32045af
Refactor: Simplify stake address handling and remove unnecessary enco…
lowhung Oct 21, 2025
fe8c1c9
### Description
lowhung Oct 22, 2025
f8a97b4
Refactor: Remove `NetworkId` from `BlockInfo` and standardize `StakeA…
lowhung Oct 22, 2025
de08f0a
Refactor: Replace `StakeCredentials` with `StakeAddresses` for MIR ta…
lowhung Oct 22, 2025
39e0f13
Refactor: Standardize variable names (e.g., `cred` -> `delegator`) fo…
lowhung Oct 22, 2025
2faea48
Merge pull request #265 from input-output-hk/lowhung/163-replace-rewa…
lowhung Oct 22, 2025
85f3354
Unstage files with simple import changes, use Display implementation …
lowhung Oct 22, 2025
f54e8f7
Merge branch 'main' into lowhung/163-replace-reward-account-with-stak…
lowhung Oct 22, 2025
9669139
Consolidated `#[derive(...)]` traits for `Credential` enum
lowhung Oct 22, 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
75 changes: 53 additions & 22 deletions codec/src/map_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ pub fn map_stake_credential(cred: &PallasStakeCredential) -> StakeCredential {
}
}

/// Map a PallasStakeCredential to our StakeAddress
pub fn map_stake_address(cred: &PallasStakeCredential, network_id: NetworkId) -> StakeAddress {
let payload = match cred {
PallasStakeCredential::AddrKeyhash(key_hash) => {
StakeAddressPayload::StakeKeyHash(key_hash.to_vec())
}
PallasStakeCredential::ScriptHash(script_hash) => {
StakeAddressPayload::ScriptHash(script_hash.to_vec())
}
};

StakeAddress::new(payload, network_id.into())
}

/// Map a Pallas DRep to our DRepChoice
pub fn map_drep(drep: &conway::DRep) -> DRepChoice {
match drep {
Expand Down Expand Up @@ -203,24 +217,25 @@ pub fn map_certificate(
tx_hash: TxHash,
tx_index: u16,
cert_index: usize,
network_id: NetworkId,
) -> Result<TxCertificate> {
match cert {
MultiEraCert::NotApplicable => Err(anyhow!("Not applicable cert!")),

MultiEraCert::AlonzoCompatible(cert) => match cert.as_ref().as_ref() {
alonzo::Certificate::StakeRegistration(cred) => {
Ok(TxCertificate::StakeRegistration(StakeCredentialWithPos {
stake_credential: map_stake_credential(cred),
Ok(TxCertificate::StakeRegistration(StakeAddressWithPos {
stake_address: map_stake_address(cred, network_id),
tx_index: tx_index.try_into().unwrap(),
cert_index: cert_index.try_into().unwrap(),
}))
}
alonzo::Certificate::StakeDeregistration(cred) => Ok(
TxCertificate::StakeDeregistration(map_stake_credential(cred)),
TxCertificate::StakeDeregistration(map_stake_address(cred, network_id)),
),
alonzo::Certificate::StakeDelegation(cred, pool_key_hash) => {
Ok(TxCertificate::StakeDelegation(StakeDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
}))
}
Expand All @@ -245,8 +260,16 @@ pub fn map_certificate(
numerator: margin.numerator,
denominator: margin.denominator,
},
reward_account: reward_account.to_vec(),
pool_owners: pool_owners.into_iter().map(|v| v.to_vec()).collect(),
reward_account: StakeAddress::from_binary(reward_account)?,
pool_owners: pool_owners
.into_iter()
.map(|v| {
StakeAddress::new(
StakeAddressPayload::StakeKeyHash(v.to_vec()),
network_id.clone().into(),
)
})
.collect(),
relays: relays.into_iter().map(|relay| map_relay(relay)).collect(),
pool_metadata: match pool_metadata {
Nullable::Some(md) => Some(PoolMetadata {
Expand Down Expand Up @@ -291,10 +314,10 @@ pub fn map_certificate(
},
target: match &mir.target {
alonzo::InstantaneousRewardTarget::StakeCredentials(creds) => {
InstantaneousRewardTarget::StakeCredentials(
InstantaneousRewardTarget::StakeAddresses(
creds
.iter()
.map(|(sc, v)| (map_stake_credential(&sc), *v))
.map(|(sc, v)| (map_stake_address(&sc, network_id.clone()), *v))
.collect(),
)
}
Expand All @@ -310,18 +333,18 @@ pub fn map_certificate(
MultiEraCert::Conway(cert) => {
match cert.as_ref().as_ref() {
conway::Certificate::StakeRegistration(cred) => {
Ok(TxCertificate::StakeRegistration(StakeCredentialWithPos {
stake_credential: map_stake_credential(cred),
Ok(TxCertificate::StakeRegistration(StakeAddressWithPos {
stake_address: map_stake_address(cred, network_id),
tx_index: tx_index.try_into().unwrap(),
cert_index: cert_index.try_into().unwrap(),
}))
}
conway::Certificate::StakeDeregistration(cred) => Ok(
TxCertificate::StakeDeregistration(map_stake_credential(cred)),
TxCertificate::StakeDeregistration(map_stake_address(cred, network_id)),
),
conway::Certificate::StakeDelegation(cred, pool_key_hash) => {
Ok(TxCertificate::StakeDelegation(StakeDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
}))
}
Expand All @@ -347,8 +370,16 @@ pub fn map_certificate(
numerator: margin.numerator,
denominator: margin.denominator,
},
reward_account: reward_account.to_vec(),
pool_owners: pool_owners.into_iter().map(|v| v.to_vec()).collect(),
reward_account: StakeAddress::from_binary(reward_account)?,
pool_owners: pool_owners
.into_iter()
.map(|v| {
StakeAddress::new(
StakeAddressPayload::StakeKeyHash(v.to_vec()),
network_id.clone().into(),
)
})
.collect(),
relays: relays.into_iter().map(|relay| map_relay(relay)).collect(),
pool_metadata: match pool_metadata {
Nullable::Some(md) => Some(PoolMetadata {
Expand All @@ -375,36 +406,36 @@ pub fn map_certificate(

conway::Certificate::Reg(cred, coin) => {
Ok(TxCertificate::Registration(Registration {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
deposit: *coin,
}))
}

conway::Certificate::UnReg(cred, coin) => {
Ok(TxCertificate::Deregistration(Deregistration {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
refund: *coin,
}))
}

conway::Certificate::VoteDeleg(cred, drep) => {
Ok(TxCertificate::VoteDelegation(VoteDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
drep: map_drep(drep),
}))
}

conway::Certificate::StakeVoteDeleg(cred, pool_key_hash, drep) => Ok(
TxCertificate::StakeAndVoteDelegation(StakeAndVoteDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
drep: map_drep(drep),
}),
),

conway::Certificate::StakeRegDeleg(cred, pool_key_hash, coin) => Ok(
TxCertificate::StakeRegistrationAndDelegation(StakeRegistrationAndDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
deposit: *coin,
}),
Expand All @@ -413,7 +444,7 @@ pub fn map_certificate(
conway::Certificate::VoteRegDeleg(cred, drep, coin) => {
Ok(TxCertificate::StakeRegistrationAndVoteDelegation(
StakeRegistrationAndVoteDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
drep: map_drep(drep),
deposit: *coin,
},
Expand All @@ -423,7 +454,7 @@ pub fn map_certificate(
conway::Certificate::StakeVoteRegDeleg(cred, pool_key_hash, drep, coin) => {
Ok(TxCertificate::StakeRegistrationAndStakeAndVoteDelegation(
StakeRegistrationAndStakeAndVoteDelegation {
credential: map_stake_credential(cred),
stake_address: map_stake_address(cred, network_id),
operator: pool_key_hash.to_vec(),
drep: map_drep(drep),
deposit: *coin,
Expand Down Expand Up @@ -804,7 +835,7 @@ pub fn map_governance_proposals_procedures(
) -> Result<ProposalProcedure> {
Ok(ProposalProcedure {
deposit: prop.deposit,
reward_account: prop.reward_account.to_vec(),
reward_account: StakeAddress::from_binary(&prop.reward_account)?,
gov_action_id: gov_action_id.clone(),
gov_action: map_governance_action(&prop.gov_action)?,
anchor: map_anchor(&prop.anchor),
Expand Down
Loading