Merge pull request #2 from wallet42/blockv3
Support for forknote (BCN, ...) v2 and v3 Blocks
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
/nbproject/
|
/node_modules
|
||||||
|
/build
|
||||||
|
|||||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptonote-util",
|
"name": "forknote-util",
|
||||||
"version": "0.0.1",
|
"version": "0.9.1",
|
||||||
"main": "cryptonote",
|
"main": "cryptonote",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/clintar/node-cryptonote-util.git"
|
"url": "https://github.com/wallet42/node-forknote-util.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bindings": "*",
|
"bindings": "*",
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"cryptonight",
|
"cryptonight",
|
||||||
"cryptonote"
|
"cryptonote",
|
||||||
|
"forknote",
|
||||||
|
"bytecoin"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -456,11 +456,17 @@ 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)
|
if (BLOCK_MAJOR_VERSION_1 == major_version)
|
||||||
|
{
|
||||||
|
VARINT_FIELD(timestamp)
|
||||||
|
}
|
||||||
FIELD(prev_id)
|
FIELD(prev_id)
|
||||||
FIELD(nonce)
|
if (BLOCK_MAJOR_VERSION_1 == major_version)
|
||||||
|
{
|
||||||
|
FIELD(nonce)
|
||||||
|
}
|
||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -473,11 +479,11 @@ 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)
|
if (BLOCK_MAJOR_VERSION_2 <= major_version)
|
||||||
// {
|
{
|
||||||
// auto sbb = make_serializable_bytecoin_block(*this, false, false);
|
auto sbb = make_serializable_bytecoin_block(*this, false, false);
|
||||||
// FIELD_N("parent_block", sbb);
|
FIELD_N("parent_block", sbb);
|
||||||
// }
|
}
|
||||||
FIELD(miner_tx)
|
FIELD(miner_tx)
|
||||||
FIELD(tx_hashes)
|
FIELD(tx_hashes)
|
||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
|
|||||||
@@ -650,15 +650,15 @@ 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)
|
if (BLOCK_MAJOR_VERSION_2 <= 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))
|
||||||
// return false;
|
return false;
|
||||||
|
|
||||||
// blob.append(parent_blob);
|
blob.append(parent_blob);
|
||||||
// }
|
}
|
||||||
|
|
||||||
return get_object_hash(blob, res);
|
return get_object_hash(blob, res);
|
||||||
}
|
}
|
||||||
@@ -851,8 +851,8 @@ namespace cryptonote
|
|||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
bool check_proof_of_work_v1(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work)
|
bool check_proof_of_work_v1(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work)
|
||||||
{
|
{
|
||||||
// if (BLOCK_MAJOR_VERSION_1 != bl.major_version)
|
if (BLOCK_MAJOR_VERSION_1 != bl.major_version)
|
||||||
// return false;
|
return false;
|
||||||
|
|
||||||
proof_of_work = get_block_longhash(bl, 0);
|
proof_of_work = get_block_longhash(bl, 0);
|
||||||
return check_hash(proof_of_work, current_diffic);
|
return check_hash(proof_of_work, current_diffic);
|
||||||
@@ -860,7 +860,8 @@ 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))
|
||||||
@@ -899,7 +900,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);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ NAN_METHOD(convert_blob) {
|
|||||||
|
|
||||||
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");
|
||||||
|
|
||||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
||||||
info.GetReturnValue().Set(
|
info.GetReturnValue().Set(
|
||||||
returnValue
|
returnValue
|
||||||
@@ -141,7 +141,7 @@ NAN_METHOD(convert_blob_fa) {
|
|||||||
// info.GetReturnValue().Set(
|
// info.GetReturnValue().Set(
|
||||||
// returnValue
|
// returnValue
|
||||||
// );
|
// );
|
||||||
|
|
||||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
||||||
info.GetReturnValue().Set(
|
info.GetReturnValue().Set(
|
||||||
returnValue
|
returnValue
|
||||||
@@ -168,7 +168,7 @@ void get_block_id(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
|||||||
crypto::hash block_id;
|
crypto::hash block_id;
|
||||||
if (!get_block_hash(b, block_id))
|
if (!get_block_hash(b, block_id))
|
||||||
return THROW_ERROR_EXCEPTION("Failed to calculate hash for block");
|
return THROW_ERROR_EXCEPTION("Failed to calculate hash for block");
|
||||||
|
|
||||||
char *cstr = reinterpret_cast<char*>(&block_id);
|
char *cstr = reinterpret_cast<char*>(&block_id);
|
||||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer(cstr, 32).ToLocalChecked();
|
v8::Local<v8::Value> returnValue = Nan::CopyBuffer(cstr, 32).ToLocalChecked();
|
||||||
info.GetReturnValue().Set(
|
info.GetReturnValue().Set(
|
||||||
@@ -296,7 +296,7 @@ void address_decode(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
|||||||
info.GetReturnValue().Set(Nan::Undefined());
|
info.GetReturnValue().Set(Nan::Undefined());
|
||||||
}
|
}
|
||||||
// info.GetReturnValue().Set(Nan::Undefined());
|
// info.GetReturnValue().Set(Nan::Undefined());
|
||||||
|
|
||||||
|
|
||||||
account_public_address adr;
|
account_public_address adr;
|
||||||
if (!::serialization::parse_binary(data, adr) || !crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
|
if (!::serialization::parse_binary(data, adr) || !crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
|
||||||
|
|||||||
Reference in New Issue
Block a user