fix: correctly serialize TxPoolInspectSummary (#1305)
* fix: correctly serialize TxPoolInspectSummary previously we'd use the default serde derive, now we serialize it like geth does * chore: add back removed Eq derive
This commit is contained in:
parent
f874680404
commit
dc107ce892
|
@ -7,7 +7,7 @@ use serde::{
|
|||
use std::{collections::BTreeMap, fmt, str::FromStr};
|
||||
|
||||
/// Transaction summary as found in the Txpool Inspection property.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TxpoolInspectSummary {
|
||||
/// Recipient (None when contract creation)
|
||||
pub to: Option<Address>,
|
||||
|
@ -83,6 +83,24 @@ impl<'de> Deserialize<'de> for TxpoolInspectSummary {
|
|||
}
|
||||
}
|
||||
|
||||
/// Implement the `Serialize` trait for `TxpoolInspectSummary` struct so that the
|
||||
/// format matches the one from geth.
|
||||
impl Serialize for TxpoolInspectSummary {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let formatted = format!(
|
||||
"{:?}: {} wei + {} gas × {} wei",
|
||||
self.to.unwrap_or_default(),
|
||||
self.value,
|
||||
self.gas,
|
||||
self.gas_price
|
||||
);
|
||||
serializer.serialize_str(&formatted)
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction Pool Content
|
||||
///
|
||||
/// The content inspection property can be queried to list the exact details of all
|
||||
|
@ -274,6 +292,10 @@ mod tests {
|
|||
}"#;
|
||||
let deserialized: TxpoolInspect = serde_json::from_str(txpool_inspect_json).unwrap();
|
||||
assert_eq!(deserialized, expected_txpool_inspect());
|
||||
|
||||
let serialized = serde_json::to_string(&deserialized).unwrap();
|
||||
let deserialized2: TxpoolInspect = serde_json::from_str(&serialized).unwrap();
|
||||
assert_eq!(deserialized2, deserialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue