corr marker to cc unspendable for F, added validation to prevent its spending
added marker to prevent archiving for A
This commit is contained in:
@@ -16,8 +16,6 @@
|
|||||||
#include "CCHeir.h"
|
#include "CCHeir.h"
|
||||||
#include "heir_validate.h"
|
#include "heir_validate.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
class CoinHelper;
|
class CoinHelper;
|
||||||
class TokenHelper;
|
class TokenHelper;
|
||||||
|
|
||||||
@@ -653,6 +651,8 @@ template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std
|
|||||||
cp = CCinit(&C, Helper::getMyEval());
|
cp = CCinit(&C, Helper::getMyEval());
|
||||||
if (txfee == 0)
|
if (txfee == 0)
|
||||||
txfee = 10000;
|
txfee = 10000;
|
||||||
|
|
||||||
|
int64_t markerfee = 10000;
|
||||||
|
|
||||||
//std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl;
|
//std::cerr << "HeirFund() amount=" << amount << " txfee=" << txfee << " heirPubkey IsValid()=" << heirPubkey.IsValid() << " inactivityTime(sec)=" << inactivityTimeSec << " tokenid=" << tokenid.GetHex() << std::endl;
|
||||||
|
|
||||||
@@ -664,17 +664,18 @@ template <typename Helper> UniValue _HeirFund(int64_t txfee, int64_t amount, std
|
|||||||
|
|
||||||
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
CPubKey myPubkey = pubkey2pk(Mypubkey());
|
||||||
|
|
||||||
if (AddNormalinputs(mtx, myPubkey, txfee, 3) > 0) { // txfee for miners
|
if (AddNormalinputs(mtx, myPubkey, markerfee, 3) > 0) {
|
||||||
int64_t inputs, change;
|
int64_t inputs, change;
|
||||||
|
|
||||||
if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) { // 2 x txfee: 1st for marker vout, 2nd to miners
|
if ((inputs=Helper::addOwnerInputs(tokenid, mtx, myPubkey, amount, (int32_t)64)) > 0) {
|
||||||
//mtx.vout.push_back(MakeTokensCC1of2vout(/*Helper::getMyEval()*/EVAL_HEIR, amount, myPubkey, heirPubkey)); // add cryptocondition to spend amount for either pk
|
|
||||||
mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey));
|
mtx.vout.push_back(Helper::make1of2Vout(amount, myPubkey, heirPubkey));
|
||||||
|
|
||||||
// add a marker for finding all plans in HeirList()
|
// add a marker for finding all plans in HeirList()
|
||||||
// TODO: change marker either to cc or normal txidaddr unspendable
|
// TODO: change marker either to cc or normal txidaddr unspendable
|
||||||
CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0);
|
CPubKey heirUnspendablePubKey = GetUnspendable(cp, 0);
|
||||||
mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); // TODO: do we need this marker?
|
// mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone
|
||||||
|
MakeCC1vout(EVAL_HEIR, txfee, heirUnspendablePubKey); // this marker spending is disabled in the validation code
|
||||||
|
|
||||||
// calc and add change vout:
|
// calc and add change vout:
|
||||||
if (inputs > amount)
|
if (inputs > amount)
|
||||||
@@ -782,7 +783,11 @@ template <class Helper> UniValue _HeirAdd(uint256 fundingtxid, int64_t txfee, in
|
|||||||
|
|
||||||
// add cryptocondition to spend this funded amount for either pk
|
// add cryptocondition to spend this funded amount for either pk
|
||||||
mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey));
|
mtx.vout.push_back(Helper::make1of2Vout(amount, ownerPubkey, heirPubkey));
|
||||||
|
|
||||||
|
char markeraddr[64];
|
||||||
|
CPubKey markerPubkey = CCtxidaddr(markeraddr, fundingtxid);
|
||||||
|
mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(markerPubkey)) << OP_CHECKSIG)); // marker to prevent archiving of the funds add vouts
|
||||||
|
|
||||||
if (inputs > amount)
|
if (inputs > amount)
|
||||||
change = (inputs - amount); // -txfee <-- txfee pays user
|
change = (inputs - amount); // -txfee <-- txfee pays user
|
||||||
|
|
||||||
@@ -1232,10 +1237,10 @@ UniValue HeirInfo(uint256 fundingtxid)
|
|||||||
template <typename Helper>void _HeirList(struct CCcontract_info *cp, UniValue &result)
|
template <typename Helper>void _HeirList(struct CCcontract_info *cp, UniValue &result)
|
||||||
{
|
{
|
||||||
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>> unspentOutputs;
|
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue>> unspentOutputs;
|
||||||
char coinaddr[64];
|
char markeraddr[64];
|
||||||
CPubKey ccPubKeyEmpty;
|
|
||||||
GetCCaddress(cp, coinaddr, ccPubKeyEmpty);
|
GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL));
|
||||||
SetCCunspents(unspentOutputs, cp->normaladdr);
|
SetCCunspents(unspentOutputs, markeraddr);
|
||||||
|
|
||||||
//std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n';
|
//std::cerr << "HeirList() finding heir marker from Heir contract addr=" << cp->normaladdr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n';
|
||||||
|
|
||||||
@@ -1283,10 +1288,10 @@ UniValue HeirList()
|
|||||||
struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit!
|
struct CCcontract_info *cpHeir, *cpTokens, heirC, tokenC; // NOTE we must use a separate 'C' structure for each CCinit!
|
||||||
|
|
||||||
cpHeir = CCinit(&heirC, EVAL_HEIR);
|
cpHeir = CCinit(&heirC, EVAL_HEIR);
|
||||||
cpTokens = CCinit(&tokenC, EVAL_TOKENS);
|
//cpTokens = CCinit(&tokenC, EVAL_TOKENS);
|
||||||
|
|
||||||
_HeirList<CoinHelper>(cpHeir, result);
|
_HeirList<CoinHelper>(cpHeir, result);
|
||||||
_HeirList<TokenHelper>(cpTokens, result);
|
//_HeirList<TokenHelper>(cpTokens, result); not used anymore
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ 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, std::string& message) const = 0;
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const = 0;
|
||||||
virtual bool validateVout(CTxOut vout, std::string& message) const = 0;
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CCcontract_info * m_cp;
|
CCcontract_info * m_cp;
|
||||||
@@ -258,10 +258,10 @@ 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], refMessage);
|
result = v->validateVin(pTx->vin[iv], pPrevTx->vout[pTx->vin[iv].prevout.n], 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], refMessage);
|
result = v->validateVout( pPrevTx->vout[pTx->vin[iv].prevout.n], pTx->vin[iv].prevout.n, refMessage);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -359,7 +359,7 @@ private:
|
|||||||
|
|
||||||
if (!v->isVinValidator()) {
|
if (!v->isVinValidator()) {
|
||||||
// if this is a 'in' validation plan then pass the previous tx vout:
|
// if this is a 'in' validation plan then pass the previous tx vout:
|
||||||
bool result = v->validateVout(pTx->vout[iv], refMessage);
|
bool result = v->validateVout(pTx->vout[iv], iv, refMessage);
|
||||||
if (!result)
|
if (!result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -402,7 +402,7 @@ public:
|
|||||||
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; }
|
||||||
virtual bool validateVout(CTxOut vout, std::string& message) const
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const
|
||||||
{
|
{
|
||||||
//std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl;
|
//std::cerr << "CCC1of2AddressValidator::validateVout() entered" << std::endl;
|
||||||
CPubKey ownerPubkey, heirPubkey;
|
CPubKey ownerPubkey, heirPubkey;
|
||||||
@@ -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, std::string& message) const { return false; }
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
@@ -456,7 +456,7 @@ public:
|
|||||||
: 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; }
|
||||||
virtual bool validateVout(CTxOut vout, std::string& message) const
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const
|
||||||
{
|
{
|
||||||
//std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl;
|
//std::cerr << "CMyPubkeyVoutValidator::validateVout() entered" << std::endl;
|
||||||
|
|
||||||
@@ -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, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
@@ -516,7 +516,7 @@ public:
|
|||||||
: 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; }
|
||||||
virtual bool validateVout(CTxOut vout, std::string& message) const
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const
|
||||||
{
|
{
|
||||||
//std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl;
|
//std::cerr << "CHeirSpendValidator::validateVout() entered" << std::endl;
|
||||||
|
|
||||||
@@ -554,7 +554,7 @@ public:
|
|||||||
// this is not heir:
|
// this is not heir:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
virtual bool validateVin(CTxIn vin, CTxOut prevVout, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
@@ -572,7 +572,7 @@ public:
|
|||||||
: m_fundingOpretScript(opret), CValidatorBase(cp) {}
|
: m_fundingOpretScript(opret), CValidatorBase(cp) {}
|
||||||
|
|
||||||
virtual bool isVinValidator() const { return false; }
|
virtual bool isVinValidator() const { return false; }
|
||||||
virtual bool validateVout(CTxOut vout, std::string& message) const
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const
|
||||||
{
|
{
|
||||||
//std::cerr << "COpRetValidator::validateVout() entered" << std::endl;
|
//std::cerr << "COpRetValidator::validateVout() entered" << std::endl;
|
||||||
|
|
||||||
@@ -607,12 +607,42 @@ 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, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CScript m_fundingOpretScript;
|
CScript m_fundingOpretScript;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** marker spending prevention validator,
|
||||||
|
** returns false if for tx with funcid=F vout.1 is being tried to spend
|
||||||
|
*/
|
||||||
|
template <class Helper> class CMarkerValidator : CValidatorBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CMarkerValidator(CCcontract_info* cp)
|
||||||
|
: CValidatorBase(cp) { }
|
||||||
|
|
||||||
|
virtual bool isVinValidator() const { return false; } // this is vout validator
|
||||||
|
virtual bool validateVout(CTxOut vout, int32_t vout_n, std::string& message) const {
|
||||||
|
|
||||||
|
uint256 fundingTxidInOpret = zeroid, dummyTxid, tokenid = zeroid, initialTokenid = zeroid;
|
||||||
|
uint8_t dummyIsHeirSpendingBegan;
|
||||||
|
|
||||||
|
uint8_t funcId = DecodeHeirEitherOpRet(m_opret, tokenid, fundingTxidInOpret, dummyIsHeirSpendingBegan, true);
|
||||||
|
|
||||||
|
if( funcId == 'F' && vout_n == 1 )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CScript m_fundingOpretScript;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* empty validator always returns true
|
* empty validator always returns true
|
||||||
*/
|
*/
|
||||||
@@ -623,8 +653,8 @@ public:
|
|||||||
: CValidatorBase(cp) { }
|
: CValidatorBase(cp) { }
|
||||||
|
|
||||||
virtual bool isVinValidator() const { return false; }
|
virtual bool isVinValidator() const { return false; }
|
||||||
virtual bool validateVout(CTxOut vout, 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, std::string& message) const { return true; }
|
virtual bool validateVin(CTxIn vin, CTxOut prevVout, int32_t vout_n, std::string& message) const { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user