From c2942d60a487571a6d9c6a1d0a52d72e48fe84b4 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 10 Jan 2019 15:23:07 +0500 Subject: [PATCH] Tokens CC cond test code added to HeirClaim TokenValidate --- src/cc/CCinclude.h | 2 ++ src/cc/CCtokens.cpp | 2 +- src/cc/CCutils.cpp | 14 +++++++++++++- src/cc/heir.cpp | 6 +++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3e70ba380..2ebba82f7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -189,6 +189,8 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *c CTxOut MakeTokensCC1of2vout(uint8_t evalcode, CAmount nValue, CPubKey pk1, CPubKey pk2); CC *MakeTokensCCcond1of2(uint8_t evalcode, CPubKey pk1, CPubKey pk2); +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2); +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr); bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 8e4dc17ca..362529a53 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -337,7 +337,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c if (voutPubkeys.size() == 1) testVout = MakeCC1vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0]); else // voutPubkeys.size() == 2 - testVout = MakeCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); + testVout = MakeTokensCC1of2vout(EVAL_TOKENS, tx.vout[v].nValue, voutPubkeys[0], voutPubkeys[1]); if (tx.vout[v].scriptPubKey == testVout.scriptPubKey) { //std::cerr << indentStr << "IsTokensvout() vout is EVAL_TOKENS, returning nValue=" << tx.vout[v].nValue << " for txid=" << tx.GetHash().GetHex() << " for tokenid=" << reftokenid.GetHex() << std::endl; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index c07755c2a..f677127a6 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -237,7 +237,7 @@ void CCaddr1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *c } // set pubkeys, myprivkey and 1of2 cc addr for spending from 1of2 tokens cryptocondition vout: -void CCaddr1of2setTokens(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) +void CCaddrTokens1of2set(struct CCcontract_info *cp, CPubKey pk1, CPubKey pk2, char *coinaddr) { cp->tokens1of2pk[0] = pk1; cp->tokens1of2pk[1] = pk2; @@ -348,6 +348,18 @@ bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubK return(destaddr[0] != 0); } +bool GetTokensCCaddress1of2(struct CCcontract_info *cp, char *destaddr, CPubKey pk, CPubKey pk2) +{ + CC *payoutCond; + destaddr[0] = 0; + if ((payoutCond = MakeTokensCCcond1of2(cp->evalcode, pk, pk2)) != 0) + { + Getscriptaddress(destaddr, CCPubKey(payoutCond)); + cc_free(payoutCond); + } + return(destaddr[0] != 0); +} + bool ConstrainVout(CTxOut vout, int32_t CCflag, char *cmpaddr, int64_t nValue) { char destaddr[64]; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index fe93e7a5a..1d776a865 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -578,7 +578,7 @@ template int64_t Add1of2AddressInputs(struct CCcontract_info* cp, std::vector> unspentOutputs; char coinaddr[64]; - GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 pubkey of 2 pubkeys' + GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); // get address of cryptocondition '1 pubkey of 2 pubkeys' SetCCunspents(unspentOutputs, coinaddr); // char markeraddr[64]; @@ -930,7 +930,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee uint8_t myprivkey[32]; char coinaddr[64]; // set priv key addresses in CC structure: - GetCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); + GetTokensCCaddress1of2(cp, coinaddr, ownerPubkey, heirPubkey); Myprivkey(myprivkey); ////fprintf(stderr,"HeirClaim() before setting unspendable CC addr2= (%s) addr3= (%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); @@ -938,7 +938,7 @@ template UniValue HeirClaim(uint256 fundingtxid, uint64_t txfee //CCaddr3set(cp, Helper::getMyEval(), heirPubkey, myprivkey, coinaddr); ////fprintf(stderr, "HeirClaim() after setting unspendable CC addr2=(%s) addr3=(%s)\n", cp->unspendableaddr2, cp->unspendableaddr3); - CCaddr1of2set(cp, ownerPubkey, heirPubkey, coinaddr); + CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, coinaddr); // add 1of2 vout validation pubkeys: std::vector voutTokenPubkeys;