Skip to content

Commit e01d07a

Browse files
committed
Merge branch 'main' into lowhung/refactor-key-hash-to-stake-address
# Conflicts: # common/src/stake_addresses.rs # modules/rest_blockfrost/src/handlers/epochs.rs # modules/rest_blockfrost/src/handlers/pools.rs # modules/rest_blockfrost/src/types.rs # modules/tx_unpacker/src/tx_unpacker.rs
2 parents 8c08f44 + 4586648 commit e01d07a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1171
-1056
lines changed

.github/workflows/run-tests-on-push-to-main.yml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,7 @@ jobs:
2424
run: cargo fmt --all -- --check
2525

2626
- name: Run Clippy
27-
run: |
28-
cargo clippy --all-targets --all-features \
29-
--package acropolis_common \
30-
--package acropolis_codec \
31-
--package acropolis_module_accounts_state \
32-
--package acropolis_module_address_state \
33-
--package acropolis_module_assets_state \
34-
--package acropolis_module_block_unpacker \
35-
--package acropolis_module_chain_store \
36-
--package acropolis_module_consensus \
37-
--package acropolis_module_drdd_state \
38-
--package acropolis_module_drep_state \
39-
--package acropolis_module_epochs_state \
40-
--package acropolis_module_genesis_bootstrapper \
41-
--package acropolis_module_governance_state \
42-
--package acropolis_module_historical_accounts_state \
43-
--package acropolis_module_mithril_snapshot_fetcher \
44-
--package acropolis_module_parameters_state \
45-
--package acropolis_module_rest_blockfrost \
46-
--package acropolis_module_snapshot_bootstrapper \
47-
--package acropolis_module_spdd_state \
48-
--package acropolis_module_spo_state \
49-
--package acropolis_module_stake_delta_filter \
50-
--package acropolis_module_tx_submitter \
51-
--package acropolis_module_tx_unpacker \
52-
--package acropolis_module_upstream_chain_fetcher \
53-
--package acropolis_module_utxo_state \
54-
--package acropolis_process_tx_submitter_cli
27+
run: cargo clippy --all-targets --all-features -- -D warnings
5528

5629
- name: Run Build
5730
run: cargo build --verbose

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codec/src/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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 {

codec/src/map_parameters.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ 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(pallas_hash: &pallas_primitives::Genesishash) -> GenesisKeyhash {
41-
GenesisKeyhash::try_from(pallas_hash.as_ref()).unwrap()
40+
pub fn genesis_to_hash(pallas_hash: &pallas_primitives::Genesishash) -> Hash<32> {
41+
Hash::try_from(pallas_hash.as_ref()).unwrap()
4242
}
4343

4444
/// Convert a Pallas Hash reference to an Acropolis Hash (owned)
@@ -198,7 +198,7 @@ pub fn map_nullable_gov_action_id(
198198
fn map_constitution(constitution: &conway::Constitution) -> Constitution {
199199
Constitution {
200200
anchor: map_anchor(&constitution.anchor),
201-
guardrail_script: map_nullable(|x| to_hash(x), &constitution.guardrail_script),
201+
guardrail_script: map_nullable(to_hash, &constitution.guardrail_script),
202202
}
203203
}
204204

common/src/address.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ impl StakeAddress {
398398

399399
pub fn get_credential(&self) -> Credential {
400400
match &self.credential {
401-
StakeCredential::AddrKeyHash(hash) => Credential::AddrKeyHash(hash.clone()),
402-
StakeCredential::ScriptHash(hash) => Credential::ScriptHash(hash.clone()),
401+
StakeCredential::AddrKeyHash(hash) => Credential::AddrKeyHash(*hash),
402+
StakeCredential::ScriptHash(hash) => Credential::ScriptHash(*hash),
403403
}
404404
}
405405

@@ -411,7 +411,7 @@ impl StakeAddress {
411411
};
412412

413413
let data = self.to_binary();
414-
Ok(bech32::encode::<bech32::Bech32>(hrp, &data.as_slice())?)
414+
Ok(bech32::encode::<bech32::Bech32>(hrp, data.as_slice())?)
415415
}
416416

417417
/// Read from a string format ("stake1xxx...")
@@ -520,7 +520,7 @@ impl<C> minicbor::Encode<C> for StakeAddress {
520520
_ctx: &mut C,
521521
) -> Result<(), minicbor::encode::Error<W::Error>> {
522522
let data = self.to_binary();
523-
e.bytes(&data.as_slice())?;
523+
e.bytes(data.as_slice())?;
524524
Ok(())
525525
}
526526
}
@@ -902,7 +902,7 @@ mod tests {
902902
assert_eq!(sa.network, NetworkId::Mainnet);
903903
assert_eq!(
904904
match sa.credential {
905-
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
905+
StakeCredential::AddrKeyHash(key) => hex::encode(key),
906906
_ => "SCRIPT".to_string(),
907907
},
908908
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -918,7 +918,7 @@ mod tests {
918918
assert_eq!(sa.network, NetworkId::Mainnet);
919919
assert_eq!(
920920
match sa.credential {
921-
StakeCredential::ScriptHash(key) => hex::encode(&key),
921+
StakeCredential::ScriptHash(key) => hex::encode(key),
922922
_ => "STAKE".to_string(),
923923
},
924924
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -934,7 +934,7 @@ mod tests {
934934
assert_eq!(sa.network, NetworkId::Testnet);
935935
assert_eq!(
936936
match sa.credential {
937-
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
937+
StakeCredential::AddrKeyHash(key) => hex::encode(key),
938938
_ => "SCRIPT".to_string(),
939939
},
940940
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -963,7 +963,7 @@ mod tests {
963963
// - 0x1d: Length of 29 bytes (the stake address data)
964964
// - [29 bytes]: The actual stake address (network header + 28-byte hash)
965965
// Total: 31 bytes (2-byte CBOR framing + 29-byte payload)
966-
let expected = [[0x58, 0x1d].as_slice(), &binary.as_slice()].concat();
966+
let expected = [[0x58, 0x1d].as_slice(), binary.as_slice()].concat();
967967

968968
let mut actual = Vec::new();
969969
let mut encoder = minicbor::Encoder::new(&mut actual);
@@ -977,7 +977,7 @@ mod tests {
977977
fn stake_addresses_decode_mainnet_stake() {
978978
let binary = {
979979
let mut v = vec![0x58, 0x1d];
980-
v.extend_from_slice(&mainnet_stake_address().to_binary().as_slice());
980+
v.extend_from_slice(mainnet_stake_address().to_binary().as_slice());
981981
v
982982
};
983983

@@ -987,7 +987,7 @@ mod tests {
987987
assert_eq!(decoded.network, NetworkId::Mainnet);
988988
assert_eq!(
989989
match decoded.credential {
990-
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
990+
StakeCredential::AddrKeyHash(key) => hex::encode(key),
991991
_ => "STAKE".to_string(),
992992
},
993993
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -1010,7 +1010,7 @@ mod tests {
10101010
assert_eq!(decoded.network, NetworkId::Mainnet);
10111011
assert_eq!(
10121012
match decoded.credential {
1013-
StakeCredential::ScriptHash(key) => hex::encode(&key),
1013+
StakeCredential::ScriptHash(key) => hex::encode(key),
10141014
_ => "STAKE".to_string(),
10151015
},
10161016
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
@@ -1031,7 +1031,7 @@ mod tests {
10311031
assert_eq!(decoded.network, NetworkId::Testnet);
10321032
assert_eq!(
10331033
match decoded.credential {
1034-
StakeCredential::ScriptHash(key) => hex::encode(&key),
1034+
StakeCredential::ScriptHash(key) => hex::encode(key),
10351035
_ => "SCRIPT".to_string(),
10361036
},
10371037
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"

common/src/crypto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cryptoxide::hashing::blake2b::Blake2b;
99
pub fn keyhash_256(key: &[u8]) -> Hash<32> {
1010
let mut context = Blake2b::<256>::new();
1111
context.update_mut(key);
12-
Hash::new(context.finalize().into())
12+
Hash::new(context.finalize())
1313
}
1414

1515
/// Get a Blake2b-224 hash of a key
@@ -18,5 +18,5 @@ pub fn keyhash_256(key: &[u8]) -> Hash<32> {
1818
pub fn keyhash_224(key: &[u8]) -> Hash<28> {
1919
let mut context = Blake2b::<224>::new();
2020
context.update_mut(key);
21-
Hash::new(context.finalize().into())
21+
Hash::new(context.finalize())
2222
}

common/src/hash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ macro_rules! declare_hash_type_with_bech32 {
312312
}
313313
}
314314

315-
impl crate::serialization::Bech32Conversion for $name {
315+
impl $crate::serialization::Bech32Conversion for $name {
316316
fn to_bech32(&self) -> Result<String, anyhow::Error> {
317-
use crate::serialization::Bech32WithHrp;
318317
use anyhow::Context;
318+
use $crate::serialization::Bech32WithHrp;
319319

320320
self.as_ref().to_bech32_with_hrp($hrp).with_context(|| {
321321
format!(
@@ -327,8 +327,8 @@ macro_rules! declare_hash_type_with_bech32 {
327327
}
328328

329329
fn from_bech32(s: &str) -> Result<Self, anyhow::Error> {
330-
use crate::serialization::Bech32WithHrp;
331330
use anyhow::Context;
331+
use $crate::serialization::Bech32WithHrp;
332332

333333
let v = Vec::<u8>::from_bech32_with_hrp(s, $hrp).with_context(|| {
334334
format!("Failed to decode {} from bech32", stringify!($name))

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/queries/accounts.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::HashMap;
22

3-
use crate::{DRepChoice, KeyHash, PoolId, PoolLiveStakeInfo, StakeAddress, TxIdentifier};
3+
use crate::{
4+
DRepChoice, KeyHash, PoolId, PoolLiveStakeInfo, RewardType, StakeAddress, TxIdentifier,
5+
};
46

57
pub const DEFAULT_ACCOUNTS_QUERY_TOPIC: (&str, &str) =
68
("accounts-state-query-topic", "cardano.query.accounts");
@@ -12,8 +14,8 @@ pub const DEFAULT_HISTORICAL_ACCOUNTS_QUERY_TOPIC: (&str, &str) = (
1214

1315
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
1416
pub enum AccountsStateQuery {
15-
GetAccountInfo { stake_address: StakeAddress },
16-
GetAccountRewardHistory { stake_key: Vec<u8> },
17+
GetAccountInfo { account: StakeAddress },
18+
GetAccountRewardHistory { account: StakeAddress },
1719
GetAccountHistory { stake_key: Vec<u8> },
1820
GetAccountRegistrationHistory { account: StakeAddress },
1921
GetAccountDelegationHistory { account: StakeAddress },
@@ -47,7 +49,7 @@ pub enum AccountsStateQuery {
4749
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
4850
pub enum AccountsStateQueryResponse {
4951
AccountInfo(AccountInfo),
50-
AccountRewardHistory(AccountRewardHistory),
52+
AccountRewardHistory(Vec<AccountReward>),
5153
AccountHistory(AccountHistory),
5254
AccountRegistrationHistory(Vec<RegistrationUpdate>),
5355
AccountDelegationHistory(Vec<DelegationUpdate>),
@@ -91,9 +93,6 @@ pub struct AccountInfo {
9193
pub delegated_drep: Option<DRepChoice>,
9294
}
9395

94-
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
95-
pub struct AccountRewardHistory {}
96-
9796
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
9897
pub struct AccountHistory {}
9998

@@ -150,6 +149,20 @@ pub struct AccountWithdrawal {
150149
pub amount: u64,
151150
}
152151

152+
#[derive(
153+
Debug, Clone, minicbor::Decode, minicbor::Encode, serde::Serialize, serde::Deserialize,
154+
)]
155+
pub struct AccountReward {
156+
#[n(0)]
157+
pub epoch: u32,
158+
#[n(1)]
159+
pub amount: u64,
160+
#[n(2)]
161+
pub pool: PoolId,
162+
#[n(3)]
163+
pub reward_type: RewardType,
164+
}
165+
153166
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
154167
pub struct AccountWithdrawalHistory {}
155168

common/src/queries/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Serialize for BlockInfo {
157157
"block_vrf",
158158
&self.block_vrf.and_then(|vkey| vkey.to_bech32().ok()),
159159
)?;
160-
state.serialize_field("op_cert", &self.op_cert.clone().map(hex::encode))?;
160+
state.serialize_field("op_cert", &self.op_cert.map(hex::encode))?;
161161
state.serialize_field("op_cert_counter", &self.op_cert_counter)?;
162162
state.serialize_field("previous_block", &self.previous_block)?;
163163
state.serialize_field("next_block", &self.next_block)?;

0 commit comments

Comments
 (0)