1
0
Fork 0
forked from lthn/blockchain

fixes over signatures structure

This commit is contained in:
cryptozoidberg 2022-05-18 16:34:19 +02:00
parent c17ec013ca
commit 60f6c76ad6
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
3 changed files with 87 additions and 8 deletions

View file

@ -541,8 +541,7 @@ namespace currency
extra_alias_entry(const extra_alias_entry_old& old)
: extra_alias_entry_base(old)
, m_alias(old.m_alias)
{
}
{}
std::string m_alias;
@ -656,6 +655,26 @@ namespace currency
END_BOOST_SERIALIZATION()
};
//classic CryptoNote signature by Nicolas Van Saberhagen
struct NLSAG_sig
{
std::vector<std::vector<crypto::signature> > s;
};
struct zarcanum_sig
{
//TODO:
};
struct void_sig
{
//TODO:
};
typedef boost::variant<void_sig, NLSAG_sig, zarcanum_sig> signature_v;
//include backward compatibility defintions
#include "currency_basic_backward_comp.inl"
@ -668,7 +687,7 @@ namespace currency
//extra
std::vector<extra_v> extra;
std::vector<txin_v> vin;
std::vector<tx_out_bare> vout;//std::vector<tx_out> vout;
std::vector<tx_out_v> vout;
BEGIN_SERIALIZE()
VARINT_FIELD(version)
@ -697,14 +716,16 @@ namespace currency
class transaction: public transaction_prefix
{
public:
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
signature_v signature;
std::vector<attachment_v> attachment;
transaction();
BEGIN_SERIALIZE_OBJECT()
FIELDS(*static_cast<transaction_prefix *>(this))
FIELD(signatures)
CHAIN_TRANSITION_VER(TRANSACTION_VERSION_INITAL, transaction_v1)
CHAIN_TRANSITION_VER(TRANSACTION_VERSION_PRE_HF4, transaction_v1)
FIELD(signature)
FIELD(attachment)
END_SERIALIZE()
};
@ -913,6 +934,9 @@ SET_VARIANT_TAGS(currency::tx_out_zarcanum, 38, "tx_out_zarcanum");
SET_VARIANT_TAGS(currency::zarcanum_tx_data_v1, 39, "zarcanum_tx_data_v1");
SET_VARIANT_TAGS(crypto::bpp_signature_serialized, 40, "bpp_signature_serialized");
SET_VARIANT_TAGS(crypto::bppe_signature_serialized, 41, "bppe_signature_serialized");
SET_VARIANT_TAGS(currency::NLSAG_sig, 42, "NLSAG_sig");
SET_VARIANT_TAGS(currency::zarcanum_sig, 43, "zarcanum_sig");
SET_VARIANT_TAGS(currency::void_sig, 43, "void_sig");

View file

@ -49,7 +49,16 @@ bool transition_convert(const transaction_prefix_current_t& from, transaction_pr
to.version = from.version;
to.extra = from.extra;
to.vin = from.vin;
to.vout = from.vout;
for (const auto& v : from.vout)
{
if (v.type() == typeid(tx_out_bare))
{
to.vout.push_back(boost::get<tx_out_bare>(v));
}
else {
throw std::runtime_error("Unexpected type in tx_out_v");
}
}
return true;
}
template<typename transaction_prefix_current_t>
@ -58,8 +67,45 @@ bool transition_convert(const transaction_prefix_v1& from, transaction_prefix_cu
to.version = from.version;
to.extra = from.extra;
to.vin = from.vin;
to.vout = from.vout;
for (const auto& v : from.vout)
{
to.vout.push_back(v);
}
return true;
}
class transaction_v1:
{
public:
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
std::vector<attachment_v> attachment;
BEGIN_SERIALIZE_OBJECT()
FIELD(signatures)
FIELD(attachment)
END_SERIALIZE()
};
template<typename transaction_current_t>
bool transition_convert(const transaction_current_t& from, transaction_v1& to)
{
to.attachment = from.attachment;
if (from.signature.type() == typeid(NLSAG_sig))
{
to.signatures = boost::get<NLSAG_sig>(from.signature).s;
}
else
{
throw std::runtime_error("Unexpected type in signature_v");
}
return true;
}
template<typename transaction_current_t>
bool transition_convert(const transaction_v1& from, transaction_current_t& to)
{
to.attachment = from.attachment;
to.signature = NLSAG_sig();
boost::get<NLSAG_sig>(to.signature).s = from.signatures;
return true;
}

View file

@ -32,6 +32,15 @@ namespace currency
return expiration_time <= expiration_ts_median + TX_EXPIRATION_MEDIAN_SHIFT;
}
//---------------------------------------------------------------
#define VARIANT_SWITCH_BEGIN(v_type_obj) {decltype(v_type_obj)& local_reference_eokcmeokmeokcm = v_type_obj; if(false) {;
#define VARIANT_CASE(v_type) } else if(local_reference_eokcmeokmeokcm.type() == typeid(v_type)) { v_type& v_type_obj##_typed = boost::get<v_type>(local_reference_eokcmeokmeokcm);
#define VARIANT_CASE_OTHER(v_type) } else {
#define VARIANT_SWITCH_END() } }
uint64_t get_burned_amount(const transaction& tx)
{
uint64_t res = 0;