mirror of
https://github.com/serai-dex/serai.git
synced 2025-02-02 11:16:41 +00:00
clippy fixes
This commit is contained in:
parent
43841f95fc
commit
a1b2bdf0a2
7 changed files with 38 additions and 17 deletions
|
@ -209,7 +209,7 @@ async fn handle_batch_and_burns<D: Db, Pro: Processors>(
|
||||||
}
|
}
|
||||||
|
|
||||||
for burn in serai.coins().burn_events().await? {
|
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();
|
let network = instruction.balance.coin.network();
|
||||||
network_had_event(&mut burns, &mut batches, network);
|
network_had_event(&mut burns, &mut batches, network);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl<'a> SeraiCoins<'a> {
|
||||||
Payload::new(
|
Payload::new(
|
||||||
PALLET,
|
PALLET,
|
||||||
"transfer",
|
"transfer",
|
||||||
scale_composite(serai_runtime::coins::Call::<Runtime>::transfer { to, balance }),
|
scale_composite(serai_runtime::coins::Call::<Runtime>::transfer { to: to.into(), balance }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,10 @@ serai_test!(
|
||||||
}
|
}
|
||||||
|
|
||||||
let serai = serai.coins();
|
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_supply(coin).await.unwrap(), amount);
|
||||||
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), amount);
|
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), amount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ serai_test!(
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serai.coins().mint_events().await.unwrap(),
|
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_supply(coin).await.unwrap(), amount);
|
||||||
assert_eq!(serai.coins().coin_balance(coin, address).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 serai = serai.as_of(block).coins();
|
||||||
let events = serai.burn_events().await.unwrap();
|
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_supply(coin).await.unwrap(), Amount(0));
|
||||||
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), Amount(0));
|
assert_eq!(serai.coin_balance(coin, address).await.unwrap(), Amount(0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,12 @@ pub mod pallet {
|
||||||
#[pallet::genesis_config]
|
#[pallet::genesis_config]
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
|
#[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)]
|
||||||
pub struct GenesisConfig<T: Config> {
|
pub struct GenesisConfig<T: Config> {
|
||||||
_config: PhantomData<T>,
|
pub accounts: Vec<(T::AccountId, Balance)>,
|
||||||
pub accounts: Vec<(Public, Balance)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Config> Default for GenesisConfig<T> {
|
impl<T: Config> Default for GenesisConfig<T> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
GenesisConfig { _config: PhantomData, accounts: Default::default() }
|
GenesisConfig { accounts: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +59,15 @@ pub mod pallet {
|
||||||
// ID.
|
// ID.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn balances)]
|
#[pallet::getter(fn balances)]
|
||||||
pub type Balances<T: Config> =
|
pub type Balances<T: Config> = StorageDoubleMap<
|
||||||
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.
|
||||||
|
@ -152,7 +158,10 @@ pub mod pallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Burn `balance` from the specified account.
|
// 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
|
// don't waste time if amount == 0
|
||||||
if balance.amount.0 == 0 {
|
if balance.amount.0 == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -162,13 +171,18 @@ 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).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);
|
Supply::<T>::set(balance.coin, new_supply);
|
||||||
|
|
||||||
Ok(())
|
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::burn_internal(from, Balance { coin: Coin::Serai, amount })?;
|
||||||
Self::deposit_event(Event::SriBurn { from, amount });
|
Self::deposit_event(Event::SriBurn { from, amount });
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -187,7 +201,11 @@ pub mod pallet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transfer `balance` from `from` to `to`.
|
/// 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
|
// 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)?;
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub mod pallet {
|
||||||
fn execute(instruction: InInstructionWithBalance) -> Result<(), ()> {
|
fn execute(instruction: InInstructionWithBalance) -> Result<(), ()> {
|
||||||
match instruction.instruction {
|
match instruction.instruction {
|
||||||
InInstruction::Transfer(address) => {
|
InInstruction::Transfer(address) => {
|
||||||
Coins::<T>::mint(&address.into(), instruction.balance).map_err(|_| ())
|
Coins::<T>::mint(address.into(), instruction.balance).map_err(|_| ())
|
||||||
}
|
}
|
||||||
_ => panic!("unsupported instruction"),
|
_ => panic!("unsupported instruction"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ pub mod pallet {
|
||||||
pub fn stake(origin: OriginFor<T>, #[pallet::compact] amount: u64) -> DispatchResult {
|
pub fn stake(origin: OriginFor<T>, #[pallet::compact] amount: u64) -> DispatchResult {
|
||||||
let signer = ensure_signed(origin)?;
|
let signer = ensure_signed(origin)?;
|
||||||
let balance = Balance { coin: Coin::Serai, amount: Amount(amount) };
|
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);
|
Self::add_stake(&signer, amount);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ pub mod pallet {
|
||||||
let signer = ensure_signed(origin)?;
|
let signer = ensure_signed(origin)?;
|
||||||
Self::remove_stake(&signer, amount)?;
|
Self::remove_stake(&signer, amount)?;
|
||||||
let balance = Balance { coin: Coin::Serai, amount: Amount(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue