Skip to content

Commit

Permalink
implement burn cert/mit
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhaohui committed Aug 17, 2018
1 parent a9c1538 commit 135f9d6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 14 deletions.
25 changes: 22 additions & 3 deletions include/metaverse/explorer/extensions/commands/burn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,20 @@ class burn: public command_extension
)
(
"AMOUNT",
value<uint64_t>(&argument_.amount)->required(),
value<uint64_t>(&argument_.amount)->default_value(0),
"Asset integer bits. see asset <decimal_number>."
);
)
(
"cert,c",
value<std::string>(&option_.cert_type)->default_value(""),
"If specified, then only burn related cert. Default is not specified."
)
(
"mit,m",
value<bool>(&option_.is_mit)->default_value(false)->zero_tokens(),
"If specified, then only burn related MIT. Default is not specified."
)
;

return options;
}
Expand All @@ -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_;

};
Expand Down
5 changes: 2 additions & 3 deletions src/lib/blockchain/validate_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
35 changes: 27 additions & 8 deletions src/lib/explorer/extensions/commands/burn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 135f9d6

Please sign in to comment.