Skip to content

Commit

Permalink
Merge pull request paritytech#12 from dzmitry-lahoda-forks/dz/assets-…
Browse files Browse the repository at this point in the history
…tx-27

merge assets tx config from master to 0.9.27
  • Loading branch information
dzmitry-lahoda authored Sep 7, 2022
2 parents 9b9e2a2 + 71bb4b2 commit f709a3d
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 28 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

27 changes: 20 additions & 7 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use frame_support::{
pallet_prelude::Get,
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, Currency, EitherOfDiverse,
EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter, KeyOwnerProofSystem,
LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
tokens::OneToOneBalanceConversion, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32,
Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter,
KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
Expand Down Expand Up @@ -455,12 +455,25 @@ impl pallet_transaction_payment::Config for Runtime {
TargetedFeeAdjustment<Self, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier>;
}

parameter_types! {
pub const UseUserConfiguration: bool = false;
}

type AssetsBalances = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
CreditToBlockAuthor,
>;

impl pallet_asset_tx_payment::Config for Runtime {
type Fungibles = Assets;
type OnChargeAssetTransaction = pallet_asset_tx_payment::FungiblesAdapter<
pallet_assets::BalanceToAssetBalance<Balances, Runtime, ConvertInto>,
CreditToBlockAuthor,
>;
type OnChargeAssetTransaction = AssetsBalances;
type UseUserConfiguration = UseUserConfiguration;
type WeightInfo = ();
type ConfigurationOrigin = EnsureRoot<AccountId>;
type PayableCall = Call;
type ConfigurationExistentialDeposit = ConstU128<100>;
type BalanceConverter = OneToOneBalanceConversion;
type Lock = Assets;
}

parameter_types! {
Expand Down
52 changes: 51 additions & 1 deletion frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<T: Config<I>, I: 'static> fungibles::approvals::Mutate<<T as SystemConfig>:
Self::do_approve_transfer(asset, owner, delegate, amount)
}

// Aprove spending tokens from a given account
// Approve spending tokens from a given account
fn transfer_from(
asset: T::AssetId,
owner: &<T as SystemConfig>::AccountId,
Expand All @@ -263,3 +263,53 @@ impl<T: Config<I>, I: 'static> fungibles::approvals::Mutate<<T as SystemConfig>:
Self::do_transfer_approved(asset, owner, delegate, dest, amount)
}
}

// noop hold implementation
// real impl can be next pr
impl<T: Config<I>, I: 'static> fungibles::InspectHold<<T as SystemConfig>::AccountId>
for Pallet<T, I>
{
fn balance_on_hold(_asset: T::AssetId, _who: &<T as SystemConfig>::AccountId) -> Self::Balance {
<_>::default()
}

fn can_hold(
_asset: T::AssetId,
_who: &<T as SystemConfig>::AccountId,
_amount: Self::Balance,
) -> bool {
false
}
}

impl<T: Config<I>, I: 'static> fungibles::MutateHold<<T as SystemConfig>::AccountId>
for Pallet<T, I>
{
fn hold(
_asset: T::AssetId,
_who: &<T as SystemConfig>::AccountId,
_amount: Self::Balance,
) -> DispatchResult {
Err(DispatchError::Other("not implemented"))
}

fn release(
_asset: T::AssetId,
_who: &<T as SystemConfig>::AccountId,
_amount: Self::Balance,
_best_effort: bool,
) -> Result<Self::Balance, DispatchError> {
Err(DispatchError::Other("not implemented"))
}

fn transfer_held(
_asset: Self::AssetId,
_source: &<T as SystemConfig>::AccountId,
_dest: &<T as SystemConfig>::AccountId,
_amount: Self::Balance,
_best_effort: bool,
_on_hold: bool,
) -> Result<Self::Balance, DispatchError> {
Err(DispatchError::Other("not implemented"))
}
}
2 changes: 1 addition & 1 deletion frame/support/src/traits/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ pub mod nonfungibles;
pub use imbalance::Imbalance;
pub use misc::{
AssetId, Balance, BalanceConversion, BalanceStatus, DepositConsequence, ExistenceRequirement,
Locker, WithdrawConsequence, WithdrawReasons,
Locker, OneToOneBalanceConversion, WithdrawConsequence, WithdrawReasons,
};
8 changes: 8 additions & 0 deletions frame/support/src/traits/tokens/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result<OutBalance, Self::Error>;
}

pub struct OneToOneBalanceConversion;
impl<Balance, AssetId> BalanceConversion<Balance, AssetId, Balance> for OneToOneBalanceConversion {
type Error = DispatchError;
fn to_asset_balance(balance: Balance, _asset_id: AssetId) -> Result<Balance, Self::Error> {
Ok(balance)
}
}

/// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented
/// downstream to extend logic of Uniques current functionality.
pub trait Locker<CollectionId, ItemId> {
Expand Down
5 changes: 5 additions & 0 deletions frame/transaction-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ std = [
"sp-std/std",
]
try-runtime = ["frame-support/try-runtime"]

runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
8 changes: 8 additions & 0 deletions frame/transaction-payment/asset-tx-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sp-std = { version = "4.0.0", default-features = false, path = "../../../primiti

frame-support = { version = "4.0.0-dev", default-features = false, path = "../../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../../benchmarking" }
pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, path = ".." }

# Other dependencies
Expand Down Expand Up @@ -52,3 +53,10 @@ std = [
"pallet-transaction-payment/std",
]
try-runtime = ["frame-support/try-runtime"]

runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
]
38 changes: 38 additions & 0 deletions frame/transaction-payment/asset-tx-payment/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is part of Substrate.

// Copyright (C) 2019-2022 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.

// Benchmarks for AssetTxPayment Pallet

#![cfg(feature = "runtime-benchmarks")]

use super::*;
#[allow(unused_imports)] // benchmarks
use crate::Pallet as AssetTxPayment;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin;

benchmarks! {
set_payment_asset {
let caller: T::AccountId = whitelisted_caller();
// NOTE: best effort without refactoring to support runtime for tests (need asset_id)
}: _(RawOrigin::Signed(caller.clone()), caller.clone(), <_>::default())
verify {
let actual = <PaymentAssets::<T>>::get(&caller);
assert_eq!(actual, None);
}
impl_benchmark_test_suite!(AssetTxPayment, crate::tests::new_test_ext(), crate::tests::Runtime);
}
Loading

0 comments on commit f709a3d

Please sign in to comment.