aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-05-07 10:47:00 -0400
committerGavin Andresen <gavinandresen@gmail.com>2013-05-07 11:47:33 -0400
commit92f2c1fe0fe2905540b0435188988851145f92be (patch)
treebd9d7b05aee0bbe4520ddcb08b0a88947c51795d /src/bitcoinrpc.h
parent9d053d170be718cf0ff902916fb11ffdee46537b (diff)
downloadbitcoin-92f2c1fe0fe2905540b0435188988851145f92be.tar.xz
Use boost::asio::deadline_timer for walletpassphrase timeout
New method in bitcoinrpc: RunLater, that uses a map of deadline timers to run a function later. Behavior of walletpassphrase is changed; before, calling walletpassphrase again before the lock timeout passed would result in: Error: Wallet is already unlocked. You would have to call lockwallet before walletpassphrase. Now: the last walletpassphrase with correct password wins, and overrides any previous timeout. Fixes issue# 1961 which was caused by spawning too many threads. Test plan: Start with encrypted wallet, password 'foo' NOTE: python -c 'import time; print("%d"%time.time())' ... will tell you current unix timestamp. Try: walletpassphrase foo 600 getinfo EXPECT: unlocked_until is about 10 minutes in the future walletpassphrase foo 1 sleep 2 sendtoaddress mun74Bvba3B1PF2YkrF4NsgcJwHXXh12LF 11 EXPECT: Error: Please enter the wallet passphrase with walletpassphrase first. walletpassphrase foo 600 walletpassphrase foo 0 getinfo EXPECT: wallet is locked (unlocked_until is 0) walletpassphrase foo 10 walletpassphrase foo 600 getinfo EXPECT: wallet is unlocked until 10 minutes in future walletpassphrase foo 60 walletpassphrase bar 600 EXPECT: Error, incorrect passphrase getinfo EXPECT: wallet still scheduled to lock 60 seconds from first (successful) walletpassphrase
Diffstat (limited to 'src/bitcoinrpc.h')
-rw-r--r--src/bitcoinrpc.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h
index 315fd92383..270c2a009c 100644
--- a/src/bitcoinrpc.h
+++ b/src/bitcoinrpc.h
@@ -88,6 +88,12 @@ void RPCTypeCheck(const json_spirit::Array& params,
void RPCTypeCheck(const json_spirit::Object& o,
const std::map<std::string, json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
+/*
+ Run func nSeconds from now. Uses boost deadline timers.
+ Overrides previous timer <name> (if any).
+ */
+void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64 nSeconds);
+
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
class CRPCCommand