From 15ebf5253e8b63098617578e6ad0de24e1d2d0f2 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 28 Oct 2014 11:52:03 -0700 Subject: [PATCH] add keypoolrefill method. --- lib/bitcoind.js | 4 ++++ src/bitcoindjs.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib/bitcoind.js b/lib/bitcoind.js index b0939817..14c2ea6c 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -735,6 +735,10 @@ Wallet.prototype.dumpPrivKey = function(options) { return bitcoindjs.dumpPrivKey(options || {}); }; +Wallet.prototype.keyPoolRefill = function(options) { + return bitcoindjs.walletKeyPoolRefill(options || {}); +}; + Wallet.prototype.setTxFee = function(options) { return bitcoindjs.walletSetTxFee(options || {}); }; diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index abdfbcf9..56d4deaf 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -194,6 +194,7 @@ NAN_METHOD(WalletLock); NAN_METHOD(WalletEncrypt); NAN_METHOD(WalletEncrypted); NAN_METHOD(WalletDumpPrivKey); +NAN_METHOD(WalletKeyPoolRefill); NAN_METHOD(WalletSetTxFee); NAN_METHOD(WalletImportKey); @@ -2110,6 +2111,7 @@ NAN_METHOD(WalletNewAddress) { std::string strAccount = std::string(*name_); if (!pwalletMain->IsLocked()) { + // XXX Do this asynchronously pwalletMain->TopUpKeyPool(); } @@ -2122,6 +2124,7 @@ NAN_METHOD(WalletNewAddress) { if (pwalletMain->IsLocked()) { return NanThrowError("Please enter the wallet passphrase with walletpassphrase first."); } + // XXX Do this asynchronously pwalletMain->TopUpKeyPool(100); if (pwalletMain->GetKeyPoolSize() < 100) { return NanThrowError("Error refreshing keypool."); @@ -3044,6 +3047,7 @@ NAN_METHOD(WalletPassphrase) { "Stores the wallet decryption key in memory for seconds."); } + // XXX Do this asynchronously pwalletMain->TopUpKeyPool(); NanReturnValue(Undefined()); @@ -3238,6 +3242,42 @@ NAN_METHOD(WalletDumpPrivKey) { NanReturnValue(obj); } +/** + * WalletKeyPoolRefill() + * bitcoindjs.walletKeyPoolRefill(options) + * Refill key pool + */ + +NAN_METHOD(WalletKeyPoolRefill) { + NanScope(); + + if (args.Length() < 1 || !args[0]->IsObject()) { + return NanThrowError( + "Usage: bitcoindjs.walletKeyPoolRefill(options)"); + } + + Local options = Local::Cast(args[0]); + + // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool + unsigned int kpSize = 0; + if (options->Get(NanNew("size"))->IsNumber()) { + kpSize = (unsigned int)options->Get(NanNew("size"))->IntegerValue(); + } + + // EnsureWalletIsUnlocked(); + if (pwalletMain->IsLocked()) { + return NanThrowError("Please enter the wallet passphrase with walletpassphrase first."); + } + // XXX Do this asynchronously + pwalletMain->TopUpKeyPool(kpSize); + + if (pwalletMain->GetKeyPoolSize() < kpSize) { + return NanThrowError("Error refreshing keypool."); + } + + NanReturnValue(True()); +} + /** * WalletSetTxFee() * bitcoindjs.walletSetTxFee(options) @@ -3784,6 +3824,7 @@ init(Handle target) { NODE_SET_METHOD(target, "walletEncrypt", WalletEncrypt); NODE_SET_METHOD(target, "walletEncrypted", WalletEncrypted); NODE_SET_METHOD(target, "walletDumpPrivKey", WalletDumpPrivKey); + NODE_SET_METHOD(target, "walletKeyPoolRefill", WalletKeyPoolRefill); NODE_SET_METHOD(target, "walletSetTxFee", WalletSetTxFee); NODE_SET_METHOD(target, "walletImportKey", WalletImportKey); }