Skip to content

Add MaxEncodedLen bound to Currency traits #687

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

Merged
merged 3 commits into from
Feb 2, 2022
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
3 changes: 2 additions & 1 deletion currencies/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ where
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ Default,
+ Default
+ codec::MaxEncodedLen,
Currency: PalletCurrency<AccountId>,
T: Config,
{
Expand Down
5 changes: 3 additions & 2 deletions tokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ pub mod module {
+ arithmetic::SimpleArithmetic
+ Default
+ Copy
+ MaybeSerializeDeserialize;
+ MaybeSerializeDeserialize
+ MaxEncodedLen;

/// The currency ID type
type CurrencyId: Parameter + Member + Copy + MaybeSerializeDeserialize + Ord + TypeInfo;
type CurrencyId: Parameter + Member + Copy + MaybeSerializeDeserialize + Ord + TypeInfo + MaxEncodedLen;

/// Weight information for extrinsics in this module.
type WeightInfo: WeightInfo;
Expand Down
22 changes: 16 additions & 6 deletions traits/src/currency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::arithmetic;
use codec::{Codec, FullCodec};
use codec::{Codec, FullCodec, MaxEncodedLen};
pub use frame_support::{
traits::{BalanceStatus, LockIdentifier},
transactional,
Expand All @@ -17,7 +17,14 @@ use sp_std::{
/// Abstraction over a fungible multi-currency system.
pub trait MultiCurrency<AccountId> {
/// The currency identifier.
type CurrencyId: FullCodec + Eq + PartialEq + Copy + MaybeSerializeDeserialize + Debug + scale_info::TypeInfo;
type CurrencyId: FullCodec
+ Eq
+ PartialEq
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ scale_info::TypeInfo
+ MaxEncodedLen;

/// The balance of an account.
type Balance: AtLeast32BitUnsigned
Expand All @@ -26,7 +33,8 @@ pub trait MultiCurrency<AccountId> {
+ MaybeSerializeDeserialize
+ Debug
+ Default
+ scale_info::TypeInfo;
+ scale_info::TypeInfo
+ MaxEncodedLen;

// Public immutables

Expand Down Expand Up @@ -88,7 +96,8 @@ pub trait MultiCurrencyExtended<AccountId>: MultiCurrency<AccountId> {
+ MaybeSerializeDeserialize
+ Debug
+ Default
+ scale_info::TypeInfo;
+ scale_info::TypeInfo
+ MaxEncodedLen;

/// Add or remove abs(`by_amount`) from the balance of `who` under
/// `currency_id`. If positive `by_amount`, do add, else do remove.
Expand Down Expand Up @@ -195,7 +204,7 @@ pub trait MultiReservableCurrency<AccountId>: MultiCurrency<AccountId> {
/// Abstraction over a fungible (single) currency system.
pub trait BasicCurrency<AccountId> {
/// The balance of an account.
type Balance: AtLeast32BitUnsigned + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default;
type Balance: AtLeast32BitUnsigned + FullCodec + Copy + MaybeSerializeDeserialize + Debug + Default + MaxEncodedLen;

// Public immutables

Expand Down Expand Up @@ -249,7 +258,8 @@ pub trait BasicCurrencyExtended<AccountId>: BasicCurrency<AccountId> {
+ Copy
+ MaybeSerializeDeserialize
+ Debug
+ Default;
+ Default
+ MaxEncodedLen;

/// Add or remove abs(`by_amount`) from the balance of `who`. If positive
/// `by_amount`, do add, else do remove.
Expand Down
2 changes: 1 addition & 1 deletion xtokens/src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod relay;
pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]);
pub const BOB: AccountId32 = AccountId32::new([1u8; 32]);

#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, TypeInfo)]
#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, codec::MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum CurrencyId {
/// Relay chain token.
Expand Down