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

Removed action::current_action_data and PACKED macro since all actions are...

Removed action::current_action_data and PACKED macro since all actions are packed/unpacked according to the abi definition and cleanup of tests. GH #2350
上级 2164df8b
......@@ -15,22 +15,10 @@ extern "C" {
require_auth(code);
if( code == N(asserter) ) {
if( action == N(procassert) ) {
assertdef check;
read_action_data(&check, sizeof(assertdef));
unsigned char buffer[256];
size_t actsize = read_action_data(buffer, 256);
assertdef *def = reinterpret_cast<assertdef *>(buffer);
// make sure to null term the string
if (actsize < 255) {
buffer[actsize] = 0;
} else {
buffer[255] = 0;
}
assertdef def = eosio::unpack_action_data<assertdef>();
// maybe assert?
eosio_assert((uint32_t)def->condition, def->message);
eosio_assert((uint32_t)def.condition, def.message.c_str());
} else if( action == N(provereset) ) {
eosio_assert(global_variable == 45, "Global Variable Initialized poorly");
global_variable = 100;
......
......@@ -6,9 +6,10 @@
#include <eosiolib/eosio.hpp>
namespace asserter {
struct PACKED(assertdef) {
struct assertdef {
int8_t condition;
int8_t message_length;
char message[];
std::string message;
EOSLIB_SERIALIZE( assertdef, (condition)(message) )
};
}
......@@ -21,8 +21,7 @@ namespace eosio {
/**
*
* This method attempts to reinterpret the action body as type T. This will only work
* if the action has no dynamic fields and the struct packing on type T is properly defined.
* This method unpacks the current action at type T.
*
* @brief Interpret the action body as type T
*
......@@ -32,18 +31,12 @@ namespace eosio {
* char a; //1
* unsigned long long b; //8
* int c; //4
*
* EOSLIB_SERIALIZE( dummy_action, (a)(b)(c) )
* };
* dummy_action msg = current_action_data<dummy_action>();
* dummy_action msg = unpack_action_data<dummy_action>();
* @endcode
*/
template<typename T>
T current_action_data() {
T value;
auto read = read_action_data( &value, sizeof(value) );
eosio_assert( read >= sizeof(value), "action shorter than expected" );
return value;
}
template<typename T>
T unpack_action_data() {
char buffer[action_data_size()];
......
......@@ -32,8 +32,6 @@ typedef uint64_t asset_symbol;
typedef int64_t share_type;
typedef uint16_t weight_type;
#define PACKED(X) __attribute((packed)) X
struct public_key {
char data[34];
};
......
......@@ -104,7 +104,7 @@ extern "C" {
}
} else if (code == receiver ) {
if ( action == N(setowner)) {
apply_setowner(receiver, current_action_data<set_owner>());
apply_setowner(receiver, unpack_action_data<set_owner>());
}
}
}
......
......@@ -7,9 +7,11 @@
namespace proxy {
//@abi action
struct PACKED( set_owner ) {
struct set_owner {
account_name owner;
uint32_t delay;
EOSLIB_SERIALIZE( set_owner, (owner)(delay) )
};
//@abi table
......
......@@ -41,6 +41,8 @@ struct dummy_action {
struct u128_action {
unsigned __int128 values[3]; //16*3
EOSLIB_SERIALIZE( u128_action, (values) )
};
struct cf_action {
......
......@@ -5,9 +5,7 @@
#include "test_api.hpp"
void test_math::test_multeq() {
u128_action act;
auto n = read_action_data(&act, sizeof(u128_action));
eosio_assert( n == sizeof(u128_action), "test_multeq n == sizeof(u128_action)" );
u128_action act = eosio::unpack_action_data<u128_action>();
uint128_t self = *(act.values);
uint128_t other = *(act.values+1);
......@@ -16,9 +14,7 @@ void test_math::test_multeq() {
}
void test_math::test_diveq() {
u128_action act;
auto n = read_action_data(&act, sizeof(u128_action));
eosio_assert( n == sizeof(u128_action), "test_diveq n == sizeof(u128_action)" );
u128_action act = eosio::unpack_action_data<u128_action>();
uint128_t self = *(act.values);
uint128_t other = *(act.values+1);
......
......@@ -910,7 +910,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_unable_to_determine_index, abi_gen_helper)
#include <eosiolib/types.h>
//@abi table
struct PACKED(table1) {
struct table1 {
uint32_t field1;
uint64_t field2;
};
......@@ -930,7 +930,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_long_field_name, abi_gen_helper)
#include <eosiolib/types.h>
//@abi table
struct PACKED(table1) {
struct table1 {
uint64_t thisisaverylongfieldname;
};
......@@ -951,7 +951,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_long_type_name, abi_gen_helper)
};
//@abi table
struct PACKED(table1) {
struct table1 {
this_is_a_very_very_very_very_long_type_name field1;
};
......@@ -1344,7 +1344,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_field_typedef, abi_gen_helper)
typedef complex_field my_complex_field_alias;
//@abi table
struct PACKED(table1) {
struct table1 {
uint64_t field1;
my_complex_field_alias field2;
my_name_alias name;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册