Attempt 2

bcn-Nan-2.0
Petar Mitchev 2016-04-21 19:14:04 +03:00 committed by Harald Wolff
parent 16109f5e10
commit 268a421e7e
4 changed files with 15 additions and 4 deletions

View File

@ -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)

View File

@ -481,7 +481,7 @@ 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)
FIELD(prev_id)

View File

@ -915,7 +915,7 @@ 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))
@ -954,7 +954,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);

View File

@ -125,7 +125,7 @@ NAN_METHOD(convert_blob_fa) {
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) {
if (b.major_version < BLOCK_MAJOR_VERSION_3) {
if (!get_block_hashing_blob(b, output))
return THROW_ERROR_EXCEPTION("Failed to create mining block");
} 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>()))
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))
return THROW_ERROR_EXCEPTION("Failed to convert block to blob");