From 135f9d681c4cf7036bee557c18a6a0aa3d70ff51 Mon Sep 17 00:00:00 2001 From: luozhaohui Date: Fri, 17 Aug 2018 10:22:48 +0800 Subject: [PATCH] implement burn cert/mit --- .../explorer/extensions/commands/burn.hpp | 25 +++++++++++-- src/lib/blockchain/validate_transaction.cpp | 5 ++- src/lib/explorer/extensions/commands/burn.cpp | 35 ++++++++++++++----- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/include/metaverse/explorer/extensions/commands/burn.hpp b/include/metaverse/explorer/extensions/commands/burn.hpp index 645f92416..cd68be23f 100644 --- a/include/metaverse/explorer/extensions/commands/burn.hpp +++ b/include/metaverse/explorer/extensions/commands/burn.hpp @@ -86,9 +86,20 @@ class burn: public command_extension ) ( "AMOUNT", - value(&argument_.amount)->required(), + value(&argument_.amount)->default_value(0), "Asset integer bits. see asset ." - ); + ) + ( + "cert,c", + value(&option_.cert_type)->default_value(""), + "If specified, then only burn related cert. Default is not specified." + ) + ( + "mit,m", + value(&option_.is_mit)->default_value(false)->zero_tokens(), + "If specified, then only burn related MIT. Default is not specified." + ) + ; return options; } @@ -102,12 +113,20 @@ class burn: public command_extension struct argument { - std::string symbol; + argument(): amount(0), symbol("") + {} + uint64_t amount; + std::string symbol; } argument_; struct option { + option(): is_mit(false), cert_type("") + {} + + bool is_mit; + std::string cert_type; } option_; }; diff --git a/src/lib/blockchain/validate_transaction.cpp b/src/lib/blockchain/validate_transaction.cpp index 1a3ecfc24..831d16e73 100644 --- a/src/lib/blockchain/validate_transaction.cpp +++ b/src/lib/blockchain/validate_transaction.cpp @@ -1360,9 +1360,8 @@ code validate_transaction::check_transaction_basic() const } } else if (output.is_asset_cert()) { - auto&& asset_cert = output.get_asset_cert(); - if (!check_did_exist(asset_cert.get_owner())) { - return error::did_address_needed; + if (!chain::output::is_valid_symbol(output.get_asset_symbol(), tx.version)) { + return error::asset_symbol_invalid; } } else if (output.is_did_register()) { diff --git a/src/lib/explorer/extensions/commands/burn.cpp b/src/lib/explorer/extensions/commands/burn.cpp index 427c3ce64..c7d0d9a6a 100644 --- a/src/lib/explorer/extensions/commands/burn.cpp +++ b/src/lib/explorer/extensions/commands/burn.cpp @@ -36,17 +36,36 @@ console_result burn::invoke(Json::Value& jv_output, auto& blockchain = node.chain_impl(); blockchain.is_account_passwd_valid(auth_.name, auth_.auth); - if (!argument_.amount) - throw argument_legality_exception{"invalid amount parameter!"}; - - auto&& amount = std::to_string(argument_.amount); std::string blackhole_did = did_detail::get_blackhole_did_symbol(); - std::stringstream sout(""); - const char* cmds[]{"sendasset", auth_.name.c_str(), auth_.auth.c_str(), blackhole_did.c_str(), argument_.symbol.c_str(), amount.c_str()}; + if (option_.is_mit) { + const char* cmds[] { + "transfermit", auth_.name.c_str(), auth_.auth.c_str(), + blackhole_did.c_str(), argument_.symbol.c_str() + }; + + return dispatch_command(5, cmds, jv_output, node, get_api_version()); + } + else if (!option_.cert_type.empty()) { + const char* cmds[] { + "transfercert", auth_.name.c_str(), auth_.auth.c_str(), + blackhole_did.c_str(), argument_.symbol.c_str(), option_.cert_type.c_str() + }; + + return dispatch_command(6, cmds, jv_output, node, get_api_version()); + } + else { + if (argument_.amount <= 0) { + throw argument_legality_exception{"invalid amount parameter!"}; + } + + auto&& amount = std::to_string(argument_.amount); + const char* cmds[] { + "sendasset", auth_.name.c_str(), auth_.auth.c_str(), + blackhole_did.c_str(), argument_.symbol.c_str(), amount.c_str() + }; - if (dispatch_command(6, cmds, jv_output, node, get_api_version()) != console_result::okay) { - throw address_generate_exception(sout.str()); + return dispatch_command(6, cmds, jv_output, node, get_api_version()); } return console_result::okay;