From b138877e197f9391cac7e5f5f370ab7499b61289 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 25 Sep 2015 14:33:37 -0400 Subject: [PATCH] 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);