Merge pull request #338 from svost/c++11
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Sun, 1 May 2016 18:01:30 +0000 (22:01 +0400)
committerCryptoManiac <CryptoManiac@users.noreply.github.com>
Sun, 1 May 2016 18:01:30 +0000 (22:01 +0400)
Minor fix

src/kernel.cpp
src/kernel.h
src/kernel_worker.cpp
src/key.cpp
src/key.h
src/util.cpp
src/util.h

index 769e7a2..422c48e 100644 (file)
@@ -301,7 +301,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStake
 
 // The stake modifier used to hash for a stake kernel is chosen as the stake
 // modifier about a selection interval later than the coin generating the kernel
-static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier, int& nStakeModifierHeight, int64_t& nStakeModifierTime, bool fPrintProofOfStake)
+static bool GetKernelStakeModifier(const uint256 &hashBlockFrom, uint64_t& nStakeModifier, int& nStakeModifierHeight, int64_t& nStakeModifierTime, bool fPrintProofOfStake)
 {
     nStakeModifier = 0;
     if (!mapBlockIndex.count(hashBlockFrom))
@@ -333,7 +333,7 @@ static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifi
     return true;
 }
 
-bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier)
+bool GetKernelStakeModifier(const uint256 &hashBlockFrom, uint64_t& nStakeModifier)
 {
     int nStakeModifierHeight;
     int64_t nStakeModifierTime;
index 8504a59..de4b52d 100644 (file)
@@ -25,7 +25,7 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexCurrent, uint64_t& nStake
 
 // The stake modifier used to hash for a stake kernel is chosen as the stake
 // modifier about a selection interval later than the coin generating the kernel
-bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier);
+bool GetKernelStakeModifier(const uint256 &hashBlockFrom, uint64_t& nStakeModifier);
 
 // Check whether stake kernel meets hash target
 // Sets hashProofOfStake on success return
index 0155361..0091f4b 100644 (file)
@@ -41,13 +41,13 @@ void KernelWorker::Do_generic()
         // Complete first hashing iteration
         uint256 hash1;
         SHA256_Update(&ctx, (unsigned char*)&nTimeTx, 4);
-        SHA256_Final((unsigned char*)&hash1, &ctx);
+        SHA256_Final(hash1.begin(), &ctx);
 
         // Restore context
         ctx = workerCtx;
 
         // Finally, calculate kernel hash
-        SHA256((unsigned char*)&hash1, sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
+        SHA256(hash1.begin(), sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
 
         // Skip if hash doesn't satisfy the maximum target
         if (hashProofOfStake[7] > nMaxTarget32)
@@ -95,14 +95,14 @@ bool ScanKernelBackward(unsigned char *kernel, uint32_t nBits, uint32_t nInputTx
         // Complete first hashing iteration
         uint256 hash1;
         SHA256_Update(&ctx, (unsigned char*)&nTimeTx, 4);
-        SHA256_Final((unsigned char*)&hash1, &ctx);
+        SHA256_Final(hash1.begin(), &ctx);
 
         // Restore context
         ctx = workerCtx;
 
         // Finally, calculate kernel hash
         uint256 hashProofOfStake;
-        SHA256((unsigned char*)&hash1, sizeof(hashProofOfStake), (unsigned char*)&hashProofOfStake);
+        SHA256(hash1.begin(), hashProofOfStake.size(), hashProofOfStake.begin());
 
         // Skip if hash doesn't satisfy the maximum target
         if (hashProofOfStake > nMaxTarget)
index 226ee68..e1a6014 100644 (file)
@@ -370,7 +370,7 @@ CPubKey CKey::GetPubKey() const
 bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
 {
     vchSig.clear();
-    auto sig = ECDSA_do_sign((unsigned char*)&hash, sizeof(hash), pkey);
+    auto sig = ECDSA_do_sign(hash.begin(), hash.size(), pkey);
     if (sig==NULL)
         return false;
     auto group = EC_KEY_get0_group(pkey);
@@ -399,7 +399,7 @@ bool CKey::Sign(uint256 hash, std::vector<unsigned char>& vchSig)
 // The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
 // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
 //                  0x1D = second key with even y, 0x1E = second key with odd y
-bool CKey::SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
+bool CKey::SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig)
 {
     bool fOk = false;
     auto sig = ECDSA_do_sign(hash.begin(), hash.size(), pkey);
@@ -453,7 +453,7 @@ bool CKey::SignCompact(uint256 hash, std::vector<unsigned char>& vchSig)
 // This is only slightly more CPU intensive than just verifying it.
 // If this function succeeds, the recovered public key is guaranteed to be valid
 // (the signature is a valid signature of the given data for that key)
-bool CPubKey::SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig)
+bool CPubKey::SetCompactSignature(const uint256 &hash, const std::vector<unsigned char>& vchSig)
 {
     if (vchSig.size() != 65)
         return false;
@@ -531,7 +531,7 @@ bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchS
     return ret;
 }
 
-bool CPubKey::VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig)
+bool CPubKey::VerifyCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig)
 {
     CPubKey key;
     if (!key.SetCompactSignature(hash, vchSig))
index cb5a712..a8ed447 100644 (file)
--- a/src/key.h
+++ b/src/key.h
@@ -200,9 +200,9 @@ public:
     }
 
     bool Verify(const uint256& hash, const std::vector<unsigned char>& vchSig) const;
-    bool VerifyCompact(uint256 hash, const std::vector<unsigned char>& vchSig);
+    bool VerifyCompact(const uint256 &hash, const std::vector<unsigned char>& vchSig);
 
-    bool SetCompactSignature(uint256 hash, const std::vector<unsigned char>& vchSig);
+    bool SetCompactSignature(const uint256 &hash, const std::vector<unsigned char>& vchSig);
 
     // Reserialize to DER
     static bool ReserealizeSignature(std::vector<unsigned char>& vchSig);
@@ -255,7 +255,7 @@ public:
     // The format is one header byte, followed by two times 32 bytes for the serialized r and s values.
     // The header byte: 0x1B = first key with even y, 0x1C = first key with odd y,
     //                  0x1D = second key with even y, 0x1E = second key with odd y
-    bool SignCompact(uint256 hash, std::vector<unsigned char>& vchSig);
+    bool SignCompact(const uint256 &hash, std::vector<unsigned char>& vchSig);
 
     bool IsValid();
 
index 8eba871..744717c 100644 (file)
@@ -185,7 +185,7 @@ int GetRandInt(int nMax)
 uint256 GetRandHash()
 {
     uint256 hash;
-    RAND_bytes((uint8_t*)&hash, sizeof(hash));
+    RAND_bytes(hash.begin(), hash.size());
     return hash;
 }
 
index e778979..079e56d 100644 (file)
@@ -49,11 +49,6 @@ static const int64_t CENT = 10000;
 #define UBEGIN(a)           ((unsigned char*)&(a))
 #define UEND(a)             ((unsigned char*)&((&(a))[1]))
 
-#define UVOIDBEGIN(a)        ((void*)&(a))
-#define CVOIDBEGIN(a)        ((const void*)&(a))
-#define UINTBEGIN(a)        ((uint32_t*)&(a))
-#define CUINTBEGIN(a)        ((const uint32_t*)&(a))
-
 #ifndef THROW_WITH_STACKTRACE
 #define THROW_WITH_STACKTRACE(exception)  \
 {                                         \