From bf202c86c4f45cb7cdbdba6b2fa5b2f43bca0589 Mon Sep 17 00:00:00 2001 From: wallet42 Date: Sat, 21 May 2016 18:16:47 -0500 Subject: [PATCH] Support for forknote (BCN, ...) v2 and v3 Blocks --- .gitignore | 3 ++- package.json | 10 ++++--- src/cryptonote_config.h | 1 + src/cryptonote_core/cryptonote_basic.h | 22 ++++++++++------ .../cryptonote_format_utils.cpp | 26 ++++++++++--------- src/main.cc | 8 +++--- 6 files changed, 41 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 187adb2..febbb5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/nbproject/ \ No newline at end of file +/node_modules +/build diff --git a/package.json b/package.json index bef4d71..7b93e3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "cryptonote-util", - "version": "0.0.1", + "name": "forknote-util", + "version": "0.9.1", "main": "cryptonote", "author": { "name": "LucasJones", @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/clintar/node-cryptonote-util.git" + "url": "https://github.com/wallet42/node-forknote-util.git" }, "dependencies": { "bindings": "*", @@ -16,6 +16,8 @@ }, "keywords": [ "cryptonight", - "cryptonote" + "cryptonote", + "forknote", + "bytecoin" ] } diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index f516b24..e9cf60d 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -7,6 +7,7 @@ #define BLOCK_MAJOR_VERSION_1 1 #define BLOCK_MAJOR_VERSION_2 2 +#define BLOCK_MAJOR_VERSION_3 3 #define COIN ((uint64_t)100000000) // pow(10, 8) #define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6) diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index f9e6727..627f87e 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -456,11 +456,17 @@ namespace cryptonote BEGIN_SERIALIZE() VARINT_FIELD(major_version) - if(major_version > BLOCK_MAJOR_VERSION_2) return false; + if(major_version > BLOCK_MAJOR_VERSION_3) return false; VARINT_FIELD(minor_version) - VARINT_FIELD(timestamp) + if (BLOCK_MAJOR_VERSION_1 == major_version) + { + VARINT_FIELD(timestamp) + } FIELD(prev_id) - FIELD(nonce) + if (BLOCK_MAJOR_VERSION_1 == major_version) + { + FIELD(nonce) + } END_SERIALIZE() }; @@ -473,11 +479,11 @@ namespace cryptonote BEGIN_SERIALIZE_OBJECT() FIELDS(*static_cast(this)) -// if (BLOCK_MAJOR_VERSION_2 <= major_version) -// { -// auto sbb = make_serializable_bytecoin_block(*this, false, false); -// FIELD_N("parent_block", sbb); -// } + if (BLOCK_MAJOR_VERSION_2 <= major_version) + { + auto sbb = make_serializable_bytecoin_block(*this, false, false); + FIELD_N("parent_block", sbb); + } FIELD(miner_tx) FIELD(tx_hashes) END_SERIALIZE() diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 739b3b6..043363c 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -650,15 +650,15 @@ namespace cryptonote if (!get_block_hashing_blob(b, blob)) return false; -// if (BLOCK_MAJOR_VERSION_2 <= b.major_version) -// { -// blobdata parent_blob; -// auto sbb = make_serializable_bytecoin_block(b, true, false); -// if (!t_serializable_object_to_blob(sbb, parent_blob)) -// return false; + if (BLOCK_MAJOR_VERSION_2 <= b.major_version) + { + blobdata parent_blob; + auto sbb = make_serializable_bytecoin_block(b, true, false); + if (!t_serializable_object_to_blob(sbb, parent_blob)) + return false; -// blob.append(parent_blob); -// } + blob.append(parent_blob); + } return get_object_hash(blob, res); } @@ -851,8 +851,8 @@ namespace cryptonote //--------------------------------------------------------------- bool check_proof_of_work_v1(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work) { -// if (BLOCK_MAJOR_VERSION_1 != bl.major_version) -// return false; + if (BLOCK_MAJOR_VERSION_1 != bl.major_version) + return false; proof_of_work = get_block_longhash(bl, 0); return check_hash(proof_of_work, current_diffic); @@ -860,7 +860,8 @@ namespace cryptonote //--------------------------------------------------------------- bool check_proof_of_work_v2(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work) { - if (BLOCK_MAJOR_VERSION_2 != bl.major_version) + if (BLOCK_MAJOR_VERSION_2 != bl.major_version || + BLOCK_MAJOR_VERSION_3 != bl.major_version) return false; if (!get_bytecoin_block_longhash(bl, proof_of_work)) @@ -899,7 +900,8 @@ namespace cryptonote switch (bl.major_version) { case BLOCK_MAJOR_VERSION_1: return check_proof_of_work_v1(bl, current_diffic, proof_of_work); - case BLOCK_MAJOR_VERSION_2: return check_proof_of_work_v1(bl, current_diffic, proof_of_work); + case BLOCK_MAJOR_VERSION_2: return check_proof_of_work_v2(bl, current_diffic, proof_of_work); + case BLOCK_MAJOR_VERSION_3: return check_proof_of_work_v2(bl, current_diffic, proof_of_work); } CHECK_AND_ASSERT_MES(false, false, "unknown block major version: " << bl.major_version << "." << bl.minor_version); diff --git a/src/main.cc b/src/main.cc index cf575a1..d212de0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -100,7 +100,7 @@ NAN_METHOD(convert_blob) { if (!get_block_hashing_blob(b, output)) return THROW_ERROR_EXCEPTION("Failed to create mining block"); - + v8::Local returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked(); info.GetReturnValue().Set( returnValue @@ -141,7 +141,7 @@ NAN_METHOD(convert_blob_fa) { // info.GetReturnValue().Set( // returnValue // ); - + v8::Local returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked(); info.GetReturnValue().Set( returnValue @@ -168,7 +168,7 @@ void get_block_id(const Nan::FunctionCallbackInfo& info) { crypto::hash block_id; if (!get_block_hash(b, block_id)) return THROW_ERROR_EXCEPTION("Failed to calculate hash for block"); - + char *cstr = reinterpret_cast(&block_id); v8::Local returnValue = Nan::CopyBuffer(cstr, 32).ToLocalChecked(); info.GetReturnValue().Set( @@ -296,7 +296,7 @@ void address_decode(const Nan::FunctionCallbackInfo& info) { info.GetReturnValue().Set(Nan::Undefined()); } // info.GetReturnValue().Set(Nan::Undefined()); - + account_public_address adr; if (!::serialization::parse_binary(data, adr) || !crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))