Fix this class.

This commit is contained in:
JoelKatz
2012-05-21 19:39:32 -07:00
parent f516cb29d6
commit a6273613a5
2 changed files with 27 additions and 40 deletions

View File

@@ -3,59 +3,46 @@
#include <boost/make_shared.hpp>
LedgerProposal::LedgerProposal(SerializerIterator& it) : mKey(boost::make_shared<CKey>())
#include "key.h"
#include "Application.h"
LedgerProposal::LedgerProposal(uint32 closingSeq, uint32 proposeSeq, const uint256& prevTx, const uint256& proposeTx,
const std::string& pubKey) : mPrevHash(prevTx), mCurrentHash(proposeTx),
mProposeSeq(proposeSeq), mKey(boost::make_shared<CKey>())
{
if (it.get32() != sProposeMagic)
throw std::runtime_error("Not a ledger proposal");
mPreviousLedger = it.get256();
mCurrentHash = it.get256();
mPrevHash = it.get256();
mProposeSeq = it.get32();
if (mKey->SetPubKey(it.getVL()))
throw std::runtime_error("Unable to set public key");
mSignature = it.getVL();
if (!mKey->SetPubKey(pubKey))
throw std::runtime_error("Invalid public key in proposal");
mPreviousLedger = theApp->getMasterLedger().getClosedLedger()->getHash();
mPeerID = Serializer::getSHA512Half(mKey->GetPubKey());
if (!mKey->Verify(getSigningHash(), mSignature))
throw std::runtime_error("Ledger proposal invalid");
}
LedgerProposal::LedgerProposal(CKey::pointer mPrivateKey, const uint256& prevLgr, const uint256& position) :
mPreviousLedger(prevLgr), mCurrentHash(position), mProposeSeq(0), mKey(mPrivateKey)
{
mPeerID = Serializer::getSHA512Half(mKey->GetPubKey());
if (!mKey->Sign(getSigningHash(), mSignature))
throw std::runtime_error("Unable to sign proposal");
}
LedgerProposal::LedgerProposal(LedgerProposal::pointer previous, const uint256& newp) :
mPeerID(previous->mPeerID), mPreviousLedger(previous->mPreviousLedger), mPrevHash(previous->mCurrentHash),
mCurrentHash(newp), mProposeSeq(previous->mProposeSeq + 1), mKey(previous->mKey)
mPeerID(previous->mPeerID), mPreviousLedger(previous->mPreviousLedger),
mPrevHash(previous->mCurrentHash), mCurrentHash(newp),
mProposeSeq(previous->mProposeSeq + 1), mKey(previous->mKey)
{
if (!mKey->Sign(getSigningHash(), mSignature))
throw std::runtime_error("Unable to sign proposal");
}
void LedgerProposal::add(Serializer& s, bool for_signature) const
{
s.add32(sProposeMagic);
s.add256(mPreviousLedger);
s.add256(mCurrentHash);
s.add256(mPrevHash);
s.add32(mProposeSeq);
if (for_signature)
return;
s.addVL(mKey->GetPubKey());
s.addVL(mSignature);
;
}
uint256 LedgerProposal::getSigningHash() const
{
Serializer s(104);
add(s, true);
s.add32(sProposeMagic);
s.add32(mProposeSeq);
s.add256(mPreviousLedger);
s.add256(mCurrentHash);
s.add256(mPrevHash);
return s.getSHA512Half();
}
bool LedgerProposal::checkSign(const std::string& signature)
{
return mKey->Verify(getSigningHash(), signature);
}