WIP: Add ContractFactory
This commit is contained in:
parent
7a17b2dec2
commit
e96446388f
|
@ -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<T: Tokenize>(
|
||||||
|
constructor_args: T,
|
||||||
|
) -> Result<Contract<'a, P, N, S>, 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,9 @@ pub use event::Event;
|
||||||
mod call;
|
mod call;
|
||||||
pub use call::{ContractCall, ContractError};
|
pub use call::{ContractCall, ContractError};
|
||||||
|
|
||||||
|
mod factory;
|
||||||
|
pub use factory::ContractFactory;
|
||||||
|
|
||||||
#[cfg(feature = "abigen")]
|
#[cfg(feature = "abigen")]
|
||||||
pub use ethers_contract_abigen::Builder;
|
pub use ethers_contract_abigen::Builder;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue