chore: apply lint recommendations (#458)

This commit is contained in:
Santiago Carmuega 2024-05-14 21:14:19 -03:00 committed by GitHub
parent ed38adc0ce
commit 0bb407d691
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 19 deletions

View file

@ -10,7 +10,7 @@
pub mod byron; pub mod byron;
pub mod varuint; pub mod varuint;
use std::{io::Cursor, str::FromStr}; use std::{fmt::Display, io::Cursor, str::FromStr};
use pallas_crypto::hash::Hash; use pallas_crypto::hash::Hash;
use thiserror::Error; use thiserror::Error;
@ -690,12 +690,12 @@ impl Address {
} }
} }
impl ToString for Address { impl Display for Address {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Address::Byron(x) => x.to_base58(), Address::Byron(x) => f.write_str(&x.to_base58()),
Address::Shelley(x) => x.to_bech32().unwrap_or_else(|_| x.to_hex()), Address::Shelley(x) => f.write_str(&x.to_bech32().unwrap_or_else(|_| x.to_hex())),
Address::Stake(x) => x.to_bech32().unwrap_or_else(|_| x.to_hex()), Address::Stake(x) => f.write_str(&x.to_bech32().unwrap_or_else(|_| x.to_hex())),
} }
} }
} }

View file

@ -316,6 +316,7 @@ where
KeyIterator::new(inner) KeyIterator::new(inner)
} }
#[allow(dead_code)]
fn iter_keys_start(db: &rocksdb::DB) -> KeyIterator<'_, K> { fn iter_keys_start(db: &rocksdb::DB) -> KeyIterator<'_, K> {
Self::iter_keys(db, rocksdb::IteratorMode::Start) Self::iter_keys(db, rocksdb::IteratorMode::Start)
} }
@ -333,10 +334,12 @@ where
ValueIterator::new(inner) ValueIterator::new(inner)
} }
#[allow(dead_code)]
fn iter_values_start(db: &rocksdb::DB) -> ValueIterator<'_, V> { fn iter_values_start(db: &rocksdb::DB) -> ValueIterator<'_, V> {
Self::iter_values(db, rocksdb::IteratorMode::Start) Self::iter_values(db, rocksdb::IteratorMode::Start)
} }
#[allow(dead_code)]
fn iter_values_from(db: &rocksdb::DB, from: K) -> ValueIterator<'_, V> { fn iter_values_from(db: &rocksdb::DB, from: K) -> ValueIterator<'_, V> {
let from_raw = Box::<[u8]>::from(from); let from_raw = Box::<[u8]>::from(from);
let mode = rocksdb::IteratorMode::From(&from_raw, rocksdb::Direction::Forward); let mode = rocksdb::IteratorMode::From(&from_raw, rocksdb::Direction::Forward);
@ -353,6 +356,7 @@ where
EntryIterator::new(inner) EntryIterator::new(inner)
} }
#[allow(dead_code)]
fn iter_entries_start(db: &rocksdb::DB) -> EntryIterator<'_, K, V> { fn iter_entries_start(db: &rocksdb::DB) -> EntryIterator<'_, K, V> {
Self::iter_entries(db, rocksdb::IteratorMode::Start) Self::iter_entries(db, rocksdb::IteratorMode::Start)
} }
@ -373,6 +377,7 @@ where
} }
} }
#[allow(dead_code)]
fn last_value(db: &rocksdb::DB) -> Result<Option<V>, Error> { fn last_value(db: &rocksdb::DB) -> Result<Option<V>, Error> {
let mut iter = Self::iter_values(db, rocksdb::IteratorMode::End); 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<Option<(K, V)>, Error> { fn last_entry(db: &rocksdb::DB) -> Result<Option<(K, V)>, Error> {
let mut iter = Self::iter_entries(db, rocksdb::IteratorMode::End); let mut iter = Self::iter_entries(db, rocksdb::IteratorMode::End);

View file

@ -45,7 +45,7 @@ impl<C: Context> Mapper<C> {
let as_output = match &self.context { let as_output = match &self.context {
Some(_) => { 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 { match tx_output {
Some(output) => Some(self.map_tx_output(&output)), Some(output) => Some(self.map_tx_output(&output)),
None => panic!( None => panic!(
@ -89,7 +89,7 @@ impl<C: Context> Mapper<C> {
}, },
script: match x.script_ref() { script: match x.script_ref() {
Some(conway::PseudoScript::NativeScript(x)) => u5c::Script { 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(), .into(),
Some(conway::PseudoScript::PlutusV1Script(x)) => u5c::Script { Some(conway::PseudoScript::PlutusV1Script(x)) => u5c::Script {
@ -265,25 +265,25 @@ impl<C: Context> Mapper<C> {
} }
} }
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 { let inner = match x {
babbage::NativeScript::ScriptPubkey(x) => { babbage::NativeScript::ScriptPubkey(x) => {
u5c::native_script::NativeScript::ScriptPubkey(x.to_vec().into()) u5c::native_script::NativeScript::ScriptPubkey(x.to_vec().into())
} }
babbage::NativeScript::ScriptAll(x) => { babbage::NativeScript::ScriptAll(x) => {
u5c::native_script::NativeScript::ScriptAll(u5c::NativeScriptList { 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) => { babbage::NativeScript::ScriptAny(x) => {
u5c::native_script::NativeScript::ScriptAll(u5c::NativeScriptList { 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) => { babbage::NativeScript::ScriptNOfK(n, k) => {
u5c::native_script::NativeScript::ScriptNOfK(u5c::ScriptNOfK { u5c::native_script::NativeScript::ScriptNOfK(u5c::ScriptNOfK {
k: *n, 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) => { babbage::NativeScript::InvalidBefore(s) => {
@ -303,7 +303,7 @@ impl<C: Context> Mapper<C> {
let ns = tx let ns = tx
.native_scripts() .native_scripts()
.iter() .iter()
.map(|x| self.map_native_script(x.deref())) .map(|x| Self::map_native_script(x.deref()))
.map(|x| u5c::Script { .map(|x| u5c::Script {
script: u5c::script::Script::Native(x).into(), script: u5c::script::Script::Native(x).into(),
}); });
@ -396,7 +396,7 @@ impl<C: Context> Mapper<C> {
} }
} }
pub fn map_metadatum(&self, x: &alonzo::Metadatum) -> u5c::Metadatum { pub fn map_metadatum(x: &alonzo::Metadatum) -> u5c::Metadatum {
let inner = match x { let inner = match x {
babbage::Metadatum::Int(x) => u5c::metadatum::Metadatum::Int(i128::from(x.0) as i64), babbage::Metadatum::Int(x) => u5c::metadatum::Metadatum::Int(i128::from(x.0) as i64),
babbage::Metadatum::Bytes(x) => { babbage::Metadatum::Bytes(x) => {
@ -404,14 +404,14 @@ impl<C: Context> Mapper<C> {
} }
babbage::Metadatum::Text(x) => u5c::metadatum::Metadatum::Text(x.clone()), babbage::Metadatum::Text(x) => u5c::metadatum::Metadatum::Text(x.clone()),
babbage::Metadatum::Array(x) => u5c::metadatum::Metadatum::Array(u5c::MetadatumArray { 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 { babbage::Metadatum::Map(x) => u5c::metadatum::Metadatum::Map(u5c::MetadatumMap {
pairs: x pairs: x
.iter() .iter()
.map(|(k, v)| u5c::MetadatumPair { .map(|(k, v)| u5c::MetadatumPair {
key: self.map_metadatum(k).into(), key: Self::map_metadatum(k).into(),
value: self.map_metadatum(v).into(), value: Self::map_metadatum(v).into(),
}) })
.collect(), .collect(),
}), }),
@ -425,7 +425,7 @@ impl<C: Context> Mapper<C> {
pub fn map_metadata(&self, label: u64, datum: &alonzo::Metadatum) -> u5c::Metadata { pub fn map_metadata(&self, label: u64, datum: &alonzo::Metadatum) -> u5c::Metadata {
u5c::Metadata { u5c::Metadata {
label, label,
value: self.map_metadatum(datum).into(), value: Self::map_metadatum(datum).into(),
} }
} }
@ -433,7 +433,7 @@ impl<C: Context> Mapper<C> {
let ns = tx let ns = tx
.aux_native_scripts() .aux_native_scripts()
.iter() .iter()
.map(|x| self.map_native_script(x)) .map(|x| Self::map_native_script(x))
.map(|x| u5c::Script { .map(|x| u5c::Script {
script: u5c::script::Script::Native(x).into(), script: u5c::script::Script::Native(x).into(),
}); });