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

Commit

Permalink
add deploy_tokens to ContractFactory (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored Dec 16, 2021
1 parent 060dd60 commit cf53924
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions ethers-contract/src/factory.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Contract, ContractError};

use ethers_core::{
abi::{Abi, Tokenize},
abi::{Abi, Token, Tokenize},
types::{transaction::eip2718::TypedTransaction, BlockNumber, Bytes, TransactionRequest},
};
use ethers_providers::Middleware;
Expand Down Expand Up @@ -148,17 +148,8 @@ impl<M: Middleware> ContractFactory<M> {
Self { client, abi, bytecode }
}

/// 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>> {
pub fn deploy_tokens(self, params: Vec<Token>) -> Result<Deployer<M>, ContractError<M>> {
// 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()) {
(None, false) => return Err(ContractError::ConstructorError),
(None, true) => self.bytecode.clone(),
Expand All @@ -184,4 +175,16 @@ impl<M: Middleware> ContractFactory<M> {
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())
}
}

0 comments on commit cf53924

Please sign in to comment.