aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-11-30 16:49:11 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2018-01-09 15:35:31 -0800
commit940a21932ba769ba5829cba713579db84f96d2f8 (patch)
tree2f1db2f007ef50255baddae3ef712831ad46ab58 /src/wallet/wallet.h
parentf37c64e477d679853a4076f2f7888568bb034e90 (diff)
downloadbitcoin-940a21932ba769ba5829cba713579db84f96d2f8.tar.xz
SegWit wallet support
This introduces two command line flags (-addresstype and -changetype) which control the type of addresses/outputs created by the GUI and RPCs. Certain RPCs allow overriding these (`getnewaddress` and `getrawchangeaddress`). Supported types are "legacy" (P2PKH and P2SH-multisig), "p2sh-segwit" (P2SH-P2WPKH and P2SH-P2WSH-multisig), and "bech32" (P2WPKH and P2WSH-multisig). A few utility functions are added to the wallet to construct different address type and to add the necessary entries to the wallet file to be compatible with earlier versions (see `CWallet::LearnRelatedScripts`, `GetDestinationForKey`, `GetAllDestinationsForKey`, `CWallet::AddAndGetDestinationForScript`).
Diffstat (limited to 'src/wallet/wallet.h')
-rw-r--r--src/wallet/wallet.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index e64ea2534a..4088ed1985 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -99,6 +99,19 @@ enum WalletFeature
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
};
+enum OutputType
+{
+ OUTPUT_TYPE_NONE,
+ OUTPUT_TYPE_LEGACY,
+ OUTPUT_TYPE_P2SH_SEGWIT,
+ OUTPUT_TYPE_BECH32,
+
+ OUTPUT_TYPE_DEFAULT = OUTPUT_TYPE_P2SH_SEGWIT
+};
+
+extern OutputType g_address_type;
+extern OutputType g_change_type;
+
/** A key pool entry */
class CKeyPool
@@ -1129,6 +1142,26 @@ public:
* deadlock
*/
void BlockUntilSyncedToCurrentChain();
+
+ /**
+ * Explicitly make the wallet learn the related scripts for outputs to the
+ * given key. This is purely to make the wallet file compatible with older
+ * software, as CBasicKeyStore automatically does this implicitly for all
+ * keys now.
+ */
+ void LearnRelatedScripts(const CPubKey& key, OutputType);
+
+ /**
+ * Same as LearnRelatedScripts, but when the OutputType is not known (and could
+ * be anything).
+ */
+ void LearnAllRelatedScripts(const CPubKey& key);
+
+ /**
+ * Get a destination of the requested type (if possible) to the specified script.
+ * This function will automatically add the necessary scripts to the wallet.
+ */
+ CTxDestination AddAndGetDestinationForScript(const CScript& script, OutputType);
};
/** A key allocated from the key pool. */
@@ -1218,4 +1251,16 @@ bool CWallet::DummySignTx(CMutableTransaction &txNew, const ContainerType &coins
return true;
}
+OutputType ParseOutputType(const std::string& str, OutputType default_type = OUTPUT_TYPE_DEFAULT);
+const std::string& FormatOutputType(OutputType type);
+
+/**
+ * Get a destination of the requested type (if possible) to the specified key.
+ * The caller must make sure LearnRelatedScripts has been called beforehand.
+ */
+CTxDestination GetDestinationForKey(const CPubKey& key, OutputType);
+
+/** Get all destinations (potentially) supported by the wallet for the given key. */
+std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
+
#endif // BITCOIN_WALLET_WALLET_H