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
b8dd4c4d
Commit
b8dd4c4d
authored
Feb 13, 2019
by
Hero Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[pdsl_model] Adjust example contracts to new interfaces
Make them work actually or at least compile.
parent
b61ad390
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
27 deletions
+30
-27
model/examples/adder.rs
model/examples/adder.rs
+9
-8
model/examples/erc20.rs
model/examples/erc20.rs
+21
-19
No files found.
model/examples/adder.rs
View file @
b8dd4c4d
use
crate
::{
contract
::
ContractDecl
,
state
::
ContractState
,
msg
::
Message
,
#![feature(const_str_as_bytes)]
use
pdsl_model
::{
ContractDecl
,
Contract
,
state
,
messages
,
};
use
pdsl_core
::
storage
;
use
crate
as
pdsl_model
;
// TODO: We really don't want this as a hack to make state! work.
state!
{
/// A simple contract having just one value that can be incremented and returned.
struct
Adder
{
...
...
@@ -22,7 +23,7 @@ messages! {
Get
()
->
u32
;
}
fn
instantiate
()
->
impl
Contract
Instance
{
fn
instantiate
()
->
impl
Contract
{
ContractDecl
::
new
::
<
Adder
>
()
.on_deploy
(|
env
,
init_val
|
{
env
.state.val
.set
(
init_val
)
...
...
@@ -43,5 +44,5 @@ fn deploy() {
#[no_mangle]
fn
call
()
{
instantiate
()
.
run
()
instantiate
()
.
dispatch
()
}
model/examples/erc20.rs
View file @
b8dd4c4d
use
crate
::{
contract
::
ContractDecl
,
state
::
ContractState
,
msg
::
Message
,
#![feature(const_str_as_bytes)]
use
pdsl_model
::{
ContractDecl
,
Contract
,
state
,
messages
,
};
use
pdsl_core
::{
env
::{
Env
,
ContractEnv
,
srml
::
Address
,
srml
::
Balance
,
},
...
...
@@ -19,7 +20,7 @@ state! {
/// The balance for an address.
balances
:
storage
::
HashMap
<
Address
,
Balance
>
,
/// The total supply.
total
:
storage
::
Value
<
Balance
>
,
total
:
storage
::
Value
<
Balance
>
}
}
...
...
@@ -34,29 +35,30 @@ messages! {
Transfer
(
to
:
Address
,
amount
:
Balance
)
->
bool
;
}
fn
instantiate
()
->
impl
Contract
Instance
{
Contract
::
new
::
<
Erc20Token
>
()
fn
instantiate
()
->
impl
Contract
{
Contract
Decl
::
new
::
<
Erc20Token
>
()
.on_deploy
(|
env
,
init_supply
|
{
env
.state.balances
[
ContractEnv
::
caller
()]
=
init_supply
;
let
caller
=
env
.caller
();
env
.state.balances
[
&
caller
]
=
init_supply
;
env
.state.total
.set
(
init_supply
);
})
.on_msg
::
<
TotalSupply
>
(|
env
,
_
|
{
*
env
.state.total
.get
()
})
.on_msg
::
<
BalanceOf
>
(|
env
,
owner
|
{
env
.state.balances
[
owner
]
env
.state.balances
[
&
owner
]
})
.on_msg_mut
::
<
Transfer
>
(|
env
,
(
to
,
amount
)|
{
if
amount
==
Address
::
from
(
0x0
)
{
return
false
;
}
// if amount == Address::from(0x0) { // In Substrate we do not have the zero address!
//
return false;
//
}
let
from
=
env
.caller
();
let
balance_from
=
env
.state.balances
[
from
];
let
balance_to
=
env
.state.balances
[
to
];
let
balance_from
=
env
.state.balances
[
&
from
];
let
balance_to
=
env
.state.balances
[
&
to
];
if
balance_from
>=
amount
{
env
.state.balances
[
from
]
=
existing
_from
-
amount
;
env
.state.balances
[
to
]
=
existing
_to
+
amount
;
env
.state.balances
[
&
from
]
=
balance
_from
-
amount
;
env
.state.balances
[
&
to
]
=
balance
_to
+
amount
;
return
true
}
...
...
@@ -72,5 +74,5 @@ fn deploy() {
#[no_mangle]
fn
call
()
{
instantiate
()
.
run
()
instantiate
()
.
dispatch
()
}
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