From ff3116ce3cd816007fba72e1ea8a4bd3c270eef0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 02:55:45 -1100 Subject: [PATCH] Chance for AssetConvert to validate --- src/cc/CCassetsCore.cpp | 3 ++- src/cc/CCassetstx.cpp | 3 +-- src/cc/assets.cpp | 1 - src/cc/gateways.cpp | 6 +++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index cd2e267e1..e2bcf01ff 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -490,8 +490,9 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti fprintf(stderr,"i.%d starti.%d numvins.%d\n",i,starti,numvins); return eval->Invalid("always should find vin, but didnt"); } - else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) + else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 || vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + assetoshis = vinTx.vout[i].nValue; fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); inputs += assetoshis; } diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 2ce13a1ff..70a2c76ee 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -261,9 +261,8 @@ std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector dest { if ( inputs > total ) CCchange = (inputs - total); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); mtx.vout.push_back(MakeCC1vout(evalcode,total,pubkey2pk(destpubkey))); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index bf979a1e0..fa6d87500 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -167,7 +167,6 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.n-1: opreturn [EVAL_ASSETS] ['c'] [{"":""}] return eval->Invalid("unexpected AssetValidate for createasset"); break; - case 't': // transfer //vin.0: normal input //vin.1 .. vin.n-1: valid CC outputs diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5c06a7c54..976cd1971 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -134,7 +134,11 @@ Implementation Issues: When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. - Care must be taken so that tokens are not lost and can be converted back + Care must be taken so that tokens are not lost and can be converted back. + + This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 251 + + The gatewaysclaim automatically converts the deposit amount of tokens back to EVAL_ASSETS. */