Skip to content

Commit

Permalink
Merge pull request #385 from baidang201/365-mit-domain-cert
Browse files Browse the repository at this point in the history
#365 mit domain cert
  • Loading branch information
canguruhh authored Feb 28, 2020
2 parents b3e3717 + 6ed14d6 commit 03a6ab0
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
13 changes: 9 additions & 4 deletions include/metaverse/explorer/extensions/base_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ class BCX_API base_transfer_common
receiver_record::list&& receiver_list, uint64_t fee,
std::string&& symbol, std::string&& from, std::string&& change,
uint32_t locktime = 0, uint32_t sequence = bc::max_input_sequence,
exclude_range_t exclude_etp_range = {0, 0})
exclude_range_t exclude_etp_range = {0, 0},
std::set<std::string>&& payment_domain_set = std::set<std::string>())
: blockchain_{blockchain}
, symbol_{std::move(symbol)}
, from_{std::move(from)}
Expand All @@ -312,6 +313,7 @@ class BCX_API base_transfer_common
, locktime_(locktime)
, sequence_(sequence)
, exclude_etp_range_(exclude_etp_range)
, payment_domain_set_(std::move(payment_domain_set))
{
};

Expand Down Expand Up @@ -392,6 +394,7 @@ class BCX_API base_transfer_common
uint8_t unspent_did_{0};
uint8_t payment_mit_{0};
uint8_t unspent_mit_{0};
std::set<std::string> payment_domain_set_;
std::vector<receiver_record> receiver_list_;
std::vector<address_asset_record> from_list_;
uint32_t locktime_;
Expand All @@ -410,10 +413,11 @@ class BCX_API base_transfer_helper : public base_transfer_common
std::string&& change = std::string(""),
uint32_t locktime = 0,
uint32_t sequence = bc::max_input_sequence,
exclude_range_t exclude_etp_range = {0, 0})
exclude_range_t exclude_etp_range = {0, 0},
std::set<std::string>&& payment_domain_set = std::set<std::string>())
: base_transfer_common(blockchain, std::move(receiver_list), fee,
std::move(symbol), std::move(from),
std::move(change), locktime, sequence, exclude_etp_range)
std::move(change), locktime, sequence, exclude_etp_range, std::move(payment_domain_set))
, cmd_{cmd}
, name_{std::move(name)}
, passwd_{std::move(passwd)}
Expand Down Expand Up @@ -769,11 +773,12 @@ class BCX_API registering_mit : public base_transfer_helper
registering_mit(command& cmd, bc::blockchain::block_chain_impl& blockchain,
std::string&& name, std::string&& passwd,
std::string&& from, std::string&& symbol, std::map<std::string, std::string>&& mit_map,
std::set<std::string>&& payment_domain_set,
receiver_record::list&& receiver_list,
uint64_t fee, uint32_t locktime = 0)
: base_transfer_helper(cmd, blockchain, std::move(name), std::move(passwd),
std::move(from), std::move(receiver_list),
fee, std::move(symbol), "", locktime)
fee, std::move(symbol), "", locktime, bc::max_input_sequence, {0,0}, std::move(payment_domain_set))
, mit_map_(mit_map)
{}

Expand Down
17 changes: 16 additions & 1 deletion src/lib/blockchain/validate_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ code validate_transaction::check_asset_mit_transaction() const
std::string asset_address;
uint64_t num_mit_transfer = 0;
uint64_t num_mit_register = 0;
std::string cert_owner;
for (auto& output : tx.outputs)
{
if (output.is_asset_mit_register()) {
Expand Down Expand Up @@ -992,6 +993,20 @@ code validate_transaction::check_asset_mit_transaction() const
return error::mit_register_error;
}
}
else if (output.is_asset_cert()) {
asset_cert&& cert_info = output.get_asset_cert();
if (cert_info.get_type() == asset_cert_ns::domain) {
if (!check_same(cert_owner, cert_info.get_owner())) {
return error::mit_register_error;
}
}
else {
log::debug(LOG_BLOCKCHAIN) << "MIT: "
<< " the cert is not domain. "
<< cert_info.get_type() << " != " << asset_cert_ns::domain;
return error::mit_register_error;
}
}
else if (!output.is_message()) {
log::debug(LOG_BLOCKCHAIN) << "MIT: illegal output, "
<< asset_symbol << " : " << output.to_string(1);
Expand Down Expand Up @@ -2026,7 +2041,7 @@ bool validate_transaction::check_asset_certs(const transaction& tx) const
has_asset_issue = true;
}
}
else if (!output.is_etp() && !output.is_message()) {
else if (!output.is_etp() && !output.is_message() && !output.is_asset_mit_register()) {
// asset cert transfer tx only related to asset_cert and etp output
log::debug(LOG_BLOCKCHAIN) << "cert tx mix other illegal output";
return false;
Expand Down
12 changes: 9 additions & 3 deletions src/lib/explorer/extensions/base_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,9 +1131,15 @@ void base_transfer_common::sync_fetchutxo(

// check cert symbol
if (cert_type == asset_cert_ns::domain) {
auto&& domain = asset_cert::get_domain(symbol_);
if (domain != asset_symbol)
continue;
if (symbol_.size() > 0) {
auto&& domain = asset_cert::get_domain(symbol_);
if (domain != asset_symbol)
continue;
} else {
if (payment_domain_set_.find(asset_symbol) == payment_domain_set_.end()) {
continue;
}
}
}
else if (cert_type == asset_cert_ns::witness) {
auto&& primary = asset_cert::get_primary_witness_symbol(symbol_);
Expand Down
32 changes: 31 additions & 1 deletion src/lib/explorer/extensions/commands/registermit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,39 @@ console_result registermit::invoke (Json::Value& jv_output,
throw address_dismatch_account_exception{"target did does not match account. " + to_did};
}

std::string cert_symbol;
chain::asset_cert_type cert_type = asset_cert_ns::none;
std::set<std::string> payment_domain_set;

// receiver
std::vector<receiver_record> receiver;
for (auto& pair : mit_map) {
// domain cert check
auto&& domain = chain::asset_cert::get_domain(pair.first);
if (chain::asset_cert::is_valid_domain(domain)) {
bool exist = blockchain.is_asset_cert_exist(domain, asset_cert_ns::domain);
if (exist) {
// if domain cert exists then check whether it belongs to the account.
auto cert = blockchain.get_account_asset_cert(auth_.name, domain, asset_cert_ns::domain);
if (cert) {
cert_symbol = domain;
cert_type = cert->get_type();

payment_domain_set.insert(domain);
receiver.push_back(
{
to_address, cert_symbol, 0, 0, cert_type,
utxo_attach_type::asset_cert,
chain::attachment("", to_did)
});
}
else {
throw asset_cert_notfound_exception{
"Domain cert " + pair.first + " exists on the blockchain and is not owned by " + auth_.name};
}
}
}

receiver.push_back(
{
to_address, pair.first, 0, 0, 0,
Expand All @@ -147,7 +177,7 @@ console_result registermit::invoke (Json::Value& jv_output,
auto helper = registering_mit(
*this, blockchain,
std::move(auth_.name), std::move(auth_.auth),
std::move(to_address), "", std::move(mit_map),
std::move(to_address), "", std::move(mit_map), std::move(payment_domain_set),
std::move(receiver), argument_.fee);

helper.exec();
Expand Down

0 comments on commit 03a6ab0

Please sign in to comment.