From 5d604edd5c5eb13714fe39d54a26f470033a5ced Mon Sep 17 00:00:00 2001 From: Meet Mangukiya Date: Sun, 22 May 2022 06:18:41 +0530 Subject: [PATCH] feat(ContractDeployer): add tx builder methods (#1289) --- CHANGELOG.md | 2 ++ ethers-contract/src/factory.rs | 52 ++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e15b3a61..b7db676d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -213,6 +213,8 @@ ### Unreleased +- Added tx builder methods to `ContractFactory` + [#1289](https://github.com/gakonst/ethers-rs/pull/1289) - Relax Clone requirements when Arc is used [#1183](https://github.com/gakonst/ethers-rs/pull/1183) - Add `EventStream::select` to combine streams with different event types diff --git a/ethers-contract/src/factory.rs b/ethers-contract/src/factory.rs index 23ef6bb9..cb493e0b 100644 --- a/ethers-contract/src/factory.rs +++ b/ethers-contract/src/factory.rs @@ -4,8 +4,8 @@ use std::marker::PhantomData; use ethers_core::{ abi::{Abi, Token, Tokenize}, types::{ - transaction::eip2718::TypedTransaction, BlockNumber, Bytes, TransactionReceipt, - TransactionRequest, + transaction::eip2718::TypedTransaction, Address, BlockNumber, Bytes, NameOrAddress, + TransactionReceipt, TransactionRequest, U256, U64, }, }; use ethers_providers::Middleware; @@ -59,6 +59,54 @@ impl>> ContractDeployer { self } + /// Sets the `from` field in the deploy transaction to the provided value + pub fn from>(mut self, from: T) -> Self { + self.deployer.tx.set_from(from.into()); + self + } + + /// Sets the `to` field in the deploy transaction to the provided value + pub fn to>(mut self, to: T) -> Self { + self.deployer.tx.set_to(to.into()); + self + } + + /// Sets the `gas` field in the deploy transaction to the provided value + pub fn gas>(mut self, gas: T) -> Self { + self.deployer.tx.set_gas(gas.into()); + self + } + + /// Sets the `gas_price` field in the deploy transaction to the provided value + pub fn gas_price>(mut self, gas_price: T) -> Self { + self.deployer.tx.set_gas_price(gas_price.into()); + self + } + + /// Sets the `value` field in the deploy transaction to the provided value + pub fn value>(mut self, value: T) -> Self { + self.deployer.tx.set_value(value.into()); + self + } + + /// Sets the `data` field in the deploy transaction to the provided value + pub fn data>(mut self, data: T) -> Self { + self.deployer.tx.set_data(data.into()); + self + } + + /// Sets the `nonce` field in the deploy transaction to the provided value + pub fn nonce>(mut self, nonce: T) -> Self { + self.deployer.tx.set_nonce(nonce.into()); + self + } + + /// Sets the `chain_id` field in the deploy transaction to the provided value + pub fn chain_id>(mut self, chain_id: T) -> Self { + self.deployer.tx.set_chain_id(chain_id.into()); + self + } + /// Dry runs the deployment of the contract /// /// Note: this function _does not_ send a transaction from your account