Skip to content
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

Usage of send_enabled param for bank xmod #318

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gears/src/x/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub enum BankKeeperError {
AccountPermission,
#[error("{0} is not allowed to receive funds. Probably tried send to module as account")]
Blocked(AccAddress),
#[error("Send disabled for denom: {0}")]
SendDisabled(Denom),
#[error("{0}")]
GasError(#[from] GasStoreErrors),
}
Expand Down
32 changes: 32 additions & 0 deletions x/bank/src/keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ impl<
amount,
}: MsgSend,
) -> Result<(), BankKeeperError> {
if let Some(denom) = self.find_first_blocked_denom_if_any(ctx, amount.inner())? {
Err(BankKeeperError::SendDisabled(denom.clone()))?
}

let mut events = vec![];

for send_coin in amount.inner() {
Expand Down Expand Up @@ -669,6 +673,34 @@ impl<
Err(_) => Ok((None, total, pagination)),
}
}

fn find_first_blocked_denom_if_any<'a, DB: Database, CTX: QueryableContext<DB, SK>>(
&self,
ctx: &CTX,
coins: impl IntoIterator<Item = &'a UnsignedCoin>,
) -> Result<Option<&'a Denom>, GasStoreErrors> {
let BankParams {
send_enabled,
default_send_enabled,
} = self.bank_params_keeper.try_get(ctx)?;

let send_enabled = send_enabled
.into_iter()
.map(|this| (this.denom, this.enabled))
.collect::<HashMap<_, _>>();
for UnsignedCoin { denom, amount: _ } in coins {
let enabled = send_enabled
.get(denom)
.map(bool::clone)
.unwrap_or(default_send_enabled);

if !enabled {
return Ok(Some(denom));
}
}

Ok(None)
}
}

//TODO: copy tests across
Loading