added isTokenVout call to Add1of2address func in heir.cpp

corrected ExtractTokensVinPubkeys call -> in isTokensVout
This commit is contained in:
dimxy
2019-01-14 01:27:45 +05:00
parent 42a48b9653
commit 5c35c03d60
2 changed files with 16 additions and 16 deletions

View File

@@ -262,14 +262,17 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction &
// helper funcs:
// extract my vins pubkeys:
bool ExtractVinPubkeys(struct CCcontract_info *cp, CTransaction tx, std::vector<CPubKey> &vinPubkeys) {
bool ExtractTokensVinPubkeys(CTransaction tx, std::vector<CPubKey> &vinPubkeys) {
bool found = false;
CPubKey pubkey;
struct CCcontract_info *cpTokens, tokensC;
cpTokens = CCinit(&tokensC, EVAL_TOKENS);
for (int32_t i = 0; i < tx.vin.size(); i++)
{ // check for additional contracts which may send tokens to the Tokens contract
if( (*cp->ismyvin)(tx.vin[i].scriptSig) )
if( (*cpTokens->ismyvin)(tx.vin[i].scriptSig) )
{
auto findEval = [](CC *cond, struct CCVisitor _) {
@@ -345,7 +348,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec
// goDeeper is true: the func also validates amounts of the passed transaction:
// it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx
// checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true!
int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector<uint8_t> &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector<CPubKey> vinPubkeys)
int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector<uint8_t> &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector<CPubKey> vinPubkeys000)
{
// this is just for log messages indentation fur debugging recursive calls:
@@ -421,6 +424,9 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c
}
// maybe it is token change?
std::vector<CPubKey> vinPubkeys;
ExtractTokensVinPubkeys(tx, vinPubkeys);
for(std::vector<CPubKey>::iterator it = vinPubkeys.begin(); it != vinPubkeys.end(); it++) {
CTxOut testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it);
@@ -450,7 +456,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t
//int32_t flag;
int64_t tokenoshis;
// std::vector<uint8_t> tmporigpubkey; int64_t tmpprice;
std::vector<CPubKey> vinPubkeys, vinPubkeysEmpty;
std::vector<CPubKey> vinPubkeys;
int32_t numvins = tx.vin.size();
int32_t numvouts = tx.vout.size();
@@ -459,7 +465,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t
// this is just for log messages indentation for debugging recursive calls:
std::string indentStr = std::string().append(tokenValIndentSize, '.');
ExtractVinPubkeys(cpTokens, tx, vinPubkeys);
ExtractTokensVinPubkeys(tx, vinPubkeys);
for (int32_t i = 0; i<numvins; i++)
{ // check for additional contracts which may send tokens to the Tokens contract

View File

@@ -590,22 +590,16 @@ template <class Helper> int64_t Add1of2AddressInputs(struct CCcontract_info* cp,
if (GetTransaction(txid, heirtx, hashBlock, false) != 0) {
uint256 tokenid;
uint256 fundingTxidInOpret;
uint8_t dummyHasHeirSpendingBegun;
uint8_t evalCodeTokens = 0;
std::vector<uint8_t> vopretExtra;
std::vector<CPubKey> voutPubkeys;
uint8_t hasHeirSpendingBegunDummy;
std::vector<CPubKey> vinPubkeysEmpty;
CScript heirScript = heirtx.vout[heirtx.vout.size() - 1].scriptPubKey;
uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra);
if (funcId != 0) {
heirScript = CScript(vopretExtra);
}
funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true);
CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript();
uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false);
if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) &&
funcId != 0 &&
isMyFuncId(funcId) &&
// (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && // deep validation for tokens - not used anymore
(typeid(Helper) == typeid(TokenHelper) && IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid, vinPubkeysEmpty) > 0) && // deep validation for tokens - not used anymore
(voutValue = IsHeirFundingVout<Helper>(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 &&
!myIsutxo_spentinmempool(txid, voutIndex))
{