From a6273613a508e2207eddabd4dc9e94dc5cac712a Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 21 May 2012 19:39:32 -0700 Subject: [PATCH] Fix this class. --- src/LedgerProposal.cpp | 61 +++++++++++++++++------------------------- src/LedgerProposal.h | 6 ++--- 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/LedgerProposal.cpp b/src/LedgerProposal.cpp index dba8532917..5ad65ffb5f 100644 --- a/src/LedgerProposal.cpp +++ b/src/LedgerProposal.cpp @@ -3,59 +3,46 @@ #include -LedgerProposal::LedgerProposal(SerializerIterator& it) : mKey(boost::make_shared()) +#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()) { - 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); +} diff --git a/src/LedgerProposal.h b/src/LedgerProposal.h index a36c3a77f9..82e101c3f8 100644 --- a/src/LedgerProposal.h +++ b/src/LedgerProposal.h @@ -16,7 +16,6 @@ protected: uint256 mPeerID, mPreviousLedger, mPrevHash, mCurrentHash; uint32 mProposeSeq; CKey::pointer mKey; - std::vector mSignature; // std::vector mAddedTx, mRemovedTx; static const uint32 sProposeMagic = 0x50525000; // PRP @@ -26,7 +25,8 @@ public: typedef boost::shared_ptr pointer; // proposal from peer - LedgerProposal(SerializerIterator& it); + LedgerProposal(uint32 closingSeq, uint32 proposeSeq, const uint256& prevTx, const uint256& propose, + const std::string& pubKey); // our first proposal LedgerProposal(CKey::pointer privateKey, const uint256& prevLedger, const uint256& position); @@ -34,8 +34,8 @@ public: // our following proposals LedgerProposal(LedgerProposal::pointer previous, const uint256& newPosition); - void add(Serializer&, bool for_signature) const; uint256 getSigningHash() const; + bool checkSign(const std::string& signature); const uint256& getPeerID() const { return mPeerID; } const uint256& getPrevHash() const { return mPrevHash; }