Repository: gakonst/ethers-rs
Pull request #1288 (2022-05-20 03:10:23)

chore(deps): bump once_cell from 1.10.0 to 1.11.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.10.0 to 1.11.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/matklad/once_cell/blob/master/CHANGELOG.md">once_cell's changelog</a>.</em></p>
<blockquote>
<h1>Changelog</h1>
<h2>Unreleased</h2>
<ul>
<li></li>
</ul>
<h2>1.11</h2>
<ul>
<li>Add <code>OnceCell::with_value</code> to create initialized <code>OnceCell</code> in <code>const</code> context.</li>
<li>Improve <code>Clone</code> implementation for <code>OnceCell</code>.</li>
<li>Rewrite <code>parking_lot</code> version on top of <code>parking_lot_core</code>, for even smaller cells!</li>
</ul>
<h2>1.10</h2>
<ul>
<li>upgrade <code>parking_lot</code> to <code>0.12.0</code> (note that this bumps MSRV with <code>parking_lot</code> feature enabled to <code>1.49.0</code>).</li>
</ul>
<h2>1.9</h2>
<ul>
<li>Added an <code>atomic-polyfill</code> optional dependency to compile <code>race</code> on platforms without atomics</li>
</ul>
<h2>1.8.0</h2>
<ul>
<li>Add <code>try_insert</code> API -- a version of <code>set</code> that returns a reference.</li>
</ul>
<h2>1.7.2</h2>
<ul>
<li>Improve code size when using parking_lot feature.</li>
</ul>
<h2>1.7.1</h2>
<ul>
<li>Fix <code>race::OnceBox&lt;T&gt;</code> to also impl <code>Default</code> even if <code>T</code> doesn't impl <code>Default</code>.</li>
</ul>
<h2>1.7.0</h2>
<ul>
<li>Hide the <code>race</code> module behind (default) <code>race</code> feature.
Turns out that adding <code>race</code> by default was a breaking change on some platforms without atomics.
In this release, we make the module opt-out.
Technically, this is a breaking change for those who use <code>race</code> with <code>no_default_features</code>.
Given that the <code>race</code> module itself only several days old, the breakage is deemed acceptable.</li>
</ul>
<h2>1.6.0</h2>
<ul>
<li>Add <code>Lazy::into_value</code></li>
<li>Stabilize <code>once_cell::race</code> module for &quot;first one wins&quot; no_std-compatible initialization flavor.</li>
<li>Migrate from deprecated <code>compare_and_swap</code> to <code>compare_exchange</code>.</li>
</ul>
<h2>1.5.2</h2>
<ul>
<li><code>OnceBox</code> API uses <code>Box&lt;T&gt;</code>.
This a breaking change to unstable API.</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/matklad/once_cell/commit/12f283fd8dff990bc1b6fe4b7bf2e2e348aa8b86"><code>12f283f</code></a> Merge <a href="https://github-redirect.dependabot.com/matklad/once_cell/issues/178">#178</a></li>
<li><a href="https://github.com/matklad/once_cell/commit/443d23c74fb379da14e05ca2d96f39b49eed079b"><code>443d23c</code></a> readability</li>
<li><a href="https://github.com/matklad/once_cell/commit/39a47e32d3ce22c42392e9fedf9b0646255a74d4"><code>39a47e3</code></a> release 1.11.0</li>
<li><a href="https://github.com/matklad/once_cell/commit/5386606ec4a8f9dcfa1124f7a7b9c23a049529be"><code>5386606</code></a> fix deadlock</li>
<li><a href="https://github.com/matklad/once_cell/commit/0067580881b0bedf860dd27f5e087c273198b0eb"><code>0067580</code></a> use exchange_weak</li>
<li><a href="https://github.com/matklad/once_cell/commit/662fcf9784b9f54af9b2b904bba1f3ad675cc79d"><code>662fcf9</code></a> replace parking_lot with parking_lot_core</li>
<li><a href="https://github.com/matklad/once_cell/commit/b57c77415b1146859402dcb905850fe9f44b7bb6"><code>b57c774</code></a> Merge <a href="https://github-redirect.dependabot.com/matklad/once_cell/issues/175">#175</a></li>
<li><a href="https://github.com/matklad/once_cell/commit/580fb726679a7d3b233c631f4cc05725596ccf27"><code>580fb72</code></a> Note that Acquire/Release is necessary in OnceBox</li>
<li><a href="https://github.com/matklad/once_cell/commit/7d45ce0a1e9f73b33a3ad7464724b6f38db90a1f"><code>7d45ce0</code></a> Explain the atomic orderings used in race</li>
<li><a href="https://github.com/matklad/once_cell/commit/090caea92f21ecba71b743c1c636f3fe9d14b598"><code>090caea</code></a> Merge <a href="https://github-redirect.dependabot.com/matklad/once_cell/issues/170">#170</a></li>
<li>Additional commits viewable in <a href="https://github.com/matklad/once_cell/compare/v1.10.0...v1.11.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=once_cell&package-manager=cargo&previous-version=1.10.0&new-version=1.11.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e15b3a61..b7db676d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -213,6 +213,8 @@
 
 ### Unreleased
 
+- Added tx builder methods to `ContractFactory`
+  [#1289](https://github.com/gakonst/ethers-rs/pull/1289)
 - Relax Clone requirements when Arc<Middleware> is used
   [#1183](https://github.com/gakonst/ethers-rs/pull/1183)
 - Add `EventStream::select` to combine streams with different event types
diff --git a/Cargo.lock b/Cargo.lock
index 68ce1317..1f4b5336 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2328,9 +2328,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
 
 [[package]]
 name = "once_cell"
-version = "1.10.0"
+version = "1.11.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
+checksum = "7b10983b38c53aebdf33f542c6275b0f58a238129d00c4ae0e6fb59738d783ca"
 
 [[package]]
 name = "oorandom"
diff --git a/ethers-addressbook/Cargo.toml b/ethers-addressbook/Cargo.toml
index 15ec1b64..dde2cb12 100644
--- a/ethers-addressbook/Cargo.toml
+++ b/ethers-addressbook/Cargo.toml
@@ -10,7 +10,7 @@ repository = "https://github.com/gakonst/ethers-rs"
 keywords = ["ethereum", "web3", "celo", "ethers"]
 
 [dependencies]
-once_cell = "1.10.0"
+once_cell = "1.11.0"
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 
diff --git a/ethers-contract/Cargo.toml b/ethers-contract/Cargo.toml
index 1f0cd464..6a760542 100644
--- a/ethers-contract/Cargo.toml
+++ b/ethers-contract/Cargo.toml
@@ -19,7 +19,7 @@ ethers-derive-eip712 = { version = "^0.2.0", path = "../ethers-core/ethers-deriv
 serde = { version = "1.0.124", default-features = false }
 serde_json = { version = "1.0.64", default-features = false }
 thiserror = { version = "1.0.31", default-features = false }
-once_cell = { version = "1.10.0" }
+once_cell = { version = "1.11.0" }
 pin-project = {version = "1.0.7", default-features = false }
 futures-util = { version = "^0.3" }
 hex = { version = "0.4.3", default-features = false, features = ["std"] }
diff --git a/ethers-contract/src/factory.rs b/ethers-contract/src/factory.rs
index 23ef6bb9..cb493e0b 100644
--- a/ethers-contract/src/factory.rs
+++ b/ethers-contract/src/factory.rs
@@ -4,8 +4,8 @@ use std::marker::PhantomData;
 use ethers_core::{
     abi::{Abi, Token, Tokenize},
     types::{
-        transaction::eip2718::TypedTransaction, BlockNumber, Bytes, TransactionReceipt,
-        TransactionRequest,
+        transaction::eip2718::TypedTransaction, Address, BlockNumber, Bytes, NameOrAddress,
+        TransactionReceipt, TransactionRequest, U256, U64,
     },
 };
 use ethers_providers::Middleware;
@@ -59,6 +59,54 @@ impl<M: Middleware, C: From<Contract<M>>> ContractDeployer<M, C> {
         self
     }
 
+    /// Sets the `from` field in the deploy transaction to the provided value
+    pub fn from<T: Into<Address>>(mut self, from: T) -> Self {
+        self.deployer.tx.set_from(from.into());
+        self
+    }
+
+    /// Sets the `to` field in the deploy transaction to the provided value
+    pub fn to<T: Into<NameOrAddress>>(mut self, to: T) -> Self {
+        self.deployer.tx.set_to(to.into());
+        self
+    }
+
+    /// Sets the `gas` field in the deploy transaction to the provided value
+    pub fn gas<T: Into<U256>>(mut self, gas: T) -> Self {
+        self.deployer.tx.set_gas(gas.into());
+        self
+    }
+
+    /// Sets the `gas_price` field in the deploy transaction to the provided value
+    pub fn gas_price<T: Into<U256>>(mut self, gas_price: T) -> Self {
+        self.deployer.tx.set_gas_price(gas_price.into());
+        self
+    }
+
+    /// Sets the `value` field in the deploy transaction to the provided value
+    pub fn value<T: Into<U256>>(mut self, value: T) -> Self {
+        self.deployer.tx.set_value(value.into());
+        self
+    }
+
+    /// Sets the `data` field in the deploy transaction to the provided value
+    pub fn data<T: Into<Bytes>>(mut self, data: T) -> Self {
+        self.deployer.tx.set_data(data.into());
+        self
+    }
+
+    /// Sets the `nonce` field in the deploy transaction to the provided value
+    pub fn nonce<T: Into<U256>>(mut self, nonce: T) -> Self {
+        self.deployer.tx.set_nonce(nonce.into());
+        self
+    }
+
+    /// Sets the `chain_id` field in the deploy transaction to the provided value
+    pub fn chain_id<T: Into<U64>>(mut self, chain_id: T) -> Self {
+        self.deployer.tx.set_chain_id(chain_id.into());
+        self
+    }
+
     /// Dry runs the deployment of the contract
     ///
     /// Note: this function _does not_ send a transaction from your account
diff --git a/ethers-core/Cargo.toml b/ethers-core/Cargo.toml
index 8bdafe87..01b88aac 100644
--- a/ethers-core/Cargo.toml
+++ b/ethers-core/Cargo.toml
@@ -29,7 +29,7 @@ serde_json = { version = "1.0.64", default-features = false }
 thiserror = { version = "1.0.31", default-features = false }
 bytes = { version = "1.1.0", features = ["serde"] }
 hex = { version = "0.4.3", default-features = false, features = ["std"] }
-once_cell = { version = "1.10.0", optional = true }
+once_cell = { version = "1.11.0", optional = true }
 unicode-xid = "0.2.3"
 strum = { version = "0.24", features = ["derive"] }
 
@@ -44,7 +44,7 @@ proc-macro2 = { version = "1.0.39", optional = true }
 [dev-dependencies]
 serde_json = { version = "1.0.64", default-features = false }
 bincode = { version = "1.3.3", default-features = false }
-once_cell = { version = "1.10.0" }
+once_cell = { version = "1.11.0" }
 hex-literal = "0.3.4"
 rand = "0.8.5"
 
diff --git a/ethers-middleware/Cargo.toml b/ethers-middleware/Cargo.toml
index 8da735d7..6e8cc8f6 100644
--- a/ethers-middleware/Cargo.toml
+++ b/ethers-middleware/Cargo.toml
@@ -42,7 +42,7 @@ tokio = { version = "1.5" }
 hex = { version = "0.4.3", default-features = false, features = ["std"] }
 rand = { version = "0.8.5", default-features = false }
 ethers-providers = { version = "^0.6.0", path = "../ethers-providers", default-features = false, features = ["ws", "rustls"] }
-once_cell = "1.10.0"
+once_cell = "1.11.0"
 ethers-solc = { version = "^0.3.0", path = "../ethers-solc", default-features = false }
 serial_test = "0.6.0"
 
diff --git a/ethers-providers/Cargo.toml b/ethers-providers/Cargo.toml
index abbb3fa7..a0263d1c 100644
--- a/ethers-providers/Cargo.toml
+++ b/ethers-providers/Cargo.toml
@@ -39,7 +39,7 @@ tracing = { version = "0.1.34", default-features = false }
 tracing-futures = { version = "0.2.5", default-features = false, features = ["std-future"] }
 
 bytes = { version  = "1.1.0", default-features = false, optional = true }
-once_cell = "1.10.0"
+once_cell = "1.11.0"
 hashers = "1.0.1"
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
diff --git a/ethers-solc/Cargo.toml b/ethers-solc/Cargo.toml
index 45350789..fa822c65 100644
--- a/ethers-solc/Cargo.toml
+++ b/ethers-solc/Cargo.toml
@@ -21,7 +21,7 @@ semver = { version = "1.0.9", features = ["serde"] }
 walkdir = "2.3.2"
 tokio = { version = "1.15.0", default-features = false, features = ["rt"] }
 futures-util = { version = "^0.3", optional = true }
-once_cell = "1.10.0"
+once_cell = "1.11.0"
 regex = "1.5.5"
 md-5 = "0.10.1"
 thiserror = "1.0.31"
diff --git a/ethers-solc/src/config.rs b/ethers-solc/src/config.rs
index 90307818..0311c286 100644
--- a/ethers-solc/src/config.rs
+++ b/ethers-solc/src/config.rs
@@ -311,41 +311,40 @@ impl ProjectPathsConfig {
         let mut content = content.as_bytes().to_vec();
         let mut offset = 0_isize;
 
-        if strip_license {
-            if let Some(license) = target_node.license() {
-                let license_range = license.loc_by_offset(offset);
-                offset -= license_range.len() as isize;
-                content.splice(license_range, std::iter::empty());
+        let mut statements = [
+            (target_node.license(), strip_license),
+            (target_node.version(), strip_version_pragma),
+            (target_node.experimental(), strip_experimental_pragma),
+        ]
+        .iter()
+        .filter_map(|(data, condition)| if *condition { data.to_owned().as_ref() } else { None })
+        .collect::<Vec<_>>();
+        statements.sort_by_key(|x| x.loc().start);
+
+        let (mut imports, mut statements) =
+            (imports.iter().peekable(), statements.iter().peekable());
+        while imports.peek().is_some() || statements.peek().is_some() {
+            let (next_import_start, next_statement_start) = (
+                imports.peek().map_or(usize::max_value(), |x| x.loc().start),
+                statements.peek().map_or(usize::max_value(), |x| x.loc().start),
+            );
+            if next_statement_start < next_import_start {
+                let repl_range = statements.next().unwrap().loc_by_offset(offset);
+                offset -= repl_range.len() as isize;
+                content.splice(repl_range, std::iter::empty());
+            } else {
+                let import = imports.next().unwrap();
+                let import_path = self.resolve_import(target_dir, import.data().path())?;
+                let s = self.flatten_node(&import_path, graph, imported, true, true, true)?;
+
+                let import_content = s.as_bytes();
+                let import_content_len = import_content.len() as isize;
+                let import_range = import.loc_by_offset(offset);
+                offset += import_content_len - (import_range.len() as isize);
+                content.splice(import_range, import_content.iter().copied());
             }
         }
 
-        if strip_version_pragma {
-            if let Some(version) = target_node.version() {
-                let version_range = version.loc_by_offset(offset);
-                offset -= version_range.len() as isize;
-                content.splice(version_range, std::iter::empty());
-            }
-        }
-
-        if strip_experimental_pragma {
-            if let Some(experiment) = target_node.experimental() {
-                let experimental_pragma_range = experiment.loc_by_offset(offset);
-                offset -= experimental_pragma_range.len() as isize;
-                content.splice(experimental_pragma_range, std::iter::empty());
-            }
-        }
-
-        for import in imports.iter() {
-            let import_path = self.resolve_import(target_dir, import.data().path())?;
-            let s = self.flatten_node(&import_path, graph, imported, true, true, true)?;
-
-            let import_content = s.as_bytes();
-            let import_content_len = import_content.len() as isize;
-            let import_range = import.loc_by_offset(offset);
-            offset += import_content_len - (import_range.len() as isize);
-            content.splice(import_range, import_content.iter().copied());
-        }
-
         let result = String::from_utf8(content).map_err(|err| {
             SolcError::msg(format!("failed to convert extended bytes to string: {}", err))
         })?;


Test patch:
diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs
index 55529d51..be809dea 100644
--- a/ethers-solc/tests/project.rs
+++ b/ethers-solc/tests/project.rs
@@ -873,6 +873,71 @@ contract Contract is ParentContract,
     );
 }
 
+#[test]
+fn can_flatten_with_version_pragma_after_imports() {
+    let project = TempProject::dapptools().unwrap();
+
+    let f = project
+        .add_source(
+            "A",
+            r#"
+pragma solidity ^0.8.10;
+
+import * as B from "./B.sol";
+
+contract A { }
+"#,
+        )
+        .unwrap();
+
+    project
+        .add_source(
+            "B",
+            r#"
+import D from "./D.sol";
+pragma solidity ^0.8.10;
+import * as C from "./C.sol";
+contract B { }
+"#,
+        )
+        .unwrap();
+
+    project
+        .add_source(
+            "C",
+            r#"
+pragma solidity ^0.8.10;
+contract C { }
+"#,
+        )
+        .unwrap();
+
+    project
+        .add_source(
+            "D",
+            r#"
+pragma solidity ^0.8.10;
+contract D { }
+"#,
+        )
+        .unwrap();
+
+    let result = project.flatten(&f).unwrap();
+    assert_eq!(
+        result,
+        r#"pragma solidity ^0.8.10;
+
+contract D { }
+
+contract C { }
+
+contract B { }
+
+contract A { }
+"#
+    );
+}
+
 #[test]
 fn can_detect_type_error() {
     let project = TempProject::<ConfigurableArtifacts>::dapptools().unwrap();