diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c5a0718..ef467b52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,16 @@ jobs: export PATH=$HOME/bin:$PATH solc --version + - name: Install geth + run: | + mkdir -p "$HOME/bin" + wget -q https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.9.23-8c2f2715.tar.gz + tar -xvf geth-linux-amd64-1.9.23-8c2f2715.tar.gz + mv geth-linux-amd64-1.9.23-8c2f2715/geth $HOME/bin/geth + chmod u+x "$HOME/bin/geth" + export PATH=$HOME/bin:$PATH + geth version + - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: diff --git a/ethers-core/src/types/mod.rs b/ethers-core/src/types/mod.rs index 3e2dcd4d..1bac8e0a 100644 --- a/ethers-core/src/types/mod.rs +++ b/ethers-core/src/types/mod.rs @@ -27,3 +27,6 @@ pub use ens::NameOrAddress; mod signature; pub use signature::*; + +mod txpool; +pub use txpool::*; diff --git a/ethers-core/src/types/txpool.rs b/ethers-core/src/types/txpool.rs new file mode 100644 index 00000000..38d439b0 --- /dev/null +++ b/ethers-core/src/types/txpool.rs @@ -0,0 +1,411 @@ +use crate::types::{Address, TransactionRequest as TxpoolTransaction, U256, U64}; + +use serde::{ + de::{self, Deserializer, Visitor}, + Deserialize, Serialize, +}; +use std::{collections::BTreeMap, fmt, str::FromStr}; + +/// Transaction summary as found in the Txpool Inspection property. +#[derive(Debug, Clone, PartialEq)] +pub struct TxpoolInspectSummary { + /// Recipient (None when contract creation) + pub to: Option
, + /// Transfered value + pub value: U256, + /// Gas amount + pub gas: U256, + /// Gas Price + pub gas_price: U256, +} + +/// Visitor struct for TxpoolInspectSummary. +struct TxpoolInspectSummaryVisitor; + +/// Walk through the deserializer to parse a txpool inspection summary into the +/// `TxpoolInspectSummary` struct. +impl<'de> Visitor<'de> for TxpoolInspectSummaryVisitor { + type Value = TxpoolInspectSummary; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("to: value wei + gasLimit gas × gas_price wei") + } + + fn visit_string {
fn pending_transaction(&self, tx_hash: TxHash) -> PendingTransaction<'_, P> {
PendingTransaction::new(tx_hash, self).interval(self.get_interval())
}
+
+ /// Returns the details of all transactions currently pending for inclusion in the next
+ /// block(s), as well as the ones that are being scheduled for future execution only.
+ /// Ref: [Here](https://geth.ethereum.org/docs/rpc/ns-txpool#txpool_content)
+ async fn txpool_content(&self) -> Result {
diff --git a/ethers-providers/tests/provider.rs b/ethers-providers/tests/provider.rs
index cd3f7005..62ff0695 100644
--- a/ethers-providers/tests/provider.rs
+++ b/ethers-providers/tests/provider.rs
@@ -1,4 +1,3 @@
-#![allow(unused_braces)]
use ethers::providers::{Http, Middleware, Provider};
use std::{convert::TryFrom, time::Duration};
diff --git a/ethers-providers/tests/txpool.rs b/ethers-providers/tests/txpool.rs
new file mode 100644
index 00000000..b215ba8c
--- /dev/null
+++ b/ethers-providers/tests/txpool.rs
@@ -0,0 +1,56 @@
+use ethers::{
+ providers::{Http, Middleware, Provider},
+ types::TransactionRequest,
+ utils::Geth,
+};
+use std::convert::TryFrom;
+
+#[tokio::test]
+async fn txpool() {
+ let geth = Geth::new().block_time(20u64).spawn();
+ let provider = Provider::