Compare commits

...

9 Commits
master ... bcn

Author SHA1 Message Date
Harald Wolff 3f2b2ce73a fixed rs_comm() bug with new compiler versions 2017-09-13 23:33:33 +02:00
Harald Wolff 48ac60139f Fix old except(..) to THROW_ERROR_EXCEPTION(..) 2017-09-13 23:31:57 +02:00
clintar 594ecbaf33 make compatible with standard node-cryptonote-pool 2017-09-13 23:29:55 +02:00
clintar 7551044f8a use copybuffer 2017-09-13 23:29:38 +02:00
clintar 25db84cdf0 updates for Nan 2.x 2017-09-13 23:29:24 +02:00
clintar 4e798b9025 Nan 2.0 changed api. Set required Nan version to 1 2017-09-13 23:28:34 +02:00
clintar 9e81febac8 Initial commit of changes to get this to build using nan. Not sure what I'm doing, though. Not tested 2017-09-13 23:27:57 +02:00
Petar Mitchev 1138e27ea3 Because fuck logic 2016-04-22 06:20:17 +03:00
Petar Mitchev e5ac040561 Attempt 2 2016-04-21 19:14:04 +03:00
8 changed files with 134 additions and 91 deletions

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/nbproject/

View File

@ -16,6 +16,7 @@
"include_dirs": [ "include_dirs": [
"src", "src",
"src/contrib/epee/include", "src/contrib/epee/include",
"<!(node -e \"require('nan')\")",
], ],
"link_settings": { "link_settings": {
"libraries": [ "libraries": [

View File

@ -1,20 +1,21 @@
{ {
"name": "cryptonote-util", "name": "cryptonote-util",
"version": "0.0.1", "version": "0.0.1",
"main": "cryptonote", "main": "cryptonote",
"author": { "author": {
"name": "LucasJones", "name": "LucasJones",
"email": "lucasjonesdev@hotmail.co.uk" "email": "lucasjonesdev@hotmail.co.uk"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/LucasJones/node-cryptonote-util.git" "url": "https://github.com/clintar/node-cryptonote-util.git"
}, },
"dependencies" : { "dependencies": {
"bindings" : "*" "bindings": "*",
}, "nan": "^2.0.0"
"keywords": [ },
"cryptonight", "keywords": [
"cryptonote" "cryptonight",
] "cryptonote"
]
} }

View File

@ -221,7 +221,7 @@ DISABLE_VS_WARNINGS(4200)
POP_WARNINGS POP_WARNINGS
static inline size_t rs_comm_size(size_t pubs_count) { static inline size_t rs_comm_size(size_t pubs_count) {
return sizeof(rs_comm) + pubs_count * sizeof(rs_comm().ab[0]); return sizeof(rs_comm) + pubs_count * sizeof(((rs_comm*)0)->ab[0]);
} }
void crypto_ops::generate_ring_signature(const hash &prefix_hash, const key_image &image, void crypto_ops::generate_ring_signature(const hash &prefix_hash, const key_image &image,

View File

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

View File

@ -456,7 +456,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)
if (BLOCK_MAJOR_VERSION_1 == major_version) if (BLOCK_MAJOR_VERSION_1 == major_version)
{ {

View File

@ -860,7 +860,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))
@ -900,6 +900,7 @@ namespace cryptonote
{ {
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_v2(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);

View File

@ -12,15 +12,18 @@
#include "crypto/hash.h" #include "crypto/hash.h"
#include "common/base58.h" #include "common/base58.h"
#include "serialization/binary_utils.h" #include "serialization/binary_utils.h"
#include <nan.h>
#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x)
void callback(char* data, void* hint) {
free(data);
}
using namespace node; using namespace node;
using namespace v8; using namespace v8;
using namespace cryptonote; using namespace cryptonote;
Handle<Value> except(const char* msg) {
return ThrowException(Exception::Error(String::New(msg)));
}
blobdata uint64be_to_blob(uint64_t num) { blobdata uint64be_to_blob(uint64_t num) {
blobdata res = " "; blobdata res = " ";
res[0] = num >> 56 & 0xff; res[0] = num >> 56 & 0xff;
@ -77,16 +80,15 @@ static bool construct_parent_block(const cryptonote::block& b, cryptonote::block
return fillExtra(parent_block, b); return fillExtra(parent_block, b);
} }
Handle<Value> convert_blob(const Arguments& args) { NAN_METHOD(convert_blob) {
HandleScope scope;
if (args.Length() < 1) if (info.Length() < 1)
return except("You must provide one argument."); return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = args[0]->ToObject(); Local<Object> target = info[0]->ToObject();
if (!Buffer::HasInstance(target)) if (!Buffer::HasInstance(target))
return except("Argument should be a buffer object."); return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = ""; blobdata output = "";
@ -94,64 +96,72 @@ Handle<Value> convert_blob(const Arguments& args) {
//convert //convert
block b = AUTO_VAL_INIT(b); block b = AUTO_VAL_INIT(b);
if (!parse_and_validate_block_from_blob(input, b)) if (!parse_and_validate_block_from_blob(input, b))
return except("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_2) {
if (!get_block_hashing_blob(b, output)) if (!get_block_hashing_blob(b, output))
return except("Failed to create mining block"); return THROW_ERROR_EXCEPTION("Failed to create mining block");
} else { } else {
block parent_block; block parent_block;
if (!construct_parent_block(b, parent_block)) if (!construct_parent_block(b, parent_block))
return except("Failed to construct parent block"); return THROW_ERROR_EXCEPTION("Failed to construct parent block");
if (!get_block_hashing_blob(parent_block, output)) if (!get_block_hashing_blob(parent_block, output))
return except("Failed to create mining block"); return THROW_ERROR_EXCEPTION("Failed to create mining block");
} }
// Local<Object> v8::Local<v8::Value> returnValue = Nan::NewBuffer(output.length()).ToLocalChecked();
Buffer* buff = Buffer::New(output.data(), output.size()); // memcpy(Buffer::Data(returnValue), output.c_str(), output.length());
return scope.Close(buff->handle_); // info.GetReturnValue().Set(
// returnValue
// );
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
} }
Handle<Value> get_block_id(const Arguments& args) { void get_block_id(const Nan::FunctionCallbackInfo<v8::Value>& info) {
HandleScope scope;
if (args.Length() < 1) if (info.Length() < 1)
return except("You must provide one argument."); return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = args[0]->ToObject(); Local<Object> target = info[0]->ToObject();
if (!Buffer::HasInstance(target)) if (!Buffer::HasInstance(target))
return except("Argument should be a buffer object."); return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = ""; blobdata output = "";
block b = AUTO_VAL_INIT(b); block b = AUTO_VAL_INIT(b);
if (!parse_and_validate_block_from_blob(input, b)) if (!parse_and_validate_block_from_blob(input, b))
return except("Failed to parse block"); return THROW_ERROR_EXCEPTION("Failed to parse block");
crypto::hash block_id; crypto::hash block_id;
if (!get_block_hash(b, block_id)) if (!get_block_hash(b, block_id))
return except("Failed to calculate hash for block"); return THROW_ERROR_EXCEPTION("Failed to calculate hash for block");
Buffer* buff = Buffer::New(reinterpret_cast<char*>(&block_id), sizeof(block_id)); char *cstr = reinterpret_cast<char*>(&block_id);
return scope.Close(buff->handle_); v8::Local<v8::Value> returnValue = Nan::CopyBuffer(cstr, 32).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
} }
Handle<Value> construct_block_blob(const Arguments& args) { void construct_block_blob(const Nan::FunctionCallbackInfo<v8::Value>& info) {
HandleScope scope;
if (args.Length() < 2) if (info.Length() < 2)
return except("You must provide two arguments."); return THROW_ERROR_EXCEPTION("You must provide two arguments.");
Local<Object> block_template_buf = args[0]->ToObject(); Local<Object> block_template_buf = info[0]->ToObject();
Local<Object> nonce_buf = args[1]->ToObject(); Local<Object> nonce_buf = info[1]->ToObject();
if (!Buffer::HasInstance(block_template_buf) || !Buffer::HasInstance(nonce_buf)) if (!Buffer::HasInstance(block_template_buf) || !Buffer::HasInstance(nonce_buf))
return except("Both arguments should be buffer objects."); return THROW_ERROR_EXCEPTION("Both arguments should be buffer objects.");
if (Buffer::Length(nonce_buf) != 4) if (Buffer::Length(nonce_buf) != 4)
return except("Nonce buffer has invalid size."); return THROW_ERROR_EXCEPTION("Nonce buffer has invalid size.");
uint32_t nonce = *reinterpret_cast<uint32_t*>(Buffer::Data(nonce_buf)); uint32_t nonce = *reinterpret_cast<uint32_t*>(Buffer::Data(nonce_buf));
@ -160,36 +170,46 @@ Handle<Value> construct_block_blob(const Arguments& args) {
block b = AUTO_VAL_INIT(b); block b = AUTO_VAL_INIT(b);
if (!parse_and_validate_block_from_blob(block_template_blob, b)) if (!parse_and_validate_block_from_blob(block_template_blob, b))
return except("Failed to parse block"); return THROW_ERROR_EXCEPTION("Failed to parse block");
b.nonce = nonce; b.nonce = nonce;
if (b.major_version == BLOCK_MAJOR_VERSION_2) { if (b.major_version == BLOCK_MAJOR_VERSION_2) {
block parent_block; block parent_block;
b.parent_block.nonce = nonce; b.parent_block.nonce = nonce;
if (!construct_parent_block(b, parent_block)) if (!construct_parent_block(b, parent_block))
return except("Failed to construct parent block"); return THROW_ERROR_EXCEPTION("Failed to construct parent block");
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>())) if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
return except("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 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");
} }
if (!block_to_blob(b, output)) if (!block_to_blob(b, output))
return except("Failed to convert block to blob"); return THROW_ERROR_EXCEPTION("Failed to convert block to blob");
Buffer* buff = Buffer::New(output.data(), output.size()); v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
return scope.Close(buff->handle_); info.GetReturnValue().Set(
returnValue
);
} }
Handle<Value> convert_blob_bb(const Arguments& args) { void convert_blob_bb(const Nan::FunctionCallbackInfo<v8::Value>& info) {
HandleScope scope;
if (args.Length() < 1) if (info.Length() < 1)
return except("You must provide one argument."); return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = args[0]->ToObject(); Local<Object> target = info[0]->ToObject();
if (!Buffer::HasInstance(target)) if (!Buffer::HasInstance(target))
return except("Argument should be a buffer object."); return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = ""; blobdata output = "";
@ -197,48 +217,66 @@ Handle<Value> convert_blob_bb(const Arguments& args) {
//convert //convert
bb_block b = AUTO_VAL_INIT(b); bb_block b = AUTO_VAL_INIT(b);
if (!parse_and_validate_block_from_blob(input, b)) { if (!parse_and_validate_block_from_blob(input, b)) {
return except("Failed to parse block"); return THROW_ERROR_EXCEPTION("Failed to parse block");
} }
output = get_block_hashing_blob(b); output = get_block_hashing_blob(b);
Buffer* buff = Buffer::New(output.data(), output.size()); v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
return scope.Close(buff->handle_); info.GetReturnValue().Set(
returnValue
);
} }
Handle<Value> address_decode(const Arguments& args) { void address_decode(const Nan::FunctionCallbackInfo<v8::Value>& info) {
HandleScope scope;
if (args.Length() < 1) if (info.Length() < 1)
return except("You must provide one argument."); return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = args[0]->ToObject(); Local<Object> target = info[0]->ToObject();
if (!Buffer::HasInstance(target)) if (!Buffer::HasInstance(target))
return except("Argument should be a buffer object."); return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata data; blobdata data;
uint64_t prefix; uint64_t prefix;
if (!tools::base58::decode_addr(input, prefix, data)) if (!tools::base58::decode_addr(input, prefix, data))
return scope.Close(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)) if (!::serialization::parse_binary(data, adr) || !crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
return scope.Close(Undefined()); {
if(data.length())
{
data = uint64be_to_blob(prefix) + data;
}
else
{
info.GetReturnValue().Set(Nan::Undefined());
}
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)data.data(), data.size()).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
if (!crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key)) }
return scope.Close(Undefined()); else
{
return scope.Close(Integer::New(static_cast<uint32_t>(prefix))); info.GetReturnValue().Set(Nan::New(static_cast<uint32_t>(prefix)));
}
} }
void init(Handle<Object> exports) { NAN_MODULE_INIT(init) {
exports->Set(String::NewSymbol("construct_block_blob"), FunctionTemplate::New(construct_block_blob)->GetFunction()); Nan::Set(target, Nan::New("construct_block_blob").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(construct_block_blob)).ToLocalChecked());
exports->Set(String::NewSymbol("get_block_id"), FunctionTemplate::New(get_block_id)->GetFunction()); Nan::Set(target, Nan::New("get_block_id").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(get_block_id)).ToLocalChecked());
exports->Set(String::NewSymbol("convert_blob"), FunctionTemplate::New(convert_blob)->GetFunction()); Nan::Set(target, Nan::New("convert_blob").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(convert_blob)).ToLocalChecked());
exports->Set(String::NewSymbol("convert_blob_bb"), FunctionTemplate::New(convert_blob_bb)->GetFunction()); Nan::Set(target, Nan::New("convert_blob_bb").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(convert_blob_bb)).ToLocalChecked());
exports->Set(String::NewSymbol("address_decode"), FunctionTemplate::New(address_decode)->GetFunction()); Nan::Set(target, Nan::New("address_decode").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(address_decode)).ToLocalChecked());
} }
NODE_MODULE(cryptonote, init) NODE_MODULE(cryptonote, init)