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

Commit

Permalink
refactor: deploy function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Mar 17, 2022
1 parent 8b50237 commit 1e04fa0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
37 changes: 12 additions & 25 deletions ethers-contract/ethers-contract-abigen/src/contract/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,26 @@ impl Context {
#bytecode_name.clone().into()
};

let get_client = quote! {
self.deref().client().clone()
};
let deploy_tokens = quote! {
/// Constructs the general purpose `Deployer` instance based on the provided constructor arguments
/// You must call `send()` in order to actually deploy the contract.
let deploy = quote! {
/// Constructs the general purpose `Deployer` instance based on the provided constructor arguments and sends it.
/// Returns a new instance of this contract afterwards
///
/// Notes:
/// 1. If there are no constructor arguments, you should pass `()` as the argument.
/// 1. The default poll duration is 7 seconds.
/// 1. The default number of confirmations is 1 block.
pub fn deploy_tokens<T: #ethers_core::abi::Tokenize >(self, constructor_args: T) -> Result<#ethers_contract::factory::Deployer<M>, #ethers_contract::call::ContractError<M>> {
let factory = #ethers_contract::factory::ContractFactory::new(#get_abi, #get_bytecode, #get_client);
factory.deploy_tokens(constructor_args.into_tokens())
// TODO make this return an additional helper type
pub async fn deploy<T: #ethers_core::abi::Tokenize >(client client: ::std::sync::Arc<M>, constructor_args: T) -> Result<#ethers_contract::factory::Deployer<M>, #ethers_contract::call::ContractError<M>> {
let factory = #ethers_contract::factory::ContractFactory::new(#get_abi, #get_bytecode, :client);
let contract = factory.deploy(constructor_args)?.send().await?;
Self(contract)
}

};
// /// Constructs the deployment transaction and returns a `Deployer` instance.
// /// You must call `send()` in order to actually deploy the contract.
// ///
// /// Notes:
// /// 1. If there are no constructor arguments, you should pass `()` as the argument.
// /// 1. The default poll duration is 7 seconds.
// /// 1. The default number of confirmations is 1 block.
// pub fn deploy<T: Tokenize>(self, constructor_args: T) -> Result<Deployer<M>,
// ContractError<M>> { self.deploy_tokens(constructor_args.
// into_tokens()) // let factory = ContractFactory::new(abi.unwrap(),
// bytecode.unwrap(), client.clone()); }

return quote! {

#deploy_tokens
}

// TODO generate all constructors,

return deploy
}

quote! {}
Expand Down
21 changes: 21 additions & 0 deletions ethers-contract/tests/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,27 @@ fn can_handle_case_sensitive_calls() {
let _ = contract.INDEX();
}

#[tokio::test]
async fn can_deploy_greeter() {
abigen!(Greeter, "ethers-contract/tests/solidity-contracts/greeter_with_struct.json",);
let ganache = ethers_core::utils::Ganache::new().spawn();
let from = ganache.addresses()[0];
let provider = Provider::try_from(ganache.endpoint())
.unwrap()
.with_sender(from)
.interval(std::time::Duration::from_millis(10));
let client = Arc::new(provider);

Greeter::deploy(client, ());
// let addr = factory.deploy(()).unwrap().legacy().send().await.unwrap().address();
//
// let contract = AbiEncoderv2Test::new(addr, client.clone());
// let person = Person { name: "Alice".to_string(), age: 20u64.into() };
//
// let res = contract.default_person().call().await.unwrap();
// assert_eq!(res, person);
}

#[tokio::test]
async fn can_abiencoderv2_output() {
abigen!(AbiEncoderv2Test, "ethers-contract/tests/solidity-contracts/abiencoderv2test_abi.json",);
Expand Down

0 comments on commit 1e04fa0

Please sign in to comment.