Better ZEPH support
This commit is contained in:
@@ -233,7 +233,8 @@ 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_zephyr_key> txin_v;
|
||||
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_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;
|
||||
@@ -293,6 +294,7 @@ namespace cryptonote
|
||||
uint64_t unlock_time; //number of block (or time), used as a limitation like: spend this tx not early then block/time
|
||||
|
||||
std::vector<txin_v> vin;
|
||||
std::vector<txin_zephyr_v> vin_zephyr;
|
||||
std::vector<tx_out> vout;
|
||||
std::vector<tx_out_xhv> vout_xhv;
|
||||
std::vector<tx_out_zephyr> vout_zephyr;
|
||||
@@ -334,7 +336,10 @@ namespace cryptonote
|
||||
}
|
||||
if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV || version < POU_TRANSACTION_VERSION)
|
||||
VARINT_FIELD(unlock_time)
|
||||
FIELD(vin)
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||
FIELD(vin_zephyr)
|
||||
else
|
||||
FIELD(vin)
|
||||
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||
FIELD(vout_zephyr)
|
||||
@@ -437,7 +442,13 @@ namespace cryptonote
|
||||
if (!vin.empty())
|
||||
{
|
||||
ar.begin_object();
|
||||
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? vout_zephyr.size() : blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? vout.size() : vout_xhv.size());
|
||||
bool r;
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
|
||||
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout_xhv.size());
|
||||
else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||
r = rct_signatures.serialize_rctsig_base(ar, vin_zephyr.size(), vout_zephyr.size());
|
||||
else
|
||||
r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
|
||||
if (!r || !ar.stream().good()) return false;
|
||||
ar.end_object();
|
||||
if (rct_signatures.type != rct::RCTTypeNull)
|
||||
@@ -445,8 +456,8 @@ namespace cryptonote
|
||||
ar.tag("rctsig_prunable");
|
||||
ar.begin_object();
|
||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_zephyr.size(),
|
||||
vin[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(vin[0]).key_offsets.size() - 1 : 0);
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin_zephyr.size(), vout_zephyr.size(),
|
||||
vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(vin_zephyr[0]).key_offsets.size() - 1 : 0);
|
||||
} else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_xhv.size(),
|
||||
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
|
||||
@@ -486,6 +497,7 @@ namespace cryptonote
|
||||
version = 0;
|
||||
unlock_time = 0;
|
||||
vin.clear();
|
||||
vin_zephyr.clear();
|
||||
vout.clear();
|
||||
vout_xhv.clear();
|
||||
vout_zephyr.clear();
|
||||
|
||||
@@ -163,48 +163,6 @@ namespace cryptonote
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool get_inputs_money_amount(const transaction& tx, uint64_t& money)
|
||||
{
|
||||
money = 0;
|
||||
BOOST_FOREACH(const auto& in, tx.vin)
|
||||
{
|
||||
CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
|
||||
money += tokey_in.amount;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
uint64_t get_block_height(const block& b)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(b.miner_tx.vin.size() == 1, 0, "wrong miner tx in block: " << get_block_hash(b) << ", b.miner_tx.vin.size() != 1");
|
||||
CHECKED_GET_SPECIFIC_VARIANT(b.miner_tx.vin[0], const txin_gen, coinbase_in, 0);
|
||||
return coinbase_in.height;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool check_inputs_types_supported(const transaction& tx)
|
||||
{
|
||||
BOOST_FOREACH(const auto& in, tx.vin)
|
||||
{
|
||||
if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_zephyr_key), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_zephyr_key).name()
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
} else if (tx.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_offshore) || in.type() == typeid(txin_onshore) || in.type() == typeid(txin_xasset), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
|
||||
<< "or " << typeid(txin_offshore).name()
|
||||
<< "or " << typeid(txin_onshore).name()
|
||||
<< "or " << typeid(txin_xasset).name()
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
} else {
|
||||
CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: "
|
||||
<< in.type().name() << ", expected " << typeid(txin_to_key).name()
|
||||
<< ", in transaction id=" << get_transaction_hash(tx));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
std::string short_hash_str(const crypto::hash& h)
|
||||
{
|
||||
std::string res = string_tools::pod_to_hex(h);
|
||||
@@ -262,7 +220,7 @@ namespace cryptonote
|
||||
{
|
||||
std::stringstream ss;
|
||||
binary_archive<true> ba(ss);
|
||||
const size_t inputs = t.vin.size();
|
||||
const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size();
|
||||
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
||||
bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base");
|
||||
@@ -278,11 +236,11 @@ namespace cryptonote
|
||||
{
|
||||
std::stringstream ss;
|
||||
binary_archive<true> ba(ss);
|
||||
const size_t inputs = t.vin.size();
|
||||
const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size();
|
||||
const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size();
|
||||
size_t mixin;
|
||||
if (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||
mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(t.vin[0]).key_offsets.size() - 1 : 0;
|
||||
mixin = t.vin_zephyr.empty() ? 0 : t.vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get<txin_zephyr_key>(t.vin_zephyr[0]).key_offsets.size() - 1 : 0;
|
||||
} else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||
mixin = t.vin.empty() ? 0 :
|
||||
t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 :
|
||||
|
||||
@@ -78,12 +78,9 @@ namespace cryptonote
|
||||
bool get_block_header_hash(const block& b, crypto::hash& res);
|
||||
bool get_bytecoin_block_longhash(const block& blk, crypto::hash& res);
|
||||
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b);
|
||||
bool get_inputs_money_amount(const transaction& tx, uint64_t& money);
|
||||
std::map<std::string, uint64_t> get_outs_money_amount(const transaction& tx);
|
||||
bool check_inputs_types_supported(const transaction& tx);
|
||||
bool check_outs_valid(const transaction& tx);
|
||||
|
||||
uint64_t get_block_height(const block& b);
|
||||
std::vector<uint64_t> relative_output_offsets_to_absolute(const std::vector<uint64_t>& off);
|
||||
std::vector<uint64_t> absolute_output_offsets_to_relative(const std::vector<uint64_t>& off);
|
||||
//---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user