Skip to content

Commit 9fbcb16

Browse files
committed
Merge in Xmr nan 2.0
- Snipa22#5
1 parent eefe9b7 commit 9fbcb16

10 files changed

Lines changed: 368 additions & 167 deletions

File tree

binding.gyp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"-fexceptions",
3131
"-frtti",
3232
],
33+
"xcode_settings": {
34+
"OTHER_CFLAGS": ["-fexceptions", "-frtti"]
35+
}
3336
}
3437
]
3538
}

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"name": "cryptonote-util",
3-
"version": "0.0.1",
4-
"main": "cryptonote",
5-
"author": {
6-
"name": "LucasJones",
7-
"email": "lucasjonesdev@hotmail.co.uk"
8-
},
9-
"repository": {
10-
"type": "git",
11-
"url": "https://github.com/LucasJones/node-cryptonote-util.git"
12-
},
13-
"dependencies" : {
14-
"bindings" : "*",
15-
"nan" : "1"
16-
},
17-
"keywords": [
18-
"cryptonight",
19-
"cryptonote"
20-
]
2+
"name": "cryptonote-util",
3+
"version": "0.0.3",
4+
"main": "cryptonote",
5+
"author": {
6+
"name": "LucasJones",
7+
"email": "lucasjonesdev@hotmail.co.uk"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/clintar/node-cryptonote-util.git"
12+
},
13+
"dependencies": {
14+
"bindings": "*",
15+
"nan": "^2.0.0"
16+
},
17+
"keywords": [
18+
"cryptonight",
19+
"cryptonote"
20+
]
2121
}

src/crypto/crypto.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,17 @@ namespace crypto {
212212

213213
PUSH_WARNINGS
214214
DISABLE_VS_WARNINGS(4200)
215+
struct ec_point_pair {
216+
ec_point a, b;
217+
};
215218
struct rs_comm {
216219
hash h;
217-
struct {
218-
ec_point a, b;
219-
} ab[];
220-
};
220+
struct ec_point_pair ab[];
221+
} ;
221222
POP_WARNINGS
222223

223224
static inline size_t rs_comm_size(size_t pubs_count) {
224-
return sizeof(rs_comm) + pubs_count * sizeof(rs_comm().ab[0]);
225+
return sizeof(rs_comm) + pubs_count * sizeof(ec_point_pair);
225226
}
226227

227228
void crypto_ops::generate_ring_signature(const hash &prefix_hash, const key_image &image,

src/crypto/hash.h

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,57 @@
1111

1212
namespace crypto {
1313

14-
extern "C" {
14+
extern "C" {
1515
#include "hash-ops.h"
16-
}
16+
}
1717

1818
#pragma pack(push, 1)
19-
POD_CLASS hash {
20-
char data[HASH_SIZE];
21-
};
19+
POD_CLASS hash{
20+
char data[HASH_SIZE];
21+
};
22+
POD_CLASS hash8{
23+
char data[8];
24+
};
25+
2226
#pragma pack(pop)
2327

24-
static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
28+
static_assert(sizeof(hash) == HASH_SIZE, "Invalid structure size");
29+
static_assert(sizeof(hash8) == 8, "Invalid structure size");
2530

26-
/*
27-
Cryptonight hash functions
28-
*/
31+
/*
32+
Cryptonight hash functions
33+
*/
2934

30-
inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
31-
cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
32-
}
35+
inline void cn_fast_hash(const void *data, std::size_t length, hash &hash) {
36+
cn_fast_hash(data, length, reinterpret_cast<char *>(&hash));
37+
}
3338

34-
inline hash cn_fast_hash(const void *data, std::size_t length) {
35-
hash h;
36-
cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
37-
return h;
38-
}
39+
inline hash cn_fast_hash(const void *data, std::size_t length) {
40+
hash h;
41+
cn_fast_hash(data, length, reinterpret_cast<char *>(&h));
42+
return h;
43+
}
3944

40-
inline void cn_slow_hash(const void *data, std::size_t length, hash &hash) {
41-
cn_slow_hash(data, length, reinterpret_cast<char *>(&hash));
42-
}
45+
inline void cn_slow_hash(const void *data, std::size_t length, hash &hash) {
46+
cn_slow_hash(data, length, reinterpret_cast<char *>(&hash));
47+
}
4348

44-
inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
45-
tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
46-
}
49+
inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
50+
tree_hash(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char *>(&root_hash));
51+
}
4752

48-
inline void tree_branch(const hash* hashes, std::size_t count, hash* branch)
49-
{
50-
tree_branch(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count, reinterpret_cast<char (*)[HASH_SIZE]>(branch));
51-
}
53+
inline void tree_branch(const hash *hashes, std::size_t count, hash *branch) {
54+
tree_branch(reinterpret_cast<const char (*)[HASH_SIZE]>(hashes), count,
55+
reinterpret_cast<char (*)[HASH_SIZE]>(branch));
56+
}
5257

53-
inline void tree_hash_from_branch(const hash* branch, std::size_t depth, const hash& leaf, const void* path, hash& root_hash)
54-
{
55-
tree_hash_from_branch(reinterpret_cast<const char (*)[HASH_SIZE]>(branch), depth, reinterpret_cast<const char*>(&leaf), path, reinterpret_cast<char*>(&root_hash));
56-
}
58+
inline void
59+
tree_hash_from_branch(const hash *branch, std::size_t depth, const hash &leaf, const void *path, hash &root_hash) {
60+
tree_hash_from_branch(reinterpret_cast<const char (*)[HASH_SIZE]>(branch), depth,
61+
reinterpret_cast<const char *>(&leaf), path, reinterpret_cast<char *>(&root_hash));
62+
}
5763

5864
}
5965

6066
CRYPTO_MAKE_HASHABLE(hash)
67+
CRYPTO_MAKE_COMPARABLE(hash8)

src/cryptonote_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

33
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0
4-
#define CURRENT_TRANSACTION_VERSION 1
4+
#define CURRENT_TRANSACTION_VERSION 2
55
#define CURRENT_BLOCK_MAJOR_VERSION 1
66
#define CURRENT_BLOCK_MINOR_VERSION 0
77

88
#define BLOCK_MAJOR_VERSION_1 1
9-
#define BLOCK_MAJOR_VERSION_2 2
9+
#define BLOCK_MAJOR_VERSION_2 3
1010

1111
#define COIN ((uint64_t)100000000) // pow(10, 8)
1212
#define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6)

src/cryptonote_core/cryptonote_basic.h

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "crypto/hash.h"
2525
#include "misc_language.h"
2626
#include "tx_extra.h"
27+
#include "ringct/rctTypes.h"
2728

2829

2930
namespace cryptonote
@@ -189,6 +190,7 @@ namespace cryptonote
189190
{
190191
public:
191192
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
193+
rct::rctSig rct_signatures;
192194

193195
transaction();
194196
virtual ~transaction();
@@ -197,34 +199,57 @@ namespace cryptonote
197199
BEGIN_SERIALIZE_OBJECT()
198200
FIELDS(*static_cast<transaction_prefix *>(this))
199201

200-
ar.tag("signatures");
201-
ar.begin_array();
202-
PREPARE_CUSTOM_VECTOR_SERIALIZATION(vin.size(), signatures);
203-
bool signatures_not_expected = signatures.empty();
204-
if (!signatures_not_expected && vin.size() != signatures.size())
205-
return false;
206-
207-
for (size_t i = 0; i < vin.size(); ++i)
202+
if (version == 1)
208203
{
209-
size_t signature_size = get_signature_size(vin[i]);
210-
if (signatures_not_expected)
204+
ar.tag("signatures");
205+
ar.begin_array();
206+
PREPARE_CUSTOM_VECTOR_SERIALIZATION(vin.size(), signatures);
207+
bool signatures_not_expected = signatures.empty();
208+
if (!signatures_not_expected && vin.size() != signatures.size())
209+
return false;
210+
211+
for (size_t i = 0; i < vin.size(); ++i)
211212
{
212-
if (0 == signature_size)
213-
continue;
214-
else
213+
size_t signature_size = get_signature_size(vin[i]);
214+
if (signatures_not_expected)
215+
{
216+
if (0 == signature_size)
217+
continue;
218+
else
219+
return false;
220+
}
221+
222+
PREPARE_CUSTOM_VECTOR_SERIALIZATION(signature_size, signatures[i]);
223+
if (signature_size != signatures[i].size())
215224
return false;
216-
}
217-
218-
PREPARE_CUSTOM_VECTOR_SERIALIZATION(signature_size, signatures[i]);
219-
if (signature_size != signatures[i].size())
220-
return false;
221225

222-
FIELDS(signatures[i]);
226+
FIELDS(signatures[i]);
223227

224-
if (vin.size() - i > 1)
225-
ar.delimit_array();
228+
if (vin.size() - i > 1)
229+
ar.delimit_array();
230+
}
231+
ar.end_array();
232+
}
233+
else
234+
{
235+
ar.tag("rct_signatures");
236+
if (!vin.empty())
237+
{
238+
ar.begin_object();
239+
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
240+
if (!r || !ar.stream().good()) return false;
241+
ar.end_object();
242+
if (rct_signatures.type != rct::RCTTypeNull)
243+
{
244+
ar.tag("rctsig_prunable");
245+
ar.begin_object();
246+
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(),
247+
vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0);
248+
if (!r || !ar.stream().good()) return false;
249+
ar.end_object();
250+
}
251+
}
226252
}
227-
ar.end_array();
228253
END_SERIALIZE()
229254

230255
private:
@@ -383,7 +408,6 @@ namespace cryptonote
383408

384409
BEGIN_SERIALIZE_OBJECT()
385410
VARINT_FIELD_N("major_version", b.major_version);
386-
if(b.major_version > CURRENT_BYTECOIN_BLOCK_MAJOR_VERSION) return false;
387411
VARINT_FIELD_N("minor_version", b.minor_version);
388412
VARINT_FIELD(timestamp);
389413
FIELD_N("prev_id", b.prev_id);
@@ -456,17 +480,10 @@ namespace cryptonote
456480

457481
BEGIN_SERIALIZE()
458482
VARINT_FIELD(major_version)
459-
if(major_version > BLOCK_MAJOR_VERSION_2) return false;
460483
VARINT_FIELD(minor_version)
461-
if (BLOCK_MAJOR_VERSION_1 == major_version)
462-
{
463-
VARINT_FIELD(timestamp)
464-
}
484+
VARINT_FIELD(timestamp)
465485
FIELD(prev_id)
466-
if (BLOCK_MAJOR_VERSION_1 == major_version)
467-
{
468-
FIELD(nonce)
469-
}
486+
FIELD(nonce)
470487
END_SERIALIZE()
471488
};
472489

@@ -479,11 +496,6 @@ namespace cryptonote
479496

480497
BEGIN_SERIALIZE_OBJECT()
481498
FIELDS(*static_cast<block_header *>(this))
482-
if (BLOCK_MAJOR_VERSION_2 <= major_version)
483-
{
484-
auto sbb = make_serializable_bytecoin_block(*this, false, false);
485-
FIELD_N("parent_block", sbb);
486-
}
487499
FIELD(miner_tx)
488500
FIELD(tx_hashes)
489501
END_SERIALIZE()
@@ -547,7 +559,23 @@ namespace cryptonote
547559
END_KV_SERIALIZE_MAP()
548560
};
549561

550-
struct keypair
562+
struct integrated_address {
563+
account_public_address adr;
564+
crypto::hash8 payment_id;
565+
566+
BEGIN_SERIALIZE_OBJECT()
567+
FIELD(adr)
568+
FIELD(payment_id)
569+
END_SERIALIZE()
570+
571+
BEGIN_KV_SERIALIZE_MAP()
572+
KV_SERIALIZE(adr)
573+
KV_SERIALIZE(payment_id)
574+
END_KV_SERIALIZE_MAP()
575+
};
576+
577+
578+
struct keypair
551579
{
552580
crypto::public_key pub;
553581
crypto::secret_key sec;

0 commit comments

Comments
 (0)