Struct ethers_solc::Solc
source · Expand description
Abstraction over solc command line utility
Supports sync and async functions.
By default the solc path is configured as follows, with descending priority:
SOLC_PATHenvironment variable- svm’s
global_version(set viasvm use <version>), stored at<svm_home>/.global_version solcotherwise
Fields
solc: PathBufPath to the solc executable
base_path: Option<PathBuf>The base path to set when invoking solc, see also https://docs.soliditylang.org/en/v0.8.11/path-resolution.html#base-path-and-include-paths
args: Vec<String>Additional arguments passed to the solc exectuable
Implementations
sourceimpl Solc
impl Solc
sourcepub fn with_base_path(self, base_path: impl Into<PathBuf>) -> Self
pub fn with_base_path(self, base_path: impl Into<PathBuf>) -> Self
Sets solc’s base path
Ref: https://docs.soliditylang.org/en/v0.8.11/path-resolution.html#base-path-and-include-paths
sourcepub fn arg<T: Into<String>>(self, arg: T) -> Self
pub fn arg<T: Into<String>>(self, arg: T) -> Self
Adds an argument to pass to the solc command.
sourcepub fn args<I, S>(self, args: I) -> Selfwhere
I: IntoIterator<Item = S>,
S: Into<String>,
pub fn args<I, S>(self, args: I) -> Selfwhere
I: IntoIterator<Item = S>,
S: Into<String>,
Adds multiple arguments to pass to the solc.
sourcepub fn svm_home() -> Option<PathBuf>
pub fn svm_home() -> Option<PathBuf>
Returns the directory in which svm stores all versions
This will be ~/.svm on unix
sourcepub fn svm_global_version() -> Option<Version>
pub fn svm_global_version() -> Option<Version>
Returns the semver::Version svm’s .global_version is currently set to.
global_version is configured with (svm use <version>)
This will read the version string (eg: “0.8.9”) that the ~/.svm/.global_version file
contains
sourcepub fn installed_versions() -> Vec<SolcVersion> ⓘ
pub fn installed_versions() -> Vec<SolcVersion> ⓘ
Returns the list of all solc instances installed at SVM_HOME
sourcepub fn find_matching_installation(
versions: &[Version],
required_version: &VersionReq
) -> Option<Version>
pub fn find_matching_installation(
versions: &[Version],
required_version: &VersionReq
) -> Option<Version>
Assuming the versions array is sorted, it returns the first element which satisfies
the provided VersionReq
sourcepub fn source_version_req(source: &Source) -> Result<VersionReq>
pub fn source_version_req(source: &Source) -> Result<VersionReq>
Parses the given source looking for the pragma definition and
returns the corresponding SemVer version requirement.
sourcepub fn version_req(version: &str) -> Result<VersionReq>
pub fn version_req(version: &str) -> Result<VersionReq>
Returns the corresponding SemVer version requirement for the solidity version
sourcepub fn compile_source(&self, path: impl AsRef<Path>) -> Result<CompilerOutput>
pub fn compile_source(&self, path: impl AsRef<Path>) -> Result<CompilerOutput>
Convenience function for compiling all sources under the given path
sourcepub fn compile_exact(&self, input: &CompilerInput) -> Result<CompilerOutput>
pub fn compile_exact(&self, input: &CompilerInput) -> Result<CompilerOutput>
Same as Self::compile(), but only returns those files which are included in the
CompilerInput.
In other words, this removes those files from the CompilerOutput that are not included
in the provided CompilerInput.
Example
use ethers_solc::{CompilerInput, Solc};
let solc = Solc::default();
let input = CompilerInput::new("./contracts")?[0].clone();
let output = solc.compile_exact(&input)?;sourcepub fn compile<T: Serialize>(&self, input: &T) -> Result<CompilerOutput>
pub fn compile<T: Serialize>(&self, input: &T) -> Result<CompilerOutput>
Run solc --stand-json and return the solc’s output as
CompilerOutput
Example
use ethers_solc::{CompilerInput, Solc};
let solc = Solc::default();
let input = CompilerInput::new("./contracts")?;
let output = solc.compile(&input)?;sourcepub fn compile_as<T: Serialize, D: DeserializeOwned>(
&self,
input: &T
) -> Result<D>
pub fn compile_as<T: Serialize, D: DeserializeOwned>(
&self,
input: &T
) -> Result<D>
Run solc --stand-json and return the solc’s output as the given json
output
pub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>
pub fn version_short(&self) -> Result<Version>
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Solc
impl<'de> Deserialize<'de> for Solc
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
sourceimpl Ord for Solc
impl Ord for Solc
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Solc> for Solc
impl PartialOrd<Solc> for Solc
sourcefn partial_cmp(&self, other: &Solc) -> Option<Ordering>
fn partial_cmp(&self, other: &Solc) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for Solc
impl StructuralEq for Solc
impl StructuralPartialEq for Solc
Auto Trait Implementations
impl RefUnwindSafe for Solc
impl Send for Solc
impl Sync for Solc
impl Unpin for Solc
impl UnwindSafe for Solc
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.