Added next fork Haven support

This commit is contained in:
MoneroOcean
2023-08-28 03:37:06 +00:00
parent 82693cbe57
commit 59edc8c114
8 changed files with 523 additions and 68 deletions
+341 -51
View File
@@ -89,6 +89,48 @@ namespace cryptonote
END_SERIALIZE()
};
// outputs <= HF_VERSION_VIEW_TAGS
struct txout_haven_key
{
txout_haven_key() { }
txout_haven_key(const crypto::public_key &_key, const std::string &_asset_type, const uint64_t &_unlock_time, const bool &_is_collateral, const bool &_is_collateral_change) : key(_key), asset_type(_asset_type), unlock_time(_unlock_time), is_collateral(_is_collateral), is_collateral_change(_is_collateral_change) { }
crypto::public_key key;
std::string asset_type;
uint64_t unlock_time;
bool is_collateral;
bool is_collateral_change;
BEGIN_SERIALIZE_OBJECT()
FIELD(key)
FIELD(asset_type)
VARINT_FIELD(unlock_time)
FIELD(is_collateral)
FIELD(is_collateral_change)
END_SERIALIZE()
};
// outputs >= HF_VERSION_VIEW_TAGS
struct txout_haven_tagged_key
{
txout_haven_tagged_key() { }
txout_haven_tagged_key(const crypto::public_key &_key, const std::string &_asset_type, const uint64_t &_unlock_time, const bool &_is_collateral, const bool &_is_collateral_change, const crypto::view_tag &_view_tag) : key(_key), asset_type(_asset_type), unlock_time(_unlock_time), is_collateral(_is_collateral), is_collateral_change(_is_collateral_change), view_tag(_view_tag) { }
crypto::public_key key;
std::string asset_type;
uint64_t unlock_time;
bool is_collateral;
bool is_collateral_change;
crypto::view_tag view_tag; // optimization to reduce scanning time
BEGIN_SERIALIZE_OBJECT()
FIELD(key)
FIELD(asset_type)
VARINT_FIELD(unlock_time)
FIELD(is_collateral)
FIELD(is_collateral_change)
FIELD(view_tag)
END_SERIALIZE()
};
struct txout_offshore
{
txout_offshore() { }
@@ -203,6 +245,21 @@ namespace cryptonote
END_SERIALIZE()
};
struct txin_haven_key
{
uint64_t amount;
std::string asset_type;
std::vector<uint64_t> key_offsets;
crypto::key_image k_image; // double spending protection
BEGIN_SERIALIZE_OBJECT()
VARINT_FIELD(amount)
FIELD(asset_type)
FIELD(key_offsets)
FIELD(k_image)
END_SERIALIZE()
};
struct txin_xasset
{
uint64_t amount;
@@ -233,11 +290,11 @@ namespace cryptonote
END_SERIALIZE()
};
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset> txin_v;
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset, txin_haven_key> txin_v;
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_zephyr_key> txin_zephyr_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset> txout_xhv_target_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset, txout_haven_key, txout_haven_tagged_key> txout_xhv_target_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_stablero_target_v;
@@ -327,62 +384,288 @@ namespace cryptonote
};
BEGIN_SERIALIZE()
VARINT_FIELD(version)
if (version > loki_version_2 && (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC))
{
FIELD(output_unlock_times)
if (version == loki_version_3_per_output_unlock_times)
FIELD(is_deregister)
}
if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV || version < POU_TRANSACTION_VERSION)
VARINT_FIELD(unlock_time)
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
FIELD(vin_zephyr)
else
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
VARINT_FIELD(version)
//if(version == 0 || CURRENT_TRANSACTION_VERSION < version) return false;
// Only transactions prior to HAVEN_TYPES_TRANSACTION_VERSION are permitted to be anything other than HAVEN_TYPES and need translation
if (version < HAVEN_TYPES_TRANSACTION_VERSION) {
if (version < POU_TRANSACTION_VERSION) {
VARINT_FIELD(unlock_time)
}
if (!typename Archive<W>::is_saving()) {
FIELD(vin)
FIELD(vout_xhv)
FIELD(extra)
if(version >= OFFSHORE_TRANSACTION_VERSION) {
VARINT_FIELD(pricing_record_height)
if (version < 5)
FIELD(offshore_data)
if (version >= POU_TRANSACTION_VERSION) {
FIELD(output_unlock_times)
if (vout_xhv.size() != output_unlock_times.size()) {
return false;
}
}
VARINT_FIELD(amount_burnt)
VARINT_FIELD(amount_minted)
if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) {
FIELD(collateral_indices)
if (collateral_indices.size() != 2) {
return false;
}
for (const auto vout_idx: collateral_indices) {
if (vout_idx >= vout_xhv.size())
return false;
}
}
}
std::vector<txin_v> vin_tmp(vin);
bool is_conversion_tx = (amount_burnt != 0);
bool is_offshore_tx = is_conversion_tx;
bool is_onshore_tx = false;
vin.clear();
for (auto &vin_entry: vin_tmp) {
if (vin_entry.type() == typeid(txin_gen)) {
vin.push_back(vin_entry);
continue;
}
txin_haven_key in;
if (vin_entry.type() == typeid(txin_to_key)) {
in.asset_type = "XHV";
in.amount = boost::get<txin_to_key>(vin_entry).amount;
in.key_offsets = boost::get<txin_to_key>(vin_entry).key_offsets;
in.k_image = boost::get<txin_to_key>(vin_entry).k_image;
} else if (vin_entry.type() == typeid(txin_offshore)) {
is_offshore_tx = false;
is_onshore_tx = false;
in.asset_type = "XUSD";
in.amount = boost::get<txin_offshore>(vin_entry).amount;
in.key_offsets = boost::get<txin_offshore>(vin_entry).key_offsets;
in.k_image = boost::get<txin_offshore>(vin_entry).k_image;
} else if (vin_entry.type() == typeid(txin_onshore)) {
is_offshore_tx = false;
is_onshore_tx = true;
in.asset_type = "XUSD";
in.amount = boost::get<txin_onshore>(vin_entry).amount;
in.key_offsets = boost::get<txin_onshore>(vin_entry).key_offsets;
in.k_image = boost::get<txin_onshore>(vin_entry).k_image;
} else if (vin_entry.type() == typeid(txin_xasset)) {
is_offshore_tx = false;
is_onshore_tx = false;
in.amount = boost::get<txin_xasset>(vin_entry).amount;
in.key_offsets = boost::get<txin_xasset>(vin_entry).key_offsets;
in.k_image = boost::get<txin_xasset>(vin_entry).k_image;
in.asset_type = boost::get<txin_xasset>(vin_entry).asset_type;
} else {
return false;
}
vin.push_back(in);
}
std::vector<tx_out_xhv> vout_tmp(vout_xhv);
vout_xhv.clear();
for (size_t i=0; i<vout_tmp.size(); i++) {
txout_haven_key out;
if (vout_tmp[i].target.type() == typeid(txout_to_key)) {
out.asset_type = "XHV";
out.key = boost::get<txout_to_key>(vout_tmp[i].target).key;
} else if (vout_tmp[i].target.type() == typeid(txout_offshore)) {
out.asset_type = "XUSD";
out.key = boost::get<txout_offshore>(vout_tmp[i].target).key;
} else if (vout_tmp[i].target.type() == typeid(txout_xasset)) {
out.asset_type = boost::get<txout_xasset>(vout_tmp[i].target).asset_type;
out.key = boost::get<txout_xasset>(vout_tmp[i].target).key;
} else {
return false;
}
out.unlock_time = (version >= POU_TRANSACTION_VERSION) ? output_unlock_times[i] : unlock_time;
out.is_collateral = false;
out.is_collateral_change = false;
if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) {
if (((is_onshore_tx) &&
(collateral_indices[0] == i)) ||
((!is_onshore_tx) &&
(is_offshore_tx) &&
(collateral_indices[0] == i && collateral_indices[1] == 0))) {
out.is_collateral = true;
}
if (is_onshore_tx && collateral_indices[1] == i) {
out.is_collateral_change = true;
}
}
tx_out_xhv foo;
foo.amount = vout_tmp[i].amount;
foo.target = out;
vout_xhv.push_back(foo);
}
return true;
}
bool is_offshore_tx = (amount_burnt != 0);
bool is_onshore_tx = false;
std::vector<txin_v> vin_tmp;
vin_tmp.reserve(vin.size());
for (auto &vin_entry_v: vin) {
if (vin_entry_v.type() == typeid(txin_gen)) {
vin_tmp.push_back(vin_entry_v);
continue;
}
txin_haven_key vin_entry = boost::get<txin_haven_key>(vin_entry_v);
if (vin_entry.asset_type == "XHV") {
txin_to_key in;
in.amount = vin_entry.amount;
in.key_offsets = vin_entry.key_offsets;
in.k_image = vin_entry.k_image;
vin_tmp.push_back(in);
} else if (vin_entry.asset_type == "XUSD") {
is_offshore_tx = false;
int xhv_outputs = std::count_if(vout_xhv.begin(), vout_xhv.end(), [](tx_out_xhv &foo_v) {
if (foo_v.target.type() == typeid(txout_haven_key)) {
txout_haven_key out = boost::get<txout_haven_key>(foo_v.target);
return out.asset_type == "XHV";
} else if (foo_v.target.type() == typeid(txout_haven_tagged_key)) {
txout_haven_tagged_key out = boost::get<txout_haven_tagged_key>(foo_v.target);
return out.asset_type == "XHV";
} else {
return false;
}
});
if (xhv_outputs) {
is_onshore_tx = true;
txin_onshore in;
in.amount = vin_entry.amount;
in.key_offsets = vin_entry.key_offsets;
in.k_image = vin_entry.k_image;
vin_tmp.push_back(in);
} else {
txin_offshore in;
in.amount = vin_entry.amount;
in.key_offsets = vin_entry.key_offsets;
in.k_image = vin_entry.k_image;
vin_tmp.push_back(in);
}
} else {
is_offshore_tx = false;
txin_xasset in;
in.amount = vin_entry.amount;
in.asset_type = vin_entry.asset_type;
in.key_offsets = vin_entry.key_offsets;
in.k_image = vin_entry.k_image;
vin_tmp.push_back(in);
}
}
std::vector<tx_out_xhv> vout_tmp;
vout_tmp.reserve(vout_xhv.size());
output_unlock_times.resize(vout_xhv.size());
std::vector<uint32_t> collateral_indices_temp;
collateral_indices_temp.resize(2);
for (size_t i=0; i<vout_xhv.size(); i++) {
txout_haven_key outhk = boost::get<txout_haven_key>(vout_xhv[i].target);
tx_out_xhv foo;
foo.amount = vout_xhv[i].amount;
if (outhk.asset_type == "XHV") {
txout_to_key out;
out.key = outhk.key;
foo.target = out;
} else if (outhk.asset_type == "XUSD") {
txout_offshore out;
out.key = outhk.key;
foo.target = out;
} else {
txout_xasset out;
out.asset_type = outhk.asset_type;
out.key = outhk.key;
foo.target = out;
}
output_unlock_times[i] = outhk.unlock_time;
if (outhk.is_collateral) {
collateral_indices_temp[0] = i;
} else if (outhk.is_collateral_change) {
collateral_indices_temp[1] = i;
}
vout_tmp.push_back(foo);
}
FIELD_N("vin", vin_tmp)
FIELD_N("vout", vout_tmp)
FIELD(extra)
if(version >= OFFSHORE_TRANSACTION_VERSION) {
VARINT_FIELD(pricing_record_height)
if (version < 5)
FIELD(offshore_data)
if (version >= POU_TRANSACTION_VERSION) {
FIELD(output_unlock_times)
if (vout_xhv.size() != output_unlock_times.size()) {
return false;
}
}
VARINT_FIELD(amount_burnt)
VARINT_FIELD(amount_minted)
if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) {
if (collateral_indices.size() != 2) {
if ((is_offshore_tx || is_onshore_tx) && collateral_indices_temp.size() != 2) {
return false;
}
if (is_offshore_tx || is_onshore_tx) {
collateral_indices = collateral_indices_temp;
} else {
collateral_indices.clear();
collateral_indices.push_back(0);
collateral_indices.push_back(0);
}
}
FIELD(collateral_indices)
for (const auto vout_idx: collateral_indices) {
if (vout_idx >= vout_xhv.size())
return false;
}
}
}
return true;
}
FIELD(vin)
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
FIELD(vout_zephyr)
else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
FIELD(vout_xhv)
else
FIELD(vout)
if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC)
{
if (version >= loki_version_3_per_output_unlock_times && vout.size() != output_unlock_times.size()) return false;
}
FIELD(extra)
if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types)
{
VARINT_FIELD(type)
if (static_cast<uint16_t>(type) >= loki_type_count) return false;
}
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
FIELD(extra)
VARINT_FIELD(pricing_record_height)
VARINT_FIELD(amount_burnt)
VARINT_FIELD(amount_minted)
}
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && version >= OFFSHORE_TRANSACTION_VERSION) {
VARINT_FIELD(pricing_record_height)
if (version < 5)
FIELD(offshore_data)
if (version >= POU_TRANSACTION_VERSION)
} else {
VARINT_FIELD(version)
if (version > loki_version_2 && (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC))
{
FIELD(output_unlock_times)
if (version == loki_version_3_per_output_unlock_times)
FIELD(is_deregister)
}
if (version >= POU_TRANSACTION_VERSION && vout_xhv.size() != output_unlock_times.size()) return false;
VARINT_FIELD(amount_burnt)
VARINT_FIELD(amount_minted)
if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) {
FIELD(collateral_indices)
if (collateral_indices.size() != 2) {
return false;
}
for (const auto vout_idx: collateral_indices) {
if (vout_idx >= vout.size())
return false;
}
VARINT_FIELD(unlock_time)
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
FIELD(vin_zephyr)
else
FIELD(vin)
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
FIELD(vout_zephyr)
else
FIELD(vout)
if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC)
{
if (version >= loki_version_3_per_output_unlock_times && vout.size() != output_unlock_times.size()) return false;
}
FIELD(extra)
if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types)
{
VARINT_FIELD(type)
if (static_cast<uint16_t>(type) >= loki_type_count) return false;
}
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
VARINT_FIELD(pricing_record_height)
VARINT_FIELD(amount_burnt)
VARINT_FIELD(amount_minted)
}
}
END_SERIALIZE()
@@ -463,7 +746,10 @@ namespace cryptonote
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 : 0);
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 :
vin.size() > 0 && vin[0].type() == typeid(txin_haven_key) ? boost::get<txin_haven_key>(vin[0]).key_offsets.size() - 1 :
0
);
} else {
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(),
vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0);
@@ -523,6 +809,7 @@ namespace cryptonote
size_t operator()(const txin_offshore& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_onshore& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_xasset& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_haven_key& txin) const {return txin.key_offsets.size();}
size_t operator()(const txin_zephyr_key& txin) const {return txin.key_offsets.size();}
};
@@ -755,6 +1042,7 @@ VARIANT_TAG(binary_archive, cryptonote::txin_zephyr_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3);
VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4);
VARIANT_TAG(binary_archive, cryptonote::txin_xasset, 0x5);
VARIANT_TAG(binary_archive, cryptonote::txin_haven_key, 0x6);
VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0);
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
@@ -762,5 +1050,7 @@ VARIANT_TAG(binary_archive, cryptonote::txout_zephyr_tagged_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::txout_to_tagged_key, 0x3);
VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3);
VARIANT_TAG(binary_archive, cryptonote::txout_xasset, 0x5);
VARIANT_TAG(binary_archive, cryptonote::txout_haven_key, 0x6);
VARIANT_TAG(binary_archive, cryptonote::txout_haven_tagged_key, 0x7);
VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc);
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);