abigen adopt hardhat generated bytecode (#2012)
* abigen adopt hardhat generated bytecode * update changelog
This commit is contained in:
parent
c0e607da1e
commit
4a8a6ad259
|
@ -4,6 +4,7 @@
|
|||
|
||||
### Unreleased
|
||||
|
||||
- Add abigen support for hardhat generated bytecode json format [#2012](https://github.com/gakonst/ethers-rs/pull/2012)
|
||||
- Fix typo in `RwClient` docs for `write_client` method.
|
||||
- Add support for Geth `debug_traceCall` [#1949](https://github.com/gakonst/ethers-rs/pull/1949)
|
||||
- Graceful handling of WebSocket transport errors [#1889](https://github.com/gakonst/ethers-rs/issues/1889) [#1815](https://github.com/gakonst/ethers-rs/issues/1815)
|
||||
|
|
|
@ -147,8 +147,10 @@ impl<'de> Visitor<'de> for AbiObjectVisitor {
|
|||
let mut bytecode = None;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct BytecodeObject {
|
||||
object: Bytes,
|
||||
#[serde(untagged)]
|
||||
enum Bytecode {
|
||||
Object { object: Bytes },
|
||||
Bytes(Bytes),
|
||||
}
|
||||
|
||||
struct DeserializeBytes(Bytes);
|
||||
|
@ -169,9 +171,12 @@ impl<'de> Visitor<'de> for AbiObjectVisitor {
|
|||
}
|
||||
"bytecode" | "byteCode" => {
|
||||
bytecode = map
|
||||
.next_value::<BytecodeObject>()
|
||||
.next_value::<Bytecode>()
|
||||
.ok()
|
||||
.map(|obj| obj.object)
|
||||
.map(|obj| match obj {
|
||||
Bytecode::Object { object } => object,
|
||||
Bytecode::Bytes(bytes) => bytes,
|
||||
})
|
||||
.filter(|bytecode| !bytecode.0.is_empty());
|
||||
}
|
||||
"bin" => {
|
||||
|
@ -263,6 +268,9 @@ mod tests {
|
|||
let s = format!(r#"{{"abi": {abi_str}, "bytecode" : {{ "object": "{code}" }} }}"#);
|
||||
assert_has_bytecode(&s);
|
||||
|
||||
let s = format!(r#"{{"abi": {abi_str}, "bytecode" : "{code}" }}"#);
|
||||
assert_has_bytecode(&s);
|
||||
|
||||
let hh_artifact = include_str!(
|
||||
"../../../ethers-contract/tests/solidity-contracts/verifier_abi_hardhat.json"
|
||||
);
|
||||
|
|
|
@ -10,8 +10,8 @@ use std::{convert::TryFrom, sync::Arc, time::Duration};
|
|||
|
||||
// Generate the type-safe contract bindings by providing the json artifact
|
||||
// *Note*: this requires a `bytecode` and `abi` object in the `greeter.json` artifact:
|
||||
// `{"abi": [..], "bin": "..."}` or `{"abi": [..], "bytecode": {"object": "..."}}`
|
||||
// this will embedd the bytecode in a variable `GREETER_BYTECODE`
|
||||
// `{"abi": [..], "bin": "..."}` , `{"abi": [..], "bytecode": {"object": "..."}}` or
|
||||
// `{"abi": [..], "bytecode": "..."}` this will embedd the bytecode in a variable `GREETER_BYTECODE`
|
||||
abigen!(Greeter, "ethers-contract/tests/solidity-contracts/greeter.json",);
|
||||
|
||||
#[tokio::main]
|
||||
|
|
Loading…
Reference in New Issue