Skip to content
Merged
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
8 changes: 6 additions & 2 deletions polkadot/xcm/src/v3/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,13 @@ impl MaxEncodedLen for MultiAssets {

impl Decode for MultiAssets {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
let bounded_instructions =
let mut bounded_instructions =
BoundedVec::<MultiAsset, ConstU32<{ MAX_ITEMS_IN_MULTIASSETS as u32 }>>::decode(input)?;

bounded_instructions.sort();

Self::from_sorted_and_deduplicated(bounded_instructions.into_inner())
.map_err(|()| "Out of order".into())
.map_err(|()| "Duplicate items".into())
}
}

Expand Down Expand Up @@ -682,6 +685,7 @@ impl MultiAssets {
pub fn from_sorted_and_deduplicated_skip_checks(r: Vec<MultiAsset>) -> Self {
Self::from_sorted_and_deduplicated(r).expect("Invalid input r is not sorted/deduped")
}

/// Create a new instance of `MultiAssets` from a `Vec<MultiAsset>` whose contents are sorted
/// and which contain no duplicates.
///
Expand Down
7 changes: 5 additions & 2 deletions polkadot/xcm/src/v4/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,13 @@ impl MaxEncodedLen for Assets {

impl Decode for Assets {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
let bounded_instructions =
let mut bounded_instructions =
BoundedVec::<Asset, ConstU32<{ MAX_ITEMS_IN_ASSETS as u32 }>>::decode(input)?;

bounded_instructions.sort();

Self::from_sorted_and_deduplicated(bounded_instructions.into_inner())
.map_err(|()| "Out of order".into())
.map_err(|()| "Duplicate items".into())
}
}

Expand Down
7 changes: 5 additions & 2 deletions polkadot/xcm/src/v5/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,10 +562,13 @@ impl MaxEncodedLen for Assets {

impl Decode for Assets {
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
let bounded_instructions =
let mut bounded_instructions =
BoundedVec::<Asset, ConstU32<{ MAX_ITEMS_IN_ASSETS as u32 }>>::decode(input)?;

bounded_instructions.sort();

Self::from_sorted_and_deduplicated(bounded_instructions.into_inner())
.map_err(|()| "Out of order".into())
.map_err(|()| "Duplicate items".into())
}
}

Expand Down
8 changes: 8 additions & 0 deletions prdoc/pr_9842.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: 'xcm: Do not require `Asset` to be sorted on `decode`'
doc:
- audience: Runtime User
description: |-
`Asset` was requiring that all the assets are sorted at decoding. This is quite confusing for people writingg frontends, because this is not really documented anywhere. There are also only at max 20 assets available, we can just make everyones life easier and always sort the assets after decoding.
crates:
- name: staging-xcm
bump: patch
Loading