Enum Source

Source
pub enum Source {
    Local(PathBuf),
    Http(Url),
    Etherscan(Address),
    Npm(String),
}
Expand description

A source of an artifact JSON.

Variants§

§

Local(PathBuf)

File on the local file system.

§

Http(Url)

Resource in the internet, available via HTTP(S).

§

Etherscan(Address)

An address of a mainnet contract, available via Etherscan.

Artifacts loaded from etherstan can be parsed using the truffle loader.

Note that Etherscan rate-limits requests to their API, to avoid this, provide an Etherscan API key via the ETHERSCAN_API_KEY environment variable.

§

Npm(String)

The package identifier of an NPM package with a path to an artifact or ABI to be retrieved from unpkg.

Implementations§

Source§

impl Source

Source

pub fn parse(source: &str) -> Result<Self>

Parses an artifact source from a string.

This method accepts the following:

  • relative path to a contract JSON file on the local filesystem, for example build/IERC20.json. This relative path is rooted in the current working directory. To specify the root for relative paths, use [with_root] function;

  • absolute path to a contract JSON file on the local filesystem, or a file URL, for example /build/IERC20.json, or the same path using URL: file:///build/IERC20.json;

  • an HTTP(S) URL pointing to artifact JSON or contract ABI JSON;

  • a URL with etherscan scheme and a mainnet contract address. For example etherscan:0xC02AA.... Alternatively, specify an etherscan URL: https://etherscan.io/address/0xC02AA.... The contract artifact or ABI will be retrieved through [Etherscan];

  • a URL with npm scheme, NPM package name, an optional version and a path (defaulting to the latest version and index.js). For example npm:@openzeppelin/contracts/build/contracts/IERC20.json. The contract artifact or ABI will be retrieved through [unpkg].

Source

pub fn with_root(root: impl AsRef<Path>, source: &str) -> Result<Self>

Parses an artifact source from a string and uses the specified root directory for resolving relative paths. See [parse] for more details on supported source strings.

Source

pub fn local(path: impl AsRef<Path>) -> Self

Creates a local filesystem source from a path string.

Source

pub fn http(url: &str) -> Result<Self>

Creates an HTTP source from a URL.

Source

pub fn etherscan(address: &str) -> Result<Self>

Creates an Etherscan source from contract address on mainnet.

Source

pub fn npm(package_path: impl Into<String>) -> Self

Creates an NPM source from a package path.

Source

pub fn artifact_json(&self) -> Result<String>

Retrieves the source JSON of the artifact.

This will either read the JSON from the file system or retrieve a contract ABI from the network, depending on the source type.

Contract ABIs will be wrapped into a JSON object, so that you can load them using the truffle loader.

Trait Implementations§

Source§

impl Clone for Source

Source§

fn clone(&self) -> Source

Returns a duplicate 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 Source

Source§

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

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

impl FromStr for Source

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Source

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Source

Source§

impl StructuralPartialEq for Source

Auto Trait Implementations§

§

impl Freeze for Source

§

impl RefUnwindSafe for Source

§

impl Send for Source

§

impl Sync for Source

§

impl Unpin for Source

§

impl UnwindSafe for Source

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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> ErasedDestructor for T
where T: 'static,