From e96446388f9b061206647aaa946340a0f601ebc4 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sat, 30 May 2020 17:24:50 +0300 Subject: [PATCH] WIP: Add ContractFactory --- crates/ethers-contract/src/factory.rs | 43 +++++++++++++++++++++++++++ crates/ethers-contract/src/lib.rs | 3 ++ 2 files changed, 46 insertions(+) create mode 100644 crates/ethers-contract/src/factory.rs diff --git a/crates/ethers-contract/src/factory.rs b/crates/ethers-contract/src/factory.rs new file mode 100644 index 00000000..cc49e8fb --- /dev/null +++ b/crates/ethers-contract/src/factory.rs @@ -0,0 +1,43 @@ +use crate::Contract; + +use ethers_providers::{networks::Network, JsonRpcClient}; +use ethers_signers::{Client, Signer}; +use ethers_types::{ + abi::{Abi, Tokenize}, + Bytes, +}; + +#[derive(Debug, Clone)] +pub struct ContractFactory<'a, P, N, S> { + client: &'a Client<'a, P, N, S>, + abi: &'a Abi, + bytecode: &'a Bytes, +} + +impl<'a, P: JsonRpcClient, N: Network, S: Signer> ContractFactory<'a, P, N, S> { + /// Instantiate a new contract factory + pub fn new(client: &'a Client<'a, P, N, S>, abi: &'a Abi, bytecode: &'a Bytes) -> Self { + Self { + client, + abi, + bytecode, + } + } + + /// Deploys an instance of the contract with the provider constructor arguments + /// and returns the contract's instance + pub async fn deploy( + constructor_args: T, + ) -> Result, P::Error> { + // 1. Encode the constructor args + // + // 2. Create the runtime bytecode by concatenating the bytecode with the constructor + // arguments (?) + // + // 3. Call `client.send_transaction()` to deploy + // + // 4. Get the address of the contract from the transaction receipt + // + // 5. Instantiate & return the contract object + } +} diff --git a/crates/ethers-contract/src/lib.rs b/crates/ethers-contract/src/lib.rs index 99352d49..c1498a0e 100644 --- a/crates/ethers-contract/src/lib.rs +++ b/crates/ethers-contract/src/lib.rs @@ -7,6 +7,9 @@ pub use event::Event; mod call; pub use call::{ContractCall, ContractError}; +mod factory; +pub use factory::ContractFactory; + #[cfg(feature = "abigen")] pub use ethers_contract_abigen::Builder;