clippy fixes

This commit is contained in:
Luke Parker 2023-10-19 06:30:58 -04:00
parent 43841f95fc
commit a1b2bdf0a2
No known key found for this signature in database
7 changed files with 38 additions and 17 deletions

View file

@ -209,7 +209,7 @@ async fn handle_batch_and_burns<D: Db, Pro: Processors>(
}
for burn in serai.coins().burn_events().await? {
if let CoinsEvent::Burn { address: _, instruction } = burn {
if let CoinsEvent::Burn { from: _, instruction } = burn {
let network = instruction.balance.coin.network();
network_had_event(&mut burns, &mut batches, network);

View file

@ -60,7 +60,7 @@ impl<'a> SeraiCoins<'a> {
Payload::new(
PALLET,
"transfer",
scale_composite(serai_runtime::coins::Call::<Runtime>::transfer { to, balance }),
scale_composite(serai_runtime::coins::Call::<Runtime>::transfer { to: to.into(), balance }),
)
}

View file

@ -65,7 +65,10 @@ serai_test!(
}
let serai = serai.coins();
assert_eq!(serai.mint_events().await.unwrap(), vec![CoinsEvent::Mint { address, balance }],);
assert_eq!(
serai.mint_events().await.unwrap(),
vec![CoinsEvent::Mint { to: address.into(), balance }]
);
assert_eq!(serai.coin_supply(coin).await.unwrap(), amount);
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), amount);
}

View file

@ -70,7 +70,7 @@ serai_test!(
assert_eq!(
serai.coins().mint_events().await.unwrap(),
vec![CoinsEvent::Mint { address, balance }]
vec![CoinsEvent::Mint { to: address.into(), balance }]
);
assert_eq!(serai.coins().coin_supply(coin).await.unwrap(), amount);
assert_eq!(serai.coins().coin_balance(coin, address).await.unwrap(), amount);
@ -103,7 +103,7 @@ serai_test!(
let serai = serai.as_of(block).coins();
let events = serai.burn_events().await.unwrap();
assert_eq!(events, vec![CoinsEvent::Burn { address, instruction }]);
assert_eq!(events, vec![CoinsEvent::Burn { from: address.into(), instruction }]);
assert_eq!(serai.coin_supply(coin).await.unwrap(), Amount(0));
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), Amount(0));
}

View file

@ -26,13 +26,12 @@ pub mod pallet {
#[pallet::genesis_config]
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
pub struct GenesisConfig<T: Config> {
_config: PhantomData<T>,
pub accounts: Vec<(Public, Balance)>,
pub accounts: Vec<(T::AccountId, Balance)>,
}
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig { _config: PhantomData, accounts: Default::default() }
GenesisConfig { accounts: Default::default() }
}
}
@ -60,8 +59,15 @@ 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.
@ -152,7 +158,10 @@ 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(());
@ -162,13 +171,18 @@ 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(())
@ -187,7 +201,11 @@ 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)?;

View file

@ -74,7 +74,7 @@ pub mod pallet {
fn execute(instruction: InInstructionWithBalance) -> Result<(), ()> {
match instruction.instruction {
InInstruction::Transfer(address) => {
Coins::<T>::mint(&address.into(), instruction.balance).map_err(|_| ())
Coins::<T>::mint(address.into(), instruction.balance).map_err(|_| ())
}
_ => panic!("unsupported instruction"),
}

View file

@ -97,7 +97,7 @@ pub mod pallet {
pub fn stake(origin: OriginFor<T>, #[pallet::compact] amount: u64) -> DispatchResult {
let signer = ensure_signed(origin)?;
let balance = Balance { coin: Coin::Serai, amount: Amount(amount) };
Coins::<T>::transfer_internal(&signer, &Self::account(), balance)?;
Coins::<T>::transfer_internal(signer, Self::account(), balance)?;
Self::add_stake(&signer, amount);
Ok(())
}
@ -109,7 +109,7 @@ pub mod pallet {
let signer = ensure_signed(origin)?;
Self::remove_stake(&signer, amount)?;
let balance = Balance { coin: Coin::Serai, amount: Amount(amount) };
Coins::<T>::transfer_internal(&Self::account(), &signer, balance)?;
Coins::<T>::transfer_internal(Self::account(), signer, balance)?;
Ok(())
}