Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests-on-push-to-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: cargo fmt --all -- --check

- name: Run Clippy
run: cargo clippy --all-targets --all-features
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Run Build
run: cargo build --verbose
Expand Down
2 changes: 1 addition & 1 deletion codec/src/map_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,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| to_hash(x), &constitution.guardrail_script),
guardrail_script: map_nullable(to_hash, &constitution.guardrail_script),
}
}

Expand Down
24 changes: 12 additions & 12 deletions common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ impl StakeAddress {

pub fn get_credential(&self) -> Credential {
match &self.credential {
StakeCredential::AddrKeyHash(hash) => Credential::AddrKeyHash(hash.clone()),
StakeCredential::ScriptHash(hash) => Credential::ScriptHash(hash.clone()),
StakeCredential::AddrKeyHash(hash) => Credential::AddrKeyHash(*hash),
StakeCredential::ScriptHash(hash) => Credential::ScriptHash(*hash),
}
}

Expand All @@ -411,7 +411,7 @@ impl StakeAddress {
};

let data = self.to_binary();
Ok(bech32::encode::<bech32::Bech32>(hrp, &data.as_slice())?)
Ok(bech32::encode::<bech32::Bech32>(hrp, data.as_slice())?)
}

/// Read from a string format ("stake1xxx...")
Expand Down Expand Up @@ -520,7 +520,7 @@ impl<C> minicbor::Encode<C> for StakeAddress {
_ctx: &mut C,
) -> Result<(), minicbor::encode::Error<W::Error>> {
let data = self.to_binary();
e.bytes(&data.as_slice())?;
e.bytes(data.as_slice())?;
Ok(())
}
}
Expand Down Expand Up @@ -902,7 +902,7 @@ mod tests {
assert_eq!(sa.network, NetworkId::Mainnet);
assert_eq!(
match sa.credential {
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
StakeCredential::AddrKeyHash(key) => hex::encode(key),
_ => "SCRIPT".to_string(),
},
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
Expand All @@ -918,7 +918,7 @@ mod tests {
assert_eq!(sa.network, NetworkId::Mainnet);
assert_eq!(
match sa.credential {
StakeCredential::ScriptHash(key) => hex::encode(&key),
StakeCredential::ScriptHash(key) => hex::encode(key),
_ => "STAKE".to_string(),
},
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
Expand All @@ -934,7 +934,7 @@ mod tests {
assert_eq!(sa.network, NetworkId::Testnet);
assert_eq!(
match sa.credential {
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
StakeCredential::AddrKeyHash(key) => hex::encode(key),
_ => "SCRIPT".to_string(),
},
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
Expand Down Expand Up @@ -963,7 +963,7 @@ mod tests {
// - 0x1d: Length of 29 bytes (the stake address data)
// - [29 bytes]: The actual stake address (network header + 28-byte hash)
// Total: 31 bytes (2-byte CBOR framing + 29-byte payload)
let expected = [[0x58, 0x1d].as_slice(), &binary.as_slice()].concat();
let expected = [[0x58, 0x1d].as_slice(), binary.as_slice()].concat();

let mut actual = Vec::new();
let mut encoder = minicbor::Encoder::new(&mut actual);
Expand All @@ -977,7 +977,7 @@ mod tests {
fn stake_addresses_decode_mainnet_stake() {
let binary = {
let mut v = vec![0x58, 0x1d];
v.extend_from_slice(&mainnet_stake_address().to_binary().as_slice());
v.extend_from_slice(mainnet_stake_address().to_binary().as_slice());
v
};

Expand All @@ -987,7 +987,7 @@ mod tests {
assert_eq!(decoded.network, NetworkId::Mainnet);
assert_eq!(
match decoded.credential {
StakeCredential::AddrKeyHash(key) => hex::encode(&key),
StakeCredential::AddrKeyHash(key) => hex::encode(key),
_ => "STAKE".to_string(),
},
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
Expand All @@ -1010,7 +1010,7 @@ mod tests {
assert_eq!(decoded.network, NetworkId::Mainnet);
assert_eq!(
match decoded.credential {
StakeCredential::ScriptHash(key) => hex::encode(&key),
StakeCredential::ScriptHash(key) => hex::encode(key),
_ => "STAKE".to_string(),
},
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
Expand All @@ -1031,7 +1031,7 @@ mod tests {
assert_eq!(decoded.network, NetworkId::Testnet);
assert_eq!(
match decoded.credential {
StakeCredential::ScriptHash(key) => hex::encode(&key),
StakeCredential::ScriptHash(key) => hex::encode(key),
_ => "SCRIPT".to_string(),
},
"558f3ee09b26d88fac2eddc772a9eda94cce6dbadbe9fee439bd6001"
Expand Down
4 changes: 2 additions & 2 deletions common/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cryptoxide::hashing::blake2b::Blake2b;
pub fn keyhash_256(key: &[u8]) -> Hash<32> {
let mut context = Blake2b::<256>::new();
context.update_mut(key);
Hash::new(context.finalize().into())
Hash::new(context.finalize())
}

/// Get a Blake2b-224 hash of a key
Expand All @@ -18,5 +18,5 @@ pub fn keyhash_256(key: &[u8]) -> Hash<32> {
pub fn keyhash_224(key: &[u8]) -> Hash<28> {
let mut context = Blake2b::<224>::new();
context.update_mut(key);
Hash::new(context.finalize().into())
Hash::new(context.finalize())
}
6 changes: 3 additions & 3 deletions common/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ macro_rules! declare_hash_type_with_bech32 {
}
}

impl crate::serialization::Bech32Conversion for $name {
impl $crate::serialization::Bech32Conversion for $name {
fn to_bech32(&self) -> Result<String, anyhow::Error> {
use crate::serialization::Bech32WithHrp;
use anyhow::Context;
use $crate::serialization::Bech32WithHrp;

self.as_ref().to_bech32_with_hrp($hrp).with_context(|| {
format!(
Expand All @@ -327,8 +327,8 @@ macro_rules! declare_hash_type_with_bech32 {
}

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

let v = Vec::<u8>::from_bech32_with_hrp(s, $hrp).with_context(|| {
format!("Failed to decode {} from bech32", stringify!($name))
Expand Down
2 changes: 1 addition & 1 deletion common/src/queries/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Serialize for BlockInfo {
"block_vrf",
&self.block_vrf.and_then(|vkey| vkey.to_bech32().ok()),
)?;
state.serialize_field("op_cert", &self.op_cert.clone().map(hex::encode))?;
state.serialize_field("op_cert", &self.op_cert.map(hex::encode))?;
state.serialize_field("op_cert_counter", &self.op_cert_counter)?;
state.serialize_field("previous_block", &self.previous_block)?;
state.serialize_field("next_block", &self.next_block)?;
Expand Down
31 changes: 14 additions & 17 deletions common/src/stake_addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,11 @@ impl StakeAddressMap {
let sas_data: Vec<(PoolId, u64)> = self
.inner
.values()
.filter_map(|sas| sas.delegated_spo.as_ref().map(|spo| (spo.clone(), sas.utxo_value)))
.filter_map(|sas| sas.delegated_spo.as_ref().map(|spo| (*spo, sas.utxo_value)))
.collect();

sas_data.iter().for_each(|(spo, utxo_value)| {
live_stakes_map
.entry(spo.clone())
.and_modify(|v| *v += utxo_value)
.or_insert(*utxo_value);
live_stakes_map.entry(*spo).and_modify(|v| *v += utxo_value).or_insert(*utxo_value);
});

spos.iter()
Expand Down Expand Up @@ -298,7 +295,7 @@ impl StakeAddressMap {
.inner
.values()
.filter_map(|sas| {
sas.delegated_spo.as_ref().map(|spo| (spo.clone(), (sas.utxo_value, sas.rewards)))
sas.delegated_spo.as_ref().map(|spo| (*spo, (sas.utxo_value, sas.rewards)))
})
.collect();

Expand All @@ -307,7 +304,7 @@ impl StakeAddressMap {
.par_iter() // Rayon multi-threaded iterator
.for_each(|(spo, (utxo_value, rewards))| {
spo_stakes
.entry(spo.clone())
.entry(*spo)
.and_modify(|v| {
v.active += *utxo_value;
v.active_delegators_count += 1;
Expand All @@ -321,7 +318,7 @@ impl StakeAddressMap {
});

// Collect into a plain BTreeMap, so that it is ordered on output
spo_stakes.iter().map(|entry| (entry.key().clone(), *entry.value())).collect()
spo_stakes.iter().map(|entry| (*entry.key(), *entry.value())).collect()
}

/// Dump current Stake Pool Delegation Distribution State
Expand All @@ -331,7 +328,7 @@ impl StakeAddressMap {
.inner
.par_iter()
.filter_map(|(key, sas)| {
sas.delegated_spo.as_ref().map(|spo| (spo.clone(), (key.clone(), sas.utxo_value)))
sas.delegated_spo.as_ref().map(|spo| (*spo, (key.clone(), sas.utxo_value)))
})
.collect();

Expand Down Expand Up @@ -436,7 +433,7 @@ impl StakeAddressMap {
pub fn record_stake_delegation(&mut self, stake_address: &StakeAddress, spo: &PoolId) -> bool {
if let Some(sas) = self.get_mut(stake_address) {
if sas.registered {
sas.delegated_spo = Some(spo.clone());
sas.delegated_spo = Some(*spo);
true
} else {
error!(
Expand Down Expand Up @@ -1251,8 +1248,8 @@ mod tests {
let map = stake_addresses.get_accounts_utxo_values_map(&keys).unwrap();

assert_eq!(map.len(), 2);
assert_eq!(map.get(&addr1.get_hash()).copied().unwrap(), 1000);
assert_eq!(map.get(&addr2.get_hash()).copied().unwrap(), 2000);
assert_eq!(map.get(addr1.get_hash()).copied().unwrap(), 1000);
assert_eq!(map.get(addr2.get_hash()).copied().unwrap(), 2000);
}

#[test]
Expand Down Expand Up @@ -1365,8 +1362,8 @@ mod tests {
let map = stake_addresses.get_accounts_balances_map(&addresses).unwrap();

assert_eq!(map.len(), 2);
assert_eq!(map.get(&addr1.get_hash()).copied().unwrap(), 1100);
assert_eq!(map.get(&addr2.get_hash()).copied().unwrap(), 2000);
assert_eq!(map.get(addr1.get_hash()).copied().unwrap(), 1100);
assert_eq!(map.get(addr2.get_hash()).copied().unwrap(), 2000);
}

#[test]
Expand Down Expand Up @@ -1474,14 +1471,14 @@ mod tests {

assert_eq!(map.len(), 3);
assert_eq!(
map.get(&addr1.get_hash()).unwrap(),
map.get(addr1.get_hash()).unwrap(),
&Some(DRepChoice::Abstain)
);
assert_eq!(
map.get(&addr2.get_hash()).unwrap(),
map.get(addr2.get_hash()).unwrap(),
&Some(DRepChoice::Key(DREP_HASH))
);
assert_eq!(map.get(&addr3.get_hash()).unwrap(), &None);
assert_eq!(map.get(addr3.get_hash()).unwrap(), &None);
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions common/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,10 @@ impl Credential {
}

pub fn get_hash(&self) -> KeyHash {
match self {
*match self {
Self::AddrKeyHash(hash) => hash,
Self::ScriptHash(hash) => hash,
}
.clone()
}

pub fn from_drep_bech32(bech32_str: &str) -> Result<Self, Error> {
Expand Down
2 changes: 1 addition & 1 deletion modules/accounts_state/src/accounts_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl AccountsState {
AccountsStateQueryResponse::AccountInfo(AccountInfo {
utxo_value: account.utxo_value,
rewards: account.rewards,
delegated_spo: account.delegated_spo.clone(),
delegated_spo: account.delegated_spo,
delegated_drep: account.delegated_drep.clone(),
})
} else {
Expand Down
4 changes: 2 additions & 2 deletions modules/accounts_state/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ pub fn calculate_rewards(
result.total_paid += reward.amount;
}

result.rewards.insert(operator_id.clone(), rewards);
result.spo_rewards.push((operator_id.clone(), spo_rewards));
result.rewards.insert(*operator_id, rewards);
result.spo_rewards.push((*operator_id, spo_rewards));
}
}

Expand Down
18 changes: 9 additions & 9 deletions modules/accounts_state/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Snapshot {

// Add the new one
snapshot.spos.insert(
spo_id.clone(),
*spo_id,
SnapshotSPO {
delegators: vec![],
total_stake: 0,
Expand Down Expand Up @@ -229,7 +229,7 @@ mod tests {
StakeAddressState {
utxo_value: 42,
registered: true,
delegated_spo: Some(spo1.clone()),
delegated_spo: Some(spo1),
..StakeAddressState::default()
},
);
Expand All @@ -238,7 +238,7 @@ mod tests {
StakeAddressState {
utxo_value: 99,
registered: true,
delegated_spo: Some(spo2.clone()),
delegated_spo: Some(spo2),
..StakeAddressState::default()
},
);
Expand All @@ -247,7 +247,7 @@ mod tests {
StakeAddressState {
utxo_value: 0,
registered: true,
delegated_spo: Some(spo1.clone()),
delegated_spo: Some(spo1),
..StakeAddressState::default()
},
);
Expand All @@ -271,8 +271,8 @@ mod tests {
);

let mut spos: OrdMap<PoolId, PoolRegistration> = OrdMap::new();
spos.insert(spo1.clone(), PoolRegistration::default());
spos.insert(spo2.clone(), PoolRegistration::default());
spos.insert(spo1, PoolRegistration::default());
spos.insert(spo2, PoolRegistration::default());
let spo_block_counts: HashMap<PoolId, usize> = HashMap::new();
let snapshot = Snapshot::new(
42,
Expand Down Expand Up @@ -313,7 +313,7 @@ mod tests {
let addr4 = create_test_stake_address(0x14);

snapshot.spos.insert(
spo1.clone(),
spo1,
SnapshotSPO {
delegators: vec![
(addr1.clone(), 100),
Expand All @@ -340,7 +340,7 @@ mod tests {
let addr_x = create_test_stake_address(0x99);

snapshot.spos.insert(
spo1.clone(),
spo1,
SnapshotSPO {
delegators: vec![(addr1.clone(), 100)],
total_stake: 100,
Expand Down Expand Up @@ -369,7 +369,7 @@ mod tests {
let addr1 = create_test_stake_address(0x11);

snapshot.spos.insert(
spo1.clone(),
spo1,
SnapshotSPO {
delegators: vec![(addr1.clone(), 100)],
total_stake: 100,
Expand Down
4 changes: 2 additions & 2 deletions modules/accounts_state/src/spo_distribution_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ mod tests {
const DB_PATH: &str = "spdd_db";

fn test_pool_hash(byte: u8) -> PoolId {
keyhash_224(&vec![byte]).into()
keyhash_224(&[byte]).into()
}

fn test_addr_hash(byte: u8) -> AddrKeyhash {
keyhash_224(&vec![byte])
keyhash_224(&[byte])
}

#[test]
Expand Down
Loading