Skip to content

Commit

Permalink
fix vtable for CCcontract_info
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjatlanta committed Nov 23, 2021
1 parent e69abbe commit 2bcc883
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
10 changes: 0 additions & 10 deletions src/cc/CCcontract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ bool CCcontract_info::ismyvin(CScript const& scriptSig)
return out;
}

/// cc contract transaction validation callback that enforces the contract consensus rules
/// @param eval object of Eval type, used to report validation error like eval->Invalid("some error");
/// @param tx transaction object to validate
/// @param nIn not used at this time
bool CCcontract_info::validate(Eval* eval, const CTransaction &tx, uint32_t nIn)
{
throw std::logic_error("validation not supported for eval code");
return false; // just to keep the compiler quiet
}

/***
* Get an unspendable public key
* @param unspendablepriv filled with the private key
Expand Down
11 changes: 5 additions & 6 deletions src/cc/CCcontract.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
struct CCcontract_info
{
/***
* Default ctor, sets everything to 0
* Default ctor
*/
CCcontract_info() { memset(this, 0, sizeof(CCcontract_info)); }
CCcontract_info() = default;

/****
* Constructor that sets the most common values
* @param evalcode the type of contract
Expand Down Expand Up @@ -65,7 +66,7 @@ struct CCcontract_info
/// @param eval object of Eval type, used to report validation error like eval->Invalid("some error");
/// @param tx transaction object to validate
/// @param nIn not used at this time
virtual bool validate(Eval* eval, const CTransaction &tx, uint32_t nIn);
virtual bool validate(Eval* eval, const CTransaction &tx, uint32_t nIn) = 0;

/// checks if the value of evalcode in cp object is present in the scriptSig parameter,
/// that is, the vin for this scriptSig will be validated by the cc contract (Antara module) defined by the eval code in this CCcontract_info object
Expand All @@ -79,9 +80,7 @@ struct CCcontract_info
/// break;
/// }
/// \endcode
virtual bool ismyvin(CScript const& scriptSig);
bool ismyvin(CScript const& scriptSig);

/// @private
//uint8_t didinit;
};

11 changes: 11 additions & 0 deletions src/cc/CClib.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ struct CClibContract_info : public CCcontract_info
}
}
}

/// cc contract transaction validation callback that enforces the contract consensus rules
/// @param eval object of Eval type, used to report validation error like eval->Invalid("some error");
/// @param tx transaction object to validate
/// @param nIn not used at this time
virtual bool validate(Eval* eval, const CTransaction &tx, uint32_t nIn) override
{
throw std::logic_error("validation not supported for eval code");
return false; // just to keep the compiler quiet
}

};
2 changes: 1 addition & 1 deletion src/cc/gateways.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ uint8_t DecodeGatewaysDepositOpRet(const CScript &scriptPubKey,uint256 &bindtxid

CScript EncodeGatewaysClaimOpRet(uint8_t funcid,uint256 tokenid,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount)
{
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; struct CCcontract_info *cp,C; CPubKey gatewayspk;
CScript opret; uint8_t evalcode = EVAL_GATEWAYS; CPubKey gatewayspk;
std::vector<CPubKey> pubkeys;
vscript_t vopret;

Expand Down
3 changes: 0 additions & 3 deletions src/rpc/testtransactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ int32_t ensure_CCrequirements(uint8_t evalcode);

UniValue test_ac(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
// make fake token tx:
struct CCcontract_info *cp, C;

if (fHelp || (params.size() != 4))
throw runtime_error("incorrect params\n");
if (ensure_CCrequirements(EVAL_HEIR) < 0)
Expand Down
19 changes: 9 additions & 10 deletions src/script/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ std::vector<CCcontract_info> &GetCryptoConditions()
{
static bool initialized = false;
static std::vector<CCcontract_info> vCC = std::vector<CCcontract_info>();
CCcontract_info C;

if (!initialized)
{
Expand Down Expand Up @@ -228,20 +227,20 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
vector<CPubKey> vPK;
vector<valtype> vParams = vector<valtype>();
COptCCParams p;
CCcontract_info *cp;

// get information to sign with
CCcontract_info C;

scriptPubKey.IsPayToCryptoCondition(&subScript, vParams);
if (vParams.empty())
{
// get the keyID address of the cc and if it is an unspendable cc address, use its pubkey
// we have nothing else
char addr[64];
if (_Getscriptaddress(addr, subScript) && GetCCByUnspendableAddress(&C, addr))
if (_Getscriptaddress(addr, subScript) && GetCCByUnspendableAddress(cp, addr))
{
vPK.push_back(CPubKey(ParseHex(C.CChexstr)));
p = COptCCParams(p.VERSION, C.evalcode, 1, 1, vPK, vParams);
vPK.push_back(CPubKey(ParseHex(cp->CChexstr)));
p = COptCCParams(p.VERSION, cp->evalcode, 1, 1, vPK, vParams);
}
}
else
Expand All @@ -255,18 +254,18 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
CKey privKey;

// must be a valid cc eval code
if (CCinitLite(&C, p.evalCode))
if (CCinitLite(cp, p.evalCode))
{
// pay to cc address is a valid tx
if (!is1of2)
{
bool havePriv = creator.KeyStore().GetKey(p.vKeys[0].GetID(), privKey);

// if we don't have the private key, it must be the unspendable address
if (!havePriv && (p.vKeys[0] == CPubKey(ParseHex(C.CChexstr))))
if (!havePriv && (p.vKeys[0] == CPubKey(ParseHex(cp->CChexstr))))
{
privKey = CKey();
std::vector<unsigned char> vch(&(C.CCpriv[0]), C.CCpriv + sizeof(C.CCpriv));
std::vector<unsigned char> vch(&(cp->CCpriv[0]), cp->CCpriv + sizeof(cp->CCpriv));
privKey.Set(vch.begin(), vch.end(), false);
}

Expand Down Expand Up @@ -296,10 +295,10 @@ static bool SignStepCC(const BaseSignatureCreator& creator, const CScript& scrip
if (creator.IsKeystoreValid() && creator.KeyStore().GetKey(pk.GetID(), privKey) && privKey.IsValid())
break;

if (pk == CPubKey(ParseHex(C.CChexstr)))
if (pk == CPubKey(ParseHex(cp->CChexstr)))
{
privKey = CKey();
std::vector<unsigned char> vch(&(C.CCpriv[0]), C.CCpriv + sizeof(C.CCpriv));
std::vector<unsigned char> vch(&(cp->CCpriv[0]), cp->CCpriv + sizeof(cp->CCpriv));
privKey.Set(vch.begin(), vch.end(), false);
break;
}
Expand Down

0 comments on commit 2bcc883

Please sign in to comment.