Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
open-runtime-module-library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Noxim
open-runtime-module-library
Commits
0b73e5f6
Unverified
Commit
0b73e5f6
authored
5 years ago
by
Shaopeng Wang
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
More currency traits. (#10)
parent
3d0a8a25
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
traits/src/lib.rs
+61
-2
61 additions, 2 deletions
traits/src/lib.rs
with
61 additions
and
2 deletions
traits/src/lib.rs
+
61
−
2
View file @
0b73e5f6
#![cfg_attr(not(feature
=
"std"
),
no_std)]
use
codec
::
FullCodec
;
use
rstd
::{
fmt
::
Debug
,
result
};
use
rstd
::{
convert
::{
TryFrom
,
TryInto
},
fmt
::
Debug
,
result
,
};
use
sr_primitives
::
traits
::{
MaybeSerializeDeserialize
,
SimpleArithmetic
};
/// Abstraction over a fungible multi-currency system.
...
...
@@ -40,7 +44,7 @@ pub trait MultiCurrency<AccountId> {
amount
:
Self
::
Balance
,
)
->
result
::
Result
<
(),
Self
::
Error
>
;
/// Remove `amount` from the balance of `who` under `currency_id` and re
cud
e total issuance.
/// Remove `amount` from the balance of `who` under `currency_id` and re
duc
e total issuance.
fn
withdraw
(
currency_id
:
Self
::
CurrencyId
,
who
:
&
AccountId
,
...
...
@@ -52,3 +56,58 @@ pub trait MultiCurrency<AccountId> {
/// As much funds up to `amount` will be deducted as possible, the actual slashed amount will be returned.
fn
slash
(
currency_id
:
Self
::
CurrencyId
,
who
:
&
AccountId
,
amount
:
Self
::
Balance
)
->
Self
::
Balance
;
}
/// Extended `MultiCurrency` with additional helper types and methods.
pub
trait
MultiCurrencyExtended
<
AccountId
>
:
MultiCurrency
<
AccountId
>
{
/// The type for balance related operations, typically signed int.
type
Amount
:
TryInto
<
Self
::
Balance
>
+
TryFrom
<
Self
::
Balance
>
;
/// Add or remove abs(`by_amount`) from the balance of `who` under `currency_id`. If positive `by_amount`, do add, else do remove.
fn
update_balance
(
currency_id
:
Self
::
CurrencyId
,
who
:
AccountId
,
by_amount
:
Self
::
Amount
,
)
->
result
::
Result
<
(),
Self
::
Error
>
;
}
/// Abstraction over a fungible (single) currency system.
pub
trait
BasicCurrency
<
AccountId
>
{
/// The balance of an account.
type
Balance
:
SimpleArithmetic
+
FullCodec
+
Copy
+
MaybeSerializeDeserialize
+
Debug
+
Default
;
/// The error type.
type
Error
:
Into
<&
'static
str
>
;
// Public immutables
/// The total amount of issuance.
fn
total_inssuance
()
->
Self
::
Balance
;
/// The balance of `who`.
fn
balance
(
who
:
&
AccountId
)
->
Self
::
Balance
;
// Public mutables
/// Transfer some amount from one account to another.
fn
transfer
(
from
:
&
AccountId
,
to
:
&
AccountId
,
amount
:
Self
::
Balance
)
->
result
::
Result
<
(),
Self
::
Error
>
;
/// Add `amount` to the balance of `who` and increase total issuance.
fn
deposit
(
who
:
&
AccountId
,
amount
:
Self
::
Balance
)
->
result
::
Result
<
(),
Self
::
Error
>
;
/// Remove `amount` from the balance of `who` and reduce total issuance.
fn
withdraw
(
who
:
&
AccountId
,
amount
:
Self
::
Balance
)
->
result
::
Result
<
(),
Self
::
Error
>
;
/// Deduct the balance of `who` by up to `amount`.
///
/// As much funds up to `amount` will be deducted as possible, the actual slashed amount will be returned.
fn
slash
(
who
:
&
AccountId
,
amount
:
Self
::
Balance
)
->
Self
::
Balance
;
}
/// Extended `BasicCurrency` with additional helper types and methods.
pub
trait
BasicCurrencyExtended
<
AccountId
>
:
BasicCurrency
<
AccountId
>
{
/// The type for balance related operations, typically signed int.
type
Amount
:
TryInto
<
Self
::
Balance
>
+
TryFrom
<
Self
::
Balance
>
;
/// Add or remove abs(`by_amount`) from the balance of `who`. If positive `by_amount`, do add, else do remove.
fn
update_balance
(
who
:
AccountId
,
by_amount
:
Self
::
Amount
)
->
result
::
Result
<
(),
Self
::
Error
>
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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