Compare commits

...

10 Commits

Author SHA1 Message Date
clintar 0ac3c3c532 since BLOCK_MAJOR_VERSION_2 is the same after xmr hardfork, create a
different function for fantomcoin for now.
2016-03-23 16:46:36 -06:00
clintar 0c76cc8bff lost convert_blob_lui export during merge pt 2 2015-11-18 11:33:18 -07:00
clintar f3ce82dd5e lost convert_blob_lui export during merge 2015-11-18 11:29:50 -07:00
clintar c0b991d505 Merge origin/Nan-2.0 into lui_support
Conflicts:
	package.json
	src/main.cc
2015-11-18 11:14:28 -07:00
clintar 54f5563ebb make compatible with standard node-cryptonote-pool 2015-11-17 23:26:36 -07:00
clintar 0ac11dca8b use copybuffer 2015-11-12 13:42:40 -07:00
clintar da133cd384 updates for Nan 2.x 2015-11-11 19:24:47 -07:00
clintar 4bdd09f0e9 Nan 2.0 changed api. Set required Nan version to 1 2015-08-19 00:11:34 -06:00
clintar 626049b715 fixing v0.12 problem caused by bad copy/paste 2015-07-09 14:59:46 -06:00
clintar 0ade460299 initial lui support 2015-07-09 14:53:10 -06:00
7 changed files with 615 additions and 82 deletions

View File

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

View File

@ -0,0 +1,7 @@
// Copyright (c) 2012-2013 The Boolberry developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#define CURRENCY_BLOCK_FLAG_POS_BLOCK 0x01

View File

@ -24,10 +24,28 @@
#include "crypto/hash.h"
#include "misc_language.h"
#include "tx_extra.h"
#include "block_flags.h"
namespace cryptonote
{
/************************************************************************/
/* */
/************************************************************************/
struct account_public_address
{
crypto::public_key m_spend_public_key;
crypto::public_key m_view_public_key;
BEGIN_SERIALIZE_OBJECT()
FIELD(m_spend_public_key)
FIELD(m_view_public_key)
END_SERIALIZE()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_public_key)
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_public_key)
END_KV_SERIALIZE_MAP()
};
struct block;
class transaction;
struct tx_extra_merge_mining_tag;
@ -75,6 +93,14 @@ namespace cryptonote
crypto::public_key key;
uint8_t mix_attr;
};
struct lui_txout_to_key
{
lui_txout_to_key() { }
lui_txout_to_key(const crypto::public_key &_key) : key(_key) { }
crypto::public_key key;
uint8_t mix_attr;
};
#pragma pack(pop)
@ -135,6 +161,7 @@ namespace cryptonote
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key> txout_target_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, bb_txout_to_key> bb_txout_target_v;
typedef boost::variant<txout_to_script, txout_to_scripthash, lui_txout_to_key> lui_txout_target_v;
//typedef std::pair<uint64_t, txout> out_t;
struct tx_out
@ -157,6 +184,16 @@ namespace cryptonote
FIELD(target)
END_SERIALIZE()
};
struct lui_tx_out
{
uint64_t amount;
lui_txout_target_v target;
BEGIN_SERIALIZE_OBJECT()
VARINT_FIELD(amount)
FIELD(target)
END_SERIALIZE()
};
class transaction_prefix
{
@ -274,6 +311,189 @@ namespace cryptonote
static size_t get_signature_size(const txin_v& tx_in);
};
#define OFFER_TYPE_LUI_TO_ETC 0
#define OFFER_TYPE_ETC_TO_LUI 1
/************************************************************************/
/* attachment structures */
/************************************************************************/
struct offer_details
{
uint8_t offer_type;
uint64_t amount_lui; //amount of lui
uint64_t amount_etc; //amount of other currency or goods
std::string bonus; //
std::string target; //[max 30 characters] currency / goods
std::string location_country; //US
std::string location_city; //ChIJD7fiBh9u5kcRYJSMaMOCCwQ (google geo-autocomplete id)
std::string contacts; //[max 140 characters] (Skype, mail, ICQ, etc., website)
std::string comment; //[max 160 characters]
std::string payment_types; //[max 20 characters ]money accept type(bank transaction, internet money, cash, etc)
uint8_t expiration_time; //n-days
BEGIN_SERIALIZE_OBJECT()
VALUE(offer_type)
VARINT_FIELD(amount_lui)
VARINT_FIELD(amount_etc)
VALUE(bonus)
VALUE(target)
VALUE(location_country)
VALUE(location_city)
VALUE(contacts)
VALUE(comment)
VALUE(payment_types)
VALUE(expiration_time)
END_SERIALIZE()
};
/************************************************************************/
/* attachment structures */
/************************************************************************/
struct cancel_offer
{
crypto::hash tx_id;
uint64_t offer_index;
crypto::signature sig; //tx_id signed by transaction secrete key
BEGIN_SERIALIZE_OBJECT()
VALUE(tx_id)
VALUE(offer_index)
VALUE(sig)
END_SERIALIZE()
};
struct tx_comment
{
std::string comment;
BEGIN_SERIALIZE()
FIELD(comment)
END_SERIALIZE()
};
struct tx_payer
{
account_public_address acc_addr;
BEGIN_SERIALIZE()
FIELD(acc_addr)
END_SERIALIZE()
};
struct tx_crypto_checksum
{
uint32_t summ;
BEGIN_SERIALIZE()
FIELD(summ)
END_SERIALIZE()
};
struct tx_message
{
std::string msg;
BEGIN_SERIALIZE()
FIELD(msg)
END_SERIALIZE()
};
typedef boost::variant<offer_details, tx_comment, tx_payer, tx_crypto_checksum, tx_message, std::string, cancel_offer> attachment_v;
/************************************************************************/
/* extra structures */
/************************************************************************/
struct extra_attachment_info
{
uint64_t sz;
crypto::hash hsh;
BEGIN_SERIALIZE()
VARINT_FIELD(sz)
FIELD(hsh)
END_SERIALIZE()
};
struct extra_user_data
{
std::string buff;
BEGIN_SERIALIZE()
FIELD(buff)
END_SERIALIZE()
};
struct extra_alias_entry
{
std::vector<uint8_t> buff; //manual parse
BEGIN_SERIALIZE()
FIELD(buff)
END_SERIALIZE()
};
struct extra_padding
{
std::vector<uint8_t> buff; //stub
BEGIN_SERIALIZE()
FIELD(buff)
END_SERIALIZE()
};
typedef boost::variant<crypto::public_key, extra_attachment_info, extra_alias_entry, extra_user_data, extra_padding> extra_v;
class lui_transaction_prefix
{
public:
// tx information
size_t version;
uint64_t unlock_time; //number of block (or time), used as a limitation like: spend this tx not early then block/time
std::vector<txin_v> vin;
std::vector<lui_tx_out> vout;
//extra
std::vector<extra_v> extra;
BEGIN_SERIALIZE()
VARINT_FIELD(version)
VARINT_FIELD(unlock_time)
FIELD(vin)
FIELD(vout)
FIELD(extra)
END_SERIALIZE()
protected:
lui_transaction_prefix(){}
};
class lui_transaction: public lui_transaction_prefix
{
public:
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
std::vector<attachment_v> attachment;
lui_transaction();
//virtual ~transaction();
//void set_null();
BEGIN_SERIALIZE_OBJECT()
FIELDS(*static_cast<lui_transaction_prefix *>(this))
FIELD(signatures)
FIELD(attachment)
END_SERIALIZE()
static size_t get_signature_size(const txin_v& tx_in);
};
inline
transaction::transaction()
@ -349,6 +569,49 @@ namespace cryptonote
return boost::apply_visitor(txin_signature_size_visitor(), tx_in);
}
inline
lui_transaction::lui_transaction()
{
version = 0;
unlock_time = 0;
vin.clear();
vout.clear();
extra.clear();
signatures.clear();
attachment.clear();
}
/*
inline
transaction::~transaction()
{
//set_null();
}
inline
void transaction::set_null()
{
version = 0;
unlock_time = 0;
vin.clear();
vout.clear();
extra.clear();
signatures.clear();
}
*/
inline
size_t lui_transaction::get_signature_size(const txin_v& tx_in)
{
struct txin_signature_size_visitor : public boost::static_visitor<size_t>
{
size_t operator()(const txin_gen& /*txin*/) const{return 0;}
size_t operator()(const txin_to_script& /*txin*/) const{return 0;}
size_t operator()(const txin_to_scripthash& /*txin*/) const{return 0;}
size_t operator()(const txin_to_key& txin) const {return txin.key_offsets.size();}
};
return boost::apply_visitor(txin_signature_size_visitor(), tx_in);
}
/************************************************************************/
@ -527,26 +790,45 @@ namespace cryptonote
END_SERIALIZE()
};
/************************************************************************/
/* */
/************************************************************************/
struct account_public_address
struct lui_block_header
{
crypto::public_key m_spend_public_key;
crypto::public_key m_view_public_key;
uint8_t major_version;
uint8_t minor_version;
uint64_t timestamp;
crypto::hash prev_id;
uint64_t nonce;
uint8_t flags;
BEGIN_SERIALIZE_OBJECT()
FIELD(m_spend_public_key)
FIELD(m_view_public_key)
BEGIN_SERIALIZE()
FIELD(major_version)
if(major_version > CURRENT_BLOCK_MAJOR_VERSION) return false;
FIELD(nonce)
FIELD(prev_id)
VARINT_FIELD(minor_version)
VARINT_FIELD(timestamp)
FIELD(flags)
END_SERIALIZE()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_spend_public_key)
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(m_view_public_key)
END_KV_SERIALIZE_MAP()
};
struct lui_block: public lui_block_header
{
lui_transaction miner_tx;
std::vector<crypto::hash> tx_hashes;
crypto::signature pos_sig;
BEGIN_SERIALIZE_OBJECT()
FIELDS(*static_cast<lui_block_header *>(this))
FIELD(miner_tx)
FIELD(tx_hashes)
if (this->flags&CURRENCY_BLOCK_FLAG_POS_BLOCK)
{
FIELD(pos_sig)
}
END_SERIALIZE()
};
struct keypair
{
crypto::public_key pub;
@ -560,11 +842,79 @@ namespace cryptonote
}
};
//---------------------------------------------------------------
//PoS
//based from ppcoin/novacoin approach
/*
POS PROTOCOL, stake modifier
*/
struct offer_details_ex : public cryptonote::offer_details
{
std::string tx_hash;
uint64_t index_in_tx;
uint64_t timestamp; //this is not kept by transaction, info filled by corresponding transaction
uint64_t fee; //value of fee to pay(or paid in case of existing offers) to rank it
bool stopped; //value of fee to pay(or paid in case of existing offers) to rank it
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(offer_type)
KV_SERIALIZE(amount_lui)
KV_SERIALIZE(amount_etc)
KV_SERIALIZE(bonus)
KV_SERIALIZE(target)
KV_SERIALIZE(location_country)
KV_SERIALIZE(location_city)
KV_SERIALIZE(contacts)
KV_SERIALIZE(comment)
KV_SERIALIZE(payment_types)
KV_SERIALIZE(expiration_time)
KV_SERIALIZE(tx_hash)
KV_SERIALIZE(index_in_tx)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(fee)
END_KV_SERIALIZE_MAP()
};
#pragma pack(push, 1)
struct stake_modifier_type
{
crypto::hash last_pow_id;
crypto::hash last_pos_kernel_id;
};
struct stake_kernel
{
stake_modifier_type stake_modifier;
uint64_t block_timestamp; //this block timestamp
crypto::key_image kimage;
};
#pragma pack(pop)
struct pos_entry
{
uint64_t amount;
uint64_t index;
crypto::key_image keyimage;
uint64_t block_timestamp;
//not for serialization
uint64_t wallet_index;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount)
KV_SERIALIZE(index)
KV_SERIALIZE(block_timestamp)
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(keyimage)
END_KV_SERIALIZE_MAP()
};
}
BLOB_SERIALIZER(cryptonote::txout_to_key);
BLOB_SERIALIZER(cryptonote::bb_txout_to_key);
BLOB_SERIALIZER(cryptonote::lui_txout_to_key);
BLOB_SERIALIZER(cryptonote::txout_to_scripthash);
VARIANT_TAG(binary_archive, cryptonote::txin_gen, 0xff);
@ -575,9 +925,27 @@ VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0);
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::bb_txout_to_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::lui_txout_to_key, 0x2);
VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc);
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);
VARIANT_TAG(binary_archive, cryptonote::offer_details, 0x0);
VARIANT_TAG(binary_archive, cryptonote::tx_comment, 0x1);
VARIANT_TAG(binary_archive, cryptonote::tx_payer, 0x2);
VARIANT_TAG(binary_archive, std::string, 0x3);
VARIANT_TAG(binary_archive, cryptonote::tx_crypto_checksum, 0x4);
VARIANT_TAG(binary_archive, cryptonote::tx_message, 0x5);
VARIANT_TAG(binary_archive, cryptonote::cancel_offer, 0x6);
VARIANT_TAG(binary_archive, cryptonote::extra_attachment_info, 0x0);
VARIANT_TAG(binary_archive, cryptonote::extra_user_data, 0x1);
VARIANT_TAG(binary_archive, cryptonote::extra_alias_entry, 0x2);
VARIANT_TAG(binary_archive, cryptonote::extra_padding, 0x3);
VARIANT_TAG(binary_archive, crypto::public_key, 0x4);
VARIANT_TAG(json_archive, cryptonote::txin_gen, "gen");
VARIANT_TAG(json_archive, cryptonote::txin_to_script, "script");
VARIANT_TAG(json_archive, cryptonote::txin_to_scripthash, "scripthash");
@ -586,9 +954,27 @@ VARIANT_TAG(json_archive, cryptonote::txout_to_script, "script");
VARIANT_TAG(json_archive, cryptonote::txout_to_scripthash, "scripthash");
VARIANT_TAG(json_archive, cryptonote::txout_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::bb_txout_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::lui_txout_to_key, "key");
VARIANT_TAG(json_archive, cryptonote::transaction, "tx");
VARIANT_TAG(json_archive, cryptonote::block, "block");
VARIANT_TAG(json_archive, cryptonote::offer_details, "offer");
VARIANT_TAG(json_archive, cryptonote::tx_comment, "comment");
VARIANT_TAG(json_archive, cryptonote::tx_payer, "payer");
VARIANT_TAG(json_archive, std::string, "string");
VARIANT_TAG(json_archive, crypto::public_key, "pub_key");
VARIANT_TAG(json_archive, cryptonote::tx_crypto_checksum, "check_summ");
VARIANT_TAG(json_archive, cryptonote::tx_message, "message");
VARIANT_TAG(json_archive, cryptonote::cancel_offer, "canscel_offer");
VARIANT_TAG(json_archive, cryptonote::extra_attachment_info, "attachment");
VARIANT_TAG(json_archive, cryptonote::extra_user_data, "user_data");
VARIANT_TAG(json_archive, cryptonote::extra_alias_entry, "alias");
VARIANT_TAG(json_archive, cryptonote::extra_padding, "padding");
VARIANT_TAG(debug_archive, cryptonote::txin_gen, "gen");
VARIANT_TAG(debug_archive, cryptonote::txin_to_script, "script");
VARIANT_TAG(debug_archive, cryptonote::txin_to_scripthash, "scripthash");
@ -597,5 +983,20 @@ VARIANT_TAG(debug_archive, cryptonote::txout_to_script, "script");
VARIANT_TAG(debug_archive, cryptonote::txout_to_scripthash, "scripthash");
VARIANT_TAG(debug_archive, cryptonote::txout_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::bb_txout_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::lui_txout_to_key, "key");
VARIANT_TAG(debug_archive, cryptonote::transaction, "tx");
VARIANT_TAG(debug_archive, cryptonote::block, "block");
VARIANT_TAG(debug_archive, cryptonote::offer_details, "offer");
VARIANT_TAG(debug_archive, cryptonote::tx_comment, "comment");
VARIANT_TAG(debug_archive, cryptonote::tx_payer, "payer");
VARIANT_TAG(debug_archive, std::string, "string");
//VARIANT_TAG(debug_archive, crypto::public_key, "pub_key");
VARIANT_TAG(debug_archive, cryptonote::extra_attachment_info, "attachment");
VARIANT_TAG(debug_archive, cryptonote::extra_user_data, "user_data");
VARIANT_TAG(debug_archive, cryptonote::extra_alias_entry, "alias");
VARIANT_TAG(debug_archive, cryptonote::extra_padding, "padding");
VARIANT_TAG(debug_archive, cryptonote::cancel_offer, "cancel_offer");

View File

@ -75,7 +75,14 @@ namespace boost
a & x.key;
a & x.mix_attr;
}
template <class Archive>
inline void serialize(Archive &a, cryptonote::lui_txout_to_key &x, const boost::serialization::version_type ver)
{
a & x.key;
a & x.mix_attr;
}
template <class Archive>
inline void serialize(Archive &a, cryptonote::txout_to_scripthash &x, const boost::serialization::version_type ver)
{

View File

@ -613,6 +613,13 @@ namespace cryptonote
return get_object_hash(static_cast<const bb_transaction_prefix&>(t), res, blob_size);
}
//---------------------------------------------------------------
bool get_transaction_hash(const lui_transaction& t, crypto::hash& res)
{
size_t blob_size = 0;
return get_object_hash(static_cast<const lui_transaction_prefix&>(t), res, blob_size);
}
//---------------------------------------------------------------
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t& blob_size)
{
@ -643,6 +650,14 @@ namespace cryptonote
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
return blob;
}
blobdata get_block_hashing_blob(const lui_block& b)
{
blobdata blob = t_serializable_object_to_blob(static_cast<lui_block_header>(b));
crypto::hash tree_root_hash = get_tx_tree_hash(b);
blob.append((const char*)&tree_root_hash, sizeof(tree_root_hash ));
blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
return blob;
}
//---------------------------------------------------------------
bool get_block_hash(const block& b, crypto::hash& res)
{
@ -786,6 +801,16 @@ namespace cryptonote
return true;
}
bool parse_and_validate_block_from_blob(const blobdata& b_blob, bb_block& b)
{
std::stringstream ss;
ss << b_blob;
binary_archive<false> ba(ss);
bool r = ::serialization::serialize(ba, b);
CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob");
return true;
}
//---------------------------------------------------------------
bool parse_and_validate_block_from_blob(const blobdata& b_blob, lui_block& b)
{
std::stringstream ss;
ss << b_blob;
@ -839,6 +864,17 @@ namespace cryptonote
return get_tx_tree_hash(txs_ids);
}
crypto::hash get_tx_tree_hash(const bb_block& b)
{
std::vector<crypto::hash> txs_ids;
crypto::hash h = null_hash;
get_transaction_hash(b.miner_tx, h);
txs_ids.push_back(h);
BOOST_FOREACH(auto& th, b.tx_hashes)
txs_ids.push_back(th);
return get_tx_tree_hash(txs_ids);
}
//---------------------------------------------------------------
crypto::hash get_tx_tree_hash(const lui_block& b)
{
std::vector<crypto::hash> txs_ids;
crypto::hash h = null_hash;

View File

@ -80,6 +80,7 @@ namespace cryptonote
bool get_block_hashing_blob(const block& b, blobdata& blob);
bool get_bytecoin_block_hashing_blob(const block& b, blobdata& blob);
blobdata get_block_hashing_blob(const bb_block& b);
blobdata get_block_hashing_blob(const lui_block& b);
bool get_block_hash(const block& b, crypto::hash& res);
crypto::hash get_block_hash(const block& b);
bool get_block_header_hash(const block& b, crypto::hash& res);
@ -90,6 +91,7 @@ namespace cryptonote
bool get_genesis_block_hash(crypto::hash& h);
bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b);
bool parse_and_validate_block_from_blob(const blobdata& b_blob, bb_block& b);
bool parse_and_validate_block_from_blob(const blobdata& b_blob, lui_block& b);
bool get_inputs_money_amount(const transaction& tx, uint64_t& money);
uint64_t get_outs_money_amount(const transaction& tx);
bool check_inputs_types_supported(const transaction& tx);
@ -205,6 +207,7 @@ namespace cryptonote
crypto::hash get_tx_tree_hash(const std::vector<crypto::hash>& tx_hashes);
crypto::hash get_tx_tree_hash(const block& b);
crypto::hash get_tx_tree_hash(const bb_block& b);
crypto::hash get_tx_tree_hash(const lui_block& b);
bool check_proof_of_work_v1(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);

View File

@ -14,9 +14,12 @@
#include "serialization/binary_utils.h"
#include <nan.h>
#define THROW_ERROR_EXCEPTION(x) NanThrowError(x)
#define THROW_ERROR_EXCEPTION_WITH_STATUS_CODE(x, y) NanThrowError(x, y)
#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x)
void callback(char* data, void* hint) {
free(data);
}
using namespace node;
using namespace v8;
using namespace cryptonote;
@ -78,12 +81,38 @@ static bool construct_parent_block(const cryptonote::block& b, cryptonote::block
}
NAN_METHOD(convert_blob) {
NanScope();
if (args.Length() < 1)
if (info.Length() < 1)
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))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = "";
//convert
block b = AUTO_VAL_INIT(b);
if (!parse_and_validate_block_from_blob(input, b))
return THROW_ERROR_EXCEPTION("Failed to parse block");
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
);
}
NAN_METHOD(convert_blob_fa) {
if (info.Length() < 1)
return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = info[0]->ToObject();
if (!Buffer::HasInstance(target))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
@ -107,19 +136,24 @@ NAN_METHOD(convert_blob) {
if (!get_block_hashing_blob(parent_block, output))
return THROW_ERROR_EXCEPTION("Failed to create mining block");
}
NanReturnValue(
NanNewBufferHandle(output.data(), output.size())
// Local<Object> v8::Local<v8::Value> returnValue = Nan::NewBuffer(output.length()).ToLocalChecked();
// memcpy(Buffer::Data(returnValue), output.c_str(), output.length());
// info.GetReturnValue().Set(
// returnValue
// );
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
}
NAN_METHOD(get_block_id) {
NanScope();
void get_block_id(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (args.Length() < 1)
if (info.Length() < 1)
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))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
@ -134,20 +168,21 @@ NAN_METHOD(get_block_id) {
crypto::hash block_id;
if (!get_block_hash(b, block_id))
return THROW_ERROR_EXCEPTION("Failed to calculate hash for block");
NanReturnValue(
NanNewBufferHandle(reinterpret_cast<char*>(&block_id), sizeof(block_id))
char *cstr = reinterpret_cast<char*>(&block_id);
v8::Local<v8::Value> returnValue = Nan::CopyBuffer(cstr, 32).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
}
NAN_METHOD(construct_block_blob) {
NanScope();
void construct_block_blob(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (args.Length() < 2)
if (info.Length() < 2)
return THROW_ERROR_EXCEPTION("You must provide two arguments.");
Local<Object> block_template_buf = args[0]->ToObject();
Local<Object> nonce_buf = args[1]->ToObject();
Local<Object> block_template_buf = info[0]->ToObject();
Local<Object> nonce_buf = info[1]->ToObject();
if (!Buffer::HasInstance(block_template_buf) || !Buffer::HasInstance(nonce_buf))
return THROW_ERROR_EXCEPTION("Both arguments should be buffer objects.");
@ -178,18 +213,18 @@ NAN_METHOD(construct_block_blob) {
if (!block_to_blob(b, output))
return THROW_ERROR_EXCEPTION("Failed to convert block to blob");
NanReturnValue(
NanNewBufferHandle(output.data(), output.size())
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
}
NAN_METHOD(convert_blob_bb) {
NanScope();
void convert_blob_bb(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (args.Length() < 1)
if (info.Length() < 1)
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))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
@ -204,18 +239,44 @@ NAN_METHOD(convert_blob_bb) {
}
output = get_block_hashing_blob(b);
NanReturnValue(
NanNewBufferHandle(output.data(), output.size())
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
}
NAN_METHOD(address_decode) {
NanEscapableScope();
void convert_blob_lui (const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (args.Length() < 1)
if (info.Length() < 1)
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))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
blobdata output = "";
//convert
lui_block b = AUTO_VAL_INIT(b);
if (!parse_and_validate_block_from_blob(input, b)) {
return THROW_ERROR_EXCEPTION("Failed to parse block");
}
output = get_block_hashing_blob(b);
v8::Local<v8::Value> returnValue = Nan::CopyBuffer((char*)output.data(), output.size()).ToLocalChecked();
info.GetReturnValue().Set(
returnValue
);
}
void address_decode(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() < 1)
return THROW_ERROR_EXCEPTION("You must provide one argument.");
Local<Object> target = info[0]->ToObject();
if (!Buffer::HasInstance(target))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
@ -225,24 +286,42 @@ NAN_METHOD(address_decode) {
blobdata data;
uint64_t prefix;
if (!tools::base58::decode_addr(input, prefix, data))
NanReturnUndefined();
{
info.GetReturnValue().Set(Nan::Undefined());
}
// info.GetReturnValue().Set(Nan::Undefined());
account_public_address adr;
if (!::serialization::parse_binary(data, adr))
NanReturnUndefined();
if (!::serialization::parse_binary(data, adr) || !crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key))
{
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))
NanReturnUndefined();
NanReturnValue(NanNew(static_cast<uint32_t>(prefix)));
}
else
{
info.GetReturnValue().Set(Nan::New(static_cast<uint32_t>(prefix)));
}
}
void init(Handle<Object> exports) {
exports->Set(NanNew<String>("construct_block_blob"), NanNew<FunctionTemplate>(construct_block_blob)->GetFunction());
exports->Set(NanNew<String>("get_block_id"), NanNew<FunctionTemplate>(get_block_id)->GetFunction());
exports->Set(NanNew<String>("convert_blob"), NanNew<FunctionTemplate>(convert_blob)->GetFunction());
exports->Set(NanNew<String>("convert_blob_bb"), NanNew<FunctionTemplate>(convert_blob_bb)->GetFunction());
exports->Set(NanNew<String>("address_decode"), NanNew<FunctionTemplate>(address_decode)->GetFunction());
NAN_MODULE_INIT(init) {
Nan::Set(target, Nan::New("construct_block_blob").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(construct_block_blob)).ToLocalChecked());
Nan::Set(target, Nan::New("get_block_id").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(get_block_id)).ToLocalChecked());
Nan::Set(target, Nan::New("convert_blob").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(convert_blob)).ToLocalChecked());
Nan::Set(target, Nan::New("convert_blob_bb").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(convert_blob_bb)).ToLocalChecked());
Nan::Set(target, Nan::New("convert_blob_lui").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(convert_blob_lui)).ToLocalChecked());
Nan::Set(target, Nan::New("address_decode").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(address_decode)).ToLocalChecked());
}
NODE_MODULE(cryptonote, init)