Added blob type selection
This commit is contained in:
@@ -15,3 +15,9 @@
|
|||||||
|
|
||||||
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60
|
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60
|
||||||
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 12
|
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 12
|
||||||
|
|
||||||
|
enum BLOB_TYPE {
|
||||||
|
BLOB_TYPE_CRYPTONOTE = 0,
|
||||||
|
BLOB_TYPE_FORKNOTE1 = 1,
|
||||||
|
BLOB_TYPE_FORKNOTE2 = 2,
|
||||||
|
};
|
||||||
@@ -174,10 +174,6 @@ namespace cryptonote
|
|||||||
|
|
||||||
BEGIN_SERIALIZE()
|
BEGIN_SERIALIZE()
|
||||||
VARINT_FIELD(version)
|
VARINT_FIELD(version)
|
||||||
//if(8 < version) {
|
|
||||||
// printf("!!! Current tx version %zu exceeds %u max", version, 8);
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
VARINT_FIELD(unlock_time)
|
VARINT_FIELD(unlock_time)
|
||||||
FIELD(vin)
|
FIELD(vin)
|
||||||
FIELD(vout)
|
FIELD(vout)
|
||||||
@@ -475,6 +471,8 @@ namespace cryptonote
|
|||||||
|
|
||||||
struct block_header
|
struct block_header
|
||||||
{
|
{
|
||||||
|
enum BLOB_TYPE blob_type;
|
||||||
|
|
||||||
uint8_t major_version;
|
uint8_t major_version;
|
||||||
uint8_t minor_version;
|
uint8_t minor_version;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
@@ -484,16 +482,9 @@ namespace cryptonote
|
|||||||
BEGIN_SERIALIZE()
|
BEGIN_SERIALIZE()
|
||||||
VARINT_FIELD(major_version)
|
VARINT_FIELD(major_version)
|
||||||
VARINT_FIELD(minor_version)
|
VARINT_FIELD(minor_version)
|
||||||
if (BLOCK_MAJOR_VERSION_2 != major_version && BLOCK_MAJOR_VERSION_3 != major_version)
|
if (blob_type != BLOB_TYPE_FORKNOTE2) VARINT_FIELD(timestamp)
|
||||||
{
|
|
||||||
printf("block_header: block version %u\n", major_version);
|
|
||||||
VARINT_FIELD(timestamp)
|
|
||||||
}
|
|
||||||
FIELD(prev_id)
|
FIELD(prev_id)
|
||||||
if (BLOCK_MAJOR_VERSION_2 != major_version && BLOCK_MAJOR_VERSION_3 != major_version)
|
if (blob_type != BLOB_TYPE_FORKNOTE2) FIELD(nonce)
|
||||||
{
|
|
||||||
FIELD(nonce)
|
|
||||||
}
|
|
||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -506,15 +497,10 @@ namespace cryptonote
|
|||||||
|
|
||||||
BEGIN_SERIALIZE_OBJECT()
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
FIELDS(*static_cast<block_header *>(this))
|
FIELDS(*static_cast<block_header *>(this))
|
||||||
if (BLOCK_MAJOR_VERSION_2 == major_version || BLOCK_MAJOR_VERSION_3 == major_version)
|
if (blob_type == BLOB_TYPE_FORKNOTE2)
|
||||||
{
|
{
|
||||||
printf("block: block version %u\n", major_version);
|
auto sbb = make_serializable_bytecoin_block(*this, false, false);
|
||||||
try {
|
FIELD_N("parent_block", sbb);
|
||||||
auto sbb = make_serializable_bytecoin_block(*this, false, false);
|
|
||||||
FIELD_N("parent_block", sbb);
|
|
||||||
} catch(...) {
|
|
||||||
puts("Exception!!!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
FIELD(miner_tx)
|
FIELD(miner_tx)
|
||||||
FIELD(tx_hashes)
|
FIELD(tx_hashes)
|
||||||
|
|||||||
@@ -509,9 +509,8 @@ namespace cryptonote
|
|||||||
if (!get_block_hashing_blob(b, blob))
|
if (!get_block_hashing_blob(b, blob))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (BLOCK_MAJOR_VERSION_2 == b.major_version || BLOCK_MAJOR_VERSION_3 == b.major_version)
|
if (b.blob_type == BLOB_TYPE_FORKNOTE2)
|
||||||
{
|
{
|
||||||
printf("get_block_hash: block version %u\n", b.major_version);
|
|
||||||
blobdata parent_blob;
|
blobdata parent_blob;
|
||||||
auto sbb = make_serializable_bytecoin_block(b, true, false);
|
auto sbb = make_serializable_bytecoin_block(b, true, false);
|
||||||
if (!t_serializable_object_to_blob(sbb, parent_blob))
|
if (!t_serializable_object_to_blob(sbb, parent_blob))
|
||||||
|
|||||||
25
src/main.cc
25
src/main.cc
@@ -74,14 +74,20 @@ NAN_METHOD(convert_blob) {
|
|||||||
if (info.Length() < 1) return THROW_ERROR_EXCEPTION("You must provide one argument.");
|
if (info.Length() < 1) return THROW_ERROR_EXCEPTION("You must provide one argument.");
|
||||||
|
|
||||||
Local<Object> target = info[0]->ToObject();
|
Local<Object> target = info[0]->ToObject();
|
||||||
|
|
||||||
if (!Buffer::HasInstance(target)) return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
|
if (!Buffer::HasInstance(target)) return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
|
||||||
|
|
||||||
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
|
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
|
||||||
blobdata output = "";
|
blobdata output = "";
|
||||||
|
|
||||||
|
enum BLOB_TYPE blob_type = BLOB_TYPE_CRYPTONOTE;
|
||||||
|
if (info.Length() >= 2) {
|
||||||
|
if (!info[1]->IsNumber()) return THROW_ERROR_EXCEPTION("Argument 2 should be a number");
|
||||||
|
blob_type = static_cast<enum BLOB_TYPE>(Nan::To<int>(info[1]).FromMaybe(0));
|
||||||
|
}
|
||||||
|
|
||||||
//convert
|
//convert
|
||||||
block b = AUTO_VAL_INIT(b);
|
block b = AUTO_VAL_INIT(b);
|
||||||
|
b.blob_type = blob_type;
|
||||||
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
||||||
|
|
||||||
if (b.major_version == BLOCK_MAJOR_VERSION_2 || b.major_version == BLOCK_MAJOR_VERSION_3) {
|
if (b.major_version == BLOCK_MAJOR_VERSION_2 || b.major_version == BLOCK_MAJOR_VERSION_3) {
|
||||||
@@ -100,13 +106,19 @@ NAN_METHOD(get_block_id) {
|
|||||||
if (info.Length() < 1) return THROW_ERROR_EXCEPTION("You must provide one argument.");
|
if (info.Length() < 1) return THROW_ERROR_EXCEPTION("You must provide one argument.");
|
||||||
|
|
||||||
Local<Object> target = info[0]->ToObject();
|
Local<Object> target = info[0]->ToObject();
|
||||||
|
|
||||||
if (!Buffer::HasInstance(target)) return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
|
if (!Buffer::HasInstance(target)) return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
|
||||||
|
|
||||||
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
|
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
|
||||||
blobdata output = "";
|
blobdata output = "";
|
||||||
|
|
||||||
|
enum BLOB_TYPE blob_type = BLOB_TYPE_CRYPTONOTE;
|
||||||
|
if (info.Length() >= 2) {
|
||||||
|
if (!info[1]->IsNumber()) return THROW_ERROR_EXCEPTION("Argument 2 should be a number");
|
||||||
|
blob_type = static_cast<enum BLOB_TYPE>(Nan::To<int>(info[1]).FromMaybe(0));
|
||||||
|
}
|
||||||
|
|
||||||
block b = AUTO_VAL_INIT(b);
|
block b = AUTO_VAL_INIT(b);
|
||||||
|
b.block_type = blob_type;
|
||||||
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
||||||
|
|
||||||
crypto::hash block_id;
|
crypto::hash block_id;
|
||||||
@@ -124,15 +136,20 @@ NAN_METHOD(construct_block_blob) {
|
|||||||
Local<Object> nonce_buf = info[1]->ToObject();
|
Local<Object> 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::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.");
|
if (Buffer::Length(nonce_buf) != 4) return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size.");
|
||||||
|
|
||||||
uint32_t nonce = *reinterpret_cast<uint32_t*>(Buffer::Data(nonce_buf));
|
uint32_t nonce = *reinterpret_cast<uint32_t*>(Buffer::Data(nonce_buf));
|
||||||
|
|
||||||
blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf));
|
blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf));
|
||||||
blobdata output = "";
|
blobdata output = "";
|
||||||
|
|
||||||
|
enum BLOB_TYPE blob_type = BLOB_TYPE_CRYPTONOTE;
|
||||||
|
if (info.Length() >= 3) {
|
||||||
|
if (!info[2]->IsNumber()) return THROW_ERROR_EXCEPTION("Argument 3 should be a number");
|
||||||
|
blob_type = static_cast<enum BLOB_TYPE>(Nan::To<int>(info[2]).FromMaybe(0));
|
||||||
|
}
|
||||||
|
|
||||||
block b = AUTO_VAL_INIT(b);
|
block b = AUTO_VAL_INIT(b);
|
||||||
|
b.blob_type = blob_type;
|
||||||
if (!parse_and_validate_block_from_blob(block_template_blob, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
if (!parse_and_validate_block_from_blob(block_template_blob, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
||||||
|
|
||||||
b.nonce = nonce;
|
b.nonce = nonce;
|
||||||
|
|||||||
Reference in New Issue
Block a user