Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mit feature merge #421

Open
wants to merge 12 commits into
base: v0.10.0
Choose a base branch
from
4 changes: 3 additions & 1 deletion include/metaverse/blockchain/validate_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ class BCB_API validate_transaction
uint64_t value_in_;
uint64_t asset_amount_in_;
std::vector<chain::asset_cert_type> asset_certs_in_;
std::string old_symbol_in_; // used for check same asset/did/mit symbol in previous outputs
std::string old_asset_symbol_in_; // used for check same asset/did/mit symbol in previous outputs
std::string old_did_symbol_in_;
std::string old_mit_symbol_in_;
std::string old_cert_symbol_in_; // used for check same cert symbol in previous outputs
uint32_t current_input_;
chain::point::indexes unconfirmed_;
Expand Down
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
50 changes: 30 additions & 20 deletions src/lib/blockchain/validate_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ void validate_transaction::reset(uint64_t last_height)
value_in_ = 0;
asset_amount_in_ = 0;
asset_certs_in_.clear();
old_symbol_in_ = "";

old_asset_symbol_in_ = "";
old_did_symbol_in_ = "";
old_mit_symbol_in_ = "";

old_cert_symbol_in_ = "";
}

Expand Down Expand Up @@ -953,6 +957,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 @@ -984,11 +989,19 @@ code validate_transaction::check_asset_mit_transaction() const
auto&& asset_info = output.get_asset_mit();
asset_symbol = asset_info.get_symbol();
}
else if (output.is_etp()) {
if (!check_same(asset_address, output.get_script_address())) {
else if (output.is_etp() || output.is_asset_transfer()) {
}
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: "
<< " address is not same. "
<< asset_address << " != " << output.get_script_address();
<< " the cert is not domain. "
<< cert_info.get_type() << " != " << asset_cert_ns::domain;
return error::mit_register_error;
}
}
Expand Down Expand Up @@ -1017,13 +1030,7 @@ code validate_transaction::check_asset_mit_transaction() const
}

auto prev_output = prev_tx.outputs.at(input.previous_output.index);
if (prev_output.is_etp()) {
auto&& asset_address_in = prev_output.get_script_address();
if (asset_address != asset_address_in) {
log::debug(LOG_BLOCKCHAIN) << "MIT: invalid input address to pay fee: "
<< asset_address_in << " != " << asset_address;
return error::validate_inputs_failed;
}
if (prev_output.is_etp() || prev_output.is_asset()) {
}
else if (prev_output.is_asset_mit()) {
auto&& asset_info = prev_output.get_asset_mit();
Expand Down Expand Up @@ -1792,7 +1799,7 @@ bool validate_transaction::connect_input( const transaction& previous_tx, uint64
asset_transfer_amount = previous_output.get_asset_amount();

// 2. do asset symbol check
if (!check_same(old_symbol_in_, new_symbol_in)) {
if (!check_same(old_asset_symbol_in_, new_symbol_in)) {
return false;
}
// check forbidden symbol
Expand All @@ -1807,13 +1814,13 @@ bool validate_transaction::connect_input( const transaction& previous_tx, uint64
}
}
else if (previous_output.is_asset_mit()) {
if (!check_same(old_symbol_in_, previous_output.get_asset_mit_symbol())) {
if (!check_same(old_mit_symbol_in_, previous_output.get_asset_mit_symbol())) {
return false;
}
}
else if (previous_output.is_did()) {
// 1. do did symbol check
if (!check_same(old_symbol_in_, previous_output.get_did_symbol())) {
if (!check_same(old_did_symbol_in_, previous_output.get_did_symbol())) {
return false;
}
}
Expand Down Expand Up @@ -1948,13 +1955,16 @@ bool validate_transaction::check_asset_symbol(const transaction& tx) const
{
for (const auto& output : tx.outputs) {
if (output.is_asset()) {
if (old_symbol_in_ != output.get_asset_symbol()) {
if (old_asset_symbol_in_ != output.get_asset_symbol()) {
return false;
}
}
else if (output.is_asset_cert()) { // asset cert related
continue;
}
else if (output.is_asset_mit_transfer()) {
continue;
}
else if (!output.is_etp() && !output.is_message()) {
// asset tx only related to asset_cert and etp output
return false;
Expand Down Expand Up @@ -2026,7 +2036,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 Expand Up @@ -2073,11 +2083,11 @@ bool validate_transaction::check_asset_mit(const transaction& tx) const
}

auto&& asset_info = output.get_asset_mit();
if (old_symbol_in_ != asset_info.get_symbol()) {
if (old_mit_symbol_in_ != asset_info.get_symbol()) {
return false;
}
}
else if (!output.is_etp() && !output.is_message()) {
else if (!output.is_etp() && !output.is_asset_transfer() && !output.is_message()) {
return false;
}
}
Expand All @@ -2089,7 +2099,7 @@ bool validate_transaction::check_did_symbol_match(const transaction& tx) const
{
for (const auto& output : tx.outputs) {
if (output.is_did()) {
if (old_symbol_in_ != output.get_did_symbol()) {
if (old_did_symbol_in_ != output.get_did_symbol()) {
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