abigen adopt hardhat generated bytecode (#2012)

* abigen adopt hardhat generated bytecode

* update changelog
This commit is contained in:
WillQ 2023-01-05 17:46:32 +08:00 committed by GitHub
parent c0e607da1e
commit 4a8a6ad259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -4,6 +4,7 @@
### Unreleased ### 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. - Fix typo in `RwClient` docs for `write_client` method.
- Add support for Geth `debug_traceCall` [#1949](https://github.com/gakonst/ethers-rs/pull/1949) - 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) - Graceful handling of WebSocket transport errors [#1889](https://github.com/gakonst/ethers-rs/issues/1889) [#1815](https://github.com/gakonst/ethers-rs/issues/1815)

View File

@ -147,8 +147,10 @@ impl<'de> Visitor<'de> for AbiObjectVisitor {
let mut bytecode = None; let mut bytecode = None;
#[derive(Deserialize)] #[derive(Deserialize)]
struct BytecodeObject { #[serde(untagged)]
object: Bytes, enum Bytecode {
Object { object: Bytes },
Bytes(Bytes),
} }
struct DeserializeBytes(Bytes); struct DeserializeBytes(Bytes);
@ -169,9 +171,12 @@ impl<'de> Visitor<'de> for AbiObjectVisitor {
} }
"bytecode" | "byteCode" => { "bytecode" | "byteCode" => {
bytecode = map bytecode = map
.next_value::<BytecodeObject>() .next_value::<Bytecode>()
.ok() .ok()
.map(|obj| obj.object) .map(|obj| match obj {
Bytecode::Object { object } => object,
Bytecode::Bytes(bytes) => bytes,
})
.filter(|bytecode| !bytecode.0.is_empty()); .filter(|bytecode| !bytecode.0.is_empty());
} }
"bin" => { "bin" => {
@ -263,6 +268,9 @@ mod tests {
let s = format!(r#"{{"abi": {abi_str}, "bytecode" : {{ "object": "{code}" }} }}"#); let s = format!(r#"{{"abi": {abi_str}, "bytecode" : {{ "object": "{code}" }} }}"#);
assert_has_bytecode(&s); assert_has_bytecode(&s);
let s = format!(r#"{{"abi": {abi_str}, "bytecode" : "{code}" }}"#);
assert_has_bytecode(&s);
let hh_artifact = include_str!( let hh_artifact = include_str!(
"../../../ethers-contract/tests/solidity-contracts/verifier_abi_hardhat.json" "../../../ethers-contract/tests/solidity-contracts/verifier_abi_hardhat.json"
); );

View File

@ -10,8 +10,8 @@ use std::{convert::TryFrom, sync::Arc, time::Duration};
// Generate the type-safe contract bindings by providing the json artifact // Generate the type-safe contract bindings by providing the json artifact
// *Note*: this requires a `bytecode` and `abi` object in the `greeter.json` artifact: // *Note*: this requires a `bytecode` and `abi` object in the `greeter.json` artifact:
// `{"abi": [..], "bin": "..."}` or `{"abi": [..], "bytecode": {"object": "..."}}` // `{"abi": [..], "bin": "..."}` , `{"abi": [..], "bytecode": {"object": "..."}}` or
// this will embedd the bytecode in a variable `GREETER_BYTECODE` // `{"abi": [..], "bytecode": "..."}` this will embedd the bytecode in a variable `GREETER_BYTECODE`
abigen!(Greeter, "ethers-contract/tests/solidity-contracts/greeter.json",); abigen!(Greeter, "ethers-contract/tests/solidity-contracts/greeter.json",);
#[tokio::main] #[tokio::main]