Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge feature branch for hardhat support #573

Merged
merged 9 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ updates:
open-pull-requests-limit: 10
versioning-strategy: increase
rebase-strategy: disabled
- package-ecosystem: npm
directory: "/examples/hardhat"
schedule:
interval: weekly
time: "02:00"
timezone: Europe/Berlin
open-pull-requests-limit: 10
versioning-strategy: increase
rebase-strategy: disabled
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ jobs:
cargo run --package examples --example deployments
cargo run --package examples --example events
cargo run --package examples --example revert
cargo run --package examples-generate
cargo run --package examples --example linked
if [ "$PK" ] && [ "$INFURA_PROJECT_ID" ]; then
cargo run --package examples-generate
cargo run --package examples --example rinkeby
cargo run --package examples --example sources
fi
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ Cargo.lock

node_modules/
examples/*/build/
examples/*/artifacts
examples/*/cache

.idea
2 changes: 1 addition & 1 deletion ethcontract-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Common types for ethcontract-rs runtime and proc macro.
"""

[dependencies]
ethabi = "14.0"
ethabi = "14.1.0"
hex = "0.4"
serde = "1.0"
serde_derive = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions ethcontract-common/src/abiext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use serde_json::json;

/// Extension trait for `ethabi::Function`.
pub trait FunctionExt {
/// Compute the method signature in the standard ABI format. This does not
/// Computes the method signature in the standard ABI format. This does not
/// include the output types.
fn abi_signature(&self) -> String;

/// Compute the Keccak256 function selector used by contract ABIs.
/// Computes the Keccak256 function selector used by contract ABIs.
fn selector(&self) -> H32;
}

Expand All @@ -32,7 +32,7 @@ impl FunctionExt for Function {

/// Extension trait for `ethabi::Event`.
pub trait EventExt {
/// Compute the event signature in human-readable format. The `keccak256`
/// Computes the event signature in human-readable format. The `keccak256`
/// hash of this value is the actual event signature that is used as topic0
/// in the transaction logs.
fn abi_signature(&self) -> String;
Expand Down
48 changes: 24 additions & 24 deletions ethcontract-common/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ pub struct Artifact {
}

impl Artifact {
/// Create a new empty artifact.
/// Creates a new empty artifact.
pub fn new() -> Self {
Artifact {
origin: "<unknown>".to_string(),
contracts: HashMap::new(),
}
}

/// Create a new artifact with an origin information.
/// Creates a new artifact with an origin information.
pub fn with_origin(origin: impl Into<String>) -> Self {
Artifact {
origin: origin.into(),
contracts: HashMap::new(),
}
}

/// Describe where this artifact comes from.
/// Provides description of where this artifact comes from.
///
/// This function is used when a human-readable reference to the artifact
/// is required. It could be anything: path to a json file, url, etc.
pub fn origin(&self) -> &str {
&self.origin
}

/// Set new origin for the artifact.
/// Sets new origin for the artifact.
///
/// Artifact loaders will set origin to something meaningful in most cases,
/// so this function should not be used often. There are cases when
Expand All @@ -57,42 +57,42 @@ impl Artifact {
self.origin = origin.into();
}

/// Get number of contracts contained in this artifact.
/// Gets number of contracts contained in this artifact.
pub fn len(&self) -> usize {
self.contracts.len()
}

/// Check if this artifact contains no contracts.
/// Returns `true` if this artifact contains no contracts.
pub fn is_empty(&self) -> bool {
self.contracts.is_empty()
}

/// Check whether this artifact has a contract with the given name.
/// Returns `true` if this artifact has a contract with the given name.
pub fn contains(&self, name: &str) -> bool {
self.contracts.contains_key(name)
}

/// Get contract by name.
/// Looks up contract by its name and returns a reference to it.
///
/// Some artifact formats allow exporting a single unnamed contract.
/// In this case, the contract will have an empty string as its name.
pub fn get(&self, name: &str) -> Option<&Contract> {
self.contracts.get(name)
}

/// Get contract by name.
/// Looks up contract by its name and returns a handle that allows
/// safely mutating it.
///
/// Returns a handle that allows mutating the contract. It does not allow
/// renaming contract though. For that, you'll need to remove
/// it and add again.
/// The returned handle does not allow renaming contract. For that,
/// you'll need to remove it and add again.
pub fn get_mut(&mut self, name: &str) -> Option<ContractMut> {
self.contracts.get_mut(name).map(ContractMut)
}

/// Insert a new contract to the artifact.
/// Inserts a new contract to the artifact.
///
/// If contract with this name already exists, replace it
/// and return the old contract.
/// If contract with this name already exists, replaces it
/// and returns the old contract.
pub fn insert(&mut self, contract: Contract) -> InsertResult {
match self.contracts.entry(contract.name.clone()) {
Entry::Occupied(mut o) => {
Expand All @@ -109,21 +109,21 @@ impl Artifact {
}
}

/// Remove contract from the artifact.
/// Removes contract from the artifact.
///
/// Returns removed contract or [`None`] if contract with the given name
/// wasn't found.
pub fn remove(&mut self, name: &str) -> Option<Contract> {
self.contracts.remove(name)
}

/// Create an iterator that yields the artifact's contracts.
/// Creates an iterator that yields the artifact's contracts.
pub fn iter(&self) -> impl Iterator<Item = &Contract> + '_ {
self.contracts.values()
}

/// Take all contracts from the artifact, leaving it empty,
/// and iterate over them.
/// Takes all contracts from the artifact, leaving it empty,
/// and returns an iterator over the taken contracts.
pub fn drain(&mut self) -> impl Iterator<Item = Contract> + '_ {
self.contracts.drain().map(|(_, contract)| contract)
}
Expand All @@ -149,27 +149,27 @@ pub struct InsertResult<'a> {
pub struct ContractMut<'a>(&'a mut Contract);

impl<'a> ContractMut<'a> {
/// Get mutable access to abi.
/// Returns mutable reference to contract's abi.
pub fn abi_mut(&mut self) -> &mut Abi {
&mut self.0.abi
}

/// Get mutable access to bytecode.
/// Returns mutable reference to contract's bytecode.
pub fn bytecode_mut(&mut self) -> &mut Bytecode {
&mut self.0.bytecode
}

/// Get mutable access to networks.
/// Returns mutable reference to contract's networks.
pub fn networks_mut(&mut self) -> &mut HashMap<String, Network> {
&mut self.0.networks
}

/// Get mutable access to devdoc.
/// Returns mutable reference to contract's devdoc.
pub fn devdoc_mut(&mut self) -> &mut Documentation {
&mut self.0.devdoc
}

/// Get mutable access to userdoc.
/// Returns mutable reference to contract's userdoc.
pub fn userdoc_mut(&mut self) -> &mut Documentation {
&mut self.0.userdoc
}
Expand Down
Loading