From: CryptoManiac Date: Sun, 6 Mar 2016 13:38:02 +0000 (+0300) Subject: Cleanup X-Git-Tag: nvc-v0.5.6~28 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=d4488b9d263e4799f7bb4a1aaa1f692aa995f517 Cleanup --- diff --git a/src/key.cpp b/src/key.cpp index 1012915..022d83a 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -812,7 +812,7 @@ bool CMalleableKey::SetSecrets(const CSecret &pvchSecretL, const CSecret &pvchSe CKey keyL(pvchSecretL); CKey keyH(pvchSecretH); - if (!keyL.IsValid() || !keyL.IsValid()) + if (!keyL.IsValid() || !keyH.IsValid()) return false; vchSecretL = pvchSecretL; @@ -823,14 +823,8 @@ bool CMalleableKey::SetSecrets(const CSecret &pvchSecretL, const CSecret &pvchSe CMalleablePubKey CMalleableKey::GetMalleablePubKey() const { - CKey L, H; - L.SetSecret(vchSecretL, true); - H.SetSecret(vchSecretH, true); - - std::vector vchPubKeyL = L.GetPubKey().Raw(); - std::vector vchPubKeyH = H.GetPubKey().Raw(); - - return CMalleablePubKey(vchPubKeyL, vchPubKeyH); + CKey L(vchSecretL), H(vchSecretH); + return CMalleablePubKey(L.GetPubKey().Raw(), H.GetPubKey().Raw()); } // Check ownership @@ -853,8 +847,7 @@ bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVa throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode R value"); } - CKey H; - H.SetSecret(vchSecretH, true); + CKey H(vchSecretH); std::vector vchPubKeyH = H.GetPubKey().Raw(); CPoint point_H; @@ -923,8 +916,7 @@ bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVa throw key_error("CMalleableKey::CheckKeyVariant() : Unable to decode R value"); } - CKey H; - H.SetSecret(vchSecretH, true); + CKey H(vchSecretH); std::vector vchPubKeyH = H.GetPubKey().Raw(); CPoint point_H; @@ -978,7 +970,7 @@ bool CMalleableKey::CheckKeyVariant(const CPubKey &R, const CPubKey &vchPubKeyVa CBigNum bnp = bnHash + bnh; std::vector vchp = bnp.getBytes(); - privKeyVariant.SetSecret(CSecret(vchp.begin(), vchp.end()), true); + privKeyVariant.SetSecret(CSecret(vchp.begin(), vchp.end())); return true; } @@ -1027,13 +1019,11 @@ CMalleableKeyView::CMalleableKeyView(const CMalleableKey &b) throw key_error("CMalleableKeyView::CMalleableKeyView() : L size must be 32 bytes"); if (b.vchSecretH.size() != 32) - throw key_error("CMalleableKeyView::CMalleableKeyView() : L size must be 32 bytes"); + throw key_error("CMalleableKeyView::CMalleableKeyView() : H size must be 32 bytes"); vchSecretL = b.vchSecretL; - CKey H; - H.SetSecret(b.vchSecretH, true); - + CKey H(b.vchSecretH); vchPubKeyH = H.GetPubKey().Raw(); } @@ -1047,8 +1037,7 @@ CMalleableKeyView& CMalleableKeyView::operator=(const CMalleableKey &b) { vchSecretL = b.vchSecretL; - CKey H; - H.SetSecret(b.vchSecretH, true); + CKey H(b.vchSecretH); vchPubKeyH = H.GetPubKey().Raw(); return (*this); @@ -1060,8 +1049,7 @@ CMalleableKeyView::~CMalleableKeyView() CMalleablePubKey CMalleableKeyView::GetMalleablePubKey() const { - CKey keyL; - keyL.SetSecret(vchSecretL, true); + CKey keyL(vchSecretL); return CMalleablePubKey(keyL.GetPubKey(), vchPubKeyH); } diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index e28a64b..98b6171 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -32,8 +32,11 @@ QList TransactionRecord::decomposeTransaction(const CWallet * int64_t nNet = nCredit - nDebit; uint256 hash = wtx.GetHash(), hashPrev = 0; std::map mapValue = wtx.mapValue; + + bool fCoinBase = wtx.IsCoinBase(), + fCoinStake = wtx.IsCoinStake(); - if (nNet > 0 || wtx.IsCoinBase() || wtx.IsCoinStake()) + if (nNet > 0 || fCoinBase || fCoinStake) { // // Credit @@ -46,11 +49,11 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.idx = parts.size(); // sequence number sub.credit = txout.nValue; - std::string address; - if (pwalletMain->ExtractAddress(txout.scriptPubKey, address)) + CBitcoinAddress addressRet; + if (pwalletMain->ExtractAddress(txout.scriptPubKey, addressRet)) { sub.type = TransactionRecord::RecvWithAddress; - sub.address = address; + sub.address = addressRet.ToString(); } else { @@ -59,21 +62,18 @@ QList TransactionRecord::decomposeTransaction(const CWallet * sub.address = mapValue["from"]; } - if (wtx.IsCoinBase()) + if (fCoinBase || fCoinStake) { - // Generated (proof-of-work) + // Generated sub.type = TransactionRecord::Generated; - } - if (wtx.IsCoinStake()) - { - // Generated (proof-of-stake) - - if (hashPrev == hash) - continue; // last coinstake output - - sub.type = TransactionRecord::Generated; - sub.credit = nNet > 0 ? nNet : wtx.GetValueOut() - nDebit; - hashPrev = hash; + if (fCoinStake) + { + // proof-of-stake + if (hashPrev == hash) + continue; // last coinstake output + sub.credit = nNet > 0 ? nNet : wtx.GetValueOut() - nDebit; + hashPrev = hash; + } } parts.append(sub); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 47b12e9..a185ed3 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -495,11 +495,11 @@ void WalletModel::listCoins(std::map >& mapCoins) cout = COutput(&wallet->mapWallet[cout.tx->vin[0].prevout.hash], cout.tx->vin[0].prevout.n, 0, true); } - std::string address; - if(!out.fSpendable || !wallet->ExtractAddress(cout.tx->vout[cout.i].scriptPubKey, address)) + CBitcoinAddress addressRet; + if(!out.fSpendable || !wallet->ExtractAddress(cout.tx->vout[cout.i].scriptPubKey, addressRet)) continue; - mapCoins[address.c_str()].push_back(out); + mapCoins[addressRet.ToString().c_str()].push_back(out); } } diff --git a/src/wallet.cpp b/src/wallet.cpp index 908afaa..ab44a9b 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -2810,7 +2810,7 @@ void CWallet::ClearOrphans() EraseFromWallet(*it); } -bool CWallet::ExtractAddress(const CScript& scriptPubKey, std::string& addressRet) +bool CWallet::ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet) { vector vSolutions; txnouttype whichType; @@ -2819,7 +2819,7 @@ bool CWallet::ExtractAddress(const CScript& scriptPubKey, std::string& addressRe if (whichType == TX_PUBKEY) { - addressRet = CBitcoinAddress(CPubKey(vSolutions[0]).GetID()).ToString(); + addressRet = CBitcoinAddress(CPubKey(vSolutions[0]).GetID()); return true; } if (whichType == TX_PUBKEY_DROP) @@ -2829,17 +2829,17 @@ bool CWallet::ExtractAddress(const CScript& scriptPubKey, std::string& addressRe if (!CheckOwnership(CPubKey(vSolutions[0]), CPubKey(vSolutions[1]), view)) return false; - addressRet = CBitcoinAddress(view.GetMalleablePubKey()).ToString(); + addressRet = CBitcoinAddress(view.GetMalleablePubKey()); return true; } else if (whichType == TX_PUBKEYHASH) { - addressRet = CBitcoinAddress(CKeyID(uint160(vSolutions[0]))).ToString(); + addressRet = CBitcoinAddress(CKeyID(uint160(vSolutions[0]))); return true; } else if (whichType == TX_SCRIPTHASH) { - addressRet = CBitcoinAddress(CScriptID(uint160(vSolutions[0]))).ToString(); + addressRet = CBitcoinAddress(CScriptID(uint160(vSolutions[0]))); return true; } // Multisig txns have more than one address... diff --git a/src/wallet.h b/src/wallet.h index d07aa7c..aa21944 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -17,6 +17,7 @@ #include "ui_interface.h" #include "util.h" #include "walletdb.h" +#include "base58.h" extern unsigned int nStakeMaxAge; extern bool fWalletUnlockMintOnly; @@ -339,7 +340,7 @@ public: bool GetTransaction(const uint256 &hashTx, CWalletTx& wtx); - bool ExtractAddress(const CScript& scriptPubKey, std::string& addressRet); + bool ExtractAddress(const CScript& scriptPubKey, CBitcoinAddress& addressRet); bool SetDefaultKey(const CPubKey &vchPubKey);