From a1b2bdf0a2510571bb74d0fd65238b8fda138f4f Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 19 Oct 2023 06:30:58 -0400 Subject: [PATCH] clippy fixes --- coordinator/src/substrate/mod.rs | 2 +- substrate/client/src/serai/coins.rs | 2 +- substrate/client/tests/batch.rs | 5 ++- substrate/client/tests/burn.rs | 4 +-- substrate/coins/pallet/src/lib.rs | 36 +++++++++++++++------ substrate/in-instructions/pallet/src/lib.rs | 2 +- substrate/staking/pallet/src/lib.rs | 4 +-- 7 files changed, 38 insertions(+), 17 deletions(-) diff --git a/coordinator/src/substrate/mod.rs b/coordinator/src/substrate/mod.rs index 20345c61..4aa495c2 100644 --- a/coordinator/src/substrate/mod.rs +++ b/coordinator/src/substrate/mod.rs @@ -209,7 +209,7 @@ async fn handle_batch_and_burns( } 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); diff --git a/substrate/client/src/serai/coins.rs b/substrate/client/src/serai/coins.rs index 2ab1d945..b197aedd 100644 --- a/substrate/client/src/serai/coins.rs +++ b/substrate/client/src/serai/coins.rs @@ -60,7 +60,7 @@ impl<'a> SeraiCoins<'a> { Payload::new( PALLET, "transfer", - scale_composite(serai_runtime::coins::Call::::transfer { to, balance }), + scale_composite(serai_runtime::coins::Call::::transfer { to: to.into(), balance }), ) } diff --git a/substrate/client/tests/batch.rs b/substrate/client/tests/batch.rs index e90f6855..b15fbe42 100644 --- a/substrate/client/tests/batch.rs +++ b/substrate/client/tests/batch.rs @@ -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); } diff --git a/substrate/client/tests/burn.rs b/substrate/client/tests/burn.rs index 2e1800ba..6bbbb6ef 100644 --- a/substrate/client/tests/burn.rs +++ b/substrate/client/tests/burn.rs @@ -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)); } diff --git a/substrate/coins/pallet/src/lib.rs b/substrate/coins/pallet/src/lib.rs index 6e877893..d0db757b 100644 --- a/substrate/coins/pallet/src/lib.rs +++ b/substrate/coins/pallet/src/lib.rs @@ -26,13 +26,12 @@ pub mod pallet { #[pallet::genesis_config] #[derive(Clone, PartialEq, Eq, Debug, Encode, Decode)] pub struct GenesisConfig { - _config: PhantomData, - pub accounts: Vec<(Public, Balance)>, + pub accounts: Vec<(T::AccountId, Balance)>, } impl Default for GenesisConfig { 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 = - StorageDoubleMap<_, Blake2_128Concat, Public, Identity, Coin, SubstrateAmount, ValueQuery>; + pub type Balances = 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> { + fn burn_internal( + from: Public, + balance: Balance, + ) -> Result<(), Error> { // 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::::set(balance.coin, new_supply); Ok(()) } - pub fn burn_sri(from: Public, amount: Amount) -> Result<(), Error> { + pub fn burn_sri( + from: Public, + amount: Amount, + ) -> Result<(), Error> { 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> { + pub fn transfer_internal( + from: Public, + to: Public, + balance: Balance, + ) -> Result<(), Error> { // update balances of accounts Self::decrease_balance_internal(from, balance)?; Self::increase_balance_internal(to, balance)?; diff --git a/substrate/in-instructions/pallet/src/lib.rs b/substrate/in-instructions/pallet/src/lib.rs index acf2b4f3..5812ea24 100644 --- a/substrate/in-instructions/pallet/src/lib.rs +++ b/substrate/in-instructions/pallet/src/lib.rs @@ -74,7 +74,7 @@ pub mod pallet { fn execute(instruction: InInstructionWithBalance) -> Result<(), ()> { match instruction.instruction { InInstruction::Transfer(address) => { - Coins::::mint(&address.into(), instruction.balance).map_err(|_| ()) + Coins::::mint(address.into(), instruction.balance).map_err(|_| ()) } _ => panic!("unsupported instruction"), } diff --git a/substrate/staking/pallet/src/lib.rs b/substrate/staking/pallet/src/lib.rs index 4b01820f..ad6a4c41 100644 --- a/substrate/staking/pallet/src/lib.rs +++ b/substrate/staking/pallet/src/lib.rs @@ -97,7 +97,7 @@ pub mod pallet { pub fn stake(origin: OriginFor, #[pallet::compact] amount: u64) -> DispatchResult { let signer = ensure_signed(origin)?; let balance = Balance { coin: Coin::Serai, amount: Amount(amount) }; - Coins::::transfer_internal(&signer, &Self::account(), balance)?; + Coins::::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::::transfer_internal(&Self::account(), &signer, balance)?; + Coins::::transfer_internal(Self::account(), signer, balance)?; Ok(()) }