1use crate::tx::{CastTxBuilder, SenderKind, validate_authorizations};
2use alloy_network::Network;
3use eyre::Result;
4use foundry_cli::opts::CliAuthorizationList;
5use foundry_common::shell;
6
7pub(super) fn confirm_auth_rpc_disclosure<N: Network, P, S>(
13 builder: &CastTxBuilder<N, P, S>,
14 sender: &SenderKind<'_>,
15 force: bool,
16) -> Result<bool> {
17 builder.validate_auth(sender)?;
18
19 confirm_auth_rpc_disclosure_after_validation(force)
20}
21
22pub(super) fn confirm_auth_rpc_disclosure_before_network_resolution(
24 authorizations: &[CliAuthorizationList],
25 sender: &SenderKind<'_>,
26 force: bool,
27) -> Result<bool> {
28 validate_authorizations(authorizations, sender)?;
29
30 confirm_auth_rpc_disclosure_after_validation(force)
31}
32
33fn confirm_auth_rpc_disclosure_after_validation(force: bool) -> Result<bool> {
34 if force {
35 return Ok(true);
36 }
37 if shell::is_quiet() {
38 eyre::bail!(
39 "EIP-7702 authorization disclosure requires confirmation; pass `--force` to continue with `--quiet`"
40 );
41 }
42
43 sh_warn!(
44 "This command will send a signed EIP-7702 authorization to the RPC endpoint. The authorization can be submitted on-chain by anyone once its nonce is valid."
45 )?;
46 let response: String = foundry_common::prompt!("\nContinue anyway? [y/N] ")?;
47 if !matches!(response.trim(), "y" | "Y") {
48 sh_status!("Aborted.")?;
49 return Ok(false);
50 }
51
52 Ok(true)
53}
54
55pub(super) fn confirm_auth_rpc_disclosure_during_build<'a, N: Network, P, S>(
58 builder: &CastTxBuilder<N, P, S>,
59 sender: impl Into<SenderKind<'a>>,
60 force: bool,
61) -> Result<bool> {
62 if !builder.will_disclose_auth_during_build() {
63 return Ok(true);
64 }
65
66 confirm_auth_rpc_disclosure(builder, &sender.into(), force)
67}