Includes cleanup
authorsvost <ya.nowa@yandex.ru>
Thu, 15 Feb 2024 21:07:18 +0000 (00:07 +0300)
committersvost <ya.nowa@yandex.ru>
Thu, 15 Feb 2024 21:07:18 +0000 (00:07 +0300)
src/base58.cpp
src/bignum.cpp
src/bignum.h
src/crypter.cpp
src/db.cpp
src/key.cpp
src/key.h
src/keystore.h
src/script.cpp
src/script.h

index 2a6e6e7..f57c4c6 100644 (file)
@@ -14,6 +14,7 @@
 //
 
 #include "base58.h"
+#include "hash.h"
 
 static const std::array<char, 58> digits = {
     '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
index ad79919..1bbc5ea 100644 (file)
@@ -1,4 +1,5 @@
 #include "bignum.h"
+#include "uint256.h"
 
 
 CAutoBN_CTX::CAutoBN_CTX() {
@@ -45,6 +46,8 @@ CBigNum::~CBigNum() {
     BN_clear_free(bn);
 }
 
+CBigNum::CBigNum(uint256 n) { bn = BN_new(); setuint256(n); }
+
 void CBigNum::setuint32(uint32_t n) {
     if (!BN_set_word(bn, n))
         throw bignum_error("CBigNum conversion from uint32_t : BN_set_word failed");
index 418f343..57470c8 100644 (file)
@@ -7,7 +7,6 @@
 
 
 #include "serialize.h"
-#include "uint256.h"
 #include "version.h"
 
 #include <openssl/bn.h>
@@ -16,6 +15,9 @@
 #include <vector>
 #include <algorithm>
 
+class uint160;
+class uint256;
+
 /** Errors thrown by the bignum class */
 class bignum_error : public std::runtime_error
 {
@@ -67,7 +69,7 @@ public:
     CBigNum(uint32_t n) { bn = BN_new(); setuint32(n); }
     CBigNum(uint64_t n) { bn = BN_new(); setuint64(n); }
 
-    explicit CBigNum(uint256 n) { bn = BN_new(); setuint256(n); }
+    explicit CBigNum(uint256 n);
     explicit CBigNum(const std::vector<uint8_t>& vch) { bn = BN_new(); setvch(vch); }
 
     void setuint32(uint32_t n);
index 44f7cf3..313fecb 100644 (file)
@@ -2,12 +2,10 @@
 // Distributed under the MIT/X11 software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
-#include <openssl/evp.h>
-#include <vector>
-#include <string>
-
 #include "crypter.h"
 
+#include <openssl/evp.h>
+
 
 bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector<unsigned char>& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod)
 {
index f252972..81b1bc7 100644 (file)
@@ -7,6 +7,7 @@
 #include "util.h"
 #include "addrman.h"
 #include "random.h"
+#include "hash.h"
 
 #include <boost/filesystem.hpp>
 #include <boost/filesystem/fstream.hpp>
index 2df613b..82c8b34 100644 (file)
@@ -2,14 +2,14 @@
 // Distributed under the MIT/X11 software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
-#include <map>
+#include "key.h"
+#include "base58.h"
+#include "streams.h"
+#include "hash.h"
 
 #include <openssl/ecdsa.h>
 #include <openssl/evp.h>
 
-#include "key.h"
-#include "base58.h"
-#include "streams.h"
 
 // Generate a private key from just the secret parameter
 int EC_KEY_regenerate_key(EC_KEY *eckey, BIGNUM *priv_key)
@@ -516,6 +516,16 @@ bool CPubKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>
     return fSuccessful;
 }
 
+CKeyID CPubKey::GetID() const
+{
+    return CKeyID(Hash160(vbytes, vbytes + size()));
+}
+
+uint256 CPubKey::GetHash() const
+{
+    return Hash(vbytes, vbytes + size());
+}
+
 bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const
 {
     if (vchSig.empty() || !IsValid())
@@ -1175,6 +1185,8 @@ bool CMalleableKeyView::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubK
     return true;
 }
 
+bool CMalleableKeyView::operator <(const CMalleableKeyView &kv) const { return vchPubKeyH.GetID() < kv.vchPubKeyH.GetID(); }
+
 std::string CMalleableKeyView::ToString() const
 {
     CDataStream ssKey(SER_NETWORK, PROTOCOL_VERSION);
@@ -1214,3 +1226,11 @@ bool CMalleableKeyView::IsValid() const
 {
     return vchSecretL.size() == 32 && GetMalleablePubKey().IsValid();
 }
+
+CScriptID::CScriptID() : uint160(0) { }
+
+CScriptID::CScriptID(const uint160 &in) : uint160(in) { }
+
+CKeyID::CKeyID() : uint160(0) { }
+
+CKeyID::CKeyID(const uint160 &in) : uint160(in) { }
index 8dd8f16..6e7196e 100644 (file)
--- a/src/key.h
+++ b/src/key.h
 #include "allocators.h"
 #include "serialize.h"
 #include "uint256.h"
-#include "hash.h"
 #include "bignum.h"
 
 #include <openssl/ec.h> // for EC_KEY definition
 #include <openssl/obj_mac.h>
 
+
 // secp160k1
 // const unsigned int PRIVATE_KEY_SIZE = 192;
 // const unsigned int PUBLIC_KEY_SIZE  = 41;
@@ -50,16 +50,16 @@ public:
 class CKeyID : public uint160
 {
 public:
-    CKeyID() : uint160(0) { }
-    CKeyID(const uint160 &in) : uint160(in) { }
+    CKeyID();
+    CKeyID(const uint160 &in);
 };
 
 /** A reference to a CScript: the Hash160 of its serialization (see script.h) */
 class CScriptID : public uint160
 {
 public:
-    CScriptID() : uint160(0) { }
-    CScriptID(const uint160 &in) : uint160(in) { }
+    CScriptID();
+    CScriptID(const uint160 &in);
 };
 
 /** An encapsulated OpenSSL Elliptic Curve key (public) */
@@ -160,15 +160,8 @@ public:
         }
     }
 
-    CKeyID GetID() const
-    {
-        return CKeyID(Hash160(vbytes, vbytes + size()));
-    }
-
-    uint256 GetHash() const
-    {
-        return Hash(vbytes, vbytes + size());
-    }
+    CKeyID GetID() const;
+    uint256 GetHash() const;
 
     /*
      * Check syntactic correctness.
@@ -423,7 +416,7 @@ public:
     CMalleableKey GetMalleableKey(const CSecret &vchSecretH) const { return CMalleableKey(vchSecretL, vchSecretH); }
     bool CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVariant) const;
 
-    bool operator <(const CMalleableKeyView& kv) const { return vchPubKeyH.GetID() < kv.vchPubKeyH.GetID(); }
+    bool operator <(const CMalleableKeyView& kv) const;
 };
 
 #endif
index 4a1ce85..46c20ca 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "crypter.h"
 #include "sync.h"
+
 #include <boost/signals2/signal.hpp>
 
 #include <variant>
index 3acda33..5447ba0 100644 (file)
@@ -2193,3 +2193,8 @@ void CScript::SetMultisig(int nRequired, const std::vector<CPubKey>& keys)
         *this << key;
     *this << EncodeOP_N((int)(keys.size())) << OP_CHECKMULTISIG;
 }
+
+CScriptID CScript::GetID() const
+{
+    return CScriptID(Hash160(*this));
+}
index 5450803..0f7cdf2 100644 (file)
@@ -623,10 +623,7 @@ public:
         printf("%s\n", ToString().c_str());
     }
 
-    CScriptID GetID() const
-    {
-        return CScriptID(Hash160(*this));
-    }
+    CScriptID GetID() const;
 };
 
 bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey, unsigned int flags);