Skip to content

Commit

Permalink
cryptonote_basic: remove unused to_script[_hash] vin/vout
Browse files Browse the repository at this point in the history
Structs were added 9 years ago and have yet to be used. I created a variant placeholder called `reserved` which can be used to easily keep
serialization backwards compatible while removing the types from variants.
  • Loading branch information
jeffro256 committed Dec 30, 2023
1 parent 053ba2c commit a95d8fd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 240 deletions.
83 changes: 18 additions & 65 deletions src/cryptonote_basic/cryptonote_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,8 @@

namespace cryptonote
{
typedef std::vector<crypto::signature> ring_signature;


/* outputs */

struct txout_to_script
{
std::vector<crypto::public_key> keys;
std::vector<uint8_t> script;

BEGIN_SERIALIZE_OBJECT()
FIELD(keys)
FIELD(script)
END_SERIALIZE()
};

struct txout_to_scripthash
{
crypto::hash hash;
};

// outputs <= HF_VERSION_VIEW_TAGS
struct txout_to_key
{
Expand Down Expand Up @@ -107,34 +88,6 @@ namespace cryptonote
END_SERIALIZE()
};

struct txin_to_script
{
crypto::hash prev;
size_t prevout;
std::vector<uint8_t> sigset;

BEGIN_SERIALIZE_OBJECT()
FIELD(prev)
VARINT_FIELD(prevout)
FIELD(sigset)
END_SERIALIZE()
};

struct txin_to_scripthash
{
crypto::hash prev;
size_t prevout;
txout_to_script script;
std::vector<uint8_t> sigset;

BEGIN_SERIALIZE_OBJECT()
FIELD(prev)
VARINT_FIELD(prevout)
FIELD(script)
FIELD(sigset)
END_SERIALIZE()
};

struct txin_to_key
{
uint64_t amount;
Expand All @@ -148,12 +101,19 @@ namespace cryptonote
END_SERIALIZE()
};

//! @brief A placeholder for types in variants which aren't currently used
// You can replace instances of reserved<X> in a variant with no meaningful difference
template <int TAG>
struct reserved
{
BEGIN_SERIALIZE()
END_SERIALIZE()
};

typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key> txin_v;
typedef boost::variant<txin_gen, reserved<0>, reserved<1>, txin_to_key> txin_v;

typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
typedef boost::variant<reserved<0>, reserved<1>, txout_to_key, txout_to_tagged_key> txout_target_v;

//typedef std::pair<uint64_t, txout> out_t;
struct tx_out
{
uint64_t amount;
Expand Down Expand Up @@ -441,8 +401,8 @@ namespace cryptonote
struct txin_signature_size_visitor : public boost::static_visitor<size_t>
{
size_t operator()(const txin_gen& txin) const{return 0;}
size_t operator()(const txin_to_script& txin) const{return 0;}
size_t operator()(const txin_to_scripthash& txin) const{return 0;}
size_t operator()(const reserved<0>&) const { return 0; }
size_t operator()(const reserved<1>&) const { return 0; }
size_t operator()(const txin_to_key& txin) const {return txin.key_offsets.size();}
};

Expand Down Expand Up @@ -567,37 +527,30 @@ namespace std {
}

BLOB_SERIALIZER(cryptonote::txout_to_key);
BLOB_SERIALIZER(cryptonote::txout_to_scripthash);

VARIANT_TAG(binary_archive, cryptonote::txin_gen, 0xff);
VARIANT_TAG(binary_archive, cryptonote::txin_to_script, 0x0);
VARIANT_TAG(binary_archive, cryptonote::txin_to_scripthash, 0x1);
VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2);
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);
VARIANT_TAG(binary_archive, cryptonote::txout_to_tagged_key, 0x3);
VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc);
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);
VARIANT_TAG(binary_archive, cryptonote::reserved<0>, 0x00);
VARIANT_TAG(binary_archive, cryptonote::reserved<1>, 0x01);

VARIANT_TAG(json_archive, cryptonote::txin_gen, "gen");
VARIANT_TAG(json_archive, cryptonote::txin_to_script, "script");
VARIANT_TAG(json_archive, cryptonote::txin_to_scripthash, "scripthash");
VARIANT_TAG(json_archive, cryptonote::txin_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::txout_to_script, "script");
VARIANT_TAG(json_archive, cryptonote::txout_to_scripthash, "scripthash");
VARIANT_TAG(json_archive, cryptonote::txout_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::txout_to_tagged_key, "tagged_key");
VARIANT_TAG(json_archive, cryptonote::transaction, "tx");
VARIANT_TAG(json_archive, cryptonote::block, "block");
VARIANT_TAG(json_archive, cryptonote::reserved<0>, "reserved_0");
VARIANT_TAG(json_archive, cryptonote::reserved<1>, "reserved_1");

VARIANT_TAG(debug_archive, cryptonote::txin_gen, "gen");
VARIANT_TAG(debug_archive, cryptonote::txin_to_script, "script");
VARIANT_TAG(debug_archive, cryptonote::txin_to_scripthash, "scripthash");
VARIANT_TAG(debug_archive, cryptonote::txin_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::txout_to_script, "script");
VARIANT_TAG(debug_archive, cryptonote::txout_to_scripthash, "scripthash");
VARIANT_TAG(debug_archive, cryptonote::txout_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::txout_to_tagged_key, "tagged_key");
VARIANT_TAG(debug_archive, cryptonote::transaction, "tx");
VARIANT_TAG(debug_archive, cryptonote::block, "block");
VARIANT_TAG(debug_archive, cryptonote::reserved<0>, "reserved_0");
VARIANT_TAG(debug_archive, cryptonote::reserved<1>, "reserved_1");
35 changes: 4 additions & 31 deletions src/cryptonote_basic/cryptonote_boost_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ namespace boost
a & reinterpret_cast<char (&)[sizeof(crypto::hash8)]>(x);
}

template <class Archive>
inline void serialize(Archive &a, cryptonote::txout_to_script &x, const boost::serialization::version_type ver)
{
a & x.keys;
a & x.script;
}


template <class Archive>
inline void serialize(Archive &a, cryptonote::txout_to_key &x, const boost::serialization::version_type ver)
{
Expand All @@ -113,35 +105,12 @@ namespace boost
a & x.view_tag;
}

template <class Archive>
inline void serialize(Archive &a, cryptonote::txout_to_scripthash &x, const boost::serialization::version_type ver)
{
a & x.hash;
}

template <class Archive>
inline void serialize(Archive &a, cryptonote::txin_gen &x, const boost::serialization::version_type ver)
{
a & x.height;
}

template <class Archive>
inline void serialize(Archive &a, cryptonote::txin_to_script &x, const boost::serialization::version_type ver)
{
a & x.prev;
a & x.prevout;
a & x.sigset;
}

template <class Archive>
inline void serialize(Archive &a, cryptonote::txin_to_scripthash &x, const boost::serialization::version_type ver)
{
a & x.prev;
a & x.prevout;
a & x.script;
a & x.sigset;
}

template <class Archive>
inline void serialize(Archive &a, cryptonote::txin_to_key &x, const boost::serialization::version_type ver)
{
Expand Down Expand Up @@ -422,6 +391,10 @@ namespace boost
}
}

template <class Archive, int TAG>
inline void serialize(Archive &a, cryptonote::reserved<TAG> &x, const boost::serialization::version_type ver)
{}

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2921,11 +2921,11 @@ bool Blockchain::check_for_double_spend(const transaction& tx, key_images_contai
{
return true;
}
bool operator()(const txin_to_script& tx) const
bool operator()(const reserved<0>&) const
{
return false;
}
bool operator()(const txin_to_scripthash& tx) const
bool operator()(const reserved<1>&) const
{
return false;
}
Expand Down
134 changes: 8 additions & 126 deletions src/serialization/json_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::t
{
INSERT_INTO_JSON_OBJECT(dest, gen, input);
}
void operator()(cryptonote::txin_to_script const& input) const
void operator()(cryptonote::reserved<0> const&) const
{
INSERT_INTO_JSON_OBJECT(dest, to_script, input);
ASSERT_MES_AND_THROW("attemping to serialize reserved variant to JSON");
}
void operator()(cryptonote::txin_to_scripthash const& input) const
void operator()(cryptonote::reserved<1> const&) const
{
INSERT_INTO_JSON_OBJECT(dest, to_scripthash, input);
ASSERT_MES_AND_THROW("attemping to serialize reserved variant to JSON");
}
};
boost::apply_visitor(add_input{dest}, txin);
Expand Down Expand Up @@ -393,18 +393,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_v& txin)
fromJsonValue(elem.value, tmpVal);
txin = std::move(tmpVal);
}
else if (elem.name == "to_script")
{
cryptonote::txin_to_script tmpVal;
fromJsonValue(elem.value, tmpVal);
txin = std::move(tmpVal);
}
else if (elem.name == "to_scripthash")
{
cryptonote::txin_to_scripthash tmpVal;
fromJsonValue(elem.value, tmpVal);
txin = std::move(tmpVal);
}
}
}

Expand All @@ -427,57 +415,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_gen& txin)
GET_FROM_JSON_OBJECT(val, txin.height, height);
}

void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::txin_to_script& txin)
{
dest.StartObject();

INSERT_INTO_JSON_OBJECT(dest, prev, txin.prev);
INSERT_INTO_JSON_OBJECT(dest, prevout, txin.prevout);
INSERT_INTO_JSON_OBJECT(dest, sigset, txin.sigset);

dest.EndObject();
}


void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_script& txin)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}

GET_FROM_JSON_OBJECT(val, txin.prev, prev);
GET_FROM_JSON_OBJECT(val, txin.prevout, prevout);
GET_FROM_JSON_OBJECT(val, txin.sigset, sigset);
}


void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::txin_to_scripthash& txin)
{
dest.StartObject();

INSERT_INTO_JSON_OBJECT(dest, prev, txin.prev);
INSERT_INTO_JSON_OBJECT(dest, prevout, txin.prevout);
INSERT_INTO_JSON_OBJECT(dest, script, txin.script);
INSERT_INTO_JSON_OBJECT(dest, sigset, txin.sigset);

dest.EndObject();
}


void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_scripthash& txin)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}

GET_FROM_JSON_OBJECT(val, txin.prev, prev);
GET_FROM_JSON_OBJECT(val, txin.prevout, prevout);
GET_FROM_JSON_OBJECT(val, txin.script, script);
GET_FROM_JSON_OBJECT(val, txin.sigset, sigset);
}

void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::txin_to_key& txin)
{
dest.StartObject();
Expand All @@ -501,49 +438,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::txin_to_key& txin)
GET_FROM_JSON_OBJECT(val, txin.k_image, key_image);
}


void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::txout_to_script& txout)
{
dest.StartObject();

INSERT_INTO_JSON_OBJECT(dest, keys, txout.keys);
INSERT_INTO_JSON_OBJECT(dest, script, txout.script);

dest.EndObject();
}

void fromJsonValue(const rapidjson::Value& val, cryptonote::txout_to_script& txout)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}

GET_FROM_JSON_OBJECT(val, txout.keys, keys);
GET_FROM_JSON_OBJECT(val, txout.script, script);
}


void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::txout_to_scripthash& txout)
{
dest.StartObject();

INSERT_INTO_JSON_OBJECT(dest, hash, txout.hash);

dest.EndObject();
}

void fromJsonValue(const rapidjson::Value& val, cryptonote::txout_to_scripthash& txout)
{
if (!val.IsObject())
{
throw WRONG_TYPE("json object");
}

GET_FROM_JSON_OBJECT(val, txout.hash, hash);
}


void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::txout_to_key& txout)
{
dest.StartObject();
Expand Down Expand Up @@ -603,13 +497,13 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::t
{
INSERT_INTO_JSON_OBJECT(dest, to_tagged_key, output);
}
void operator()(cryptonote::txout_to_script const& output) const
void operator()(cryptonote::reserved<0> const&) const
{
INSERT_INTO_JSON_OBJECT(dest, to_script, output);
ASSERT_MES_AND_THROW("attemping to serialize reserved variant to JSON");
}
void operator()(cryptonote::txout_to_scripthash const& output) const
void operator()(cryptonote::reserved<1> const&) const
{
INSERT_INTO_JSON_OBJECT(dest, to_scripthash, output);
ASSERT_MES_AND_THROW("attemping to serialize reserved variant to JSON");
}
};
boost::apply_visitor(add_output{dest}, txout.target);
Expand Down Expand Up @@ -647,18 +541,6 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::tx_out& txout)
fromJsonValue(elem.value, tmpVal);
txout.target = std::move(tmpVal);
}
else if (elem.name == "to_script")
{
cryptonote::txout_to_script tmpVal;
fromJsonValue(elem.value, tmpVal);
txout.target = std::move(tmpVal);
}
else if (elem.name == "to_scripthash")
{
cryptonote::txout_to_scripthash tmpVal;
fromJsonValue(elem.value, tmpVal);
txout.target = std::move(tmpVal);
}
}
}

Expand Down
Loading

0 comments on commit a95d8fd

Please sign in to comment.