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
f785964d
Unverified
Commit
f785964d
authored
4 years ago
by
Xiliang Chen
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
replace SignedExtension with ValidateUnsigned (#179)
* replace SignedExtension with ValidateUnsigned * need to provide tag
parent
6292542b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
oracle/src/lib.rs
+11
-47
11 additions, 47 deletions
oracle/src/lib.rs
oracle/src/mock.rs
+0
-1
0 additions, 1 deletion
oracle/src/mock.rs
oracle/src/tests.rs
+7
-13
7 additions, 13 deletions
oracle/src/tests.rs
with
18 additions
and
61 deletions
oracle/src/lib.rs
+
11
−
47
View file @
f785964d
...
...
@@ -7,23 +7,21 @@ mod mock;
mod
tests
;
mod
timestamped_value
;
use
codec
::
{
Decode
,
Encode
}
;
use
codec
::
Encode
;
use
frame_support
::{
decl_error
,
decl_event
,
decl_module
,
decl_storage
,
dispatch
::
Dispatchable
,
ensure
,
decl_error
,
decl_event
,
decl_module
,
decl_storage
,
ensure
,
traits
::{
ChangeMembers
,
Get
,
InitializeMembers
,
Time
},
weights
::{
DispatchClass
,
FunctionOf
,
Pays
},
IsSubType
,
IterableStorageMap
,
Parameter
,
IterableStorageMap
,
Parameter
,
};
use
sp_runtime
::{
traits
::
{
DispatchInfoOf
,
Member
,
SignedExtension
}
,
traits
::
Member
,
transaction_validity
::{
InvalidTransaction
,
TransactionPriority
,
Transaction
Validity
,
TransactionValidity
Error
,
ValidTransaction
,
InvalidTransaction
,
TransactionPriority
,
Transaction
Source
,
TransactionValidity
,
ValidTransaction
,
},
DispatchResult
,
};
use
sp_std
::{
fmt
,
prelude
::
*
,
result
,
vec
};
use
sp_std
::{
prelude
::
*
,
vec
};
// FIXME: `pallet/frame-` prefix should be used for all pallet modules, but currently `frame_system`
// would cause compiling error in `decl_module!` and `construct_runtime!`
// #3295 https://github.com/paritytech/substrate/issues/3295
...
...
@@ -57,7 +55,6 @@ pub type TimestampedValueOf<T> = TimestampedValue<<T as Trait>::OracleValue, Mom
pub
trait
Trait
:
frame_system
::
Trait
{
type
Event
:
From
<
Event
<
Self
>>
+
Into
<<
Self
as
frame_system
::
Trait
>
::
Event
>
;
type
Call
:
Parameter
+
Dispatchable
<
Origin
=
<
Self
as
frame_system
::
Trait
>
::
Origin
>
+
IsSubType
<
Module
<
Self
>
,
Self
>
;
type
OnNewData
:
OnNewData
<
Self
::
AccountId
,
Self
::
OracleKey
,
Self
::
OracleValue
>
;
type
CombineData
:
CombineData
<
Self
::
OracleKey
,
TimestampedValueOf
<
Self
>>
;
type
Time
:
Time
;
...
...
@@ -265,44 +262,10 @@ impl<T: Trait> DataProviderExtended<T::OracleKey, T::OracleValue, T::AccountId>
}
}
#[derive(Encode,
Decode,
Clone,
Eq,
PartialEq,
Default)]
pub
struct
CheckOperator
<
T
:
Trait
+
Send
+
Sync
>
(
sp_std
::
marker
::
PhantomData
<
T
>
);
impl
<
T
:
Trait
+
Send
+
Sync
>
CheckOperator
<
T
>
{
pub
fn
new
()
->
Self
{
Self
(
sp_std
::
marker
::
PhantomData
)
}
}
impl
<
T
:
Trait
+
Send
+
Sync
>
fmt
::
Debug
for
CheckOperator
<
T
>
{
#[cfg(feature
=
"std"
)]
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"CheckOperator"
)
}
#[cfg(not(feature
=
"std"
))]
fn
fmt
(
&
self
,
_
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
Ok
(())
}
}
impl
<
T
:
Trait
+
Send
+
Sync
>
SignedExtension
for
CheckOperator
<
T
>
{
const
IDENTIFIER
:
&
'static
str
=
"CheckOperator"
;
type
AccountId
=
T
::
AccountId
;
type
Call
=
<
T
as
Trait
>
::
Call
;
type
AdditionalSigned
=
();
type
Pre
=
();
fn
additional_signed
(
&
self
)
->
result
::
Result
<
(),
TransactionValidityError
>
{
Ok
(())
}
fn
validate_unsigned
(
call
:
&
Self
::
Call
,
_info
:
&
DispatchInfoOf
<
Self
::
Call
>
,
_len
:
usize
)
->
TransactionValidity
{
let
call
=
match
call
.is_sub_type
()
{
Some
(
call
)
=>
call
,
None
=>
return
Ok
(
ValidTransaction
::
default
()),
};
impl
<
T
:
Trait
>
frame_support
::
unsigned
::
ValidateUnsigned
for
Module
<
T
>
{
type
Call
=
Call
<
T
>
;
fn
validate_unsigned
(
_source
:
TransactionSource
,
call
:
&
Self
::
Call
)
->
TransactionValidity
{
if
let
Call
::
feed_values
(
value
,
index
,
signature
)
=
call
{
let
members
=
Module
::
<
T
>
::
members
();
let
who
=
members
.0
.get
(
*
index
as
usize
);
...
...
@@ -326,8 +289,9 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckOperator<T> {
Nonces
::
<
T
>
::
insert
(
who
,
nonce
+
1
);
ValidTransaction
::
with_tag_prefix
(
"
O
racle"
)
ValidTransaction
::
with_tag_prefix
(
"
orml-o
racle"
)
.priority
(
T
::
UnsignedPriority
::
get
())
.and_provides
((
who
,
nonce
))
.longevity
(
256
)
.propagate
(
true
)
.build
()
...
...
This diff is collapsed.
Click to expand it.
oracle/src/mock.rs
+
0
−
1
View file @
f785964d
...
...
@@ -89,7 +89,6 @@ parameter_types! {
impl
Trait
for
Test
{
type
Event
=
();
type
Call
=
Call
;
type
OnNewData
=
();
type
CombineData
=
DefaultCombineData
<
Self
,
MinimumCount
,
ExpiresIn
>
;
type
Time
=
Timestamp
;
...
...
This diff is collapsed.
Click to expand it.
oracle/src/tests.rs
+
7
−
13
View file @
f785964d
#![cfg(test)]
use
crate
::{
mock
::{
new_test_ext
,
Call
,
ModuleOracle
,
OracleCall
,
Origin
,
Test
,
Timestamp
},
{
CheckOperator
,
TimestampedValue
}
,
mock
::{
new_test_ext
,
ModuleOracle
,
OracleCall
,
Origin
,
Timestamp
},
TimestampedValue
,
};
use
codec
::
Encode
;
use
frame_support
::{
assert_noop
,
assert_ok
,
dispatch
,
traits
::{
ChangeMembers
,
OnFinalize
},
weights
::{
DispatchClass
,
DispatchInfo
,
Pays
}
,
unsigned
::
ValidateUnsigned
,
};
use
sp_runtime
::{
testing
::
UintAuthorityId
,
traits
::
SignedExtension
,
transaction_validity
::{
InvalidTransaction
,
TransactionValidityError
},
transaction_validity
::{
InvalidTransaction
,
TransactionSource
,
TransactionValidityError
},
RuntimeAppPublic
,
};
...
...
@@ -25,14 +24,9 @@ fn feed_values_from_session_key(
)
->
Result
<
dispatch
::
DispatchResult
,
TransactionValidityError
>
{
let
sig
=
id
.sign
(
&
(
nonce
,
&
values
)
.encode
())
.unwrap
();
CheckOperator
::
<
Test
>
::
validate_unsigned
(
&
Call
::
ModuleOracle
(
OracleCall
::
feed_values
(
values
.clone
(),
index
,
sig
.clone
())),
&
DispatchInfo
{
weight
:
0
,
class
:
DispatchClass
::
Normal
,
pays_fee
:
Pays
::
Yes
,
},
0
,
<
ModuleOracle
as
ValidateUnsigned
>
::
validate_unsigned
(
TransactionSource
::
External
,
&
OracleCall
::
feed_values
(
values
.clone
(),
index
,
sig
.clone
()),
)
?
;
Ok
(
ModuleOracle
::
feed_values
(
Origin
::
NONE
,
values
,
index
,
sig
))
...
...
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