Skip to content

Commit 017dd44

Browse files
authored
add legacy option to SendTx (#626)
1 parent 457fae7 commit 017dd44

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

cast/src/lib.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ where
7474
chain: Chain,
7575
etherscan_api_key: Option<String>,
7676
) -> Result<String> {
77-
let (tx, func) =
78-
self.build_tx(from, to, Some(args), None, None, None, chain, etherscan_api_key).await?;
77+
let (tx, func) = self
78+
.build_tx(from, to, Some(args), None, None, None, chain, etherscan_api_key, false)
79+
.await?;
7980
let res = self.provider.call(&tx, None).await?;
8081

8182
// decode args into tokens
@@ -133,7 +134,7 @@ where
133134
/// let gas = U256::from_str("200000").unwrap();
134135
/// let value = U256::from_str("1").unwrap();
135136
/// let nonce = U256::from_str("1").unwrap();
136-
/// let data = cast.send(from, to, Some((sig, args)), Some(gas), Some(value), Some(nonce), Chain::Mainnet, None).await?;
137+
/// let data = cast.send(from, to, Some((sig, args)), Some(gas), Some(value), Some(nonce), Chain::Mainnet, None, false).await?;
137138
/// println!("{}", *data);
138139
/// # Ok(())
139140
/// # }
@@ -149,9 +150,11 @@ where
149150
nonce: Option<U256>,
150151
chain: Chain,
151152
etherscan_api_key: Option<String>,
153+
legacy: bool,
152154
) -> Result<PendingTransaction<'_, M::Provider>> {
153-
let (tx, _) =
154-
self.build_tx(from, to, args, gas, value, nonce, chain, etherscan_api_key).await?;
155+
let (tx, _) = self
156+
.build_tx(from, to, args, gas, value, nonce, chain, etherscan_api_key, legacy)
157+
.await?;
155158
let res = self.provider.send_transaction(tx, None).await?;
156159

157160
Ok::<_, eyre::Error>(res)
@@ -212,8 +215,9 @@ where
212215
chain: Chain,
213216
etherscan_api_key: Option<String>,
214217
) -> Result<U256> {
215-
let (tx, _) =
216-
self.build_tx(from, to, args, None, value, None, chain, etherscan_api_key).await?;
218+
let (tx, _) = self
219+
.build_tx(from, to, args, None, value, None, chain, etherscan_api_key, false)
220+
.await?;
217221
let res = self.provider.estimate_gas(&tx).await?;
218222

219223
Ok::<_, eyre::Error>(res)
@@ -230,6 +234,7 @@ where
230234
nonce: Option<U256>,
231235
chain: Chain,
232236
etherscan_api_key: Option<String>,
237+
legacy: bool,
233238
) -> Result<(TypedTransaction, Option<ethers_core::abi::Function>)> {
234239
let from = match from.into() {
235240
NameOrAddress::Name(ref ens_name) => self.provider.resolve_name(ens_name).await?,
@@ -245,7 +250,7 @@ where
245250
};
246251

247252
// make the call
248-
let mut tx: TypedTransaction = if chain.is_legacy() {
253+
let mut tx: TypedTransaction = if chain.is_legacy() || legacy {
249254
TransactionRequest::new().from(from).to(to).into()
250255
} else {
251256
Eip1559TransactionRequest::new().from(from).to(to).into()

cli/src/cast.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async fn main() -> eyre::Result<()> {
176176
let provider = Provider::try_from(rpc_url)?;
177177
println!("{}", Cast::new(&provider).transaction(hash, field, to_json).await?)
178178
}
179-
Subcommands::SendTx { eth, to, sig, cast_async, args, gas, value, nonce } => {
179+
Subcommands::SendTx { eth, to, sig, cast_async, args, gas, value, nonce, legacy } => {
180180
let provider = Provider::try_from(eth.rpc_url()?)?;
181181
let chain_id = Cast::new(&provider).chain_id().await?;
182182

@@ -194,6 +194,7 @@ async fn main() -> eyre::Result<()> {
194194
eth.chain,
195195
eth.etherscan_api_key,
196196
cast_async,
197+
legacy,
197198
)
198199
.await?;
199200
}
@@ -209,6 +210,7 @@ async fn main() -> eyre::Result<()> {
209210
eth.chain,
210211
eth.etherscan_api_key,
211212
cast_async,
213+
legacy,
212214
)
213215
.await?;
214216
}
@@ -224,6 +226,7 @@ async fn main() -> eyre::Result<()> {
224226
eth.chain,
225227
eth.etherscan_api_key,
226228
cast_async,
229+
legacy,
227230
)
228231
.await?;
229232
}
@@ -241,6 +244,7 @@ async fn main() -> eyre::Result<()> {
241244
eth.chain,
242245
eth.etherscan_api_key,
243246
cast_async,
247+
legacy,
244248
)
245249
.await?;
246250
}
@@ -599,6 +603,7 @@ async fn cast_send<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>
599603
chain: Chain,
600604
etherscan_api_key: Option<String>,
601605
cast_async: bool,
606+
legacy: bool,
602607
) -> eyre::Result<()>
603608
where
604609
M::Error: 'static,
@@ -609,7 +614,7 @@ where
609614
let params = args.1;
610615
let params = if !sig.is_empty() { Some((&sig[..], params)) } else { None };
611616
let pending_tx =
612-
cast.send(from, to, params, gas, value, nonce, chain, etherscan_api_key).await?;
617+
cast.send(from, to, params, gas, value, nonce, chain, etherscan_api_key, legacy).await?;
613618
let tx_hash = *pending_tx;
614619

615620
if cast_async {

cli/src/opts/cast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ pub enum Subcommands {
189189
cast_async: bool,
190190
#[clap(flatten)]
191191
eth: EthereumOpts,
192+
#[clap(
193+
long,
194+
help = "use legacy transactions instead of EIP1559 ones. this is auto-enabled for common networks without EIP1559"
195+
)]
196+
legacy: bool,
192197
},
193198
#[clap(name = "publish")]
194199
#[clap(about = "Publish a raw transaction to the network")]

0 commit comments

Comments
 (0)