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
3ed67849
Commit
3ed67849
authored
7 years ago
by
asynchronous rob
Browse files
Options
Downloads
Patches
Plain Diff
use new environmental API
parent
21ab1935
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/native-runtime/support/src/lib.rs
+12
-17
12 additions, 17 deletions
substrate/native-runtime/support/src/lib.rs
with
12 additions
and
17 deletions
substrate/native-runtime/support/src/lib.rs
+
12
−
17
View file @
3ed67849
...
...
@@ -21,21 +21,17 @@ impl fmt::Display for NoError {
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
""
)
}
}
pub
struct
ExternalitiesHolder
<
'a
>
{
ext
:
&
'a
mut
Externalities
<
Error
=
NoError
>
,
}
declare_generic!
(
ext
:
ExternalitiesHolder
);
environmental!
(
ext
:
Externalities
<
Error
=
NoError
>
+
'static
);
pub
fn
storage
(
key
:
&
[
u8
])
->
Vec
<
u8
>
{
ext
::
with
(|
holder
|
holder
.
ext
.storage
(
key
)
.ok
()
.map
(|
s
|
s
.to_vec
()))
ext
::
with
(|
ext
|
ext
.storage
(
key
)
.ok
()
.map
(|
s
|
s
.to_vec
()))
.unwrap_or
(
None
)
.unwrap_or_else
(||
vec!
[])
}
pub
fn
read_storage
(
key
:
&
[
u8
],
value_out
:
&
mut
[
u8
])
->
usize
{
ext
::
with
(|
holder
|
{
if
let
Ok
(
value
)
=
holder
.
ext
.storage
(
key
)
{
ext
::
with
(|
ext
|
{
if
let
Ok
(
value
)
=
ext
.storage
(
key
)
{
let
written
=
::
std
::
cmp
::
min
(
value
.len
(),
value_out
.len
());
value_out
[
0
..
written
]
.copy_from_slice
(
&
value
[
0
..
written
]);
value
.len
()
...
...
@@ -48,8 +44,8 @@ pub fn read_storage(key: &[u8], value_out: &mut [u8]) -> usize {
pub
fn
storage_into
<
T
:
Sized
>
(
_key
:
&
[
u8
])
->
Option
<
T
>
{
let
size
=
size_of
::
<
T
>
();
ext
::
with
(|
holder
|
{
if
let
Ok
(
value
)
=
holder
.
ext
.storage
(
_key
)
{
ext
::
with
(|
ext
|
{
if
let
Ok
(
value
)
=
ext
.storage
(
_key
)
{
if
value
.len
()
==
size
{
unsafe
{
let
mut
result
:
T
=
std
::
mem
::
uninitialized
();
...
...
@@ -64,15 +60,15 @@ pub fn storage_into<T: Sized>(_key: &[u8]) -> Option<T> {
}
pub
fn
set_storage
(
_key
:
&
[
u8
],
_value
:
&
[
u8
])
{
ext
::
with
(|
holder
|
holder
.
ext
.set_storage
(
_key
.to_vec
(),
_value
.to_vec
())
ext
::
with
(|
ext
|
ext
.set_storage
(
_key
.to_vec
(),
_value
.to_vec
())
);
}
/// The current relay chain identifier.
pub
fn
chain_id
()
->
u64
{
ext
::
with
(|
holder
|
holder
.
ext
.chain_id
()
ext
::
with
(|
ext
|
ext
.chain_id
()
)
.unwrap_or
(
0
)
}
...
...
@@ -81,9 +77,8 @@ pub use tiny_keccak::keccak256;
/// Execute the given closure with global function available whose functionality routes into the
/// externalities `ext`. Forwards the value that the closure returns.
pub
fn
with_externalities
<
R
,
F
:
FnOnce
()
->
R
>
(
ext
:
&
mut
Externalities
<
Error
=
NoError
>
,
f
:
F
)
->
R
{
let
mut
h
=
ExternalitiesHolder
{
ext
};
ext
::
using
(
&
mut
h
,
f
)
pub
fn
with_externalities
<
R
,
F
:
FnOnce
()
->
R
>
(
ext
:
&
mut
(
Externalities
<
Error
=
NoError
>
+
'static
),
f
:
F
)
->
R
{
ext
::
using
(
ext
,
f
)
}
#[macro_export]
...
...
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