From 32a7d89f5cbdec635d305516865979b3d8bcc321 Mon Sep 17 00:00:00 2001 From: Zak Wilcox Date: Sat, 12 Jul 2014 09:21:02 +0100 Subject: [PATCH 1/3] Clarify that redeemScript is often optional Rebased-From: 6265ecc --- src/rpcrawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 8dec20c33..f577eba4b 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -522,7 +522,7 @@ Value signrawtransaction(const Array& params, bool fHelp) " \"txid\":\"id\", (string, required) The transaction id\n" " \"vout\":n, (numeric, required) The output number\n" " \"scriptPubKey\": \"hex\", (string, required) script key\n" - " \"redeemScript\": \"hex\" (string, required) redeem script\n" + " \"redeemScript\": \"hex\" (string, required for P2SH) redeem script\n" " }\n" " ,...\n" " ]\n" From 0e2105f78c6090a3e57aa9a2234ff1795710306f Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 10 Jun 2014 09:42:42 +0200 Subject: [PATCH 2/3] Ignore too-long redeemScripts while loading wallet This avoids that long redeemScripts that were grandfathered in prevent the wallet from loading. Fixes #4313. Rebased-From: 18116b0 --- src/wallet.cpp | 16 ++++++++++++++++ src/wallet.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 56b0d183d..d2c09a671 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -130,6 +130,22 @@ bool CWallet::AddCScript(const CScript& redeemScript) return CWalletDB(strWalletFile).WriteCScript(Hash160(redeemScript), redeemScript); } +bool CWallet::LoadCScript(const CScript& redeemScript) +{ + /* A sanity check was added in pull #3843 to avoid adding redeemScripts + * that never can be redeemed. However, old wallets may still contain + * these. Do not add them to the wallet and warn. */ + if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) + { + std::string strAddr = CBitcoinAddress(redeemScript.GetID()).ToString(); + LogPrintf("%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", + __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr); + return true; + } + + return CCryptoKeyStore::AddCScript(redeemScript); +} + bool CWallet::Unlock(const SecureString& strWalletPassphrase) { CCrypter crypter; diff --git a/src/wallet.h b/src/wallet.h index 3f2b9fbf1..d47374ff8 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -398,7 +398,7 @@ public: // Adds an encrypted key to the store, without saving it to disk (used by LoadWallet) bool LoadCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); bool AddCScript(const CScript& redeemScript); - bool LoadCScript(const CScript& redeemScript) { return CCryptoKeyStore::AddCScript(redeemScript); } + bool LoadCScript(const CScript& redeemScript); /// Adds a destination data tuple to the store, and saves it to disk bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value); From 1d229e1ef55aa62f162e42965d9c684e517d6629 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Thu, 28 Aug 2014 20:58:45 +0100 Subject: [PATCH 3/3] Modified comment to make it clear that pull request refers to Bitcoin Core. --- src/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index d2c09a671..e9976f0ab 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -132,7 +132,7 @@ bool CWallet::AddCScript(const CScript& redeemScript) bool CWallet::LoadCScript(const CScript& redeemScript) { - /* A sanity check was added in pull #3843 to avoid adding redeemScripts + /* A sanity check was added in Bitcoin Core pull #3843 to avoid adding redeemScripts * that never can be redeemed. However, old wallets may still contain * these. Do not add them to the wallet and warn. */ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)