fix: use correct model for txpool_content endpoint (#1501)

* 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>
This commit is contained in:
Matthias Seitz 2022-07-24 03:21:09 +02:00 committed by GitHub
parent cf2aa07eb5
commit a5c326162a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -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)

View File

@ -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<Address, BTreeMap<String, TxpoolTransaction>>,
@ -116,6 +115,23 @@ pub struct TxpoolContent {
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
@ -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());
}