This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Simple MaxBoundedLen
Implementations
#8793
Merged
Merged
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
0de4775
implement max_values + storages info
gui1117 e7c14fb
Merge remote-tracking branch 'origin/master' into gui-max_values-macro
gui1117 42c4f48
some formatting + doc
gui1117 d1032a3
sudo sanity check
shawntabrizi f2582d5
timestamp
shawntabrizi bf354b0
assets (not working)
shawntabrizi 38cecd6
fix assets
shawntabrizi 06b872a
impl for proxy
shawntabrizi 43edcac
update balances
shawntabrizi 0ca09ee
Merge remote-tracking branch 'origin/master' into gui-max_values-macro
gui1117 ada719b
rename StoragesInfo -> PalletStorageInfo
gui1117 341d3f5
merge both StorageInfoTrait and PalletStorageInfo
gui1117 5521953
Update frame/support/procedural/src/storage/parse.rs
gui1117 02b0cbb
Update frame/support/procedural/src/storage/storage_struct.rs
gui1117 999640b
Fix max_size using hasher information
gui1117 a7909d7
fix tests
gui1117 e5964c0
fix ui tests
gui1117 2001d32
Move `MaxBoundedLen` into its own crate (#8814)
coriolinus 566425d
nits
shawntabrizi bb1d521
Merge branch 'master' into shawntabrizi-maxboundedlen-start
shawntabrizi 1a398cb
fix compile
shawntabrizi 3685d3c
line width
shawntabrizi 15918ff
Merge commit '8d02bb0bfc6136f6a3c805db19f51e43090a7cd4' into gui-max_…
gui1117 4fc7829
Merge remote-tracking branch 'origin/master' into gui-max_values-macro
gui1117 9c42372
Merge remote-tracking branch 'origin/gui-max_values-macro' into shawn…
gui1117 e8841f5
fix max-values-macro merge
gui1117 c12be40
Merge remote-tracking branch 'origin/master' into shawntabrizi-maxbou…
gui1117 1a3e03e
Add some derive, needed for test and other purpose
gui1117 9a45be6
Merge remote-tracking branch 'origin/master' into shawntabrizi-maxbou…
gui1117 5af7c4c
use weak bounded vec in some cases
gui1117 0e50fe0
Merge branch 'master' into shawntabrizi-maxboundedlen-start
shawntabrizi 7683f73
Update lib.rs
shawntabrizi 0c09750
move max-encoded-len crate
shawntabrizi d93b503
fix
shawntabrizi 73623e9
remove app crypto for now
shawntabrizi db766a8
Merge branch 'master' into shawntabrizi-maxboundedlen-start
shawntabrizi 1bb36fd
width
shawntabrizi f1e3ced
Revert "remove app crypto for now"
shawntabrizi 562f6b0
Merge branch 'master' into shawntabrizi-maxboundedlen-start
shawntabrizi 747e613
unused variable
shawntabrizi 7af3dcc
more unused variables
shawntabrizi 0dd6403
more fixes
shawntabrizi b7620ef
Add #[max_encoded_len_crate(...)] helper attribute
coriolinus 8a812bb
fix a ui test
coriolinus 04375ac
use #[max_encoded_len_crate(...)] helper in app_crypto
coriolinus d5f3ee6
remove max_encoded_len import where not necessary
coriolinus 8971223
Merge remote-tracking branch 'origin/master' into shawntabrizi-maxbou…
coriolinus 016cc16
update lockfile
coriolinus 478c742
Merge branch 'master' into shawntabrizi-maxboundedlen-start
shawntabrizi e2a16cb
fix ui test
shawntabrizi b71b2a7
ui
shawntabrizi 3acfa75
newline
shawntabrizi 62d6410
Merge branch 'master' into shawntabrizi-maxboundedlen-start
shawntabrizi cf92608
fix merge
shawntabrizi 2f739cd
try fix ui again
shawntabrizi 54839b7
Update max-encoded-len/derive/src/lib.rs
shawntabrizi 1fd92a4
extract generate_crate_access_2018
shawntabrizi f41c90a
Merge branch 'shawntabrizi-maxboundedlen-start' of https://github.com…
shawntabrizi f6d5db3
Update lib.rs
shawntabrizi c329b06
compiler isnt smart enough
shawntabrizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,14 +138,15 @@ mod functions; | |
mod types; | ||
pub use types::*; | ||
|
||
use sp_std::{prelude::*, borrow::Borrow}; | ||
use sp_std::{prelude::*, borrow::Borrow, convert::TryInto}; | ||
use sp_runtime::{ | ||
RuntimeDebug, TokenError, ArithmeticError, traits::{ | ||
TokenError, ArithmeticError, | ||
traits::{ | ||
AtLeast32BitUnsigned, Zero, StaticLookup, Saturating, CheckedSub, CheckedAdd, Bounded, | ||
StoredMapError, | ||
} | ||
}; | ||
use codec::{Encode, Decode, HasCompact}; | ||
use codec::HasCompact; | ||
use frame_support::{ensure, dispatch::{DispatchError, DispatchResult}}; | ||
use frame_support::traits::{Currency, ReservableCurrency, BalanceStatus::Reserved, StoredMap}; | ||
use frame_support::traits::tokens::{WithdrawConsequence, DepositConsequence, fungibles}; | ||
|
@@ -165,6 +166,7 @@ pub mod pallet { | |
|
||
#[pallet::pallet] | ||
#[pallet::generate_store(pub(super) trait Store)] | ||
#[pallet::generate_storage_info] | ||
pub struct Pallet<T, I = ()>(_); | ||
|
||
#[pallet::config] | ||
|
@@ -174,10 +176,10 @@ pub mod pallet { | |
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>; | ||
|
||
/// The units in which we record balances. | ||
type Balance: Member + Parameter + AtLeast32BitUnsigned + Default + Copy; | ||
type Balance: Member + Parameter + AtLeast32BitUnsigned + Default + Copy + MaxEncodedLen; | ||
|
||
/// Identifier for the class of asset. | ||
type AssetId: Member + Parameter + Default + Copy + HasCompact; | ||
type AssetId: Member + Parameter + Default + Copy + HasCompact + MaxEncodedLen; | ||
|
||
/// The currency mechanism. | ||
type Currency: ReservableCurrency<Self::AccountId>; | ||
|
@@ -207,7 +209,7 @@ pub mod pallet { | |
type Freezer: FrozenBalance<Self::AssetId, Self::AccountId, Self::Balance>; | ||
|
||
/// Additional data to be stored with an account's asset balance. | ||
type Extra: Member + Parameter + Default; | ||
type Extra: Member + Parameter + Default + MaxEncodedLen; | ||
|
||
/// Weight information for extrinsics in this pallet. | ||
type WeightInfo: WeightInfo; | ||
|
@@ -232,6 +234,8 @@ pub mod pallet { | |
T::AccountId, | ||
AssetBalance<T::Balance, T::Extra>, | ||
ValueQuery, | ||
GetDefault, | ||
ConstU32<300_000>, | ||
>; | ||
|
||
#[pallet::storage] | ||
|
@@ -247,6 +251,8 @@ pub mod pallet { | |
), | ||
Approval<T::Balance, DepositBalanceOf<T, I>>, | ||
OptionQuery, | ||
GetDefault, | ||
ConstU32<300_000>, | ||
>; | ||
|
||
#[pallet::storage] | ||
|
@@ -255,8 +261,10 @@ pub mod pallet { | |
_, | ||
Blake2_128Concat, | ||
T::AssetId, | ||
AssetMetadata<DepositBalanceOf<T, I>>, | ||
AssetMetadata<DepositBalanceOf<T, I>, BoundedVec<u8, T::StringLimit>>, | ||
ValueQuery, | ||
GetDefault, | ||
ConstU32<300_000>, | ||
>; | ||
|
||
#[pallet::event] | ||
|
@@ -899,8 +907,14 @@ pub mod pallet { | |
) -> DispatchResult { | ||
let origin = ensure_signed(origin)?; | ||
|
||
ensure!(name.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata); | ||
ensure!(symbol.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata); | ||
let bounded_name: BoundedVec<u8, T::StringLimit> = name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. due to the usage of bounded vec here we should make sure that the limit is not exceeded before migration. If these consideration are too strong, we should move to WeakBoundedVec. Also we could use BoundedVec for the call argument directly instead of Vec + conversion here. But I think this can be done later, as UI needs to handle the new type. |
||
.clone() | ||
.try_into() | ||
.map_err(|_| Error::<T, I>::BadMetadata)?; | ||
let bounded_symbol: BoundedVec<u8, T::StringLimit> = symbol | ||
.clone() | ||
.try_into() | ||
.map_err(|_| Error::<T, I>::BadMetadata)?; | ||
|
||
let d = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?; | ||
ensure!(&origin == &d.owner, Error::<T, I>::NoPermission); | ||
|
@@ -924,8 +938,8 @@ pub mod pallet { | |
|
||
*metadata = Some(AssetMetadata { | ||
deposit: new_deposit, | ||
name: name.clone(), | ||
symbol: symbol.clone(), | ||
name: bounded_name, | ||
symbol: bounded_symbol, | ||
decimals, | ||
is_frozen: false, | ||
}); | ||
|
@@ -989,16 +1003,23 @@ pub mod pallet { | |
) -> DispatchResult { | ||
T::ForceOrigin::ensure_origin(origin)?; | ||
|
||
ensure!(name.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata); | ||
ensure!(symbol.len() <= T::StringLimit::get() as usize, Error::<T, I>::BadMetadata); | ||
let bounded_name: BoundedVec<u8, T::StringLimit> = name | ||
.clone() | ||
.try_into() | ||
.map_err(|_| Error::<T, I>::BadMetadata)?; | ||
|
||
let bounded_symbol: BoundedVec<u8, T::StringLimit> = symbol | ||
.clone() | ||
.try_into() | ||
.map_err(|_| Error::<T, I>::BadMetadata)?; | ||
|
||
ensure!(Asset::<T, I>::contains_key(id), Error::<T, I>::Unknown); | ||
Metadata::<T, I>::try_mutate_exists(id, |metadata| { | ||
let deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit); | ||
*metadata = Some(AssetMetadata { | ||
deposit, | ||
name: name.clone(), | ||
symbol: symbol.clone(), | ||
name: bounded_name, | ||
symbol: bounded_symbol, | ||
decimals, | ||
is_frozen, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the future (or now) we should say how the associated types can be modified.
For instance here "T::StringLimit" is used for stored item, thus changing the limit requires a migration of those items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only when the value decreases. Increases should be backwards compatible.