fix: txpool_inspect unable to parse contract creations (#1905)
* Fixes #1899 * replace match with if let some() else * fix error: number too large to fit in target type * Apply suggestions from code review Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
This commit is contained in:
parent
d48187ac0d
commit
82f19e0789
|
@ -60,13 +60,14 @@ impl<'de> Visitor<'de> for TxpoolInspectSummaryVisitor {
|
||||||
let addr = match addr_split[0] {
|
let addr = match addr_split[0] {
|
||||||
"" => None,
|
"" => None,
|
||||||
"0x" => None,
|
"0x" => None,
|
||||||
|
"contract creation" => None,
|
||||||
addr => {
|
addr => {
|
||||||
Some(Address::from_str(&addr.to_string().split_off(2)).map_err(de::Error::custom)?)
|
Some(Address::from_str(addr.trim_start_matches("0x")).map_err(de::Error::custom)?)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let value = U256::from(u64::from_str(value_split[0]).map_err(de::Error::custom)?);
|
let value = U256::from_dec_str(value_split[0]).map_err(de::Error::custom)?;
|
||||||
let gas = U256::from(u64::from_str(gas_split[0]).map_err(de::Error::custom)?);
|
let gas = U256::from_dec_str(gas_split[0]).map_err(de::Error::custom)?;
|
||||||
let gas_price = U256::from(u64::from_str(gas_price_split[0]).map_err(de::Error::custom)?);
|
let gas_price = U256::from_dec_str(gas_price_split[0]).map_err(de::Error::custom)?;
|
||||||
|
|
||||||
Ok(TxpoolInspectSummary { to: addr, value, gas, gas_price })
|
Ok(TxpoolInspectSummary { to: addr, value, gas, gas_price })
|
||||||
}
|
}
|
||||||
|
@ -89,12 +90,14 @@ impl Serialize for TxpoolInspectSummary {
|
||||||
where
|
where
|
||||||
S: serde::Serializer,
|
S: serde::Serializer,
|
||||||
{
|
{
|
||||||
|
let formatted_to = if let Some(to) = self.to {
|
||||||
|
format!("{:?}", to)
|
||||||
|
} else {
|
||||||
|
"contract creation".to_string()
|
||||||
|
};
|
||||||
let formatted = format!(
|
let formatted = format!(
|
||||||
"{:?}: {} wei + {} gas × {} wei",
|
"{}: {} wei + {} gas × {} wei",
|
||||||
self.to.unwrap_or_default(),
|
formatted_to, self.value, self.gas, self.gas_price
|
||||||
self.value,
|
|
||||||
self.gas,
|
|
||||||
self.gas_price
|
|
||||||
);
|
);
|
||||||
serializer.serialize_str(&formatted)
|
serializer.serialize_str(&formatted)
|
||||||
}
|
}
|
||||||
|
@ -341,6 +344,9 @@ mod tests {
|
||||||
"252351": "0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF: 0 wei + 65792 gas × 2000000000 wei",
|
"252351": "0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF: 0 wei + 65792 gas × 2000000000 wei",
|
||||||
"252352": "0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF: 0 wei + 65780 gas × 2000000000 wei",
|
"252352": "0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF: 0 wei + 65780 gas × 2000000000 wei",
|
||||||
"252353": "0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF: 0 wei + 65780 gas × 2000000000 wei"
|
"252353": "0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF: 0 wei + 65780 gas × 2000000000 wei"
|
||||||
|
},
|
||||||
|
"0x00000000863B56a3C1f0F1be8BC4F8b7BD78F57a": {
|
||||||
|
"40": "contract creation: 0 wei + 612412 gas × 6000000000 wei"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"queued": {
|
"queued": {
|
||||||
|
@ -380,9 +386,9 @@ mod tests {
|
||||||
"124930".to_string(),
|
"124930".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("000000000000000000000000000000000000007E").unwrap()),
|
to: Some(Address::from_str("000000000000000000000000000000000000007E").unwrap()),
|
||||||
value: U256::from(0u64),
|
value: U256::from(0u128),
|
||||||
gas: U256::from(100187u64),
|
gas: U256::from(100187u128),
|
||||||
gas_price: U256::from(20000000000u64),
|
gas_price: U256::from(20000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
pending_map.insert(
|
pending_map.insert(
|
||||||
|
@ -394,40 +400,54 @@ mod tests {
|
||||||
"252350".to_string(),
|
"252350".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
||||||
value: U256::from(0u64),
|
value: U256::from(0u128),
|
||||||
gas: U256::from(65792u64),
|
gas: U256::from(65792u128),
|
||||||
gas_price: U256::from(2000000000u64),
|
gas_price: U256::from(2000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
pending_map_inner.insert(
|
pending_map_inner.insert(
|
||||||
"252351".to_string(),
|
"252351".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
||||||
value: U256::from(0u64),
|
value: U256::from(0u128),
|
||||||
gas: U256::from(65792u64),
|
gas: U256::from(65792u128),
|
||||||
gas_price: U256::from(2000000000u64),
|
gas_price: U256::from(2000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
pending_map_inner.insert(
|
pending_map_inner.insert(
|
||||||
"252352".to_string(),
|
"252352".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
||||||
value: U256::from(0u64),
|
value: U256::from(0u128),
|
||||||
gas: U256::from(65780u64),
|
gas: U256::from(65780u128),
|
||||||
gas_price: U256::from(2000000000u64),
|
gas_price: U256::from(2000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
pending_map_inner.insert(
|
pending_map_inner.insert(
|
||||||
"252353".to_string(),
|
"252353".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
to: Some(Address::from_str("d10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF").unwrap()),
|
||||||
value: U256::from(0u64),
|
value: U256::from(0u128),
|
||||||
gas: U256::from(65780u64),
|
gas: U256::from(65780u128),
|
||||||
gas_price: U256::from(2000000000u64),
|
gas_price: U256::from(2000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
pending_map.insert(
|
pending_map.insert(
|
||||||
Address::from_str("201354729f8d0f8b64e9a0c353c672c6a66b3857").unwrap(),
|
Address::from_str("201354729f8d0f8b64e9a0c353c672c6a66b3857").unwrap(),
|
||||||
|
pending_map_inner.clone(),
|
||||||
|
);
|
||||||
|
pending_map_inner.clear();
|
||||||
|
pending_map_inner.insert(
|
||||||
|
"40".to_string(),
|
||||||
|
TxpoolInspectSummary {
|
||||||
|
to: None,
|
||||||
|
value: U256::from(0u128),
|
||||||
|
gas: U256::from(612412u128),
|
||||||
|
gas_price: U256::from(6000000000u128),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
pending_map.insert(
|
||||||
|
Address::from_str("00000000863B56a3C1f0F1be8BC4F8b7BD78F57a").unwrap(),
|
||||||
pending_map_inner,
|
pending_map_inner,
|
||||||
);
|
);
|
||||||
let mut queued_map = BTreeMap::new();
|
let mut queued_map = BTreeMap::new();
|
||||||
|
@ -436,18 +456,18 @@ mod tests {
|
||||||
"7".to_string(),
|
"7".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("3479BE69e07E838D9738a301Bb0c89e8EA2Bef4a").unwrap()),
|
to: Some(Address::from_str("3479BE69e07E838D9738a301Bb0c89e8EA2Bef4a").unwrap()),
|
||||||
value: U256::from(1000000000000000u64),
|
value: U256::from(1000000000000000u128),
|
||||||
gas: U256::from(21000u64),
|
gas: U256::from(21000u128),
|
||||||
gas_price: U256::from(10000000000u64),
|
gas_price: U256::from(10000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
queued_map_inner.insert(
|
queued_map_inner.insert(
|
||||||
"8".to_string(),
|
"8".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("73Aaf691bc33fe38f86260338EF88f9897eCaa4F").unwrap()),
|
to: Some(Address::from_str("73Aaf691bc33fe38f86260338EF88f9897eCaa4F").unwrap()),
|
||||||
value: U256::from(1000000000000000u64),
|
value: U256::from(1000000000000000u128),
|
||||||
gas: U256::from(21000u64),
|
gas: U256::from(21000u128),
|
||||||
gas_price: U256::from(10000000000u64),
|
gas_price: U256::from(10000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
queued_map.insert(
|
queued_map.insert(
|
||||||
|
@ -459,9 +479,9 @@ mod tests {
|
||||||
"3".to_string(),
|
"3".to_string(),
|
||||||
TxpoolInspectSummary {
|
TxpoolInspectSummary {
|
||||||
to: Some(Address::from_str("73Aaf691bc33fe38f86260338EF88f9897eCaa4F").unwrap()),
|
to: Some(Address::from_str("73Aaf691bc33fe38f86260338EF88f9897eCaa4F").unwrap()),
|
||||||
value: U256::from(10000000000000000u64),
|
value: U256::from(10000000000000000u128),
|
||||||
gas: U256::from(21000u64),
|
gas: U256::from(21000u128),
|
||||||
gas_price: U256::from(10000000000u64),
|
gas_price: U256::from(10000000000u128),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
queued_map.insert(
|
queued_map.insert(
|
||||||
|
|
Loading…
Reference in New Issue