From: CryptoManiac Date: Mon, 30 Jan 2017 10:42:29 +0000 (+0300) Subject: Merge pull request #363 from svost/c++11 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=0cb45221c0de742e47d21f9007ecd412aa0d87b6;hp=55e776d2e10b8d211b2dec3785db22437fc21fc8 Merge pull request #363 from svost/c++11 Build fixes --- diff --git a/contrib/debian/examples/novacoin.conf b/contrib/debian/examples/novacoin.conf index 3e0dd1f..3ca9e02 100644 --- a/contrib/debian/examples/novacoin.conf +++ b/contrib/debian/examples/novacoin.conf @@ -6,7 +6,7 @@ # Run on the test network instead of the real novacoin network. #testnet=1 -# Connect via a socks4 proxy +# Connect via a socks5 proxy #proxy=127.0.0.1:9050 # Use as many addnode= settings as you like to connect to specific peers diff --git a/contrib/debian/manpages/novacoin.conf.5 b/contrib/debian/manpages/novacoin.conf.5 index 1901e16..20590d0 100644 --- a/contrib/debian/manpages/novacoin.conf.5 +++ b/contrib/debian/manpages/novacoin.conf.5 @@ -16,7 +16,7 @@ novacoin.conf should be located in $HOME/.novacoin Enable or disable run on the test network instead of the real *novacoin* network. .TP \fBproxy=\fR\fI'127.0.0.1:9050'\fR -Connect via a socks4 proxy. +Connect via a socks5 proxy. .TP \fBaddnode=\fR\fI'10.0.0.2:8333'\fR Use as many *addnode=* settings as you like to connect to specific peers. diff --git a/contrib/debian/manpages/novacoind.1 b/contrib/debian/manpages/novacoind.1 index b8199c2..a17b398 100644 --- a/contrib/debian/manpages/novacoind.1 +++ b/contrib/debian/manpages/novacoind.1 @@ -28,7 +28,7 @@ Start minimized Specify data directory .TP \fB\-proxy=\fR -Connect through socks4 proxy +Connect through socks5 proxy .TP \fB\-addnode=\fR Add a node to connect to diff --git a/src/init.cpp b/src/init.cpp index 90bf8de..4b64d35 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -239,8 +239,7 @@ std::string HelpMessage() " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n" + " -dblogsize= " + _("Set database disk log size in megabytes (default: 100)") + "\n" + " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" + - " -proxy= " + _("Connect through socks proxy") + "\n" + - " -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" + + " -proxy= " + _("Connect through socks5 proxy") + "\n" + " -tor= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n" " -torname= " + _("Send the specified hidden service name when connecting to Tor nodes (default: none)") + "\n" " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" + @@ -629,11 +628,6 @@ bool AppInit2() // ********************************************************* Step 6: network initialization - int nSocksVersion = GetArgInt("-socks", 5); - - if (nSocksVersion != 4 && nSocksVersion != 5) - return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion)); - if (mapArgs.count("-onlynet")) { std::set nets; for(std::string snet : mapMultiArgs["-onlynet"]) { @@ -663,14 +657,12 @@ bool AppInit2() return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str())); if (!IsLimited(NET_IPV4)) - SetProxy(NET_IPV4, addrProxy, nSocksVersion); - if (nSocksVersion > 4) { + SetProxy(NET_IPV4, addrProxy); #ifdef USE_IPV6 if (!IsLimited(NET_IPV6)) - SetProxy(NET_IPV6, addrProxy, nSocksVersion); + SetProxy(NET_IPV6, addrProxy); #endif - SetNameProxy(addrProxy, nSocksVersion); - } + SetNameProxy(addrProxy); fProxy = true; } @@ -683,7 +675,7 @@ bool AppInit2() addrOnion = CService(mapArgs["-tor"], nSocksDefault); if (!addrOnion.IsValid()) return InitError(strprintf(_("Invalid -tor address: '%s'"), mapArgs["-tor"].c_str())); - SetProxy(NET_TOR, addrOnion, 5); + SetProxy(NET_TOR, addrOnion); SetReachable(NET_TOR); } diff --git a/src/kernel.h b/src/kernel.h index 3649070..4d143ab 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -4,6 +4,8 @@ #ifndef PPCOIN_KERNEL_H #define PPCOIN_KERNEL_H +#include + #include "uint256.h" class CBlock; diff --git a/src/kernelrecord.cpp b/src/kernelrecord.cpp index beb8aa7..552d060 100644 --- a/src/kernelrecord.cpp +++ b/src/kernelrecord.cpp @@ -1,4 +1,5 @@ #include "kernelrecord.h" +#include "kernel.h" #include "wallet.h" #include "base58.h" diff --git a/src/key.cpp b/src/key.cpp index 072199b..3c4762e 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -165,6 +165,10 @@ const unsigned char vchMaxModHalfOrder[32] = { const unsigned char *vchZero = NULL; +CScriptID::CScriptID(const CScript& in) : uint160(Hash160(in.begin(), in.end())) +{ +} + void CKey::SetCompressedPubKey(bool fCompressed) { EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED); diff --git a/src/key.h b/src/key.h index c4c1c96..5c42c41 100644 --- a/src/key.h +++ b/src/key.h @@ -59,6 +59,7 @@ class CScriptID : public uint160 { public: CScriptID() : uint160(0) { } + CScriptID(const CScript& in); CScriptID(const uint160 &in) : uint160(in) { } }; diff --git a/src/keystore.cpp b/src/keystore.cpp index 86a4cc3..e5f0ce3 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -18,6 +18,15 @@ bool CKeyStore::GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const return true; } +bool CKeyStore::GetSecret(const CKeyID &address, CSecret& vchSecret, bool &fCompressed) const +{ + CKey key; + if (!GetKey(address, key)) + return false; + vchSecret = key.GetSecret(fCompressed); + return true; +} + bool CBasicKeyStore::AddKey(const CKey& key) { bool fCompressed = false; @@ -38,6 +47,54 @@ bool CBasicKeyStore::AddMalleableKey(const CMalleableKeyView& keyView, const CSe return true; } +bool CBasicKeyStore::GetMalleableKey(const CMalleableKeyView &keyView, CMalleableKey &mKey) const +{ + { + LOCK(cs_KeyStore); + MalleableKeyMap::const_iterator mi = mapMalleableKeys.find(keyView); + if (mi != mapMalleableKeys.end()) + { + mKey = mi->first.GetMalleableKey(mi->second); + return true; + } + } + return false; +} + +bool CBasicKeyStore::HaveKey(const CKeyID &address) const +{ + bool result; + { + LOCK(cs_KeyStore); + result = (mapKeys.count(address) > 0); + } + return result; +} + +void CBasicKeyStore::GetKeys(std::set &setAddress) const +{ + setAddress.clear(); + { + LOCK(cs_KeyStore); + KeyMap::const_iterator mi; + for (mi = mapKeys.begin(); mi != mapKeys.end(); ++mi) setAddress.insert((*mi).first); + } +} + +bool CBasicKeyStore::GetKey(const CKeyID &address, CKey &keyOut) const +{ + { + LOCK(cs_KeyStore); + KeyMap::const_iterator mi = mapKeys.find(address); + if (mi != mapKeys.end()) + { + keyOut.SetSecret((*mi).second.first, (*mi).second.second); + return true; + } + } + return false; +} + bool CBasicKeyStore::AddCScript(const CScript& redeemScript) { if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) @@ -45,7 +102,7 @@ bool CBasicKeyStore::AddCScript(const CScript& redeemScript) { LOCK(cs_KeyStore); - mapScripts[redeemScript.GetID()] = redeemScript; + mapScripts[CScriptID(redeemScript)] = redeemScript; } return true; } @@ -111,6 +168,77 @@ bool CBasicKeyStore::HaveWatchOnly() const return (!setWatchOnly.empty()); } +bool CBasicKeyStore::CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const +{ + { + LOCK(cs_KeyStore); + for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) + { + if (mi->first.CheckKeyVariant(R, pubKeyVariant)) + return true; + } + } + return false; +} + +bool CBasicKeyStore::CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const +{ + { + LOCK(cs_KeyStore); + for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) + { + if (mi->first.CheckKeyVariant(R, pubKeyVariant)) + { + view = mi->first; + return true; + } + } + } + return false; +} + +bool CBasicKeyStore::CreatePrivKey(const CPubKey &pubKeyVariant, const CPubKey &R, CKey &privKey) const +{ + { + LOCK(cs_KeyStore); + for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) + { + if (mi->first.CheckKeyVariant(R, pubKeyVariant)) + { + CMalleableKey mKey = mi->first.GetMalleableKey(mi->second); + return mKey.CheckKeyVariant(R, pubKeyVariant, privKey); + } + } + } + return false; +} + +void CBasicKeyStore::ListMalleableViews(std::list &malleableViewList) const +{ + malleableViewList.clear(); + { + LOCK(cs_KeyStore); + for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) + malleableViewList.push_back(CMalleableKeyView(mi->first)); + } +} + +bool CBasicKeyStore::GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view) +{ + const CKeyID &mpkID = mpk.GetID(); + { + LOCK(cs_KeyStore); + for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) + if (mi->first.GetID() == mpkID) + { + view = CMalleableKeyView(mi->first); + return true; + } + } + return false; +} + + bool CCryptoKeyStore::SetCrypted() { { @@ -124,6 +252,27 @@ bool CCryptoKeyStore::SetCrypted() return true; } +CCryptoKeyStore::CCryptoKeyStore() : fUseCrypto(false), fDecryptionThoroughlyChecked(false) +{ +} + +bool CCryptoKeyStore::IsCrypted() const +{ + return fUseCrypto; +} + +bool CCryptoKeyStore::IsLocked() const +{ + if (!IsCrypted()) + return false; + bool result; + { + LOCK(cs_KeyStore); + result = vMasterKey.empty(); + } + return result; +} + bool CCryptoKeyStore::Lock() { if (!SetCrypted()) @@ -266,6 +415,16 @@ bool CCryptoKeyStore::AddMalleableKey(const CMalleableKeyView& keyView, const CS return true; } +bool CCryptoKeyStore::HaveKey(const CKeyID &address) const +{ + { + LOCK(cs_KeyStore); + if (!IsCrypted()) + return CBasicKeyStore::HaveKey(address); + return mapCryptedKeys.count(address) > 0; + } +} + bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret) { { @@ -385,6 +544,90 @@ bool CCryptoKeyStore::GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) co return false; } +void CCryptoKeyStore::GetKeys(std::set &setAddress) const +{ + if (!IsCrypted()) + { + CBasicKeyStore::GetKeys(setAddress); + return; + } + setAddress.clear(); + CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); + while (mi != mapCryptedKeys.end()) + { + setAddress.insert((*mi).first); + mi++; + } +} + +bool CCryptoKeyStore::CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const +{ + { + LOCK(cs_KeyStore); + if (!IsCrypted()) + return CBasicKeyStore::CheckOwnership(pubKeyVariant, R); + for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) + { + if (mi->first.CheckKeyVariant(R, pubKeyVariant)) + return true; + } + } + return false; +} + +bool CCryptoKeyStore::CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const +{ + { + LOCK(cs_KeyStore); + if (!IsCrypted()) + return CBasicKeyStore::CheckOwnership(pubKeyVariant, R, view); + for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) + { + if (mi->first.CheckKeyVariant(R, pubKeyVariant)) + { + view = mi->first; + return true; + } + } + } + return false; +} + +bool CCryptoKeyStore::CheckOwnership(const CMalleablePubKey &mpk) +{ + CMalleableKeyView view; + return GetMalleableView(mpk, view); +} + +void CCryptoKeyStore::ListMalleableViews(std::list &malleableViewList) const +{ + malleableViewList.clear(); + { + LOCK(cs_KeyStore); + if (!IsCrypted()) + return CBasicKeyStore::ListMalleableViews(malleableViewList); + for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) + malleableViewList.push_back(CMalleableKeyView(mi->first)); + } +} + +bool CCryptoKeyStore::GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view) +{ + const CKeyID &mpkID = mpk.GetID(); + { + LOCK(cs_KeyStore); + if (!IsCrypted()) + return CBasicKeyStore::GetMalleableView(mpk, view); + for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) + if (mi->first.GetID() == mpkID) + { + view = CMalleableKeyView(mi->first); + return true; + } + } + return false; +} + bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) { { diff --git a/src/keystore.h b/src/keystore.h index 65398a1..a1080ad 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -60,14 +60,7 @@ public: virtual bool HaveWatchOnly(const CScript &dest) const =0; virtual bool HaveWatchOnly() const =0; - virtual bool GetSecret(const CKeyID &address, CSecret& vchSecret, bool &fCompressed) const - { - CKey key; - if (!GetKey(address, key)) - return false; - vchSecret = key.GetSecret(fCompressed); - return true; - } + virtual bool GetSecret(const CKeyID &address, CSecret& vchSecret, bool &fCompressed) const; virtual bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const =0; virtual bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const =0; @@ -93,51 +86,10 @@ protected: public: bool AddKey(const CKey& key); bool AddMalleableKey(const CMalleableKeyView& keyView, const CSecret &vchSecretH); - bool GetMalleableKey(const CMalleableKeyView &keyView, CMalleableKey &mKey) const - { - { - LOCK(cs_KeyStore); - MalleableKeyMap::const_iterator mi = mapMalleableKeys.find(keyView); - if (mi != mapMalleableKeys.end()) - { - mKey = mi->first.GetMalleableKey(mi->second); - return true; - } - } - return false; - } - - bool HaveKey(const CKeyID &address) const - { - bool result; - { - LOCK(cs_KeyStore); - result = (mapKeys.count(address) > 0); - } - return result; - } - void GetKeys(std::set &setAddress) const - { - setAddress.clear(); - { - LOCK(cs_KeyStore); - KeyMap::const_iterator mi; - for (mi = mapKeys.begin(); mi != mapKeys.end(); ++mi) setAddress.insert((*mi).first); - } - } - bool GetKey(const CKeyID &address, CKey &keyOut) const - { - { - LOCK(cs_KeyStore); - KeyMap::const_iterator mi = mapKeys.find(address); - if (mi != mapKeys.end()) - { - keyOut.SetSecret((*mi).second.first, (*mi).second.second); - return true; - } - } - return false; - } + bool GetMalleableKey(const CMalleableKeyView &keyView, CMalleableKey &mKey) const; + bool HaveKey(const CKeyID &address) const; + void GetKeys(std::set &setAddress) const; + bool GetKey(const CKeyID &address, CKey &keyOut) const; virtual bool AddCScript(const CScript& redeemScript); virtual bool HaveCScript(const CScriptID &hash) const; virtual bool GetCScript(const CScriptID &hash, CScript& redeemScriptOut) const; @@ -147,76 +99,11 @@ public: virtual bool HaveWatchOnly(const CScript &dest) const; virtual bool HaveWatchOnly() const; - bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const - { - { - LOCK(cs_KeyStore); - for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) - { - if (mi->first.CheckKeyVariant(R, pubKeyVariant)) - return true; - } - } - return false; - } - - bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const - { - { - LOCK(cs_KeyStore); - for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) - { - if (mi->first.CheckKeyVariant(R, pubKeyVariant)) - { - view = mi->first; - return true; - } - } - } - return false; - } - - bool CreatePrivKey(const CPubKey &pubKeyVariant, const CPubKey &R, CKey &privKey) const - { - { - LOCK(cs_KeyStore); - for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) - { - if (mi->first.CheckKeyVariant(R, pubKeyVariant)) - { - CMalleableKey mKey = mi->first.GetMalleableKey(mi->second); - return mKey.CheckKeyVariant(R, pubKeyVariant, privKey); - } - } - } - return false; - } - - void ListMalleableViews(std::list &malleableViewList) const - { - malleableViewList.clear(); - { - LOCK(cs_KeyStore); - for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) - malleableViewList.push_back(CMalleableKeyView(mi->first)); - } - } - - bool GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view) - { - const CKeyID &mpkID = mpk.GetID(); - { - LOCK(cs_KeyStore); - for (MalleableKeyMap::const_iterator mi = mapMalleableKeys.begin(); mi != mapMalleableKeys.end(); mi++) - if (mi->first.GetID() == mpkID) - { - view = CMalleableKeyView(mi->first); - return true; - } - } - - return false; - } + bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const; + bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const; + bool CreatePrivKey(const CPubKey &pubKeyVariant, const CPubKey &R, CKey &privKey) const; + void ListMalleableViews(std::list &malleableViewList) const; + bool GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view); }; typedef std::map > > CryptedKeyMap; @@ -250,25 +137,10 @@ protected: bool Unlock(const CKeyingMaterial& vMasterKeyIn); public: - CCryptoKeyStore() : fUseCrypto(false), fDecryptionThoroughlyChecked(false) { } - - bool IsCrypted() const - { - return fUseCrypto; - } - - bool IsLocked() const - { - if (!IsCrypted()) - return false; - bool result; - { - LOCK(cs_KeyStore); - result = vMasterKey.empty(); - } - return result; - } + CCryptoKeyStore(); + bool IsCrypted() const; + bool IsLocked() const; bool Lock(); virtual bool AddCryptedKey(const CPubKey &vchPubKey, const std::vector &vchCryptedSecret); @@ -276,106 +148,17 @@ public: bool AddKey(const CKey& key); bool AddMalleableKey(const CMalleableKeyView& keyView, const CSecret &vchSecretH); - bool HaveKey(const CKeyID &address) const - { - { - LOCK(cs_KeyStore); - if (!IsCrypted()) - return CBasicKeyStore::HaveKey(address); - return mapCryptedKeys.count(address) > 0; - } - } + bool HaveKey(const CKeyID &address) const; bool GetKey(const CKeyID &address, CKey& keyOut) const; bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const; - void GetKeys(std::set &setAddress) const - { - if (!IsCrypted()) - { - CBasicKeyStore::GetKeys(setAddress); - return; - } - setAddress.clear(); - CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); - while (mi != mapCryptedKeys.end()) - { - setAddress.insert((*mi).first); - mi++; - } - } - + void GetKeys(std::set &setAddress) const; bool GetMalleableKey(const CMalleableKeyView &keyView, CMalleableKey &mKey) const; - - bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const - { - { - LOCK(cs_KeyStore); - if (!IsCrypted()) - return CBasicKeyStore::CheckOwnership(pubKeyVariant, R); - for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) - { - if (mi->first.CheckKeyVariant(R, pubKeyVariant)) - return true; - } - } - return false; - } - - bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const - { - { - LOCK(cs_KeyStore); - if (!IsCrypted()) - return CBasicKeyStore::CheckOwnership(pubKeyVariant, R, view); - for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) - { - if (mi->first.CheckKeyVariant(R, pubKeyVariant)) - { - view = mi->first; - return true; - } - } - } - return false; - } - - bool CheckOwnership(const CMalleablePubKey &mpk) - { - CMalleableKeyView view; - return GetMalleableView(mpk, view); - } - + bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R) const; + bool CheckOwnership(const CPubKey &pubKeyVariant, const CPubKey &R, CMalleableKeyView &view) const; + bool CheckOwnership(const CMalleablePubKey &mpk); bool CreatePrivKey(const CPubKey &pubKeyVariant, const CPubKey &R, CKey &privKey) const; - - void ListMalleableViews(std::list &malleableViewList) const - { - malleableViewList.clear(); - { - LOCK(cs_KeyStore); - if (!IsCrypted()) - return CBasicKeyStore::ListMalleableViews(malleableViewList); - for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) - malleableViewList.push_back(CMalleableKeyView(mi->first)); - } - } - - bool GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view) - { - const CKeyID &mpkID = mpk.GetID(); - { - LOCK(cs_KeyStore); - if (!IsCrypted()) - return CBasicKeyStore::GetMalleableView(mpk, view); - for (CryptedMalleableKeyMap::const_iterator mi = mapCryptedMalleableKeys.begin(); mi != mapCryptedMalleableKeys.end(); mi++) - if (mi->first.GetID() == mpkID) - { - view = CMalleableKeyView(mi->first); - return true; - } - } - - return false; - } - + void ListMalleableViews(std::list &malleableViewList) const; + bool GetMalleableView(const CMalleablePubKey &mpk, CMalleableKeyView &view); /* Wallet status (encrypted, locked) changed. * Note: Called without locks held. */ diff --git a/src/main.h b/src/main.h index 62417c7..1a61a63 100644 --- a/src/main.h +++ b/src/main.h @@ -54,8 +54,6 @@ static const int64_t MIN_TXOUT_AMOUNT = CENT/100; inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } inline bool MoneyRange(CBigNum nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } -// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. -static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC // Maximum number of script-checking threads allowed static const int MAX_SCRIPTCHECK_THREADS = 16; diff --git a/src/net.cpp b/src/net.cpp index bf2f38b..7137f1d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -789,13 +789,6 @@ void CNode::copyStats(CNodeStats &stats) } #undef X -void Release(CNode* node) { - node->Release(); -} - - - - void ThreadSocketHandler(void* parg) { @@ -1143,7 +1136,8 @@ void ThreadSocketHandler2(void* parg) } { LOCK(cs_vNodes); - for_each(vNodesCopy.begin(), vNodesCopy.end(), Release); + for(CNode* pnode : vNodesCopy) + pnode->Release(); } Sleep(10); @@ -1716,7 +1710,8 @@ void ThreadMessageHandler2(void* parg) { LOCK(cs_vNodes); - for_each(vNodesCopy.begin(), vNodesCopy.end(), Release); + for(CNode* pnode : vNodesCopy) + pnode->Release(); } // Wait and allow messages to bunch up. diff --git a/src/netbase.cpp b/src/netbase.cpp index ebc5f9f..79c5b2a 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -25,7 +25,7 @@ using namespace std; // Settings static proxyType proxyInfo[NET_MAX]; -static proxyType nameproxyInfo; +static CService nameProxy; static CCriticalSection cs_proxyInfos; int nConnectTimeout = 5000; bool fNameLookup = false; @@ -179,50 +179,6 @@ bool LookupNumeric(const char *pszName, CService& addr, uint16_t portDefault) return Lookup(pszName, addr, portDefault, false); } -bool static Socks4(const CService &addrDest, SOCKET& hSocket) -{ - printf("SOCKS4 connecting %s\n", addrDest.ToString().c_str()); - if (!addrDest.IsIPv4()) - { - CloseSocket(hSocket); - return error("Proxy destination is not IPv4"); - } - char pszSocks4IP[] = "\4\1\0\0\0\0\0\0user"; - struct sockaddr_in addr; - socklen_t len = sizeof(addr); - if (!addrDest.GetSockAddr((struct sockaddr*)&addr, &len) || addr.sin_family != AF_INET) - { - CloseSocket(hSocket); - return error("Cannot get proxy destination address"); - } - memcpy(pszSocks4IP + 2, &addr.sin_port, 2); - memcpy(pszSocks4IP + 4, &addr.sin_addr, 4); - char* pszSocks4 = pszSocks4IP; - int nSize = sizeof(pszSocks4IP); - - int ret = send(hSocket, pszSocks4, nSize, MSG_NOSIGNAL); - if (ret != nSize) - { - CloseSocket(hSocket); - return error("Error sending to proxy"); - } - char pchRet[8]; - if (recv(hSocket, pchRet, 8, 0) != 8) - { - CloseSocket(hSocket); - return error("Error reading proxy response"); - } - if (pchRet[1] != 0x5a) - { - CloseSocket(hSocket); - if (pchRet[1] != 0x5b) - printf("ERROR: Proxy returned error %d\n", pchRet[1]); - return false; - } - printf("SOCKS4 connected %s\n", addrDest.ToString().c_str()); - return true; -} - bool static Socks5(string strDest, uint16_t port, SOCKET& hSocket) { printf("SOCKS5 connecting %s\n", strDest.c_str()); @@ -435,53 +391,49 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe return true; } -bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion) { +bool SetProxy(enum Network net, CService addrProxy) { assert(net >= 0 && net < NET_MAX); - if (nSocksVersion != 0 && nSocksVersion != 4 && nSocksVersion != 5) - return false; - if (nSocksVersion != 0 && !addrProxy.IsValid()) + if (!addrProxy.IsValid()) return false; LOCK(cs_proxyInfos); - proxyInfo[net] = std::make_pair(addrProxy, nSocksVersion); + proxyInfo[net] = addrProxy; return true; } bool GetProxy(enum Network net, proxyType &proxyInfoOut) { assert(net >= 0 && net < NET_MAX); LOCK(cs_proxyInfos); - if (!proxyInfo[net].second) + if (!proxyInfo[net].IsValid()) return false; proxyInfoOut = proxyInfo[net]; return true; } -bool SetNameProxy(CService addrProxy, int nSocksVersion) { - if (nSocksVersion != 0 && nSocksVersion != 5) - return false; - if (nSocksVersion != 0 && !addrProxy.IsValid()) +bool SetNameProxy(CService addrProxy) { + if (!addrProxy.IsValid()) return false; LOCK(cs_proxyInfos); - nameproxyInfo = std::make_pair(addrProxy, nSocksVersion); + nameProxy = addrProxy; return true; } -bool GetNameProxy(proxyType &nameproxyInfoOut) { +bool GetNameProxy(CService &nameProxyOut) { LOCK(cs_proxyInfos); - if (!nameproxyInfo.second) + if (!nameProxy.IsValid()) return false; - nameproxyInfoOut = nameproxyInfo; + nameProxyOut = nameProxy; return true; } bool HaveNameProxy() { LOCK(cs_proxyInfos); - return nameproxyInfo.second != 0; + return nameProxy.IsValid(); } bool IsProxy(const CNetAddr &addr) { LOCK(cs_proxyInfos); for (int i = 0; i < NET_MAX; i++) { - if (proxyInfo[i].second && (addr == (CNetAddr)proxyInfo[i].first)) + if (addr == (CNetAddr)proxyInfo[i]) return true; } return false; @@ -498,23 +450,12 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout) SOCKET hSocket = INVALID_SOCKET; // first connect to proxy server - if (!ConnectSocketDirectly(proxy.first, hSocket, nTimeout)) + if (!ConnectSocketDirectly(proxy, hSocket, nTimeout)) return false; // do socks negotiation - switch (proxy.second) { - case 4: - if (!Socks4(addrDest, hSocket)) - return false; - break; - case 5: - if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket)) - return false; - break; - default: - CloseSocket(hSocket); + if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket)) return false; - } hSocketRet = hSocket; return true; @@ -528,30 +469,23 @@ bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest SOCKET hSocket = INVALID_SOCKET; - proxyType nameproxy; - GetNameProxy(nameproxy); + CService nameProxy; + GetNameProxy(nameProxy); - CService addrResolved(CNetAddr(strDest, fNameLookup && !nameproxy.second), port); + CService addrResolved(CNetAddr(strDest, fNameLookup && !HaveNameProxy()), port); if (addrResolved.IsValid()) { addr = addrResolved; return ConnectSocket(addr, hSocketRet, nTimeout); } addr = CService("0.0.0.0:0"); - if (!nameproxy.second) + if (!HaveNameProxy) return false; - if (!ConnectSocketDirectly(nameproxy.first, hSocket, nTimeout)) + // first connect to name proxy server + if (!ConnectSocketDirectly(nameProxy, hSocket, nTimeout)) + return false; + // do socks negotiation + if (!Socks5(strDest, port, hSocket)) return false; - - switch(nameproxy.second) { - default: - case 4: - CloseSocket(hSocket); - return false; - case 5: - if (!Socks5(strDest, port, hSocket)) - return false; - break; - } hSocketRet = hSocket; return true; diff --git a/src/netbase.h b/src/netbase.h index 14c632e..e6f3e6d 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -126,14 +126,14 @@ class CService : public CNetAddr ) }; -typedef std::pair proxyType; +typedef CService proxyType; enum Network ParseNetwork(std::string net); void SplitHostPort(std::string in, uint16_t &portOut, std::string &hostOut); -bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion = 5); +bool SetProxy(enum Network net, CService addrProxy); bool GetProxy(enum Network net, proxyType &proxyInfoOut); bool IsProxy(const CNetAddr &addr); -bool SetNameProxy(CService addrProxy, int nSocksVersion = 5); +bool SetNameProxy(CService addrProxy); bool HaveNameProxy(); bool LookupHost(const std::string& strName, std::vector& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true); bool LookupHost(const char *pszName, std::vector& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true); diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 9460657..16cdf3a 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -339,9 +339,9 @@ void AddressBookPage::exportClicked() } } +#ifdef USE_QRCODE void AddressBookPage::on_showQRCode_clicked() { - #ifdef USE_QRCODE QTableView *table = ui->tableView; QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address); @@ -355,8 +355,8 @@ void AddressBookPage::on_showQRCode_clicked() dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } -#endif } +#endif void AddressBookPage::contextualMenu(const QPoint &point) { diff --git a/src/qt/addressbookpage.h b/src/qt/addressbookpage.h index df87486..87ad27b 100644 --- a/src/qt/addressbookpage.h +++ b/src/qt/addressbookpage.h @@ -65,7 +65,9 @@ private slots: void on_signMessage_clicked(); void on_verifyMessage_clicked(); void selectionChanged(); +#ifdef USE_QRCODE void on_showQRCode_clicked(); +#endif /** Spawn contextual menu (right mouse menu) for address book entry */ void contextualMenu(const QPoint &point); diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 7cf60cf..d843ffe 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -185,26 +185,6 @@ - - - SOCKS &Version: - - - Qt::PlainText - - - socksVersion - - - - - - - SOCKS version of the proxy (e.g. 5) - - - - Qt::Horizontal diff --git a/src/qt/multisigdialog.cpp b/src/qt/multisigdialog.cpp index 6f0851c..3f4c93f 100644 --- a/src/qt/multisigdialog.cpp +++ b/src/qt/multisigdialog.cpp @@ -190,7 +190,7 @@ void MultisigDialog::on_createAddressButton_clicked() QMessageBox::warning(this, tr("Error"), tr("Redeem script exceeds size limit: %1 > %2\nReduce the number of addresses involved in the address creation.").arg(script.size()).arg(MAX_SCRIPT_ELEMENT_SIZE), QMessageBox::Ok); return; } - CScriptID scriptID = script.GetID(); + CScriptID scriptID(script); CBitcoinAddress address(scriptID); ui->multisigAddress->setText(address.ToString().c_str()); @@ -216,7 +216,7 @@ void MultisigDialog::on_saveRedeemScriptButton_clicked() std::string redeemScript = ui->redeemScript->text().toStdString(); std::vector scriptData(ParseHex(redeemScript)); CScript script(scriptData.begin(), scriptData.end()); - CScriptID scriptID = script.GetID(); + CScriptID scriptID(script); LOCK(wallet->cs_wallet); if(!wallet->HaveCScript(scriptID)) @@ -238,7 +238,7 @@ void MultisigDialog::on_saveMultisigAddressButton_clicked() std::vector scriptData(ParseHex(redeemScript)); CScript script(scriptData.begin(), scriptData.end()); - CScriptID scriptID = script.GetID(); + CScriptID scriptID(script); LOCK(wallet->cs_wallet); if(!wallet->HaveCScript(scriptID)) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index adb6ffb..dc3122a 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -47,14 +47,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) : ui->TorOnly->setEnabled(false); ui->torName->setEnabled(false); - ui->socksVersion->setEnabled(false); - ui->socksVersion->addItem("5", 5); - ui->socksVersion->addItem("4", 4); - ui->socksVersion->setCurrentIndex(0); - connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool))); - connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool))); connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Proxy())); connect(ui->connectTor, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning_Tor())); @@ -164,7 +158,6 @@ void OptionsDialog::setMapper() mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse); mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP); mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort); - mapper->addMapping(ui->socksVersion, OptionsModel::ProxySocksVersion); mapper->addMapping(ui->connectTor, OptionsModel::TorUse); mapper->addMapping(ui->torIp, OptionsModel::TorIP); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 80fc84f..7e80615 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -16,25 +16,21 @@ bool static ApplyProxySettings() { QSettings settings; CService addrProxy(settings.value("addrProxy", "127.0.0.1:9050").toString().toStdString()); - int nSocksVersion(settings.value("nSocksVersion", 5).toInt()); if (!settings.value("fUseProxy", false).toBool()) { addrProxy = CService(); - nSocksVersion = 0; return false; } - if (nSocksVersion && !addrProxy.IsValid()) + if (!addrProxy.IsValid()) return false; if (!IsLimited(NET_IPV4)) - SetProxy(NET_IPV4, addrProxy, nSocksVersion); - if (nSocksVersion > 4) { + SetProxy(NET_IPV4, addrProxy); #ifdef USE_IPV6 if (!IsLimited(NET_IPV6)) - SetProxy(NET_IPV6, addrProxy, nSocksVersion); + SetProxy(NET_IPV6, addrProxy); #endif - } - SetNameProxy(addrProxy, nSocksVersion); + SetNameProxy(addrProxy); return true; } @@ -50,7 +46,7 @@ bool static ApplyTorSettings() if (!addrTor.IsValid()) return false; - SetProxy(NET_TOR, addrTor, 5); + SetProxy(NET_TOR, addrTor); SetReachable(NET_TOR); return true; @@ -132,32 +128,30 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const case ProxyIP: { proxyType proxy; if (GetProxy(NET_IPV4, proxy)) - return QVariant(QString::fromStdString(proxy.first.ToStringIP())); + return QVariant(QString::fromStdString(proxy.ToStringIP())); else return QVariant(QString::fromStdString("127.0.0.1")); } case ProxyPort: { proxyType proxy; if (GetProxy(NET_IPV4, proxy)) - return QVariant(proxy.first.GetPort()); + return QVariant(proxy.GetPort()); else return QVariant(nSocksDefault); } - case ProxySocksVersion: - return settings.value("nSocksVersion", 5); case TorUse: return settings.value("fUseTor", false); case TorIP: { proxyType proxy; if (GetProxy(NET_TOR, proxy)) - return QVariant(QString::fromStdString(proxy.first.ToStringIP())); + return QVariant(QString::fromStdString(proxy.ToStringIP())); else return QVariant(QString::fromStdString("127.0.0.1")); } case TorPort: { proxyType proxy; if (GetProxy(NET_TOR, proxy)) - return QVariant(proxy.first.GetPort()); + return QVariant(proxy.GetPort()); else return QVariant(nSocksDefault); } @@ -213,32 +207,22 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; case ProxyIP: { proxyType proxy; - proxy.first = CService("127.0.0.1", nSocksDefault); + proxy = CService("127.0.0.1", nSocksDefault); GetProxy(NET_IPV4, proxy); CNetAddr addr(value.toString().toStdString()); - proxy.first.SetIP(addr); - settings.setValue("addrProxy", proxy.first.ToStringIPPort().c_str()); + proxy.SetIP(addr); + settings.setValue("addrProxy", proxy.ToStringIPPort().c_str()); successful = ApplyProxySettings(); } break; case ProxyPort: { proxyType proxy; - proxy.first = CService("127.0.0.1", nSocksDefault); - GetProxy(NET_IPV4, proxy); - - proxy.first.SetupPort(value.toInt()); - settings.setValue("addrProxy", proxy.first.ToStringIPPort().c_str()); - successful = ApplyProxySettings(); - } - break; - case ProxySocksVersion: { - proxyType proxy; - proxy.second = 5; + proxy = CService("127.0.0.1", nSocksDefault); GetProxy(NET_IPV4, proxy); - proxy.second = value.toInt(); - settings.setValue("nSocksVersion", proxy.second); + proxy.SetupPort(value.toInt()); + settings.setValue("addrProxy", proxy.ToStringIPPort().c_str()); successful = ApplyProxySettings(); } break; @@ -249,22 +233,22 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in break; case TorIP: { proxyType proxy; - proxy.first = CService("127.0.0.1", nSocksDefault); + proxy = CService("127.0.0.1", nSocksDefault); GetProxy(NET_TOR, proxy); CNetAddr addr(value.toString().toStdString()); - proxy.first.SetIP(addr); - settings.setValue("addrTor", proxy.first.ToStringIPPort().c_str()); + proxy.SetIP(addr); + settings.setValue("addrTor", proxy.ToStringIPPort().c_str()); successful = ApplyTorSettings(); } break; case TorPort: { proxyType proxy; - proxy.first = CService("127.0.0.1", nSocksDefault); + proxy = CService("127.0.0.1", nSocksDefault); GetProxy(NET_TOR, proxy); - proxy.first.SetupPort((uint16_t)value.toUInt()); - settings.setValue("addrTor", proxy.first.ToStringIPPort().c_str()); + proxy.SetupPort((uint16_t)value.toUInt()); + settings.setValue("addrTor", proxy.ToStringIPPort().c_str()); successful = ApplyTorSettings(); } break; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 9092655..03b13be 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -29,7 +29,7 @@ Value getsubsidy(const Array& params, bool fHelp) if (params.size() != 0) { - CBigNum bnTarget(uint256(params[0].get_str())); + uint256 bnTarget(params[0].get_str()); nBits = bnTarget.GetCompact(); } else @@ -104,7 +104,7 @@ Value scaninput(const Array& params, bool fHelp) if (dDiff <= 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, diff must be greater than zero"); - CBigNum bnTarget(nPoWBase); + uint256 bnTarget(nPoWBase); bnTarget *= 1000; bnTarget /= (int) (dDiff * 1000); nBits = bnTarget.GetCompact(); @@ -292,13 +292,13 @@ Value getworkex(const Array& params, bool fHelp) char phash1[64]; FormatHashBuffers(pblock, pmidstate, pdata, phash1); - auto hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); + auto hashTarget = uint256().SetCompact(pblock->nBits); auto coinbaseTx = pblock->vtx[0]; auto merkle = pblock->GetMerkleBranch(0); Object result; - result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata)))); + result.push_back(Pair("data", HexStr(begin(pdata), end(pdata)))); result.push_back(Pair("target", HexStr(hashTarget.begin(), hashTarget.end()))); CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); @@ -431,12 +431,12 @@ Value getwork(const Array& params, bool fHelp) char phash1[64]; FormatHashBuffers(pblock, pmidstate, pdata, phash1); - auto hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); + auto hashTarget = uint256().SetCompact(pblock->nBits); Object result; - result.push_back(Pair("midstate", HexStr(BEGIN(pmidstate), END(pmidstate)))); // deprecated - result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata)))); - result.push_back(Pair("hash1", HexStr(BEGIN(phash1), END(phash1)))); // deprecated + result.push_back(Pair("midstate", HexStr(begin(pmidstate), end(pmidstate)))); // deprecated + result.push_back(Pair("data", HexStr(begin(pdata), end(pdata)))); + result.push_back(Pair("hash1", HexStr(begin(phash1), end(phash1)))); // deprecated result.push_back(Pair("target", HexStr(hashTarget.begin(), hashTarget.end()))); return result; } @@ -595,7 +595,7 @@ Value getblocktemplate(const Array& params, bool fHelp) Object aux; aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end()))); - auto hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); + auto hashTarget = uint256().SetCompact(pblock->nBits); static Array aMutable; if (aMutable.empty()) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index b3b3c31..3359338 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -368,7 +368,7 @@ Value decodescript(const Array& params, bool fHelp) } ScriptPubKeyToJSON(script, r, false); - r.push_back(Pair("p2sh", CBitcoinAddress(script.GetID()).ToString())); + r.push_back(Pair("p2sh", CBitcoinAddress(CScriptID(script)).ToString())); return r; } @@ -690,7 +690,7 @@ Value createmultisig(const Array& params, bool fHelp) throw runtime_error( strprintf("redeemScript exceeds size limit: %" PRIszu " > %d", inner.size(), MAX_SCRIPT_ELEMENT_SIZE)); - auto innerID = inner.GetID(); + auto innerID = CScriptID(inner); CBitcoinAddress address(innerID); Object result; diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index ef9276c..8f82c97 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -95,7 +95,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("moneysupply", ValueFromAmount(pindexBest->nMoneySupply))); obj.push_back(Pair("connections", (int)vNodes.size())); - obj.push_back(Pair("proxy", (proxy.first.IsValid() ? proxy.first.ToStringIPPort() : string()))); + obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.ToStringIPPort() : string()))); obj.push_back(Pair("ip", addrSeenByPeer.ToStringIP())); diff.push_back(Pair("proof-of-work", GetDifficulty())); @@ -889,7 +889,7 @@ Value addmultisigaddress(const Array& params, bool fHelp) strprintf("redeemScript exceeds size limit: %" PRIszu " > %d", inner.size(), MAX_SCRIPT_ELEMENT_SIZE)); pwalletMain->AddCScript(inner); - CBitcoinAddress address(inner.GetID()); + CBitcoinAddress address{ CScriptID(inner) }; // "most vexing parse" pwalletMain->SetAddressBookName(address, strAccount); return address.ToString(); @@ -913,7 +913,7 @@ Value addredeemscript(const Array& params, bool fHelp) auto innerData = ParseHexV(params[0], "redeemScript"); CScript inner(innerData.begin(), innerData.end()); pwalletMain->AddCScript(inner); - CBitcoinAddress address(inner.GetID()); + CBitcoinAddress address{ CScriptID(inner) }; // "most vexing parse" pwalletMain->SetAddressBookName(address, strAccount); return address.ToString(); diff --git a/src/script.cpp b/src/script.cpp index b18d4fe..c4f8d3b 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1710,7 +1710,11 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) if (whichType == TX_PUBKEY) { - addressRet = CPubKey(vSolutions[0]).GetID(); + CPubKey pubKey(vSolutions[0]); + if (!pubKey.IsValid()) + return false; + + addressRet = pubKey.GetID(); return true; } else if (whichType == TX_PUBKEYHASH) @@ -1819,9 +1823,16 @@ bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, vecto nRequiredRet = vSolutions.front()[0]; for (unsigned int i = 1; i < vSolutions.size()-1; i++) { - CTxDestination address = CPubKey(vSolutions[i]).GetID(); + CPubKey pubKey(vSolutions[i]); + if (!pubKey.IsValid()) + continue; + + CTxDestination address = pubKey.GetID(); addressRet.push_back(address); } + + if (addressRet.empty()) + return false; } else { @@ -2478,8 +2489,3 @@ void CScript::print() const { printf("%s\n", ToString().c_str()); } - -CScriptID CScript::GetID() const -{ - return CScriptID(Hash160(*this)); -} diff --git a/src/script.h b/src/script.h index 28def01..17e3d36 100644 --- a/src/script.h +++ b/src/script.h @@ -375,7 +375,6 @@ public: void PrintHex() const; std::string ToString(bool fShort=false) const; void print() const; - CScriptID GetID() const; }; bool IsCanonicalPubKey(const std::vector &vchPubKey, unsigned int flags); diff --git a/src/serialize.h b/src/serialize.h index ddff706..c0471bb 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -103,8 +103,6 @@ enum - - // // Basic types // @@ -160,8 +158,6 @@ template inline void Unserialize(Stream& s, bool& a, int, int=0 - - // // Compact size // size < 253 -- 1 byte @@ -349,11 +345,6 @@ template unsigned int GetSerializeSize(co template void Serialize(Stream& os, const std::tuple& item, int nType, int nVersion); template void Unserialize(Stream& is, std::tuple& item, int nType, int nVersion); -// 4 tuple -template unsigned int GetSerializeSize(const std::tuple& item, int nType, int nVersion); -template void Serialize(Stream& os, const std::tuple& item, int nType, int nVersion); -template void Unserialize(Stream& is, std::tuple& item, int nType, int nVersion); - // map template unsigned int GetSerializeSize(const std::map& m, int nType, int nVersion); template void Serialize(Stream& os, const std::map& m, int nType, int nVersion); @@ -367,7 +358,6 @@ template void Unserializ - // // If none of the specialized versions above matched, default to calling member function. // "int nType" is changed to "long nType" to keep from getting an ambiguous overload error. @@ -395,7 +385,6 @@ inline void Unserialize(Stream& is, T& a, long nType, int nVersion) - // // string // @@ -593,40 +582,6 @@ void Unserialize(Stream& is, std::tuple& item, int nType, int nVersi // -// 4 tuple -// -template -unsigned int GetSerializeSize(const std::tuple& item, int nType, int nVersion) -{ - unsigned int nSize = 0; - nSize += GetSerializeSize(std::get<0>(item), nType, nVersion); - nSize += GetSerializeSize(std::get<1>(item), nType, nVersion); - nSize += GetSerializeSize(std::get<2>(item), nType, nVersion); - nSize += GetSerializeSize(std::get<3>(item), nType, nVersion); - return nSize; -} - -template -void Serialize(Stream& os, const std::tuple& item, int nType, int nVersion) -{ - Serialize(os, std::get<0>(item), nType, nVersion); - Serialize(os, std::get<1>(item), nType, nVersion); - Serialize(os, std::get<2>(item), nType, nVersion); - Serialize(os, std::get<3>(item), nType, nVersion); -} - -template -void Unserialize(Stream& is, std::tuple& item, int nType, int nVersion) -{ - Unserialize(is, std::get<0>(item), nType, nVersion); - Unserialize(is, std::get<1>(item), nType, nVersion); - Unserialize(is, std::get<2>(item), nType, nVersion); - Unserialize(is, std::get<3>(item), nType, nVersion); -} - - - -// // map // template @@ -734,13 +689,6 @@ struct ser_streamplaceholder - - - - - - - typedef std::vector > CSerializeData; /** Double ended buffer combining vector and stream-like interfaces. diff --git a/src/timestamps.h b/src/timestamps.h index 57382bd..218a429 100644 --- a/src/timestamps.h +++ b/src/timestamps.h @@ -3,4 +3,6 @@ static const unsigned int TARGETS_SWITCH_TIME = 1374278400; // Saturday, 20-Jul-2013 00:00:00 UTC static const unsigned int CHECKLOCKTIMEVERIFY_SWITCH_TIME = 1461110400; // Wednesday, 20-Apr-16 00:00:00 UTC +// Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. +static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC #endif diff --git a/src/wallet.cpp b/src/wallet.cpp index 9baa959..c90b374 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -229,7 +229,7 @@ bool CWallet::LoadCScript(const CScript& redeemScript) * these. Do not add them to the wallet and warn. */ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { - auto strAddr = CBitcoinAddress(redeemScript.GetID()).ToString(); + auto strAddr = CBitcoinAddress(CScriptID(redeemScript)).ToString(); printf("LoadCScript() : Warning: This wallet contains a redeemScript of size %" PRIszu " which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr.c_str()); return true;