mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Expose coins::Pallet::transfer_internal as transfer_fn
It is safe to call and assumes no preconditions.
This commit is contained in:
@@ -241,7 +241,7 @@ mod pallet {
|
||||
}
|
||||
|
||||
/// Transfer `balance` from `from` to `to`.
|
||||
fn transfer_internal(from: Public, to: Public, balance: Balance) -> Result<(), Error<T, I>> {
|
||||
pub fn transfer_fn(from: Public, to: Public, balance: Balance) -> Result<(), Error<T, I>> {
|
||||
// update balances of accounts
|
||||
Self::decrease_balance_internal(from, balance)?;
|
||||
Self::increase_balance_internal(to, balance)?;
|
||||
@@ -257,7 +257,7 @@ mod pallet {
|
||||
#[pallet::weight((0, DispatchClass::Normal))] // TODO
|
||||
pub fn transfer(origin: OriginFor<T>, to: Public, balance: Balance) -> DispatchResult {
|
||||
let from = ensure_signed(origin)?;
|
||||
Self::transfer_internal(from, to, balance)?;
|
||||
Self::transfer_fn(from, to, balance)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -633,7 +633,7 @@ mod pallet {
|
||||
) -> DispatchResult {
|
||||
// TODO: Should this call be part of the `increase_allocation` since we have to have it
|
||||
// before each call to it?
|
||||
Coins::<T>::transfer_internal(
|
||||
Coins::<T>::transfer_fn(
|
||||
account,
|
||||
Self::account(),
|
||||
Balance { coin: Coin::Serai, amount },
|
||||
@@ -804,11 +804,7 @@ mod pallet {
|
||||
#[pallet::weight(0)] // TODO
|
||||
pub fn allocate(origin: OriginFor<T>, network: NetworkId, amount: Amount) -> DispatchResult {
|
||||
let validator = ensure_signed(origin)?;
|
||||
Coins::<T>::transfer_internal(
|
||||
validator,
|
||||
Self::account(),
|
||||
Balance { coin: Coin::Serai, amount },
|
||||
)?;
|
||||
Coins::<T>::transfer_fn(validator, Self::account(), Balance { coin: Coin::Serai, amount })?;
|
||||
Abstractions::<T>::increase_allocation(network, validator, amount, false)
|
||||
.map_err(Error::<T>::AllocationError)?;
|
||||
Ok(())
|
||||
@@ -822,11 +818,7 @@ mod pallet {
|
||||
let deallocation_timeline = Abstractions::<T>::decrease_allocation(network, account, amount)
|
||||
.map_err(Error::<T>::DeallocationError)?;
|
||||
if matches!(deallocation_timeline, DeallocationTimeline::Immediate) {
|
||||
Coins::<T>::transfer_internal(
|
||||
Self::account(),
|
||||
account,
|
||||
Balance { coin: Coin::Serai, amount },
|
||||
)?;
|
||||
Coins::<T>::transfer_fn(Self::account(), account, Balance { coin: Coin::Serai, amount })?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -844,7 +836,7 @@ mod pallet {
|
||||
let Some(amount) = Self::take_deallocatable_amount(network, session, account) else {
|
||||
Err(Error::<T>::NonExistentDeallocation)?
|
||||
};
|
||||
Coins::<T>::transfer_internal(
|
||||
Coins::<T>::transfer_fn(
|
||||
Self::account(),
|
||||
account,
|
||||
Balance { coin: Coin::Serai, amount },
|
||||
|
||||
Reference in New Issue
Block a user