-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(cast): improve handling of mktx --raw-unsigned
with runtime validation
#11111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
use crate::tx::{self, CastTxBuilder}; | ||
use alloy_ens::NameOrAddress; | ||
use alloy_network::{EthereumWallet, TransactionBuilder, eip2718::Encodable2718}; | ||
use alloy_primitives::hex; | ||
use alloy_primitives::{Address, hex}; | ||
use alloy_provider::Provider; | ||
use alloy_signer::Signer; | ||
use clap::Parser; | ||
use eyre::{OptionExt, Result}; | ||
use eyre::Result; | ||
use foundry_cli::{ | ||
opts::{EthereumOpts, TransactionOpts}, | ||
utils::{LoadConfig, get_provider}, | ||
|
@@ -49,7 +49,7 @@ pub struct MakeTxArgs { | |
/// Generate a raw RLP-encoded unsigned transaction. | ||
/// | ||
/// Relaxes the wallet requirement. | ||
#[arg(long, requires = "from")] | ||
#[arg(long)] | ||
raw_unsigned: bool, | ||
|
||
/// Call `eth_signTransaction` using the `--from` argument or $ETH_FROM as sender | ||
|
@@ -96,7 +96,7 @@ impl MakeTxArgs { | |
|
||
let provider = get_provider(&config)?; | ||
|
||
let tx_builder = CastTxBuilder::new(&provider, tx, &config) | ||
let tx_builder = CastTxBuilder::new(&provider, tx.clone(), &config) | ||
.await? | ||
.with_to(to) | ||
.await? | ||
|
@@ -106,7 +106,17 @@ impl MakeTxArgs { | |
|
||
if raw_unsigned { | ||
// Build unsigned raw tx | ||
let from = eth.wallet.from.ok_or_eyre("missing `--from` address")?; | ||
// Check if nonce is provided when --from is not specified | ||
// See: <https://github.com/foundry-rs/foundry/issues/11110> | ||
if eth.wallet.from.is_none() && tx.nonce.is_none() { | ||
Comment on lines
+109
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah, that makes sense, the api is a bit weird like that because this basically reuses the regular signing function just with an optional value for returning unsigned |
||
eyre::bail!( | ||
"Missing required parameters for raw unsigned transaction. When --from is not provided, you must specify: --nonce" | ||
); | ||
} | ||
|
||
// Use zero address as placeholder for unsigned transactions | ||
let from = eth.wallet.from.unwrap_or(Address::ZERO); | ||
|
||
let raw_tx = tx_builder.build_unsigned_raw(from).await?; | ||
|
||
sh_println!("{raw_tx}")?; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could copy the nonce first, but this would just introduce another variable and doesnt really matter for this command