From 7f639e1f35aa5f9de61ccc5cd7c93795998a5f25 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 16 May 2022 18:57:33 -0400 Subject: [PATCH 1/2] remove duplicate traits --- .../bin/rialto-parachain/node/src/command.rs | 3 +- parachain/src/primitives.rs | 53 ------------------- xcm/pallet-xcm/src/tests.rs | 4 +- 3 files changed, 3 insertions(+), 57 deletions(-) diff --git a/bridges/bin/rialto-parachain/node/src/command.rs b/bridges/bin/rialto-parachain/node/src/command.rs index c47e742675da..99ff6d2af9ed 100644 --- a/bridges/bin/rialto-parachain/node/src/command.rs +++ b/bridges/bin/rialto-parachain/node/src/command.rs @@ -23,7 +23,6 @@ use codec::Encode; use cumulus_client_service::genesis::generate_genesis_block; use cumulus_primitives_core::ParaId; use log::info; -use polkadot_parachain::primitives::AccountIdConversion; use rialto_parachain_runtime::{Block, RuntimeApi}; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, @@ -31,7 +30,7 @@ use sc_cli::{ }; use sc_service::config::{BasePath, PrometheusConfig}; use sp_core::hexdisplay::HexDisplay; -use sp_runtime::traits::Block as BlockT; +use sp_runtime::traits::{Block as BlockT, AccountIdConversion}; use std::{io::Write, net::SocketAddr}; fn load_spec( diff --git a/parachain/src/primitives.rs b/parachain/src/primitives.rs index 54c67cdf1a05..e5baaba2430e 100644 --- a/parachain/src/primitives.rs +++ b/parachain/src/primitives.rs @@ -274,59 +274,6 @@ impl IsSystem for Sibling { } } -/// This type can be converted into and possibly from an [`AccountId`] (which itself is generic). -pub trait AccountIdConversion: Sized { - /// Convert into an account ID. This is infallible. - fn into_account(&self) -> AccountId; - - /// Try to convert an account ID into this type. Might not succeed. - fn try_from_account(a: &AccountId) -> Option; -} - -// TODO: Remove all of this, move sp-runtime::AccountIdConversion to own crate and and use that. -// #360 -struct TrailingZeroInput<'a>(&'a [u8]); -impl<'a> parity_scale_codec::Input for TrailingZeroInput<'a> { - fn remaining_len(&mut self) -> Result, parity_scale_codec::Error> { - Ok(None) - } - - fn read(&mut self, into: &mut [u8]) -> Result<(), parity_scale_codec::Error> { - let len = into.len().min(self.0.len()); - into[..len].copy_from_slice(&self.0[..len]); - for i in &mut into[len..] { - *i = 0; - } - self.0 = &self.0[len..]; - Ok(()) - } -} - -/// Format is b"para" ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing -/// zeroes to fill [`AccountId`]. -impl AccountIdConversion for Id { - fn into_account(&self) -> T { - (b"para", self) - .using_encoded(|b| T::decode(&mut TrailingZeroInput(b))) - .expect("infinite length input; no invalid inputs for type; qed") - } - - fn try_from_account(x: &T) -> Option { - x.using_encoded(|d| { - if &d[0..4] != b"para" { - return None - } - let mut cursor = &d[4..]; - let result = Decode::decode(&mut cursor).ok()?; - if cursor.iter().all(|x| *x == 0) { - Some(result) - } else { - None - } - }) - } -} - /// A type that uniquely identifies an HRMP channel. An HRMP channel is established between two paras. /// In text, we use the notation `(A, B)` to specify a channel between A and B. The channels are /// unidirectional, meaning that `(A, B)` and `(B, A)` refer to different channels. The convention is diff --git a/xcm/pallet-xcm/src/tests.rs b/xcm/pallet-xcm/src/tests.rs index b61f61e436bd..74e33c4b5072 100644 --- a/xcm/pallet-xcm/src/tests.rs +++ b/xcm/pallet-xcm/src/tests.rs @@ -22,8 +22,8 @@ use frame_support::{ assert_noop, assert_ok, traits::{Currency, Hooks}, }; -use polkadot_parachain::primitives::{AccountIdConversion, Id as ParaId}; -use sp_runtime::traits::{BlakeTwo256, Hash}; +use polkadot_parachain::primitives::Id as ParaId; +use sp_runtime::traits::{BlakeTwo256, Hash, AccountIdConversion}; use xcm::prelude::*; use xcm_builder::AllowKnownQueryResponses; use xcm_executor::{traits::ShouldExecute, XcmExecutor}; From 55bdbde9b91d31f15b25ebe31465f0b5c75e9d0a Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 16 May 2022 19:00:03 -0400 Subject: [PATCH 2/2] fmt --- xcm/pallet-xcm/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcm/pallet-xcm/src/tests.rs b/xcm/pallet-xcm/src/tests.rs index 74e33c4b5072..44ef45efef53 100644 --- a/xcm/pallet-xcm/src/tests.rs +++ b/xcm/pallet-xcm/src/tests.rs @@ -23,7 +23,7 @@ use frame_support::{ traits::{Currency, Hooks}, }; use polkadot_parachain::primitives::Id as ParaId; -use sp_runtime::traits::{BlakeTwo256, Hash, AccountIdConversion}; +use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, Hash}; use xcm::prelude::*; use xcm_builder::AllowKnownQueryResponses; use xcm_executor::{traits::ShouldExecute, XcmExecutor};