Skip to content

Commit

Permalink
signed and unsiged tx files prefixes updated
Browse files Browse the repository at this point in the history
  • Loading branch information
moneroexamples committed Dec 31, 2016
1 parent fb8bb27 commit d373e5f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/monero_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#define BLOCKCHAIN_DB DB_LMDB


#define UNSIGNED_TX_PREFIX "Monero unsigned tx set\002"
#define SIGNED_TX_PREFIX "Monero signed tx set\002"
#define UNSIGNED_TX_PREFIX "Monero unsigned tx set\003"
#define SIGNED_TX_PREFIX "Monero signed tx set\003"
#define KEY_IMAGE_EXPORT_FILE_MAGIC "Monero key image export\002"
#define OUTPUT_EXPORT_FILE_MAGIC "Monero output export\003"

Expand Down
19 changes: 16 additions & 3 deletions src/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,8 @@ class page {

const size_t magiclen = strlen(UNSIGNED_TX_PREFIX);

string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen));

bool unsigned_tx_given {false};

if (strncmp(decoded_raw_tx_data.c_str(), UNSIGNED_TX_PREFIX, magiclen) == 0)
Expand All @@ -1525,6 +1527,7 @@ class page {
{"testnet" , testnet},
{"unsigned_tx_given" , unsigned_tx_given},
{"have_raw_tx" , true},
{"data_prefix" , data_prefix},
{"txs" , mstch::array{}}
};

Expand Down Expand Up @@ -1787,12 +1790,18 @@ class page {

const size_t magiclen = strlen(SIGNED_TX_PREFIX);

string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen));

if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0)
{
cout << "The data is neither unsigned nor signed tx!" << endl;
return string( "The data is neither unsigned nor signed tx!");
string msg = fmt::format("The data is neither unsigned nor signed tx! Its prefix is: {:s}",
data_prefix);

cout << msg << endl;
return string(msg);
}

context["data_prefix"] = data_prefix;

bool r {false};

Expand Down Expand Up @@ -2055,12 +2064,15 @@ class page {

const size_t magiclen = strlen(SIGNED_TX_PREFIX);

string data_prefix = xmreg::make_printable(decoded_raw_tx_data.substr(0, magiclen));

// initalize page template context map
mstch::map context {
{"testnet" , testnet},
{"have_raw_tx" , true},
{"has_error" , false},
{"error_msg" , string {}},
{"data_prefix" , data_prefix},
{"txs" , mstch::array{}}
};

Expand All @@ -2074,7 +2086,8 @@ class page {

if (strncmp(decoded_raw_tx_data.c_str(), SIGNED_TX_PREFIX, magiclen) != 0)
{
string error_msg = fmt::format("The data does not appear to be signed raw tx!");
string error_msg = fmt::format("The data does not appear to be signed raw tx! Data prefix: {:s}",
data_prefix);

context["has_error"] = true;
context["error_msg"] = error_msg;
Expand Down
3 changes: 3 additions & 0 deletions src/templates/checkrawtx.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ <h4 style="font-size: 15px; margin: 0px">(no javascript - no cookies - no web an
</div>

<div class="center">

<h3>Data file prefix: {{data_prefix}}</h3>

{{#unsigned_tx_given}}
<h3>Details of unsigned raw tx data given</h3>

Expand Down
38 changes: 38 additions & 0 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,5 +1245,43 @@ make_tx_from_json(const string& json_str, transaction& tx)
return true;
}


string
make_printable(const string& in_s)
{
string output;

for (char c: in_s)
{

if (isprint(c))
{
output += c;
}
else
{
switch(c){
case '\000': output += "\\000";break;
case '\001': output += "\\001";break;
case '\002': output += "\\002";break;
case '\003': output += "\\003";break;
case '\004': output += "\\004";break;
case '\005': output += "\\005";break;
case '\006': output += "\\006";break;
case '\007': output += "\\007";break;
// there are more case but for now its ok
default:
stringstream ss;
ss << std::hex << (int)c;
output += "0x" + ss.str();
break;
}
}

}

return output;
}

}

2 changes: 2 additions & 0 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ void chunks(Iterator begin,
bool
make_tx_from_json(const string& json_str, transaction& tx);

string
make_printable(const string& in_s);
}

#endif //XMREG01_TOOLS_H

0 comments on commit d373e5f

Please sign in to comment.