This commit is contained in:
jl777
2018-11-06 13:09:53 -11:00
parent d8b84e4ef7
commit 44a4e411eb
2 changed files with 5 additions and 29 deletions

View File

@@ -326,7 +326,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *
int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs)
{ {
int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector<COutput> vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up;
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
const CKeyStore& keystore = *pwalletMain; const CKeyStore& keystore = *pwalletMain;
assert(pwalletMain != NULL); assert(pwalletMain != NULL);
@@ -336,16 +336,15 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3
threshold = total/maxinputs; threshold = total/maxinputs;
if ( maxinputs > maxutxos ) if ( maxinputs > maxutxos )
maxutxos = maxinputs; maxutxos = maxinputs;
sum = 0;
BOOST_FOREACH(const COutput& out, vecOutputs) BOOST_FOREACH(const COutput& out, vecOutputs)
{ {
if ( out.fSpendable != 0 ) if ( out.fSpendable != 0 && out.tx->vout[out.i].nValue >= threshold )
{ {
txid = out.tx->GetHash(); txid = out.tx->GetHash();
vout = out.i; vout = out.i;
if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 )
{ {
if ( out.tx->vout[out.i].nValue < threshold )
continue;
//fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout);
if ( mtx.vin.size() > 0 ) if ( mtx.vin.size() > 0 )
{ {
@@ -369,8 +368,9 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3
up->txid = txid; up->txid = txid;
up->nValue = out.tx->vout[out.i].nValue; up->nValue = out.tx->vout[out.i].nValue;
up->vout = vout; up->vout = vout;
sum += up->nValue;
//fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos);
if ( n >= maxutxos ) if ( n >= maxutxos || sum >= total )
break; break;
} }
} }

View File

@@ -1069,7 +1069,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
fprintf(stderr,"0 ");
fundingpk = DiceFundingPk(fundingPubKey); fundingpk = DiceFundingPk(fundingPubKey);
if ( winlosetimeout != 0 ) // must be dealernode if ( winlosetimeout != 0 ) // must be dealernode
{ {
@@ -1080,17 +1079,14 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c
winlosetimeout = 0; winlosetimeout = 0;
} }
} }
fprintf(stderr,"1 ");
if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!!
{ {
CCerror = "no txfee inputs for win/lose"; CCerror = "no txfee inputs for win/lose";
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
fprintf(stderr,"2 ");
if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 )
{ {
fprintf(stderr,"3 ");
entropytxid = betTx.vin[0].prevout.hash; entropytxid = betTx.vin[0].prevout.hash;
CSpentIndexKey key(bettxid, 0); CSpentIndexKey key(bettxid, 0);
CSpentIndexValue value; CSpentIndexValue value;
@@ -1102,27 +1098,15 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
/*if ( CCtxidvalue(cp->unspendableCCaddr,bettxid,0) != 0 && CCtxidvalue(cp->unspendableCCaddr,bettxid,1) != 0 ) // already confirmed
{
if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) // but not unspent -> spent
{
CCerror = "bettxid already spent";
fprintf(stderr,"%s\n", CCerror.c_str() );
return("");
}
}*/
fprintf(stderr,"4 ");
bettorentropy = DiceGetEntropy(betTx,'B'); bettorentropy = DiceGetEntropy(betTx,'B');
if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 )
{ {
fprintf(stderr,"5 ");
if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 )
{ {
CCerror = "bettxid already spent in mempool"; CCerror = "bettxid already spent in mempool";
fprintf(stderr,"%s\n", CCerror.c_str() ); fprintf(stderr,"%s\n", CCerror.c_str() );
return(""); return("");
} }
fprintf(stderr,"6 ");
if ( winlosetimeout != 0 ) // dealernode if ( winlosetimeout != 0 ) // dealernode
{ {
entropyused = hentropyproof; entropyused = hentropyproof;
@@ -1137,7 +1121,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c
funcid = 'W'; funcid = 'W';
else funcid = 'L'; else funcid = 'L';
} }
fprintf(stderr,"7 ");
if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here
{ {
//fprintf(stderr,"iswin.%d matches\n",iswin); //fprintf(stderr,"iswin.%d matches\n",iswin);
@@ -1157,7 +1140,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c
fprintf(stderr,"set timeout win T\n"); fprintf(stderr,"set timeout win T\n");
} }
} }
fprintf(stderr,"8 ");
if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path
{ {
odds = (betTx.vout[2].nValue - txfee); odds = (betTx.vout[2].nValue - txfee);
@@ -1193,13 +1175,11 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c
mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey));
} }
//fprintf(stderr,"make tx.%c\n",funcid); //fprintf(stderr,"make tx.%c\n",funcid);
fprintf(stderr,"9 ");
if ( funcid == 'L' || funcid == 'W' ) // dealernode only if ( funcid == 'L' || funcid == 'W' ) // dealernode only
hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash);
*resultp = 1; *resultp = 1;
//char str[65],str2[65]; //char str[65],str2[65];
//fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy));
fprintf(stderr,"z ");
return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof)));
} else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout); } else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout);
} }
@@ -1256,14 +1236,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str());
continue; continue;
} }
fprintf(stderr,"[");
res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey);
fprintf(stderr,"]");
if ( result > 0 ) if ( result > 0 )
{ {
fprintf(stderr,"(");
mySenddicetransaction(res,entropyused,txid); mySenddicetransaction(res,entropyused,txid);
fprintf(stderr,")");
n++; n++;
} else error = res; } else error = res;
} }