Skip to content

Commit

Permalink
fix: fix event withdraw bug, and fix a warning (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytqaljn authored May 11, 2024
1 parent 4f5c4da commit 1134289
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pallets/reservoir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod types;
use types::*;

mod impls;
use impls::*;

pub use pallet::*;

Expand Down Expand Up @@ -205,12 +204,11 @@ pub mod pallet {

#[pallet::call_index(3)]
#[pallet::weight(Weight::zero())]
pub fn event_withdraw(origin: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {
ensure_root(origin.clone())?;
let root = ensure_signed(origin)?;
pub fn event_withdraw(origin: OriginFor<T>, amount: BalanceOf<T>, target: AccountOf<T>) -> DispatchResult {
ensure_root(origin)?;

let reservoir = T::PalletId::get().into_account_truncating();
T::Currency::transfer(&reservoir, &root, amount, KeepAlive)?;
T::Currency::transfer(&reservoir, &target, amount, KeepAlive)?;

Reservoir::<T>::try_mutate(|reservoir| -> DispatchResult {
reservoir.free_balance = reservoir.free_balance.checked_sub(&amount).ok_or(Error::<T>::Overflow)?;
Expand Down

0 comments on commit 1134289

Please sign in to comment.