Other clippy fixes

This commit is contained in:
Luke Parker 2023-10-19 07:16:35 -04:00
parent a1b2bdf0a2
commit d833254b84
No known key found for this signature in database
2 changed files with 8 additions and 27 deletions

View file

@ -59,15 +59,8 @@ pub mod pallet {
// ID. // ID.
#[pallet::storage] #[pallet::storage]
#[pallet::getter(fn balances)] #[pallet::getter(fn balances)]
pub type Balances<T: Config> = StorageDoubleMap< pub type Balances<T: Config> =
_, StorageDoubleMap<_, Blake2_128Concat, Public, Identity, Coin, SubstrateAmount, ValueQuery>;
Blake2_128Concat,
Public,
Identity,
Coin,
SubstrateAmount,
ValueQuery,
>;
/// The total supply of each coin. /// The total supply of each coin.
// We use Identity type here again due to reasons stated in the Balances Storage. // We use Identity type here again due to reasons stated in the Balances Storage.
@ -158,10 +151,7 @@ pub mod pallet {
} }
// Burn `balance` from the specified account. // Burn `balance` from the specified account.
fn burn_internal( fn burn_internal(from: Public, balance: Balance) -> Result<(), Error<T>> {
from: Public,
balance: Balance,
) -> Result<(), Error<T>> {
// don't waste time if amount == 0 // don't waste time if amount == 0
if balance.amount.0 == 0 { if balance.amount.0 == 0 {
return Ok(()); return Ok(());
@ -171,18 +161,13 @@ pub mod pallet {
Self::decrease_balance_internal(from, balance)?; Self::decrease_balance_internal(from, balance)?;
// update the supply // update the supply
let new_supply = Self::supply(balance.coin) let new_supply = Self::supply(balance.coin).checked_sub(balance.amount.0).unwrap();
.checked_sub(balance.amount.0)
.unwrap();
Supply::<T>::set(balance.coin, new_supply); Supply::<T>::set(balance.coin, new_supply);
Ok(()) Ok(())
} }
pub fn burn_sri( pub fn burn_sri(from: Public, amount: Amount) -> Result<(), Error<T>> {
from: Public,
amount: Amount,
) -> Result<(), Error<T>> {
Self::burn_internal(from, Balance { coin: Coin::Serai, amount })?; Self::burn_internal(from, Balance { coin: Coin::Serai, amount })?;
Self::deposit_event(Event::SriBurn { from, amount }); Self::deposit_event(Event::SriBurn { from, amount });
Ok(()) Ok(())
@ -201,11 +186,7 @@ pub mod pallet {
} }
/// Transfer `balance` from `from` to `to`. /// Transfer `balance` from `from` to `to`.
pub fn transfer_internal( pub fn transfer_internal(from: Public, to: Public, balance: Balance) -> Result<(), Error<T>> {
from: Public,
to: Public,
balance: Balance,
) -> Result<(), Error<T>> {
// update balances of accounts // update balances of accounts
Self::decrease_balance_internal(from, balance)?; Self::decrease_balance_internal(from, balance)?;
Self::increase_balance_internal(to, balance)?; Self::increase_balance_internal(to, balance)?;

View file

@ -258,7 +258,7 @@ async fn sign_test() {
// Verify the mint occurred as expected // Verify the mint occurred as expected
assert_eq!( assert_eq!(
serai.mint_events().await.unwrap(), 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_supply(Coin::Bitcoin).await.unwrap(), amount);
assert_eq!(serai.coin_balance(Coin::Bitcoin, serai_addr).await.unwrap(), amount); assert_eq!(serai.coin_balance(Coin::Bitcoin, serai_addr).await.unwrap(), amount);
@ -301,7 +301,7 @@ async fn sign_test() {
assert_eq!(burn_events.len(), 1); assert_eq!(burn_events.len(), 1);
assert_eq!( assert_eq!(
burn_events[0], burn_events[0],
CoinsEvent::Burn { address: serai_addr, instruction: out_instruction.clone() } CoinsEvent::Burn { from: serai_addr.into(), instruction: out_instruction.clone() }
); );
break 'outer; break 'outer;
} }