2
2
* bitcoind.js - a binding for node.js which links to libbitcoind.so/dylib.
3
3
* Copyright (c) 2015, BitPay (MIT License)
4
4
*
5
- * bitcoindjs .cc:
5
+ * libbitcoind .cc:
6
6
* A bitcoind node.js binding.
7
7
*/
8
8
@@ -91,7 +91,7 @@ init(Handle<Object>);
91
91
92
92
/* *
93
93
* Private Global Variables
94
- * Used only by bitcoindjs functions.
94
+ * Used only by bitcoind functions.
95
95
*/
96
96
static std::vector<CDataStream> txmon_messages;
97
97
static uv_async_t txmon_async;
@@ -236,6 +236,28 @@ NAN_METHOD(GetBestBlockHash) {
236
236
}
237
237
}
238
238
239
+ NAN_METHOD (GetNextBlockHash) {
240
+
241
+ if (args.Length () < 1 || !args[0 ]->IsString ()) {
242
+ return NanThrowError (" Usage: bitcoind.getNextBlockHash(blockhash)" );
243
+ }
244
+
245
+ CBlockIndex* pblockindex;
246
+ v8::String::Utf8Value param1 (args[0 ]->ToString ());
247
+ std::string *hash = new std::string (*param1);
248
+ uint256 shash = uint256S (*hash);
249
+ pblockindex = mapBlockIndex[shash];
250
+ CBlockIndex* pnextblockindex = chainActive.Next (pblockindex);
251
+ if (pnextblockindex) {
252
+ uint256 nexthash = pnextblockindex->GetBlockHash ();
253
+ std::string rethash = nexthash.ToString ();
254
+ NanReturnValue (NanNew<String>(rethash));
255
+ } else {
256
+ NanReturnValue (NanNull ());
257
+ }
258
+
259
+ }
260
+
239
261
/* *
240
262
* IsSynced()
241
263
* bitcoind.isSynced()
@@ -914,7 +936,7 @@ NAN_METHOD(GetBlock) {
914
936
|| (!args[0 ]->IsString () && !args[0 ]->IsNumber ())
915
937
|| !args[1 ]->IsFunction ()) {
916
938
return NanThrowError (
917
- " Usage: bitcoindjs .getBlock([blockhash,blockheight], callback)" );
939
+ " Usage: bitcoind .getBlock([blockhash,blockheight], callback)" );
918
940
}
919
941
920
942
async_block_data *req = new async_block_data ();
@@ -1177,7 +1199,7 @@ NAN_METHOD(GetTransactionWithBlockInfo) {
1177
1199
|| !args[1 ]->IsBoolean ()
1178
1200
|| !args[2 ]->IsFunction ()) {
1179
1201
return NanThrowError (
1180
- " Usage: bitcoindjs .getTransactionWithBlockInfo(txid, queryMempool, callback)" );
1202
+ " Usage: bitcoind .getTransactionWithBlockInfo(txid, queryMempool, callback)" );
1181
1203
}
1182
1204
1183
1205
String::Utf8Value txid_ (args[0 ]->ToString ());
@@ -1307,15 +1329,15 @@ async_get_tx_and_info_after(uv_work_t *r) {
1307
1329
1308
1330
/* *
1309
1331
* IsSpent()
1310
- * bitcoindjs .isSpent()
1332
+ * bitcoind .isSpent()
1311
1333
* Determine if an outpoint is spent
1312
1334
*/
1313
1335
NAN_METHOD (IsSpent) {
1314
1336
NanScope ();
1315
1337
1316
1338
if (args.Length () > 2 ) {
1317
1339
return NanThrowError (
1318
- " Usage: bitcoindjs .isSpent(txid, outputIndex)" );
1340
+ " Usage: bitcoind .isSpent(txid, outputIndex)" );
1319
1341
}
1320
1342
1321
1343
String::Utf8Value arg (args[0 ]->ToString ());
@@ -1341,7 +1363,7 @@ NAN_METHOD(IsSpent) {
1341
1363
1342
1364
/* *
1343
1365
* GetBlockIndex()
1344
- * bitcoindjs .getBlockIndex()
1366
+ * bitcoind .getBlockIndex()
1345
1367
* Get index information about a block by hash including:
1346
1368
* - the total amount of work (expected number of hashes) in the chain up to
1347
1369
* and including this block.
@@ -1423,7 +1445,7 @@ NAN_METHOD(IsMainChain) {
1423
1445
1424
1446
/* *
1425
1447
* GetInfo()
1426
- * bitcoindjs .getInfo()
1448
+ * bitcoind .getInfo()
1427
1449
* Get miscellaneous information
1428
1450
*/
1429
1451
@@ -1432,7 +1454,7 @@ NAN_METHOD(GetInfo) {
1432
1454
1433
1455
if (args.Length () > 0 ) {
1434
1456
return NanThrowError (
1435
- " Usage: bitcoindjs .getInfo()" );
1457
+ " Usage: bitcoind .getInfo()" );
1436
1458
}
1437
1459
1438
1460
Local<Object> obj = NanNew<Object>();
@@ -1482,7 +1504,7 @@ NAN_METHOD(EstimateFee) {
1482
1504
1483
1505
/* *
1484
1506
* Send Transaction
1485
- * bitcoindjs .sendTransaction()
1507
+ * bitcoind .sendTransaction()
1486
1508
* Will add a transaction to the mempool and broadcast to connected peers.
1487
1509
* @param {string} - The serialized hex string of the transaction.
1488
1510
* @param {boolean} - Skip absurdly high fee checks
@@ -1637,7 +1659,7 @@ set_cooked(void) {
1637
1659
1638
1660
/* *
1639
1661
* Init()
1640
- * Initialize the singleton object known as bitcoindjs .
1662
+ * Initialize the singleton object known as bitcoind .
1641
1663
*/
1642
1664
1643
1665
extern " C" void
@@ -1664,6 +1686,7 @@ init(Handle<Object> target) {
1664
1686
NODE_SET_METHOD (target, " isSynced" , IsSynced);
1665
1687
NODE_SET_METHOD (target, " getTxOutSetInfo" , GetTxOutSetInfo);
1666
1688
NODE_SET_METHOD (target, " getBestBlockHash" , GetBestBlockHash);
1689
+ NODE_SET_METHOD (target, " getNextBlockHash" , GetNextBlockHash);
1667
1690
1668
1691
}
1669
1692
0 commit comments