Skip to content
Permalink
Browse files

Merge 12146 via opt_wallet_segwit2-0.16+knots

  • Loading branch information...
luke-jr committed Jul 30, 2018
3 parents db079c9 + 6035c6a + 796e874 commit d855625b1212665e73d48b9092c5dda53533de22
Showing with 22 additions and 4 deletions.
  1. +3 −0 src/init.cpp
  2. +3 −1 src/keystore.cpp
  3. +4 −0 src/keystore.h
  4. +8 −0 src/wallet/init.cpp
  5. +2 −1 src/wallet/wallet.cpp
  6. +1 −1 test/functional/feature_segwit.py
  7. +1 −1 test/functional/wallet_dump.py
@@ -22,6 +22,7 @@
#include <httpserver.h>
#include <httprpc.h>
#include <key.h>
#include <keystore.h>
#include <validation.h>
#include <miner.h>
#include <netbase.h>
@@ -1130,6 +1131,8 @@ bool AppInitParameterInteraction()
fRequireStandard = !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandardDefault());
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp);

g_implicit_segwit = gArgs.GetBoolArg("-walletimplicitsegwit", DEFAULT_WALLET_IMPLICIT_SEGWIT);

#ifdef ENABLE_WALLET
if (!WalletParameterInteraction())
return false;
@@ -7,6 +7,8 @@

#include <util.h>

bool g_implicit_segwit = true;

bool CKeyStore::AddKey(const CKey &key) {
return AddKeyPubKey(key, key.GetPubKey());
}
@@ -28,7 +30,7 @@ void CBasicKeyStore::ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey)
// "Implicitly" refers to fact that scripts are derived automatically from
// existing keys, and are present in memory, even without being explicitly
// loaded (e.g. from a file).
if (pubkey.IsCompressed()) {
if (pubkey.IsCompressed() && g_implicit_segwit) {
CScript script = GetScriptForDestination(WitnessV0KeyHash(key_id));
// This does not use AddCScript, as it may be overridden.
CScriptID id(script);
@@ -14,6 +14,10 @@

#include <boost/signals2/signal.hpp>

static const bool DEFAULT_WALLET_IMPLICIT_SEGWIT = false;

extern bool g_implicit_segwit;

/** A virtual base class for key stores */
class CKeyStore
{
@@ -5,6 +5,7 @@

#include <wallet/init.h>

#include <keystore.h>
#include <net.h>
#include <util.h>
#include <utilmoneystr.h>
@@ -40,6 +41,7 @@ std::string GetWalletHelpString(bool showDebug)
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT));
strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), DEFAULT_WALLETBROADCAST));
strUsage += HelpMessageOpt("-walletdir=<dir>", _("Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)"));
strUsage += HelpMessageOpt("-walletimplicitsegwit", strprintf(_("Support segwit when restoring wallet backups and importing keys (default: %u)"), DEFAULT_WALLET_IMPLICIT_SEGWIT));
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID and %w is replaced by wallet name)"));
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
@@ -179,6 +181,12 @@ bool WalletParameterInteraction()
bSpendZeroConfChange = gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
fWalletRbf = gArgs.GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);

if (!g_implicit_segwit) {
if (gArgs.SoftSetArg("-addresstype", "legacy")) {
LogPrintf("%s: parameter interaction: -walletimplicitsegwit=%u -> setting -addresstype=legacy\n", __func__, g_implicit_segwit);
}
}

g_address_type = ParseOutputType(gArgs.GetArg("-addresstype", ""));
if (g_address_type == OUTPUT_TYPE_NONE) {
return InitError(strprintf("Unknown address type '%s'", gArgs.GetArg("-addresstype", "")));
@@ -4218,6 +4218,7 @@ void CWallet::LearnRelatedScripts(const CPubKey& key, OutputType type)

void CWallet::LearnAllRelatedScripts(const CPubKey& key)
{
if (!g_implicit_segwit) return;
// OUTPUT_TYPE_P2SH_SEGWIT always adds all necessary scripts for all types.
LearnRelatedScripts(key, OUTPUT_TYPE_P2SH_SEGWIT);
}
@@ -4244,7 +4245,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)
{
CKeyID keyid = key.GetID();
if (key.IsCompressed()) {
if (key.IsCompressed() && g_implicit_segwit) {
CTxDestination segwit = WitnessV0KeyHash(keyid);
CTxDestination p2sh = CScriptID(GetScriptForDestination(segwit));
return std::vector<CTxDestination>{std::move(keyid), std::move(p2sh), std::move(segwit)};
@@ -40,7 +40,7 @@ def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress", "-walletimplicitsegwit"],
["-blockversion=4", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
["-blockversion=536870915", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]

@@ -78,7 +78,7 @@ def read_dump(file_name, addrs, script_addrs, hd_master_addr_old):
class WalletDumpTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [["-keypool=90", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
self.extra_args = [["-keypool=90", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress", "-walletimplicitsegwit"]]

def setup_network(self, split=False):
# Use 1 minute timeout because the initial getnewaddress RPC can take

0 comments on commit d855625

Please sign in to comment.
You can’t perform that action at this time.