Struct ethers_solc::Solc

source ·
pub struct Solc {
    pub solc: PathBuf,
    pub base_path: Option<PathBuf>,
    pub args: Vec<String>,
}
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:

  1. SOLC_PATH environment variable
  2. svm’s global_version (set via svm use <version>), stored at <svm_home>/.global_version
  3. solc otherwise

Fields§

§solc: PathBuf

Path to the solc executable

§base_path: Option<PathBuf>§args: Vec<String>

Additional arguments passed to the solc executable

Implementations§

source§

impl Solc

source

pub fn new(path: impl Into<PathBuf>) -> Self

A new instance which points to solc

source

pub fn with_base_path(self, base_path: impl Into<PathBuf>) -> Self

source

pub fn arg<T: Into<String>>(self, arg: T) -> Self

Adds an argument to pass to the solc command.

source

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.

source

pub fn svm_home() -> Option<PathBuf>

Available on non-WebAssembly only.

Returns the directory in which svm stores all versions

This will be: ~/.svm on unix, if it exists

  • $XDG_DATA_HOME (~/.local/share/svm) if the svm folder does not exist.
source

pub fn svm_global_version() -> Option<Version>

Available on non-WebAssembly only.

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

source

pub fn installed_versions() -> Vec<SolcVersion>

Available on non-WebAssembly only.

Returns the list of all solc instances installed at SVM_HOME

source

pub fn all_versions() -> Vec<SolcVersion>

Available on crate feature svm-solc and non-WebAssembly only.

Returns the list of all versions that are available to download and marking those which are already installed.

source

pub fn find_svm_installed_version( version: impl AsRef<str> ) -> Result<Option<Self>>

Available on non-WebAssembly only.

Returns the path for a svm installed version.

§Example
 use ethers_solc::Solc;
let solc = Solc::find_svm_installed_version("0.8.9").unwrap();
assert_eq!(solc, Some(Solc::new("~/.svm/0.8.9/solc-0.8.9")));
source

pub fn find_or_install_svm_version(version: impl AsRef<str>) -> Result<Self>

Available on non-WebAssembly and crate feature svm-solc only.

Returns the path for a svm installed version.

If the version is not installed yet, it will install it.

§Example
 use ethers_solc::Solc;
let solc = Solc::find_or_install_svm_version("0.8.9").unwrap();
assert_eq!(solc, Solc::new("~/.svm/0.8.9/solc-0.8.9"));
source

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

source

pub fn detect_version(source: &Source) -> Result<Version>

Available on crate feature svm-solc and non-WebAssembly only.

Given a Solidity source, it detects the latest compiler version which can be used to build it, and returns it.

If the required compiler version is not installed, it also proceeds to install it.

source

pub fn ensure_installed(sol_version: &VersionReq) -> Result<Version>

Available on crate feature svm-solc and non-WebAssembly only.

Given a Solidity version requirement, it detects the latest compiler version which can be used to build it, and returns it.

If the required compiler version is not installed, it also proceeds to install it.

source

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.

source

pub fn version_req(version: &str) -> Result<VersionReq>

Returns the corresponding SemVer version requirement for the solidity version.

Note: This is a workaround for the fact that VersionReq::parse does not support whitespace separators and requires comma separated operators. See VersionReq.

source

pub async fn install(version: &Version) -> Result<Self, SolcVmError>

Available on crate feature svm-solc and non-WebAssembly only.

Installs the provided version of Solc in the machine under the svm dir and returns the Solc instance pointing to the installation.

§Example
 use ethers_solc::{Solc, ISTANBUL_SOLC};
 let solc = Solc::install(&ISTANBUL_SOLC).await.unwrap();
source

pub fn blocking_install(version: &Version) -> Result<Self, SolcVmError>

Available on crate feature svm-solc and non-WebAssembly only.

Blocking version of Self::install

source

pub fn verify_checksum(&self) -> Result<()>

Available on crate feature svm-solc and non-WebAssembly only.

Verify that the checksum for this version of solc is correct. We check against the SHA256 checksum from the build information published by binaries.soliditylang.org

source

pub fn compile_source(&self, path: impl AsRef<Path>) -> Result<CompilerOutput>

Convenience function for compiling all sources under the given path

source

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)?;
source

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)?;
source

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

source

pub fn compile_output<T: Serialize>(&self, input: &T) -> Result<Vec<u8>>

source

pub fn version_short(&self) -> Result<Version>

source

pub fn version(&self) -> Result<Version>

Returns the version from the configured solc

source§

impl Solc

source

pub async fn async_compile_source( &self, path: impl AsRef<Path> ) -> Result<CompilerOutput>

Available on crate feature async only.

Convenience function for compiling all sources under the given path

source

pub async fn async_compile<T: Serialize>( &self, input: &T ) -> Result<CompilerOutput>

Available on crate feature async only.

Run solc --stand-json and return the solc’s output as CompilerOutput

source

pub async fn async_compile_as<T: Serialize, D: DeserializeOwned>( &self, input: &T ) -> Result<D>

Available on crate feature async only.

Run solc --stand-json and return the solc’s output as the given json output

source

pub async fn async_compile_output<T: Serialize>( &self, input: &T ) -> Result<Vec<u8>>

Available on crate feature async only.
source

pub async fn async_version(&self) -> Result<Version>

Available on crate feature async only.
source

pub async fn compile_many<I>(jobs: I, n: usize) -> CompiledMany
where I: IntoIterator<Item = (Solc, CompilerInput)>,

Available on crate feature async only.

Compiles all CompilerInputs with their associated Solc.

This will buffer up to n solc processes and then return the CompilerOutputs in the order in which they complete. No more than n futures will be buffered at any point in time, and less than n may also be buffered depending on the state of each future.

§Example

Compile 2 CompilerInputs at once

use ethers_solc::{CompilerInput, Solc};
let solc1 = Solc::default();
let solc2 = Solc::default();
let input1 = CompilerInput::new("contracts").unwrap()[0].clone();
let input2 = CompilerInput::new("src").unwrap()[0].clone();

let outputs = Solc::compile_many([(solc1, input1), (solc2, input2)], 2).await.flattened().unwrap();

Trait Implementations§

source§

impl AsRef<Path> for Solc

source§

fn as_ref(&self) -> &Path

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Solc

source§

fn clone(&self) -> Solc

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Solc

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Solc

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Solc

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Solc

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Into<PathBuf>> From<T> for Solc

source§

fn from(solc: T) -> Self

Converts to this type from the input type.
source§

impl Ord for Solc

source§

fn cmp(&self, other: &Solc) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Solc

source§

fn eq(&self, other: &Solc) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Solc

source§

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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Solc

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Solc

source§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> JsonSchemaMaybe for T