Revert "chore: update format! macro use to satisfy latest clippy version (#194)" (#196)

This reverts commit f29de67f1f.
This commit is contained in:
Louise Poole
2025-04-25 18:09:38 +02:00
committed by GitHub
parent f29de67f1f
commit 409cf15864
38 changed files with 1680 additions and 1361 deletions

View File

@@ -4,6 +4,6 @@ pub trait Hexable {
impl<T: AsRef<[u8]>> Hexable for T {
fn to_hex(&self) -> String {
format!("0x{encoded}", encoded = hex::encode(self))
format!("0x{}", hex::encode(self))
}
}

View File

@@ -19,7 +19,7 @@ pub mod functions {
&[ethabi::ParamType::Address, ethabi::ParamType::Address],
maybe_data.unwrap(),
)
.map_err(|e| format!("unable to decode call.input: {e:?}"))?;
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
owner: values
@@ -55,7 +55,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok({
let mut v = [0 as u8; 32];
values
@@ -132,7 +132,7 @@ pub mod functions {
&[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)],
maybe_data.unwrap(),
)
.map_err(|e| format!("unable to decode call.input: {e:?}"))?;
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
spender: values
@@ -178,7 +178,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
@@ -246,7 +246,7 @@ pub mod functions {
return Err("no data to decode".to_string());
}
let mut values = ethabi::decode(&[ethabi::ParamType::Address], maybe_data.unwrap())
.map_err(|e| format!("unable to decode call.input: {e:?}"))?;
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
owner: values
@@ -273,7 +273,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok({
let mut v = [0 as u8; 32];
values
@@ -355,7 +355,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Uint(8usize)], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok({
let mut v = [0 as u8; 32];
values
@@ -437,7 +437,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<String, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
@@ -514,7 +514,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<String, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::String], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
@@ -591,7 +591,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<substreams::scalar::BigInt, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Uint(256usize)], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok({
let mut v = [0 as u8; 32];
values
@@ -668,7 +668,7 @@ pub mod functions {
&[ethabi::ParamType::Address, ethabi::ParamType::Uint(256usize)],
maybe_data.unwrap(),
)
.map_err(|e| format!("unable to decode call.input: {e:?}"))?;
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
to: values
@@ -714,7 +714,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
@@ -791,7 +791,7 @@ pub mod functions {
],
maybe_data.unwrap(),
)
.map_err(|e| format!("unable to decode call.input: {e:?}"))?;
.map_err(|e| format!("unable to decode call.input: {:?}", e))?;
values.reverse();
Ok(Self {
from: values
@@ -845,7 +845,7 @@ pub mod functions {
}
pub fn output(data: &[u8]) -> Result<bool, String> {
let mut values = ethabi::decode(&[ethabi::ParamType::Bool], data.as_ref())
.map_err(|e| format!("unable to decode output data: {e:?}"))?;
.map_err(|e| format!("unable to decode output data: {:?}", e))?;
Ok(values
.pop()
.expect("one output data should have existed")
@@ -929,19 +929,20 @@ pub mod events {
.topics
.get(0)
.expect("bounds already checked")
.as_ref()
== Self::TOPIC_ID;
.as_ref() ==
Self::TOPIC_ID;
}
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
let mut values =
ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref())
.map_err(|e| format!("unable to decode log.data: {e:?}"))?;
.map_err(|e| format!("unable to decode log.data: {:?}", e))?;
values.reverse();
Ok(Self {
owner: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref())
.map_err(|e| {
format!(
"unable to decode param 'owner' from topic of type 'address': {e:?}"
"unable to decode param 'owner' from topic of type 'address': {:?}",
e
)
})?
.pop()
@@ -953,7 +954,8 @@ pub mod events {
spender: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref())
.map_err(|e| {
format!(
"unable to decode param 'spender' from topic of type 'address': {e:?}"
"unable to decode param 'spender' from topic of type 'address': {:?}",
e
)
})?
.pop()
@@ -1007,18 +1009,21 @@ pub mod events {
.topics
.get(0)
.expect("bounds already checked")
.as_ref()
== Self::TOPIC_ID;
.as_ref() ==
Self::TOPIC_ID;
}
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
let mut values =
ethabi::decode(&[ethabi::ParamType::Uint(256usize)], log.data.as_ref())
.map_err(|e| format!("unable to decode log.data: {e:?}"))?;
.map_err(|e| format!("unable to decode log.data: {:?}", e))?;
values.reverse();
Ok(Self {
from: ethabi::decode(&[ethabi::ParamType::Address], log.topics[1usize].as_ref())
.map_err(|e| {
format!("unable to decode param 'from' from topic of type 'address': {e:?}")
format!(
"unable to decode param 'from' from topic of type 'address': {:?}",
e
)
})?
.pop()
.expect(INTERNAL_ERR)
@@ -1028,7 +1033,7 @@ pub mod events {
.to_vec(),
to: ethabi::decode(&[ethabi::ParamType::Address], log.topics[2usize].as_ref())
.map_err(|e| {
format!("unable to decode param 'to' from topic of type 'address': {e:?}")
format!("unable to decode param 'to' from topic of type 'address': {:?}", e)
})?
.pop()
.expect(INTERNAL_ERR)

File diff suppressed because it is too large Load Diff

View File

@@ -24,7 +24,7 @@ pub fn json_serialize_address_list(addresses: &[Vec<u8>]) -> Vec<u8> {
json_serialize_value(
addresses
.iter()
.map(|a| format!("0x{encoded}", encoded = hex::encode(a)))
.map(|a| format!("0x{}", hex::encode(a)))
.collect::<Vec<_>>(),
)
}
@@ -40,7 +40,7 @@ pub fn json_serialize_bigint_list(values: &[BigInt]) -> Vec<u8> {
json_serialize_value(
values
.iter()
.map(|v| format!("0x{encoded}", encoded = hex::encode(v.to_signed_bytes_be())))
.map(|v| format!("0x{}", hex::encode(v.to_signed_bytes_be())))
.collect::<Vec<_>>(),
)
}

View File

@@ -64,9 +64,12 @@ pub fn store_balance_changes(deltas: BlockBalanceDeltas, store: impl StoreAdd<Bi
.balance_deltas
.iter()
.for_each(|delta| {
let component = String::from_utf8(delta.component_id.clone())
.expect("delta.component_id is not valid utf-8!");
let balance_key = format!("{component}:{token}", token = hex::encode(&delta.token));
let balance_key = format!(
"{0}:{1}",
String::from_utf8(delta.component_id.clone())
.expect("delta.component_id is not valid utf-8!"),
hex::encode(&delta.token)
);
let current_ord = delta.ord;
previous_ordinal
.entry(balance_key.clone())
@@ -74,7 +77,8 @@ pub fn store_balance_changes(deltas: BlockBalanceDeltas, store: impl StoreAdd<Bi
// ordinals must arrive in increasing order
if *ord >= current_ord {
panic!(
"Invalid ordinal sequence for {balance_key}: {ord} >= {current_ord}",
"Invalid ordinal sequence for {}: {} >= {}",
balance_key, *ord, current_ord
);
}
*ord = current_ord;
@@ -319,12 +323,17 @@ mod tests {
}
}
fn store_deltas() -> StoreDeltas {
let comp_id = "0x42c0ffee".to_string();
let comp_id = "0x42c0ffee"
.to_string()
.as_bytes()
.to_vec();
let token_0 = hex::decode("bad999").unwrap();
let token_1 = hex::decode("babe00").unwrap();
let t0_key = format!("{comp_id}:{token}", token = hex::encode(token_0));
let t1_key = format!("{comp_id}:{token}", token = hex::encode(token_1));
let t0_key =
format!("{}:{}", String::from_utf8(comp_id.clone()).unwrap(), hex::encode(token_0));
let t1_key =
format!("{}:{}", String::from_utf8(comp_id.clone()).unwrap(), hex::encode(token_1));
StoreDeltas {
deltas: vec![
StoreDelta {
@@ -385,15 +394,26 @@ mod tests {
#[test]
fn test_store_balances() {
let comp_id = "0x42c0ffee".to_string();
let comp_id = "0x42c0ffee"
.to_string()
.as_bytes()
.to_vec();
let token_0 = hex::decode("bad999").unwrap();
let token_1 = hex::decode("babe00").unwrap();
let deltas = block_balance_deltas();
let store = <MockStore as StoreNew>::new();
store_balance_changes(deltas, store.clone());
let res_0 = store.get_last(format!("{comp_id}:{token}", token = hex::encode(token_0)));
let res_1 = store.get_last(format!("{comp_id}:{token}", token = hex::encode(token_1)));
let res_0 = store.get_last(format!(
"{}:{}",
String::from_utf8(comp_id.clone()).unwrap(),
hex::encode(token_0)
));
let res_1 = store.get_last(format!(
"{}:{}",
String::from_utf8(comp_id.clone()).unwrap(),
hex::encode(token_1)
));
assert_eq!(res_0, Some(BigInt::from_str("+999").unwrap()));
assert_eq!(res_1, Some(BigInt::from_str("+150").unwrap()));

View File

@@ -238,7 +238,7 @@ impl ProtocolComponent {
/// - `tx`: Reference to the associated transaction.
pub fn at_contract(id: &[u8]) -> Self {
Self {
id: format!("0x{encoded}", encoded = hex::encode(id)),
id: format!("0x{}", hex::encode(id)),
tokens: Vec::new(),
contracts: vec![id.to_vec()],
static_att: Vec::new(),