Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
b9f10200
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b9f10200
编写于
11月 02, 2017
作者:
B
Brian Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Making Contract API functions and methods conform to our naming standard.
上级
7435d469
变更
30
展开全部
隐藏空白更改
内联
并排
Showing
30 changed file
with
381 addition
and
375 deletion
+381
-375
contracts/currency/currency.cpp
contracts/currency/currency.cpp
+3
-3
contracts/dice/dice.cpp
contracts/dice/dice.cpp
+1
-1
contracts/eoslib/chain.h
contracts/eoslib/chain.h
+3
-3
contracts/eoslib/db.h
contracts/eoslib/db.h
+8
-8
contracts/eoslib/message.h
contracts/eoslib/message.h
+20
-13
contracts/eoslib/message.hpp
contracts/eoslib/message.hpp
+9
-9
contracts/eoslib/transaction.h
contracts/eoslib/transaction.h
+10
-10
contracts/eoslib/transaction.hpp
contracts/eoslib/transaction.hpp
+23
-23
contracts/exchange/exchange.cpp
contracts/exchange/exchange.cpp
+13
-13
contracts/infinite/infinite.cpp
contracts/infinite/infinite.cpp
+4
-4
contracts/proxy/proxy.cpp
contracts/proxy/proxy.cpp
+5
-5
contracts/simpledb/simpledb.cpp
contracts/simpledb/simpledb.cpp
+5
-5
contracts/simpledb/simpledb.gen.hpp
contracts/simpledb/simpledb.gen.hpp
+7
-7
contracts/social/social.cpp
contracts/social/social.cpp
+4
-4
contracts/storage/storage.cpp
contracts/storage/storage.cpp
+21
-21
contracts/test_api/test_api.cpp
contracts/test_api/test_api.cpp
+1
-1
contracts/test_api/test_api.hpp
contracts/test_api/test_api.hpp
+1
-1
contracts/test_api/test_chain.cpp
contracts/test_api/test_chain.cpp
+3
-3
contracts/test_api/test_db.cpp
contracts/test_api/test_db.cpp
+151
-151
contracts/test_api/test_math.cpp
contracts/test_api/test_math.cpp
+3
-3
contracts/test_api/test_message.cpp
contracts/test_api/test_message.cpp
+21
-21
contracts/test_api/test_transaction.cpp
contracts/test_api/test_transaction.cpp
+25
-25
contracts/tic_tac_toe/tic_tac_toe.cpp
contracts/tic_tac_toe/tic_tac_toe.cpp
+8
-8
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+16
-17
programs/codegen/main.cpp
programs/codegen/main.cpp
+5
-5
tests/api_tests/api_tests.cpp
tests/api_tests/api_tests.cpp
+1
-1
tests/slow_tests/slow_tests.cpp
tests/slow_tests/slow_tests.cpp
+2
-2
tests/slow_tests/wast/loop.cpp
tests/slow_tests/wast/loop.cpp
+3
-3
tests/slow_tests/wast/simplecoin.cpp
tests/slow_tests/wast/simplecoin.cpp
+3
-3
tests/tests/contracts/rate_limit_auth/rate_limit_auth.cpp
tests/tests/contracts/rate_limit_auth/rate_limit_auth.cpp
+2
-2
未找到文件。
contracts/currency/currency.cpp
浏览文件 @
b9f10200
...
...
@@ -20,8 +20,8 @@ namespace TOKEN_NAME {
}
void
apply_currency_transfer
(
const
TOKEN_NAME
::
Transfer
&
transfer
)
{
require
N
otice
(
transfer
.
to
,
transfer
.
from
);
require
A
uth
(
transfer
.
from
);
require
_n
otice
(
transfer
.
to
,
transfer
.
from
);
require
_a
uth
(
transfer
.
from
);
auto
from
=
getAccount
(
transfer
.
from
);
auto
to
=
getAccount
(
transfer
.
to
);
...
...
@@ -46,7 +46,7 @@ extern "C" {
void
apply
(
uint64_t
code
,
uint64_t
action
)
{
if
(
code
==
N
(
currency
)
)
{
if
(
action
==
N
(
transfer
)
)
currency
::
apply_currency_transfer
(
current
M
essage
<
TOKEN_NAME
::
Transfer
>
()
);
currency
::
apply_currency_transfer
(
current
_m
essage
<
TOKEN_NAME
::
Transfer
>
()
);
}
}
}
contracts/dice/dice.cpp
浏览文件 @
b9f10200
...
...
@@ -8,7 +8,7 @@ namespace dice {
void
apply_offer
(
const
OfferBet
&
offer
)
{
assert
(
offer
.
amount
>
0
,
"insufficient bet"
);
assert
(
!
hasOffer
(
offer
.
commitment
),
"offer with this commitment already exist"
);
require
A
uth
(
offer
.
player
);
require
_a
uth
(
offer
.
player
);
auto
acnt
=
getAccount
(
offer
.
player
);
acnt
.
balance
-=
offer
.
amount
;
...
...
contracts/eoslib/chain.h
浏览文件 @
b9f10200
...
...
@@ -21,11 +21,11 @@ extern "C" {
* Example:
* @code
* AccountName producers[21];
* get
ActiveP
roducers(producers, sizeof(AccountName)*21);
* get
_active_p
roducers(producers, sizeof(AccountName)*21);
* @endcode
*/
void
get
ActiveP
roducers
(
AccountName
*
producers
,
uint32_t
datalen
);
void
get
_active_p
roducers
(
AccountName
*
producers
,
uint32_t
datalen
);
///@ } chaincapi
}
\ No newline at end of file
}
contracts/eoslib/db.h
浏览文件 @
b9f10200
...
...
@@ -81,33 +81,33 @@ extern "C" {
* res = store_i64(CurrentCOde(), N(test_table), &alice, sizeof(TestModel));
* TestModel alice;
* alice.name = N(alice);
* res = load_i64( current
Code(), currentC
ode(), N(test_table), &alice, sizeof(TestModel) );
* res = load_i64( current
_code(), current_c
ode(), N(test_table), &alice, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && tmp.name == N(alice) && tmp.age == 20 && tmp.phone == 4234622, "load_i64");
*
* res = front_i64( current
Code(), currentC
ode(), N(test_table), &tmp, sizeof(TestModel) );
* res = front_i64( current
_code(), current_c
ode(), N(test_table), &tmp, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && tmp.name == N(alice) && tmp.age == 20 && tmp.phone == 4234622, "front_i64 1");
*
* res = back_i64( current
Code(), currentC
ode(), N(test_table), &tmp, sizeof(TestModel) );
* res = back_i64( current
_code(), current_c
ode(), N(test_table), &tmp, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && tmp.name == N(dave) && tmp.age == 46 && tmp.phone == 6535354, "back_i64 2");
*
* res = previous_i64( current
Code(), currentC
ode(), N(test_table), &tmp, sizeof(TestModel) );
* res = previous_i64( current
_code(), current_c
ode(), N(test_table), &tmp, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && tmp.name == N(carol) && tmp.age == 30 && tmp.phone == 545342453, "carol previous");
*
* res = next_i64( current
Code(), currentC
ode(), N(test_table), &tmp, sizeof(TestModel) );
* res = next_i64( current
_code(), current_c
ode(), N(test_table), &tmp, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && tmp.name == N(dave) && tmp.age == 46 && tmp.phone == 6535354, "back_i64 2");
*
* uint64_t key = N(alice);
* res = remove_i64(current
C
ode(), N(test_table), &key);
* res = remove_i64(current
_c
ode(), N(test_table), &key);
* ASSERT(res == 1, "remove alice");
*
* TestModel lb;
* lb.name = N(bob);
* res = lower_bound_i64( current
Code(), currentC
ode(), N(test_table), &lb, sizeof(TestModel) );
* res = lower_bound_i64( current
_code(), current_c
ode(), N(test_table), &lb, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && lb.name == N(bob), "lower_bound_i64 bob" );
*
* TestModel ub;
* ub.name = N(alice);
* res = upper_bound_i64( current
Code(), currentC
ode(), N(test_table), &ub, sizeof(TestModel) );
* res = upper_bound_i64( current
_code(), current_c
ode(), N(test_table), &ub, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && ub.age == 15 && ub.name == N(bob), "upper_bound_i64 bob" );
* @endcode
* @{
...
...
contracts/eoslib/message.h
浏览文件 @
b9f10200
...
...
@@ -47,22 +47,22 @@ extern "C" {
* // }
*
* char buffer[128];
* uint32_t total = read
M
essage(buffer, 5); // buffer contains the content of the message up to 5 bytes
* uint32_t total = read
_m
essage(buffer, 5); // buffer contains the content of the message up to 5 bytes
* print(total); // Output: 5
*
* uint32_t msgsize = message
S
ize();
* uint32_t msgsize = message
_s
ize();
* print(msgsize); // Output: size of the above message's data field
*
* require
N
otice(N(initc)); // initc account will be notified for this message
* require
_n
otice(N(initc)); // initc account will be notified for this message
*
* require
A
uth(N(inita)); // Do nothing since inita exists in the auth list
* require
A
uth(N(initb)); // Throws an exception
* require
_a
uth(N(inita)); // Do nothing since inita exists in the auth list
* require
_a
uth(N(initb)); // Throws an exception
*
* AccountName code = current
C
ode();
* AccountName code = current
_c
ode();
* print(Name(code)); // Output: eos
*
* assert(Name(current
C
ode()) === "eos", "This message expects to be received by eos"); // Do nothing
* assert(Name(current
C
ode()) === "inita", "This message expects to be received by inita"); // Throws exception and roll back transfer transaction
* assert(Name(current
_c
ode()) === "eos", "This message expects to be received by eos"); // Do nothing
* assert(Name(current
_c
ode()) === "inita", "This message expects to be received by inita"); // Throws exception and roll back transfer transaction
*
* print(now()); // Output: timestamp of last accepted block
*
...
...
@@ -79,7 +79,7 @@ extern "C" {
* @param len - len of the current message to be copied
* @return the number of bytes copied to msg
*/
uint32_t
readM
essage
(
void
*
msg
,
uint32_t
len
);
uint32_t
read_m
essage
(
void
*
msg
,
uint32_t
len
);
/**
* Get the length of the current message's data field
...
...
@@ -87,28 +87,35 @@ extern "C" {
* @brief Get the length of current message's data field
* @return the length of the current message's data field
*/
uint32_t
messageS
ize
();
uint32_t
message_s
ize
();
/**
* Add the specified account to set of accounts to be notified
* @brief Add the specified account to set of accounts to be notified
* @param name - name of the account to be verified
*/
void
require
N
otice
(
AccountName
name
);
void
require
_n
otice
(
AccountName
name
);
/**
* Verifies that @ref name exists in the set of provided auths on a message. Throws if not found
* @brief Verify specified account exists in the set of provided auths
* @param name - name of the account to be verified
*/
void
requireAuth
(
AccountName
name
);
void
require_auth
(
AccountName
name
);
/**
* Verifies that @ref name exists in the scope on a message. Throws if not found
* @brief Verify specified account exists in the scope
* @param name - name of the account to be verified
*/
void
require_scope
(
AccountName
name
);
/**
* Get the account which specifies the code that is being run
* @brief Get the account which specifies the code that is being run
* @return the account which specifies the code that is being run
*/
AccountName
current
C
ode
();
AccountName
current
_c
ode
();
///@ } messagecapi
}
contracts/eoslib/message.hpp
浏览文件 @
b9f10200
...
...
@@ -32,19 +32,19 @@ namespace eos {
* unsigned long long b; //8
* int c; //4
* };
* dummy_message msg = current
M
essage<dummy_message>();
* dummy_message msg = current
_m
essage<dummy_message>();
* @endcode
*/
template
<
typename
T
>
T
current
M
essage
()
{
T
current
_m
essage
()
{
T
value
;
auto
read
=
read
M
essage
(
&
value
,
sizeof
(
value
)
);
auto
read
=
read
_m
essage
(
&
value
,
sizeof
(
value
)
);
assert
(
read
>=
sizeof
(
value
),
"message shorter than expected"
);
return
value
;
}
using
::
require
A
uth
;
using
::
require
N
otice
;
using
::
require
_a
uth
;
using
::
require
_n
otice
;
/**
* All of the listed accounts will be added to the set of accounts to be notified
...
...
@@ -58,13 +58,13 @@ namespace eos {
*
* Example:
* @code
* require
N
otice(N(Account1), N(Account2), N(Account3)); // throws exception if any of them not in set.
* require
_n
otice(N(Account1), N(Account2), N(Account3)); // throws exception if any of them not in set.
* @endcode
*/
template
<
typename
...
Accounts
>
void
require
N
otice
(
AccountName
name
,
Accounts
...
accounts
){
require
N
otice
(
name
);
require
N
otice
(
accounts
...
);
void
require
_n
otice
(
AccountName
name
,
Accounts
...
accounts
){
require
_n
otice
(
name
);
require
_n
otice
(
accounts
...
);
}
...
...
contracts/eoslib/transaction.h
浏览文件 @
b9f10200
...
...
@@ -76,7 +76,7 @@ extern "C" {
*
* @return handle used to refer to this transaction in future API calls
*/
TransactionHandle
transaction
C
reate
();
TransactionHandle
transaction
_c
reate
();
/**
* @brief require a scope to process a pending transaction
...
...
@@ -88,7 +88,7 @@ extern "C" {
* @param scope - the `AccountName` to add
* @param readOnly - whether `scope` should be added to `scope[]` or `readScope[]`
*/
void
transaction
RequireS
cope
(
TransactionHandle
trx
,
AccountName
scope
,
int
readOnly
=
0
);
void
transaction
_require_s
cope
(
TransactionHandle
trx
,
AccountName
scope
,
int
readOnly
=
0
);
/**
* @brief finalize the pending message and add it to the transaction
...
...
@@ -98,7 +98,7 @@ extern "C" {
* @param trx - the `TransactionHandle` of the pending transaction to modify
* @param msg - the `MessageHandle` of the pending message to add
*/
void
transaction
AddM
essage
(
TransactionHandle
trx
,
MessageHandle
msg
);
void
transaction
_add_m
essage
(
TransactionHandle
trx
,
MessageHandle
msg
);
/**
...
...
@@ -112,7 +112,7 @@ extern "C" {
*
* @param trx - the `TransactionHandle` of the pending transaction to send
*/
void
transaction
S
end
(
TransactionHandle
trx
);
void
transaction
_s
end
(
TransactionHandle
trx
);
/**
* @brief drop a pending transaction
...
...
@@ -124,7 +124,7 @@ extern "C" {
*
* @param trx - the `TransactionHandle` of the pending transaction to send
*/
void
transaction
D
rop
(
TransactionHandle
trx
);
void
transaction
_d
rop
(
TransactionHandle
trx
);
/**
...
...
@@ -133,14 +133,14 @@ extern "C" {
* This function creates a pending message to be included in a deferred
* transaction or to be send as an inline message
*
* This message has no default permissions, see @ref message
RequireP
ermission
* This message has no default permissions, see @ref message
_require_p
ermission
*
* @param code - the `AccountName` which owns the contract code to execute
* @param type - the type of this message
* @param data - the payload data for this message
* @param size - the size of `data`
*/
MessageHandle
message
C
reate
(
AccountName
code
,
FuncName
type
,
void
const
*
data
,
int
size
);
MessageHandle
message
_c
reate
(
AccountName
code
,
FuncName
type
,
void
const
*
data
,
int
size
);
/**
* @brief require a permission for the pending message
...
...
@@ -151,7 +151,7 @@ extern "C" {
* @param account - the `AccountName` to of the permission
* @param permission - the `PermissionName` to of the permision
*/
void
message
RequireP
ermission
(
MessageHandle
msg
,
AccountName
account
,
PermissionName
permission
);
void
message
_require_p
ermission
(
MessageHandle
msg
,
AccountName
account
,
PermissionName
permission
);
/**
...
...
@@ -161,7 +161,7 @@ extern "C" {
*
* @param msg - the `MessageHandle` of the pending message to send inline
*/
void
message
S
end
(
MessageHandle
msg
);
void
message
_s
end
(
MessageHandle
msg
);
/**
...
...
@@ -171,7 +171,7 @@ extern "C" {
*
* @param trx - the `MessageHandle` of the pending message to discard
*/
void
message
D
rop
(
MessageHandle
msg
);
void
message
_d
rop
(
MessageHandle
msg
);
///@ } transactioncapi
...
...
contracts/eoslib/transaction.hpp
浏览文件 @
b9f10200
...
...
@@ -23,19 +23,19 @@ namespace eos {
public:
template
<
typename
Payload
,
typename
...
Permissions
>
Message
(
const
AccountName
&
code
,
const
FuncName
&
type
,
const
Payload
&
payload
,
Permissions
...
permissions
)
:
handle
(
message
C
reate
(
code
,
type
,
&
payload
,
sizeof
(
Payload
)))
:
handle
(
message
_c
reate
(
code
,
type
,
&
payload
,
sizeof
(
Payload
)))
{
add
P
ermissions
(
permissions
...);
add
_p
ermissions
(
permissions
...);
}
template
<
typename
Payload
>
Message
(
const
AccountName
&
code
,
const
FuncName
&
type
,
const
Payload
&
payload
)
:
handle
(
message
C
reate
(
code
,
type
,
&
payload
,
sizeof
(
Payload
)))
:
handle
(
message
_c
reate
(
code
,
type
,
&
payload
,
sizeof
(
Payload
)))
{
}
Message
(
const
AccountName
&
code
,
const
FuncName
&
type
)
:
handle
(
message
C
reate
(
code
,
type
,
nullptr
,
0
))
:
handle
(
message
_c
reate
(
code
,
type
,
nullptr
,
0
))
{
}
...
...
@@ -49,29 +49,29 @@ namespace eos {
~
Message
()
{
if
(
handle
!=
InvalidMessageHandle
)
{
message
D
rop
(
handle
);
message
_d
rop
(
handle
);
handle
=
InvalidMessageHandle
;
}
}
void
add
P
ermissions
(
AccountName
account
,
PermissionName
permission
)
{
message
RequireP
ermission
(
handle
,
account
,
permission
);
void
add
_p
ermissions
(
AccountName
account
,
PermissionName
permission
)
{
message
_require_p
ermission
(
handle
,
account
,
permission
);
}
template
<
typename
...
Permissions
>
void
add
P
ermissions
(
AccountName
account
,
PermissionName
permission
,
Permissions
...
permissions
)
{
add
P
ermissions
(
account
,
permission
);
add
P
ermissions
(
permissions
...);
void
add
_p
ermissions
(
AccountName
account
,
PermissionName
permission
,
Permissions
...
permissions
)
{
add
_p
ermissions
(
account
,
permission
);
add
_p
ermissions
(
permissions
...);
}
void
send
()
{
assert
ValidH
andle
();
message
S
end
(
handle
);
assert
_valid_h
andle
();
message
_s
end
(
handle
);
handle
=
InvalidMessageHandle
;
}
private:
void
assert
ValidH
andle
()
{
void
assert
_valid_h
andle
()
{
assert
(
handle
!=
InvalidMessageHandle
,
"attempting to send or modify a finalized message"
);
}
...
...
@@ -84,7 +84,7 @@ namespace eos {
class
Transaction
{
public:
Transaction
()
:
handle
(
transaction
C
reate
())
:
handle
(
transaction
_c
reate
())
{}
// no copy constructor due to opaque handle
...
...
@@ -97,26 +97,26 @@ namespace eos {
~
Transaction
()
{
if
(
handle
!=
InvalidTransactionHandle
)
{
transaction
D
rop
(
handle
);
transaction
_d
rop
(
handle
);
handle
=
InvalidTransactionHandle
;
}
}
void
addScope
(
AccountName
scope
,
bool
readOnly
=
false
)
{
assert
ValidH
andle
();
transaction
RequireS
cope
(
handle
,
scope
,
readOnly
?
1
:
0
);
assert
_valid_h
andle
();
transaction
_require_s
cope
(
handle
,
scope
,
readOnly
?
1
:
0
);
}
void
addMessage
(
Message
&
message
)
{
assert
ValidH
andle
();
message
.
assert
ValidH
andle
();
transaction
AddM
essage
(
handle
,
message
.
handle
);
assert
_valid_h
andle
();
message
.
assert
_valid_h
andle
();
transaction
_add_m
essage
(
handle
,
message
.
handle
);
message
.
handle
=
InvalidMessageHandle
;
}
void
send
()
{
assert
ValidH
andle
();
transaction
S
end
(
handle
);
assert
_valid_h
andle
();
transaction
_s
end
(
handle
);
handle
=
InvalidTransactionHandle
;
}
...
...
@@ -125,7 +125,7 @@ namespace eos {
}
private:
void
assert
ValidH
andle
()
{
void
assert
_valid_h
andle
()
{
assert
(
handle
!=
InvalidTransactionHandle
,
"attempting to send or modify a finalized transaction"
);
}
...
...
contracts/exchange/exchange.cpp
浏览文件 @
b9f10200
...
...
@@ -8,7 +8,7 @@
* provided an API header defined in currency.hpp which the exchange
* contract will use to process messages related to deposits and withdraws.
*
* The exchange contract knows that the currency contracts require
N
otice()
* The exchange contract knows that the currency contracts require
_n
otice()
* of both the sender and receiver; therefore, the exchange contract can
* implement a message handler that will be called anytime funds are deposited
* to or withdrawn from the exchange.
...
...
@@ -69,7 +69,7 @@ void apply_currency_transfer( const currency::Transfer& transfer ) {
account
.
currency_balance
+=
transfer
.
quantity
;
});
}
else
if
(
transfer
.
from
==
N
(
exchange
)
)
{
require
A
uth
(
transfer
.
to
);
/// require the receiver of funds (account owner) to authorize this transfer
require
_a
uth
(
transfer
.
to
);
/// require the receiver of funds (account owner) to authorize this transfer
modifyAccount
(
transfer
.
to
,
[
&
](
Account
&
account
){
account
.
currency_balance
-=
transfer
.
quantity
;
...
...
@@ -89,7 +89,7 @@ void apply_eos_transfer( const eos::Transfer& transfer ) {
account
.
eos_balance
+=
transfer
.
quantity
;
});
}
else
if
(
transfer
.
from
==
N
(
exchange
)
)
{
require
A
uth
(
transfer
.
to
);
/// require the receiver of funds (account owner) to authorize this transfer
require
_a
uth
(
transfer
.
to
);
/// require the receiver of funds (account owner) to authorize this transfer
modifyAccount
(
transfer
.
to
,
[
&
](
Account
&
account
){
account
.
eos_balance
-=
transfer
.
quantity
;
...
...
@@ -130,7 +130,7 @@ void match( Bid& bid, Account& buyer, Ask& ask, Account& seller ) {
*/
void
apply_exchange_buy
(
BuyOrder
order
)
{
Bid
&
bid
=
order
;
require
Auth
(
bid
.
buyer
.
name
);
require
_auth
(
bid
.
buyer
.
name
);
assert
(
bid
.
quantity
>
eos
::
Tokens
(
0
),
"invalid quantity"
);
assert
(
bid
.
expiration
>
now
(),
"order expired"
);
...
...
@@ -193,7 +193,7 @@ void apply_exchange_buy( BuyOrder order ) {
void
apply_exchange_sell
(
SellOrder
order
)
{
Ask
&
ask
=
order
;
require
Auth
(
ask
.
seller
.
name
);
require
_auth
(
ask
.
seller
.
name
);
assert
(
ask
.
quantity
>
CurrencyTokens
(
0
),
"invalid quantity"
);
assert
(
ask
.
expiration
>
now
(),
"order expired"
);
...
...
@@ -251,7 +251,7 @@ void apply_exchange_sell( SellOrder order ) {
}
void
apply_exchange_cancel_buy
(
OrderID
order
)
{
require
Auth
(
order
.
name
);
require
_auth
(
order
.
name
);
Bid
bid_to_cancel
;
assert
(
BidsById
::
get
(
order
,
bid_to_cancel
),
"bid with this id does not exists"
);
...
...
@@ -267,7 +267,7 @@ void apply_exchange_cancel_buy( OrderID order ) {
}
void
apply_exchange_cancel_sell
(
OrderID
order
)
{
require
Auth
(
order
.
name
);
require
_auth
(
order
.
name
);
Ask
ask_to_cancel
;
assert
(
AsksById
::
get
(
order
,
ask_to_cancel
),
"ask with this id does not exists"
);
...
...
@@ -303,16 +303,16 @@ extern "C" {
if
(
code
==
N
(
exchange
)
)
{
switch
(
action
)
{
case
N
(
buy
):
apply_exchange_buy
(
current
M
essage
<
exchange
::
BuyOrder
>
()
);
apply_exchange_buy
(
current
_m
essage
<
exchange
::
BuyOrder
>
()
);
break
;
case
N
(
sell
):
apply_exchange_sell
(
current
M
essage
<
exchange
::
SellOrder
>
()
);
apply_exchange_sell
(
current
_m
essage
<
exchange
::
SellOrder
>
()
);
break
;
case
N
(
cancelbuy
):
apply_exchange_cancel_buy
(
current
M
essage
<
exchange
::
OrderID
>
()
);
apply_exchange_cancel_buy
(
current
_m
essage
<
exchange
::
OrderID
>
()
);
break
;
case
N
(
cancelsell
):
apply_exchange_cancel_sell
(
current
M
essage
<
exchange
::
OrderID
>
()
);
apply_exchange_cancel_sell
(
current
_m
essage
<
exchange
::
OrderID
>
()
);
break
;
default:
assert
(
false
,
"unknown action"
);
...
...
@@ -320,11 +320,11 @@ extern "C" {
}
else
if
(
code
==
N
(
currency
)
)
{
if
(
action
==
N
(
transfer
)
)
apply_currency_transfer
(
current
M
essage
<
currency
::
Transfer
>
()
);
apply_currency_transfer
(
current
_m
essage
<
currency
::
Transfer
>
()
);
}
else
if
(
code
==
N
(
eos
)
)
{
if
(
action
==
N
(
transfer
)
)
apply_eos_transfer
(
current
M
essage
<
eos
::
Transfer
>
()
);
apply_eos_transfer
(
current
_m
essage
<
eos
::
Transfer
>
()
);
}
else
{
}
...
...
contracts/infinite/infinite.cpp
浏览文件 @
b9f10200
...
...
@@ -19,8 +19,8 @@ namespace infinite {
}
void
apply_currency_transfer
(
const
infinite
::
Transfer
&
transfer
)
{
require
N
otice
(
transfer
.
to
,
transfer
.
from
);
require
A
uth
(
transfer
.
from
);
require
_n
otice
(
transfer
.
to
,
transfer
.
from
);
require
_a
uth
(
transfer
.
from
);
auto
from
=
getAccount
(
transfer
.
from
);
auto
to
=
getAccount
(
transfer
.
to
);
...
...
@@ -47,8 +47,8 @@ extern "C" {
/// The apply method implements the dispatch of events to this contract
void
apply
(
uint64_t
code
,
uint64_t
action
)
{
if
(
code
==
N
(
currency
)
)
{
if
(
action
==
N
(
transfer
)
)
infinite
::
apply_currency_transfer
(
current
M
essage
<
infinite
::
Transfer
>
()
);
if
(
action
==
N
(
transfer
)
)
infinite
::
apply_currency_transfer
(
current
_m
essage
<
infinite
::
Transfer
>
()
);
}
}
}
contracts/proxy/proxy.cpp
浏览文件 @
b9f10200
...
...
@@ -10,7 +10,7 @@ namespace proxy {
template
<
typename
T
>
void
apply_transfer
(
AccountName
code
,
const
T
&
transfer
)
{
const
auto
self
=
current
C
ode
();
const
auto
self
=
current
_c
ode
();
Config
config
;
assert
(
Configs
::
get
(
config
,
self
),
"Attempting to use unconfigured proxy"
);
if
(
transfer
.
from
==
self
)
{
...
...
@@ -31,7 +31,7 @@ namespace proxy {
}
void
apply_setowner
(
AccountName
owner
)
{
const
auto
self
=
current
C
ode
();
const
auto
self
=
current
_c
ode
();
Config
config
;
bool
configured
=
Configs
::
get
(
config
,
self
);
config
.
owner
=
owner
;
...
...
@@ -55,15 +55,15 @@ extern "C" {
void
apply
(
uint64_t
code
,
uint64_t
action
)
{
if
(
code
==
N
(
currency
)
)
{
if
(
action
==
N
(
transfer
)
)
{
apply_transfer
(
code
,
current
M
essage
<
currency
::
Transfer
>
());
apply_transfer
(
code
,
current
_m
essage
<
currency
::
Transfer
>
());
}
}
else
if
(
code
==
N
(
eos
)
)
{
if
(
action
==
N
(
transfer
)
)
{
apply_transfer
(
code
,
current
M
essage
<
eos
::
Transfer
>
());
apply_transfer
(
code
,
current
_m
essage
<
eos
::
Transfer
>
());
}
}
else
if
(
code
==
N
(
proxy
)
)
{
if
(
action
==
N
(
setowner
))
{
apply_setowner
(
current
M
essage
<
AccountName
>
());
apply_setowner
(
current
_m
essage
<
AccountName
>
());
}
}
}
...
...
contracts/simpledb/simpledb.cpp
浏览文件 @
b9f10200
...
...
@@ -16,7 +16,7 @@ extern "C" {
if
(
action
==
N
(
insertkv1
)
)
{
// eosc push message simpledb insertkv1 '{"key":"a", "value":"aa"}' -S simpledb
// eosc get table simpledb simpledb keyvalue1
auto
kv1
=
eos
::
current
M
essage
<
KeyValue1
>
();
auto
kv1
=
eos
::
current
_m
essage
<
KeyValue1
>
();
//eos::print(kv1.key.len, "-", (const char*)kv1.key.str, "->" , kv1.value.len, "-", (const char*)kv1.value.str, "\n");
//Use kv1 in some way
...
...
@@ -26,7 +26,7 @@ extern "C" {
}
else
if
(
action
==
N
(
insertkv2
)
)
{
// eosc push message simpledb insertkv2 '{"key":"a", "value":{"name":"aaa", "age":10}}' -S simpledb
// eosc get table simpledb simpledb keyvalue2
auto
kv2
=
eos
::
current
M
essage
<
KeyValue2
>
();
auto
kv2
=
eos
::
current
_m
essage
<
KeyValue2
>
();
//eos::print(kv2.key.len, "-", (const char*)kv2.key.str, "->" , (const char*)kv2.value.name.str, "-", kv2.value.age, "\n");
//Use kv2 in some way
...
...
@@ -36,15 +36,15 @@ extern "C" {
}
else
if
(
action
==
N
(
insert1
)
)
{
record1
tmp
;
read
M
essage
(
&
tmp
,
sizeof
(
tmp
));
read
_m
essage
(
&
tmp
,
sizeof
(
tmp
));
store_i64
(
N
(
simpledb
),
N
(
record1
),
&
tmp
,
sizeof
(
tmp
)
);
}
else
if
(
action
==
N
(
insert2
))
{
record2
tmp
;
read
M
essage
(
&
tmp
,
sizeof
(
tmp
));
read
_m
essage
(
&
tmp
,
sizeof
(
tmp
));
store_i128i128
(
N
(
simpledb
),
N
(
record2
),
&
tmp
,
sizeof
(
tmp
)
);
}
else
if
(
action
==
N
(
insert3
))
{
record3
tmp
;
read
M
essage
(
&
tmp
,
sizeof
(
tmp
));
read
_m
essage
(
&
tmp
,
sizeof
(
tmp
));
store_i64i64i64
(
N
(
simpledb
),
N
(
record3
),
&
tmp
,
sizeof
(
tmp
)
);
}
else
{
assert
(
0
,
"unknown message"
);
...
...
contracts/simpledb/simpledb.gen.hpp
浏览文件 @
b9f10200
...
...
@@ -4,7 +4,7 @@
#include <eoslib/print.hpp>
// These functions can be auto-generated using the ABI definition.
// The specialization for current
Message must only be defined if the
// The specialization for current
_message must only be defined if the
// struct has at least one variable length type (String, Bytes, etc),
// otherwise the default function will do ok.
//
...
...
@@ -25,10 +25,10 @@ namespace eos {
T
bytesToValue
(
const
Bytes
&
bytes
)
{
return
*
reinterpret_cast
<
T
*>
(
bytes
.
data
);
}
template
<
>
KeyValue1
current
M
essage
<
KeyValue1
>
()
{
uint32_t
msgsize
=
message
S
ize
();
KeyValue1
current
_m
essage
<
KeyValue1
>
()
{
uint32_t
msgsize
=
message
_s
ize
();
char
*
buffer
=
(
char
*
)
eos
::
malloc
(
msgsize
);
assert
(
read
M
essage
(
buffer
,
msgsize
)
==
msgsize
,
"error reading KeyValue1"
);
assert
(
read
_m
essage
(
buffer
,
msgsize
)
==
msgsize
,
"error reading KeyValue1"
);
datastream
<
char
*>
ds
(
buffer
,
msgsize
);
KeyValue1
value
;
raw
::
unpack
(
ds
,
value
.
key
);
...
...
@@ -62,10 +62,10 @@ namespace eos {
}
template
<
>
KeyValue2
current
M
essage
<
KeyValue2
>
()
{
uint32_t
msgsize
=
message
S
ize
();
KeyValue2
current
_m
essage
<
KeyValue2
>
()
{
uint32_t
msgsize
=
message
_s
ize
();
char
*
buffer
=
(
char
*
)
eos
::
malloc
(
msgsize
);
assert
(
read
M
essage
(
buffer
,
msgsize
)
==
msgsize
,
"error reading KeyValue2"
);
assert
(
read
_m
essage
(
buffer
,
msgsize
)
==
msgsize
,
"error reading KeyValue2"
);
datastream
<
char
*>
ds
(
buffer
,
msgsize
);
KeyValue2
value
;
raw
::
unpack
(
ds
,
value
.
key
);
...
...
contracts/social/social.cpp
浏览文件 @
b9f10200
...
...
@@ -59,8 +59,8 @@ struct Account {
* any other contexts are notified
*/
void
apply_social_post
()
{
const
auto
&
post
=
current
M
essage
<
PostAction
>
();
require
A
uth
(
post
.
author
);
const
auto
&
post
=
current
_m
essage
<
PostAction
>
();
require
_a
uth
(
post
.
author
);
assert
(
currentContext
()
==
post
.
author
,
"cannot call from any other context"
);
...
...
@@ -75,8 +75,8 @@ void apply_social_post() {
* updates the vote total. When executed
*/
void
apply_social_vote
()
{
const
auto
&
vote
=
current
M
essage
<
VoteAction
>
();
require
N
otice
(
vote
.
voter
,
vote
.
author
);
const
auto
&
vote
=
current
_m
essage
<
VoteAction
>
();
require
_n
otice
(
vote
.
voter
,
vote
.
author
);
disableContextCode
(
vote
.
author
()
);
/// prevent the author's code from rejecting the potentially negative vote
auto
context
=
currentContext
();
...
...
contracts/storage/storage.cpp
浏览文件 @
b9f10200
...
...
@@ -14,8 +14,8 @@ namespace TOKEN_NAME {
}
void
apply_storage_transfer
(
const
TOKEN_NAME
::
Transfer
&
transfer
)
{
eos
::
require
N
otice
(
transfer
.
to
,
transfer
.
from
);
eos
::
require
A
uth
(
transfer
.
from
);
eos
::
require
_n
otice
(
transfer
.
to
,
transfer
.
from
);
eos
::
require
_a
uth
(
transfer
.
from
);
Account
from
=
getAccount
(
transfer
.
from
);
Account
to
=
getAccount
(
transfer
.
to
);
...
...
@@ -48,52 +48,52 @@ namespace TOKEN_NAME {
uint32_t
eospathlen
;
uint32_t
ipfspathlen
;
char
tmp
[
4098
];
auto
bufferlen
=
read
M
essage
(
tmp
,
4098
);
auto
bufferlen
=
read
_m
essage
(
tmp
,
4098
);
auto
linklen
=
readLinkFromBuffer
(
tmp
,
bufferlen
,
link
,
eospathlen
,
ipfspathlen
);
eos
::
require
N
otice
(
link
.
owner
);
eos
::
require
A
uth
(
link
.
owner
);
eos
::
require
_n
otice
(
link
.
owner
);
eos
::
require
_a
uth
(
link
.
owner
);
validate_ipfspath
(
link
.
ipfspath
,
ipfspathlen
);
validate_eospath
(
link
.
eospath
,
eospathlen
);
::
store_str
(
current
C
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
,
(
char
*
)
&
link
,
linklen
);
::
store_str
(
current
_c
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
,
(
char
*
)
&
link
,
linklen
);
}
void
apply_storage_removelink
(
char
*
eospath
,
uint32_t
eospathlen
)
{
char
tmp
[
4098
];
auto
len
=
::
load_str
(
current
Code
(),
currentC
ode
(),
N
(
storage
),
eospath
,
eospathlen
,
tmp
,
4098
);
auto
len
=
::
load_str
(
current
_code
(),
current_c
ode
(),
N
(
storage
),
eospath
,
eospathlen
,
tmp
,
4098
);
TOKEN_NAME
::
Link
link
;
uint32_t
ipfspathlen
;
len
=
readLinkFromBuffer
(
tmp
,
len
,
link
,
eospathlen
,
ipfspathlen
);
eos
::
require
A
uth
(
link
.
owner
);
eos
::
require
_a
uth
(
link
.
owner
);
uint32_t
stake
=
link
.
stake
;
::
remove_str
(
current
C
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
);
::
remove_str
(
current
_c
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
);
// Reduce Quota usage in Account table
// How does producer know to free cached file?
}
void
apply_storage_createstore
(
char
*
eospath
,
uint32_t
eospathlen
)
{
char
tmp
[
4098
];
auto
len
=
::
load_str
(
current
Code
(),
currentC
ode
(),
N
(
storage
),
eospath
,
eospathlen
,
tmp
,
4098
);
auto
len
=
::
load_str
(
current
_code
(),
current_c
ode
(),
N
(
storage
),
eospath
,
eospathlen
,
tmp
,
4098
);
TOKEN_NAME
::
Link
link
;
uint32_t
ipfspathlen
;
len
=
readLinkFromBuffer
(
tmp
,
len
,
link
,
eospathlen
,
ipfspathlen
);
// eos::require
A
uth( producer )
// How do we validate the require
A
uth() is a producer?
// eos::require
_a
uth( producer )
// How do we validate the require
_a
uth() is a producer?
// logic goes here to reduce number of tokens and increase quote used using bancor algorithm
link
.
accept
=
1
;
::
store_str
(
current
C
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
,
(
char
*
)
&
link
,
len
);
::
store_str
(
current
_c
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
,
(
char
*
)
&
link
,
len
);
}
void
apply_storage_rejectstore
(
char
*
eospath
,
uint32_t
eospathlen
)
{
char
tmp
[
4098
];
auto
len
=
::
load_str
(
current
Code
(),
currentC
ode
(),
N
(
storage
),
eospath
,
eospathlen
,
tmp
,
4098
);
auto
len
=
::
load_str
(
current
_code
(),
current_c
ode
(),
N
(
storage
),
eospath
,
eospathlen
,
tmp
,
4098
);
TOKEN_NAME
::
Link
link
;
uint32_t
ipfspathlen
;
len
=
readLinkFromBuffer
(
tmp
,
len
,
link
,
eospathlen
,
ipfspathlen
);
// eos::require
A
uth( producer )
// How do we validate the require
A
uth() is a producer?
// eos::require
_a
uth( producer )
// How do we validate the require
_a
uth() is a producer?
link
.
accept
=
0
;
::
store_str
(
current
C
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
,
(
char
*
)
&
link
,
len
);
::
store_str
(
current
_c
ode
(),
N
(
storage
),
link
.
eospath
,
eospathlen
,
(
char
*
)
&
link
,
len
);
}
}
// namespace TOKEN_NAME
...
...
@@ -109,20 +109,20 @@ extern "C" {
void
apply
(
uint64_t
code
,
uint64_t
action
)
{
if
(
code
==
N
(
storage
)
)
{
if
(
action
==
N
(
transfer
)
)
{
TOKEN_NAME
::
apply_storage_transfer
(
eos
::
current
M
essage
<
TOKEN_NAME
::
Transfer
>
()
);
TOKEN_NAME
::
apply_storage_transfer
(
eos
::
current
_m
essage
<
TOKEN_NAME
::
Transfer
>
()
);
}
else
if
(
action
==
N
(
setlink
)
)
{
TOKEN_NAME
::
apply_storage_setlink
();
}
else
if
(
action
==
N
(
removelink
)
)
{
char
tmp
[
1025
];
auto
len
=
read
M
essage
(
tmp
,
1025
);
auto
len
=
read
_m
essage
(
tmp
,
1025
);
TOKEN_NAME
::
apply_storage_removelink
(
tmp
,
len
);
}
else
if
(
action
==
N
(
acceptstore
)
)
{
char
tmp
[
1025
];
auto
len
=
read
M
essage
(
tmp
,
1025
);
auto
len
=
read
_m
essage
(
tmp
,
1025
);
TOKEN_NAME
::
apply_storage_createstore
(
tmp
,
len
);
}
else
if
(
action
==
N
(
rejectstore
)
)
{
char
tmp
[
1025
];
auto
len
=
read
M
essage
(
tmp
,
1025
);
auto
len
=
read
_m
essage
(
tmp
,
1025
);
TOKEN_NAME
::
apply_storage_rejectstore
(
tmp
,
len
);
}
else
{
assert
(
0
,
"unknown message"
);
...
...
contracts/test_api/test_api.cpp
浏览文件 @
b9f10200
...
...
@@ -32,7 +32,7 @@ extern "C" {
WASM_TEST_HANDLER
(
test_types
,
name_class
);
//test_message
WASM_TEST_HANDLER
(
test_message
,
read_message
);
WASM_TEST_HANDLER
(
test_message
,
read_message
_normal
);
WASM_TEST_HANDLER
(
test_message
,
read_message_to_0
);
WASM_TEST_HANDLER
(
test_message
,
read_message_to_64k
);
WASM_TEST_HANDLER
(
test_message
,
require_notice
);
...
...
contracts/test_api/test_api.hpp
浏览文件 @
b9f10200
...
...
@@ -68,7 +68,7 @@ struct test_print {
struct
test_message
{
static
unsigned
int
read_message
();
static
unsigned
int
read_message
_normal
();
static
unsigned
int
read_message_to_0
();
static
unsigned
int
read_message_to_64k
();
static
unsigned
int
require_notice
();
...
...
contracts/test_api/test_chain.cpp
浏览文件 @
b9f10200
...
...
@@ -16,16 +16,16 @@ struct Producers {
unsigned
int
test_chain
::
test_activeprods
()
{
Producers
msg_prods
;
read
M
essage
(
&
msg_prods
,
sizeof
(
Producers
));
read
_m
essage
(
&
msg_prods
,
sizeof
(
Producers
));
WASM_ASSERT
(
msg_prods
.
len
==
21
,
"Producers.len != 21"
);
Producers
api_prods
;
get
ActiveP
roducers
(
api_prods
.
producers
,
sizeof
(
AccountName
)
*
21
);
get
_active_p
roducers
(
api_prods
.
producers
,
sizeof
(
AccountName
)
*
21
);
for
(
int
i
=
0
;
i
<
21
;
++
i
)
{
WASM_ASSERT
(
api_prods
.
producers
[
i
]
==
msg_prods
.
producers
[
i
],
"Active producer"
);
}
return
WASM_TEST_PASS
;
}
\ No newline at end of file
}
contracts/test_api/test_db.cpp
浏览文件 @
b9f10200
此差异已折叠。
点击以展开。
contracts/test_api/test_math.cpp
浏览文件 @
b9f10200
...
...
@@ -6,7 +6,7 @@
unsigned
int
test_math
::
test_multeq_i128
()
{
u128_msg
msg
;
auto
n
=
read
M
essage
(
&
msg
,
sizeof
(
u128_msg
));
auto
n
=
read
_m
essage
(
&
msg
,
sizeof
(
u128_msg
));
WASM_ASSERT
(
n
==
sizeof
(
u128_msg
),
"test_multeq_i128 n == sizeof(u128_msg)"
);
multeq_i128
(
msg
.
values
,
msg
.
values
+
1
);
WASM_ASSERT
(
msg
.
values
[
0
]
==
msg
.
values
[
2
],
"test_multeq_i128 msg.values[0] == msg.values[2]"
);
...
...
@@ -15,7 +15,7 @@ unsigned int test_math::test_multeq_i128() {
unsigned
int
test_math
::
test_diveq_i128
()
{
u128_msg
msg
;
auto
n
=
read
M
essage
(
&
msg
,
sizeof
(
u128_msg
));
auto
n
=
read
_m
essage
(
&
msg
,
sizeof
(
u128_msg
));
WASM_ASSERT
(
n
==
sizeof
(
u128_msg
),
"test_diveq_i128 n == sizeof(u128_msg)"
);
diveq_i128
(
msg
.
values
,
msg
.
values
+
1
);
WASM_ASSERT
(
msg
.
values
[
0
]
==
msg
.
values
[
2
],
"test_diveq_i128 msg.values[0] == msg.values[2]"
);
...
...
@@ -71,4 +71,4 @@ unsigned int test_math::test_double_api_div_0() {
);
return
WASM_TEST_PASS
;
}
\ No newline at end of file
}
contracts/test_api/test_message.cpp
浏览文件 @
b9f10200
...
...
@@ -6,26 +6,26 @@
#include "test_api.hpp"
unsigned
int
test_message
::
read_message
()
{
unsigned
int
test_message
::
read_message
_normal
()
{
char
buffer
[
100
];
uint32_t
total
=
0
;
WASM_ASSERT
(
current
Code
()
==
N
(
testapi
),
"currentC
ode() == N(testapi)"
);
WASM_ASSERT
(
current
_code
()
==
N
(
testapi
),
"current_c
ode() == N(testapi)"
);
WASM_ASSERT
(
message
Size
()
==
sizeof
(
dummy_message
),
"messageS
ize() == sizeof(dummy_message)"
);
WASM_ASSERT
(
message
_size
()
==
sizeof
(
dummy_message
),
"message_s
ize() == sizeof(dummy_message)"
);
total
=
read
M
essage
(
buffer
,
30
);
WASM_ASSERT
(
total
==
sizeof
(
dummy_message
)
,
"read
M
essage(30)"
);
total
=
read
_m
essage
(
buffer
,
30
);
WASM_ASSERT
(
total
==
sizeof
(
dummy_message
)
,
"read
_m
essage(30)"
);
total
=
read
M
essage
(
buffer
,
100
);
WASM_ASSERT
(
total
==
sizeof
(
dummy_message
)
,
"read
M
essage(100)"
);
total
=
read
_m
essage
(
buffer
,
100
);
WASM_ASSERT
(
total
==
sizeof
(
dummy_message
)
,
"read
_m
essage(100)"
);
total
=
read
M
essage
(
buffer
,
5
);
WASM_ASSERT
(
total
==
5
,
"read
M
essage(5)"
);
total
=
read
_m
essage
(
buffer
,
5
);
WASM_ASSERT
(
total
==
5
,
"read
_m
essage(5)"
);
total
=
read
M
essage
(
buffer
,
sizeof
(
dummy_message
)
);
WASM_ASSERT
(
total
==
sizeof
(
dummy_message
),
"read
M
essage(sizeof(dummy_message))"
);
total
=
read
_m
essage
(
buffer
,
sizeof
(
dummy_message
)
);
WASM_ASSERT
(
total
==
sizeof
(
dummy_message
),
"read
_m
essage(sizeof(dummy_message))"
);
dummy_message
*
dummy13
=
reinterpret_cast
<
dummy_message
*>
(
buffer
);
WASM_ASSERT
(
dummy13
->
a
==
DUMMY_MESSAGE_DEFAULT_A
,
"dummy13->a == DUMMY_MESSAGE_DEFAULT_A"
);
...
...
@@ -36,30 +36,30 @@ unsigned int test_message::read_message() {
}
unsigned
int
test_message
::
read_message_to_0
()
{
uint32_t
total
=
read
M
essage
((
void
*
)
0
,
0x7FFFFFFF
);
uint32_t
total
=
read
_m
essage
((
void
*
)
0
,
0x7FFFFFFF
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_message
::
read_message_to_64k
()
{
uint32_t
total
=
read
M
essage
(
(
void
*
)((
1
<<
16
)
-
1
),
0x7FFFFFFF
);
uint32_t
total
=
read
_m
essage
(
(
void
*
)((
1
<<
16
)
-
1
),
0x7FFFFFFF
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_message
::
require_notice
()
{
if
(
current
C
ode
()
==
N
(
testapi
)
)
{
eos
::
require
N
otice
(
N
(
acc1
)
);
eos
::
require
N
otice
(
N
(
acc2
)
);
eos
::
require
N
otice
(
N
(
acc1
),
N
(
acc2
)
);
if
(
current
_c
ode
()
==
N
(
testapi
)
)
{
eos
::
require
_n
otice
(
N
(
acc1
)
);
eos
::
require
_n
otice
(
N
(
acc2
)
);
eos
::
require
_n
otice
(
N
(
acc1
),
N
(
acc2
)
);
return
WASM_TEST_FAIL
;
}
else
if
(
current
Code
()
==
N
(
acc1
)
||
currentC
ode
()
==
N
(
acc2
)
)
{
}
else
if
(
current
_code
()
==
N
(
acc1
)
||
current_c
ode
()
==
N
(
acc2
)
)
{
return
WASM_TEST_PASS
;
}
return
WASM_TEST_FAIL
;
}
unsigned
int
test_message
::
require_auth
()
{
eos
::
require
A
uth
(
N
(
acc3
)
);
eos
::
require
A
uth
(
N
(
acc4
)
);
eos
::
require
_a
uth
(
N
(
acc3
)
);
eos
::
require
_a
uth
(
N
(
acc4
)
);
return
WASM_TEST_PASS
;
}
...
...
@@ -75,7 +75,7 @@ unsigned int test_message::assert_true() {
unsigned
int
test_message
::
now
()
{
uint32_t
tmp
=
0
;
uint32_t
total
=
read
M
essage
(
&
tmp
,
sizeof
(
uint32_t
));
uint32_t
total
=
read
_m
essage
(
&
tmp
,
sizeof
(
uint32_t
));
WASM_ASSERT
(
total
==
sizeof
(
uint32_t
),
"total == sizeof(uint32_t)"
);
WASM_ASSERT
(
tmp
==
::
now
(),
"tmp == now()"
);
return
WASM_TEST_PASS
;
...
...
contracts/test_api/test_transaction.cpp
浏览文件 @
b9f10200
...
...
@@ -9,14 +9,14 @@
unsigned
int
test_transaction
::
send_message
()
{
dummy_message
payload
=
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
auto
msg
=
message
Create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message
"
),
&
payload
,
sizeof
(
dummy_message
));
message
S
end
(
msg
);
auto
msg
=
message
_create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message_normal
"
),
&
payload
,
sizeof
(
dummy_message
));
message
_s
end
(
msg
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_transaction
::
send_message_empty
()
{
auto
msg
=
message
C
reate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"assert_true"
),
nullptr
,
0
);
message
S
end
(
msg
);
auto
msg
=
message
_c
reate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"assert_true"
),
nullptr
,
0
);
message
_s
end
(
msg
);
return
WASM_TEST_PASS
;
}
...
...
@@ -26,7 +26,7 @@ unsigned int test_transaction::send_message_empty() {
unsigned
int
test_transaction
::
send_message_max
()
{
dummy_message
payload
=
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
message
Create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message
"
),
&
payload
,
sizeof
(
dummy_message
));
message
_create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message_normal
"
),
&
payload
,
sizeof
(
dummy_message
));
}
return
WASM_TEST_FAIL
;
...
...
@@ -37,7 +37,7 @@ unsigned int test_transaction::send_message_max() {
*/
unsigned
int
test_transaction
::
send_message_large
()
{
char
large_message
[
8
*
1024
];
message
Create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message
"
),
large_message
,
sizeof
(
large_message
));
message
_create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message_normal
"
),
large_message
,
sizeof
(
large_message
));
return
WASM_TEST_FAIL
;
}
...
...
@@ -46,9 +46,9 @@ unsigned int test_transaction::send_message_large() {
*/
unsigned
int
test_transaction
::
send_message_recurse
()
{
char
buffer
[
1024
];
uint32_t
size
=
read
M
essage
(
buffer
,
1024
);
auto
msg
=
message
C
reate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_transaction"
,
"send_message_recurse"
),
buffer
,
size
);
message
S
end
(
msg
);
uint32_t
size
=
read
_m
essage
(
buffer
,
1024
);
auto
msg
=
message
_c
reate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_transaction"
,
"send_message_recurse"
),
buffer
,
size
);
message
_s
end
(
msg
);
return
WASM_TEST_PASS
;
}
...
...
@@ -56,27 +56,27 @@ unsigned int test_transaction::send_message_recurse() {
* cause failure due to inline TX failure
*/
unsigned
int
test_transaction
::
send_message_inline_fail
()
{
auto
msg
=
message
C
reate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"assert_false"
),
nullptr
,
0
);
message
S
end
(
msg
);
auto
msg
=
message
_c
reate
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"assert_false"
),
nullptr
,
0
);
message
_s
end
(
msg
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_transaction
::
send_transaction
()
{
dummy_message
payload
=
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
auto
msg
=
message
Create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message
"
),
&
payload
,
sizeof
(
dummy_message
));
auto
msg
=
message
_create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message_normal
"
),
&
payload
,
sizeof
(
dummy_message
));
auto
trx
=
transaction
C
reate
();
transaction
RequireS
cope
(
trx
,
N
(
testapi
));
transaction
AddM
essage
(
trx
,
msg
);
transaction
S
end
(
trx
);
auto
trx
=
transaction
_c
reate
();
transaction
_require_s
cope
(
trx
,
N
(
testapi
));
transaction
_add_m
essage
(
trx
,
msg
);
transaction
_s
end
(
trx
);
return
WASM_TEST_PASS
;
}
unsigned
int
test_transaction
::
send_transaction_empty
()
{
auto
trx
=
transaction
C
reate
();
transaction
RequireS
cope
(
trx
,
N
(
testapi
));
transaction
S
end
(
trx
);
auto
trx
=
transaction
_c
reate
();
transaction
_require_s
cope
(
trx
,
N
(
testapi
));
transaction
_s
end
(
trx
);
return
WASM_TEST_FAIL
;
}
...
...
@@ -85,7 +85,7 @@ unsigned int test_transaction::send_transaction_empty() {
*/
unsigned
int
test_transaction
::
send_transaction_max
()
{
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
transaction
C
reate
();
transaction
_c
reate
();
}
return
WASM_TEST_FAIL
;
...
...
@@ -95,15 +95,15 @@ unsigned int test_transaction::send_transaction_max() {
* cause failure due to a large transaction size
*/
unsigned
int
test_transaction
::
send_transaction_large
()
{
auto
trx
=
transaction
C
reate
();
transaction
RequireS
cope
(
trx
,
N
(
testapi
));
auto
trx
=
transaction
_c
reate
();
transaction
_require_s
cope
(
trx
,
N
(
testapi
));
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
char
large_message
[
4
*
1024
];
auto
msg
=
message
Create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message
"
),
large_message
,
sizeof
(
large_message
));
transaction
AddM
essage
(
trx
,
msg
);
auto
msg
=
message
_create
(
N
(
testapi
),
WASM_TEST_ACTION
(
"test_message"
,
"read_message_normal
"
),
large_message
,
sizeof
(
large_message
));
transaction
_add_m
essage
(
trx
,
msg
);
}
transaction
S
end
(
trx
);
transaction
_s
end
(
trx
);
return
WASM_TEST_FAIL
;
}
contracts/tic_tac_toe/tic_tac_toe.cpp
浏览文件 @
b9f10200
...
...
@@ -88,7 +88,7 @@ namespace tic_tac_toe {
* @param create - action to be applied
*/
void
apply_create
(
const
Create
&
create
)
{
require
A
uth
(
create
.
host
);
require
_a
uth
(
create
.
host
);
assert
(
create
.
challenger
!=
create
.
host
,
"challenger shouldn't be the same as host"
);
// Check if game already exists
...
...
@@ -105,7 +105,7 @@ namespace tic_tac_toe {
* @param restart - action to be applied
*/
void
apply_restart
(
const
Restart
&
restart
)
{
require
A
uth
(
restart
.
by
);
require
_a
uth
(
restart
.
by
);
// Check if game exists
Game
game
;
...
...
@@ -126,7 +126,7 @@ namespace tic_tac_toe {
* @param close - action to be applied
*/
void
apply_close
(
const
Close
&
close
)
{
require
A
uth
(
close
.
host
);
require
_a
uth
(
close
.
host
);
// Check if game exists
Game
game
;
...
...
@@ -141,7 +141,7 @@ namespace tic_tac_toe {
* @param move - action to be applied
*/
void
apply_move
(
const
Move
&
move
)
{
require
A
uth
(
move
.
by
);
require
_a
uth
(
move
.
by
);
// Check if game exists
Game
game
;
...
...
@@ -194,13 +194,13 @@ extern "C" {
void
apply
(
uint64_t
code
,
uint64_t
action
)
{
if
(
code
==
N
(
tic
.
tac
.
toe
))
{
if
(
action
==
N
(
create
))
{
tic_tac_toe
::
apply_create
(
current
M
essage
<
tic_tac_toe
::
Create
>
());
tic_tac_toe
::
apply_create
(
current
_m
essage
<
tic_tac_toe
::
Create
>
());
}
else
if
(
action
==
N
(
restart
))
{
tic_tac_toe
::
apply_restart
(
current
M
essage
<
tic_tac_toe
::
Restart
>
());
tic_tac_toe
::
apply_restart
(
current
_m
essage
<
tic_tac_toe
::
Restart
>
());
}
else
if
(
action
==
N
(
close
))
{
tic_tac_toe
::
apply_close
(
current
M
essage
<
tic_tac_toe
::
Close
>
());
tic_tac_toe
::
apply_close
(
current
_m
essage
<
tic_tac_toe
::
Close
>
());
}
else
if
(
action
==
N
(
move
))
{
tic_tac_toe
::
apply_move
(
current
M
essage
<
tic_tac_toe
::
Move
>
());
tic_tac_toe
::
apply_move
(
current
_m
essage
<
tic_tac_toe
::
Move
>
());
}
}
}
...
...
libraries/chain/wasm_interface.cpp
浏览文件 @
b9f10200
...
...
@@ -352,8 +352,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,i64_to_double,i64_to_double,i64,i64,a) {
return
*
reinterpret_cast
<
uint64_t
*>
(
&
res
);
}
DEFINE_INTRINSIC_FUNCTION2
(
env
,
getActiveProducers
,
getActiveProducers
,
none
,
i32
,
producers
,
i32
,
datalen
)
{
DEFINE_INTRINSIC_FUNCTION2
(
env
,
get_active_producers
,
get_active_producers
,
none
,
i32
,
producers
,
i32
,
datalen
)
{
auto
&
wasm
=
wasm_interface
::
get
();
auto
mem
=
wasm
.
current_memory
;
types
::
AccountName
*
dst
=
memoryArrayPtr
<
types
::
AccountName
>
(
mem
,
producers
,
datalen
);
...
...
@@ -364,20 +363,20 @@ DEFINE_INTRINSIC_FUNCTION0(env,now,now,i32) {
return
wasm_interface
::
get
().
current_validate_context
->
controller
.
head_block_time
().
sec_since_epoch
();
}
DEFINE_INTRINSIC_FUNCTION0
(
env
,
current
Code
,
currentC
ode
,
i64
)
{
DEFINE_INTRINSIC_FUNCTION0
(
env
,
current
_code
,
current_c
ode
,
i64
)
{
auto
&
wasm
=
wasm_interface
::
get
();
return
wasm
.
current_validate_context
->
code
.
value
;
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
require
Auth
,
requireA
uth
,
none
,
i64
,
account
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
require
_auth
,
require_a
uth
,
none
,
i64
,
account
)
{
wasm_interface
::
get
().
current_validate_context
->
require_authorization
(
Name
(
account
)
);
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
require
Notice
,
requireN
otice
,
none
,
i64
,
account
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
require
_notice
,
require_n
otice
,
none
,
i64
,
account
)
{
wasm_interface
::
get
().
current_apply_context
->
require_recipient
(
account
);
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
require
Scope
,
requireS
cope
,
none
,
i64
,
scope
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
require
_scope
,
require_s
cope
,
none
,
i64
,
scope
)
{
wasm_interface
::
get
().
current_validate_context
->
require_scope
(
scope
);
}
...
...
@@ -434,7 +433,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,sbrk,sbrk,i32,i32,num_bytes) {
* @{
*/
DEFINE_INTRINSIC_FUNCTION0
(
env
,
transaction
Create
,
transactionC
reate
,
i32
)
{
DEFINE_INTRINSIC_FUNCTION0
(
env
,
transaction
_create
,
transaction_c
reate
,
i32
)
{
auto
&
ptrx
=
wasm_interface
::
get
().
current_apply_context
->
create_pending_transaction
();
return
ptrx
.
handle
;
}
...
...
@@ -446,7 +445,7 @@ static void emplace_scope(const Name& scope, std::vector<Name>& scopes) {
}
}
DEFINE_INTRINSIC_FUNCTION3
(
env
,
transaction
RequireScope
,
transactionRequireS
cope
,
none
,
i32
,
handle
,
i64
,
scope
,
i32
,
readOnly
)
{
DEFINE_INTRINSIC_FUNCTION3
(
env
,
transaction
_require_scope
,
transaction_require_s
cope
,
none
,
i32
,
handle
,
i64
,
scope
,
i32
,
readOnly
)
{
auto
&
ptrx
=
wasm_interface
::
get
().
current_apply_context
->
get_pending_transaction
(
handle
);
if
(
readOnly
==
0
)
{
emplace_scope
(
scope
,
ptrx
.
scope
);
...
...
@@ -457,7 +456,7 @@ DEFINE_INTRINSIC_FUNCTION3(env,transactionRequireScope,transactionRequireScope,n
ptrx
.
check_size
();
}
DEFINE_INTRINSIC_FUNCTION2
(
env
,
transaction
AddMessage
,
transactionAddM
essage
,
none
,
i32
,
handle
,
i32
,
msg_handle
)
{
DEFINE_INTRINSIC_FUNCTION2
(
env
,
transaction
_add_message
,
transaction_add_m
essage
,
none
,
i32
,
handle
,
i32
,
msg_handle
)
{
auto
apply_context
=
wasm_interface
::
get
().
current_apply_context
;
auto
&
ptrx
=
apply_context
->
get_pending_transaction
(
handle
);
auto
&
pmsg
=
apply_context
->
get_pending_message
(
msg_handle
);
...
...
@@ -466,7 +465,7 @@ DEFINE_INTRINSIC_FUNCTION2(env,transactionAddMessage,transactionAddMessage,none,
apply_context
->
release_pending_message
(
msg_handle
);
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
transaction
Send
,
transactionS
end
,
none
,
i32
,
handle
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
transaction
_send
,
transaction_s
end
,
none
,
i32
,
handle
)
{
auto
apply_context
=
wasm_interface
::
get
().
current_apply_context
;
auto
&
ptrx
=
apply_context
->
get_pending_transaction
(
handle
);
...
...
@@ -477,11 +476,11 @@ DEFINE_INTRINSIC_FUNCTION1(env,transactionSend,transactionSend,none,i32,handle)
apply_context
->
release_pending_transaction
(
handle
);
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
transaction
Drop
,
transactionD
rop
,
none
,
i32
,
handle
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
transaction
_drop
,
transaction_d
rop
,
none
,
i32
,
handle
)
{
wasm_interface
::
get
().
current_apply_context
->
release_pending_transaction
(
handle
);
}
DEFINE_INTRINSIC_FUNCTION4
(
env
,
message
Create
,
messageC
reate
,
i32
,
i64
,
code
,
i64
,
type
,
i32
,
data
,
i32
,
length
)
{
DEFINE_INTRINSIC_FUNCTION4
(
env
,
message
_create
,
message_c
reate
,
i32
,
i64
,
code
,
i64
,
type
,
i32
,
data
,
i32
,
length
)
{
auto
&
wasm
=
wasm_interface
::
get
();
auto
mem
=
wasm
.
current_memory
;
...
...
@@ -505,7 +504,7 @@ DEFINE_INTRINSIC_FUNCTION4(env,messageCreate,messageCreate,i32,i64,code,i64,type
return
pmsg
.
handle
;
}
DEFINE_INTRINSIC_FUNCTION3
(
env
,
message
RequirePermission
,
messageRequireP
ermission
,
none
,
i32
,
handle
,
i64
,
account
,
i64
,
permission
)
{
DEFINE_INTRINSIC_FUNCTION3
(
env
,
message
_require_permission
,
message_require_p
ermission
,
none
,
i32
,
handle
,
i64
,
account
,
i64
,
permission
)
{
auto
apply_context
=
wasm_interface
::
get
().
current_apply_context
;
// if this is not sent from the code account with the permission of "code" then we must
// presently have the permission to add it, otherwise its a failure
...
...
@@ -516,7 +515,7 @@ DEFINE_INTRINSIC_FUNCTION3(env,messageRequirePermission,messageRequirePermission
pmsg
.
authorization
.
emplace_back
(
Name
(
account
),
Name
(
permission
));
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
message
Send
,
messageS
end
,
none
,
i32
,
handle
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
message
_send
,
message_s
end
,
none
,
i32
,
handle
)
{
auto
apply_context
=
wasm_interface
::
get
().
current_apply_context
;
auto
&
pmsg
=
apply_context
->
get_pending_message
(
handle
);
...
...
@@ -524,7 +523,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,messageSend,messageSend,none,i32,handle) {
apply_context
->
release_pending_message
(
handle
);
}
DEFINE_INTRINSIC_FUNCTION1
(
env
,
message
Drop
,
messageD
rop
,
none
,
i32
,
handle
)
{
DEFINE_INTRINSIC_FUNCTION1
(
env
,
message
_drop
,
message_d
rop
,
none
,
i32
,
handle
)
{
wasm_interface
::
get
().
current_apply_context
->
release_pending_message
(
handle
);
}
...
...
@@ -534,7 +533,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,messageDrop,messageDrop,none,i32,handle) {
DEFINE_INTRINSIC_FUNCTION2
(
env
,
read
Message
,
readM
essage
,
i32
,
i32
,
destptr
,
i32
,
destsize
)
{
DEFINE_INTRINSIC_FUNCTION2
(
env
,
read
_message
,
read_m
essage
,
i32
,
i32
,
destptr
,
i32
,
destsize
)
{
FC_ASSERT
(
destsize
>
0
);
wasm_interface
&
wasm
=
wasm_interface
::
get
();
...
...
@@ -555,7 +554,7 @@ DEFINE_INTRINSIC_FUNCTION2(env,assert,assert,none,i32,test,i32,msg) {
FC_ASSERT
(
test
,
"assertion failed: ${s}"
,
(
"s"
,
message
)(
"ptr"
,
msg
)
);
}
DEFINE_INTRINSIC_FUNCTION0
(
env
,
message
Size
,
messageS
ize
,
i32
)
{
DEFINE_INTRINSIC_FUNCTION0
(
env
,
message
_size
,
message_s
ize
,
i32
)
{
return
wasm_interface
::
get
().
current_validate_context
->
msg
.
data
.
size
();
}
...
...
programs/codegen/main.cpp
浏览文件 @
b9f10200
...
...
@@ -37,10 +37,10 @@ void generateBytesToValue(ostringstream& output, const types::Table& table) {
void
generateCurrentMessage
(
ostringstream
&
output
,
const
types
::
Action
&
action
)
{
output
<<
tab
<<
"template<>"
<<
endl
;
output
<<
tab
<<
action
.
type
<<
" current
M
essage<"
<<
action
.
type
<<
">() {"
<<
endl
;
output
<<
tab
<<
tab
<<
"uint32_t msgsize = message
S
ize();"
<<
endl
;
output
<<
tab
<<
action
.
type
<<
" current
_m
essage<"
<<
action
.
type
<<
">() {"
<<
endl
;
output
<<
tab
<<
tab
<<
"uint32_t msgsize = message
_s
ize();"
<<
endl
;
output
<<
tab
<<
tab
<<
"char* buffer = (char *)eos::malloc(msgsize);"
<<
endl
;
output
<<
tab
<<
tab
<<
"assert(read
M
essage(buffer, msgsize) == msgsize,
\"
error reading "
<<
action
.
type
<<
"
\"
);"
<<
endl
;
output
<<
tab
<<
tab
<<
"assert(read
_m
essage(buffer, msgsize) == msgsize,
\"
error reading "
<<
action
.
type
<<
"
\"
);"
<<
endl
;
output
<<
tab
<<
tab
<<
"datastream<char *> ds(buffer, msgsize);"
<<
endl
;
output
<<
tab
<<
tab
<<
action
.
type
<<
" value;"
<<
endl
;
output
<<
tab
<<
tab
<<
"raw::unpack(ds, value);"
<<
endl
;
...
...
@@ -120,7 +120,7 @@ int main (int argc, char *argv[]) {
}
output
<<
"} }"
<<
endl
<<
endl
;
//Generate current
M
essage specialization for every action
//Generate current
_m
essage specialization for every action
output
<<
"namespace eos {"
<<
endl
;
vector
<
types
::
TypeName
>
types_seen
;
for
(
const
auto
&
action
:
abi
.
actions
)
{
...
...
@@ -133,4 +133,4 @@ int main (int argc, char *argv[]) {
cout
<<
output
.
str
()
<<
endl
;
return
0
;
}
\ No newline at end of file
}
tests/api_tests/api_tests.cpp
浏览文件 @
b9f10200
...
...
@@ -231,7 +231,7 @@ BOOST_FIXTURE_TEST_CASE(test_all, testing_fixture)
//Test message
dummy_message
dummy13
{
DUMMY_MESSAGE_DEFAULT_A
,
DUMMY_MESSAGE_DEFAULT_B
,
DUMMY_MESSAGE_DEFAULT_C
};
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_message"
,
"read_message
"
),
{},
fc
::
raw
::
pack
(
dummy13
)
)
==
WASM_TEST_PASS
,
"test_message::read_message
()"
);
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_message"
,
"read_message
_normal"
),
{},
fc
::
raw
::
pack
(
dummy13
)
)
==
WASM_TEST_PASS
,
"test_message::read_message_normal
()"
);
std
::
vector
<
char
>
raw_bytes
((
1
<<
16
));
BOOST_CHECK_MESSAGE
(
CALL_TEST_FUNCTION
(
TEST_METHOD
(
"test_message"
,
"read_message_to_0"
),
{},
raw_bytes
)
==
WASM_TEST_PASS
,
"test_message::read_message_to_0()"
);
...
...
tests/slow_tests/slow_tests.cpp
浏览文件 @
b9f10200
...
...
@@ -491,7 +491,7 @@ R"(
(import "env" "assert" (func $assert (param i32 i32)))
(import "env" "load" (func $load (param i32 i32 i32 i32) (result i32)))
(import "env" "memcpy" (func $memcpy (param i32 i32 i32) (result i32)))
(import "env" "read
Message" (func $readM
essage (param i32 i32) (result i32)))
(import "env" "read
_message" (func $read_m
essage (param i32 i32) (result i32)))
(import "env" "remove" (func $remove (param i32 i32) (result i32)))
(import "env" "store" (func $store (param i32 i32 i32 i32)))
(table 0 anyfunc)
...
...
@@ -855,7 +855,7 @@ R"(
(local $1 i32)
(local $2 i64)
(set_local $0
(call $read
M
essage
(call $read
_m
essage
(i32.const 8384)
(i32.const 100)
)
...
...
tests/slow_tests/wast/loop.cpp
浏览文件 @
b9f10200
...
...
@@ -8,7 +8,7 @@ typedef unsigned int uint32_t;
typedef
uint64_t
AccountName
;
int
load
(
const
void
*
keyptr
,
int
keylen
,
void
*
valueptr
,
int
valuelen
);
void
store
(
const
void
*
keyptr
,
int
keylen
,
const
void
*
valueptr
,
int
valuelen
);
int
read
M
essage
(
void
*
dest
,
int
destsize
);
int
read
_m
essage
(
void
*
dest
,
int
destsize
);
int
remove
(
const
void
*
key
,
int
keyLength
);
void
printi
(
uint64_t
);
void
print
(
const
char
*
str
);
...
...
@@ -36,7 +36,7 @@ void store( const Key& key, const Value& v ) { store( &key, sizeof(key), &v, siz
template
<
typename
Key
>
void
remove
(
const
Key
&
key
)
{
remove
(
&
key
,
sizeof
(
key
)
);
}
template
<
typename
Message
>
void
read
Message
(
Message
&
m
)
{
readM
essage
(
&
m
,
sizeof
(
Message
)
);
}
void
read
_message
(
Message
&
m
)
{
read_m
essage
(
&
m
,
sizeof
(
Message
)
);
}
/// END BUILT IN LIBRARY.... everything below this is "user contract"
...
...
@@ -68,7 +68,7 @@ void apply_simplecoin_transfer() {
static
Balance
to_balance
;
to_balance
.
balance
=
0
;
read
M
essage
(
message
);
read
_m
essage
(
message
);
load
(
message
.
from
,
from_balance
);
load
(
message
.
to
,
to_balance
);
...
...
tests/slow_tests/wast/simplecoin.cpp
浏览文件 @
b9f10200
...
...
@@ -8,7 +8,7 @@ typedef unsigned int uint32_t;
typedef
uint64_t
AccountName
;
int
load
(
const
void
*
keyptr
,
int
keylen
,
void
*
valueptr
,
int
valuelen
);
void
store
(
const
void
*
keyptr
,
int
keylen
,
const
void
*
valueptr
,
int
valuelen
);
int
read
M
essage
(
void
*
dest
,
int
destsize
);
int
read
_m
essage
(
void
*
dest
,
int
destsize
);
int
remove
(
const
void
*
key
,
int
keyLength
);
void
printi
(
uint64_t
);
void
print
(
const
char
*
str
);
...
...
@@ -35,7 +35,7 @@ void store( const Key& key, const Value& v ) { store( &key, sizeof(key), &v, siz
template
<
typename
Key
>
void
remove
(
const
Key
&
key
)
{
remove
(
&
key
,
sizeof
(
key
)
);
}
template
<
typename
Message
>
void
read
Message
(
Message
&
m
)
{
readM
essage
(
&
m
,
sizeof
(
Message
)
);
}
void
read
_message
(
Message
&
m
)
{
read_m
essage
(
&
m
,
sizeof
(
Message
)
);
}
/// END BUILT IN LIBRARY.... everything below this is "user contract"
...
...
@@ -67,7 +67,7 @@ void apply_simplecoin_transfer() {
static
Balance
to_balance
;
to_balance
.
balance
=
0
;
read
M
essage
(
message
);
read
_m
essage
(
message
);
load
(
message
.
from
,
from_balance
);
load
(
message
.
to
,
to_balance
);
...
...
tests/tests/contracts/rate_limit_auth/rate_limit_auth.cpp
浏览文件 @
b9f10200
...
...
@@ -13,8 +13,8 @@ extern "C" {
void
test_auths
(
const
currency
::
Transfer
&
auth
)
{
require
A
uth
(
auth
.
from
);
require
A
uth
(
auth
.
to
);
require
_a
uth
(
auth
.
from
);
require
_a
uth
(
auth
.
to
);
}
/// The apply method implements the dispatch of events to this contract
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录