From 0de5ed27ed2edfd365ba1a560bec5605737e4830 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 27 Jul 2018 00:55:55 -1100 Subject: [PATCH] Error check bidding for assetid that is txid but not asset creation --- src/cc/CCassets.h | 1 + src/cc/CCassetsCore.cpp | 13 +++++++++++++ src/cc/CCassetstx.cpp | 7 ++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 0b566bdd2..c072bde89 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -32,6 +32,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //CTxOut MakeAssetsVout(CAmount nValue,CPubKey pk); CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); +bool DecodeAssetCreateOpRet(std::vector &origpubkey,std::string &name,std::string &description); uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index f57e50525..53a75c58c 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -256,6 +256,19 @@ CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t return(opret); } +bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description) +{ + uint8_t evalcode,funcid,*script; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( script != 0 && vopret.size() > 2 && script[0] == EVAL_ASSETS && script[1] == 'c' ) + { + if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> origpubkey; ss >> name; ss >> description) != 0 ) + return(true); + } + return(0); +} + uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) { std::vector vopret; uint8_t funcid=0,*script,e,f; diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index d3a887c06..d5a0b4999 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -198,7 +198,7 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal) { - CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; + CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; if ( bidamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n",(long long)bidamount,(long long)pricetotal); @@ -209,6 +209,11 @@ std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64 fprintf(stderr,"cant find assetid\n"); return(0); } + if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + return(0); + } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000;