add deploy_tokens to ContractFactory (#699)

This commit is contained in:
joshieDo 2021-12-17 00:01:00 +02:00 committed by GitHub
parent 060dd6033d
commit cf53924334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -1,7 +1,7 @@
use crate::{Contract, ContractError}; use crate::{Contract, ContractError};
use ethers_core::{ use ethers_core::{
abi::{Abi, Tokenize}, abi::{Abi, Token, Tokenize},
types::{transaction::eip2718::TypedTransaction, BlockNumber, Bytes, TransactionRequest}, types::{transaction::eip2718::TypedTransaction, BlockNumber, Bytes, TransactionRequest},
}; };
use ethers_providers::Middleware; use ethers_providers::Middleware;
@ -148,17 +148,8 @@ impl<M: Middleware> ContractFactory<M> {
Self { client, abi, bytecode } Self { client, abi, bytecode }
} }
/// Constructs the deployment transaction based on the provided constructor pub fn deploy_tokens(self, params: Vec<Token>) -> Result<Deployer<M>, ContractError<M>> {
/// arguments 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>> {
// Encode the constructor args & concatenate with the bytecode if necessary // Encode the constructor args & concatenate with the bytecode if necessary
let params = constructor_args.into_tokens();
let data: Bytes = match (self.abi.constructor(), params.is_empty()) { let data: Bytes = match (self.abi.constructor(), params.is_empty()) {
(None, false) => return Err(ContractError::ConstructorError), (None, false) => return Err(ContractError::ConstructorError),
(None, true) => self.bytecode.clone(), (None, true) => self.bytecode.clone(),
@ -184,4 +175,16 @@ impl<M: Middleware> ContractFactory<M> {
block: BlockNumber::Latest, block: BlockNumber::Latest,
}) })
} }
/// Constructs the deployment transaction based on the provided constructor
/// arguments 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())
}
} }