struct CC_info

This commit is contained in:
jl777
2019-01-19 23:12:28 -11:00
parent 607f47588b
commit 4223d927ad
2 changed files with 678 additions and 677 deletions

View File

@@ -43,7 +43,7 @@ public:
static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) {
return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG);
} }
/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { /* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) {
return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG); return CTxOut(amount, CScript() << ParseHex(HexStr(myPubkey)) << OP_CHECKSIG);
} */ } */
static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) {
@@ -85,7 +85,7 @@ public:
static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) { static CTxOut makeUserVout(int64_t amount, CPubKey myPubkey) {
return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS
} }
/* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) { /* static CTxOut makeClaimerVout(int64_t amount, CPubKey myPubkey) {
return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS return MakeCC1vout(EVAL_TOKENS, amount, myPubkey); // yes EVAL_TOKENS
} */ } */
static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) { static bool GetCoinsOrTokensCCaddress1of2(char *coinaddr, CPubKey ownerPubkey, CPubKey heirPubkey) {
@@ -102,20 +102,20 @@ public:
/** /**
* Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern: * Small framework for vins and vouts validation implementing a variation of 'chain of responsibility' pattern:
* It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators * It consists of two classes CInputValidationPlan and COutputValidationPlan which both are configured with an array of vectors of validators
* (These validators are derived from the class CValidatorBase). * (These validators are derived from the class CValidatorBase).
* *
* A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn. * A example of a validator may verify for a vout if its public key corresponds to the public key which is stored in opreturn.
* Or, vin validator may check if this vin depicts correctly to the CC contract's address. * Or, vin validator may check if this vin depicts correctly to the CC contract's address.
* *
* For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class. * For validating vins CInputValidator additionally is provided with an instance of a class derived from the CInputIdentifierBase class.
* this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it. * this identifier class allows to select identical vins (for example, normal vins or cc input vins) and apply validators from the corresponding vector to it.
* Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false. * Note: CInputValidator treats that at least one identified vin should be present, otherwise it returns eval->invalid() and false.
* *
* For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied * For validating vouts COutputValidator is configured for each vector of validators with the vout index to which these validators are applied
* (see constructors of both CInputValidator and COutputValidator) * (see constructors of both CInputValidator and COutputValidator)
*/ */
/** /**
* base class for all validators * base class for all validators
@@ -123,13 +123,13 @@ public:
class CValidatorBase class CValidatorBase
{ {
public: public:
CValidatorBase(CC_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, std::string& message) const = 0; virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const = 0;
virtual bool validateVout(CTxOut vout, std::string& message) const = 0; virtual bool validateVout(CTxOut vout, std::string& message) const = 0;
protected: protected:
CC_info * m_cp; CCcontract_info * m_cp;
}; };
/** /**
@@ -138,18 +138,18 @@ protected:
class CInputIdentifierBase class CInputIdentifierBase
{ {
public: public:
CInputIdentifierBase(CC_info* cp) : m_cp(cp) {} CInputIdentifierBase(CCcontract_info* cp) : m_cp(cp) {}
virtual std::string inputName() const = 0; virtual std::string inputName() const = 0;
virtual bool identifyInput(CTxIn vin) const = 0; virtual bool identifyInput(CTxIn vin) const = 0;
protected: protected:
CC_info * m_cp; CCcontract_info * m_cp;
}; };
/** /**
* Encapsulates an array containing rows of validators * Encapsulates an array containing rows of validators
* Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts * Each row is a vector of validators (zero is possible) for validating vins or prev tx's vouts
* this validation plan is used for validating tx inputs * this validation plan is used for validating tx inputs
*/ */
template <typename TValidatorBase> template <typename TValidatorBase>
class CInputValidationPlan class CInputValidationPlan
{ {
@@ -278,10 +278,10 @@ private:
/** /**
* Encapsulates an array containing rows of validators * Encapsulates an array containing rows of validators
* Each row is a vector of validators (zero is possible) for validating vouts * Each row is a vector of validators (zero is possible) for validating vouts
* this validation plan is used for validating tx outputs * this validation plan is used for validating tx outputs
*/ */
template <typename TValidatorBase> template <typename TValidatorBase>
class COutputValidationPlan class COutputValidationPlan
{ {
@@ -375,7 +375,7 @@ private:
class CNormalInputIdentifier : CInputIdentifierBase { class CNormalInputIdentifier : CInputIdentifierBase {
public: public:
CNormalInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} CNormalInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {}
virtual std::string inputName() const { return std::string("normal input"); } virtual std::string inputName() const { return std::string("normal input"); }
virtual bool identifyInput(CTxIn vin) const { virtual bool identifyInput(CTxIn vin) const {
return !IsCCInput(vin.scriptSig); return !IsCCInput(vin.scriptSig);
@@ -384,7 +384,7 @@ public:
class CCCInputIdentifier : CInputIdentifierBase { class CCCInputIdentifier : CInputIdentifierBase {
public: public:
CCCInputIdentifier(CC_info* cp) : CInputIdentifierBase(cp) {} CCCInputIdentifier(CCcontract_info* cp) : CInputIdentifierBase(cp) {}
virtual std::string inputName() const { return std::string("CC input"); } virtual std::string inputName() const { return std::string("CC input"); }
virtual bool identifyInput(CTxIn vin) const { virtual bool identifyInput(CTxIn vin) const {
return IsCCInput(vin.scriptSig); return IsCCInput(vin.scriptSig);
@@ -393,12 +393,12 @@ public:
/** /**
* Validates 1of2address for vout (may be used for either this or prev tx) * Validates 1of2address for vout (may be used for either this or prev tx)
*/ */
template <class Helper> class CCC1of2AddressValidator : CValidatorBase template <class Helper> class CCC1of2AddressValidator : CValidatorBase
{ {
public: public:
CCC1of2AddressValidator(CC_info* cp, CScript opRetScript, std::string customMessage = "") : CCC1of2AddressValidator(CCcontract_info* cp, CScript opRetScript, std::string customMessage = "") :
m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {} m_fundingOpretScript(opRetScript), m_customMessage(customMessage), CValidatorBase(cp) {}
virtual bool isVinValidator() const { return false; } virtual bool isVinValidator() const { return false; }
@@ -447,12 +447,12 @@ private:
/** /**
* Validates if this is vout to owner or heir from opret (funding or change) * Validates if this is vout to owner or heir from opret (funding or change)
*/ */
template <class Helper> class CMyPubkeyVoutValidator : CValidatorBase template <class Helper> class CMyPubkeyVoutValidator : CValidatorBase
{ {
public: public:
CMyPubkeyVoutValidator(CC_info* cp, CScript opRetScript, bool checkNormals) CMyPubkeyVoutValidator(CCcontract_info* cp, CScript opRetScript, bool checkNormals)
: m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { } : m_fundingOpretScript(opRetScript), m_checkNormals(checkNormals), CValidatorBase(cp) { }
virtual bool isVinValidator() const { return false; } virtual bool isVinValidator() const { return false; }
@@ -507,12 +507,12 @@ private:
}; };
/** /**
* Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime) * Check if the user is the heir and the heir is allowed to spend (duration > inactivityTime)
*/ */
template <class Helper> class CHeirSpendValidator : CValidatorBase template <class Helper> class CHeirSpendValidator : CValidatorBase
{ {
public: public:
CHeirSpendValidator(CC_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan) CHeirSpendValidator(CCcontract_info* cp, CScript opRetScript, uint256 latesttxid, uint8_t isHeirSpendingBegan)
: m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {} : m_fundingOpretScript(opRetScript), m_latesttxid(latesttxid), m_isHeirSpendingBegan(isHeirSpendingBegan), CValidatorBase(cp) {}
virtual bool isVinValidator() const { return false; } virtual bool isVinValidator() const { return false; }
@@ -563,12 +563,12 @@ private:
}; };
/** /**
* Validates this opreturn and compares it with the opreturn from the previous tx * Validates this opreturn and compares it with the opreturn from the previous tx
*/ */
template <class Helper> class COpRetValidator : CValidatorBase template <class Helper> class COpRetValidator : CValidatorBase
{ {
public: public:
COpRetValidator(CC_info* cp, CScript opret) COpRetValidator(CCcontract_info* cp, CScript opret)
: m_fundingOpretScript(opret), CValidatorBase(cp) {} : m_fundingOpretScript(opret), CValidatorBase(cp) {}
virtual bool isVinValidator() const { return false; } virtual bool isVinValidator() const { return false; }
@@ -614,12 +614,12 @@ private:
}; };
/** /**
* empty validator always returns true * empty validator always returns true
*/ */
template <class Helper> class CNullValidator : CValidatorBase template <class Helper> class CNullValidator : CValidatorBase
{ {
public: public:
CNullValidator(CC_info* cp) CNullValidator(CCcontract_info* cp)
: CValidatorBase(cp) { } : CValidatorBase(cp) { }
virtual bool isVinValidator() const { return false; } virtual bool isVinValidator() const { return false; }

View File

@@ -523,8 +523,8 @@ static vector<valtype> CombineMultisig(const CScript& scriptPubKey, const BaseSi
namespace namespace
{ {
struct Stacks struct Stacks
{ {
std::vector<valtype> script; std::vector<valtype> script;
Stacks() {} Stacks() {}
@@ -538,7 +538,7 @@ struct Stacks
result.scriptSig = PushAll(script); result.scriptSig = PushAll(script);
return result; return result;
} }
}; };
} }
static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker, static Stacks CombineSignatures(const CScript& scriptPubKey, const BaseSignatureChecker& checker,
@@ -603,10 +603,10 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
} }
namespace { namespace {
/** Dummy signature checker which accepts all signatures. */ /** Dummy signature checker which accepts all signatures. */
class DummySignatureChecker : public BaseSignatureChecker class DummySignatureChecker : public BaseSignatureChecker
{ {
public: public:
DummySignatureChecker() {} DummySignatureChecker() {}
bool CheckSig( bool CheckSig(
@@ -617,8 +617,8 @@ public:
{ {
return true; return true;
} }
}; };
const DummySignatureChecker dummyChecker; const DummySignatureChecker dummyChecker;
} }
const BaseSignatureChecker& DummySignatureCreator::Checker() const const BaseSignatureChecker& DummySignatureCreator::Checker() const
@@ -647,3 +647,4 @@ bool DummySignatureCreator::CreateSig(
vchSig[6 + 33 + 32] = SIGHASH_ALL; vchSig[6 + 33 + 32] = SIGHASH_ALL;
return true; return true;
} }