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
700afbcc
Unverified
Commit
700afbcc
authored
5 years ago
by
Xiliang Chen
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
rename Key and Value because sdk requires unique name (#51)
parent
799c03f4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
oracle/src/default_combine_data.rs
+2
-2
2 additions, 2 deletions
oracle/src/default_combine_data.rs
oracle/src/lib.rs
+18
-18
18 additions, 18 deletions
oracle/src/lib.rs
oracle/src/mock.rs
+2
-2
2 additions, 2 deletions
oracle/src/mock.rs
with
22 additions
and
22 deletions
oracle/src/default_combine_data.rs
+
2
−
2
View file @
700afbcc
...
...
@@ -11,9 +11,9 @@ use crate::{MomentOf, TimestampedValueOf, Trait};
/// Returns prev_value if not enough valid values.
pub
struct
DefaultCombineData
<
T
:
Trait
>
(
rstd
::
marker
::
PhantomData
<
T
>
);
impl
<
T
:
Trait
>
CombineData
<
T
::
Key
,
TimestampedValueOf
<
T
>>
for
DefaultCombineData
<
T
>
{
impl
<
T
:
Trait
>
CombineData
<
T
::
Oracle
Key
,
TimestampedValueOf
<
T
>>
for
DefaultCombineData
<
T
>
{
fn
combine_data
(
_key
:
&
T
::
Key
,
_key
:
&
T
::
Oracle
Key
,
values
:
Vec
<
TimestampedValueOf
<
T
>>
,
prev_value
:
Option
<
TimestampedValueOf
<
T
>>
,
)
->
Option
<
TimestampedValueOf
<
T
>>
{
...
...
This diff is collapsed.
Click to expand it.
oracle/src/lib.rs
+
18
−
18
View file @
700afbcc
...
...
@@ -21,23 +21,23 @@ pub use orml_traits::{CombineData, DataProvider, OnNewData};
pub
use
timestamped_value
::
TimestampedValue
;
type
MomentOf
<
T
>
=
<<
T
as
Trait
>
::
Time
as
Time
>
::
Moment
;
pub
type
TimestampedValueOf
<
T
>
=
TimestampedValue
<<
T
as
Trait
>
::
Value
,
MomentOf
<
T
>>
;
pub
type
TimestampedValueOf
<
T
>
=
TimestampedValue
<<
T
as
Trait
>
::
Oracle
Value
,
MomentOf
<
T
>>
;
pub
trait
Trait
:
frame_system
::
Trait
{
type
Event
:
From
<
Event
<
Self
>>
+
Into
<<
Self
as
frame_system
::
Trait
>
::
Event
>
;
type
OnNewData
:
OnNewData
<
Self
::
Key
,
Self
::
Value
>
;
type
OnNewData
:
OnNewData
<
Self
::
Oracle
Key
,
Self
::
Oracle
Value
>
;
type
OperatorProvider
:
OperatorProvider
<
Self
::
AccountId
>
;
type
CombineData
:
CombineData
<
Self
::
Key
,
TimestampedValueOf
<
Self
>>
;
type
CombineData
:
CombineData
<
Self
::
Oracle
Key
,
TimestampedValueOf
<
Self
>>
;
type
Time
:
Time
;
type
Key
:
Parameter
+
Member
;
type
Value
:
Parameter
+
Member
+
Ord
;
type
Oracle
Key
:
Parameter
+
Member
;
type
Oracle
Value
:
Parameter
+
Member
+
Ord
;
}
decl_storage!
{
trait
Store
for
Module
<
T
:
Trait
>
as
Oracle
{
pub
RawValues
get
(
raw_values
):
double_map
T
::
Key
,
blake2_256
(
T
::
AccountId
)
=>
Option
<
TimestampedValueOf
<
T
>>
;
pub
HasUpdate
get
(
has_update
):
map
T
::
Key
=>
bool
;
pub
Values
get
(
values
):
map
T
::
Key
=>
Option
<
TimestampedValueOf
<
T
>>
;
pub
RawValues
get
(
raw_values
):
double_map
T
::
Oracle
Key
,
blake2_256
(
T
::
AccountId
)
=>
Option
<
TimestampedValueOf
<
T
>>
;
pub
HasUpdate
get
(
has_update
):
map
T
::
Oracle
Key
=>
bool
;
pub
Values
get
(
values
):
map
T
::
Oracle
Key
=>
Option
<
TimestampedValueOf
<
T
>>
;
}
}
...
...
@@ -52,12 +52,12 @@ decl_module! {
pub
struct
Module
<
T
:
Trait
>
for
enum
Call
where
origin
:
T
::
Origin
{
fn
deposit_event
()
=
default
;
pub
fn
feed_value
(
origin
,
key
:
T
::
Key
,
value
:
T
::
Value
)
->
Result
{
pub
fn
feed_value
(
origin
,
key
:
T
::
Oracle
Key
,
value
:
T
::
Oracle
Value
)
->
Result
{
let
who
=
ensure_signed
(
origin
)
?
;
Self
::
_feed_values
(
who
,
vec!
[(
key
,
value
)])
.map_err
(|
e
|
e
.into
())
}
pub
fn
feed_values
(
origin
,
values
:
Vec
<
(
T
::
Key
,
T
::
Value
)
>
)
->
Result
{
pub
fn
feed_values
(
origin
,
values
:
Vec
<
(
T
::
Oracle
Key
,
T
::
Oracle
Value
)
>
)
->
Result
{
let
who
=
ensure_signed
(
origin
)
?
;
Self
::
_feed_values
(
who
,
values
)
.map_err
(|
e
|
e
.into
())
}
...
...
@@ -67,23 +67,23 @@ decl_module! {
decl_event!
(
pub
enum
Event
<
T
>
where
<
T
as
frame_system
::
Trait
>
::
AccountId
,
<
T
as
Trait
>
::
Key
,
<
T
as
Trait
>
::
Value
,
<
T
as
Trait
>
::
Oracle
Key
,
<
T
as
Trait
>
::
Oracle
Value
,
{
/// New feed data is submitted (sender, values)
NewFeedData
(
AccountId
,
Vec
<
(
Key
,
Value
)
>
),
NewFeedData
(
AccountId
,
Vec
<
(
OracleKey
,
Oracle
Value
)
>
),
}
);
impl
<
T
:
Trait
>
Module
<
T
>
{
pub
fn
read_raw_values
(
key
:
&
T
::
Key
)
->
Vec
<
TimestampedValueOf
<
T
>>
{
pub
fn
read_raw_values
(
key
:
&
T
::
Oracle
Key
)
->
Vec
<
TimestampedValueOf
<
T
>>
{
T
::
OperatorProvider
::
operators
()
.iter
()
.filter_map
(|
x
|
<
RawValues
<
T
>>
::
get
(
key
,
x
))
.collect
()
}
pub
fn
get
(
key
:
&
T
::
Key
)
->
Option
<
TimestampedValueOf
<
T
>>
{
pub
fn
get
(
key
:
&
T
::
Oracle
Key
)
->
Option
<
TimestampedValueOf
<
T
>>
{
if
<
HasUpdate
<
T
>>
::
take
(
key
)
{
let
values
=
Self
::
read_raw_values
(
key
);
let
timestamped
=
T
::
CombineData
::
combine_data
(
key
,
values
,
<
Values
<
T
>>
::
get
(
key
))
?
;
...
...
@@ -94,14 +94,14 @@ impl<T: Trait> Module<T> {
}
}
impl
<
T
:
Trait
>
DataProvider
<
T
::
Key
,
T
::
Value
>
for
Module
<
T
>
{
fn
get
(
key
:
&
T
::
Key
)
->
Option
<
T
::
Value
>
{
impl
<
T
:
Trait
>
DataProvider
<
T
::
Oracle
Key
,
T
::
Oracle
Value
>
for
Module
<
T
>
{
fn
get
(
key
:
&
T
::
Oracle
Key
)
->
Option
<
T
::
Oracle
Value
>
{
Self
::
get
(
key
)
.map
(|
timestamped_value
|
timestamped_value
.value
)
}
}
impl
<
T
:
Trait
>
Module
<
T
>
{
fn
_feed_values
(
who
:
T
::
AccountId
,
values
:
Vec
<
(
T
::
Key
,
T
::
Value
)
>
)
->
result
::
Result
<
(),
Error
>
{
fn
_feed_values
(
who
:
T
::
AccountId
,
values
:
Vec
<
(
T
::
Oracle
Key
,
T
::
Oracle
Value
)
>
)
->
result
::
Result
<
(),
Error
>
{
ensure!
(
T
::
OperatorProvider
::
can_feed_data
(
&
who
),
Error
::
NoPermission
);
let
now
=
T
::
Time
::
now
();
...
...
This diff is collapsed.
Click to expand it.
oracle/src/mock.rs
+
2
−
2
View file @
700afbcc
...
...
@@ -77,8 +77,8 @@ impl Trait for Test {
type
OperatorProvider
=
MockOperatorProvider
;
type
CombineData
=
DefaultCombineData
<
Self
>
;
type
Time
=
pallet_timestamp
::
Module
<
Self
>
;
type
Key
=
Key
;
type
Value
=
Value
;
type
Oracle
Key
=
Key
;
type
Oracle
Value
=
Value
;
}
pub
type
ModuleOracle
=
Module
<
Test
>
;
...
...
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