From: alex Date: Sun, 17 Feb 2013 22:40:07 +0000 (+0400) Subject: Improve blocks signing procedure X-Git-Tag: v0.4.0-unstable~50 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=3b2f04b998fca87c3f5e57b6fbb78f01da699a34 Improve blocks signing procedure --- diff --git a/src/main.cpp b/src/main.cpp index c02298b..8a76b03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2135,21 +2135,57 @@ bool CBlock::SignBlock(const CKeyStore& keystore) { vector vSolutions; txnouttype whichType; - const CTxOut& txout = IsProofOfStake()? vtx[1].vout[1] : vtx[0].vout[0]; + int nVouts = nTime < 1361664000 ? 1 : vtx[0].vout.size(); - if (!Solver(txout.scriptPubKey, whichType, vSolutions)) - return false; - if (whichType == TX_PUBKEY) + if(!IsProofOfStake()) { - // Sign - const valtype& vchPubKey = vSolutions[0]; - CKey key; - if (!keystore.GetKey(Hash160(vchPubKey), key)) - return false; - if (key.GetPubKey() != vchPubKey) + for(int i = 0; i < nVouts; i++) + { + const CTxOut& txout = vtx[0].vout[i]; + + if (!Solver(txout.scriptPubKey, whichType, vSolutions)) + continue; + + if (whichType == TX_PUBKEY) + { + // Sign + valtype& vchPubKey = vSolutions[0]; + CKey key; + + if (!keystore.GetKey(Hash160(vchPubKey), key)) + continue; + if (key.GetPubKey() != vchPubKey) + continue; + if(!key.Sign(GetHash(), vchBlockSig)) + continue; + + return true; + } + } + } + else + { + const CTxOut& txout = vtx[1].vout[1]; + + if (!Solver(txout.scriptPubKey, whichType, vSolutions)) return false; - return key.Sign(GetHash(), vchBlockSig); + + if (whichType == TX_PUBKEY) + { + // Sign + valtype& vchPubKey = vSolutions[0]; + CKey key; + + if (!keystore.GetKey(Hash160(vchPubKey), key)) + return false; + if (key.GetPubKey() != vchPubKey) + return false; + + return key.Sign(GetHash(), vchBlockSig); + } } + + printf("Sign failed\n"); return false; } @@ -2161,26 +2197,52 @@ bool CBlock::CheckBlockSignature() const vector vSolutions; txnouttype whichType; - const CTxOut& txout = IsProofOfStake()? vtx[1].vout[1] : vtx[0].vout[0]; + int nVouts = nTime < 1361664000 ? 1 : vtx[0].vout.size(); - if (!Solver(txout.scriptPubKey, whichType, vSolutions)) - return false; - if (whichType == TX_PUBKEY) + if(IsProofOfStake()) { - const valtype& vchPubKey = vSolutions[0]; - CKey key; - if (!key.SetPubKey(vchPubKey)) - return false; - if (vchBlockSig.empty()) + const CTxOut& txout = vtx[1].vout[1]; + + if (!Solver(txout.scriptPubKey, whichType, vSolutions)) return false; - return key.Verify(GetHash(), vchBlockSig); + if (whichType == TX_PUBKEY) + { + valtype& vchPubKey = vSolutions[0]; + CKey key; + if (!key.SetPubKey(vchPubKey)) + return false; + if (vchBlockSig.empty()) + return false; + return key.Verify(GetHash(), vchBlockSig); + } } - return false; -} - + else + { + for(int i = 0; i < nVouts; i++) + { + const CTxOut& txout = vtx[0].vout[i]; + if (!Solver(txout.scriptPubKey, whichType, vSolutions)) + return false; + if (whichType == TX_PUBKEY) + { + // Verify + valtype& vchPubKey = vSolutions[0]; + CKey key; + if (!key.SetPubKey(vchPubKey)) + continue; + if (vchBlockSig.empty()) + continue; + if(!key.Verify(GetHash(), vchBlockSig)) + continue; + return true; + } + } + } + return false; +} bool CheckDiskSpace(uint64 nAdditionalBytes)