diff --git a/ethers-core/src/utils/geth.rs b/ethers-core/src/utils/geth.rs index 8c13d175..0825d2fb 100644 --- a/ethers-core/src/utils/geth.rs +++ b/ethers-core/src/utils/geth.rs @@ -16,7 +16,7 @@ const GETH_STARTUP_TIMEOUT_MILLIS: u64 = 10_000; const GETH_DIAL_LOOP_TIMEOUT: Duration = Duration::new(20, 0); /// The exposed APIs -const API: &str = "eth,net,web3,txpool,admin"; +const API: &str = "eth,net,web3,txpool,admin,miner"; /// The geth command const GETH: &str = "geth"; diff --git a/ethers-providers/src/lib.rs b/ethers-providers/src/lib.rs index fd30d5b1..2abee833 100644 --- a/ethers-providers/src/lib.rs +++ b/ethers-providers/src/lib.rs @@ -502,6 +502,11 @@ pub trait Middleware: Sync + Send + Debug { self.inner().get_proof(from, locations, block).await.map_err(FromErr::from) } + /// Returns an indication if this node is currently mining. + async fn mining(&self) -> Result { + self.inner().mining().await.map_err(FromErr::from) + } + // Admin namespace async fn add_peer(&self, enode_url: String) -> Result { @@ -528,6 +533,22 @@ pub trait Middleware: Sync + Send + Debug { self.inner().remove_trusted_peer(enode_url).await.map_err(FromErr::from) } + // Miner namespace + + /// Starts the miner with the given number of threads. If threads is nil, the number of workers + /// started is equal to the number of logical CPUs that are usable by this process. If mining + /// is already running, this method adjust the number of threads allowed to use and updates the + /// minimum price required by the transaction pool. + async fn start_mining(&self, threads: Option) -> Result<(), Self::Error> { + self.inner().start_mining(threads).await.map_err(FromErr::from) + } + + /// Stop terminates the miner, both at the consensus engine level as well as at + /// the block creation level. + async fn stop_mining(&self) -> Result<(), Self::Error> { + self.inner().stop_mining().await.map_err(FromErr::from) + } + // Mempool inspection for Geth's API async fn txpool_content(&self) -> Result { diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 37e85262..446c3229 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -813,6 +813,11 @@ impl Middleware for Provider

{ self.request("eth_getProof", [from, locations, block]).await } + /// Returns an indication if this node is currently mining. + async fn mining(&self) -> Result { + self.request("eth_mining", ()).await + } + // Admin namespace /// Requests adding the given peer, returning a boolean representing whether or not the peer @@ -855,6 +860,23 @@ impl Middleware for Provider

{ self.request("admin_removeTrustedPeer", [enode_url]).await } + // Miner namespace + + /// Starts the miner with the given number of threads. If threads is nil, the number of workers + /// started is equal to the number of logical CPUs that are usable by this process. If mining + /// is already running, this method adjust the number of threads allowed to use and updates the + /// minimum price required by the transaction pool. + async fn start_mining(&self, threads: Option) -> Result<(), Self::Error> { + let threads = utils::serialize(&threads); + self.request("miner_start", [threads]).await + } + + /// Stop terminates the miner, both at the consensus engine level as well as at the block + /// creation level. + async fn stop_mining(&self) -> Result<(), Self::Error> { + self.request("miner_stop", ()).await + } + ////// Ethereum Naming Service // The Ethereum Naming Service (ENS) allows easy to remember and use names to // be assigned to Ethereum addresses. Any provider operation which takes an address