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
7b7fb119
Commit
7b7fb119
authored
Feb 15, 2019
by
Hero Bird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[pdsl_model] Extend messages! macro with manual identifiers
parent
3623341e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
13 deletions
+36
-13
model/examples/adder.rs
model/examples/adder.rs
+2
-2
model/examples/erc20.rs
model/examples/erc20.rs
+3
-3
model/src/lib.rs
model/src/lib.rs
+0
-2
model/src/msg.rs
model/src/msg.rs
+21
-3
model/src/msg_handler.rs
model/src/msg_handler.rs
+8
-1
model/src/test.rs
model/src/test.rs
+2
-2
No files found.
model/examples/adder.rs
View file @
7b7fb119
...
...
@@ -18,9 +18,9 @@ state! {
messages!
{
/// Increases the storage value by the given amount.
Inc
(
by
:
u32
);
0
=>
Inc
(
by
:
u32
);
/// Returns the storage value.
Get
()
->
u32
;
1
=>
Get
()
->
u32
;
}
fn
instantiate
()
->
impl
Contract
{
...
...
model/examples/erc20.rs
View file @
7b7fb119
...
...
@@ -26,13 +26,13 @@ state! {
messages!
{
/// Returns the total supply.
TotalSupply
()
->
Balance
;
0
=>
TotalSupply
()
->
Balance
;
/// Returns the balance of the given address.
BalanceOf
(
owner
:
Address
)
->
Balance
;
1
=>
BalanceOf
(
owner
:
Address
)
->
Balance
;
/// Transfers balance from the caller to the given address.
///
/// Returns `true` if the transfer was successful.
Transfer
(
to
:
Address
,
amount
:
Balance
)
->
bool
;
2
=>
Transfer
(
to
:
Address
,
amount
:
Balance
)
->
bool
;
}
fn
instantiate
()
->
impl
Contract
{
...
...
model/src/lib.rs
View file @
7b7fb119
#![cfg_attr(not(feature
=
"std"
),
no_std)]
#![feature(
const_fn,
const_str_as_bytes,
)]
#![allow(unused)]
#[macro_use]
...
...
model/src/msg.rs
View file @
7b7fb119
use
crate
::{
msg_handler
::
MessageHandlerSelector
,
};
/// A message with an expected input type and output (result) type.
pub
trait
Message
{
...
...
@@ -7,6 +10,11 @@ pub trait Message {
/// The output of the message, also known as return type.
type
Output
:
parity_codec
::
Encode
;
/// The user provided message selector.
///
/// This identifier must be unique for every message.
const
ID
:
MessageHandlerSelector
;
/// The name of the message.
///
/// # Note
...
...
@@ -19,7 +27,8 @@ pub trait Message {
#[macro_export]
macro_rules!
messages
{
(
$
(
#[
$
msg_meta:meta]
)
*
$msg_name:ident
(
$
(
#[
$
msg_meta:meta]
)
*
$msg_id:literal
=>
$msg_name:ident
(
$
(
$param_name:ident
:
$param_ty:ty
),
*
)
->
$ret_ty:ty
;
...
...
@@ -33,19 +42,28 @@ macro_rules! messages {
type
Input
=
(
$
(
$param_ty
),
*
);
type
Output
=
$ret_ty
;
const
ID
:
$crate
::
MessageHandlerSelector
=
$crate
::
MessageHandlerSelector
::
new
(
$msg_id
);
const
NAME
:
&
'static
[
u8
]
=
stringify!
(
$msg_name
)
.as_bytes
();
}
messages!
(
$
(
$rest
)
*
);
};
(
$
(
#[
$
msg_meta:meta]
)
*
$msg_name:ident
(
$
(
#[
$
msg_meta:meta]
)
*
$msg_id:literal
=>
$msg_name:ident
(
$
(
$param_name:ident
:
$param_ty:ty
),
*
)
;
$
(
$rest:tt
)
*
)
=>
{
messages!
(
$
(
#[
$
msg_meta]
)
*
$msg_name
(
$
(
$param_name
:
$param_ty
),
*
)
->
();
$
(
$rest
)
*
);
messages!
(
$
(
#[
$
msg_meta]
)
*
$msg_id
=>
$msg_name
(
$
(
$param_name
:
$param_ty
),
*
)
->
();
$
(
$rest
)
*
);
};
()
=>
{};
}
model/src/msg_handler.rs
View file @
7b7fb119
...
...
@@ -70,7 +70,14 @@ impl CallData {
/// A hash to identify a called function.
#[derive(Copy,
Clone,
PartialEq,
Eq)]
pub
struct
MessageHandlerSelector
(
pub
u64
);
pub
struct
MessageHandlerSelector
(
u32
);
impl
MessageHandlerSelector
{
/// Creates a new message handler selector from the given value.
pub
const
fn
new
(
raw
:
u32
)
->
Self
{
Self
(
raw
)
}
}
/// A read-only message handler.
///
...
...
model/src/test.rs
View file @
7b7fb119
...
...
@@ -18,9 +18,9 @@ state! {
messages!
{
/// Increases the storage value by the given amount.
Inc
(
by
:
u32
);
0
=>
Inc
(
by
:
u32
);
/// Returns the storage value.
Get
()
->
u32
;
1
=>
Get
()
->
u32
;
}
fn
instantiate
()
{
...
...
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