X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fbase58.cpp;h=dc813abafa9d617cc37f001469841b59fff14f18;hb=5a7a2125b6b4ed7d3ea55f333d0cf2345bd1d916;hp=a524be6819248a7b7522ac18ee2354822de33b08;hpb=fbd44e84d5841867d36d295d4f347fd5e55d293f;p=novacoin.git diff --git a/src/base58.cpp b/src/base58.cpp index a524be6..dc813ab 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -254,15 +254,24 @@ bool DecodeBase58Check(const std::string& str, std::vector& vchRe return true; } + bool CBitcoinAddress::Set(const CBitcoinAddress &dest) + { + nVersion = dest.nVersion; + vchData = dest.vchData; + return true; + } + bool CBitcoinAddress::IsValid() const { unsigned int nExpectedSize = 20; bool fExpectTestNet = false; + bool fSimple = true; switch(nVersion) { case PUBKEY_PAIR_ADDRESS: nExpectedSize = 68; // Serialized pair of public keys fExpectTestNet = false; + fSimple = false; break; case PUBKEY_ADDRESS: nExpectedSize = 20; // Hash of public key @@ -276,6 +285,7 @@ bool DecodeBase58Check(const std::string& str, std::vector& vchRe case PUBKEY_PAIR_ADDRESS_TEST: nExpectedSize = 68; fExpectTestNet = true; + fSimple = false; break; case PUBKEY_ADDRESS_TEST: nExpectedSize = 20; @@ -289,7 +299,20 @@ bool DecodeBase58Check(const std::string& str, std::vector& vchRe default: return false; } - return fExpectTestNet == fTestNet && vchData.size() == nExpectedSize; + + // Basic format sanity check + bool fSeemsSane = (fExpectTestNet == fTestNet && vchData.size() == nExpectedSize); + + if (fSeemsSane && !fSimple) + { + // Perform dditional checking + // for pubkey pair addresses + CMalleablePubKey mpk; + mpk.setvch(vchData); + return mpk.IsValid(); + } + else + return fSeemsSane; } CTxDestination CBitcoinAddress::Get() const { @@ -329,6 +352,7 @@ bool DecodeBase58Check(const std::string& str, std::vector& vchRe CMalleablePubKey mPubKey; mPubKey.setvch(vchData); keyID = mPubKey.GetID(); + return true; } default: return false; } @@ -345,6 +369,18 @@ bool DecodeBase58Check(const std::string& str, std::vector& vchRe default: return false; } } + + bool CBitcoinAddress::IsPubKey() const { + if (!IsValid()) + return false; + switch (nVersion) { + case PUBKEY_ADDRESS: + case PUBKEY_ADDRESS_TEST: { + return true; + } + default: return false; + } + } bool CBitcoinAddress::IsPair() const { if (!IsValid())