diff --git a/CHANGELOG.md b/CHANGELOG.md index 84da1688..8ad96f05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Unreleased +- Use correct, new transaction type for `typool_content` RPC endpoint [#1501](https://github.com/gakonst/ethers-rs/pull/1501) - Fix the default config for generated `BuildInfo` [#1458](https://github.com/gakonst/ethers-rs/pull/1458) - Allow configuration of the output directory of the generated `BuildInfo` [#1433](https://github.com/gakonst/ethers-rs/pull/1433) - capture unknown fields in `Block` and `Transaction` type via new `OtherFields` type [#1423](https://github.com/gakonst/ethers-rs/pull/1423) diff --git a/ethers-core/src/types/txpool.rs b/ethers-core/src/types/txpool.rs index 0b023cf4..a9462089 100644 --- a/ethers-core/src/types/txpool.rs +++ b/ethers-core/src/types/txpool.rs @@ -1,5 +1,4 @@ -use crate::types::{Address, TransactionRequest as TxpoolTransaction, U256, U64}; - +use crate::types::{Address, Bytes, H256, U256, U64}; use serde::{ de::{self, Deserializer, Visitor}, Deserialize, Serialize, @@ -108,7 +107,7 @@ impl Serialize for TxpoolInspectSummary { /// as the ones that are being scheduled for future execution only. /// /// See [here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content) for more details -#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct TxpoolContent { /// pending tx pub pending: BTreeMap>, @@ -116,6 +115,23 @@ pub struct TxpoolContent { pub queued: BTreeMap>, } +/// Represents the Transaction object as returned by `txpool_content` +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct TxpoolTransaction { + pub block_hash: Option, + pub block_number: Option, + pub from: Option
, + pub gas: Option, + pub gas_price: Option, + pub hash: H256, + pub input: Bytes, + pub nonce: U256, + pub to: Option
, + pub transaction_index: Option, + pub value: U256, +} + /// Transaction Pool Inspect /// /// The inspect inspection property can be queried to list a textual summary @@ -261,7 +277,11 @@ mod tests { } }"#; let deserialized: TxpoolContent = serde_json::from_str(txpool_content_json).unwrap(); - let serialized: String = serde_json::to_string(&deserialized).unwrap(); + let serialized: String = serde_json::to_string_pretty(&deserialized).unwrap(); + + let origin: serde_json::Value = serde_json::from_str(txpool_content_json).unwrap(); + let serialized_value = serde_json::to_value(deserialized.clone()).unwrap(); + assert_eq!(origin, serialized_value); assert_eq!(deserialized, serde_json::from_str::(&serialized).unwrap()); }