Skip to content

Commit

Permalink
Add fields/logic for TX_EXTRA_NTZ_TXN_TAG
Browse files Browse the repository at this point in the history
  • Loading branch information
who-biz committed Jun 29, 2019
1 parent cb09d8a commit f6deef4
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/common/hex_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ using namespace epee;
}
return ret;
}
//----------------------------------------------------------------
std::vector<uint8_t> hex_to_bytes4096(const std::string &input)
{
size_t len = input.length();
bool too_long = (len > 4096) ? 1 : 0;
std::string short_long = too_long ? ("longer") : ("shorter");
std::vector<uint8_t> out;

if (len != 64) {
MERROR("Tried to convert a hex string that is " << short_long << " than the required 4096-character length.");
std::fill(out.begin(), out.begin()+4096, 0);
return out;
}

for(size_t i = 0; i < len; i += 2) {
std::istringstream strm(input.substr(i, 2));
uint8_t x;
strm >> std::hex >> x;
out.push_back(x);
}
return out;
}
15 changes: 14 additions & 1 deletion src/cryptonote_basic/cryptonote_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ using namespace epee;
#include <atomic>
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <sstream>
#include <sstream>
#include <stdio.h>
#include "common/hex_str.h"
#include "wipeable_string.h"
#include "string_tools.h"
#include "serialization/string.h"
Expand Down Expand Up @@ -437,6 +438,18 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------
bool add_ntz_txn_to_extra(std::vector<uint8_t>& tx_extra, std::string& ntzstr)
{
tx_extra.resize(tx_extra.size() + 1 + sizeof(TX_EXTRA_NTZ_MAX_COUNT));
tx_extra[tx_extra.size() - 1 - sizeof(TX_EXTRA_NTZ_MAX_COUNT)] = TX_EXTRA_NTZ_TXN_TAG;
std::vector<uint8_t> ntz_data = hex_to_bytes4096(ntzstr);
for (const auto& character : ntz_data)
{
tx_extra.push_back(character);
}
return true;
}
//---------------------------------------------------------------
std::vector<crypto::public_key> get_additional_tx_pub_keys_from_extra(const std::vector<uint8_t>& tx_extra)
{
// parse
Expand Down
2 changes: 2 additions & 0 deletions src/cryptonote_basic/cryptonote_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ namespace cryptonote
bool add_tx_pub_key_to_extra(transaction& tx, const crypto::public_key& tx_pub_key);
bool add_tx_pub_key_to_extra(transaction_prefix& tx, const crypto::public_key& tx_pub_key);
bool add_tx_pub_key_to_extra(std::vector<uint8_t>& tx_extra, const crypto::public_key& tx_pub_key);
char *ntz_data_to_char(FILE* fp, size_t size);
bool add_ntz_txn_to_extra(std::vector<uint8_t>& tx_extra, FILE& file);
std::vector<crypto::public_key> get_additional_tx_pub_keys_from_extra(const std::vector<uint8_t>& tx_extra);
std::vector<crypto::public_key> get_additional_tx_pub_keys_from_extra(const transaction_prefix& tx);
bool add_additional_tx_pub_keys_to_extra(std::vector<uint8_t>& tx_extra, const std::vector<crypto::public_key>& additional_pub_keys);
Expand Down
54 changes: 52 additions & 2 deletions src/cryptonote_basic/tx_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define TX_EXTRA_PADDING_MAX_COUNT 255
#define TX_EXTRA_NONCE_MAX_COUNT 255
#define TX_EXTRA_NTZ_MAX_COUNT 4096
#define TX_EXTRA_NTZ_MAX_COUNT 4095

#define TX_EXTRA_TAG_PADDING 0x00
#define TX_EXTRA_TAG_PUBKEY 0x01
Expand All @@ -42,12 +42,61 @@
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE
#define TX_EXTRA_NTZ_TXN_TAG 0x05
#define TX_EXTRA_NTZ_PADDING 0x05

#define TX_EXTRA_NONCE_PAYMENT_ID 0x00
#define TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID 0x01

namespace cryptonote
{

struct tx_extra_ntz_padding
{
size_t size;

// load
template <template <bool> class Archive>
bool do_serialize(Archive<false>& ar)
{
// size - 1 - because of variant tag
for (size = 1; size <= TX_EXTRA_NTZ_MAX_COUNT; ++size)
{
std::ios_base::iostate state = ar.stream().rdstate();
bool eof = EOF == ar.stream().peek();
ar.stream().clear(state);

if (eof)
break;

uint8_t zero;
if (!::do_serialize(ar, zero))
return false;

if (0 != zero)
return false;
}

return size <= TX_EXTRA_NTZ_MAX_COUNT;
}

// store
template <template <bool> class Archive>
bool do_serialize(Archive<true>& ar)
{
if(TX_EXTRA_NTZ_MAX_COUNT < size)
return false;

// i = 1 - because of variant tag
for (size_t i = 1; i < size; ++i)
{
uint8_t zero = 0;
if (!::do_serialize(ar, zero))
return false;
}
return true;
}
};

struct tx_extra_padding
{
size_t size;
Expand Down Expand Up @@ -194,10 +243,11 @@ namespace cryptonote
// varint tag;
// varint size;
// varint data[];
typedef boost::variant<tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_mysterious_minergate, tx_extra_ntz_txn> tx_extra_field;
typedef boost::variant<tx_extra_padding, tx_extra_ntz_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_mysterious_minergate, tx_extra_ntz_txn> tx_extra_field;
}

VARIANT_TAG(binary_archive, cryptonote::tx_extra_padding, TX_EXTRA_TAG_PADDING);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_ntz_padding, TX_EXTRA_NTZ_PADDING);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_pub_key, TX_EXTRA_TAG_PUBKEY);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_nonce, TX_EXTRA_NONCE);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_merge_mining_tag, TX_EXTRA_MERGE_MINING_TAG);
Expand Down
2 changes: 0 additions & 2 deletions src/komodo/komodo_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@
#include "p2p/net_node.h"
#include "crypto/hash-ops.h"
#include "p2p/net_node.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "blockchain_db/lmdb/db_lmdb.h"
#include "komodo_rpcblockchain.h"
#include "common/hex_str.h"
#include "bitcoin/bitcoin.h"
#include <limits.h>
#include <assert.h>
Expand Down
2 changes: 0 additions & 2 deletions src/komodo/komodo_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@
#include "cryptonote_core/blockchain.h"
#include "crypto/crypto.h"
#include "crypto/hash-ops.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "blockchain_db/lmdb/db_lmdb.h"
#include "komodo_rpcblockchain.h"
#include "common/hex_str.h"
#include "bitcoin/bitcoin.h"
#include "rpc/core_rpc_server.h"
#include <limits.h>
Expand Down

0 comments on commit f6deef4

Please sign in to comment.