added conds for ask/bid in GetAssetorigaddrs

This commit is contained in:
dimxy
2019-01-16 22:39:21 +05:00
parent 9293af0f1b
commit a99fd7502d
2 changed files with 21 additions and 6 deletions

View File

@@ -353,6 +353,7 @@ uint8_t DecodeAssetTokenOpRet(const CScript &scriptPubKey, uint8_t &evalCodeInOp
return (uint8_t)0; return (uint8_t)0;
} }
// extract sell/buy owner's pubkey from the opret
bool SetAssetOrigpubkey(std::vector<uint8_t> &origpubkey,int64_t &price,const CTransaction &tx) bool SetAssetOrigpubkey(std::vector<uint8_t> &origpubkey,int64_t &price,const CTransaction &tx)
{ {
uint256 assetid,assetid2; uint256 assetid,assetid2;
@@ -362,8 +363,9 @@ bool SetAssetOrigpubkey(std::vector<uint8_t> &origpubkey,int64_t &price,const CT
else else
return(false); return(false);
} }
bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) // Calculate sell/buy owner's source token/asset address from ask/bid tx
bool GetAssetorigaddrs(struct CCcontract_info *cp, char *CCaddr, char *destaddr, const CTransaction& tx)
{ {
uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid;
std::vector<uint8_t> origpubkey; std::vector<uint8_t> origpubkey;
@@ -373,7 +375,18 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co
n = tx.vout.size(); n = tx.vout.size();
if( n == 0 || (funcid = DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) == 0 ) if( n == 0 || (funcid = DecodeAssetTokenOpRet(tx.vout[n-1].scriptPubKey, evalCode, assetid, assetid2, price, origpubkey)) == 0 )
return(false); return(false);
if( GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG) != 0 )
bool bGetCCaddr = false;
if (funcid == 's' || funcid == 'S')
bGetCCaddr = GetTokensCCaddress(cp, CCaddr, pubkey2pk(origpubkey));
else if (funcid == 'b' || funcid == 'B')
bGetCCaddr = GetCCaddress(cp, CCaddr, pubkey2pk(origpubkey));
else {
std::cerr << "GetAssetorigaddrs incorrect funcid=" << (char)(funcid?funcid:' ') << std::endl;
return false;
}
if( bGetCCaddr && Getscriptaddress(destaddr, CScript() << origpubkey << OP_CHECKSIG))
return(true); return(true);
else else
return(false); return(false);

View File

@@ -334,8 +334,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
//'S'.vout.2: vin.2 value to original pubkey [origpubkey] //'S'.vout.2: vin.2 value to original pubkey [origpubkey]
//vout.3: normal output for change (if any) //vout.3: normal output for change (if any)
//'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey] //'S'.vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey]
char dualEvalUnspendableAddr[64];
GetTokensCCaddress(cpAssets, dualEvalUnspendableAddr, GetUnspendable(cpAssets, NULL));
if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 ) if( (assetoshis = AssetValidateSellvin(cpAssets, eval, totalunits, tmporigpubkey, tokensCCaddr, origaddr, tx, assetid)) == 0 )
return(false); return(false);
@@ -355,7 +354,10 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
return eval->Invalid("normal vout1 for fillask"); return eval->Invalid("normal vout1 for fillask");
else if( remaining_price != 0 ) else if( remaining_price != 0 )
{ {
if ( ConstrainVout(tx.vout[0], 1, dualEvalUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 ) char tokensUnspendableAddr[64];
GetTokensCCaddress(cpAssets, tokensUnspendableAddr, GetUnspendable(cpAssets, NULL));
if ( ConstrainVout(tx.vout[0], 1, tokensUnspendableAddr /*(char *)cpAssets->unspendableCCaddr*/, 0) == 0 )
return eval->Invalid("mismatched vout0 assets dual unspendable CCaddr for fill sell"); return eval->Invalid("mismatched vout0 assets dual unspendable CCaddr for fill sell");
} }
} }