Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
I
ink
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
parity
ink
Commits
e61f3e3f
Commit
e61f3e3f
authored
Jan 24, 2019
by
Hero Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[examples/erc20] Add missing flushing functionality
For now kept super ugly but it should work at least ...
parent
b7f65d4f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
11 deletions
+37
-11
examples/erc20/src/lib.rs
examples/erc20/src/lib.rs
+37
-11
No files found.
examples/erc20/src/lib.rs
View file @
e61f3e3f
#![no_std]
use
pdsl_core
::{
storage
::{
self
,
Key
,
alloc
::
ForwardAlloc
,
},
storage
,
env
::{
Env
,
ContractEnv
,
srml
::
Address
,
srml
::
Balance
},
};
use
parity_codec
::{
Encode
,
Decode
};
...
...
@@ -94,6 +90,16 @@ impl Erc20Token {
}
}
// BELOW THIS EVERYTHING WILL EVENTUALLY BE GENERATED BY THE eDSL
use
pdsl_core
::{
storage
::{
alloc
::
ForwardAlloc
,
Flush
,
Key
,
},
};
impl
Erc20Token
{
/// Creates new ERC-20 token using the given allocator.
pub
unsafe
fn
new_using_alloc
<
A
>
(
alloc
:
&
mut
A
)
->
Self
...
...
@@ -108,6 +114,14 @@ impl Erc20Token {
}
}
impl
Flush
for
Erc20Token
{
fn
flush
(
&
mut
self
)
{
self
.balances
.flush
();
self
.allowances
.flush
();
self
.total_supply
.flush
();
}
}
/// Erc20Token API.
#[derive(Encode,
Decode)]
enum
Action
{
...
...
@@ -144,22 +158,34 @@ pub extern "C" fn call() {
let
mut
erc20token
=
unsafe
{
Erc20Token
::
new_using_alloc
(
&
mut
alloc
)
};
match
action
{
Action
::
TotalSupply
=>
{
ret
(
erc20token
.total_supply
())
let
ret_val
=
erc20token
.total_supply
();
erc20token
.flush
();
ret
(
ret_val
);
}
Action
::
BalanceOf
{
owner
}
=>
{
ret
(
erc20token
.balance_of
(
owner
))
let
ret_val
=
erc20token
.balance_of
(
owner
);
erc20token
.flush
();
ret
(
ret_val
);
}
Action
::
Allowance
{
owner
,
spender
}
=>
{
ret
(
erc20token
.allowance
(
owner
,
spender
))
let
ret_val
=
erc20token
.allowance
(
owner
,
spender
);
erc20token
.flush
();
ret
(
ret_val
);
}
Action
::
Transfer
{
to
,
value
}
=>
{
ret
(
erc20token
.transfer
(
to
,
value
))
let
ret_val
=
erc20token
.transfer
(
to
,
value
);
erc20token
.flush
();
ret
(
ret_val
);
}
Action
::
Approve
{
spender
,
value
}
=>
{
ret
(
erc20token
.approve
(
spender
,
value
))
let
ret_val
=
erc20token
.approve
(
spender
,
value
);
erc20token
.flush
();
ret
(
ret_val
);
}
Action
::
TransferFrom
{
from
,
to
,
value
}
=>
{
ret
(
erc20token
.transfer_from
(
from
,
to
,
value
))
let
ret_val
=
erc20token
.transfer_from
(
from
,
to
,
value
);
erc20token
.flush
();
ret
(
ret_val
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment