Skip to main content
Homepage
Explore
Search or go to…
/
Sign in
Explore
Primary navigation
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Collapse sidebar
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
a8937e0b
Commit
a8937e0b
authored
Oct 13, 2023
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
perform type conversion
parent
1782a402
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#33565
waiting for manual action
Status:
Stage: quality
Status:
Stage: build
Status:
Stage: tests
Status:
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pallets/identity/src/lib.rs
+8
-2
8 additions, 2 deletions
pallets/identity/src/lib.rs
pallets/identity/src/traits.rs
+7
-2
7 additions, 2 deletions
pallets/identity/src/traits.rs
runtime/common/src/entities.rs
+18
-11
18 additions, 11 deletions
runtime/common/src/entities.rs
with
33 additions
and
15 deletions
pallets/identity/src/lib.rs
+
8
−
2
View file @
a8937e0b
...
@@ -775,7 +775,11 @@ pub mod pallet {
...
@@ -775,7 +775,11 @@ pub mod pallet {
// implement quotas
// implement quotas
impl
<
T
:
Config
,
Balance
:
Zero
>
IdtyQuotasLinker
<
T
::
IdtyIndex
,
Balance
>
for
Pallet
<
T
>
{
impl
<
T
:
Config
,
Balance
:
Zero
+
core
::
convert
::
From
<
u64
>>
IdtyQuotasLinker
<
T
::
IdtyIndex
,
Balance
>
for
Pallet
<
T
>
where
u64
:
From
<
Balance
>
,
{
fn
spend_quotas
(
fn
spend_quotas
(
idty_id
:
T
::
IdtyIndex
,
idty_id
:
T
::
IdtyIndex
,
amount
:
Balance
,
amount
:
Balance
,
...
@@ -784,9 +788,11 @@ impl<T: Config, Balance: Zero> IdtyQuotasLinker<T::IdtyIndex, Balance> for Palle
...
@@ -784,9 +788,11 @@ impl<T: Config, Balance: Zero> IdtyQuotasLinker<T::IdtyIndex, Balance> for Palle
if
let
Some
(
ref
mut
idty_val
)
=
idty_val_opt
{
if
let
Some
(
ref
mut
idty_val
)
=
idty_val_opt
{
if
idty_val
.status
==
IdtyStatus
::
Validated
{
if
idty_val
.status
==
IdtyStatus
::
Validated
{
idty_val
.data.update_quotas
::
<
T
>
();
idty_val
.data.update_quotas
::
<
T
>
();
return
Ok
(
idty_val
.data
.do_spend_quotas
(
amount
));
return
Ok
(
idty_val
.data.do_spend_quotas
::
<
Balance
>
(
amount
));
}
}
// TODO error identity not eligible to refund
}
}
// TODO identity not found
Ok
(
Balance
::
zero
())
Ok
(
Balance
::
zero
())
})
})
}
}
...
...
...
...
This diff is collapsed.
Click to expand it.
pallets/identity/src/traits.rs
+
7
−
2
View file @
a8937e0b
...
@@ -102,12 +102,17 @@ pub trait Quotas {
...
@@ -102,12 +102,17 @@ pub trait Quotas {
/// update quotas
/// update quotas
fn
update_quotas
<
T
:
frame_system
::
Config
>
(
&
mut
self
);
fn
update_quotas
<
T
:
frame_system
::
Config
>
(
&
mut
self
);
/// spend quotas
/// spend quotas
fn
do_spend_quotas
<
Balance
:
Zero
>
(
&
mut
self
,
amount
:
Balance
)
->
Balance
;
fn
do_spend_quotas
<
Balance
:
Zero
+
core
::
convert
::
From
<
u64
>>
(
&
mut
self
,
amount
:
Balance
,
)
->
Balance
where
u64
:
From
<
Balance
>
;
}
}
// dummy impl
// dummy impl
impl
Quotas
for
()
{
impl
Quotas
for
()
{
fn
update_quotas
<
T
>
(
&
mut
self
)
{}
fn
update_quotas
<
T
>
(
&
mut
self
)
{}
fn
do_spend_quotas
<
Balance
:
Zero
>
(
&
mut
self
,
amount
:
Balance
)
->
Balance
{
fn
do_spend_quotas
<
Balance
:
Zero
>
(
&
mut
self
,
_
amount
:
Balance
)
->
Balance
{
Balance
::
zero
()
Balance
::
zero
()
}
}
}
}
This diff is collapsed.
Click to expand it.
runtime/common/src/entities.rs
+
18
−
11
View file @
a8937e0b
...
@@ -89,29 +89,36 @@ impl pallet_identity::traits::Quotas for IdtyData {
...
@@ -89,29 +89,36 @@ impl pallet_identity::traits::Quotas for IdtyData {
use
sp_runtime
::
traits
::
SaturatedConversion
;
use
sp_runtime
::
traits
::
SaturatedConversion
;
// TODO make this parameters or runtime constants?
// TODO make this parameters or runtime constants?
// 14400 blocks = 24h
// 14400 blocks = 24h
const
RELOAD_RATE
:
u64
=
14400
;
// number of blocks in which MAX_QUOTAS is reloaded
const
RELOAD_RATE
:
crate
::
BlockNumber
=
14400
;
// number of blocks in which MAX_QUOTAS is reloaded
const
MAX_QUOTAS
:
pallet_balances
::
pallet
::
Pallet
<
T
>
::
Balance
=
1000
.into
();
// 10 Ǧ1
const
MAX_QUOTAS
:
crate
::
Balance
=
1000
;
// 10 Ǧ1
let
current_block
=
frame_system
::
pallet
::
Pallet
::
<
T
>
::
block_number
();
let
current_block
=
frame_system
::
pallet
::
Pallet
::
<
T
>
::
block_number
()
.saturated_into
::
<
crate
::
BlockNumber
>
();
let
(
last_use
,
amount
)
=
self
.quotas
;
let
(
last_use
,
amount
)
=
self
.quotas
;
let
new_amount
=
amount
let
new_amount
=
amount
+
MAX_QUOTAS
+
sp_runtime
::
Perbill
::
from_rational
(
current_block
-
last_use
,
RELOAD_RATE
)
*
sp_runtime
::
Perbill
::
from_rational
(
.mul_floor
(
MAX_QUOTAS
);
(
current_block
-
last_use
)
.saturated_into
::
<
u64
>
(),
RELOAD_RATE
,
);
let
new_amount
=
min
(
new_amount
,
MAX_QUOTAS
);
let
new_amount
=
min
(
new_amount
,
MAX_QUOTAS
);
self
.quotas
=
(
current_block
,
new_amount
);
self
.quotas
=
(
current_block
,
new_amount
);
}
}
/// spend a certain amount of quotas and return what was spent
/// spend a certain amount of quotas and return what was spent
fn
do_spend_quotas
<
Balance
>
(
&
mut
self
,
amount
:
Balance
)
->
Balance
{
fn
do_spend_quotas
<
Balance
:
core
::
convert
::
From
<
crate
::
Balance
>>
(
&
mut
self
,
amount
:
Balance
,
)
->
Balance
where
crate
::
Balance
:
From
<
Balance
>
,
{
use
sp_runtime
::
SaturatedConversion
;
let
amount
=
amount
.saturated_into
::
<
crate
::
Balance
>
();
let
old_amount
=
self
.quotas
.1
;
let
old_amount
=
self
.quotas
.1
;
if
amount
<=
old_amount
{
let
used
=
if
amount
<=
old_amount
{
self
.quotas
.1
-=
amount
;
self
.quotas
.1
-=
amount
;
amount
amount
}
else
{
}
else
{
self
.quotas
.1
=
0
;
self
.quotas
.1
=
0
;
amount
-
old_amount
amount
-
old_amount
}
};
used
.into
()
}
}
}
}
...
...
...
...
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
sign in
to comment