diff --git a/src/init.cpp b/src/init.cpp index 1b1ccf2c..e5e66ca1 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -229,7 +229,7 @@ std::string HelpMessage() strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; strUsage += " -keypool= " + _("Set key pool size to (default: 100)") + "\n"; strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n"; - strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n"; + strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt twisterwallet.dat") + "\n"; strUsage += " -checkblocks= " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n"; strUsage += " -checklevel= " + _("How thorough the block verification is (0-4, default: 3)") + "\n"; strUsage += " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n"; @@ -518,23 +518,23 @@ bool AppInit2(boost::thread_group& threadGroup) if (GetBoolArg("-salvagewallet", false)) { // Recover readable keypairs: - if (!CWalletDB::Recover(bitdb, "wallet.dat", true)) + if (!CWalletDB::Recover(bitdb, "twisterwallet.dat", true)) return false; } - if (filesystem::exists(GetDataDir() / "wallet.dat")) + if (filesystem::exists(GetDataDir() / "twisterwallet.dat")) { - CDBEnv::VerifyResult r = bitdb.Verify("wallet.dat", CWalletDB::Recover); + CDBEnv::VerifyResult r = bitdb.Verify("twisterwallet.dat", CWalletDB::Recover); if (r == CDBEnv::RECOVER_OK) { - string msg = strprintf(_("Warning: wallet.dat corrupt, data salvaged!" - " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if" + string msg = strprintf(_("Warning: twisterwallet.dat corrupt, data salvaged!" + " Original twisterwallet.dat saved as wallet.{timestamp}.bak in %s; if" " your balance or transactions are incorrect you should" " restore from a backup."), strDataDir.c_str()); InitWarning(msg); } if (r == CDBEnv::RECOVER_FAIL) - return InitError(_("wallet.dat corrupt, salvage failed")); + return InitError(_("twisterwallet.dat corrupt, salvage failed")); } // ********************************************************* Step 6: network initialization @@ -795,20 +795,20 @@ bool AppInit2(boost::thread_group& threadGroup) nStart = GetTimeMillis(); bool fFirstRun = true; - pwalletMain = new CWallet("wallet.dat"); + pwalletMain = new CWallet("twisterwallet.dat"); DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun); if (nLoadWalletRet != DB_LOAD_OK) { if (nLoadWalletRet == DB_CORRUPT) - strErrors << _("Error loading wallet.dat: Wallet corrupted") << "\n"; + strErrors << _("Error loading twisterwallet.dat: Wallet corrupted") << "\n"; else if (nLoadWalletRet == DB_NONCRITICAL_ERROR) { - string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data" + string msg(_("Warning: error reading twisterwallet.dat! All keys read correctly, but transaction data" " or address book entries might be missing or incorrect.")); InitWarning(msg); } else if (nLoadWalletRet == DB_TOO_NEW) - strErrors << _("Error loading wallet.dat: Wallet requires newer version of Bitcoin") << "\n"; + strErrors << _("Error loading twisterwallet.dat: Wallet requires newer version of Bitcoin") << "\n"; else if (nLoadWalletRet == DB_NEED_REWRITE) { strErrors << _("Wallet needed to be rewritten: restart Bitcoin to complete") << "\n"; @@ -816,7 +816,7 @@ bool AppInit2(boost::thread_group& threadGroup) return InitError(strErrors.str()); } else - strErrors << _("Error loading wallet.dat") << "\n"; + strErrors << _("Error loading twisterwallet.dat") << "\n"; } if (GetBoolArg("-upgradewallet", fFirstRun)) @@ -860,7 +860,7 @@ bool AppInit2(boost::thread_group& threadGroup) pindexRescan = pindexGenesisBlock; else { - CWalletDB walletdb("wallet.dat"); + CWalletDB walletdb("twisterwallet.dat"); CBlockLocator locator; if (walletdb.ReadBestBlock(locator)) pindexRescan = locator.GetBlockIndex(); diff --git a/src/keystore.cpp b/src/keystore.cpp index 808f8c24..2e243362 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -26,31 +26,6 @@ bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) return true; } -bool CBasicKeyStore::AddCScript(const CScript& redeemScript) -{ - LOCK(cs_KeyStore); - mapScripts[redeemScript.GetID()] = redeemScript; - return true; -} - -bool CBasicKeyStore::HaveCScript(const CScriptID& hash) const -{ - LOCK(cs_KeyStore); - return mapScripts.count(hash) > 0; -} - -bool CBasicKeyStore::GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const -{ - LOCK(cs_KeyStore); - ScriptMap::const_iterator mi = mapScripts.find(hash); - if (mi != mapScripts.end()) - { - redeemScriptOut = (*mi).second; - return true; - } - return false; -} - bool CCryptoKeyStore::SetCrypted() { LOCK(cs_KeyStore); diff --git a/src/keystore.h b/src/keystore.h index 49a7bf56..1823f145 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -29,22 +29,15 @@ public: virtual bool GetKey(const CKeyID &address, CKey& keyOut) const =0; virtual void GetKeys(std::set &setAddress) const =0; virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const; - - // Support for BIP 0013 : see https://en.bitcoin.it/wiki/BIP_0013 - virtual bool AddCScript(const CScript& redeemScript) =0; - virtual bool HaveCScript(const CScriptID &hash) const =0; - virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const =0; }; typedef std::map KeyMap; -typedef std::map ScriptMap; /** Basic key store, that keeps keys in an address->secret map */ class CBasicKeyStore : public CKeyStore { protected: KeyMap mapKeys; - ScriptMap mapScripts; public: bool AddKeyPubKey(const CKey& key, const CPubKey &pubkey); @@ -83,9 +76,6 @@ public: } return false; } - virtual bool AddCScript(const CScript& redeemScript); - virtual bool HaveCScript(const CScriptID &hash) const; - virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const; }; typedef std::map > > CryptedKeyMap; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index b7a6d9cc..115db89c 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -163,6 +163,7 @@ Value createrawtransaction(const Array& params, bool fHelp) vector txData(ParseHexV(params[1], "pubkey")); rawTx.pubKey << txData; } else { + pwalletMain->GenerateNewKey(username); throw JSONRPCError(RPC_INTERNAL_ERROR, "pubkey generation not implemented"); } @@ -319,17 +320,6 @@ Value signrawtransaction(const Array& params, bool fHelp) // if redeemScript given and not using the local wallet (private keys // given), add redeemScript to the tempKeystore so it can be signed: - if (fGivenKeys && scriptPubKey.IsPayToScriptHash()) - { - RPCTypeCheck(prevOut, map_list_of("txid", str_type)("vout", int_type)("scriptPubKey", str_type)("redeemScript",str_type)); - Value v = find_value(prevOut, "redeemScript"); - if (!(v == Value::null)) - { - vector rsData(ParseHexV(v, "redeemScript")); - CScript redeemScript(rsData.begin(), rsData.end()); - tempKeystore.AddCScript(redeemScript); - } - } } } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 5d115b7f..3099ce0d 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -733,11 +733,10 @@ Value addmultisigaddress(const Array& params, bool fHelp) // Construct using pay-to-script-hash: CScript inner = _createmultisig(params); - CScriptID innerID = inner.GetID(); - pwalletMain->AddCScript(inner); - pwalletMain->SetAddressBookName(innerID, strAccount); - return CBitcoinAddress(innerID).ToString(); + //pwalletMain->SetAddressBookName(innerID, strAccount); + //return CBitcoinAddress(innerID).ToString(); + return CBitcoinAddress().ToString(); } Value createmultisig(const Array& params, bool fHelp) @@ -1144,7 +1143,7 @@ Value backupwallet(const Array& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "backupwallet \n" - "Safely copies wallet.dat to destination, which can be a directory or a path with filename."); + "Safely copies twisterwallet.dat to destination, which can be a directory or a path with filename."); string strDest = params[0].get_str(); if (!BackupWallet(*pwalletMain, strDest)) @@ -1321,25 +1320,6 @@ public: obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed())); return obj; } - - Object operator()(const CScriptID &scriptID) const { - Object obj; - obj.push_back(Pair("isscript", true)); - CScript subscript; - pwalletMain->GetCScript(scriptID, subscript); - std::vector addresses; - txnouttype whichType; - int nRequired; - ExtractDestinations(subscript, whichType, addresses, nRequired); - obj.push_back(Pair("script", GetTxnOutputType(whichType))); - Array a; - BOOST_FOREACH(const CTxDestination& addr, addresses) - a.push_back(CBitcoinAddress(addr).ToString()); - obj.push_back(Pair("addresses", a)); - if (whichType == TX_MULTISIG) - obj.push_back(Pair("sigsrequired", nRequired)); - return obj; - } }; Value validateaddress(const Array& params, bool fHelp) diff --git a/src/script.cpp b/src/script.cpp index 9190fc42..5bcc5e06 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -77,7 +77,6 @@ const char* GetTxnOutputType(txnouttype t) case TX_NONSTANDARD: return "nonstandard"; case TX_PUBKEY: return "pubkey"; case TX_PUBKEYHASH: return "pubkeyhash"; - case TX_SCRIPTHASH: return "scripthash"; case TX_MULTISIG: return "multisig"; } return NULL; @@ -1135,16 +1134,6 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector hashBytes(scriptPubKey.begin()+2, scriptPubKey.begin()+22); - vSolutionsRet.push_back(hashBytes); - return true; - } - // Scan templates const CScript& script1 = scriptPubKey; BOOST_FOREACH(const PAIRTYPE(txnouttype, CScript)& tplate, mTemplates) @@ -1294,8 +1283,6 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash scriptSigRet << vch; } return true; - case TX_SCRIPTHASH: - return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet); case TX_MULTISIG: scriptSigRet << OP_0; // workaround CHECKMULTISIG bug @@ -1318,8 +1305,6 @@ int ScriptSigArgsExpected(txnouttype t, const std::vectorHaveKey(keyID); } - bool operator()(const CScriptID &scriptID) const { return keystore->HaveCScript(scriptID); } }; bool IsMine(const CKeyStore &keystore, const CTxDestination &dest) @@ -1393,13 +1377,6 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) case TX_PUBKEYHASH: keyID = CKeyID(uint160(vSolutions[0])); return keystore.HaveKey(keyID); - case TX_SCRIPTHASH: - { - CScript subscript; - if (!keystore.GetCScript(CScriptID(uint160(vSolutions[0])), subscript)) - return false; - return IsMine(keystore, subscript); - } case TX_MULTISIG: { // Only consider transactions "mine" if we own ALL the @@ -1431,11 +1408,6 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) addressRet = CKeyID(uint160(vSolutions[0])); return true; } - else if (whichType == TX_SCRIPTHASH) - { - addressRet = CScriptID(uint160(vSolutions[0])); - return true; - } // Multisig txns have more than one address... return false; } @@ -1492,12 +1464,6 @@ public: vKeys.push_back(keyId); } - void operator()(const CScriptID &scriptId) { - CScript script; - if (keystore.GetCScript(scriptId, script)) - Process(script); - } - void operator()(const CNoDestination &none) {} }; @@ -1678,26 +1644,6 @@ static CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, if (sigs1.empty() || sigs1[0].empty()) return PushAll(sigs2); return PushAll(sigs1); - case TX_SCRIPTHASH: - if (sigs1.empty() || sigs1.back().empty()) - return PushAll(sigs2); - else if (sigs2.empty() || sigs2.back().empty()) - return PushAll(sigs1); - else - { - // Recur to combine: - valtype spk = sigs1.back(); - CScript pubKey2(spk.begin(), spk.end()); - - txnouttype txType2; - vector > vSolutions2; - Solver(pubKey2, txType2, vSolutions2); - sigs1.pop_back(); - sigs2.pop_back(); - CScript result = CombineSignatures(pubKey2, txTo, nIn, txType2, vSolutions2, sigs1, sigs2); - result << spk; - return result; - } case TX_MULTISIG: return CombineMultisig(scriptPubKey, txTo, nIn, vSolutions, sigs1, sigs2); } diff --git a/src/script.h b/src/script.h index 9956bac9..630b36da 100644 --- a/src/script.h +++ b/src/script.h @@ -43,7 +43,6 @@ enum txnouttype // 'standard' transaction types: TX_PUBKEY, TX_PUBKEYHASH, - TX_SCRIPTHASH, TX_MULTISIG, }; diff --git a/src/wallet.cpp b/src/wallet.cpp index 6dedfd40..25ef5130 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -27,7 +27,7 @@ struct CompareValueOnly } }; -CPubKey CWallet::GenerateNewKey() +CPubKey CWallet::GenerateNewKey(std::string username) { bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets @@ -43,7 +43,7 @@ CPubKey CWallet::GenerateNewKey() // Create new metadata int64 nCreationTime = GetTime(); - mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime); + mapKeyMetadata[pubkey.GetID()] = CKeyMetadata(nCreationTime, username); if (!nTimeFirstKey || nCreationTime < nTimeFirstKey) nTimeFirstKey = nCreationTime; @@ -101,15 +101,6 @@ bool CWallet::LoadCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); // 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 Unlock(const SecureString& strWalletPassphrase); bool ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase); diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 702e219a..34a20885 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -374,7 +374,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, // stored metadata for that key later, which is fine. CKeyID keyid = keypool.vchPubKey.GetID(); if (pwallet->mapKeyMetadata.count(keyid) == 0) - pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime); + pwallet->mapKeyMetadata[keyid] = CKeyMetadata(keypool.nTime, std::string()); } else if (strType == "version") { @@ -382,18 +382,6 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, if (wss.nFileVersion == 10300) wss.nFileVersion = 300; } - else if (strType == "cscript") - { - uint160 hash; - ssKey >> hash; - CScript script; - ssValue >> script; - if (!pwallet->LoadCScript(script)) - { - strErr = "Error reading wallet database: LoadCScript failed"; - return false; - } - } else if (strType == "orderposnext") { ssValue >> pwallet->nOrderPosNext; @@ -557,7 +545,7 @@ void ThreadFlushWalletDB(const string& strFile) map::iterator mi = bitdb.mapFileUseCount.find(strFile); if (mi != bitdb.mapFileUseCount.end()) { - printf("Flushing wallet.dat\n"); + printf("Flushing twisterwallet.dat\n"); nLastFlushed = nWalletDBUpdated; int64 nStart = GetTimeMillis(); @@ -566,7 +554,7 @@ void ThreadFlushWalletDB(const string& strFile) bitdb.CheckpointLSN(strFile); bitdb.mapFileUseCount.erase(mi++); - printf("Flushed wallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart); + printf("Flushed twisterwallet.dat %"PRI64d"ms\n", GetTimeMillis() - nStart); } } } @@ -589,7 +577,7 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) bitdb.CheckpointLSN(wallet.strWalletFile); bitdb.mapFileUseCount.erase(wallet.strWalletFile); - // Copy wallet.dat + // Copy twisterwallet.dat filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile; filesystem::path pathDest(strDest); if (filesystem::is_directory(pathDest)) @@ -601,10 +589,10 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) #else filesystem::copy_file(pathSrc, pathDest); #endif - printf("copied wallet.dat to %s\n", pathDest.string().c_str()); + printf("copied twisterwallet.dat to %s\n", pathDest.string().c_str()); return true; } catch(const filesystem::filesystem_error &e) { - printf("error copying wallet.dat to %s - %s\n", pathDest.string().c_str(), e.what()); + printf("error copying twisterwallet.dat to %s - %s\n", pathDest.string().c_str(), e.what()); return false; } } diff --git a/src/walletdb.h b/src/walletdb.h index 4dfa35d8..a89eb311 100644 --- a/src/walletdb.h +++ b/src/walletdb.h @@ -31,15 +31,17 @@ public: static const int CURRENT_VERSION=1; int nVersion; int64 nCreateTime; // 0 means unknown + std::string username; CKeyMetadata() { SetNull(); } - CKeyMetadata(int64 nCreateTime_) + CKeyMetadata(int64 nCreateTime_, std::string username_) { nVersion = CKeyMetadata::CURRENT_VERSION; nCreateTime = nCreateTime_; + username = username_; } IMPLEMENT_SERIALIZE @@ -47,16 +49,18 @@ public: READWRITE(this->nVersion); nVersion = this->nVersion; READWRITE(nCreateTime); + READWRITE(username); ) void SetNull() { nVersion = CKeyMetadata::CURRENT_VERSION; nCreateTime = 0; + username.clear(); } }; -/** Access to the wallet database (wallet.dat) */ +/** Access to the wallet database (twisterwallet.dat) */ class CWalletDB : public CDB { public: @@ -168,7 +172,7 @@ public: return Erase(std::make_pair(std::string("pool"), nPool)); } - // Settings are no longer stored in wallet.dat; these are + // Settings are no longer stored in twisterwallet.dat; these are // used only for backwards compatibility: template bool ReadSetting(const std::string& strKey, T& value)