Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy fixes #794

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pallets/dex-api/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = 'https://github.com/sora-xor/sora2-network'
[dependencies]
serde = { version = "1.0.101", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3" }
jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }
jsonrpsee = { version = "0.16.2", features = ["server", "client", "macros"] }
sp-api = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
sp-blockchain = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
sp-core = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38", default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions pallets/dex-api/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// TODO #167: fix clippy warnings
#![allow(clippy::all)]
#![allow(clippy::too_many_arguments)]

use codec::Codec;
use common::BalanceWrapper;
Expand Down
12 changes: 5 additions & 7 deletions pallets/dex-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#![cfg_attr(not(feature = "std"), no_std)]
// TODO #167: fix clippy warnings
#![allow(clippy::all)]

use assets::AssetIdOf;
use common::prelude::EnsureDEXManager;
Expand Down Expand Up @@ -63,10 +61,10 @@ impl<T: Config> EnsureDEXManager<T::DEXId, T::AccountId, DispatchError> for Pall
{
match origin.into() {
Ok(RawOrigin::Signed(who)) => {
let dex_info = Self::get_dex_info(&dex_id)?;
let dex_info = Self::get_dex_info(dex_id)?;
// If DEX is public, anyone can manage it, otherwise confirm ownership.
if !dex_info.is_public || mode != ManagementMode::Public {
Self::ensure_direct_manager(&dex_id, &who)?;
Self::ensure_direct_manager(dex_id, &who)?;
}
Ok(Some(who))
}
Expand All @@ -77,12 +75,12 @@ impl<T: Config> EnsureDEXManager<T::DEXId, T::AccountId, DispatchError> for Pall

impl<T: Config> DexInfoProvider<T::DEXId, DEXInfo<T>> for Pallet<T> {
fn get_dex_info(dex_id: &T::DEXId) -> Result<DEXInfo<T>, DispatchError> {
Ok(DEXInfos::<T>::get(&dex_id).ok_or(Error::<T>::DEXDoesNotExist)?)
Ok(DEXInfos::<T>::get(dex_id).ok_or(Error::<T>::DEXDoesNotExist)?)
}

fn ensure_dex_exists(dex_id: &T::DEXId) -> DispatchResult {
ensure!(
DEXInfos::<T>::contains_key(&dex_id),
DEXInfos::<T>::contains_key(dex_id),
Error::<T>::DEXDoesNotExist
);
Ok(())
Expand Down Expand Up @@ -161,7 +159,7 @@ pub mod pallet {
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
self.dex_list.iter().for_each(|(dex_id, dex_info)| {
DEXInfos::<T>::insert(dex_id.clone(), dex_info);
DEXInfos::<T>::insert(*dex_id, dex_info);
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/dex-manager/src/migrations/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn test() {
super::migrate::<Runtime>();

for dex_info in DEXInfos::<Runtime>::iter_values() {
assert_eq!(dex_info.synthetic_base_asset_id, XST.into());
assert_eq!(dex_info.synthetic_base_asset_id, XST);
}
assert_eq!(Pallet::<Runtime>::on_chain_storage_version(), 2);
});
Expand Down
6 changes: 3 additions & 3 deletions pallets/dex-manager/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use currencies::BasicCurrencyAdapter;
use frame_support::traits::{Everything, GenesisBuild};
use frame_support::weights::Weight;
use frame_support::{construct_runtime, parameter_types};
use frame_system;

use permissions::Scope;
use sp_core::H256;
use sp_runtime::testing::Header;
Expand Down Expand Up @@ -195,8 +195,8 @@ impl Default for ExtBuilder {
Self {
initial_dex_list: Vec::new(),
endowed_accounts: vec![
(ALICE, XOR, 1_000_000_000_000_000_000u128.into()),
(BOB, DOT, 1_000_000_000_000_000_000u128.into()),
(ALICE, XOR, 1_000_000_000_000_000_000u128),
(BOB, DOT, 1_000_000_000_000_000_000u128),
],
initial_permission_owners: Vec::new(),
initial_permissions: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/eth-bridge/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "0.1.0"
[dependencies]
serde = { version = "1.0.101", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3" }
jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }
jsonrpsee = { version = "0.16.2", features = ["server", "macros", "client"] }
sp-runtime = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
sp-api = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
sp-blockchain = { git = "https://github.com/sora-xor/substrate.git", branch = "polkadot-v0.9.38" }
Expand Down
3 changes: 1 addition & 2 deletions pallets/eth-bridge/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// TODO #167: fix clippy warnings
#![allow(clippy::all)]
#![allow(clippy::type_complexity)]

use codec::Codec;
pub use eth_bridge_runtime_api::EthBridgeRuntimeApi;
Expand Down
3 changes: 1 addition & 2 deletions pallets/eth-bridge/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#![cfg_attr(not(feature = "std"), no_std)]
// TODO #167: fix clippy warnings
#![allow(clippy::all)]

use codec::Codec;
use sp_runtime::DispatchError;
Expand Down Expand Up @@ -66,6 +64,7 @@ sp_api::decl_runtime_apis! {
fn get_approved_requests(hashes: Vec<Hash>, network_id: Option<NetworkId>) -> Result<Vec<(OutgoingRequestEncoded, Vec<Approval>)>, DispatchError>;
fn get_approvals(hashes: Vec<Hash>, network_id: Option<NetworkId>) -> Result<Vec<Vec<Approval>>, DispatchError>;
fn get_account_requests(account_id: AccountId, status_filter: Option<RequestStatus>) -> Result<Vec<(NetworkId, Hash)>, DispatchError>;
#[allow(clippy::type_complexity)]
fn get_registered_assets(network_id: Option<NetworkId>) -> Result<Vec<(AssetKind, (AssetId, BalancePrecision), Option<(EthAddress, BalancePrecision)>)>, DispatchError>;
}
}
30 changes: 15 additions & 15 deletions pallets/eth-bridge/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ benchmarks! {
let caller = alice::<T>();
let asset_id: T::AssetId = XOR.into();
let net_id = 0u32.into();
let bridge_acc_id = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let bridge_acc_id = crate::BridgeAccount::<T>::get(net_id).unwrap();
Assets::<T>::mint_to(&asset_id, &bridge_acc_id, &caller, balance!(100)).unwrap();
let initial_base_balance = Assets::<T>::free_balance(&asset_id, &caller).unwrap();
}: transfer_to_sidechain(
Expand All @@ -85,7 +85,7 @@ benchmarks! {
let caller = alice::<T>();
let asset_id: T::AssetId = XOR.into();
let net_id = 0u32.into();
let bridge_acc_id = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let bridge_acc_id = crate::BridgeAccount::<T>::get(net_id).unwrap();
Assets::<T>::mint_to(&asset_id, &bridge_acc_id, &caller, balance!(100)).unwrap();
let initial_base_balance = Assets::<T>::free_balance(&asset_id, &caller).unwrap();
let req_hash = H256([1u8; 32]);
Expand All @@ -101,7 +101,7 @@ benchmarks! {

register_incoming_request {
let net_id = 0u32.into();
let caller = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let caller = crate::BridgeAccount::<T>::get(net_id).unwrap();
let asset_id: T::AssetId = XOR.into();
let alice = alice::<T>();
let inc_req = IncomingRequest::Transfer(IncomingTransfer::<T> {
Expand All @@ -110,7 +110,7 @@ benchmarks! {
asset_id,
asset_kind: AssetKind::SidechainOwned,
amount: 1u32.into(),
author: alice.clone(),
author: alice,
tx_hash: H256([1u8; 32]),
at_height: 0,
timepoint: Default::default(),
Expand All @@ -128,7 +128,7 @@ benchmarks! {

finalize_incoming_request {
let net_id = 0u32.into();
let caller = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let caller = crate::BridgeAccount::<T>::get(net_id).unwrap();
let asset_id: T::AssetId = XOR.into();
let req_hash = H256([1u8; 32]);
let alice = alice::<T>();
Expand All @@ -138,7 +138,7 @@ benchmarks! {
asset_id,
asset_kind: AssetKind::SidechainOwned,
amount: 1u32.into(),
author: alice.clone(),
author: alice,
tx_hash: req_hash,
at_height: 0,
timepoint: Default::default(),
Expand All @@ -161,13 +161,13 @@ benchmarks! {

approve_request {
let net_id = 0u32.into();
let caller = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let caller = crate::BridgeAccount::<T>::get(net_id).unwrap();
let asset_id: T::AssetId = XOR.into();
let alice = alice::<T>();
Assets::<T>::mint_to(&asset_id, &caller, &caller, balance!(100)).unwrap();
let initial_base_balance = Assets::<T>::free_balance(&asset_id, &caller).unwrap();
frame_support::assert_ok!(crate::Pallet::<T>::transfer_to_sidechain(
RawOrigin::Signed(caller.clone()).into(),
RawOrigin::Signed(caller).into(),
asset_id,
EthAddress::from(hex!("19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A")),
balance!(100),
Expand All @@ -180,7 +180,7 @@ benchmarks! {
let public = secp256k1::PublicKey::from_secret_key(&sk);
let address = public_key_to_eth_address(&public);
let public = ecdsa::Public(public.serialize_compressed());
let account_id = T::AccountId::decode(&mut &MultiSigner::Ecdsa(public.clone()).into_account().encode()[..]).unwrap();
let account_id = T::AccountId::decode(&mut &MultiSigner::Ecdsa(public).into_account().encode()[..]).unwrap();
Pallet::<T>::force_add_peer(RawOrigin::Root.into(), account_id.clone(), address, net_id).unwrap();
let (signature, _) = Pallet::<T>::sign_message(encoded_request.as_raw(), &sk);
}: approve_request(
Expand All @@ -191,18 +191,18 @@ benchmarks! {
net_id
)
verify {
assert_eq!(RequestApprovals::<T>::get(net_id, &req_hash).len(), 1);
assert_eq!(RequestApprovals::<T>::get(net_id, req_hash).len(), 1);
}

approve_request_finalize {
let net_id = 0u32.into();
let caller = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let caller = crate::BridgeAccount::<T>::get(net_id).unwrap();
let asset_id: T::AssetId = XOR.into();
let alice = alice::<T>();
Assets::<T>::mint_to(&asset_id, &caller, &caller, balance!(100)).unwrap();
let initial_base_balance = Assets::<T>::free_balance(&asset_id, &caller).unwrap();
frame_support::assert_ok!(crate::Pallet::<T>::transfer_to_sidechain(
RawOrigin::Signed(caller.clone()).into(),
RawOrigin::Signed(caller).into(),
asset_id,
EthAddress::from(hex!("19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A")),
balance!(100),
Expand All @@ -215,10 +215,10 @@ benchmarks! {
let public = secp256k1::PublicKey::from_secret_key(&sk);
let address = public_key_to_eth_address(&public);
let public = ecdsa::Public(public.serialize_compressed());
let account_id = T::AccountId::decode(&mut &MultiSigner::Ecdsa(public.clone()).into_account().encode()[..]).unwrap();
let account_id = T::AccountId::decode(&mut &MultiSigner::Ecdsa(public).into_account().encode()[..]).unwrap();
Pallet::<T>::force_add_peer(RawOrigin::Root.into(), account_id.clone(), address, net_id).unwrap();
let (signature, _) = Pallet::<T>::sign_message(encoded_request.as_raw(), &sk);
RequestApprovals::<T>::mutate(net_id, &req_hash, |v| {
RequestApprovals::<T>::mutate(net_id, req_hash, |v| {
for i in 0..majority(crate::Peers::<T>::get(net_id).len()) - 1 {
v.insert(SignatureParams {
v: i as u8,
Expand All @@ -239,7 +239,7 @@ benchmarks! {

abort_request {
let net_id = 0u32.into();
let caller = crate::BridgeAccount::<T>::get(&net_id).unwrap();
let caller = crate::BridgeAccount::<T>::get(net_id).unwrap();
let asset_id: T::AssetId = XOR.into();
let alice = alice::<T>();
Assets::<T>::mint_to(&asset_id, &caller, &caller, balance!(100)).unwrap();
Expand Down
Loading