Skip to content

Commit

Permalink
Make Balance not transferable (#4)
Browse files Browse the repository at this point in the history
Make Balance not transferable
  • Loading branch information
alebaffa authored Sep 12, 2022
1 parent 24c700f commit 1b6228d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ pub mod pallet {

/// The id type for named reserves.
type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;

type IsTransferable: Get<bool>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -485,6 +487,8 @@ pub mod pallet {
DeadAccount,
/// Number of named reserves exceed MaxReserves
TooManyReserves,
/// Whether transfer function is allowed or not
CannotTransfer,
}

/// The total units issued in the system.
Expand Down Expand Up @@ -1472,13 +1476,16 @@ where
}

// Transfer some free balance from `transactor` to `dest`, respecting existence requirements.
// Is a no-op if value to be transferred is zero or the `transactor` is the same as `dest`.
// Is a no-op if value to be transferred is zero or the `transactor` is the same as `dest` or the
// transferability set in config is forbidden.
fn transfer(
transactor: &T::AccountId,
dest: &T::AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement,
) -> DispatchResult {
ensure!(T::IsTransferable::get(), Error::<T, I>::CannotTransfer);

if value.is_zero() || transactor == dest {
return Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static ExistentialDeposit: u64 = 0;
pub static IsTransferable: bool = true;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
Expand Down Expand Up @@ -95,6 +96,7 @@ impl Config for Test {
type MaxReserves = ConstU32<2>;
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type IsTransferable = IsTransferable;
}

pub struct ExtBuilder {
Expand Down
2 changes: 2 additions & 0 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static ExistentialDeposit: u64 = 0;
pub static IsTransferable: bool = true;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
Expand Down Expand Up @@ -97,6 +98,7 @@ impl Config for Test {
type MaxReserves = ConstU32<2>;
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type Transferable = IsTransferable;
}

pub struct ExtBuilder {
Expand Down
2 changes: 2 additions & 0 deletions frame/balances/src/tests_reentrancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
pub static ExistentialDeposit: u64 = 0;
pub static IsTransferable: bool = true;
}
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
Expand Down Expand Up @@ -99,6 +100,7 @@ impl Config for Test {
type MaxReserves = ConstU32<2>;
type ReserveIdentifier = [u8; 8];
type WeightInfo = ();
type IsTransferable = IsTransferable;
}

pub struct ExtBuilder {
Expand Down

0 comments on commit 1b6228d

Please sign in to comment.