From a78e41f103e47c85f4dc96c1dae6a073efade9f6 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Mon, 16 Apr 2018 09:23:23 -0500 Subject: [PATCH] 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 --- contracts/asserter/asserter.cpp | 16 ++-------------- contracts/asserter/asserter.hpp | 9 +++++---- contracts/eosiolib/action.hpp | 15 ++++----------- contracts/eosiolib/types.h | 2 -- contracts/proxy/proxy.cpp | 2 +- contracts/proxy/proxy.hpp | 6 ++++-- contracts/test_api/test_api_common.hpp | 2 ++ contracts/test_api/test_math.cpp | 8 ++------ tests/tests/abi_tests.cpp | 12 ++++++------ 9 files changed, 26 insertions(+), 46 deletions(-) diff --git a/contracts/asserter/asserter.cpp b/contracts/asserter/asserter.cpp index fab723825..aee8199c1 100644 --- a/contracts/asserter/asserter.cpp +++ b/contracts/asserter/asserter.cpp @@ -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(buffer); - - // make sure to null term the string - if (actsize < 255) { - buffer[actsize] = 0; - } else { - buffer[255] = 0; - } + assertdef def = eosio::unpack_action_data(); // 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; diff --git a/contracts/asserter/asserter.hpp b/contracts/asserter/asserter.hpp index 99ebad6d3..99680870c 100644 --- a/contracts/asserter/asserter.hpp +++ b/contracts/asserter/asserter.hpp @@ -6,9 +6,10 @@ #include namespace asserter { - struct PACKED(assertdef) { - int8_t condition; - int8_t message_length; - char message[]; + struct assertdef { + int8_t condition; + std::string message; + + EOSLIB_SERIALIZE( assertdef, (condition)(message) ) }; } diff --git a/contracts/eosiolib/action.hpp b/contracts/eosiolib/action.hpp index 7d156671d..20de85a2c 100644 --- a/contracts/eosiolib/action.hpp +++ b/contracts/eosiolib/action.hpp @@ -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 msg = unpack_action_data(); * @endcode */ - template - 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 T unpack_action_data() { char buffer[action_data_size()]; diff --git a/contracts/eosiolib/types.h b/contracts/eosiolib/types.h index 7fbf3be4f..eedb5926c 100644 --- a/contracts/eosiolib/types.h +++ b/contracts/eosiolib/types.h @@ -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]; }; diff --git a/contracts/proxy/proxy.cpp b/contracts/proxy/proxy.cpp index fe27d159b..100b64b51 100644 --- a/contracts/proxy/proxy.cpp +++ b/contracts/proxy/proxy.cpp @@ -104,7 +104,7 @@ extern "C" { } } else if (code == receiver ) { if ( action == N(setowner)) { - apply_setowner(receiver, current_action_data()); + apply_setowner(receiver, unpack_action_data()); } } } diff --git a/contracts/proxy/proxy.hpp b/contracts/proxy/proxy.hpp index f85b9ea2c..b31b31ecd 100644 --- a/contracts/proxy/proxy.hpp +++ b/contracts/proxy/proxy.hpp @@ -5,11 +5,13 @@ #include 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 diff --git a/contracts/test_api/test_api_common.hpp b/contracts/test_api/test_api_common.hpp index 2546b9622..e74c23429 100644 --- a/contracts/test_api/test_api_common.hpp +++ b/contracts/test_api/test_api_common.hpp @@ -41,6 +41,8 @@ struct dummy_action { struct u128_action { unsigned __int128 values[3]; //16*3 + + EOSLIB_SERIALIZE( u128_action, (values) ) }; struct cf_action { diff --git a/contracts/test_api/test_math.cpp b/contracts/test_api/test_math.cpp index 08393e860..fb8ecc2e2 100644 --- a/contracts/test_api/test_math.cpp +++ b/contracts/test_api/test_math.cpp @@ -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(); 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(); uint128_t self = *(act.values); uint128_t other = *(act.values+1); diff --git a/tests/tests/abi_tests.cpp b/tests/tests/abi_tests.cpp index 8b0d3c970..89b75418a 100644 --- a/tests/tests/abi_tests.cpp +++ b/tests/tests/abi_tests.cpp @@ -910,7 +910,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_unable_to_determine_index, abi_gen_helper) #include //@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 //@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,10 +1344,10 @@ BOOST_FIXTURE_TEST_CASE(abigen_field_typedef, abi_gen_helper) typedef complex_field my_complex_field_alias; //@abi table - struct PACKED(table1) { - uint64_t field1; + struct table1 { + uint64_t field1; my_complex_field_alias field2; - my_name_alias name; + my_name_alias name; }; )====="; -- GitLab