Skip to content

Commit

Permalink
Other clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Oct 19, 2023
1 parent a1b2bdf commit d833254
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
31 changes: 6 additions & 25 deletions substrate/coins/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,8 @@ pub mod pallet {
// ID.
#[pallet::storage]
#[pallet::getter(fn balances)]
pub type Balances<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
Public,
Identity,
Coin,
SubstrateAmount,
ValueQuery,
>;
pub type Balances<T: Config> =
StorageDoubleMap<_, Blake2_128Concat, Public, Identity, Coin, SubstrateAmount, ValueQuery>;

/// The total supply of each coin.
// We use Identity type here again due to reasons stated in the Balances Storage.
Expand Down Expand Up @@ -158,10 +151,7 @@ pub mod pallet {
}

// Burn `balance` from the specified account.
fn burn_internal(
from: Public,
balance: Balance,
) -> Result<(), Error<T>> {
fn burn_internal(from: Public, balance: Balance) -> Result<(), Error<T>> {
// don't waste time if amount == 0
if balance.amount.0 == 0 {
return Ok(());
Expand All @@ -171,18 +161,13 @@ pub mod pallet {
Self::decrease_balance_internal(from, balance)?;

// update the supply
let new_supply = Self::supply(balance.coin)
.checked_sub(balance.amount.0)
.unwrap();
let new_supply = Self::supply(balance.coin).checked_sub(balance.amount.0).unwrap();
Supply::<T>::set(balance.coin, new_supply);

Ok(())
}

pub fn burn_sri(
from: Public,
amount: Amount,
) -> Result<(), Error<T>> {
pub fn burn_sri(from: Public, amount: Amount) -> Result<(), Error<T>> {
Self::burn_internal(from, Balance { coin: Coin::Serai, amount })?;
Self::deposit_event(Event::SriBurn { from, amount });
Ok(())
Expand All @@ -201,11 +186,7 @@ pub mod pallet {
}

/// Transfer `balance` from `from` to `to`.
pub fn transfer_internal(
from: Public,
to: Public,
balance: Balance,
) -> Result<(), Error<T>> {
pub fn transfer_internal(from: Public, to: Public, balance: Balance) -> Result<(), Error<T>> {
// update balances of accounts
Self::decrease_balance_internal(from, balance)?;
Self::increase_balance_internal(to, balance)?;
Expand Down
4 changes: 2 additions & 2 deletions tests/coordinator/src/tests/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async fn sign_test() {
// Verify the mint occurred as expected
assert_eq!(
serai.mint_events().await.unwrap(),
vec![CoinsEvent::Mint { address: serai_addr, balance }]
vec![CoinsEvent::Mint { to: serai_addr.into(), balance }]
);
assert_eq!(serai.coin_supply(Coin::Bitcoin).await.unwrap(), amount);
assert_eq!(serai.coin_balance(Coin::Bitcoin, serai_addr).await.unwrap(), amount);
Expand Down Expand Up @@ -301,7 +301,7 @@ async fn sign_test() {
assert_eq!(burn_events.len(), 1);
assert_eq!(
burn_events[0],
CoinsEvent::Burn { address: serai_addr, instruction: out_instruction.clone() }
CoinsEvent::Burn { from: serai_addr.into(), instruction: out_instruction.clone() }
);
break 'outer;
}
Expand Down

0 comments on commit d833254

Please sign in to comment.