From 2032cf355f013c36d466357afa92fdd814101b18 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 3 Sep 2025 00:48:15 -0400 Subject: [PATCH] Expose `coins::Pallet::transfer_internal` as `transfer_fn` It is safe to call and assumes no preconditions. --- substrate/coins/src/lib.rs | 4 ++-- substrate/validator-sets/src/lib.rs | 16 ++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/substrate/coins/src/lib.rs b/substrate/coins/src/lib.rs index 7295a6a7..c73cd956 100644 --- a/substrate/coins/src/lib.rs +++ b/substrate/coins/src/lib.rs @@ -241,7 +241,7 @@ mod pallet { } /// Transfer `balance` from `from` to `to`. - fn transfer_internal(from: Public, to: Public, balance: Balance) -> Result<(), Error> { + pub fn transfer_fn(from: Public, to: Public, balance: Balance) -> Result<(), Error> { // 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, to: Public, balance: Balance) -> DispatchResult { let from = ensure_signed(origin)?; - Self::transfer_internal(from, to, balance)?; + Self::transfer_fn(from, to, balance)?; Ok(()) } diff --git a/substrate/validator-sets/src/lib.rs b/substrate/validator-sets/src/lib.rs index 672e51cc..7cce9c6c 100644 --- a/substrate/validator-sets/src/lib.rs +++ b/substrate/validator-sets/src/lib.rs @@ -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::::transfer_internal( + Coins::::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, network: NetworkId, amount: Amount) -> DispatchResult { let validator = ensure_signed(origin)?; - Coins::::transfer_internal( - validator, - Self::account(), - Balance { coin: Coin::Serai, amount }, - )?; + Coins::::transfer_fn(validator, Self::account(), Balance { coin: Coin::Serai, amount })?; Abstractions::::increase_allocation(network, validator, amount, false) .map_err(Error::::AllocationError)?; Ok(()) @@ -822,11 +818,7 @@ mod pallet { let deallocation_timeline = Abstractions::::decrease_allocation(network, account, amount) .map_err(Error::::DeallocationError)?; if matches!(deallocation_timeline, DeallocationTimeline::Immediate) { - Coins::::transfer_internal( - Self::account(), - account, - Balance { coin: Coin::Serai, amount }, - )?; + Coins::::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::::NonExistentDeallocation)? }; - Coins::::transfer_internal( + Coins::::transfer_fn( Self::account(), account, Balance { coin: Coin::Serai, amount },