Skip to content

Commit

Permalink
Add Fragnova changes on top of the latest pdot release
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkingsugar committed Mar 14, 2023
1 parent 1837f42 commit 0ba470e
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 121 deletions.
4 changes: 2 additions & 2 deletions client/offchain/src/api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ impl HttpApi {
self.requests
.insert(new_id, HttpApiRequest::NotDispatched(request, body_sender));

tracing::error!(
tracing::trace!(
target: LOG_TARGET,
id = %new_id.0,
%method,
%uri,
"Requested started",
"Request started",
);

Ok(new_id)
Expand Down
5 changes: 3 additions & 2 deletions frame/assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn create_default_asset<T: Config<I>, I: 'static>(
caller_lookup.clone(),
is_sufficient,
1u32.into(),
true,
)
.is_ok());
(asset_id, caller, caller_lookup)
Expand Down Expand Up @@ -140,7 +141,7 @@ benchmarks_instance_pallet! {
let caller = T::CreateOrigin::ensure_origin(origin, &asset_id.into()).unwrap();
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, 1u32.into())
}: _(SystemOrigin::Signed(caller.clone()), asset_id, caller_lookup, 1u32.into(), true)
verify {
assert_last_event::<T, I>(Event::Created { asset_id: asset_id.into(), creator: caller.clone(), owner: caller }.into());
}
Expand All @@ -149,7 +150,7 @@ benchmarks_instance_pallet! {
let asset_id = default_asset_id::<T, I>();
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
}: _(SystemOrigin::Root, asset_id, caller_lookup, true, 1u32.into())
}: _(SystemOrigin::Root, asset_id, caller_lookup, true, 1u32.into(), true)
verify {
assert_last_event::<T, I>(Event::ForceCreated { asset_id: asset_id.into(), owner: caller }.into());
}
Expand Down
5 changes: 4 additions & 1 deletion frame/assets/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
///
/// Will fail if the amount transferred is so small that it cannot create the destination due
/// to minimum balance requirements.
pub(super) fn do_transfer(
pub fn do_transfer(
id: T::AssetId,
source: &T::AccountId,
dest: &T::AccountId,
Expand Down Expand Up @@ -635,11 +635,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// this asset.
/// * `min_balance`: The minimum balance a user is allowed to have of this asset before they are
/// considered dust and cleaned up.
/// * `transferable`: Whether the new asset is transferable or not.
pub(super) fn do_force_create(
id: T::AssetId,
owner: T::AccountId,
is_sufficient: bool,
min_balance: T::Balance,
transferable: bool,
) -> DispatchResult {
ensure!(!Asset::<T, I>::contains_key(id), Error::<T, I>::InUse);
ensure!(!min_balance.is_zero(), Error::<T, I>::MinBalanceZero);
Expand All @@ -659,6 +661,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
sufficients: 0,
approvals: 0,
status: AssetStatus::Live,
is_transferable: transferable,
},
);
Self::deposit_event(Event::ForceCreated { asset_id: id, owner: owner.clone() });
Expand Down
2 changes: 1 addition & 1 deletion frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<T: Config<I>, I: 'static> fungibles::Create<T::AccountId> for Pallet<T, I>
is_sufficient: bool,
min_balance: Self::Balance,
) -> DispatchResult {
Self::do_force_create(id, admin, is_sufficient, min_balance)
Self::do_force_create(id, admin, is_sufficient, min_balance, true)
}
}

Expand Down
38 changes: 33 additions & 5 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ pub mod pallet {

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
/// Genesis assets: id, owner, is_sufficient, min_balance
pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance)>,
/// Genesis assets: id, owner, is_sufficient, min_balance, transferable
pub assets: Vec<(T::AssetId, T::AccountId, bool, T::Balance, bool)>,
/// Genesis metadata: id, name, symbol, decimals
pub metadata: Vec<(T::AssetId, Vec<u8>, Vec<u8>, u8)>,
/// Genesis accounts: id, account_id, balance
Expand All @@ -378,7 +378,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
fn build(&self) {
for (id, owner, is_sufficient, min_balance) in &self.assets {
for (id, owner, is_sufficient, min_balance, transferable) in &self.assets {
assert!(!Asset::<T, I>::contains_key(id), "Asset id already in use");
assert!(!min_balance.is_zero(), "Min balance should not be zero");
Asset::<T, I>::insert(
Expand All @@ -396,6 +396,7 @@ pub mod pallet {
sufficients: 0,
approvals: 0,
status: AssetStatus::Live,
is_transferable: *transferable, // This line has been added by Fragnova
},
);
}
Expand Down Expand Up @@ -559,6 +560,10 @@ pub mod pallet {
IncorrectStatus,
/// The asset should be frozen before the given operation.
NotFrozen,
/// Cannot transfer an asset that is not transferable.
///
/// Note: This error has been added by Fragnova
CannotTransferThisFragnovaAsset,
}

#[pallet::call]
Expand All @@ -578,6 +583,7 @@ pub mod pallet {
/// member of the asset class's admin team.
/// - `min_balance`: The minimum balance of this new asset that any single account must
/// have. If an account's balance is reduced below this, then it collapses to zero.
/// - `transferable`: Whether the new asset is transferable or not. Note: This parameter has been added by Fragnova.
///
/// Emits `Created` event when successful.
///
Expand All @@ -589,6 +595,7 @@ pub mod pallet {
id: T::AssetIdParameter,
admin: AccountIdLookupOf<T>,
min_balance: T::Balance,
transferable: bool, // Note: This parameter has been added by Fragnova
) -> DispatchResult {
let id: T::AssetId = id.into();
let owner = T::CreateOrigin::ensure_origin(origin, &id)?;
Expand All @@ -615,6 +622,7 @@ pub mod pallet {
sufficients: 0,
approvals: 0,
status: AssetStatus::Live,
is_transferable: transferable, // This line has been added by Fragnova
},
);

Expand Down Expand Up @@ -643,6 +651,7 @@ pub mod pallet {
/// `transfer_ownership` and `set_team`.
/// - `min_balance`: The minimum balance of this new asset that any single account must
/// have. If an account's balance is reduced below this, then it collapses to zero.
///- `transferable`: Whether the asset is transferable or not. Note: This parameter has been added by Fragnova.
///
/// Emits `ForceCreated` event when successful.
///
Expand All @@ -655,11 +664,12 @@ pub mod pallet {
owner: AccountIdLookupOf<T>,
is_sufficient: bool,
#[pallet::compact] min_balance: T::Balance,
transferable: bool, // Note: This parameter has been added by Fragnova.
) -> DispatchResult {
T::ForceOrigin::ensure_origin(origin)?;
let owner = T::Lookup::lookup(owner)?;
let id: T::AssetId = id.into();
Self::do_force_create(id, owner, is_sufficient, min_balance)
Self::do_force_create(id, owner, is_sufficient, min_balance, transferable)
}

/// Start the process of destroying a fungible asset class.
Expand Down Expand Up @@ -839,6 +849,10 @@ pub mod pallet {
let dest = T::Lookup::lookup(target)?;
let id: T::AssetId = id.into();

// These 2 lines have been added by Fragnova
let info = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
ensure!(info.is_transferable, Error::<T, I>::CannotTransferThisFragnovaAsset);

let f = TransferFlags { keep_alive: false, best_effort: false, burn_dust: false };
Self::do_transfer(id, &origin, &dest, amount, None, f).map(|_| ())
}
Expand Down Expand Up @@ -873,6 +887,10 @@ pub mod pallet {
let dest = T::Lookup::lookup(target)?;
let id: T::AssetId = id.into();

// These 2 lines have been added by Fragnova
let info = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
ensure!(info.is_transferable, Error::<T, I>::CannotTransferThisFragnovaAsset);

let f = TransferFlags { keep_alive: true, best_effort: false, burn_dust: false };
Self::do_transfer(id, &source, &dest, amount, None, f).map(|_| ())
}
Expand Down Expand Up @@ -1068,7 +1086,7 @@ pub mod pallet {
ensure!(details.status == AssetStatus::Live, Error::<T, I>::LiveAsset);
ensure!(origin == details.owner, Error::<T, I>::NoPermission);
if details.owner == owner {
return Ok(())
return Ok(());
}

let metadata_deposit = Metadata::<T, I>::get(id).deposit;
Expand Down Expand Up @@ -1358,6 +1376,11 @@ pub mod pallet {
let owner = ensure_signed(origin)?;
let delegate = T::Lookup::lookup(delegate)?;
let id: T::AssetId = id.into();

// These 2 lines have been added by Fragnova
let info = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
ensure!(info.is_transferable, Error::<T, I>::CannotTransferThisFragnovaAsset);

Self::do_approve_transfer(id, &owner, &delegate, amount)
}

Expand Down Expand Up @@ -1474,6 +1497,11 @@ pub mod pallet {
let owner = T::Lookup::lookup(owner)?;
let destination = T::Lookup::lookup(destination)?;
let id: T::AssetId = id.into();

// These 2 lines have been added by Fragnova
let info = Asset::<T, I>::get(id).ok_or(Error::<T, I>::Unknown)?;
ensure!(info.is_transferable, Error::<T, I>::CannotTransferThisFragnovaAsset);

Self::do_transfer_approved(id, &owner, &delegate, &destination, amount)
}

Expand Down
2 changes: 2 additions & 0 deletions frame/assets/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub mod v1 {
impl<Balance, AccountId, DepositBalance> OldAssetDetails<Balance, AccountId, DepositBalance> {
fn migrate_to_v1(self) -> AssetDetails<Balance, AccountId, DepositBalance> {
let status = if self.is_frozen { AssetStatus::Frozen } else { AssetStatus::Live };
let is_transferable = false;

AssetDetails {
owner: self.owner,
Expand All @@ -56,6 +57,7 @@ pub mod v1 {
sufficients: self.sufficients,
approvals: self.approvals,
status,
is_transferable,
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions frame/assets/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl pallet_balances::Config for Test {
type MaxLocks = ();
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type IsTransferable = frame_support::traits::ConstBool<true>; // This line was added by Fragnova
}

pub struct AssetsCallbackHandle;
Expand Down Expand Up @@ -173,8 +174,8 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities {

let config: pallet_assets::GenesisConfig<Test> = pallet_assets::GenesisConfig {
assets: vec![
// id, owner, is_sufficient, min_balance
(999, 0, true, 1),
// id, owner, is_sufficient, min_balance, transferable
(999, 0, true, 1, true),
],
metadata: vec![
// id, name, symbol, decimals
Expand Down
Loading

0 comments on commit 0ba470e

Please sign in to comment.