Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Implement fungible::* for Balances #8454

Merged
merged 48 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
145e4a4
Reservable, Transferrable Fungible(s), plus adapters.
gavofyork Mar 23, 2021
80b9c68
Repot into new dir
gavofyork Mar 23, 2021
e11fc3a
Imbalances for Fungibles
gavofyork Mar 23, 2021
68fe49b
Repot and balanced fungible.
gavofyork Mar 23, 2021
3098860
Clean up names and bridge-over Imbalanced.
gavofyork Mar 24, 2021
db6ac4f
Repot frame_support::trait. Finally.
gavofyork Mar 24, 2021
5e63c10
Make build.
gavofyork Mar 24, 2021
5e36471
Docs
gavofyork Mar 24, 2021
6e6dc8d
Good errors
gavofyork Mar 24, 2021
f5f44ae
Fix tests. Implement fungible::Inspect for Balances.
gavofyork Mar 24, 2021
2e7f3af
Implement additional traits for Balances.
gavofyork Mar 24, 2021
63ac01a
Revert UI test "fixes"
gavofyork Mar 24, 2021
adddb8f
Fix UI error
gavofyork Mar 24, 2021
f78749e
Fix UI test
bkchr Mar 24, 2021
3f80625
Merge branch 'gav-fungibles-traits' of github.com:paritytech/substrat…
bkchr Mar 24, 2021
452d4a0
More work on fungibles
gavofyork Mar 25, 2021
ff03aeb
Fixes
gavofyork Mar 25, 2021
b86e271
Merge branch 'gav-fungibles-traits' into gav-fungibles-more
gavofyork Mar 25, 2021
7f70f25
Merge remote-tracking branch 'origin/master' into gav-fungibles-traits
gavofyork Mar 25, 2021
2fc54c5
Merge branch 'gav-fungibles-traits' into gav-fungibles-more
gavofyork Mar 25, 2021
9d15e8c
More work.
gavofyork Mar 25, 2021
4213dd2
Update lock
gavofyork Mar 25, 2021
e5d697c
Merge branch 'gav-fungibles-traits' into gav-fungibles-more
gavofyork Mar 25, 2021
8fd468b
Make fungible::reserved work for Balances
gavofyork Mar 25, 2021
dcf11ec
Introduce Freezer to Assets, ready for a reserve & locks pallet. Some…
gavofyork Mar 25, 2021
00b17ca
Cleanup errors
gavofyork Mar 25, 2021
32b08a4
Imbalances working with Assets
gavofyork Mar 25, 2021
bf0565f
Test for freezer.
gavofyork Mar 25, 2021
7d5661b
Grumbles
gavofyork Mar 26, 2021
3fa07fc
Grumbles
gavofyork Mar 26, 2021
9831df2
Fixes
gavofyork Mar 26, 2021
2d12c43
Merge branch 'gav-fungibles-traits' into gav-fungibles-more
gavofyork Mar 26, 2021
526aac5
Extra "side-car" data for a user's asset balance.
gavofyork Mar 27, 2021
9a1e448
Merge remote-tracking branch 'origin/master' into gav-fungibles-more
gavofyork Mar 27, 2021
145ec81
Fix
gavofyork Mar 27, 2021
a77fd73
Fix test
gavofyork Mar 27, 2021
d3963d1
Merge remote-tracking branch 'origin/master' into gav-fungibles-more
gavofyork Mar 27, 2021
412e20c
Fixes
gavofyork Mar 27, 2021
3a102cd
Line lengths
gavofyork Mar 27, 2021
8abac16
Comments
gavofyork Mar 27, 2021
92675e2
Update frame/assets/src/tests.rs
gavofyork Mar 27, 2021
d6c5f86
Update frame/support/src/traits/tokens/fungibles.rs
gavofyork Mar 27, 2021
a61ea63
Update frame/assets/src/lib.rs
gavofyork Mar 27, 2021
790a810
Update frame/support/src/traits/tokens/fungible.rs
gavofyork Mar 27, 2021
577b61f
Introduce `transfer_reserved`
gavofyork Mar 28, 2021
5f6af14
Rename fungible Reserve -> Hold, add flag structs
gavofyork Mar 28, 2021
f7956ba
Avoid the `melted` API - its too complex and gives little help
gavofyork Mar 28, 2021
f141383
Repot Assets pallet
gavofyork Mar 28, 2021
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
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ impl pallet_assets::Config for Runtime {
type MetadataDepositPerByte = MetadataDepositPerByte;
type ApprovalDeposit = ApprovalDeposit;
type StringLimit = StringLimit;
type Freezer = ();
type Extra = ();
type WeightInfo = pallet_assets::weights::SubstrateWeight<Runtime>;
}

Expand Down
105 changes: 105 additions & 0 deletions frame/assets/src/extra_mutator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// This file is part of Substrate.

// Copyright (C) 2017-2021 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.

//! Datatype for easy mutation of the extra "sidecar" data.

use super::*;

/// A mutator type allowing inspection and possible modification of the extra "sidecar" data.
///
/// This may be used as a `Deref` for the pallet's extra data. If mutated (using `DerefMut`), then
/// any uncommitted changes (see `commit` function) will be automatically committed to storage when
/// dropped. Changes, even after committed, may be reverted to their original values with the
/// `revert` function.
pub struct ExtraMutator<T: Config> {
id: T::AssetId,
who: T::AccountId,
original: T::Extra,
pending: Option<T::Extra>,
}

impl<T: Config> Drop for ExtraMutator<T> {
fn drop(&mut self) {
debug_assert!(self.commit().is_ok(), "attempt to write to non-existent asset account");
}
}

impl<T: Config> sp_std::ops::Deref for ExtraMutator<T> {
type Target = T::Extra;
fn deref(&self) -> &T::Extra {
match self.pending {
Some(ref value) => value,
None => &self.original,
}
}
}

impl<T: Config> sp_std::ops::DerefMut for ExtraMutator<T> {
fn deref_mut(&mut self) -> &mut T::Extra {
if self.pending.is_none() {
self.pending = Some(self.original.clone());
}
self.pending.as_mut().unwrap()
}
}

impl<T: Config> ExtraMutator<T> {
pub(super) fn maybe_new(id: T::AssetId, who: impl sp_std::borrow::Borrow<T::AccountId>)
-> Option<ExtraMutator<T>>
{
if Account::<T>::contains_key(id, who.borrow()) {
Some(ExtraMutator::<T> {
id,
who: who.borrow().clone(),
original: Account::<T>::get(id, who.borrow()).extra,
pending: None,
})
} else {
None
}
}


/// Commit any changes to storage.
pub fn commit(&mut self) -> Result<(), ()> {
if let Some(extra) = self.pending.take() {
Account::<T>::try_mutate_exists(self.id, self.who.borrow(), |maybe_account|
if let Some(ref mut account) = maybe_account {
account.extra = extra;
Ok(())
} else {
Err(())
}
)
} else {
Ok(())
}
}

/// Revert any changes, even those already committed by `self` and drop self.
pub fn revert(mut self) -> Result<(), ()> {
self.pending = None;
Account::<T>::try_mutate_exists(self.id, self.who.borrow(), |maybe_account|
if let Some(ref mut account) = maybe_account {
account.extra = self.original.clone();
Ok(())
} else {
Err(())
}
)
}
}
Loading