From 8e0eddbb5769d46ca65b9f6d3ace6feef97dc816 Mon Sep 17 00:00:00 2001 From: thasarito Date: Sat, 8 Jan 2022 16:17:36 +0700 Subject: [PATCH] feat: change abi_str to abi from contract in for hardhat abi (#740) --- ethers-contract/ethers-contract-abigen/src/contract.rs | 9 ++++++++- ethers-contract/tests/abigen.rs | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ethers-contract/ethers-contract-abigen/src/contract.rs b/ethers-contract/ethers-contract-abigen/src/contract.rs index b47c8d50..42c1feba 100644 --- a/ethers-contract/ethers-contract-abigen/src/contract.rs +++ b/ethers-contract/ethers-contract-abigen/src/contract.rs @@ -152,7 +152,7 @@ impl Context { /// Create a context from the code generation arguments. pub fn from_abigen(args: Abigen) -> Result { // get the actual ABI string - let abi_str = + let mut abi_str = args.abi_source.get().map_err(|e| anyhow!("failed to get ABI JSON: {}", e))?; let (abi, human_readable, abi_parser) = parse_abi(&abi_str)?; @@ -172,6 +172,13 @@ impl Context { internal_structs.outputs = abi_parser.outputs.clone(); internal_structs + } else if abi_str.starts_with('{') { + abi_str = serde_json::to_string(&abi).context("fail to serialize abi to json")?; + + serde_json::from_str::(&abi_str) + .ok() + .map(InternalStructs::new) + .unwrap_or_default() } else { serde_json::from_str::(&abi_str) .ok() diff --git a/ethers-contract/tests/abigen.rs b/ethers-contract/tests/abigen.rs index a4647be7..556879a1 100644 --- a/ethers-contract/tests/abigen.rs +++ b/ethers-contract/tests/abigen.rs @@ -25,6 +25,11 @@ fn can_gen_human_readable() { assert_eq!("ValueChanged(address,string,string)", ValueChangedFilter::abi_signature()); } +#[test] +fn can_gen_not_human_readable() { + abigen!(VerifierAbiHardhatContract, "./tests/solidity-contracts/verifier_abi_hardhat.json"); +} + #[test] fn can_gen_human_readable_multiple() { abigen!(