This commit is contained in:
jl777
2018-07-26 00:36:53 -11:00
parent c272ff8636
commit 855ff4a174
2 changed files with 16 additions and 18 deletions

View File

@@ -139,36 +139,36 @@ bool SetAskFillamounts(uint64_t &received_assetoshis,uint64_t &remaining_nValue,
} else return(false); } else return(false);
} }
bool ValidateAskRemainder(uint64_t remaining_price,uint64_t remaining_nValue,uint64_t orig_nValue,uint64_t received_nValue,uint64_t paidunits,uint64_t totalunits) bool ValidateAskRemainder(uint64_t remaining_nValue,uint64_t remaining_assetoshis,uint64_t orig_assetoshis,uint64_t received_assetoshis,uint64_t paid_nValue,uint64_t total_nValue)
{ {
uint64_t unitprice,recvunitprice,newunitprice=0; uint64_t unitprice,recvunitprice,newunitprice=0;
if ( orig_nValue == 0 || received_nValue == 0 || paidunits == 0 || totalunits == 0 ) if ( orig_assetoshis == 0 || received_assetoshis == 0 || paid_nValue == 0 || total_nValue == 0 )
{ {
fprintf(stderr,"ValidateAssetRemainder: orig_nValue == %llu || received_nValue == %llu || paidunits == %llu || totalunits == %llu\n",(long long)orig_nValue,(long long)received_nValue,(long long)paidunits,(long long)totalunits); fprintf(stderr,"ValidateAssetRemainder: orig_assetoshis == %llu || received_assetoshis == %llu || paid_nValue == %llu || total_nValue == %llu\n",(long long)orig_assetoshis,(long long)received_assetoshis,(long long)paid_nValue,(long long)total_nValue);
return(false); return(false);
} }
else if ( totalunits != (remaining_price + paidunits) ) else if ( total_nValue != (remaining_nValue + paid_nValue) )
{ {
fprintf(stderr,"ValidateAssetRemainder: totalunits %llu != %llu (remaining_price %llu + %llu paidunits)\n",(long long)totalunits,(long long)(remaining_price + paidunits),(long long)remaining_price,(long long)paidunits); fprintf(stderr,"ValidateAssetRemainder: total_nValue %llu != %llu (remaining_nValue %llu + %llu paid_nValue)\n",(long long)total_nValue,(long long)(remaining_nValue + paid_nValue),(long long)remaining_nValue,(long long)paid_nValue);
return(false); return(false);
} }
else if ( orig_nValue != (remaining_nValue + received_nValue) ) else if ( orig_assetoshis != (remaining_assetoshis + received_assetoshis) )
{ {
fprintf(stderr,"ValidateAssetRemainder: orig_nValue %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_nValue,(long long)(remaining_nValue - received_nValue),(long long)remaining_nValue,(long long)received_nValue); fprintf(stderr,"ValidateAssetRemainder: orig_assetoshis %llu != %llu (remaining_nValue %llu + %llu received_nValue)\n",(long long)orig_assetoshis,(long long)(remaining_assetoshis - received_assetoshis),(long long)remaining_assetoshis,(long long)received_assetoshis);
return(false); return(false);
} }
else else
{ {
unitprice = (orig_nValue * COIN) / totalunits; unitprice = (orig_nValue / orig_assetoshis);
recvunitprice = (received_nValue * COIN) / paidunits; recvunitprice = (received_nValue / received_assetoshis);
if ( remaining_price != 0 ) if ( remaining_nValue != 0 )
newunitprice = (remaining_nValue * COIN) / remaining_price; newunitprice = (remaining_nValue / remaining_assetoshis);
if ( recvunitprice < unitprice ) if ( recvunitprice < unitprice )
{ {
fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); fprintf(stderr,"error recvunitprice %.8f < %.8f unitprice, new unitprice %.8f\n",(double)recvunitprice/COIN,(double)unitprice/COIN,(double)newunitprice/COIN);
return(false); return(false);
} }
fprintf(stderr,"recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); fprintf(stderr,"error recvunitprice %.8f >= %.8f unitprice, new unitprice %.8f\n",(double)recvunitprice/COIN,(double)unitprice/COIN,(double)newunitprice/COIN);
} }
return(true); return(true);
} }

View File

@@ -228,7 +228,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
else else
{ {
inputs = 0; inputs = 0;
for (i=2; i<numvouts; i++) for (i=2; i<numvouts-1; i++)
{ {
if ((assetoshis= IsAssetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 && ConstrainVout(tx.vout[i],1,CCaddr,0) == assetoshis ) if ((assetoshis= IsAssetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 && ConstrainVout(tx.vout[i],1,CCaddr,0) == assetoshis )
inputs += assetoshis; inputs += assetoshis;
@@ -296,7 +296,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
else else
{ {
inputs = 0; inputs = 0;
for (i=2; i<numvouts; i++) for (i=2; i<numvouts-1; i++)
{ {
if ( (nValue= ConstrainVout(tx.vout[i],0,origaddr,0)) != 0 ) if ( (nValue= ConstrainVout(tx.vout[i],0,origaddr,0)) != 0 )
inputs += nValue; inputs += nValue;
@@ -341,13 +341,11 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx
else else
{ {
inputs = 0; inputs = 0;
for (i=2; i<numvouts; i++) for (i=2; i<numvouts-1; i++)
{ {
if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 && ConstrainVout(tx.vout[i],1,CCaddr,0) == assetoshis ) if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 && ConstrainVout(tx.vout[i],1,CCaddr,0) == assetoshis )
inputs += assetoshis; inputs += assetoshis;
} }
//ValidateAssetRemainder: orig_nValue == 10 || received_nValue == 0 || paidunits == 10 || totalunits == 100000000000
//bool ValidateAssetRemainder(int32_t sellflag,uint64_t remaining_price,uint64_t remaining_nValue,uint64_t orig_nValue,uint64_t received_nValue,uint64_t paidunits,uint64_t totalunits)
fprintf(stderr,"assets vout0 %llu, vin1 %llu, vout2 %llu -> orig, vout1 %llu, total %llu\n",(long long)tx.vout[0].nValue,(long long)assetoshis,(long long)tx.vout[2].nValue,(long long)tx.vout[1].nValue,(long long)totalunits); fprintf(stderr,"assets vout0 %llu, vin1 %llu, vout2 %llu -> orig, vout1 %llu, total %llu\n",(long long)tx.vout[0].nValue,(long long)assetoshis,(long long)tx.vout[2].nValue,(long long)tx.vout[1].nValue,(long long)totalunits);
if ( ValidateSwapRemainder(remaining_price,tx.vout[0].nValue,assetoshis,tx.vout[2].nValue,tx.vout[1].nValue,totalunits) == false ) if ( ValidateSwapRemainder(remaining_price,tx.vout[0].nValue,assetoshis,tx.vout[2].nValue,tx.vout[1].nValue,totalunits) == false )
return eval->Invalid("mismatched remainder for fill"); return eval->Invalid("mismatched remainder for fill");