From a41f07e913d002e04a37bd713f125562e7386093 Mon Sep 17 00:00:00 2001 From: Keke Li Date: Mon, 1 Mar 2021 12:44:46 -0800 Subject: [PATCH 1/3] when serialize action.data, let "hex_data" always means hex string and be present whether the action.data can be parsed as json object or not. In the old code, "data" always be present, it could be json object or hex string if parsed successfully or failed. --- .../include/eosio/chain/abi_serializer.hpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index db5a09572ba..c81e4b25591 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -432,20 +432,11 @@ namespace impl { binary_to_variant_context _ctx(*abi, ctx, type); _ctx.short_path = true; // Just to be safe while avoiding the complexity of threading an override boolean all over the place mvo( "data", abi->_binary_to_variant( type, act.data, _ctx )); - mvo("hex_data", act.data); - } catch(...) { - // any failure to serialize data, then leave as not serailzed - mvo("data", act.data); - } - } else { - mvo("data", act.data); + } catch(...) {} } - } else { - mvo("data", act.data); } - } catch(...) { - mvo("data", act.data); - } + }catch(...) {} + mvo("hex_data", act.data); out(name, std::move(mvo)); } @@ -829,7 +820,7 @@ namespace impl { } } - if( !valid_empty_data && act.data.empty() ) { + if( ( !valid_empty_data && act.data.empty() ) || !vo.contains( "data" ) ) { if( vo.contains( "hex_data" ) ) { const auto& data = vo["hex_data"]; if( data.is_string() ) { From 01bff5a59e32efd8b9afb4297f058887fb30ef0c Mon Sep 17 00:00:00 2001 From: Keke Li Date: Mon, 1 Mar 2021 16:09:38 -0800 Subject: [PATCH 2/3] Change test case to adapt new action.data json format --- unittests/abi_tests.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index f4018543cc4..2895527474b 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -2700,8 +2700,8 @@ BOOST_AUTO_TEST_CASE(abi_large_signature) BOOST_CHECK_LE( (stop - start).count(), 51*1000 ); // only contains hex_data if it didn't hit the deadline if( check_data ) { - BOOST_CHECK( var.get_object().contains( "data" ) ); - BOOST_CHECK( !var.get_object().contains( "hex_data" ) ); + BOOST_CHECK( !var.get_object().contains( "data" ) ); + BOOST_CHECK( var.get_object().contains( "hex_data" ) ); } } FC_LOG_AND_RETHROW() } @@ -3356,7 +3356,7 @@ inline std::pair generate_action_trace(const std::opt << "\"actor\":\"acctest\"," << "\"permission\":\"active\"" << "}]," - << "\"data\":\"09746573745f64617461\"" + << "\"hex_data\":\"09746573745f64617461\"" << "}," << "\"context_free\":false," << "\"elapsed\":3," From e080f35ca6532f255f496f71d241ff6dedbd82e5 Mon Sep 17 00:00:00 2001 From: Keke Li Date: Tue, 2 Mar 2021 08:17:50 -0800 Subject: [PATCH 3/3] change the comment so as to match the new code better --- unittests/abi_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index 2895527474b..8108de16a48 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -2698,7 +2698,7 @@ BOOST_AUTO_TEST_CASE(abi_large_signature) auto stop = fc::time_point::now(); // Give it a leaway of 50ms BOOST_CHECK_LE( (stop - start).count(), 51*1000 ); - // only contains hex_data if it didn't hit the deadline + // contains only hex_data if it didn't hit the deadline if( check_data ) { BOOST_CHECK( !var.get_object().contains( "data" ) ); BOOST_CHECK( var.get_object().contains( "hex_data" ) );