Initial support for Moneta Verde Multi-PoW merged mining
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
Node-CryptoForkNote-Util
|
||||
====================
|
||||
Node-CryptoForkNote-Util with Merged Mining support
|
||||
===================================================
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
@@ -9,4 +9,32 @@ enum BLOB_TYPE {
|
||||
BLOB_TYPE_CRYPTONOTE2 = 3, // Masari
|
||||
BLOB_TYPE_CRYPTONOTE_RYO = 4, // Ryo
|
||||
BLOB_TYPE_CRYPTONOTE_LOKI = 5, // Loki
|
||||
};
|
||||
|
||||
enum POW_TYPE {
|
||||
POW_TYPE_NOT_SET = -1,
|
||||
POW_TYPE_CN_ORIGINAL = 0,
|
||||
POW_TYPE_CN_V1 = 1, // Monero v7
|
||||
POW_TYPE_CN_XTL = 3,
|
||||
POW_TYPE_CN_MSR = 4,
|
||||
POW_TYPE_CN_XAO = 6,
|
||||
POW_TYPE_CN_RTO = 7,
|
||||
POW_TYPE_CN_V2 = 8, // Monero v8
|
||||
POW_TYPE_CN_HALF = 9,
|
||||
POW_TYPE_CN_GPU = 11,
|
||||
POW_TYPE_CN_WOW = 12,
|
||||
POW_TYPE_CN_V4 = 13, // Monero cn-R
|
||||
POW_TYPE_CN_RWZ = 14,
|
||||
POW_TYPE_CN_ZLS = 15,
|
||||
POW_TYPE_CN_DOUBLE = 16,
|
||||
|
||||
POW_TYPE_CNLITE_ORIGINAL = 20,
|
||||
POW_TYPE_CNLITE_V1 = 21,
|
||||
|
||||
POW_TYPE_CNHEAVY_ORIGINAL = 30,
|
||||
POW_TYPE_CNHEAVY_XHV = 31,
|
||||
POW_TYPE_CNHEAVY_TUBE = 32,
|
||||
|
||||
POW_TYPE_CNPICO_TRTL = 40
|
||||
|
||||
};
|
||||
32
src/main.cc
32
src/main.cc
@@ -134,7 +134,9 @@ NAN_METHOD(get_merge_mining_tag_reserved_size) {
|
||||
info.GetReturnValue().Set(returnValue);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* var blob = convert_blob (parentBlockBuffer, cnBlobType, [childBlockBuffer], [PoW])
|
||||
*/
|
||||
NAN_METHOD(convert_blob) {
|
||||
if (info.Length() < 1) return THROW_ERROR_EXCEPTION("You must provide one argument.");
|
||||
|
||||
@@ -150,6 +152,12 @@ NAN_METHOD(convert_blob) {
|
||||
blob_type = static_cast<enum BLOB_TYPE>(Nan::To<int>(info[1]).FromMaybe(0));
|
||||
}
|
||||
|
||||
enum POW_TYPE pow_type = POW_TYPE_NOT_SET;
|
||||
if (info.Length() >= 4) {
|
||||
if (!info[1]->IsNumber()) return THROW_ERROR_EXCEPTION("Argument 4 should be a number");
|
||||
pow_type = static_cast<enum POW_TYPE>(Nan::To<int>(info[3]).FromMaybe(0));
|
||||
}
|
||||
|
||||
//convert
|
||||
block b = AUTO_VAL_INIT(b);
|
||||
b.set_blob_type(blob_type);
|
||||
@@ -166,6 +174,7 @@ NAN_METHOD(convert_blob) {
|
||||
|
||||
if (blob_type == BLOB_TYPE_FORKNOTE2) {
|
||||
block parent_block;
|
||||
if (POW_TYPE_NOT_SET != pow_type) b.minor_version = pow_type;
|
||||
if (!construct_parent_block(b, parent_block)) return THROW_ERROR_EXCEPTION("Failed to construct parent block");
|
||||
if (!get_block_hashing_blob(parent_block, output)) return THROW_ERROR_EXCEPTION("Failed to create mining block");
|
||||
} else {
|
||||
@@ -208,6 +217,9 @@ NAN_METHOD(get_block_id) {
|
||||
info.GetReturnValue().Set(returnValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* var shareBuffer = construct_block_blob(parentBlockTemplateBuffer, nonceBuffer, cnBlobType, [childBlockTemplateBuffer], [PoW]);
|
||||
*/
|
||||
NAN_METHOD(construct_block_blob) {
|
||||
if (info.Length() < 2) return THROW_ERROR_EXCEPTION("You must provide two arguments.");
|
||||
|
||||
@@ -227,6 +239,12 @@ NAN_METHOD(construct_block_blob) {
|
||||
blob_type = static_cast<enum BLOB_TYPE>(Nan::To<int>(info[2]).FromMaybe(0));
|
||||
}
|
||||
|
||||
enum POW_TYPE pow_type = POW_TYPE_NOT_SET;
|
||||
if (info.Length() >= 5) {
|
||||
if (!info[1]->IsNumber()) return THROW_ERROR_EXCEPTION("Argument 5 should be a number");
|
||||
pow_type = static_cast<enum POW_TYPE>(Nan::To<int>(info[4]).FromMaybe(0));
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -244,6 +262,7 @@ NAN_METHOD(construct_block_blob) {
|
||||
if (blob_type == BLOB_TYPE_FORKNOTE2) {
|
||||
block parent_block;
|
||||
b.parent_block.nonce = nonce;
|
||||
if (POW_TYPE_NOT_SET != pow_type) b.minor_version = pow_type;
|
||||
if (!construct_parent_block(b, parent_block)) return THROW_ERROR_EXCEPTION("Failed to construct parent block");
|
||||
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>())) return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
|
||||
} else if (BLOB_TYPE_CRYPTONOTE == blob_type && info.Length() > 3) { // MM
|
||||
@@ -321,7 +340,7 @@ NAN_METHOD(address_decode_integrated) {
|
||||
|
||||
|
||||
/**
|
||||
* var mmShareBuffer = merge_blocks(shareBuffer, childBlockTemplate);
|
||||
* var mmShareBuffer = merge_blocks(shareBuffer, childBlockTemplate, [PoW] );
|
||||
*/
|
||||
NAN_METHOD(merge_blocks) {
|
||||
|
||||
@@ -337,6 +356,12 @@ NAN_METHOD(merge_blocks) {
|
||||
if (!Buffer::HasInstance(child_block_template_buf))
|
||||
return THROW_ERROR_EXCEPTION("Second argument should be a buffer object.");
|
||||
|
||||
enum POW_TYPE pow_type = POW_TYPE_NOT_SET;
|
||||
if (info.Length() >= 3) {
|
||||
if (!info[1]->IsNumber()) return THROW_ERROR_EXCEPTION("Argument 3 should be a number");
|
||||
pow_type = static_cast<enum POW_TYPE>(Nan::To<int>(info[2]).FromMaybe(0));
|
||||
}
|
||||
|
||||
blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf));
|
||||
blobdata child_block_template_blob = std::string(Buffer::Data(child_block_template_buf), Buffer::Length(child_block_template_buf));
|
||||
blobdata output = "";
|
||||
@@ -351,7 +376,8 @@ NAN_METHOD(merge_blocks) {
|
||||
|
||||
if (!mergeBlocks(b, b2, std::vector<crypto::hash>()))
|
||||
return THROW_ERROR_EXCEPTION("mergeBlocks(b,b2): Failed to postprocess mining block");
|
||||
|
||||
if (POW_TYPE_NOT_SET != pow_type) b2.minor_version = pow_type;
|
||||
|
||||
if (!block_to_blob(b2, output)) {
|
||||
return THROW_ERROR_EXCEPTION("Failed to convert block to blob (merge_blocks)");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user