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) -> Self where
I: IntoIterator<Item = S>,
S: Into<String>,
pub fn args<I, S>(self, args: I) -> Self where
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>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn installed_versions() -> Vec<SolcVersion>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Ord for Solc
impl Ord for Solc
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>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more