feat(ContractDeployer): add tx builder methods (#1289)

This commit is contained in:
Meet Mangukiya 2022-05-22 06:18:41 +05:30 committed by GitHub
parent 592144e308
commit 5d604edd5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View File

@ -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<Middleware> is used
[#1183](https://github.com/gakonst/ethers-rs/pull/1183)
- Add `EventStream::select` to combine streams with different event types

View File

@ -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<M: Middleware, C: From<Contract<M>>> ContractDeployer<M, C> {
self
}
/// Sets the `from` field in the deploy transaction to the provided value
pub fn from<T: Into<Address>>(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<T: Into<NameOrAddress>>(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<T: Into<U256>>(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<T: Into<U256>>(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<T: Into<U256>>(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<T: Into<Bytes>>(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<T: Into<U256>>(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<T: Into<U64>>(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