Port -txsend from str4d #37, https://github.com/zcash/zcash/pull/4522
This commit is contained in:
11
src/init.cpp
11
src/init.cpp
@@ -392,6 +392,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-sysperms", _("Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)"));
|
||||
#endif
|
||||
strUsage += HelpMessageOpt("-txindex", strprintf(_("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-txsend=<cmd>", _("Execute command to send a transaction instead of broadcasting (%s in cmd is replaced by transaction hex)"));
|
||||
strUsage += HelpMessageOpt("-addressindex", strprintf(_("Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses (default: %u)"), DEFAULT_ADDRESSINDEX));
|
||||
strUsage += HelpMessageOpt("-timestampindex", strprintf(_("Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps (default: %u)"), DEFAULT_TIMESTAMPINDEX));
|
||||
strUsage += HelpMessageOpt("-spentindex", strprintf(_("Maintain a full spent index, used to query the spending txid and input index for an outpoint (default: %u)"), DEFAULT_SPENTINDEX));
|
||||
@@ -1118,6 +1119,16 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (mapArgs.count("-txsend")) {
|
||||
if (GetBoolArg("-walletbroadcast", true)) {
|
||||
if (SoftSetBoolArg("-walletbroadcast", false)) {
|
||||
LogPrintf("%s: parameter interaction: -txsend=<cmd> -> setting -walletbroadcast=0\n", __func__);
|
||||
} else {
|
||||
return InitError(_("Wallet transaction broadcasting is incompatible with -txsend (for privacy)."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ********************************************************* Step 3: parameter-to-internal-flags
|
||||
|
||||
fZdebug=GetBoolArg("-zdebug", false);
|
||||
|
||||
@@ -45,7 +45,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
#include <boost/assign/list_of.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
@@ -1373,6 +1376,19 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp, const CPubKey& m
|
||||
const CCoins* existingCoins = view.AccessCoins(hashTx);
|
||||
bool fHaveMempool = mempool.exists(hashTx);
|
||||
bool fHaveChain = existingCoins && existingCoins->nHeight < 1000000000;
|
||||
|
||||
// If we are configured to send transactions via an
|
||||
// external service instead of broadcasting, do that
|
||||
std::string strCmd = GetArg("-txsend", "");
|
||||
if (!strCmd.empty()) {
|
||||
if (fHaveChain) {
|
||||
throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain");
|
||||
}
|
||||
boost::replace_all(strCmd, "%s", EncodeHexTx(tx));
|
||||
boost::thread t(runCommand, strCmd); // thread runs free
|
||||
// Return here so we don't add to our mempool or broadcast to peers
|
||||
return hashTx.GetHex();
|
||||
}
|
||||
if (!fHaveMempool && !fHaveChain) {
|
||||
// push to local node and sync with wallets
|
||||
CValidationState state;
|
||||
|
||||
@@ -3950,6 +3950,8 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
|
||||
// Track how many getdata requests our transaction gets
|
||||
mapRequestCount[wtxNew.GetHash()] = 0;
|
||||
|
||||
std::string strCmd = GetArg("-txsend", "");
|
||||
|
||||
if (fBroadcastTransactions)
|
||||
{
|
||||
// Broadcast
|
||||
@@ -3962,6 +3964,12 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
|
||||
}
|
||||
wtxNew.RelayWalletTransaction();
|
||||
}
|
||||
// If we are configured to send transactions via an
|
||||
// external service instead of broadcasting, do that
|
||||
else if (!strCmd.empty()) {
|
||||
boost::replace_all(strCmd, "%s", EncodeHexTx(wtxNew));
|
||||
boost::thread t(runCommand, strCmd); // thread runs free
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user