From 02d48ecc7248c0cca7ffaf2e9bc0e7b092f78d56 Mon Sep 17 00:00:00 2001 From: MoneroOcean Date: Fri, 25 Oct 2019 17:22:31 -0700 Subject: [PATCH] Aeon support --- package.json | 2 +- src/cryptonote_config.h | 1 + src/cryptonote_core/cryptonote_basic.h | 13 +++++++++++-- src/main.cc | 11 ++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4974a77..a7516c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cryptoforknote-util", - "version": "5.0.0", + "version": "6.0.0", "main": "cryptoforknote-util", "author": { "name": "LucasJones", diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index ef7caa3..54f4e51 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -10,4 +10,5 @@ enum BLOB_TYPE { BLOB_TYPE_CRYPTONOTE_RYO = 4, // Ryo BLOB_TYPE_CRYPTONOTE_LOKI = 5, // Loki BLOB_TYPE_CRYPTONOTE3 = 6, // Masari + BLOB_TYPE_AEON = 7, // Aeon }; diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index 7361fbb..bc21fde 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -429,14 +429,23 @@ namespace cryptonote uint8_t minor_version; uint64_t timestamp; crypto::hash prev_id; - uint32_t nonce; + uint64_t nonce; BEGIN_SERIALIZE() VARINT_FIELD(major_version) VARINT_FIELD(minor_version) if (blob_type != BLOB_TYPE_FORKNOTE2) VARINT_FIELD(timestamp) FIELD(prev_id) - if (blob_type != BLOB_TYPE_FORKNOTE2) FIELD(nonce) + if (blob_type != BLOB_TYPE_FORKNOTE2) { + if (blob_type == BLOB_TYPE_AEON) { + FIELD(nonce) + } else { + uint32_t nonce32; + if (typename Archive::is_saving()) nonce32 = (uint32_t)nonce; + FIELD_N("nonce", nonce32); + if (!typename Archive::is_saving()) nonce = nonce32; + } + } END_SERIALIZE() }; diff --git a/src/main.cc b/src/main.cc index eb91f42..87dfab1 100644 --- a/src/main.cc +++ b/src/main.cc @@ -191,11 +191,6 @@ NAN_METHOD(construct_block_blob) { // (parentBlockTemplateBuffer, nonceBuffer, c Local nonce_buf = info[1]->ToObject(); if (!Buffer::HasInstance(block_template_buf) || !Buffer::HasInstance(nonce_buf)) return THROW_ERROR_EXCEPTION("Both arguments should be buffer objects."); - if (Buffer::Length(nonce_buf) != 4) return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size."); - - uint32_t nonce = *reinterpret_cast(Buffer::Data(nonce_buf)); - blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf)); - blobdata output = ""; enum BLOB_TYPE blob_type = BLOB_TYPE_CRYPTONOTE; if (info.Length() >= 3) { @@ -203,6 +198,12 @@ NAN_METHOD(construct_block_blob) { // (parentBlockTemplateBuffer, nonceBuffer, c blob_type = static_cast(Nan::To(info[2]).FromMaybe(0)); } + if (Buffer::Length(nonce_buf) != (blob_type == BLOB_TYPE_AEON ? 8 : 4)) return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size."); + + uint64_t nonce = blob_type == BLOB_TYPE_AEON ? *reinterpret_cast(Buffer::Data(nonce_buf)) : *reinterpret_cast(Buffer::Data(nonce_buf)); + blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf)); + blobdata output = ""; + block b = AUTO_VAL_INIT(b); b.set_blob_type(blob_type); if (!parse_and_validate_block_from_blob(block_template_blob, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");