Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
78a8d9f3
Commit
78a8d9f3
authored
5 years ago
by
Gavin Wood
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix vesting logic (#4864)
* Fix vesting logic * Bump runtime version * Docs.
parent
e5a7fcc8
Branches
Branches containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
substrate/bin/node/runtime/src/lib.rs
+2
-2
2 additions, 2 deletions
substrate/bin/node/runtime/src/lib.rs
substrate/frame/support/src/traits.rs
+6
-0
6 additions, 0 deletions
substrate/frame/support/src/traits.rs
substrate/frame/vesting/src/lib.rs
+12
-6
12 additions, 6 deletions
substrate/frame/vesting/src/lib.rs
with
20 additions
and
8 deletions
substrate/bin/node/runtime/src/lib.rs
+
2
−
2
View file @
78a8d9f3
...
...
@@ -81,8 +81,8 @@ 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
:
21
4
,
impl_version
:
3
,
spec_version
:
21
5
,
impl_version
:
0
,
apis
:
RUNTIME_API_VERSIONS
,
};
...
...
This diff is collapsed.
Click to expand it.
substrate/frame/support/src/traits.rs
+
6
−
0
View file @
78a8d9f3
...
...
@@ -620,6 +620,10 @@ pub trait VestingSchedule<AccountId> {
///
/// If there already exists a vesting schedule for the given account, an `Err` is returned
/// and nothing is updated.
///
/// Is a no-op if the amount to be vested is zero.
///
/// NOTE: This doesn't alter the free balance of the account.
fn
add_vesting_schedule
(
who
:
&
AccountId
,
locked
:
<
Self
::
Currency
as
Currency
<
AccountId
>>
::
Balance
,
...
...
@@ -628,6 +632,8 @@ pub trait VestingSchedule<AccountId> {
)
->
DispatchResult
;
/// Remove a vesting schedule for a given account.
///
/// NOTE: This doesn't alter the free balance of the account.
fn
remove_vesting_schedule
(
who
:
&
AccountId
);
}
...
...
This diff is collapsed.
Click to expand it.
substrate/frame/vesting/src/lib.rs
+
12
−
6
View file @
78a8d9f3
...
...
@@ -52,7 +52,7 @@ use codec::{Encode, Decode};
use
sp_runtime
::{
DispatchResult
,
RuntimeDebug
,
traits
::{
StaticLookup
,
Zero
,
SimpleArithmetic
,
MaybeSerializeDeserialize
,
Saturating
,
Convert
}};
use
frame_support
::{
decl_module
,
decl_event
,
decl_storage
,
ensure
,
decl_error
};
use
frame_support
::{
decl_module
,
decl_event
,
decl_storage
,
decl_error
};
use
frame_support
::
traits
::{
Currency
,
LockableCurrency
,
VestingSchedule
,
WithdrawReason
,
LockIdentifier
};
...
...
@@ -212,16 +212,18 @@ impl<T: Trait> Module<T> {
/// (Re)set or remove the module's currency lock on `who`'s account in accordance with their
/// current unvested amount.
fn
update_lock
(
who
:
T
::
AccountId
)
->
DispatchResult
{
ensure!
(
Vesting
::
<
T
>
::
contains_key
(
&
who
),
Error
::
<
T
>
::
NotVesting
);
let
unvested
=
Self
::
vesting_balance
(
&
who
);
if
unvested
.is_zero
()
{
let
vesting
=
Self
::
vesting
(
&
who
)
.ok_or
(
Error
::
<
T
>
::
NotVesting
)
?
;
let
now
=
<
frame_system
::
Module
<
T
>>
::
block_number
();
let
locked_now
=
vesting
.locked_at
::
<
T
::
BlockNumberToBalance
>
(
now
);
if
locked_now
.is_zero
()
{
T
::
Currency
::
remove_lock
(
VESTING_ID
,
&
who
);
Vesting
::
<
T
>
::
remove
(
&
who
);
Self
::
deposit_event
(
RawEvent
::
VestingCompleted
(
who
));
}
else
{
let
reasons
=
WithdrawReason
::
Transfer
|
WithdrawReason
::
Reserve
;
T
::
Currency
::
set_lock
(
VESTING_ID
,
&
who
,
unvested
,
reasons
);
Self
::
deposit_event
(
RawEvent
::
VestingUpdated
(
who
,
unvested
));
T
::
Currency
::
set_lock
(
VESTING_ID
,
&
who
,
locked_now
,
reasons
);
Self
::
deposit_event
(
RawEvent
::
VestingUpdated
(
who
,
locked_now
));
}
Ok
(())
}
...
...
@@ -249,6 +251,10 @@ impl<T: Trait> VestingSchedule<T::AccountId> for Module<T> where
/// If there already exists a vesting schedule for the given account, an `Err` is returned
/// and nothing is updated.
///
/// On success, a linearly reducing amount of funds will be locked. In order to realise any
/// reduction of the lock over time as it diminishes, the account owner must use `vest` or
/// `vest_other`.
///
/// Is a no-op if the amount to be vested is zero.
fn
add_vesting_schedule
(
who
:
&
T
::
AccountId
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment