-
Notifications
You must be signed in to change notification settings - Fork 665
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
Implement Inactive balance tracking in Assets pallet #1747
base: master
Are you sure you want to change the base?
Changes from all commits
58a50da
1167d68
ebdb21e
8af1f39
632d1a8
57ec30a
180d91b
ea52ad0
1b61d66
4550656
f69f85a
ecea308
7af51dd
b0d6691
889a898
91ac946
c2b3f2b
6c7a197
6a436d2
401a229
ce71499
File filter
Filter by extension
Conversations
Jump to
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
||
title: Implement Inactive balance tracking in Assets pallet | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
The trait `fungibles::Unbalanced` provides methods to increase and decrease active issuance. | ||
This PR addresses the lack of this feature in Assets, by introducing a new field `inactive` in the `Asset` struct and implementing the methods accordingly. | ||
|
||
crates: | ||
- name: pallet-assets |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,7 +164,22 @@ impl<T: Config<I>, I: 'static> fungibles::Unbalanced<T::AccountId> for Pallet<T, | |
Ok(amount) | ||
} | ||
|
||
// TODO: #13196 implement deactivate/reactivate once we have inactive balance tracking. | ||
fn deactivate(asset: Self::AssetId, amount: Self::Balance) { | ||
Asset::<T, I>::mutate(&asset, |maybe_asset| match maybe_asset { | ||
Some(ref mut asset) => { | ||
// Inactive amount can't exceed supply | ||
asset.inactive = asset.inactive.saturating_add(amount).max(asset.supply); | ||
}, | ||
None => log::error!("Called deactivate for nonexistent asset {:?}", asset), | ||
}); | ||
} | ||
|
||
fn reactivate(asset: Self::AssetId, amount: Self::Balance) { | ||
Asset::<T, I>::mutate(&asset, |maybe_asset| match maybe_asset { | ||
Some(ref mut asset) => asset.inactive.saturating_reduce(amount), | ||
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. Should be defensive in case > total inactive amount is attempted to be reactivated? |
||
None => log::error!("Called reactivate for nonexistent asset {:?}", asset), | ||
}); | ||
} | ||
} | ||
|
||
impl<T: Config<I>, I: 'static> fungibles::Create<T::AccountId> for Pallet<T, I> { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -218,8 +218,8 @@ pub mod pallet { | |||||
}; | ||||||
use frame_system::pallet_prelude::*; | ||||||
|
||||||
/// The in-code storage version. | ||||||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); | ||||||
/// The current storage version. | ||||||
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.
Suggested change
|
||||||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); | ||||||
|
||||||
#[pallet::pallet] | ||||||
#[pallet::storage_version(STORAGE_VERSION)] | ||||||
|
@@ -440,6 +440,7 @@ pub mod pallet { | |||||
admin: owner.clone(), | ||||||
freezer: owner.clone(), | ||||||
supply: Zero::zero(), | ||||||
inactive: Zero::zero(), | ||||||
deposit: Zero::zero(), | ||||||
min_balance: *min_balance, | ||||||
is_sufficient: *is_sufficient, | ||||||
|
@@ -666,6 +667,7 @@ pub mod pallet { | |||||
admin: admin.clone(), | ||||||
freezer: admin.clone(), | ||||||
supply: Zero::zero(), | ||||||
inactive: Zero::zero(), | ||||||
deposit, | ||||||
min_balance, | ||||||
is_sufficient: false, | ||||||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Version 0 to 1. | ||
pub mod v1; | ||
/// Version 1 to 2. | ||
pub mod v2; |
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.
Seems this be a defensive check if the runtime is trying to set the inactive amt > total supply, probably indicates a bug?