Skip to content
Snippets Groups Projects
Unverified Commit 109287f4 authored by Gavin Wood's avatar Gavin Wood Committed by GitHub
Browse files

Put `GetWeight` where it belongs (#1212)


* Put `GetWeight` where it belongs

* add GetWeight to v2

* Re-export unchanged trait

---------

Co-authored-by: default avatarJust van Stam <just.van.stam@gmail.com>
Co-authored-by: default avatarKeith Yeung <kungfukeith11@gmail.com>
parent 36b4f258
No related merge requests found
Pipeline #385717 failed with stages
in 52 minutes and 23 seconds
...@@ -447,11 +447,6 @@ pub mod opaque { ...@@ -447,11 +447,6 @@ pub mod opaque {
pub type VersionedXcm = super::VersionedXcm<()>; pub type VersionedXcm = super::VersionedXcm<()>;
} }
// A simple trait to get the weight of some object.
pub trait GetWeight<W> {
fn weight(&self) -> latest::Weight;
}
#[test] #[test]
fn conversion_works() { fn conversion_works() {
use latest::prelude::*; use latest::prelude::*;
......
...@@ -55,7 +55,7 @@ use super::{ ...@@ -55,7 +55,7 @@ use super::{
NetworkId as NewNetworkId, Response as NewResponse, WeightLimit as NewWeightLimit, NetworkId as NewNetworkId, Response as NewResponse, WeightLimit as NewWeightLimit,
Xcm as NewXcm, Xcm as NewXcm,
}, },
DoubleEncoded, GetWeight, DoubleEncoded,
}; };
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use bounded_collections::{ConstU32, WeakBoundedVec}; use bounded_collections::{ConstU32, WeakBoundedVec};
...@@ -77,7 +77,7 @@ pub use multiasset::{ ...@@ -77,7 +77,7 @@ pub use multiasset::{
pub use multilocation::{ pub use multilocation::{
Ancestor, AncestorThen, InteriorMultiLocation, Junctions, MultiLocation, Parent, ParentThen, Ancestor, AncestorThen, InteriorMultiLocation, Junctions, MultiLocation, Parent, ParentThen,
}; };
pub use traits::{Error, ExecuteXcm, Outcome, Result, SendError, SendResult, SendXcm}; pub use traits::{Error, ExecuteXcm, GetWeight, Outcome, Result, SendError, SendResult, SendXcm};
/// Basically just the XCM (more general) version of `ParachainDispatchOrigin`. /// Basically just the XCM (more general) version of `ParachainDispatchOrigin`.
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)] #[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
......
...@@ -23,6 +23,11 @@ use scale_info::TypeInfo; ...@@ -23,6 +23,11 @@ use scale_info::TypeInfo;
use super::*; use super::*;
// A simple trait to get the weight of some object.
pub trait GetWeight<W> {
fn weight(&self) -> sp_weights::Weight;
}
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
pub enum Error { pub enum Error {
// Errors that happen due to instructions being executed. These alone are defined in the // Errors that happen due to instructions being executed. These alone are defined in the
......
...@@ -20,7 +20,7 @@ use super::v2::{ ...@@ -20,7 +20,7 @@ use super::v2::{
Instruction as OldInstruction, Response as OldResponse, WeightLimit as OldWeightLimit, Instruction as OldInstruction, Response as OldResponse, WeightLimit as OldWeightLimit,
Xcm as OldXcm, Xcm as OldXcm,
}; };
use crate::{DoubleEncoded, GetWeight}; use crate::DoubleEncoded;
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use bounded_collections::{parameter_types, BoundedVec, ConstU32}; use bounded_collections::{parameter_types, BoundedVec, ConstU32};
use core::{ use core::{
...@@ -54,7 +54,7 @@ pub use traits::{ ...@@ -54,7 +54,7 @@ pub use traits::{
SendResult, SendXcm, Weight, XcmHash, SendResult, SendXcm, Weight, XcmHash,
}; };
// These parts of XCM v2 are unchanged in XCM v3, and are re-imported here. // These parts of XCM v2 are unchanged in XCM v3, and are re-imported here.
pub use super::v2::OriginKind; pub use super::v2::{GetWeight, OriginKind};
/// This module's XCM version. /// This module's XCM version.
pub const VERSION: super::Version = 3; pub const VERSION: super::Version = 3;
...@@ -186,6 +186,7 @@ pub mod prelude { ...@@ -186,6 +186,7 @@ pub mod prelude {
AssetInstance::{self, *}, AssetInstance::{self, *},
BodyId, BodyPart, Error as XcmError, ExecuteXcm, BodyId, BodyPart, Error as XcmError, ExecuteXcm,
Fungibility::{self, *}, Fungibility::{self, *},
GetWeight,
Instruction::*, Instruction::*,
InteriorMultiLocation, InteriorMultiLocation,
Junction::{self, *}, Junction::{self, *},
......
...@@ -73,7 +73,7 @@ where ...@@ -73,7 +73,7 @@ where
W: XcmWeightInfo<C>, W: XcmWeightInfo<C>,
C: Decode + GetDispatchInfo, C: Decode + GetDispatchInfo,
M: Get<u32>, M: Get<u32>,
Instruction<C>: xcm::GetWeight<W>, Instruction<C>: xcm::latest::GetWeight<W>,
{ {
fn weight(message: &mut Xcm<C>) -> Result<Weight, ()> { fn weight(message: &mut Xcm<C>) -> Result<Weight, ()> {
log::trace!(target: "xcm::weight", "WeightInfoBounds message: {:?}", message); log::trace!(target: "xcm::weight", "WeightInfoBounds message: {:?}", message);
...@@ -90,7 +90,7 @@ where ...@@ -90,7 +90,7 @@ where
W: XcmWeightInfo<C>, W: XcmWeightInfo<C>,
C: Decode + GetDispatchInfo, C: Decode + GetDispatchInfo,
M: Get<u32>, M: Get<u32>,
Instruction<C>: xcm::GetWeight<W>, Instruction<C>: xcm::latest::GetWeight<W>,
{ {
fn weight_with_limit(message: &Xcm<C>, instrs_limit: &mut u32) -> Result<Weight, ()> { fn weight_with_limit(message: &Xcm<C>, instrs_limit: &mut u32) -> Result<Weight, ()> {
let mut r: Weight = Weight::zero(); let mut r: Weight = Weight::zero();
...@@ -104,7 +104,6 @@ where ...@@ -104,7 +104,6 @@ where
instruction: &Instruction<C>, instruction: &Instruction<C>,
instrs_limit: &mut u32, instrs_limit: &mut u32,
) -> Result<Weight, ()> { ) -> Result<Weight, ()> {
use xcm::GetWeight;
let instr_weight = match instruction { let instr_weight = match instruction {
Transact { require_weight_at_most, .. } => *require_weight_at_most, Transact { require_weight_at_most, .. } => *require_weight_at_most,
SetErrorHandler(xcm) | SetAppendix(xcm) => Self::weight_with_limit(xcm, instrs_limit)?, SetErrorHandler(xcm) | SetAppendix(xcm) => Self::weight_with_limit(xcm, instrs_limit)?,
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment