diff --git a/libraries/chain/include/eosio/chain/wast_to_wasm.hpp b/libraries/chain/include/eosio/chain/wast_to_wasm.hpp index eb478d7653a..d601bbf5cef 100644 --- a/libraries/chain/include/eosio/chain/wast_to_wasm.hpp +++ b/libraries/chain/include/eosio/chain/wast_to_wasm.hpp @@ -5,7 +5,5 @@ namespace eosio { namespace chain { std::vector wast_to_wasm( const std::string& wast ); -std::string wasm_to_wast( const std::vector& wasm, bool strip_names ); -std::string wasm_to_wast( const uint8_t* data, uint64_t size, bool strip_names ); } } /// eosio::chain diff --git a/libraries/chain/wast_to_wasm.cpp b/libraries/chain/wast_to_wasm.cpp index 0527d57f604..ed4769a0eee 100644 --- a/libraries/chain/wast_to_wasm.cpp +++ b/libraries/chain/wast_to_wasm.cpp @@ -4,10 +4,10 @@ #include #include #include -#include #include #include #include +#include #include namespace eosio { namespace chain { @@ -58,20 +58,4 @@ namespace eosio { namespace chain { } FC_CAPTURE_AND_RETHROW( (wast) ) } /// wast_to_wasm - std::string wasm_to_wast( const std::vector& wasm, bool strip_names ) { - return wasm_to_wast( wasm.data(), wasm.size(), strip_names ); - } /// wasm_to_wast - - std::string wasm_to_wast( const uint8_t* data, uint64_t size, bool strip_names ) - { try { - IR::Module module; - Serialization::MemoryInputStream stream((const U8*)data,size); - WASM::serialize(stream,module); - if(strip_names) - module.userSections.clear(); - // Print the module to WAST. - return WAST::print(module); - } FC_CAPTURE_AND_RETHROW() } /// wasm_to_wast - - } } // eosio::chain diff --git a/programs/cleos/main.cpp b/programs/cleos/main.cpp index cdf98e9d653..43a19510d9b 100644 --- a/programs/cleos/main.cpp +++ b/programs/cleos/main.cpp @@ -82,7 +82,6 @@ Usage: ./cleos create account [OPTIONS] creator name OwnerKey ActiveKey #include #include -#include #include #include #include @@ -2839,14 +2838,14 @@ int main( int argc, char** argv ) { // get code string codeFilename; string abiFilename; - bool code_as_wasm = false; + bool code_as_wasm = true; auto getCode = get->add_subcommand("code", localized("Retrieve the code and ABI for an account")); getCode->add_option("name", accountName, localized("The name of the account whose code should be retrieved"))->required(); - getCode->add_option("-c,--code",codeFilename, localized("The name of the file to save the contract .wast/wasm to") ); + getCode->add_option("-c,--code",codeFilename, localized("The name of the file to save the contract wasm to") ); getCode->add_option("-a,--abi",abiFilename, localized("The name of the file to save the contract .abi to") ); - getCode->add_flag("--wasm", code_as_wasm, localized("Save contract as wasm")); + getCode->add_flag("--wasm", code_as_wasm, localized("Save contract as wasm (ignored, default)")); getCode->callback([&] { - string code_hash, wasm, wast, abi; + string code_hash, wasm, abi; try { const auto result = call(get_raw_code_and_abi_func, fc::mutable_variant_object("account_name", accountName)); const std::vector wasm_v = result["wasm"].as_blob().data; @@ -2858,8 +2857,6 @@ int main( int argc, char** argv ) { code_hash = (string)hash; wasm = string(wasm_v.begin(), wasm_v.end()); - if(!code_as_wasm && wasm_v.size()) - wast = wasm_to_wast((const uint8_t*)wasm_v.data(), wasm_v.size(), false); abi_def abi_d; if(abi_serializer::to_abi(abi_v, abi_d)) @@ -2869,25 +2866,18 @@ int main( int argc, char** argv ) { //see if this is an old nodeos that doesn't support get_raw_code_and_abi const auto old_result = call(get_code_func, fc::mutable_variant_object("account_name", accountName)("code_as_wasm",code_as_wasm)); code_hash = old_result["code_hash"].as_string(); - if(code_as_wasm) { - wasm = old_result["wasm"].as_string(); - std::cout << localized("Warning: communicating to older ${n} which returns malformed binary wasm", ("n", node_executable_name)) << std::endl; - } - else - wast = old_result["wast"].as_string(); + wasm = old_result["wasm"].as_string(); + std::cout << localized("Warning: communicating to older ${n} which returns malformed binary wasm", ("n", node_executable_name)) << std::endl; abi = fc::json::to_pretty_string(old_result["abi"]); } std::cout << localized("code hash: ${code_hash}", ("code_hash", code_hash)) << std::endl; if( codeFilename.size() ){ - std::cout << localized("saving ${type} to ${codeFilename}", ("type", (code_as_wasm ? "wasm" : "wast"))("codeFilename", codeFilename)) << std::endl; + std::cout << localized("saving wasm to ${codeFilename}", ("codeFilename", codeFilename)) << std::endl; std::ofstream out( codeFilename.c_str() ); - if(code_as_wasm) - out << wasm; - else - out << wast; + out << wasm; } if( abiFilename.size() ) { std::cout << localized("saving abi to ${abiFilename}", ("abiFilename", abiFilename)) << std::endl; diff --git a/unittests/wasm_tests.cpp b/unittests/wasm_tests.cpp index 2f5be2b793a..c9641da2bee 100644 --- a/unittests/wasm_tests.cpp +++ b/unittests/wasm_tests.cpp @@ -1664,17 +1664,18 @@ BOOST_FIXTURE_TEST_CASE( fuzz, TESTER ) try { vector wasm(g80k_deep_loop_with_voidData, g80k_deep_loop_with_voidData + g80k_deep_loop_with_voidSize); BOOST_CHECK_THROW(set_code("fuzzy"_n, wasm), wasm_exception); } + { + vector wasm(ggetcode_deepindentData, ggetcode_deepindentData + ggetcode_deepindentSize); + set_code( "fuzzy"_n, wasm ); + } + { + vector wasm(gindent_mismatchData, gindent_mismatchData + gindent_mismatchSize); + set_code( "fuzzy"_n, wasm ); + } produce_blocks(1); } FC_LOG_AND_RETHROW() -BOOST_FIXTURE_TEST_CASE( getcode_checks, TESTER ) try { - vector wasm(ggetcode_deepindentData, ggetcode_deepindentData + ggetcode_deepindentSize); - wasm_to_wast( wasm.data(), wasm.size(), true ); - vector wasmx(gindent_mismatchData, gindent_mismatchData + gindent_mismatchSize); - wasm_to_wast( wasmx.data(), wasmx.size(), true ); -} FC_LOG_AND_RETHROW() - BOOST_FIXTURE_TEST_CASE( big_maligned_host_ptr, TESTER ) try { produce_blocks(2); create_accounts( {"bigmaligned"_n} );