From 0bb407d691168740aa0247d0486eada26bba1d82 Mon Sep 17 00:00:00 2001 From: Santiago Carmuega Date: Tue, 14 May 2024 21:14:19 -0300 Subject: [PATCH] chore: apply lint recommendations (#458) --- pallas-addresses/src/lib.rs | 12 ++++++------ pallas-rolldb/src/kvtable.rs | 6 ++++++ pallas-utxorpc/src/lib.rs | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pallas-addresses/src/lib.rs b/pallas-addresses/src/lib.rs index c21ff17..6dcc899 100644 --- a/pallas-addresses/src/lib.rs +++ b/pallas-addresses/src/lib.rs @@ -10,7 +10,7 @@ pub mod byron; pub mod varuint; -use std::{io::Cursor, str::FromStr}; +use std::{fmt::Display, io::Cursor, str::FromStr}; use pallas_crypto::hash::Hash; use thiserror::Error; @@ -690,12 +690,12 @@ impl Address { } } -impl ToString for Address { - fn to_string(&self) -> String { +impl Display for Address { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Address::Byron(x) => x.to_base58(), - Address::Shelley(x) => x.to_bech32().unwrap_or_else(|_| x.to_hex()), - Address::Stake(x) => x.to_bech32().unwrap_or_else(|_| x.to_hex()), + Address::Byron(x) => f.write_str(&x.to_base58()), + Address::Shelley(x) => f.write_str(&x.to_bech32().unwrap_or_else(|_| x.to_hex())), + Address::Stake(x) => f.write_str(&x.to_bech32().unwrap_or_else(|_| x.to_hex())), } } } diff --git a/pallas-rolldb/src/kvtable.rs b/pallas-rolldb/src/kvtable.rs index 36c8d64..608418b 100644 --- a/pallas-rolldb/src/kvtable.rs +++ b/pallas-rolldb/src/kvtable.rs @@ -316,6 +316,7 @@ where KeyIterator::new(inner) } + #[allow(dead_code)] fn iter_keys_start(db: &rocksdb::DB) -> KeyIterator<'_, K> { Self::iter_keys(db, rocksdb::IteratorMode::Start) } @@ -333,10 +334,12 @@ where ValueIterator::new(inner) } + #[allow(dead_code)] fn iter_values_start(db: &rocksdb::DB) -> ValueIterator<'_, V> { Self::iter_values(db, rocksdb::IteratorMode::Start) } + #[allow(dead_code)] fn iter_values_from(db: &rocksdb::DB, from: K) -> ValueIterator<'_, V> { let from_raw = Box::<[u8]>::from(from); let mode = rocksdb::IteratorMode::From(&from_raw, rocksdb::Direction::Forward); @@ -353,6 +356,7 @@ where EntryIterator::new(inner) } + #[allow(dead_code)] fn iter_entries_start(db: &rocksdb::DB) -> EntryIterator<'_, K, V> { Self::iter_entries(db, rocksdb::IteratorMode::Start) } @@ -373,6 +377,7 @@ where } } + #[allow(dead_code)] fn last_value(db: &rocksdb::DB) -> Result, Error> { let mut iter = Self::iter_values(db, rocksdb::IteratorMode::End); @@ -382,6 +387,7 @@ where } } + #[allow(dead_code)] fn last_entry(db: &rocksdb::DB) -> Result, Error> { let mut iter = Self::iter_entries(db, rocksdb::IteratorMode::End); diff --git a/pallas-utxorpc/src/lib.rs b/pallas-utxorpc/src/lib.rs index 5612c8b..3fca413 100644 --- a/pallas-utxorpc/src/lib.rs +++ b/pallas-utxorpc/src/lib.rs @@ -45,7 +45,7 @@ impl Mapper { let as_output = match &self.context { Some(_) => { - let tx_output = C::get_spent_tx_output(i.hash().clone(), i.index() as u32); + let tx_output = C::get_spent_tx_output(*i.hash(), i.index() as u32); match tx_output { Some(output) => Some(self.map_tx_output(&output)), None => panic!( @@ -89,7 +89,7 @@ impl Mapper { }, script: match x.script_ref() { Some(conway::PseudoScript::NativeScript(x)) => u5c::Script { - script: u5c::script::Script::Native(self.map_native_script(&x)).into(), /* */ + script: u5c::script::Script::Native(Self::map_native_script(&x)).into(), /* */ } .into(), Some(conway::PseudoScript::PlutusV1Script(x)) => u5c::Script { @@ -265,25 +265,25 @@ impl Mapper { } } - pub fn map_native_script(&self, x: &alonzo::NativeScript) -> u5c::NativeScript { + pub fn map_native_script(x: &alonzo::NativeScript) -> u5c::NativeScript { let inner = match x { babbage::NativeScript::ScriptPubkey(x) => { u5c::native_script::NativeScript::ScriptPubkey(x.to_vec().into()) } babbage::NativeScript::ScriptAll(x) => { u5c::native_script::NativeScript::ScriptAll(u5c::NativeScriptList { - items: x.iter().map(|x| self.map_native_script(x)).collect(), + items: x.iter().map(|x| Self::map_native_script(x)).collect(), }) } babbage::NativeScript::ScriptAny(x) => { u5c::native_script::NativeScript::ScriptAll(u5c::NativeScriptList { - items: x.iter().map(|x| self.map_native_script(x)).collect(), + items: x.iter().map(|x| Self::map_native_script(x)).collect(), }) } babbage::NativeScript::ScriptNOfK(n, k) => { u5c::native_script::NativeScript::ScriptNOfK(u5c::ScriptNOfK { k: *n, - scripts: k.iter().map(|x| self.map_native_script(x)).collect(), + scripts: k.iter().map(|x| Self::map_native_script(x)).collect(), }) } babbage::NativeScript::InvalidBefore(s) => { @@ -303,7 +303,7 @@ impl Mapper { let ns = tx .native_scripts() .iter() - .map(|x| self.map_native_script(x.deref())) + .map(|x| Self::map_native_script(x.deref())) .map(|x| u5c::Script { script: u5c::script::Script::Native(x).into(), }); @@ -396,7 +396,7 @@ impl Mapper { } } - pub fn map_metadatum(&self, x: &alonzo::Metadatum) -> u5c::Metadatum { + pub fn map_metadatum(x: &alonzo::Metadatum) -> u5c::Metadatum { let inner = match x { babbage::Metadatum::Int(x) => u5c::metadatum::Metadatum::Int(i128::from(x.0) as i64), babbage::Metadatum::Bytes(x) => { @@ -404,14 +404,14 @@ impl Mapper { } babbage::Metadatum::Text(x) => u5c::metadatum::Metadatum::Text(x.clone()), babbage::Metadatum::Array(x) => u5c::metadatum::Metadatum::Array(u5c::MetadatumArray { - items: x.iter().map(|x| self.map_metadatum(x)).collect(), + items: x.iter().map(|x| Self::map_metadatum(x)).collect(), }), babbage::Metadatum::Map(x) => u5c::metadatum::Metadatum::Map(u5c::MetadatumMap { pairs: x .iter() .map(|(k, v)| u5c::MetadatumPair { - key: self.map_metadatum(k).into(), - value: self.map_metadatum(v).into(), + key: Self::map_metadatum(k).into(), + value: Self::map_metadatum(v).into(), }) .collect(), }), @@ -425,7 +425,7 @@ impl Mapper { pub fn map_metadata(&self, label: u64, datum: &alonzo::Metadatum) -> u5c::Metadata { u5c::Metadata { label, - value: self.map_metadatum(datum).into(), + value: Self::map_metadatum(datum).into(), } } @@ -433,7 +433,7 @@ impl Mapper { let ns = tx .aux_native_scripts() .iter() - .map(|x| self.map_native_script(x)) + .map(|x| Self::map_native_script(x)) .map(|x| u5c::Script { script: u5c::script::Script::Native(x).into(), });