@@ -52,7 +52,7 @@ use codec::{Encode, Decode};
52
52
use sp_runtime:: { DispatchResult , RuntimeDebug , traits:: {
53
53
StaticLookup , Zero , SimpleArithmetic , MaybeSerializeDeserialize , Saturating , Convert
54
54
} } ;
55
- use frame_support:: { decl_module, decl_event, decl_storage, ensure , decl_error} ;
55
+ use frame_support:: { decl_module, decl_event, decl_storage, decl_error} ;
56
56
use frame_support:: traits:: {
57
57
Currency , LockableCurrency , VestingSchedule , WithdrawReason , LockIdentifier
58
58
} ;
@@ -212,16 +212,18 @@ impl<T: Trait> Module<T> {
212
212
/// (Re)set or remove the module's currency lock on `who`'s account in accordance with their
213
213
/// current unvested amount.
214
214
fn update_lock ( who : T :: AccountId ) -> DispatchResult {
215
- ensure ! ( Vesting :: <T >:: contains_key( & who) , Error :: <T >:: NotVesting ) ;
216
- let unvested = Self :: vesting_balance ( & who) ;
217
- if unvested. is_zero ( ) {
215
+ let vesting = Self :: vesting ( & who) . ok_or ( Error :: < T > :: NotVesting ) ?;
216
+ let now = <frame_system:: Module < T > >:: block_number ( ) ;
217
+ let locked_now = vesting. locked_at :: < T :: BlockNumberToBalance > ( now) ;
218
+
219
+ if locked_now. is_zero ( ) {
218
220
T :: Currency :: remove_lock ( VESTING_ID , & who) ;
219
221
Vesting :: < T > :: remove ( & who) ;
220
222
Self :: deposit_event ( RawEvent :: VestingCompleted ( who) ) ;
221
223
} else {
222
224
let reasons = WithdrawReason :: Transfer | WithdrawReason :: Reserve ;
223
- T :: Currency :: set_lock ( VESTING_ID , & who, unvested , reasons) ;
224
- Self :: deposit_event ( RawEvent :: VestingUpdated ( who, unvested ) ) ;
225
+ T :: Currency :: set_lock ( VESTING_ID , & who, locked_now , reasons) ;
226
+ Self :: deposit_event ( RawEvent :: VestingUpdated ( who, locked_now ) ) ;
225
227
}
226
228
Ok ( ( ) )
227
229
}
@@ -249,6 +251,10 @@ impl<T: Trait> VestingSchedule<T::AccountId> for Module<T> where
249
251
/// If there already exists a vesting schedule for the given account, an `Err` is returned
250
252
/// and nothing is updated.
251
253
///
254
+ /// On success, a linearly reducing amount of funds will be locked. In order to realise any
255
+ /// reduction of the lock over time as it diminishes, the account owner must use `vest` or
256
+ /// `vest_other`.
257
+ ///
252
258
/// Is a no-op if the amount to be vested is zero.
253
259
fn add_vesting_schedule (
254
260
who : & T :: AccountId ,
0 commit comments