mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
wallet: Replace %w by wallet name in -walletnotify script
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
This commit is contained in:
parent
6196e93001
commit
9a5b5ee81f
4 changed files with 22 additions and 1 deletions
|
@ -63,6 +63,7 @@
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
|
@ -1022,6 +1023,15 @@ fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
std::string ShellEscape(const std::string& arg)
|
||||||
|
{
|
||||||
|
std::string escaped = arg;
|
||||||
|
boost::replace_all(escaped, "'", "'\"'\"'");
|
||||||
|
return "'" + escaped + "'";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAVE_SYSTEM
|
#if HAVE_SYSTEM
|
||||||
void runCommand(const std::string& strCommand)
|
void runCommand(const std::string& strCommand)
|
||||||
{
|
{
|
||||||
|
|
|
@ -81,6 +81,9 @@ fs::path GetConfigFile(const std::string& confPath);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef WIN32
|
||||||
|
std::string ShellEscape(const std::string& arg);
|
||||||
|
#endif
|
||||||
#if HAVE_SYSTEM
|
#if HAVE_SYSTEM
|
||||||
void runCommand(const std::string& strCommand);
|
void runCommand(const std::string& strCommand);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -62,7 +62,7 @@ void WalletInit::AddWalletOptions() const
|
||||||
gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
|
gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
|
||||||
gArgs.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
|
gArgs.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
|
||||||
#if HAVE_SYSTEM
|
#if HAVE_SYSTEM
|
||||||
gArgs.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
|
gArgs.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes. %s in cmd is replaced by TxID and %w is replaced by wallet name. %w is not currently implemented on windows. On systems where %w is supported, it should NOT be quoted because this would break shell escaping used to invoke the command.", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
|
||||||
#endif
|
#endif
|
||||||
gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
|
gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
|
||||||
gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
|
gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
|
||||||
|
|
|
@ -835,6 +835,14 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
|
||||||
if (!strCmd.empty())
|
if (!strCmd.empty())
|
||||||
{
|
{
|
||||||
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
|
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
|
||||||
|
#ifndef WIN32
|
||||||
|
// Substituting the wallet name isn't currently supported on windows
|
||||||
|
// because windows shell escaping has not been implemented yet:
|
||||||
|
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-537384875
|
||||||
|
// A few ways it could be implemented in the future are described in:
|
||||||
|
// https://github.com/bitcoin/bitcoin/pull/13339#issuecomment-461288094
|
||||||
|
boost::replace_all(strCmd, "%w", ShellEscape(GetName()));
|
||||||
|
#endif
|
||||||
std::thread t(runCommand, strCmd);
|
std::thread t(runCommand, strCmd);
|
||||||
t.detach(); // thread runs free
|
t.detach(); // thread runs free
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue