Skip to content

Commit 0f551f9

Browse files
committed
Refactor: Replace gen_delegs Vec<u8> with PoolId
1 parent 0dc9c03 commit 0f551f9

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

codec/src/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
use acropolis_common::{
2-
GenesisDelegate, HeavyDelegate, crypto::keyhash_224, queries::blocks::BlockIssuer,
2+
GenesisDelegate, HeavyDelegate, PoolId, crypto::keyhash_224, queries::blocks::BlockIssuer,
33
};
44
use pallas_primitives::byron::BlockSig::DlgSig;
55
use pallas_traverse::MultiEraHeader;
66
use std::collections::HashMap;
77

88
pub fn map_to_block_issuer(
99
header: &MultiEraHeader,
10-
byron_heavy_delegates: &HashMap<Vec<u8>, HeavyDelegate>,
11-
shelley_genesis_delegates: &HashMap<Vec<u8>, GenesisDelegate>,
10+
byron_heavy_delegates: &HashMap<PoolId, HeavyDelegate>,
11+
shelley_genesis_delegates: &HashMap<PoolId, GenesisDelegate>,
1212
) -> Option<BlockIssuer> {
1313
match header.issuer_vkey() {
1414
Some(vkey) => match header {
1515
MultiEraHeader::ShelleyCompatible(_) => {
1616
let digest = keyhash_224(vkey);
1717
if let Some(issuer) = shelley_genesis_delegates
1818
.values()
19-
.find(|v| v.delegate == digest.to_vec())
19+
.find(|v| v.delegate == digest)
2020
.map(|i| BlockIssuer::GenesisDelegate(i.clone()))
2121
{
2222
Some(issuer)

common/src/protocol_params.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
genesis_values::GenesisValues,
33
rational_number::{ChameleonFraction, RationalNumber},
44
BlockHash, BlockVersionData, Committee, Constitution, CostModel, DRepVotingThresholds, Era,
5-
ExUnitPrices, ExUnits, GenesisDelegate, HeavyDelegate, NetworkId, PoolVotingThresholds,
5+
ExUnitPrices, ExUnits, GenesisDelegate, HeavyDelegate, NetworkId, PoolId, PoolVotingThresholds,
66
ProtocolConsts,
77
};
88
use anyhow::{bail, Result};
@@ -34,7 +34,7 @@ pub struct ByronParams {
3434
pub start_time: u64,
3535

3636
#[serde_as(as = "Vec<(_, _)>")]
37-
pub heavy_delegation: HashMap<Vec<u8>, HeavyDelegate>,
37+
pub heavy_delegation: HashMap<PoolId, HeavyDelegate>,
3838
}
3939

4040
//
@@ -131,7 +131,7 @@ pub struct ShelleyParams {
131131
pub update_quorum: u32,
132132

133133
#[serde_as(as = "HashMap<Hex, _>")]
134-
pub gen_delegs: HashMap<Vec<u8>, GenesisDelegate>,
134+
pub gen_delegs: HashMap<PoolId, GenesisDelegate>,
135135
}
136136

137137
#[serde_as]

common/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ pub struct HeavyDelegate {
13501350
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
13511351
pub struct GenesisDelegate {
13521352
#[serde_as(as = "Hex")]
1353-
pub delegate: Vec<u8>,
1353+
pub delegate: Hash<28>,
13541354
#[serde_as(as = "Hex")]
13551355
pub vrf: Vec<u8>,
13561356
}

modules/accounts_state/src/monetary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ fn calculate_monetary_expansion(
108108
mod tests {
109109
use super::*;
110110
use acropolis_common::rational_number::rational_number_from_f32;
111-
use acropolis_common::NetworkId;
112111
use acropolis_common::{
113112
protocol_params::{Nonce, NonceVariant, ProtocolVersion, ShelleyProtocolParams},
114113
GenesisDelegate,
115114
};
115+
use acropolis_common::{NetworkId, PoolId};
116116
use chrono::{DateTime, Utc};
117117
use std::collections::HashMap;
118118

@@ -175,7 +175,7 @@ mod tests {
175175
slots_per_kes_period: 129600,
176176
system_start: DateTime::<Utc>::default(),
177177
update_quorum: 5,
178-
gen_delegs: HashMap::<Vec<u8>, GenesisDelegate>::new(),
178+
gen_delegs: HashMap::<PoolId, GenesisDelegate>::new(),
179179
}
180180
}
181181

modules/chain_store/src/chain_store.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use acropolis_common::{
1212
},
1313
queries::misc::Order,
1414
state_history::{StateHistory, StateHistoryStore},
15-
BechOrdAddress, BlockHash, GenesisDelegate, HeavyDelegate, TxHash,
15+
BechOrdAddress, BlockHash, GenesisDelegate, HeavyDelegate, PoolId, TxHash,
1616
};
1717
use anyhow::{bail, Result};
1818
use caryatid_sdk::{module, Context, Module};
@@ -525,8 +525,8 @@ impl ChainStore {
525525

526526
#[derive(Default, Debug, Clone)]
527527
pub struct State {
528-
pub byron_heavy_delegates: HashMap<Vec<u8>, HeavyDelegate>,
529-
pub shelley_genesis_delegates: HashMap<Vec<u8>, GenesisDelegate>,
528+
pub byron_heavy_delegates: HashMap<PoolId, HeavyDelegate>,
529+
pub shelley_genesis_delegates: HashMap<PoolId, GenesisDelegate>,
530530
}
531531

532532
impl State {

modules/parameters_state/src/genesis_params.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use acropolis_common::{
33
protocol_params::{AlonzoParams, BabbageParams, ByronParams, ConwayParams, ShelleyParams},
44
rational_number::{rational_number_from_f32, RationalNumber},
55
Anchor, BlockVersionData, Committee, Constitution, CostModel, Credential, DRepVotingThresholds,
6-
Era, HeavyDelegate, PoolVotingThresholds, ProtocolConsts, SoftForkRule, TxFeePolicy,
6+
Era, HeavyDelegate, PoolId, PoolVotingThresholds, ProtocolConsts, SoftForkRule, TxFeePolicy,
77
};
88
use anyhow::{anyhow, bail, Result};
99
use base64::prelude::*;
@@ -183,13 +183,13 @@ fn map_byron(genesis: &byron::GenesisFile) -> Result<ByronParams> {
183183
.heavy_delegation
184184
.iter()
185185
.map(|(k, v)| {
186-
let k = hex::decode(k)?;
186+
let k = PoolId::try_from(decode(k)?)?;
187187
let v = HeavyDelegate {
188-
cert: hex::decode(v.cert.clone())?,
188+
cert: decode(v.cert.clone())?,
189189
delegate_pk: BASE64_STANDARD.decode(v.delegate_pk.clone())?,
190190
issuer_pk: BASE64_STANDARD.decode(v.issuer_pk.clone())?,
191191
};
192-
Ok::<(Vec<u8>, HeavyDelegate), anyhow::Error>((k, v))
192+
Ok::<(PoolId, HeavyDelegate), anyhow::Error>((k, v))
193193
})
194194
.collect::<Result<_, _>>()?;
195195
Ok(ByronParams {

0 commit comments

Comments
 (0)