提交 b9f10200 编写于 作者: B Brian Johnson

Making Contract API functions and methods conform to our naming standard.

上级 7435d469
......@@ -20,8 +20,8 @@ namespace TOKEN_NAME {
}
void apply_currency_transfer( const TOKEN_NAME::Transfer& transfer ) {
requireNotice( transfer.to, transfer.from );
requireAuth( transfer.from );
require_notice( transfer.to, transfer.from );
require_auth( 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( currentMessage< TOKEN_NAME::Transfer >() );
currency::apply_currency_transfer( current_message< TOKEN_NAME::Transfer >() );
}
}
}
......@@ -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" );
requireAuth( offer.player );
require_auth( offer.player );
auto acnt = getAccount( offer.player );
acnt.balance -= offer.amount;
......
......@@ -21,11 +21,11 @@ extern "C" {
* Example:
* @code
* AccountName producers[21];
* getActiveProducers(producers, sizeof(AccountName)*21);
* get_active_producers(producers, sizeof(AccountName)*21);
* @endcode
*/
void getActiveProducers( AccountName* producers, uint32_t datalen );
void get_active_producers( AccountName* producers, uint32_t datalen );
///@ } chaincapi
}
\ No newline at end of file
}
......@@ -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( currentCode(), currentCode(), N(test_table), &alice, sizeof(TestModel) );
* res = load_i64( current_code(), current_code(), 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( currentCode(), currentCode(), N(test_table), &tmp, sizeof(TestModel) );
* res = front_i64( current_code(), current_code(), 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( currentCode(), currentCode(), N(test_table), &tmp, sizeof(TestModel) );
* res = back_i64( current_code(), current_code(), 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( currentCode(), currentCode(), N(test_table), &tmp, sizeof(TestModel) );
* res = previous_i64( current_code(), current_code(), 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( currentCode(), currentCode(), N(test_table), &tmp, sizeof(TestModel) );
* res = next_i64( current_code(), current_code(), 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(currentCode(), N(test_table), &key);
* res = remove_i64(current_code(), N(test_table), &key);
* ASSERT(res == 1, "remove alice");
*
* TestModel lb;
* lb.name = N(bob);
* res = lower_bound_i64( currentCode(), currentCode(), N(test_table), &lb, sizeof(TestModel) );
* res = lower_bound_i64( current_code(), current_code(), 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( currentCode(), currentCode(), N(test_table), &ub, sizeof(TestModel) );
* res = upper_bound_i64( current_code(), current_code(), N(test_table), &ub, sizeof(TestModel) );
* ASSERT(res == sizeof(TestModel) && ub.age == 15 && ub.name == N(bob), "upper_bound_i64 bob" );
* @endcode
* @{
......
......@@ -47,22 +47,22 @@ extern "C" {
* // }
*
* char buffer[128];
* uint32_t total = readMessage(buffer, 5); // buffer contains the content of the message up to 5 bytes
* uint32_t total = read_message(buffer, 5); // buffer contains the content of the message up to 5 bytes
* print(total); // Output: 5
*
* uint32_t msgsize = messageSize();
* uint32_t msgsize = message_size();
* print(msgsize); // Output: size of the above message's data field
*
* requireNotice(N(initc)); // initc account will be notified for this message
* require_notice(N(initc)); // initc account will be notified for this message
*
* requireAuth(N(inita)); // Do nothing since inita exists in the auth list
* requireAuth(N(initb)); // Throws an exception
* require_auth(N(inita)); // Do nothing since inita exists in the auth list
* require_auth(N(initb)); // Throws an exception
*
* AccountName code = currentCode();
* AccountName code = current_code();
* print(Name(code)); // Output: eos
*
* assert(Name(currentCode()) === "eos", "This message expects to be received by eos"); // Do nothing
* assert(Name(currentCode()) === "inita", "This message expects to be received by inita"); // Throws exception and roll back transfer transaction
* assert(Name(current_code()) === "eos", "This message expects to be received by eos"); // Do nothing
* assert(Name(current_code()) === "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 readMessage( void* msg, uint32_t len );
uint32_t read_message( 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 messageSize();
uint32_t message_size();
/**
* 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 requireNotice( AccountName name );
void require_notice( 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 currentCode();
AccountName current_code();
///@ } messagecapi
}
......@@ -32,19 +32,19 @@ namespace eos {
* unsigned long long b; //8
* int c; //4
* };
* dummy_message msg = currentMessage<dummy_message>();
* dummy_message msg = current_message<dummy_message>();
* @endcode
*/
template<typename T>
T currentMessage() {
T current_message() {
T value;
auto read = readMessage( &value, sizeof(value) );
auto read = read_message( &value, sizeof(value) );
assert( read >= sizeof(value), "message shorter than expected" );
return value;
}
using ::requireAuth;
using ::requireNotice;
using ::require_auth;
using ::require_notice;
/**
* All of the listed accounts will be added to the set of accounts to be notified
......@@ -58,13 +58,13 @@ namespace eos {
*
* Example:
* @code
* requireNotice(N(Account1), N(Account2), N(Account3)); // throws exception if any of them not in set.
* require_notice(N(Account1), N(Account2), N(Account3)); // throws exception if any of them not in set.
* @endcode
*/
template<typename... Accounts>
void requireNotice( AccountName name, Accounts... accounts ){
requireNotice( name );
requireNotice( accounts... );
void require_notice( AccountName name, Accounts... accounts ){
require_notice( name );
require_notice( accounts... );
}
......
......@@ -76,7 +76,7 @@ extern "C" {
*
* @return handle used to refer to this transaction in future API calls
*/
TransactionHandle transactionCreate();
TransactionHandle transaction_create();
/**
* @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 transactionRequireScope(TransactionHandle trx, AccountName scope, int readOnly = 0);
void transaction_require_scope(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 transactionAddMessage(TransactionHandle trx, MessageHandle msg);
void transaction_add_message(TransactionHandle trx, MessageHandle msg);
/**
......@@ -112,7 +112,7 @@ extern "C" {
*
* @param trx - the `TransactionHandle` of the pending transaction to send
*/
void transactionSend(TransactionHandle trx);
void transaction_send(TransactionHandle trx);
/**
* @brief drop a pending transaction
......@@ -124,7 +124,7 @@ extern "C" {
*
* @param trx - the `TransactionHandle` of the pending transaction to send
*/
void transactionDrop(TransactionHandle trx);
void transaction_drop(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 messageRequirePermission
* This message has no default permissions, see @ref message_require_permission
*
* @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 messageCreate(AccountName code, FuncName type, void const* data, int size);
MessageHandle message_create(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 messageRequirePermission(MessageHandle msg, AccountName account, PermissionName permission);
void message_require_permission(MessageHandle msg, AccountName account, PermissionName permission);
/**
......@@ -161,7 +161,7 @@ extern "C" {
*
* @param msg - the `MessageHandle` of the pending message to send inline
*/
void messageSend(MessageHandle msg);
void message_send(MessageHandle msg);
/**
......@@ -171,7 +171,7 @@ extern "C" {
*
* @param trx - the `MessageHandle` of the pending message to discard
*/
void messageDrop(MessageHandle msg);
void message_drop(MessageHandle msg);
///@ } transactioncapi
......
......@@ -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(messageCreate(code, type, &payload, sizeof(Payload)))
: handle(message_create(code, type, &payload, sizeof(Payload)))
{
addPermissions(permissions...);
add_permissions(permissions...);
}
template<typename Payload>
Message(const AccountName& code, const FuncName& type, const Payload& payload )
: handle(messageCreate(code, type, &payload, sizeof(Payload)))
: handle(message_create(code, type, &payload, sizeof(Payload)))
{
}
Message(const AccountName& code, const FuncName& type)
: handle(messageCreate(code, type, nullptr, 0))
: handle(message_create(code, type, nullptr, 0))
{
}
......@@ -49,29 +49,29 @@ namespace eos {
~Message() {
if (handle != InvalidMessageHandle) {
messageDrop(handle);
message_drop(handle);
handle = InvalidMessageHandle;
}
}
void addPermissions(AccountName account, PermissionName permission) {
messageRequirePermission(handle, account, permission);
void add_permissions(AccountName account, PermissionName permission) {
message_require_permission(handle, account, permission);
}
template<typename ...Permissions>
void addPermissions(AccountName account, PermissionName permission, Permissions... permissions) {
addPermissions(account, permission);
addPermissions(permissions...);
void add_permissions(AccountName account, PermissionName permission, Permissions... permissions) {
add_permissions(account, permission);
add_permissions(permissions...);
}
void send() {
assertValidHandle();
messageSend(handle);
assert_valid_handle();
message_send(handle);
handle = InvalidMessageHandle;
}
private:
void assertValidHandle() {
void assert_valid_handle() {
assert(handle != InvalidMessageHandle, "attempting to send or modify a finalized message" );
}
......@@ -84,7 +84,7 @@ namespace eos {
class Transaction {
public:
Transaction()
: handle(transactionCreate())
: handle(transaction_create())
{}
// no copy constructor due to opaque handle
......@@ -97,26 +97,26 @@ namespace eos {
~Transaction() {
if (handle != InvalidTransactionHandle) {
transactionDrop(handle);
transaction_drop(handle);
handle = InvalidTransactionHandle;
}
}
void addScope(AccountName scope, bool readOnly = false) {
assertValidHandle();
transactionRequireScope(handle, scope, readOnly ? 1 : 0);
assert_valid_handle();
transaction_require_scope(handle, scope, readOnly ? 1 : 0);
}
void addMessage(Message &message) {
assertValidHandle();
message.assertValidHandle();
transactionAddMessage(handle, message.handle);
assert_valid_handle();
message.assert_valid_handle();
transaction_add_message(handle, message.handle);
message.handle = InvalidMessageHandle;
}
void send() {
assertValidHandle();
transactionSend(handle);
assert_valid_handle();
transaction_send(handle);
handle = InvalidTransactionHandle;
}
......@@ -125,7 +125,7 @@ namespace eos {
}
private:
void assertValidHandle() {
void assert_valid_handle() {
assert(handle != InvalidTransactionHandle, "attempting to send or modify a finalized transaction" );
}
......
......@@ -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 requireNotice()
* The exchange contract knows that the currency contracts require_notice()
* 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) ) {
requireAuth( transfer.to ); /// require the receiver of funds (account owner) to authorize this transfer
require_auth( 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) ) {
requireAuth( transfer.to ); /// require the receiver of funds (account owner) to authorize this transfer
require_auth( 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;
requireAuth( 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;
requireAuth( 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 ) {
requireAuth( 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 ) {
requireAuth( 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( currentMessage<exchange::BuyOrder>() );
apply_exchange_buy( current_message<exchange::BuyOrder>() );
break;
case N(sell):
apply_exchange_sell( currentMessage<exchange::SellOrder>() );
apply_exchange_sell( current_message<exchange::SellOrder>() );
break;
case N(cancelbuy):
apply_exchange_cancel_buy( currentMessage<exchange::OrderID>() );
apply_exchange_cancel_buy( current_message<exchange::OrderID>() );
break;
case N(cancelsell):
apply_exchange_cancel_sell( currentMessage<exchange::OrderID>() );
apply_exchange_cancel_sell( current_message<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( currentMessage<currency::Transfer>() );
apply_currency_transfer( current_message<currency::Transfer>() );
}
else if( code == N(eos) ) {
if( action == N(transfer) )
apply_eos_transfer( currentMessage<eos::Transfer>() );
apply_eos_transfer( current_message<eos::Transfer>() );
}
else {
}
......
......@@ -19,8 +19,8 @@ namespace infinite {
}
void apply_currency_transfer( const infinite::Transfer& transfer ) {
requireNotice( transfer.to, transfer.from );
requireAuth( transfer.from );
require_notice( transfer.to, transfer.from );
require_auth( 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( currentMessage< infinite::Transfer >() );
if( action == N(transfer) )
infinite::apply_currency_transfer( current_message< infinite::Transfer >() );
}
}
}
......@@ -10,7 +10,7 @@ namespace proxy {
template<typename T>
void apply_transfer(AccountName code, const T& transfer) {
const auto self = currentCode();
const auto self = current_code();
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 = currentCode();
const auto self = current_code();
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, currentMessage<currency::Transfer>());
apply_transfer(code, current_message<currency::Transfer>());
}
} else if ( code == N(eos) ) {
if( action == N(transfer) ) {
apply_transfer(code, currentMessage<eos::Transfer>());
apply_transfer(code, current_message<eos::Transfer>());
}
} else if (code == N(proxy) ) {
if ( action == N(setowner)) {
apply_setowner(currentMessage<AccountName>());
apply_setowner(current_message<AccountName>());
}
}
}
......
......@@ -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::currentMessage<KeyValue1>();
auto kv1 = eos::current_message<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::currentMessage<KeyValue2>();
auto kv2 = eos::current_message<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;
readMessage(&tmp, sizeof(tmp));
read_message(&tmp, sizeof(tmp));
store_i64( N(simpledb), N(record1), &tmp, sizeof(tmp) );
} else if(action == N(insert2)) {
record2 tmp;
readMessage(&tmp, sizeof(tmp));
read_message(&tmp, sizeof(tmp));
store_i128i128( N(simpledb), N(record2), &tmp, sizeof(tmp) );
} else if(action == N(insert3)) {
record3 tmp;
readMessage(&tmp, sizeof(tmp));
read_message(&tmp, sizeof(tmp));
store_i64i64i64( N(simpledb), N(record3), &tmp, sizeof(tmp) );
} else {
assert(0, "unknown message");
......
......@@ -4,7 +4,7 @@
#include <eoslib/print.hpp>
// These functions can be auto-generated using the ABI definition.
// The specialization for currentMessage 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 currentMessage<KeyValue1>() {
uint32_t msgsize = messageSize();
KeyValue1 current_message<KeyValue1>() {
uint32_t msgsize = message_size();
char* buffer = (char *)eos::malloc(msgsize);
assert(readMessage(buffer, msgsize) == msgsize, "error reading KeyValue1");
assert(read_message(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 currentMessage<KeyValue2>() {
uint32_t msgsize = messageSize();
KeyValue2 current_message<KeyValue2>() {
uint32_t msgsize = message_size();
char* buffer = (char *)eos::malloc(msgsize);
assert(readMessage(buffer, msgsize) == msgsize, "error reading KeyValue2");
assert(read_message(buffer, msgsize) == msgsize, "error reading KeyValue2");
datastream<char *> ds(buffer, msgsize);
KeyValue2 value;
raw::unpack(ds, value.key);
......
......@@ -59,8 +59,8 @@ struct Account {
* any other contexts are notified
*/
void apply_social_post() {
const auto& post = currentMessage<PostAction>();
requireAuth( post.author );
const auto& post = current_message<PostAction>();
require_auth( 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 = currentMessage<VoteAction>();
requireNotice( vote.voter, vote.author );
const auto& vote = current_message<VoteAction>();
require_notice( vote.voter, vote.author );
disableContextCode( vote.author() ); /// prevent the author's code from rejecting the potentially negative vote
auto context = currentContext();
......
......@@ -14,8 +14,8 @@ namespace TOKEN_NAME {
}
void apply_storage_transfer( const TOKEN_NAME::Transfer& transfer ) {
eos::requireNotice( transfer.to, transfer.from );
eos::requireAuth( transfer.from );
eos::require_notice( transfer.to, transfer.from );
eos::require_auth( 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 = readMessage(tmp, 4098);
auto bufferlen = read_message(tmp, 4098);
auto linklen = readLinkFromBuffer( tmp, bufferlen, link, eospathlen, ipfspathlen );
eos::requireNotice( link.owner );
eos::requireAuth( link.owner );
eos::require_notice( link.owner );
eos::require_auth( link.owner );
validate_ipfspath( link.ipfspath, ipfspathlen );
validate_eospath( link.eospath, eospathlen );
::store_str( currentCode(), N(storage), link.eospath, eospathlen, (char*)&link, linklen );
::store_str( current_code(), N(storage), link.eospath, eospathlen, (char*)&link, linklen );
}
void apply_storage_removelink( char* eospath, uint32_t eospathlen ) {
char tmp[4098];
auto len = ::load_str( currentCode(), currentCode(), N(storage), eospath, eospathlen, tmp, 4098 );
auto len = ::load_str( current_code(), current_code(), N(storage), eospath, eospathlen, tmp, 4098 );
TOKEN_NAME::Link link;
uint32_t ipfspathlen;
len = readLinkFromBuffer( tmp, len, link, eospathlen, ipfspathlen );
eos::requireAuth( link.owner );
eos::require_auth( link.owner );
uint32_t stake = link.stake;
::remove_str( currentCode(), N(storage), link.eospath, eospathlen );
::remove_str( current_code(), 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( currentCode(), currentCode(), N(storage), eospath, eospathlen, tmp, 4098 );
auto len = ::load_str( current_code(), current_code(), N(storage), eospath, eospathlen, tmp, 4098 );
TOKEN_NAME::Link link;
uint32_t ipfspathlen;
len = readLinkFromBuffer( tmp, len, link, eospathlen, ipfspathlen );
// eos::requireAuth( producer )
// How do we validate the requireAuth() is a producer?
// eos::require_auth( producer )
// How do we validate the require_auth() is a producer?
// logic goes here to reduce number of tokens and increase quote used using bancor algorithm
link.accept = 1;
::store_str( currentCode(), N(storage), link.eospath, eospathlen, (char*)&link, len );
::store_str( current_code(), N(storage), link.eospath, eospathlen, (char*)&link, len );
}
void apply_storage_rejectstore( char* eospath, uint32_t eospathlen ) {
char tmp[4098];
auto len = ::load_str( currentCode(), currentCode(), N(storage), eospath, eospathlen, tmp, 4098 );
auto len = ::load_str( current_code(), current_code(), N(storage), eospath, eospathlen, tmp, 4098 );
TOKEN_NAME::Link link;
uint32_t ipfspathlen;
len = readLinkFromBuffer( tmp, len, link, eospathlen, ipfspathlen );
// eos::requireAuth( producer )
// How do we validate the requireAuth() is a producer?
// eos::require_auth( producer )
// How do we validate the require_auth() is a producer?
link.accept = 0;
::store_str( currentCode(), N(storage), link.eospath, eospathlen, (char*)&link, len );
::store_str( current_code(), 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::currentMessage< TOKEN_NAME::Transfer >() );
TOKEN_NAME::apply_storage_transfer( eos::current_message< TOKEN_NAME::Transfer >() );
} else if (action == N(setlink) ) {
TOKEN_NAME::apply_storage_setlink();
} else if (action == N(removelink) ) {
char tmp[1025];
auto len = readMessage( tmp, 1025 );
auto len = read_message( tmp, 1025 );
TOKEN_NAME::apply_storage_removelink( tmp, len );
} else if (action == N(acceptstore) ) {
char tmp[1025];
auto len = readMessage( tmp, 1025 );
auto len = read_message( tmp, 1025 );
TOKEN_NAME::apply_storage_createstore( tmp, len );
} else if (action == N(rejectstore) ) {
char tmp[1025];
auto len = readMessage( tmp, 1025 );
auto len = read_message( tmp, 1025 );
TOKEN_NAME::apply_storage_rejectstore( tmp, len );
} else {
assert(0, "unknown message");
......
......@@ -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);
......
......@@ -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();
......
......@@ -16,16 +16,16 @@ struct Producers {
unsigned int test_chain::test_activeprods() {
Producers msg_prods;
readMessage(&msg_prods, sizeof(Producers));
read_message(&msg_prods, sizeof(Producers));
WASM_ASSERT(msg_prods.len == 21, "Producers.len != 21");
Producers api_prods;
getActiveProducers(api_prods.producers, sizeof(AccountName)*21);
get_active_producers(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
}
此差异已折叠。
......@@ -6,7 +6,7 @@
unsigned int test_math::test_multeq_i128() {
u128_msg msg;
auto n = readMessage(&msg, sizeof(u128_msg));
auto n = read_message(&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 = readMessage(&msg, sizeof(u128_msg));
auto n = read_message(&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
}
......@@ -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( currentCode() == N(testapi), "currentCode() == N(testapi)" );
WASM_ASSERT( current_code() == N(testapi), "current_code() == N(testapi)" );
WASM_ASSERT(messageSize() == sizeof(dummy_message), "messageSize() == sizeof(dummy_message)");
WASM_ASSERT(message_size() == sizeof(dummy_message), "message_size() == sizeof(dummy_message)");
total = readMessage(buffer, 30);
WASM_ASSERT(total == sizeof(dummy_message) , "readMessage(30)" );
total = read_message(buffer, 30);
WASM_ASSERT(total == sizeof(dummy_message) , "read_message(30)" );
total = readMessage(buffer, 100);
WASM_ASSERT(total == sizeof(dummy_message) , "readMessage(100)" );
total = read_message(buffer, 100);
WASM_ASSERT(total == sizeof(dummy_message) , "read_message(100)" );
total = readMessage(buffer, 5);
WASM_ASSERT(total == 5 , "readMessage(5)" );
total = read_message(buffer, 5);
WASM_ASSERT(total == 5 , "read_message(5)" );
total = readMessage(buffer, sizeof(dummy_message) );
WASM_ASSERT(total == sizeof(dummy_message), "readMessage(sizeof(dummy_message))" );
total = read_message(buffer, sizeof(dummy_message) );
WASM_ASSERT(total == sizeof(dummy_message), "read_message(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 = readMessage((void *)0, 0x7FFFFFFF);
uint32_t total = read_message((void *)0, 0x7FFFFFFF);
return WASM_TEST_PASS;
}
unsigned int test_message::read_message_to_64k() {
uint32_t total = readMessage( (void *)((1<<16)-1), 0x7FFFFFFF);
uint32_t total = read_message( (void *)((1<<16)-1), 0x7FFFFFFF);
return WASM_TEST_PASS;
}
unsigned int test_message::require_notice() {
if( currentCode() == N(testapi) ) {
eos::requireNotice( N(acc1) );
eos::requireNotice( N(acc2) );
eos::requireNotice( N(acc1), N(acc2) );
if( current_code() == N(testapi) ) {
eos::require_notice( N(acc1) );
eos::require_notice( N(acc2) );
eos::require_notice( N(acc1), N(acc2) );
return WASM_TEST_FAIL;
} else if ( currentCode() == N(acc1) || currentCode() == N(acc2) ) {
} else if ( current_code() == N(acc1) || current_code() == N(acc2) ) {
return WASM_TEST_PASS;
}
return WASM_TEST_FAIL;
}
unsigned int test_message::require_auth() {
eos::requireAuth( N(acc3) );
eos::requireAuth( N(acc4) );
eos::require_auth( N(acc3) );
eos::require_auth( 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 = readMessage(&tmp, sizeof(uint32_t));
uint32_t total = read_message(&tmp, sizeof(uint32_t));
WASM_ASSERT( total == sizeof(uint32_t), "total == sizeof(uint32_t)");
WASM_ASSERT( tmp == ::now(), "tmp == now()" );
return WASM_TEST_PASS;
......
......@@ -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 = messageCreate(N(testapi), WASM_TEST_ACTION("test_message", "read_message"), &payload, sizeof(dummy_message));
messageSend(msg);
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_message", "read_message_normal"), &payload, sizeof(dummy_message));
message_send(msg);
return WASM_TEST_PASS;
}
unsigned int test_transaction::send_message_empty() {
auto msg = messageCreate(N(testapi), WASM_TEST_ACTION("test_message", "assert_true"), nullptr, 0);
messageSend(msg);
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_message", "assert_true"), nullptr, 0);
message_send(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++) {
messageCreate(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];
messageCreate(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 = readMessage(buffer, 1024);
auto msg = messageCreate(N(testapi), WASM_TEST_ACTION("test_transaction", "send_message_recurse"), buffer, size);
messageSend(msg);
uint32_t size = read_message(buffer, 1024);
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_transaction", "send_message_recurse"), buffer, size);
message_send(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 = messageCreate(N(testapi), WASM_TEST_ACTION("test_message", "assert_false"), nullptr, 0);
messageSend(msg);
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_message", "assert_false"), nullptr, 0);
message_send(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 = messageCreate(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 = transactionCreate();
transactionRequireScope(trx, N(testapi));
transactionAddMessage(trx, msg);
transactionSend(trx);
auto trx = transaction_create();
transaction_require_scope(trx, N(testapi));
transaction_add_message(trx, msg);
transaction_send(trx);
return WASM_TEST_PASS;
}
unsigned int test_transaction::send_transaction_empty() {
auto trx = transactionCreate();
transactionRequireScope(trx, N(testapi));
transactionSend(trx);
auto trx = transaction_create();
transaction_require_scope(trx, N(testapi));
transaction_send(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++) {
transactionCreate();
transaction_create();
}
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 = transactionCreate();
transactionRequireScope(trx, N(testapi));
auto trx = transaction_create();
transaction_require_scope(trx, N(testapi));
for (int i = 0; i < 32; i ++) {
char large_message[4 * 1024];
auto msg = messageCreate(N(testapi), WASM_TEST_ACTION("test_message", "read_message"), large_message, sizeof(large_message));
transactionAddMessage(trx, msg);
auto msg = message_create(N(testapi), WASM_TEST_ACTION("test_message", "read_message_normal"), large_message, sizeof(large_message));
transaction_add_message(trx, msg);
}
transactionSend(trx);
transaction_send(trx);
return WASM_TEST_FAIL;
}
......@@ -88,7 +88,7 @@ namespace tic_tac_toe {
* @param create - action to be applied
*/
void apply_create(const Create& create) {
requireAuth(create.host);
require_auth(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) {
requireAuth(restart.by);
require_auth(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) {
requireAuth(close.host);
require_auth(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) {
requireAuth(move.by);
require_auth(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(currentMessage<tic_tac_toe::Create>());
tic_tac_toe::apply_create(current_message<tic_tac_toe::Create>());
} else if (action == N(restart)) {
tic_tac_toe::apply_restart(currentMessage<tic_tac_toe::Restart>());
tic_tac_toe::apply_restart(current_message<tic_tac_toe::Restart>());
} else if (action == N(close)) {
tic_tac_toe::apply_close(currentMessage<tic_tac_toe::Close>());
tic_tac_toe::apply_close(current_message<tic_tac_toe::Close>());
} else if (action == N(move)) {
tic_tac_toe::apply_move(currentMessage<tic_tac_toe::Move>());
tic_tac_toe::apply_move(current_message<tic_tac_toe::Move>());
}
}
}
......
......@@ -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,currentCode,currentCode,i64) {
DEFINE_INTRINSIC_FUNCTION0(env,current_code,current_code,i64) {
auto& wasm = wasm_interface::get();
return wasm.current_validate_context->code.value;
}
DEFINE_INTRINSIC_FUNCTION1(env,requireAuth,requireAuth,none,i64,account) {
DEFINE_INTRINSIC_FUNCTION1(env,require_auth,require_auth,none,i64,account) {
wasm_interface::get().current_validate_context->require_authorization( Name(account) );
}
DEFINE_INTRINSIC_FUNCTION1(env,requireNotice,requireNotice,none,i64,account) {
DEFINE_INTRINSIC_FUNCTION1(env,require_notice,require_notice,none,i64,account) {
wasm_interface::get().current_apply_context->require_recipient( account );
}
DEFINE_INTRINSIC_FUNCTION1(env,requireScope,requireScope,none,i64,scope) {
DEFINE_INTRINSIC_FUNCTION1(env,require_scope,require_scope,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,transactionCreate,transactionCreate,i32) {
DEFINE_INTRINSIC_FUNCTION0(env,transaction_create,transaction_create,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,transactionRequireScope,transactionRequireScope,none,i32,handle,i64,scope,i32,readOnly) {
DEFINE_INTRINSIC_FUNCTION3(env,transaction_require_scope,transaction_require_scope,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,transactionAddMessage,transactionAddMessage,none,i32,handle,i32,msg_handle) {
DEFINE_INTRINSIC_FUNCTION2(env,transaction_add_message,transaction_add_message,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,transactionSend,transactionSend,none,i32,handle) {
DEFINE_INTRINSIC_FUNCTION1(env,transaction_send,transaction_send,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,transactionDrop,transactionDrop,none,i32,handle) {
DEFINE_INTRINSIC_FUNCTION1(env,transaction_drop,transaction_drop,none,i32,handle) {
wasm_interface::get().current_apply_context->release_pending_transaction(handle);
}
DEFINE_INTRINSIC_FUNCTION4(env,messageCreate,messageCreate,i32,i64,code,i64,type,i32,data,i32,length) {
DEFINE_INTRINSIC_FUNCTION4(env,message_create,message_create,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,messageRequirePermission,messageRequirePermission,none,i32,handle,i64,account,i64,permission) {
DEFINE_INTRINSIC_FUNCTION3(env,message_require_permission,message_require_permission,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,messageSend,messageSend,none,i32,handle) {
DEFINE_INTRINSIC_FUNCTION1(env,message_send,message_send,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,messageDrop,messageDrop,none,i32,handle) {
DEFINE_INTRINSIC_FUNCTION1(env,message_drop,message_drop,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,readMessage,readMessage,i32,i32,destptr,i32,destsize) {
DEFINE_INTRINSIC_FUNCTION2(env,read_message,read_message,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,messageSize,messageSize,i32) {
DEFINE_INTRINSIC_FUNCTION0(env,message_size,message_size,i32) {
return wasm_interface::get().current_validate_context->msg.data.size();
}
......
......@@ -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 << " currentMessage<" << action.type << ">() {" << endl;
output << tab << tab << "uint32_t msgsize = messageSize();" << endl;
output << tab << action.type << " current_message<" << action.type << ">() {" << endl;
output << tab << tab << "uint32_t msgsize = message_size();" << endl;
output << tab << tab << "char* buffer = (char *)eos::malloc(msgsize);" << endl;
output << tab << tab << "assert(readMessage(buffer, msgsize) == msgsize, \"error reading " << action.type << "\");" << endl;
output << tab << tab << "assert(read_message(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 currentMessage specialization for every action
//Generate current_message 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
}
......@@ -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()" );
......
......@@ -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" "readMessage" (func $readMessage (param i32 i32) (result i32)))
(import "env" "read_message" (func $read_message (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 $readMessage
(call $read_message
(i32.const 8384)
(i32.const 100)
)
......
......@@ -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 readMessage( void* dest, int destsize );
int read_message( 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 readMessage( Message& m ) { readMessage( &m, sizeof(Message) ); }
void read_message( Message& m ) { read_message( &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;
readMessage( message );
read_message( message );
load( message.from, from_balance );
load( message.to, to_balance );
......
......@@ -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 readMessage( void* dest, int destsize );
int read_message( 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 readMessage( Message& m ) { readMessage( &m, sizeof(Message) ); }
void read_message( Message& m ) { read_message( &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;
readMessage( message );
read_message( message );
load( message.from, from_balance );
load( message.to, to_balance );
......
......@@ -13,8 +13,8 @@ extern "C" {
void test_auths(const currency::Transfer& auth)
{
requireAuth( auth.from );
requireAuth( auth.to );
require_auth( auth.from );
require_auth( 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.
先完成此消息的编辑!
想要评论请 注册