Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Oct 19, 2023
1 parent 43841f9 commit a1b2bdf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion coordinator/src/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion substrate/client/src/serai/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
)
}

Expand Down
5 changes: 4 additions & 1 deletion substrate/client/tests/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
Expand Down
36 changes: 27 additions & 9 deletions substrate/coins/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(());
Expand All @@ -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(())
Expand All @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion substrate/in-instructions/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/staking/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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(())
}

Expand Down

0 comments on commit a1b2bdf

Please sign in to comment.