From: svost Date: Thu, 15 Feb 2024 21:07:18 +0000 (+0300) Subject: Includes cleanup X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=53792d0d27e0c68322f1a4ab402150a8d4fcee6f Includes cleanup --- diff --git a/src/base58.cpp b/src/base58.cpp index 2a6e6e7..f57c4c6 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -14,6 +14,7 @@ // #include "base58.h" +#include "hash.h" static const std::array digits = { '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', diff --git a/src/bignum.cpp b/src/bignum.cpp index ad79919..1bbc5ea 100644 --- a/src/bignum.cpp +++ b/src/bignum.cpp @@ -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"); diff --git a/src/bignum.h b/src/bignum.h index 418f343..57470c8 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -7,7 +7,6 @@ #include "serialize.h" -#include "uint256.h" #include "version.h" #include @@ -16,6 +15,9 @@ #include #include +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& vch) { bn = BN_new(); setvch(vch); } void setuint32(uint32_t n); diff --git a/src/crypter.cpp b/src/crypter.cpp index 44f7cf3..313fecb 100644 --- a/src/crypter.cpp +++ b/src/crypter.cpp @@ -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 -#include -#include - #include "crypter.h" +#include + bool CCrypter::SetKeyFromPassphrase(const SecureString& strKeyData, const std::vector& chSalt, const unsigned int nRounds, const unsigned int nDerivationMethod) { diff --git a/src/db.cpp b/src/db.cpp index f252972..81b1bc7 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -7,6 +7,7 @@ #include "util.h" #include "addrman.h" #include "random.h" +#include "hash.h" #include #include diff --git a/src/key.cpp b/src/key.cpp index 2df613b..82c8b34 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -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 +#include "key.h" +#include "base58.h" +#include "streams.h" +#include "hash.h" #include #include -#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 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& 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) { } diff --git a/src/key.h b/src/key.h index 8dd8f16..6e7196e 100644 --- a/src/key.h +++ b/src/key.h @@ -11,12 +11,12 @@ #include "allocators.h" #include "serialize.h" #include "uint256.h" -#include "hash.h" #include "bignum.h" #include // for EC_KEY definition #include + // 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 diff --git a/src/keystore.h b/src/keystore.h index 4a1ce85..46c20ca 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -7,6 +7,7 @@ #include "crypter.h" #include "sync.h" + #include #include diff --git a/src/script.cpp b/src/script.cpp index 3acda33..5447ba0 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -2193,3 +2193,8 @@ void CScript::SetMultisig(int nRequired, const std::vector& keys) *this << key; *this << EncodeOP_N((int)(keys.size())) << OP_CHECKMULTISIG; } + +CScriptID CScript::GetID() const +{ + return CScriptID(Hash160(*this)); +} diff --git a/src/script.h b/src/script.h index 5450803..0f7cdf2 100644 --- a/src/script.h +++ b/src/script.h @@ -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 &vchPubKey, unsigned int flags);