Attempt 2
parent
16109f5e10
commit
268a421e7e
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#define BLOCK_MAJOR_VERSION_1 1
|
#define BLOCK_MAJOR_VERSION_1 1
|
||||||
#define BLOCK_MAJOR_VERSION_2 2
|
#define BLOCK_MAJOR_VERSION_2 2
|
||||||
|
#define BLOCK_MAJOR_VERSION_3 3
|
||||||
|
|
||||||
#define COIN ((uint64_t)100000000) // pow(10, 8)
|
#define COIN ((uint64_t)100000000) // pow(10, 8)
|
||||||
#define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6)
|
#define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6)
|
||||||
|
|
|
@ -481,7 +481,7 @@ namespace cryptonote
|
||||||
|
|
||||||
BEGIN_SERIALIZE()
|
BEGIN_SERIALIZE()
|
||||||
VARINT_FIELD(major_version)
|
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(minor_version)
|
||||||
VARINT_FIELD(timestamp)
|
VARINT_FIELD(timestamp)
|
||||||
FIELD(prev_id)
|
FIELD(prev_id)
|
||||||
|
|
|
@ -915,7 +915,7 @@ namespace cryptonote
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
bool check_proof_of_work_v2(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work)
|
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;
|
return false;
|
||||||
|
|
||||||
if (!get_bytecoin_block_longhash(bl, proof_of_work))
|
if (!get_bytecoin_block_longhash(bl, proof_of_work))
|
||||||
|
@ -954,7 +954,8 @@ namespace cryptonote
|
||||||
switch (bl.major_version)
|
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_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);
|
CHECK_AND_ASSERT_MES(false, false, "unknown block major version: " << bl.major_version << "." << bl.minor_version);
|
||||||
|
|
11
src/main.cc
11
src/main.cc
|
@ -125,7 +125,7 @@ NAN_METHOD(convert_blob_fa) {
|
||||||
if (!parse_and_validate_block_from_blob(input, b))
|
if (!parse_and_validate_block_from_blob(input, b))
|
||||||
return THROW_ERROR_EXCEPTION("Failed to parse block");
|
return THROW_ERROR_EXCEPTION("Failed to parse block");
|
||||||
|
|
||||||
if (b.major_version < BLOCK_MAJOR_VERSION_2) {
|
if (b.major_version < BLOCK_MAJOR_VERSION_3) {
|
||||||
if (!get_block_hashing_blob(b, output))
|
if (!get_block_hashing_blob(b, output))
|
||||||
return THROW_ERROR_EXCEPTION("Failed to create mining block");
|
return THROW_ERROR_EXCEPTION("Failed to create mining block");
|
||||||
} else {
|
} else {
|
||||||
|
@ -241,6 +241,15 @@ void construct_block_blob_fa(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
||||||
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
|
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
|
||||||
return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
|
return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
|
||||||
}
|
}
|
||||||
|
if (b.major_version == BLOCK_MAJOR_VERSION_3) {
|
||||||
|
block parent_block;
|
||||||
|
b.parent_block.nonce = nonce;
|
||||||
|
if (!construct_parent_block(b, parent_block))
|
||||||
|
return except("Failed to construct parent block");
|
||||||
|
|
||||||
|
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
|
||||||
|
return except("Failed to postprocess mining block");
|
||||||
|
}
|
||||||
|
|
||||||
if (!block_to_blob(b, output))
|
if (!block_to_blob(b, output))
|
||||||
return THROW_ERROR_EXCEPTION("Failed to convert block to blob");
|
return THROW_ERROR_EXCEPTION("Failed to convert block to blob");
|
||||||
|
|
Loading…
Reference in New Issue