Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: use correct model for txpool_content endpoint (#1501)
Browse files Browse the repository at this point in the history
* fix: use correct model for txpool_content endpoint

* chore: update CHANGELOG

* update failing tests

* Update ethers-providers/tests/txpool.rs

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
  • Loading branch information
mattsse and gakonst authored Jul 24, 2022
1 parent cf2aa07 commit a5c3261
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 24 additions & 4 deletions ethers-core/src/types/txpool.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -108,14 +107,31 @@ 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<Address, BTreeMap<String, TxpoolTransaction>>,
/// queued tx
pub queued: BTreeMap<Address, BTreeMap<String, TxpoolTransaction>>,
}

/// 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<H256>,
pub block_number: Option<U64>,
pub from: Option<Address>,
pub gas: Option<U256>,
pub gas_price: Option<U256>,
pub hash: H256,
pub input: Bytes,
pub nonce: U256,
pub to: Option<Address>,
pub transaction_index: Option<U64>,
pub value: U256,
}

/// Transaction Pool Inspect
///
/// The inspect inspection property can be queried to list a textual summary
Expand Down Expand Up @@ -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::<TxpoolContent>(&serialized).unwrap());
}

Expand Down

0 comments on commit a5c3261

Please sign in to comment.