Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fixbreaking compactref api
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Dec 6, 2021
1 parent 0cc5836 commit 4ce6e58
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ethers-contract/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<M: Middleware> Deployer<M> {
/// let client = std::sync::Arc::new(client);
///
/// // create a factory which will be used to deploy instances of the contract
/// let factory = ContractFactory::new(contract.abi.unwrap().clone(), contract.bin.unwrap().clone(), client);
/// let factory = ContractFactory::new(contract.abi.unwrap().clone(), contract.bytecode().unwrap().clone(), client);
///
/// // The deployer created by the `deploy` call exposes a builder which gets consumed
/// // by the async `send` call
Expand Down
2 changes: 1 addition & 1 deletion ethers-contract/tests/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async fn can_handle_underscore_functions() {
let compiled = compiled.get(path, contract).unwrap();
let factory = ethers_contract::ContractFactory::new(
compiled.abi.unwrap().clone(),
compiled.bin.unwrap().clone(),
compiled.bytecode().unwrap().clone(),
client.clone(),
);
let addr = factory.deploy("hi".to_string()).unwrap().legacy().send().await.unwrap().address();
Expand Down
3 changes: 2 additions & 1 deletion ethers-contract/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ pub fn compile_contract(name: &str, filename: &str) -> (Abi, Bytes) {
let path = format!("./tests/solidity-contracts/{}", filename);
let compiled = Solc::default().compile_source(&path).unwrap();
let contract = compiled.get(&path, name).expect("could not find contract");
(contract.abi.unwrap().clone(), contract.bin.unwrap().clone())
let (abi, bin, _) = contract.into_parts_or_default();
(abi, bin)
}

/// connects the private key to http://localhost:8545
Expand Down
3 changes: 2 additions & 1 deletion ethers-middleware/tests/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ async fn deploy_and_call_contract() {
let path = format!("./tests/solidity-contracts/{}", path);
let compiled = Solc::default().compile_source(&path).unwrap();
let contract = compiled.get(&path, name).expect("could not find contract");
(contract.abi.unwrap().clone(), contract.bin.unwrap().clone())
let (abi, bin, _) = contract.into_parts_or_default();
(abi, bin)
}

let (abi, bytecode) = compile_contract("SimpleStorage.sol", "SimpleStorage");
Expand Down
3 changes: 2 additions & 1 deletion ethers-middleware/tests/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ fn compile_contract(path: &str, name: &str) -> (Abi, Bytes) {
let path = format!("./tests/solidity-contracts/{}", path);
let compiled = Solc::default().compile_source(&path).unwrap();
let contract = compiled.get(&path, name).expect("could not find contract");
(contract.abi.unwrap().clone(), contract.bin.unwrap().clone())
let (abi, bin, _) = contract.into_parts_or_default();
(abi, bin)
}

#[tokio::test]
Expand Down
8 changes: 8 additions & 0 deletions ethers-solc/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,14 @@ impl<'a> CompactContractRef<'a> {
pub fn into_parts_or_default(self) -> (Abi, Bytes, Bytes) {
CompactContract::from(self).into_parts_or_default()
}

pub fn bytecode(&self) -> Option<&Bytes> {
self.bin.as_ref().and_then(|bin| bin.as_bytes())
}

pub fn runtime_bytecode(&self) -> Option<&Bytes> {
self.bin_runtime.as_ref().and_then(|bin| bin.as_bytes())
}
}

impl<'a> From<&'a Contract> for CompactContractRef<'a> {
Expand Down
2 changes: 1 addition & 1 deletion examples/contract_human_readable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> Result<()> {
// 5. create a factory which will be used to deploy instances of the contract
let factory = ContractFactory::new(
contract.abi.unwrap().clone(),
contract.bin.unwrap().clone(),
contract.bytecode().unwrap().clone(),
client.clone(),
);

Expand Down

0 comments on commit 4ce6e58

Please sign in to comment.