Fix 'b'/'B' vout0 exemption

This commit is contained in:
jl777
2018-07-23 00:24:32 -11:00
parent db2a2a0e14
commit 1d504829f1
2 changed files with 18 additions and 11 deletions

View File

@@ -238,7 +238,7 @@ uint64_t IsAssetvout(uint64_t &price,std::vector<uint8_t> &origpubkey,const CTra
if ( refassetid == tx.GetHash() && v == 0 ) if ( refassetid == tx.GetHash() && v == 0 )
return(nValue); return(nValue);
} }
else if ( funcid == 'b' || funcid == 'B' ) else if ( (funcid == 'b' || funcid == 'B') && v == 0 ) // critical! 'b'/'B' vout0 is NOT asset
return(0); return(0);
else if ( funcid != 'E' ) else if ( funcid != 'E' )
{ {
@@ -319,22 +319,31 @@ bool AssetExactAmounts(uint64_t &inputs,uint64_t &outputs,Eval* eval,const CTran
numvins = tx.vin.size(); numvins = tx.vin.size();
numvouts = tx.vout.size(); numvouts = tx.vout.size();
inputs = outputs = 0; inputs = outputs = 0;
for (i=1; i<numvins; i++) for (i=0; i<numvins; i++)
{ {
if ( IsAssetsInput(tx.vin[i].scriptSig) != 0 ) if ( IsAssetsInput(tx.vin[i].scriptSig) != 0 )
{ {
if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 )
return eval->Invalid("always should find vin, but didnt"); 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 )
{
fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis)
inputs += assetoshis; inputs += assetoshis;
}
} }
} }
for (i=0; i<numvouts; i++) for (i=0; i<numvouts; i++)
{ {
if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 ) if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,tx,i,assetid)) != 0 )
{
fprintf(stderr,"vout%d %llu, ",i,(long long)assetoshis)
outputs += assetoshis; outputs += assetoshis;
}
} }
if ( inputs != outputs ) if ( inputs != outputs )
{
fprintf(stderr,"inputs %.8f vs %.8f outputs\n",(double)inputs/COIN,(double)outputs/COIN);
return(false); return(false);
}
else return(true); else return(true);
} }

View File

@@ -143,7 +143,7 @@ bool AssetValidate(Eval* eval,const CTransaction &tx,int32_t numvouts,uint8_t fu
if ( assetid == zero ) if ( assetid == zero )
return eval->Invalid("illegal assetid"); return eval->Invalid("illegal assetid");
else if ( AssetExactAmounts(inputs,outputs,eval,tx,assetid) == false ) else if ( AssetExactAmounts(inputs,outputs,eval,tx,assetid) == false )
eval->Invalid("asset inputs != outputs"); return eval->Invalid("asset inputs != outputs");
} }
switch ( funcid ) switch ( funcid )
{ {
@@ -310,11 +310,11 @@ bool AssetValidate(Eval* eval,const CTransaction &tx,int32_t numvouts,uint8_t fu
bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn) bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull,const CTransaction &ctx, unsigned int nIn)
{ {
static uint256 zero; static uint256 zero,prevtxid;
CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector<uint8_t> origpubkey; CTransaction createTx; uint256 txid,assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector<uint8_t> origpubkey;
//txid = ctx.GetHash(); txid = ctx.GetHash();
//if ( txid == prevtxid ) if ( txid == prevtxid )
// return(true); return(true);
fprintf(stderr,"ProcessAssets\n"); fprintf(stderr,"ProcessAssets\n");
if ( paramsNull.size() != 0 ) // Don't expect params if ( paramsNull.size() != 0 ) // Don't expect params
return eval->Invalid("Cannot have params"); return eval->Invalid("Cannot have params");
@@ -328,9 +328,7 @@ bool ProcessAssets(Eval* eval, std::vector<uint8_t> paramsNull,const CTransactio
return eval->Invalid("cant find asset2 create txid"); return eval->Invalid("cant find asset2 create txid");
else if ( AssetValidate(eval,ctx,n,funcid,assetid,assetid2,amount,origpubkey) != 0 ) else if ( AssetValidate(eval,ctx,n,funcid,assetid,assetid2,amount,origpubkey) != 0 )
{ {
//prevtxid = txid; prevtxid = txid;
if ( funcid == 'B' )
return(false);
fprintf(stderr,"AssetValidate.(%c) passed\n",funcid); fprintf(stderr,"AssetValidate.(%c) passed\n",funcid);
return(true); return(true);
} }