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
2e6300ca
Commit
2e6300ca
authored
7 years ago
by
Gav
Browse files
Options
Downloads
Patches
Plain Diff
Add marshaller for xfer function
parent
adbeecbd
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/wasm-runtime/polkadot/src/lib.rs
+32
-4
32 additions, 4 deletions
substrate/wasm-runtime/polkadot/src/lib.rs
with
32 additions
and
4 deletions
substrate/wasm-runtime/polkadot/src/lib.rs
+
32
−
4
View file @
2e6300ca
...
...
@@ -22,6 +22,7 @@ pub type TxOrder = u64;
pub
enum
Function
{
StakingStake
,
StakingUnstake
,
StakingTransferStake
,
ConsensusSetSessionKey
,
}
...
...
@@ -35,6 +36,11 @@ impl Function {
Function
::
StakingUnstake
=>
{
staking
::
unstake
(
transactor
);
}
Function
::
StakingTransferStake
=>
{
let
dest
=
FromSlice
::
from_slice
(
&
params
[
0
..
size_of
::
<
AccountID
>
()])
.unwrap
();
let
value
=
FromSlice
::
from_slice
(
&
params
[
size_of
::
<
AccountID
>
()
..
size_of
::
<
AccountID
>
()
+
4
])
.unwrap
();
staking
::
transfer_stake
(
transactor
,
&
dest
,
value
);
}
Function
::
ConsensusSetSessionKey
=>
{
let
mut
session
=
AccountID
::
default
();
session
.copy_from_slice
(
&
params
[
0
..
size_of
::
<
AccountID
>
()]);
...
...
@@ -140,8 +146,8 @@ macro_rules! impl_non_endians {
)
*
}
}
impl_endians!
(
u8
,
u16
,
u32
,
u64
,
usize
,
i8
,
i16
,
i32
,
i64
,
isize
);
impl_non_endians!
([
u8
;
20
],
[
u8
;
32
]);
impl_endians!
(
u16
,
u32
,
u64
,
usize
,
i16
,
i32
,
i64
,
isize
);
impl_non_endians!
(
u8
,
i8
,
[
u8
;
20
],
[
u8
;
32
]);
trait
Storage
{
fn
storage_into
(
key
:
&
[
u8
])
->
Self
;
...
...
@@ -150,7 +156,9 @@ trait Storage {
impl
<
T
:
Default
+
EndianSensitive
>
Storage
for
T
{
fn
storage_into
(
key
:
&
[
u8
])
->
Self
{
runtime_support
::
storage_into
(
key
)
.map
(
EndianSensitive
::
from_le
)
.unwrap_or_else
(
Default
::
default
)
runtime_support
::
storage_into
(
key
)
.map
(
EndianSensitive
::
from_le
)
.unwrap_or_else
(
Default
::
default
)
}
fn
store
(
self
,
key
:
&
[
u8
])
{
...
...
@@ -167,6 +175,26 @@ fn storage_into<T: Storage>(key: &[u8]) -> T {
T
::
storage_into
(
key
)
}
trait
FromSlice
:
Sized
{
fn
from_slice
(
value
:
&
[
u8
])
->
Option
<
Self
>
;
}
impl
<
T
:
EndianSensitive
>
FromSlice
for
T
{
fn
from_slice
(
value
:
&
[
u8
])
->
Option
<
Self
>
{
let
size
=
size_of
::
<
T
>
();
if
value
.len
()
==
size
{
unsafe
{
let
mut
result
:
T
=
std
::
mem
::
uninitialized
();
std
::
slice
::
from_raw_parts_mut
(
transmute
::
<*
mut
T
,
*
mut
u8
>
(
&
mut
result
),
size
)
.copy_from_slice
(
&
value
);
Some
(
result
.from_le
())
}
}
else
{
None
}
}
}
trait
KeyedVec
{
fn
to_keyed_vec
(
&
self
,
prepend_key
:
&
[
u8
])
->
Vec
<
u8
>
;
}
...
...
@@ -196,7 +224,7 @@ macro_rules! impl_endians {
)
*
}
}
impl_endians!
(
u8
,
u16
,
u32
,
u64
,
usize
,
i8
,
i16
,
i32
,
i64
,
isize
);
impl_endians!
(
u16
,
u32
,
u64
,
usize
,
i16
,
i32
,
i64
,
isize
);
// TODO: include RLP implementation
// TODO: add keccak256 (or some better hashing scheme) & ECDSA-recover (or some better sig scheme)
...
...
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