Support for forknote (BCN, ...) v2 and v3 Blocks
parent
e87d0672b0
commit
bf202c86c4
|
@ -1 +1,2 @@
|
|||
/nbproject/
|
||||
/node_modules
|
||||
/build
|
||||
|
|
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cryptonote-util",
|
||||
"version": "0.0.1",
|
||||
"name": "forknote-util",
|
||||
"version": "0.9.1",
|
||||
"main": "cryptonote",
|
||||
"author": {
|
||||
"name": "LucasJones",
|
||||
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/clintar/node-cryptonote-util.git"
|
||||
"url": "https://github.com/wallet42/node-forknote-util.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"bindings": "*",
|
||||
|
@ -16,6 +16,8 @@
|
|||
},
|
||||
"keywords": [
|
||||
"cryptonight",
|
||||
"cryptonote"
|
||||
"cryptonote",
|
||||
"forknote",
|
||||
"bytecoin"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -456,11 +456,17 @@ 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)
|
||||
if (BLOCK_MAJOR_VERSION_1 == major_version)
|
||||
{
|
||||
VARINT_FIELD(timestamp)
|
||||
}
|
||||
FIELD(prev_id)
|
||||
FIELD(nonce)
|
||||
if (BLOCK_MAJOR_VERSION_1 == major_version)
|
||||
{
|
||||
FIELD(nonce)
|
||||
}
|
||||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
|
@ -473,11 +479,11 @@ namespace cryptonote
|
|||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
FIELDS(*static_cast<block_header *>(this))
|
||||
// if (BLOCK_MAJOR_VERSION_2 <= major_version)
|
||||
// {
|
||||
// auto sbb = make_serializable_bytecoin_block(*this, false, false);
|
||||
// FIELD_N("parent_block", sbb);
|
||||
// }
|
||||
if (BLOCK_MAJOR_VERSION_2 <= major_version)
|
||||
{
|
||||
auto sbb = make_serializable_bytecoin_block(*this, false, false);
|
||||
FIELD_N("parent_block", sbb);
|
||||
}
|
||||
FIELD(miner_tx)
|
||||
FIELD(tx_hashes)
|
||||
END_SERIALIZE()
|
||||
|
|
|
@ -650,15 +650,15 @@ namespace cryptonote
|
|||
if (!get_block_hashing_blob(b, blob))
|
||||
return false;
|
||||
|
||||
// if (BLOCK_MAJOR_VERSION_2 <= b.major_version)
|
||||
// {
|
||||
// blobdata parent_blob;
|
||||
// auto sbb = make_serializable_bytecoin_block(b, true, false);
|
||||
// if (!t_serializable_object_to_blob(sbb, parent_blob))
|
||||
// return false;
|
||||
if (BLOCK_MAJOR_VERSION_2 <= b.major_version)
|
||||
{
|
||||
blobdata parent_blob;
|
||||
auto sbb = make_serializable_bytecoin_block(b, true, false);
|
||||
if (!t_serializable_object_to_blob(sbb, parent_blob))
|
||||
return false;
|
||||
|
||||
// blob.append(parent_blob);
|
||||
// }
|
||||
blob.append(parent_blob);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// if (BLOCK_MAJOR_VERSION_1 != bl.major_version)
|
||||
// return false;
|
||||
if (BLOCK_MAJOR_VERSION_1 != bl.major_version)
|
||||
return false;
|
||||
|
||||
proof_of_work = get_block_longhash(bl, 0);
|
||||
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)
|
||||
{
|
||||
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))
|
||||
|
@ -899,7 +900,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);
|
||||
|
|
|
@ -100,7 +100,7 @@ NAN_METHOD(convert_blob) {
|
|||
|
||||
if (!get_block_hashing_blob(b, output))
|
||||
return THROW_ERROR_EXCEPTION("Failed to create mining block");
|
||||
|
||||
|
||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
||||
info.GetReturnValue().Set(
|
||||
returnValue
|
||||
|
@ -141,7 +141,7 @@ NAN_METHOD(convert_blob_fa) {
|
|||
// info.GetReturnValue().Set(
|
||||
// returnValue
|
||||
// );
|
||||
|
||||
|
||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
|
||||
info.GetReturnValue().Set(
|
||||
returnValue
|
||||
|
@ -168,7 +168,7 @@ void get_block_id(const Nan::FunctionCallbackInfo<v8::Value>& info) {
|
|||
crypto::hash block_id;
|
||||
if (!get_block_hash(b, block_id))
|
||||
return THROW_ERROR_EXCEPTION("Failed to calculate hash for block");
|
||||
|
||||
|
||||
char *cstr = reinterpret_cast<char*>(&block_id);
|
||||
v8::Local<v8::Value> returnValue = Nan::CopyBuffer(cstr, 32).ToLocalChecked();
|
||||
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());
|
||||
|
||||
|
||||
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue