Have consensus use the config for validation and use uint160 for peerIDs.

This commit is contained in:
Arthur Britto
2012-06-13 15:51:30 -07:00
parent 5aaeef3a50
commit 368e5a0acc
6 changed files with 69 additions and 43 deletions

View File

@@ -7,34 +7,44 @@
#include "Application.h"
LedgerProposal::LedgerProposal(const uint256& pLgr, uint32 seq, const uint256& tx, const std::string& pubKey) :
mPreviousLedger(pLgr), mCurrentHash(tx), mProposeSeq(seq), mKey(boost::make_shared<CKey>())
mPreviousLedger(pLgr), mCurrentHash(tx), mProposeSeq(seq)
{
if (!mKey->SetPubKey(pubKey))
throw std::runtime_error("Invalid public key in proposal");
mPreviousLedger = theApp->getMasterLedger().getClosedLedger()->getHash();
mPeerID = Serializer::getSHA512Half(mKey->GetPubKey());
// XXX Make caller give us a vuc for pubkey.
mPublicKey.setNodePublic(strCopy(pubKey));
// XXX Validate key.
// if (!mKey->SetPubKey(pubKey))
// throw std::runtime_error("Invalid public key in proposal");
mPreviousLedger = theApp->getMasterLedger().getClosedLedger()->getHash();
mPeerID = mPublicKey.getNodeID();
}
LedgerProposal::LedgerProposal(CKey::pointer mPrivateKey, const uint256& prevLgr, const uint256& position) :
mPreviousLedger(prevLgr), mCurrentHash(position), mProposeSeq(0), mKey(mPrivateKey)
LedgerProposal::LedgerProposal(const NewcoinAddress& naSeed, const uint256& prevLgr, const uint256& position) :
mPreviousLedger(prevLgr), mCurrentHash(position), mProposeSeq(0)
{
mPeerID = Serializer::getSHA512Half(mKey->GetPubKey());
mSeed = naSeed;
mPublicKey = NewcoinAddress::createNodePublic(naSeed);
mPrivateKey = NewcoinAddress::createNodePrivate(naSeed);
mPeerID = mPublicKey.getNodeID();
}
uint256 LedgerProposal::getSigningHash() const
{
Serializer s(72);
s.add32(sProposeMagic);
s.add32(mProposeSeq);
s.add256(mPreviousLedger);
s.add256(mCurrentHash);
return s.getSHA512Half();
}
bool LedgerProposal::checkSign(const std::string& signature)
{
return mKey->Verify(getSigningHash(), signature);
return mPublicKey.verifyNodePublic(getSigningHash(), signature);
}
void LedgerProposal::changePosition(const uint256& newPosition)
@@ -46,7 +56,13 @@ void LedgerProposal::changePosition(const uint256& newPosition)
std::vector<unsigned char> LedgerProposal::sign(void)
{
std::vector<unsigned char> ret;
if (!mKey->Sign(getSigningHash(), ret))
throw std::runtime_error("unable to sign proposal");
mPrivateKey.signNodePrivate(getSigningHash(), ret);
// XXX If this can fail, find out sooner.
// if (!mPrivateKey.signNodePrivate(getSigningHash(), ret))
// throw std::runtime_error("unable to sign proposal");
return ret;
}
// vim:ts=4