corr F tx marker protection validation code
This commit is contained in:
@@ -56,6 +56,7 @@ template <typename Helper> bool RunValidationPlans(uint8_t funcId, struct CCcont
|
|||||||
// only for tokens:
|
// only for tokens:
|
||||||
CMyPubkeyVoutValidator<TokenHelper> ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret
|
CMyPubkeyVoutValidator<TokenHelper> ownerCCaddrValidator(cp, fundingOpretScript, false); // check if this correct owner's cc user addr corresponding to opret
|
||||||
COpRetValidator<Helper> opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx
|
COpRetValidator<Helper> opRetValidator(cp, fundingOpretScript); // compare opRets in this and last tx
|
||||||
|
CMarkerValidator<Helper> markerValidator(cp); // initial tx marker spending protection
|
||||||
CNullValidator<Helper> nullValidator(cp);
|
CNullValidator<Helper> nullValidator(cp);
|
||||||
|
|
||||||
switch (funcId) {
|
switch (funcId) {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class CValidatorBase
|
|||||||
public:
|
public:
|
||||||
CValidatorBase(CCcontract_info* cp) : m_cp(cp) {}
|
CValidatorBase(CCcontract_info* cp) : m_cp(cp) {}
|
||||||
virtual bool isVinValidator() const = 0;
|
virtual bool isVinValidator() const = 0;
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const = 0;
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const = 0;
|
||||||
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0;
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -258,7 +258,7 @@ private:
|
|||||||
|
|
||||||
if (v->isVinValidator())
|
if (v->isVinValidator())
|
||||||
// validate this vin and previous vout:
|
// validate this vin and previous vout:
|
||||||
result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage);
|
result = v->validateVin(pTx->vin[iv], pPrevTx->vout, pTx->vin[iv].prevout.n, refMessage);
|
||||||
else
|
else
|
||||||
// if it is vout validator pass the previous tx vout:
|
// if it is vout validator pass the previous tx vout:
|
||||||
result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage);
|
result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage);
|
||||||
@@ -438,7 +438,7 @@ public:
|
|||||||
std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl;
|
std::cerr << "CCC1of2AddressValidator::validateVout() exits with false: " << message << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return false; }
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
@@ -498,7 +498,7 @@ public:
|
|||||||
message = std::string("invalid pubkey");
|
message = std::string("invalid pubkey");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
@@ -554,7 +554,7 @@ public:
|
|||||||
// this is not heir:
|
// this is not heir:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
@@ -607,17 +607,17 @@ public:
|
|||||||
//std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl;
|
//std::cerr << "COpRetValidator::validateVout() exits with true" << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
** marker spending prevention validator,
|
* marker spending prevention validator,
|
||||||
** returns false if for tx with funcid=F vout.1 is being tried to spend
|
* returns false if for tx with funcid=F vout.1 is being tried to spend
|
||||||
*/
|
*/
|
||||||
template <class Helper> class CMarkerValidator : CValidatorBase
|
template <class Helper> class CMarkerValidator : CValidatorBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -625,22 +625,22 @@ public:
|
|||||||
: CValidatorBase(cp) { }
|
: CValidatorBase(cp) { }
|
||||||
|
|
||||||
virtual bool isVinValidator() const { return false; } // this is vout validator
|
virtual bool isVinValidator() const { return false; } // this is vout validator
|
||||||
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const {
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const {
|
||||||
|
|
||||||
uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid;
|
uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid;
|
||||||
uint8_t dummyIsHeirSpendingBegan;
|
uint8_t dummyIsHeirSpendingBegan;
|
||||||
|
|
||||||
uint8_t funcId = DecodeHeirEitherOpRet(m_opret, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true);
|
if (prevVout.size() > 0) {
|
||||||
|
|
||||||
if( funcId == 'F' && vout_n == 1 )
|
// get funcId for prev tx:
|
||||||
return false;
|
uint8_t funcId = DecodeHeirEitherOpRet(prevVout[prevVout.size()-1].scriptPubKey, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true);
|
||||||
|
if (funcId == 'F' && prevN == 1) // do not allow to spend 'F' marker's vout
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CScript m_fundingOpretScript;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -654,7 +654,7 @@ public:
|
|||||||
|
|
||||||
virtual bool isVinValidator() const { return false; }
|
virtual bool isVinValidator() const { return false; }
|
||||||
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; }
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, std::vector<CTxOut> prevVout, int32_t prevN, std::string& message) const { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user