From b138877e197f9391cac7e5f5f370ab7499b61289 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 25 Sep 2015 14:33:37 -0400 Subject: [PATCH 01/12] Start upgrade to Node.js 4 --- package.json | 2 +- src/libbitcoind.cc | 100 ++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index 02ff6bcd..b2bcfbf2 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "commander": "^2.8.1", "errno": "^0.1.4", "express": "^4.13.3", - "leveldown": "^1.4.1", + "leveldown": "git://github.com/Level/leveldown#86b96a823f74718f085e28086556a9697d61de84", "levelup": "^1.2.1", "liftoff": "^2.2.0", "memdown": "^1.0.0", diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index 26eb7859..c219a113 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -273,15 +273,15 @@ tx_notifier(uv_async_t *handle) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; std::string stx = ssTx.str(); - Local txBuffer = node::Buffer::New(isolate, stx.c_str(), stx.size()); + Nan::MaybeLocal txBuffer = Nan::NewBuffer((char *)stx.c_str(), stx.size()); uint256 hash = tx.GetHash(); Local obj = New(); - Set(obj, New("buffer").ToLocalChecked(), txBuffer); - Set(obj, New("hash").ToLocalChecked(), New(hash.GetHex()).ToLocalChecked()); - Set(obj, New("mempool").ToLocalChecked(), New(true)); + Nan::Set(obj, New("buffer").ToLocalChecked(), txBuffer.ToLocalChecked()); + Nan::Set(obj, New("hash").ToLocalChecked(), New(hash.GetHex()).ToLocalChecked()); + Nan::Set(obj, New("mempool").ToLocalChecked(), New(true)); results->Set(arrayIndex, obj); arrayIndex++; @@ -926,14 +926,14 @@ async_get_block_after(uv_work_t *r) { cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); } else { - Local rawNodeBuffer = node::Buffer::New(isolate, req->buffer, req->size); + Nan::MaybeLocal rawNodeBuffer = Nan::NewBuffer(req->buffer, req->size); delete req->buffer; req->buffer = NULL; Local argv[2] = { Local::New(isolate, Null()), - rawNodeBuffer + rawNodeBuffer.ToLocalChecked() }; cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); } @@ -1049,18 +1049,18 @@ async_get_tx_after(uv_work_t *r) { cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); } else { - Local result = Local::New(isolate, Null()); + Nan::MaybeLocal result = Local::New(isolate, Null()); if (!ctx.IsNull()) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << ctx; std::string stx = ssTx.str(); - result = node::Buffer::New(isolate, stx.c_str(), stx.size()); + result = Nan::NewBuffer((char *)stx.c_str(), stx.size()); } Local argv[2] = { Local::New(isolate, Null()), - result + result.ToLocalChecked() }; cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); } @@ -1195,12 +1195,12 @@ async_get_tx_and_info_after(uv_work_t *r) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << ctx; std::string stx = ssTx.str(); - Local rawNodeBuffer = node::Buffer::New(isolate, stx.c_str(), stx.size()); + Nan::MaybeLocal rawNodeBuffer = Nan::NewBuffer((char *)stx.c_str(), stx.size()); - Set(obj, New("blockHash").ToLocalChecked(), New(req->blockHash).ToLocalChecked()); - Set(obj, New("height").ToLocalChecked(), New(req->height)); - Set(obj, New("timestamp").ToLocalChecked(), New(req->nTime)); - Set(obj, New("buffer").ToLocalChecked(), rawNodeBuffer); + Nan::Set(obj, New("blockHash").ToLocalChecked(), New(req->blockHash).ToLocalChecked()); + Nan::Set(obj, New("height").ToLocalChecked(), New(req->height)); + Nan::Set(obj, New("timestamp").ToLocalChecked(), New(req->nTime)); + Nan::Set(obj, New("buffer").ToLocalChecked(), rawNodeBuffer.ToLocalChecked()); Local argv[2] = { Local::New(isolate, Null()), @@ -1290,15 +1290,15 @@ NAN_METHOD(GetBlockIndex) { CBlockIndex* prevBlockIndex = blockIndex->pprev; if (&prevBlockIndex->phashBlock != 0) { const uint256* prevHash = prevBlockIndex->phashBlock; - Set(obj, New("prevHash").ToLocalChecked(), New(prevHash->GetHex()).ToLocalChecked()); + Nan::Set(obj, New("prevHash").ToLocalChecked(), New(prevHash->GetHex()).ToLocalChecked()); } else { - Set(obj, New("prevHash").ToLocalChecked(), Null()); + Nan::Set(obj, New("prevHash").ToLocalChecked(), Null()); } - Set(obj, New("hash").ToLocalChecked(), New(blockIndex->phashBlock->GetHex()).ToLocalChecked()); - Set(obj, New("chainWork").ToLocalChecked(), New(cw.GetHex()).ToLocalChecked()); + Nan::Set(obj, New("hash").ToLocalChecked(), New(blockIndex->phashBlock->GetHex()).ToLocalChecked()); + Nan::Set(obj, New("chainWork").ToLocalChecked(), New(cw.GetHex()).ToLocalChecked()); - Set(obj, New("height").ToLocalChecked(), New(blockIndex->nHeight)); + Nan::Set(obj, New("height").ToLocalChecked(), New(blockIndex->nHeight)); info.GetReturnValue().Set(obj); }; @@ -1350,15 +1350,15 @@ NAN_METHOD(GetInfo) { proxyType proxy; GetProxy(NET_IPV4, proxy); - Set(obj, New("version").ToLocalChecked(), New(CLIENT_VERSION)); - Set(obj, New("protocolversion").ToLocalChecked(), New(PROTOCOL_VERSION)); - Set(obj, New("blocks").ToLocalChecked(), New((int)chainActive.Height())->ToInt32()); - Set(obj, New("timeoffset").ToLocalChecked(), New(GetTimeOffset())); - Set(obj, New("connections").ToLocalChecked(), New((int)vNodes.size())->ToInt32()); - Set(obj, New("difficulty").ToLocalChecked(), New((double)GetDifficulty())); - Set(obj, New("testnet").ToLocalChecked(), New(Params().NetworkIDString() == "test")); - Set(obj, New("relayfee").ToLocalChecked(), New(::minRelayTxFee.GetFeePerK())); // double - Set(obj, New("errors").ToLocalChecked(), New(GetWarnings("statusbar")).ToLocalChecked()); + Nan::Set(obj, New("version").ToLocalChecked(), New(CLIENT_VERSION)); + Nan::Set(obj, New("protocolversion").ToLocalChecked(), New(PROTOCOL_VERSION)); + Nan::Set(obj, New("blocks").ToLocalChecked(), New((int)chainActive.Height())->ToInt32()); + Nan::Set(obj, New("timeoffset").ToLocalChecked(), New(GetTimeOffset())); + Nan::Set(obj, New("connections").ToLocalChecked(), New((int)vNodes.size())->ToInt32()); + Nan::Set(obj, New("difficulty").ToLocalChecked(), New((double)GetDifficulty())); + Nan::Set(obj, New("testnet").ToLocalChecked(), New(Params().NetworkIDString() == "test")); + Nan::Set(obj, New("relayfee").ToLocalChecked(), New(::minRelayTxFee.GetFeePerK())); // double + Nan::Set(obj, New("errors").ToLocalChecked(), New(GetWarnings("statusbar")).ToLocalChecked()); info.GetReturnValue().Set(obj); } @@ -1473,8 +1473,8 @@ NAN_METHOD(GetMempoolTransactions) { CDataStream dataStreamTx(SER_NETWORK, PROTOCOL_VERSION); dataStreamTx << tx; std::string txString = dataStreamTx.str(); - Local txBuffer = node::Buffer::New(isolate, txString.c_str(), txString.size()); - transactions->Set(arrayIndex, txBuffer); + Nan::MaybeLocal txBuffer = Nan::NewBuffer((char *)txString.c_str(), txString.size()); + transactions->Set(arrayIndex, txBuffer.ToLocalChecked()); arrayIndex++; } } @@ -1523,26 +1523,26 @@ set_cooked(void) { */ NAN_MODULE_INIT(init) { - Set(target, New("start").ToLocalChecked(), GetFunction(New(StartBitcoind)).ToLocalChecked()); - Set(target, New("onBlocksReady").ToLocalChecked(), GetFunction(New(OnBlocksReady)).ToLocalChecked()); - Set(target, New("onTipUpdate").ToLocalChecked(), GetFunction(New(OnTipUpdate)).ToLocalChecked()); - Set(target, New("stop").ToLocalChecked(), GetFunction(New(StopBitcoind)).ToLocalChecked()); - Set(target, New("getBlock").ToLocalChecked(), GetFunction(New(GetBlock)).ToLocalChecked()); - Set(target, New("getTransaction").ToLocalChecked(), GetFunction(New(GetTransaction)).ToLocalChecked()); - Set(target, New("getTransactionWithBlockInfo").ToLocalChecked(), GetFunction(New(GetTransactionWithBlockInfo)).ToLocalChecked()); - Set(target, New("getInfo").ToLocalChecked(), GetFunction(New(GetInfo)).ToLocalChecked()); - Set(target, New("isSpent").ToLocalChecked(), GetFunction(New(IsSpent)).ToLocalChecked()); - Set(target, New("getBlockIndex").ToLocalChecked(), GetFunction(New(GetBlockIndex)).ToLocalChecked()); - Set(target, New("isMainChain").ToLocalChecked(), GetFunction(New(IsMainChain)).ToLocalChecked()); - Set(target, New("getMempoolTransactions").ToLocalChecked(), GetFunction(New(GetMempoolTransactions)).ToLocalChecked()); - Set(target, New("addMempoolUncheckedTransaction").ToLocalChecked(), GetFunction(New(AddMempoolUncheckedTransaction)).ToLocalChecked()); - Set(target, New("sendTransaction").ToLocalChecked(), GetFunction(New(SendTransaction)).ToLocalChecked()); - Set(target, New("estimateFee").ToLocalChecked(), GetFunction(New(EstimateFee)).ToLocalChecked()); - Set(target, New("startTxMon").ToLocalChecked(), GetFunction(New(StartTxMon)).ToLocalChecked()); - Set(target, New("syncPercentage").ToLocalChecked(), GetFunction(New(SyncPercentage)).ToLocalChecked()); - Set(target, New("isSynced").ToLocalChecked(), GetFunction(New(IsSynced)).ToLocalChecked()); - Set(target, New("getBestBlockHash").ToLocalChecked(), GetFunction(New(GetBestBlockHash)).ToLocalChecked()); - Set(target, New("getNextBlockHash").ToLocalChecked(), GetFunction(New(GetNextBlockHash)).ToLocalChecked()); + Nan::Set(target, New("start").ToLocalChecked(), GetFunction(New(StartBitcoind)).ToLocalChecked()); + Nan::Set(target, New("onBlocksReady").ToLocalChecked(), GetFunction(New(OnBlocksReady)).ToLocalChecked()); + Nan::Set(target, New("onTipUpdate").ToLocalChecked(), GetFunction(New(OnTipUpdate)).ToLocalChecked()); + Nan::Set(target, New("stop").ToLocalChecked(), GetFunction(New(StopBitcoind)).ToLocalChecked()); + Nan::Set(target, New("getBlock").ToLocalChecked(), GetFunction(New(GetBlock)).ToLocalChecked()); + Nan::Set(target, New("getTransaction").ToLocalChecked(), GetFunction(New(GetTransaction)).ToLocalChecked()); + Nan::Set(target, New("getTransactionWithBlockInfo").ToLocalChecked(), GetFunction(New(GetTransactionWithBlockInfo)).ToLocalChecked()); + Nan::Set(target, New("getInfo").ToLocalChecked(), GetFunction(New(GetInfo)).ToLocalChecked()); + Nan::Set(target, New("isSpent").ToLocalChecked(), GetFunction(New(IsSpent)).ToLocalChecked()); + Nan::Set(target, New("getBlockIndex").ToLocalChecked(), GetFunction(New(GetBlockIndex)).ToLocalChecked()); + Nan::Set(target, New("isMainChain").ToLocalChecked(), GetFunction(New(IsMainChain)).ToLocalChecked()); + Nan::Set(target, New("getMempoolTransactions").ToLocalChecked(), GetFunction(New(GetMempoolTransactions)).ToLocalChecked()); + Nan::Set(target, New("addMempoolUncheckedTransaction").ToLocalChecked(), GetFunction(New(AddMempoolUncheckedTransaction)).ToLocalChecked()); + Nan::Set(target, New("sendTransaction").ToLocalChecked(), GetFunction(New(SendTransaction)).ToLocalChecked()); + Nan::Set(target, New("estimateFee").ToLocalChecked(), GetFunction(New(EstimateFee)).ToLocalChecked()); + Nan::Set(target, New("startTxMon").ToLocalChecked(), GetFunction(New(StartTxMon)).ToLocalChecked()); + Nan::Set(target, New("syncPercentage").ToLocalChecked(), GetFunction(New(SyncPercentage)).ToLocalChecked()); + Nan::Set(target, New("isSynced").ToLocalChecked(), GetFunction(New(IsSynced)).ToLocalChecked()); + Nan::Set(target, New("getBestBlockHash").ToLocalChecked(), GetFunction(New(GetBestBlockHash)).ToLocalChecked()); + Nan::Set(target, New("getNextBlockHash").ToLocalChecked(), GetFunction(New(GetNextBlockHash)).ToLocalChecked()); } NODE_MODULE(libbitcoind, init); From 7afeef0f081ceab55e5b621f5ce8d072a44dd866 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Sat, 26 Sep 2015 04:10:05 -0400 Subject: [PATCH 02/12] Debugging, clear warnings, fixed GetBlock. --- src/libbitcoind.cc | 81 ++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index c219a113..eb6eb587 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -161,7 +161,7 @@ struct async_node_data { struct async_block_data { uv_work_t req; std::string err_msg; - std::string hash; + uint256 hash; int64_t height; char* buffer; uint32_t size; @@ -352,7 +352,7 @@ async_tip_update_after(uv_work_t *r) { HandleScope scope(isolate); Local cb = Local::New(isolate, req->callback); - TryCatch try_catch; + Nan::TryCatch try_catch; Local result = Undefined(isolate); if (!shutdown_complete) { @@ -363,11 +363,10 @@ async_tip_update_after(uv_work_t *r) { }; cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } NAN_METHOD(OnBlocksReady) { @@ -443,7 +442,7 @@ async_blocks_ready_after(uv_work_t *r) { Isolate* isolate = req->isolate; HandleScope scope(isolate); - TryCatch try_catch; + Nan::TryCatch try_catch; Local cb = Local::New(isolate, req->callback); if (req->err_msg != "") { @@ -459,11 +458,10 @@ async_blocks_ready_after(uv_work_t *r) { } if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } /** @@ -575,7 +573,7 @@ async_start_node_after(uv_work_t *r) { Isolate* isolate = req->isolate; HandleScope scope(isolate); - TryCatch try_catch; + Nan::TryCatch try_catch; Local cb = Local::New(isolate, req->callback); if (req->err_msg != "") { @@ -591,11 +589,10 @@ async_start_node_after(uv_work_t *r) { } if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } /** @@ -789,7 +786,7 @@ async_stop_node_after(uv_work_t *r) { Isolate* isolate = req->isolate; HandleScope scope(isolate); - TryCatch try_catch; + Nan::TryCatch try_catch; Local cb = Local::New(isolate, req->callback); if (req->err_msg != "") { @@ -805,10 +802,9 @@ async_stop_node_after(uv_work_t *r) { } if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } /** @@ -832,13 +828,11 @@ NAN_METHOD(GetBlock) { if (info[0]->IsNumber()) { int64_t height = info[0]->IntegerValue(); req->err_msg = std::string(""); - req->hash = std::string(""); req->height = height; } else { - String::Utf8Value hash_(info[0]->ToString()); - std::string hash = std::string(*hash_); + std::string hash = *Nan::Utf8String(info[0]); req->err_msg = std::string(""); - req->hash = hash; + req->hash = uint256S(hash); req->height = -1; } @@ -861,7 +855,6 @@ async_get_block(uv_work_t *req) { async_block_data* data = reinterpret_cast(req->data); CBlockIndex* pblockindex; - uint256 hash = uint256S(data->hash); if (data->height != -1) { pblockindex = chainActive[data->height]; @@ -870,11 +863,11 @@ async_get_block(uv_work_t *req) { return; } } else { - if (mapBlockIndex.count(hash) == 0) { + if (mapBlockIndex.count(data->hash) == 0) { data->err_msg = std::string("Block not found."); return; } else { - pblockindex = mapBlockIndex[hash]; + pblockindex = mapBlockIndex[data->hash]; } } @@ -917,7 +910,7 @@ async_get_block_after(uv_work_t *r) { Isolate *isolate = req->isolate; HandleScope scope(isolate); - TryCatch try_catch; + Nan::TryCatch try_catch; Local cb = Local::New(isolate, req->callback); if (req->err_msg != "") { @@ -928,9 +921,6 @@ async_get_block_after(uv_work_t *r) { Nan::MaybeLocal rawNodeBuffer = Nan::NewBuffer(req->buffer, req->size); - delete req->buffer; - req->buffer = NULL; - Local argv[2] = { Local::New(isolate, Null()), rawNodeBuffer.ToLocalChecked() @@ -939,11 +929,10 @@ async_get_block_after(uv_work_t *r) { } if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } /** @@ -963,17 +952,14 @@ NAN_METHOD(GetTransaction) { "Usage: daemon.getTransaction(txid, queryMempool, callback)"); } - String::Utf8Value txid_(info[0]->ToString()); + std::string txid = *Nan::Utf8String(info[0]); + bool queryMempool = info[1]->BooleanValue(); Local callback = Local::Cast(info[2]); async_tx_data *req = new async_tx_data(); req->err_msg = std::string(""); - req->txid = std::string(""); - - std::string txid = std::string(*txid_); - req->txid = txid; req->queryMempool = queryMempool; req->isolate = isolate; @@ -993,8 +979,8 @@ static void async_get_tx(uv_work_t *req) { async_tx_data* data = reinterpret_cast(req->data); - uint256 hash = uint256S(data->txid); uint256 blockhash; + uint256 hash = uint256S(data->txid); CTransaction ctx; if (data->queryMempool) { @@ -1040,7 +1026,7 @@ async_get_tx_after(uv_work_t *r) { HandleScope scope(isolate); CTransaction ctx = req->ctx; - TryCatch try_catch; + Nan::TryCatch try_catch; Local cb = Local::New(isolate, req->callback); if (req->err_msg != "") { @@ -1049,28 +1035,32 @@ async_get_tx_after(uv_work_t *r) { cb->Call(isolate->GetCurrentContext()->Global(), 1, argv); } else { - Nan::MaybeLocal result = Local::New(isolate, Null()); - if (!ctx.IsNull()) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << ctx; std::string stx = ssTx.str(); - result = Nan::NewBuffer((char *)stx.c_str(), stx.size()); + Nan::MaybeLocal result = Nan::NewBuffer((char *)stx.c_str(), stx.size()); + Local argv[2] = { + Local::New(isolate, Null()), + result.ToLocalChecked() + }; + cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); + + } else { + Local argv[2] = { + Local::New(isolate, Null()), + Local::New(isolate, Null()) + }; + cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); } - Local argv[2] = { - Local::New(isolate, Null()), - result.ToLocalChecked() - }; - cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); } if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } /** @@ -1182,7 +1172,7 @@ async_get_tx_and_info_after(uv_work_t *r) { HandleScope scope(isolate); CTransaction ctx = req->ctx; - TryCatch try_catch; + Nan::TryCatch try_catch; Local cb = Local::New(isolate, req->callback); Local obj = New(); @@ -1209,10 +1199,9 @@ async_get_tx_and_info_after(uv_work_t *r) { cb->Call(isolate->GetCurrentContext()->Global(), 2, argv); } if (try_catch.HasCaught()) { - node::FatalException(try_catch); + Nan::FatalException(try_catch); } req->callback.Reset(); - delete req; } /** From 1d6f11e10f30ff49fcb13a9148236ceab2e0dfdc Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 26 Oct 2015 11:39:04 -0400 Subject: [PATCH 03/12] Remove node.js version check. --- index.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/index.js b/index.js index 4b2aa56a..da3b0539 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,6 @@ 'use strict'; -var semver = require('semver'); -var packageData = require('./package.json'); - -function nodeVersionCheck(version, expected) { - if (!semver.satisfies(version, expected)) { - throw new Error('Node.js version ' + version + ' is expected to be ' + expected); - } -} -nodeVersionCheck(process.versions.node, packageData.engines.node); - module.exports = require('./lib'); -module.exports.nodeVersionCheck = nodeVersionCheck; module.exports.Node = require('./lib/node'); module.exports.Transaction = require('./lib/transaction'); module.exports.Service = require('./lib/service'); From 9d477fb64fbc8d12e094eafa4f0f0a3faff16a41 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 26 Oct 2015 11:43:32 -0400 Subject: [PATCH 04/12] Use Nan::CopyBuffer to avoid invalid pointer errors during garbage collection. --- .travis.yml | 1 + binding.gyp | 3 +-- src/libbitcoind.cc | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index e2df2e3b..97c0df3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ env: - BITCORENODE_ENV=test BITCORENODE_ASSUME_YES=true node_js: - "v0.12.7" + - "v4" before_install: - git config --global user.email "dev@bitpay.com" - git config --global user.name "BitPay, Inc." diff --git a/binding.gyp b/binding.gyp index 99a5cab0..3db1adb1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -48,8 +48,7 @@ "GetIsolate(); + Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); Local results = Array::New(isolate); @@ -273,7 +273,7 @@ tx_notifier(uv_async_t *handle) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; std::string stx = ssTx.str(); - Nan::MaybeLocal txBuffer = Nan::NewBuffer((char *)stx.c_str(), stx.size()); + Nan::MaybeLocal txBuffer = Nan::CopyBuffer((char *)stx.c_str(), stx.size()); uint256 hash = tx.GetHash(); @@ -1039,7 +1039,7 @@ async_get_tx_after(uv_work_t *r) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << ctx; std::string stx = ssTx.str(); - Nan::MaybeLocal result = Nan::NewBuffer((char *)stx.c_str(), stx.size()); + Nan::MaybeLocal result = Nan::CopyBuffer((char *)stx.c_str(), stx.size()); Local argv[2] = { Local::New(isolate, Null()), result.ToLocalChecked() @@ -1185,7 +1185,7 @@ async_get_tx_and_info_after(uv_work_t *r) { CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << ctx; std::string stx = ssTx.str(); - Nan::MaybeLocal rawNodeBuffer = Nan::NewBuffer((char *)stx.c_str(), stx.size()); + Nan::MaybeLocal rawNodeBuffer = Nan::CopyBuffer((char *)stx.c_str(), stx.size()); Nan::Set(obj, New("blockHash").ToLocalChecked(), New(req->blockHash).ToLocalChecked()); Nan::Set(obj, New("height").ToLocalChecked(), New(req->height)); @@ -1462,7 +1462,7 @@ NAN_METHOD(GetMempoolTransactions) { CDataStream dataStreamTx(SER_NETWORK, PROTOCOL_VERSION); dataStreamTx << tx; std::string txString = dataStreamTx.str(); - Nan::MaybeLocal txBuffer = Nan::NewBuffer((char *)txString.c_str(), txString.size()); + Nan::MaybeLocal txBuffer = Nan::CopyBuffer((char *)txString.c_str(), txString.size()); transactions->Set(arrayIndex, txBuffer.ToLocalChecked()); arrayIndex++; } @@ -1510,7 +1510,6 @@ set_cooked(void) { * Init() * Initialize the singleton object known as bitcoind. */ - NAN_MODULE_INIT(init) { Nan::Set(target, New("start").ToLocalChecked(), GetFunction(New(StartBitcoind)).ToLocalChecked()); Nan::Set(target, New("onBlocksReady").ToLocalChecked(), GetFunction(New(OnBlocksReady)).ToLocalChecked()); From f0e599fea1fbe34c69dbaf1f10d574a1961b3130 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Tue, 27 Oct 2015 12:46:14 -0400 Subject: [PATCH 05/12] Return node version check and include additional v4 engine. --- index.js | 11 +++++++++++ package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index da3b0539..4b2aa56a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,17 @@ 'use strict'; +var semver = require('semver'); +var packageData = require('./package.json'); + +function nodeVersionCheck(version, expected) { + if (!semver.satisfies(version, expected)) { + throw new Error('Node.js version ' + version + ' is expected to be ' + expected); + } +} +nodeVersionCheck(process.versions.node, packageData.engines.node); + module.exports = require('./lib'); +module.exports.nodeVersionCheck = nodeVersionCheck; module.exports.Node = require('./lib/node'); module.exports.Transaction = require('./lib/transaction'); module.exports.Service = require('./lib/service'); diff --git a/package.json b/package.json index b2bcfbf2..f3d17f90 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "bitcore-p2p": "~1.0.0" }, "engines": { - "node": "^0.12" + "node": "^0.12 || ^4.2" }, "os": [ "darwin", From d0129cc48b7ef9b353a4bb6224c92a443697a2eb Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Tue, 27 Oct 2015 12:53:43 -0400 Subject: [PATCH 06/12] Update leveldown to version 1.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3d17f90..a949da2f 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "commander": "^2.8.1", "errno": "^0.1.4", "express": "^4.13.3", - "leveldown": "git://github.com/Level/leveldown#86b96a823f74718f085e28086556a9697d61de84", + "leveldown": "^1.4.2", "levelup": "^1.2.1", "liftoff": "^2.2.0", "memdown": "^1.0.0", From 2d1c4b1455e08713725c2cf5e051179ce9f29576 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 28 Oct 2015 12:02:58 -0400 Subject: [PATCH 07/12] Add g++-4.8 to travis builds. --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 97c0df3c..5f534440 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,13 @@ sudo: false language: node_js env: -- BITCORENODE_ENV=test BITCORENODE_ASSUME_YES=true + - BITCORENODE_ENV=test BITCORENODE_ASSUME_YES=true CXX=g++-4.8 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 node_js: - "v0.12.7" - "v4" From 1e4939a9780476b4228a00d2cce0c9dbfb691c67 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 28 Oct 2015 13:58:53 -0400 Subject: [PATCH 08/12] Add CC environment variable and gcc-4.8 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f534440..5b0f5095 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,14 @@ sudo: false language: node_js env: - - BITCORENODE_ENV=test BITCORENODE_ASSUME_YES=true CXX=g++-4.8 + - BITCORENODE_ENV=test BITCORENODE_ASSUME_YES=true CXX=g++-4.8 CC=gcc-4.8 addons: apt: sources: - ubuntu-toolchain-r-test packages: - g++-4.8 + - gcc-4.8 node_js: - "v0.12.7" - "v4" From e987723ab983c1d0c20153b18799fb021919497b Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 28 Oct 2015 13:49:38 -0400 Subject: [PATCH 09/12] Update bitcoin patch to build depends with CC and CXX environment set --- etc/bitcoin.patch | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/etc/bitcoin.patch b/etc/bitcoin.patch index e1fe3b1b..10f8099a 100644 --- a/etc/bitcoin.patch +++ b/etc/bitcoin.patch @@ -79,6 +79,30 @@ index fd74aef..9c79637 100644 LEVELDB_CPPFLAGS= LIBLEVELDB= LIBMEMENV= +diff --git a/depends/hosts/linux.mk b/depends/hosts/linux.mk +index b13a0f1..0513394 100644 +--- a/depends/hosts/linux.mk ++++ b/depends/hosts/linux.mk +@@ -10,15 +10,15 @@ linux_debug_CXXFLAGS=$(linux_debug_CFLAGS) + linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC + + ifeq (86,$(findstring 86,$(build_arch))) +-i686_linux_CC=gcc -m32 +-i686_linux_CXX=g++ -m32 ++i686_linux_CC=${CC} -m32 ++i686_linux_CXX=${CXX} -m32 + i686_linux_AR=ar + i686_linux_RANLIB=ranlib + i686_linux_NM=nm + i686_linux_STRIP=strip + +-x86_64_linux_CC=gcc -m64 +-x86_64_linux_CXX=g++ -m64 ++x86_64_linux_CC=${CC} -m64 ++x86_64_linux_CXX=${CXX} -m64 + x86_64_linux_AR=ar + x86_64_linux_RANLIB=ranlib + x86_64_linux_NM=nm diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk index 68841af..65a105b 100644 --- a/depends/packages/bdb.mk @@ -268,7 +292,7 @@ index cce687a..0f162ff 100644 { SetupEnvironment(); @@ -175,3 +180,4 @@ int main(int argc, char* argv[]) - + return (AppInit(argc, argv) ? 0 : 1); } +#endif From bf97d7e70bce723eb9a454a6cb081b9a624a8509 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 28 Oct 2015 14:45:49 -0400 Subject: [PATCH 10/12] Include node version in binary distribution. --- bin/get-tarball-name.js | 3 ++- test/bin/get-tarball-name.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/bin/get-tarball-name.js diff --git a/bin/get-tarball-name.js b/bin/get-tarball-name.js index 114916c9..e931904b 100644 --- a/bin/get-tarball-name.js +++ b/bin/get-tarball-name.js @@ -5,7 +5,8 @@ function getTarballName() { var version = require(packageRoot + '/package.json').version; var platform = process.platform; var arch = process.arch; - var tarballName = 'libbitcoind-' + version + '-' + platform + '-' + arch + '.tgz'; + var abi = process.versions.modules; + var tarballName = 'libbitcoind-' + version + '-node' + abi + '-' + platform + '-' + arch + '.tgz'; return tarballName; } diff --git a/test/bin/get-tarball-name.js b/test/bin/get-tarball-name.js new file mode 100644 index 00000000..fa2b0601 --- /dev/null +++ b/test/bin/get-tarball-name.js @@ -0,0 +1,17 @@ +'use strict'; + +var should = require('chai').should(); +var path = require('path'); +var getTarballName = require('../../bin/get-tarball-name'); + +describe('#getTarballName', function() { + it('will return the expected tarball name', function() { + var name = getTarballName(); + var version = require(path.resolve(__dirname + '../../../package.json')).version; + var platform = process.platform; + var arch = process.arch; + var abi = process.versions.modules; + var expected = 'libbitcoind-' + version + '-node' + abi + '-' + platform + '-' + arch + '.tgz'; + name.should.equal(expected); + }); +}); From 39e2f4ded5ba30fc2bded2e425aef3c645fec32f Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 28 Oct 2015 16:20:34 -0400 Subject: [PATCH 11/12] Removed stray space in bitcoin patch. --- etc/bitcoin.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/bitcoin.patch b/etc/bitcoin.patch index 10f8099a..e262753e 100644 --- a/etc/bitcoin.patch +++ b/etc/bitcoin.patch @@ -292,7 +292,7 @@ index cce687a..0f162ff 100644 { SetupEnvironment(); @@ -175,3 +180,4 @@ int main(int argc, char* argv[]) - + return (AppInit(argc, argv) ? 0 : 1); } +#endif From 37441004c822864cf9ab66fa61e5aa89bfb8bb75 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 28 Oct 2015 16:02:04 -0400 Subject: [PATCH 12/12] Docs: Update prerequisites to include Node.js v4.2 --- README.md | 2 +- docs/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f3f6212..2da202a5 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Note: For your convenience, we distribute binaries for x86_64 Linux and x86_64 M ## Prerequisites -- Node.js v0.12 +- Node.js v0.12 or v4.2 - ~100GB of disk storage - ~4GB of RAM - Mac OS X >= 10.9, Ubuntu >= 12.04 (libc >= 2.15 and libstdc++ >= 6.0.16) diff --git a/docs/index.md b/docs/index.md index ff617ce8..aec8f91c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -10,7 +10,7 @@ bitcore-node start Note: For your convenience, we distribute binaries for x86_64 Linux and x86_64 Mac OS X. Upon npm install, the binaries for your platform will be downloaded. For more detailed installation instructions, or if you want to compile the project yourself, then please see the [Build & Install](build.md) documentation to build the project from source. # Prerequisites -- Node.js v0.12 +- Node.js v0.12 or v4.2 - ~100GB of disk storage - ~4GB of RAM - Mac OS X >= 10.9, Ubuntu >= 12.04 (libc >= 2.15 and libstdc++ >= 6.0.16)