Merge #937: Fix/improve upon previous DS refactoring

11598a6 Fix/improve DS refactoring
This commit is contained in:
UdjinM6 2016-08-12 09:43:18 +04:00 committed by Holger Schinzel
parent 625b5ebb09
commit 8d28ed0dd1
2 changed files with 43 additions and 23 deletions

View File

@ -1552,7 +1552,7 @@ bool CDarksendPool::DoAutomaticDenominating(bool fDryRun)
CMasternode* pmn = mnodeman.Find(dsq.vin);
if(pmn == NULL) {
LogPrintf("CDarksendPool::DoAutomaticDenominating -- dsq vin is not in masternode list! vin=%s\n", dsq.vin.ToString());
LogPrintf("CDarksendPool::DoAutomaticDenominating -- dsq masternode is not in masternode list! vin=%s\n", dsq.vin.ToString());
continue;
}
@ -2084,13 +2084,13 @@ bool CDarkSendSigner::IsVinAssociatedWithPubkey(const CTxIn& txin, const CPubKey
return false;
}
bool CDarkSendSigner::GetKeysFromSecret(std::string strSecret, std::string& strErrorMessageRet, CKey& keyRet, CPubKey& pubkeyRet)
bool CDarkSendSigner::GetKeysFromSecret(std::string strSecret, std::string& strErrorRet, CKey& keyRet, CPubKey& pubkeyRet)
{
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);
if(!fGood) {
strErrorMessageRet = _("Invalid secret.");
strErrorRet = _("Invalid secret.");
return false;
}
@ -2100,21 +2100,21 @@ bool CDarkSendSigner::GetKeysFromSecret(std::string strSecret, std::string& strE
return true;
}
bool CDarkSendSigner::SignMessage(std::string strMessage, std::string& strErrorMessageRet, std::vector<unsigned char>& vchSigRet, CKey key)
bool CDarkSendSigner::SignMessage(std::string strMessage, std::string& strErrorRet, std::vector<unsigned char>& vchSigRet, CKey key)
{
CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
ss << strMessage;
if(!key.SignCompact(ss.GetHash(), vchSigRet)) {
strErrorMessageRet = _("Signing failed.");
strErrorRet = _("Signing failed.");
return false;
}
return true;
}
bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorMessageRet)
bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorRet)
{
CHashWriter ss(SER_GETHASH, 0);
ss << strMessageMagic;
@ -2122,12 +2122,12 @@ bool CDarkSendSigner::VerifyMessage(CPubKey pubkey, const std::vector<unsigned c
CPubKey pubkeyFromSig;
if(!pubkeyFromSig.RecoverCompact(ss.GetHash(), vchSig)) {
strErrorMessageRet = _("Error recovering public key.");
strErrorRet = _("Error recovering public key.");
return false;
}
if(pubkeyFromSig.GetID() != pubkey.GetID()) {
strErrorMessageRet = strprintf("keys don't match: pubkey=%s, pubkeyFromSig=%s, strMessage=%s, vchSig=%s",
strErrorRet = strprintf("keys don't match: pubkey=%s, pubkeyFromSig=%s, strMessage=%s, vchSig=%s",
pubkey.GetID().ToString(), pubkeyFromSig.GetID().ToString(), strMessage,
EncodeBase64(&vchSig[0], vchSig.size()));
return false;
@ -2177,9 +2177,9 @@ bool CDarksendQueue::Sign()
if(!fMasterNode) return false;
std::string strMessage = vin.ToString() + boost::lexical_cast<std::string>(nDenom) + boost::lexical_cast<std::string>(nTime) + boost::lexical_cast<std::string>(fReady);
std::string strErrorMessage = "";
std::string strError = "";
if(!darkSendSigner.SignMessage(strMessage, strErrorMessage, vchSig, activeMasternode.keyMasternode)) {
if(!darkSendSigner.SignMessage(strMessage, strError, vchSig, activeMasternode.keyMasternode)) {
LogPrintf("CDarksendQueue::Sign -- SignMessage() failed\n");
return false;
}
@ -2193,9 +2193,9 @@ bool CDarksendQueue::CheckSignature()
if(pmn == NULL) return false;
std::string strMessage = vin.ToString() + boost::lexical_cast<std::string>(nDenom) + boost::lexical_cast<std::string>(nTime) + boost::lexical_cast<std::string>(fReady);
std::string strErrorMessage = "";
std::string strError = "";
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strErrorMessage)) {
if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, strError)) {
LogPrintf("CDarksendQueue::CheckSignature -- Got bad Masternode queue signature, vin=%s\n", vin.ToString());
return false;
}

View File

@ -77,7 +77,8 @@ public:
CTxDSIn(const CTxIn& txin) :
CTxIn(txin),
fHasSig(false),
nSentTimes(0) {}
nSentTimes(0)
{}
};
/** Holds an mixing output
@ -89,7 +90,8 @@ public:
CTxDSOut(const CTxOut& out) :
CTxOut(out),
nSentTimes(0) {}
nSentTimes(0)
{}
};
// A clients transaction in the mixing pool
@ -107,7 +109,8 @@ public:
txCollateral(CTransaction()),
nAmount(0),
nTimeAdded(0),
isSet(false) {}
isSet(false)
{}
/// Add entries to use for mixing
bool Add(const std::vector<CTxIn> vecTxIn, CAmount nAmount, const CTransaction txCollateral, const std::vector<CTxOut> vecTxOut);
@ -130,13 +133,21 @@ public:
bool fReady; //ready for submit
std::vector<unsigned char> vchSig;
CDarksendQueue() { CDarksendQueue(0, CTxIn(), 0, false); }
CDarksendQueue() :
nDenom(0),
vin(CTxIn()),
nTime(0),
fReady(false),
vchSig(std::vector<unsigned char>())
{}
CDarksendQueue(int nDenom, CTxIn vin, int64_t nTime, bool fReady) :
nDenom(nDenom),
vin(vin),
nTime(nTime),
fReady(fReady) { vchSig = std::vector<unsigned char>(); }
fReady(fReady),
vchSig(std::vector<unsigned char>())
{}
ADD_SERIALIZE_METHODS;
@ -179,10 +190,19 @@ public:
std::vector<unsigned char> vchSig;
int64_t sigTime;
CDarksendBroadcastTx() { CDarksendBroadcastTx(CTransaction(), CTxIn(), 0); }
CDarksendBroadcastTx() :
tx(CTransaction()),
vin(CTxIn()),
vchSig(std::vector<unsigned char>()),
sigTime(0)
{}
CDarksendBroadcastTx(CTransaction tx, CTxIn vin, int64_t sigTime) :
tx(tx), vin(vin), sigTime(sigTime) { vchSig = std::vector<unsigned char>(); }
tx(tx),
vin(vin),
vchSig(std::vector<unsigned char>()),
sigTime(sigTime)
{}
ADD_SERIALIZE_METHODS;
@ -203,14 +223,14 @@ public:
class CDarkSendSigner
{
public:
/// Is the inputs associated with this public key? (and there is 1000 DASH - checking if valid masternode)
/// Is the input associated with this public key? (and there is 1000 DASH - checking if valid masternode)
bool IsVinAssociatedWithPubkey(const CTxIn& vin, const CPubKey& pubkey);
/// Set the private/public key values, returns true if successful
bool GetKeysFromSecret(std::string strSecret, std::string& strErrorMessageRet, CKey& keyRet, CPubKey& pubkeyRet);
bool GetKeysFromSecret(std::string strSecret, std::string& strErrorRet, CKey& keyRet, CPubKey& pubkeyRet);
/// Sign the message, returns true if successful
bool SignMessage(std::string strMessage, std::string& strErrorMessageRet, std::vector<unsigned char>& vchSigRet, CKey key);
bool SignMessage(std::string strMessage, std::string& strErrorRet, std::vector<unsigned char>& vchSigRet, CKey key);
/// Verify the message, returns true if succcessful
bool VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorMessageRet);
bool VerifyMessage(CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string strMessage, std::string& strErrorRet);
};
/** Used to keep track of current status of mixing pool