diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index b60056e045..c4d60437a3 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -81,7 +81,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 222, + spec_version: 223, impl_version: 0, apis: RUNTIME_API_VERSIONS, }; diff --git a/substrate/frame/support/src/traits.rs b/substrate/frame/support/src/traits.rs index 570342bf57..4730e1955e 100644 --- a/substrate/frame/support/src/traits.rs +++ b/substrate/frame/support/src/traits.rs @@ -734,7 +734,8 @@ pub trait VestingSchedule { type Currency: Currency; /// Get the amount that is currently being vested and cannot be transferred out of this account. - fn vesting_balance(who: &AccountId) -> >::Balance; + /// Returns `None` if the account has no vesting schedule. + fn vesting_balance(who: &AccountId) -> Option<>::Balance>; /// Adds a vesting schedule to a given account. /// diff --git a/substrate/frame/vesting/src/lib.rs b/substrate/frame/vesting/src/lib.rs index 15adcaaf53..dd51259842 100644 --- a/substrate/frame/vesting/src/lib.rs +++ b/substrate/frame/vesting/src/lib.rs @@ -237,13 +237,13 @@ impl VestingSchedule for Module where type Currency = T::Currency; /// Get the amount that is currently being vested and cannot be transferred out of this account. - fn vesting_balance(who: &T::AccountId) -> BalanceOf { + fn vesting_balance(who: &T::AccountId) -> Option> { if let Some(v) = Self::vesting(who) { let now = >::block_number(); let locked_now = v.locked_at::(now); - T::Currency::free_balance(who).min(locked_now) + Some(T::Currency::free_balance(who).min(locked_now)) } else { - Zero::zero() + None } } @@ -484,28 +484,28 @@ mod tests { assert_eq!(Vesting::vesting(&12), Some(user12_vesting_schedule)); // Account 12 has a vesting schedule // Account 1 has only 128 units vested from their illiquid 256 * 5 units at block 1 - assert_eq!(Vesting::vesting_balance(&1), 128 * 9); + assert_eq!(Vesting::vesting_balance(&1), Some(128 * 9)); // Account 2 has their full balance locked - assert_eq!(Vesting::vesting_balance(&2), user2_free_balance); + assert_eq!(Vesting::vesting_balance(&2), Some(user2_free_balance)); // Account 12 has only their illiquid funds locked - assert_eq!(Vesting::vesting_balance(&12), user12_free_balance - 256 * 5); + assert_eq!(Vesting::vesting_balance(&12), Some(user12_free_balance - 256 * 5)); System::set_block_number(10); assert_eq!(System::block_number(), 10); // Account 1 has fully vested by block 10 - assert_eq!(Vesting::vesting_balance(&1), 0); + assert_eq!(Vesting::vesting_balance(&1), Some(0)); // Account 2 has started vesting by block 10 - assert_eq!(Vesting::vesting_balance(&2), user2_free_balance); + assert_eq!(Vesting::vesting_balance(&2), Some(user2_free_balance)); // Account 12 has started vesting by block 10 - assert_eq!(Vesting::vesting_balance(&12), user12_free_balance - 256 * 5); + assert_eq!(Vesting::vesting_balance(&12), Some(user12_free_balance - 256 * 5)); System::set_block_number(30); assert_eq!(System::block_number(), 30); - assert_eq!(Vesting::vesting_balance(&1), 0); // Account 1 is still fully vested, and not negative - assert_eq!(Vesting::vesting_balance(&2), 0); // Account 2 has fully vested by block 30 - assert_eq!(Vesting::vesting_balance(&12), 0); // Account 2 has fully vested by block 30 + assert_eq!(Vesting::vesting_balance(&1), Some(0)); // Account 1 is still fully vested, and not negative + assert_eq!(Vesting::vesting_balance(&2), Some(0)); // Account 2 has fully vested by block 30 + assert_eq!(Vesting::vesting_balance(&12), Some(0)); // Account 2 has fully vested by block 30 }); } @@ -520,7 +520,7 @@ mod tests { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance // Account 1 has only 5 units vested at block 1 (plus 50 unvested) - assert_eq!(Vesting::vesting_balance(&1), 45); + assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_noop!( Balances::transfer(Some(1).into(), 2, 56), pallet_balances::Error::::LiquidityRestrictions, @@ -538,7 +538,7 @@ mod tests { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance // Account 1 has only 5 units vested at block 1 (plus 50 unvested) - assert_eq!(Vesting::vesting_balance(&1), 45); + assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest(Some(1).into())); assert_ok!(Balances::transfer(Some(1).into(), 2, 55)); }); @@ -554,7 +554,7 @@ mod tests { let user1_free_balance = Balances::free_balance(&1); assert_eq!(user1_free_balance, 100); // Account 1 has free balance // Account 1 has only 5 units vested at block 1 (plus 50 unvested) - assert_eq!(Vesting::vesting_balance(&1), 45); + assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest_other(Some(2).into(), 1)); assert_ok!(Balances::transfer(Some(1).into(), 2, 55)); }); @@ -577,12 +577,12 @@ mod tests { assert_eq!(user2_free_balance, 300); // Account 2 has 100 more free balance than normal // Account 1 has only 5 units vested at block 1 (plus 150 unvested) - assert_eq!(Vesting::vesting_balance(&1), 45); + assert_eq!(Vesting::vesting_balance(&1), Some(45)); assert_ok!(Vesting::vest(Some(1).into())); assert_ok!(Balances::transfer(Some(1).into(), 3, 155)); // Account 1 can send extra units gained // Account 2 has no units vested at block 1, but gained 100 - assert_eq!(Vesting::vesting_balance(&2), 200); + assert_eq!(Vesting::vesting_balance(&2), Some(200)); assert_ok!(Vesting::vest(Some(2).into())); assert_ok!(Balances::transfer(Some(2).into(), 3, 100)); // Account 2 can send extra units gained }); @@ -599,7 +599,7 @@ mod tests { assert_eq!(user12_free_balance, 2560); // Account 12 has free balance // Account 12 has liquid funds - assert_eq!(Vesting::vesting_balance(&12), user12_free_balance - 256 * 5); + assert_eq!(Vesting::vesting_balance(&12), Some(user12_free_balance - 256 * 5)); // Account 12 has delayed vesting let user12_vesting_schedule = VestingInfo {