Enum ethcontract_generate::source::Source
source · [−]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
sourceimpl Source
impl Source
sourcepub fn parse(source: &str) -> Result<Self>
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
etherscanscheme and a mainnet contract address. For exampleetherscan:0xC02AA.... Alternatively, specify an etherscan URL:https://etherscan.io/address/0xC02AA.... The contract artifact or ABI will be retrieved through [Etherscan]; -
a URL with
npmscheme, NPM package name, an optional version and a path (defaulting to the latest version andindex.js). For examplenpm:@openzeppelin/contracts/build/contracts/IERC20.json. The contract artifact or ABI will be retrieved through [unpkg].
sourcepub fn with_root(root: impl AsRef<Path>, source: &str) -> Result<Self>
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.
sourcepub fn local(path: impl AsRef<Path>) -> Self
pub fn local(path: impl AsRef<Path>) -> Self
Creates a local filesystem source from a path string.
sourcepub fn etherscan(address: &str) -> Result<Self>
pub fn etherscan(address: &str) -> Result<Self>
Creates an Etherscan source from contract address on mainnet.
sourcepub fn artifact_json(&self) -> Result<String>
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
impl Eq for Source
impl StructuralEq for Source
impl StructuralPartialEq for Source
Auto Trait Implementations
impl RefUnwindSafe for Source
impl Send for Source
impl Sync for Source
impl Unpin for Source
impl UnwindSafe for Source
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more