diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index c868cc705..cb0398129 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -30,5 +30,6 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); UniValue DiceList(); +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random); #endif diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 45025d274..6f8a910f0 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -51,7 +51,7 @@ one other technical note is that komodod has the insight-explorer extensions bui #include "../utlist.h" #include "../uthash.h" -extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; +extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE,KOMODO_DEALERNODE; extern uint32_t ASSETCHAINS_CC; extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2f2a86957..69f685cf3 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -41,7 +41,10 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*cond; CPubKey unspendablepk; + CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; + int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0,normalvins=0,ccvins=0; + int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; + uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*othercond2=0,*othercond3=0,*cond; CPubKey unspendablepk; n = mtx.vout.size(); for (i=0; i 0 ) mtx.vout.push_back(CTxOut(0,opret)); PrecomputedTransactionData txdata(mtx); - n = mtx.vin.size(); + n = mtx.vin.size(); + //Reorder vins so that for multiple normal vins all other except vin0 goes to the end + //This is a must to avoid hardfork change of validation in every CC, because there could be maximum one normal vin at the begining with current validation. + if (normalvins>1) + { + for(i=1;iunspendableaddr2); privkey = cp->unspendablepriv2; - if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS) + if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR ) othercond2 = MakeCCcond1(cp->evalcode2,cp->unspendablepk2); - else if ( othercond2 == 0 && cp->evalcode == EVAL_CHANNELS) + else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR) ) othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); cond = othercond2; } @@ -160,7 +175,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } } } else fprintf(stderr,"FinalizeCCTx couldnt find %s\n",mtx.vin[i].prevout.hash.ToString().c_str()); - } + } if ( mycond != 0 ) cc_free(mycond); if ( othercond != 0 ) @@ -276,9 +291,9 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * abovei = belowi = -1; for (above=below=i=0; i 500 ) { - // if ( (rand() % 100) < 80 ) + // Filter to randomly pick utxo to avoid conflicts, and having multiple CC choose the same ones. + //if ( numunspents > 200 ) { + // if ( (rand() % 100) < 90 ) // continue; //} if ( (atx_value= utxos[i].nValue) <= 0 ) diff --git a/src/cc/dapps/sendmany100 b/src/cc/dapps/sendmany100 new file mode 100755 index 000000000..9638766ab --- /dev/null +++ b/src/cc/dapps/sendmany100 @@ -0,0 +1,2 @@ +./komodo-cli -ac_name=KMDICE sendmany "" "{\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002,\"RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo\":0.0002}" + diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index aa9418e72..d13a245d4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 -#define DICE_MINUTXOS 7777 +#define DICE_MINUTXOS 10000 extern int32_t KOMODO_INSYNC; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -226,7 +226,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,int32_t entropyvo //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,oldentropyvout,entropyused,bettxid,betTx,entropyvout)) >= 0 ) { - //LOCK(cs_main); + LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); @@ -319,10 +319,11 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CTransaction betTx,finishTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); + dicepk = GetUnspendable(cp,0); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); if ( (newht= KOMODO_INSYNC) == 0 ) @@ -393,18 +394,28 @@ void *dicefinish(void *_ptr) fprintf(stderr,"send refund!\n"); mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } + dicefinish_delete(ptr); continue; } } if ( ptr->bettxid_ready != 0 ) { - if ( newblock != 0 && ptr->txid != zeroid ) + if ( now > ptr->bettxid_ready + 2*3600 ) { - CCduration(numblocks,ptr->txid); - //fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); - if ( numblocks == 0 ) - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); - else continue; + fprintf(stderr,"purge bettxid_ready %s\n",ptr->bettxid.GetHex().c_str()); + dicefinish_delete(ptr); + continue; + } + else if ( newblock != 0 ) + { + if ( ptr->txid != zeroid ) + { + CCduration(numblocks,ptr->txid); + //fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( numblocks == 0 ) + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + else continue; + } } if ( ptr->txid == zeroid ) vin0_needed++; @@ -417,7 +428,7 @@ void *dicefinish(void *_ptr) utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { - //fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); + //fprintf(stderr,"iter.%d vin0_needed.%d got %d, num 0.0002 %d\n",iter,vin0_needed,n,num); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -471,28 +482,7 @@ void *dicefinish(void *_ptr) } } } - else if ( newblock != 0 ) - dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( newblock != 0 && num < DICE_MINUTXOS ) - { - char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - n = sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; - fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n); - for (i=0; i>>>>>>>>>>> use (%c) %.8f %s %s/v%d\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid),vout); mtx.vin.push_back(CTxIn(txid,vout,CScript())); } totalinputs += it->second.satoshis; @@ -1142,7 +1133,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); - if ( (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) + if ( (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'R' || funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; @@ -1205,7 +1196,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } } } - else if ( funcid != 'B' ) + else if ( 0 && funcid != 'B' ) fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case funcid (%c) %d %s vs %s\n",funcid,funcid,uint256_str(str,reffundingtxid),uint256_str(str2,fundingtxid)); } //else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); @@ -1443,7 +1434,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet entropyval = entropyval2; entropytxid = entropytxid2; } - if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) + if ( funding >= 2*bet*odds+txfee && entropyval != 0 ) { if ( entropytxs < 100 ) { CCerror = "Your dealer is broke, find a new casino."; @@ -1477,7 +1468,6 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv entropyused = zeroid; *resultp = 0; funcid = 0; - //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in finish, is your transaction confirmed?"; @@ -1539,7 +1529,8 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); funcid = 'R'; - mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue,dicepk)); + //mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); *resultp = 1; @@ -1639,9 +1630,72 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv return("couldnt find bettx or entropytx"); } +static uint256 dealer0_fundingtxid; +void *dealer0_loop(void *_arg) +{ + char *planstr = (char *)_arg; + CTransaction tx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,i,n,num; CScript fundingPubKey; struct CCcontract_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000; + if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + { + fprintf(stderr,"error initializing dealer0_loop\n"); + exit(-1); + } + fprintf(stderr,"dealer0 node running\n"); + while ( 1 ) + { + DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,dealer0_fundingtxid,entropytxs,false); + if ( entropytxs < DICE_MINUTXOS ) + { + n = sqrt(DICE_MINUTXOS - entropytxs) + 10; + for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) + { + if ( DecodeHexTx(tx,res) != 0 ) + { + LOCK(cs_main); + if ( myAddtomempool(tx) != 0 ) + { + fprintf(stderr,"ENTROPY %s: %d of %d, %d\n",tx.GetHash().GetHex().c_str(),i,n,DICE_MINUTXOS - entropytxs); + RelayTransaction(tx); + } else break; + } else break; + } else break; + } + } + pubkey2addr(coinaddr,Mypubkey().data()); + dicefinish_utxosget(num,0,0,coinaddr); + fprintf(stderr,"have %d 0.0002 utxos, need %d\n",num,DICE_MINUTXOS); + if ( num < DICE_MINUTXOS ) // this deadlocks, need to put it in a different thread + { + char *cmd = (char *)malloc(100 * 128); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + n = sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; + fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n); + for (i=0; isecond.satoshis/COIN,(double)sum/COIN); + fprintf(stderr,"serialized bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); res = DiceBetFinish(funcid,entropyused,entropyvout,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey,zeroid,-1); if ( result > 0 ) { mySenddicetransaction(res,entropyused,entropyvout,txid,betTx,funcid,0); n++; + if ( n > 10 ) + break; } } } else fprintf(stderr,"bettxid.%s cant find entropyTx.%s\n",txid.GetHex().c_str(),betTx.vin[0].prevout.hash.GetHex().c_str()); } } } - if ( scriptPubKey == fundingPubKey ) + if ( didinit == 0 && KOMODO_DEALERNODE == 0 && scriptPubKey == fundingPubKey ) { - CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs; - DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,fundingtxid,entropytxs,false); - if ( entropytxs < DICE_MINUTXOS ) - { - n = 10;//sqrt(DICE_MINUTXOS - entropytxs) + 10; - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) - { - if ( DecodeHexTx(tx,res) != 0 ) - { - //LOCK(cs_main); - if ( myAddtomempool(tx) != 0 ) - { - fprintf(stderr,"ENTROPY %s: %d of %d, %d\n",tx.GetHash().GetHex().c_str(),i,n,DICE_MINUTXOS - entropytxs); - RelayTransaction(tx); - } else break; - } else break; - } else break; - } - } + strcpy(_planstr,planstr); + dealer0_fundingtxid = fundingtxid; + if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dealer0_loop,_planstr) == 0 ) + didinit = 1; } return(n); } diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 58c1ccaee..114bd65ce 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -133,10 +133,11 @@ uint8_t DecodeOraclesOpRet(const CScript &scriptPubKey,uint256 &oracletxid,CPubK std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); - if ( vopret.size() > 1 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> pk; ss >> num) != 0 ) + if ( vopret.size() > 1 && script[0] == EVAL_ORACLES ) { - if ( e == EVAL_ORACLES && (f == 'R' || f == 'S') ) + if (script[0] == EVAL_ORACLES && (script[1]== 'R' || script[1] == 'S') && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> oracletxid; ss >> pk; ss >> num)!=0) return(f); + else return(script[1]); } return(0); } @@ -567,9 +568,6 @@ bool OraclesDataValidate(struct CCcontract_info *cp,Eval* eval,const CTransactio } } } - else if ( i != 0 ) - return eval->Invalid("vin0 not normal"); - } for (i=0; i origpubkey; CTransaction vintx; int32_t vout,n = 0; - std::vector > unspentOutputs; + char coinaddr[64],funcid; int64_t nValue,price,totalinputs = 0; uint256 tmporacletxid,tmpbatontxid,txid,hashBlock; std::vector origpubkey,data; CTransaction vintx; int32_t numvouts,vout,n = 0; + std::vector > unspentOutputs; CPubKey tmppk; int64_t tmpnum; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); //fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr); @@ -677,19 +675,27 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub txid = it->first.txhash; vout = (int32_t)it->first.index; //char str[65]; fprintf(stderr,"oracle check %s/v%d\n",uint256_str(str,txid),vout); - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && (numvouts=vintx.vout.size()-1)>0) { - // get valid CC payments - if ( (nValue= IsOraclesvout(cp,vintx,vout)) >= 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ((funcid=DecodeOraclesOpRet(vintx.vout[numvouts].scriptPubKey,tmporacletxid,tmppk,tmpnum))!=0 && (funcid=='S' || funcid=='D')) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; - } //else fprintf(stderr,"nValue %.8f or utxo memspent\n",(double)nValue/COIN); + if (funcid=='D' && DecodeOraclesData(vintx.vout[numvouts].scriptPubKey,tmporacletxid,tmpbatontxid,tmppk,data)==0) + fprintf(stderr,"invalid oraclesdata transaction \n"); + else if (tmporacletxid==oracletxid) + { + // get valid CC payments + if ( (nValue= IsOraclesvout(cp,vintx,vout)) >= 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } //else fprintf(stderr,"nValue %.8f or utxo memspent\n",(double)nValue/COIN); + } + } } else fprintf(stderr,"couldnt find transaction\n"); } return(totalinputs); @@ -802,7 +808,7 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da if ( batontxid != zeroid ) // not impossible to fail, but hopefully a very rare event mtx.vin.push_back(CTxIn(batontxid,1,CScript())); else fprintf(stderr,"warning: couldnt find baton utxo %s\n",batonaddr); - if ( (inputs= AddOracleInputs(cp,mtx,mypk,datafee,60)) > 0 ) + if ( (inputs= AddOracleInputs(cp,mtx,oracletxid,mypk,datafee,60)) > 0 ) { if ( inputs > datafee ) CCchange = (inputs - datafee); @@ -898,7 +904,7 @@ UniValue OracleInfo(uint256 origtxid) funding = LifetimeOraclesFunds(cp,oracletxid,pk); sprintf(numstr,"%.8f",(double)funding/COIN); obj.push_back(Pair("lifetime",numstr)); - funding = AddOracleInputs(cp,mtx,pk,0,0); + funding = AddOracleInputs(cp,mtx,oracletxid,pk,0,0); sprintf(numstr,"%.8f",(double)funding/COIN); obj.push_back(Pair("funds",numstr)); sprintf(numstr,"%.8f",(double)datafee/COIN); diff --git a/src/deprecation.cpp b/src/deprecation.cpp index f6fba9f8f..9b34b1d0f 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -20,7 +20,7 @@ void EnforceNodeDeprecation(int nHeight, bool forceLogging, bool fThread) { std::string networkID = Params().NetworkIDString(); std::string msg; - if (networkID != "main" || strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0 ) return; + if (networkID != "main" || ASSETCHAINS_SYMBOL[0] != 0 ) return; int blocksToDeprecation = DEPRECATION_HEIGHT - nHeight; if (blocksToDeprecation <= 0) { @@ -33,7 +33,7 @@ void EnforceNodeDeprecation(int nHeight, bool forceLogging, bool fThread) { if (blocksToDeprecation == 0 || forceLogging) { msg = strprintf(_("This version has been deprecated as of block height %d."), DEPRECATION_HEIGHT) + " " + - _("You should upgrade to the latest version of Verus."); + _("You should upgrade to the latest version of Komodo."); LogPrintf("*** %s\n", msg); CAlert::Notify(msg, fThread); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); @@ -42,7 +42,7 @@ void EnforceNodeDeprecation(int nHeight, bool forceLogging, bool fThread) { } else if (blocksToDeprecation == DEPRECATION_WARN_LIMIT || (blocksToDeprecation < DEPRECATION_WARN_LIMIT && forceLogging)) { msg = strprintf(_("This version will be deprecated at block height %d, and will automatically shut down."), DEPRECATION_HEIGHT) + " " + - _("You should upgrade to the latest version of Verus."); + _("You should upgrade to the latest version of Komodo."); LogPrintf("*** %s\n", msg); CAlert::Notify(msg, fThread); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_WARNING); diff --git a/src/deprecation.h b/src/deprecation.h index 694a11d9d..33782e1eb 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -8,7 +8,7 @@ // Deprecation policy: // * Shut down 16 weeks' worth of blocks after the estimated release block height. // * A warning is shown during the 2 weeks' worth of blocks prior to shut down. -static const int APPROX_RELEASE_HEIGHT = 227000; +static const int APPROX_RELEASE_HEIGHT = 1102000; static const int WEEKS_UNTIL_DEPRECATION = 24; static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 60 * 24); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c69621ac..ba817fc45 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1108,7 +1108,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) if ( ASSETCHAINS_FOUNDERS != 0 ) { nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); - fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); + //fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); n = pblock->vtx[0].vout.size(); for (j=0; j 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here return(-1); else*/ if ( checktoshis != 0 ) @@ -1676,10 +1676,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - int32_t i; - for (i=0; i<25; i++) - fprintf(stderr,"%02x",script[i]); - fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); + //int32_t i; + //for (i=0; i<25; i++) + // fprintf(stderr,"%02x",script[i]); + //fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); return(-1); } @@ -1783,13 +1783,26 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + if ( failed == 0 && ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { if ( height == 1 ) { - script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0]; - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) - return(-1); + if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) + { + int32_t scriptlen; uint8_t scripthex[10000]; + if ( ASSETCHAINS_SCRIPTPUB.size()/2 == pblock->vtx[0].vout[0].scriptPubKey.size() && scriptlen < sizeof(scripthex) ) + { + decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + if ( memcmp(scripthex,script,scriptlen) != 0 ) + return(-1); + } else return(-1); + } + else + { + script = (uint8_t *)&pblock->vtx[0].vout[0].scriptPubKey[0]; + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + } } else { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 31bbb8a54..2fb81e8e9 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = 0,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8a8e4fe58..7bf95d578 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1664,6 +1664,7 @@ void komodo_args(char *argv0) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); + KOMODO_DEALERNODE = GetArg("-dealer",0); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { USE_EXTERNAL_PUBKEY = 1; @@ -1791,10 +1792,18 @@ void komodo_args(char *argv0) decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33); } - if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 ) + if ( ASSETCHAINS_COMMISSION == 0 ) { - ASSETCHAINS_COMMISSION = 53846154; // maps to 35% - printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); + if (ASSETCHAINS_FOUNDERS != 0 ) + { + ASSETCHAINS_COMMISSION = 53846154; // maps to 35% + printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); + } + else + { + ASSETCHAINS_OVERRIDE_PUBKEY.clear(); + printf("-ac_perc must be set with -ac_pubkey\n"); + } } } else @@ -1812,8 +1821,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { - printf("perc.%llu\n",(long long)ASSETCHAINS_COMMISSION); - + fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...]\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2]); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; @@ -1881,9 +1889,8 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; - if ( MAX_MONEY <= 0 || MAX_MONEY > 1000000000LL*SATOSHIDEN ) - MAX_MONEY = 1000000000LL*SATOSHIDEN; - + if ( MAX_MONEY <= 0 || MAX_MONEY > 10000100000LL*SATOSHIDEN ) + MAX_MONEY = 10000100000LL*SATOSHIDEN; //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); @@ -1988,6 +1995,8 @@ void komodo_args(char *argv0) dpowconfs = 0; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); + if ( ASSETCHAINS_SYMBOL[0] == 0 || strcmp(ASSETCHAINS_SYMBOL,"SUPERNET") == 0 || strcmp(ASSETCHAINS_SYMBOL,"DEX") == 0 || strcmp(ASSETCHAINS_SYMBOL,"COQUI") == 0 || strcmp(ASSETCHAINS_SYMBOL,"PIRATE") == 0 || strcmp(ASSETCHAINS_SYMBOL,"KMDICE") == 0 ) + KOMODO_EXTRASATOSHI = 1; } void komodo_nameset(char *symbol,char *dest,char *source) diff --git a/src/main.cpp b/src/main.cpp index b34234063..c29ff8257 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,7 +63,7 @@ using namespace std; CCriticalSection cs_main; extern uint8_t NOTARY_PUBKEY33[33]; -extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CONNECTING; +extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CONNECTING,KOMODO_EXTRASATOSHI; int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); @@ -3424,12 +3424,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); CAmount blockReward = nFees + GetBlockSubsidy(pindex->GetHeight(), chainparams.GetConsensus()) + sum; - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && { uint64_t checktoshis; if ( (checktoshis= komodo_commission((CBlock *)&block,(int32_t)pindex->GetHeight())) != 0 ) { - if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) + if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); } @@ -3439,7 +3439,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): coinbase for block 1 pays wrong amount (actual=%d vs correct=%d)", block.vtx[0].GetValueOut(), blockReward), REJECT_INVALID, "bad-cb-amount"); } - if ( block.vtx[0].GetValueOut() > blockReward+1 ) + if ( block.vtx[0].GetValueOut() > blockReward+KOMODO_EXTRASATOSHI ) { if ( ASSETCHAINS_SYMBOL[0] != 0 || pindex->GetHeight() >= KOMODO_NOTARIES_HEIGHT1 || block.vtx[0].vout[0].nValue > blockReward ) { diff --git a/src/miner.cpp b/src/miner.cpp index 10f95e210..e7f7f3270 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -138,6 +138,7 @@ uint64_t komodo_commission(const CBlock *block,int32_t height); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -541,7 +542,14 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, txNew.vout.resize(2); txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) - txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB); + { + //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); + int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); + len >>= 1; + txNew.vout[1].scriptPubKey.resize(len); + ptr = (uint8_t *)&txNew.vout[1].scriptPubKey[0]; + decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + } else { txNew.vout[1].scriptPubKey.resize(35); @@ -706,10 +714,19 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake) { - CPubKey pubkey; CScript scriptPubKey; uint8_t *ptr; int32_t i; - if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len; + if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 ) { - scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + else + { + len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); + len >>= 1; + scriptPubKey.resize(len); + ptr = (uint8_t *)&scriptPubKey[0]; + decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + } } else if ( USE_EXTERNAL_PUBKEY != 0 ) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 27935047c..afdc8d4ca 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -552,10 +552,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) #endif } - std::string strMode = "template"; UniValue lpval = NullUniValue; // TODO: Re-enable coinbasevalue once a specification has been written bool coinbasetxn = true; + std::string strMode; if (params.size() > 0) { const UniValue& oparam = params[0].get_obj(); @@ -564,12 +564,15 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) strMode = modeval.get_str(); else if (modeval.isNull()) { - /* Do nothing */ + strMode = "template"; } else throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); lpval = find_value(oparam, "longpollid"); + if (strMode == "disablecb") + coinbasetxn = false; + if (strMode == "proposal") { const UniValue& dataval = find_value(oparam, "data"); @@ -614,37 +617,6 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } if (Params().MiningRequiresPeers() && (IsNotInSync() || fvNodesEmpty)) { - /* - int loops = 0, blockDiff = 0, newDiff = 0; - const int delay = 15; - do { - if (fvNodesEmpty) - { - MilliSleep(1000 + rand() % 4000); - LOCK(cs_vNodes); - fvNodesEmpty = vNodes.empty(); - loops = 0; - blockDiff = 0; - } - if ((newDiff = IsNotInSync()) > 1) - { - if (blockDiff != newDiff) - { - blockDiff = newDiff; - } - else - { - if (++loops <= delay) - { - MilliSleep(1000); - } - else break; - } - } - } while (fvNodesEmpty || IsNotInSync()); - if (loops > delay) - throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Cannot get a block template while no peers are connected or chain not in sync!"); - */ throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Cannot get a block template while no peers are connected or chain not in sync!"); } @@ -748,8 +720,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) uint256 txHash = tx.GetHash(); setTxIndex[txHash] = i++; - if (tx.IsCoinBase() && !coinbasetxn) - continue; + //if (tx.IsCoinBase() && !coinbasetxn) + // continue; UniValue entry(UniValue::VOBJ); @@ -769,7 +741,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template])); entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template])); - if (tx.IsCoinBase()) { + if (tx.IsCoinBase() && coinbasetxn == true ) { // Show founders' reward if it is required //if (pblock->vtx[0].vout.size() > 1) { // Correct this if GetBlockTemplate changes the order @@ -805,10 +777,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) if (coinbasetxn) { assert(txCoinbase.isObject()); result.push_back(Pair("coinbasetxn", txCoinbase)); - } else { - result.push_back(Pair("coinbaseaux", aux)); - result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); - } + } // else { + // result.push_back(Pair("coinbaseaux", aux)); + // result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); + //} result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); if ( ASSETCHAINS_STAKED != 0 ) { @@ -832,6 +804,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) return result; } + class submitblock_StateCatcher : public CValidationInterface { public: diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 9e07c0b1b..be8df2b33 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -110,7 +110,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("version", CLIENT_VERSION)); obj.push_back(Pair("protocolversion", PROTOCOL_VERSION)); obj.push_back(Pair("KMDversion", KOMODO_VERSION)); - obj.push_back(Pair("VRSCversion", VERUS_VERSION)); + //obj.push_back(Pair("VRSCversion", VERUS_VERSION)); obj.push_back(Pair("notarized", notarized_height)); obj.push_back(Pair("prevMoMheight", prevMoMheight)); obj.push_back(Pair("notarizedhash", notarized_hash.ToString())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 233553afb..f006bf876 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -53,6 +53,7 @@ const std::string ADDR_TYPE_SAPLING = "sapling"; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); extern uint8_t ASSETCHAINS_PRIVATE; +extern int32_t USE_EXTERNAL_PUBKEY; uint32_t komodo_segid32(char *coinaddr); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int32_t komodo_isnotaryvout(char *coinaddr); // from ac_private chains only @@ -5344,7 +5345,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error( "setpubkey\n" - "\nSets the -pubkey if the daemon was not started with it, if it was already set, it returns the pubkey.\n" + "\nSets the -pubkey if the daemon was not started with it, if it was already set, it returns the pubkey, and its Raddress.\n" "\nArguments:\n" "1. \"pubkey\" (string) pubkey to set.\n" "\nResult:\n" @@ -5389,12 +5390,16 @@ UniValue setpubkey(const UniValue& params, bool fHelp) } NOTARY_PUBKEY = params[0].get_str(); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + USE_EXTERNAL_PUBKEY = 1; } } else { result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string.")); } } else { - result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); + result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon, pubkey in use is below.")); + pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); + std::string address_ret; address_ret.assign(Raddress); + result.push_back(Pair("address",address_ret)); } result.push_back(Pair("pubkey", NOTARY_PUBKEY)); return result; @@ -5756,7 +5761,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) minseconds = maxseconds = 60 * 3600 * 24; mindeposit = 100 * COIN; name = (char *)params[0].get_str().c_str(); - funds = atof(params[1].get_str().c_str()) * COIN; + funds = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; if (!VALID_PLAN_NAME(name)) { ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); @@ -5794,7 +5799,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) return result; } if ( params.size() > 5 ) - mindeposit = atof(params[5].get_str().c_str()) * COIN; + mindeposit = atof(params[5].get_str().c_str()) * COIN + 0.00000000499999; if ( mindeposit <= 0 ) { ERR_RESULT("mindeposit must be positive"); return result; @@ -5822,7 +5827,7 @@ UniValue rewardslock(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN; + amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; hex = RewardsLock(0,name,fundingtxid,amount); if (!VALID_PLAN_NAME(name)) { @@ -5852,7 +5857,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN; + amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; hex = RewardsAddfunding(0,name,fundingtxid,amount); if (!VALID_PLAN_NAME(name)) { @@ -5995,7 +6000,7 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) deposithex = params[5].get_str(); proof = ParseHex(params[6].get_str()); destpub = ParseHex(params[7].get_str()); - amount = atof((char *)params[8].get_str().c_str()) * COIN; + amount = atof((char *)params[8].get_str().c_str()) * COIN + 0.00000000499999; if ( amount <= 0 || claimvout < 0 ) throw runtime_error("invalid param: amount, numpks or claimvout\n"); hex = GatewaysDeposit(0,bindtxid,height,coin,cointxid,claimvout,deposithex,proof,pubkey2pk(destpub),amount); @@ -6020,7 +6025,7 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) coin = params[1].get_str(); deposittxid = Parseuint256((char *)params[2].get_str().c_str()); destpub = ParseHex(params[3].get_str()); - amount = atof((char *)params[4].get_str().c_str()) * COIN; + amount = atof((char *)params[4].get_str().c_str()) * COIN + 0.00000000499999; hex = GatewaysClaim(0,bindtxid,coin,deposittxid,pubkey2pk(destpub),amount); if ( hex.size() > 0 ) { @@ -6040,9 +6045,9 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); - coin = params[1].get_str(); + coin = params[1].get_str(); withdrawpub = ParseHex(params[2].get_str()); - amount = atof((char *)params[3].get_str().c_str()) * COIN; + amount = atof((char *)params[3].get_str().c_str()) * COIN + 0.00000000499999; hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount); if ( hex.size() > 0 ) { @@ -6093,7 +6098,7 @@ UniValue gatewaysmultisig(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); txidaddr = (char *)params[0].get_str().c_str(); return(GatewaysMultisig(txidaddr)); } @@ -6106,7 +6111,7 @@ UniValue gatewayspartialsign(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); parthex = params[2].get_str(); @@ -6150,7 +6155,7 @@ UniValue oraclesregister(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); if ( (datafee= atol((char *)params[1].get_str().c_str())) == 0 ) - datafee = atof((char *)params[1].get_str().c_str()) * COIN; + datafee = atof((char *)params[1].get_str().c_str()) * COIN + 0.00000000499999; hex = OracleRegister(0,txid,datafee); if ( hex.size() > 0 ) { @@ -6171,7 +6176,7 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); pubkey = ParseHex(params[1].get_str().c_str()); - amount = atof((char *)params[2].get_str().c_str()) * COIN; + amount = atof((char *)params[2].get_str().c_str()) * COIN + 0.00000000499999; hex = OracleSubscribe(0,txid,pubkey2pk(pubkey),amount); if ( hex.size() > 0 ) { @@ -6328,7 +6333,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - funds = atof(params[0].get_str().c_str()) * COIN; + funds = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; if (funds > 0) { hex = FaucetFund(0,(uint64_t) funds); if ( hex.size() > 0 ) @@ -6393,7 +6398,7 @@ UniValue pricescreate(const UniValue& params, bool fHelp) longtoken = Parseuint256((char *)params[4].get_str().c_str()); shorttoken = Parseuint256((char *)params[5].get_str().c_str()); maxleverage = atol(params[6].get_str().c_str()); - funding = atof(params[7].get_str().c_str()) * COIN; + funding = atof(params[7].get_str().c_str()) * COIN + 0.00000000499999; n = atoi(params[8].get_str().c_str()); if ( n > 0 ) { @@ -6429,7 +6434,7 @@ UniValue pricesaddfunding(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); bettoken = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN; + amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; hex = PricesAddFunding(0,bettoken,fundingtxid,amount); if ( hex.size() > 0 ) { @@ -6454,7 +6459,7 @@ UniValue pricesbet(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); bettoken = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN; + amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; leverage = atoi(params[3].get_str().c_str()); hex = PricesBet(0,bettoken,fundingtxid,amount,leverage); if ( hex.size() > 0 ) @@ -6517,9 +6522,9 @@ UniValue dicefund(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); - funds = atof(params[1].get_str().c_str()) * COIN; - minbet = atof(params[2].get_str().c_str()) * COIN; - maxbet = atof(params[3].get_str().c_str()) * COIN; + funds = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + minbet = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; + maxbet = atof(params[3].get_str().c_str()) * COIN + 0.00000000499999; maxodds = atol(params[4].get_str().c_str()); timeoutblocks = atol(params[5].get_str().c_str()); @@ -6551,7 +6556,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN; + amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; if (!VALID_PLAN_NAME(name)) { ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); return(result); @@ -6579,7 +6584,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN; + amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; odds = atol(params[3].get_str().c_str()); if (!VALID_PLAN_NAME(name)) { @@ -6768,7 +6773,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); name = params[0].get_str(); - supply = atof(params[1].get_str().c_str()) * COIN; + supply = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; if ( name.size() == 0 || name.size() > 32) { ERR_RESULT("Token name must not be empty and up to 32 characters");