diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 320cd967d..d927119d6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -40,7 +40,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; } @@ -159,7 +174,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 ) @@ -275,9 +290,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/dice.cpp b/src/cc/dice.cpp index 81a141d3b..addef4e06 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1442,7 +1442,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."; @@ -1476,7 +1476,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?"; diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 8fe1fe6d3..70e4e983f 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/komodo_bitcoind.h b/src/komodo_bitcoind.h index 708365fd0..d0d6a7632 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1508,10 +1508,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); } @@ -1606,13 +1606,25 @@ 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.data(); - 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.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); } } else @@ -1623,19 +1635,15 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( ASSETCHAINS_STREAM != 0 && height > 128 ) { int lasttx = ( pblock->vtx.size() -1 ); - printf("ABOUT TO CHECK LAST TX: %d\n",lasttx); if ( lasttx == 0 ) return(-1); uint256 hash; CTransaction tx; if (GetTransaction(pblock->vtx[lasttx].vin[0].prevout.hash,tx,hash,false)) { - printf("CHECKING THE script pubkey\n"); script = (uint8_t *)tx.vout[pblock->vtx[lasttx].vin[0].prevout.n].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) { - printf("THE PUBKEY IS WRONG!\n"); return(-1); } - printf("THE PUBKEY IS RIGHT! \n"); } } } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c9d21030c..a1705c20a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1613,10 +1613,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 @@ -1634,7 +1642,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { - fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); + fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x%02x%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,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; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY),(void *)&ASSETCHAINS_ENDSUBSIDY); @@ -1765,7 +1773,7 @@ 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 ) + 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; } diff --git a/src/main.cpp b/src/main.cpp index 13a07fde6..92c743401 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,12 +3181,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->nHeight, chainparams.GetConsensus()) + sum; - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0) ) + if ( ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_STREAM != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && { uint64_t checktoshis; if ( (checktoshis= komodo_commission((CBlock *)&block,(int32_t)pindex->nHeight)) != 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()); } diff --git a/src/miner.cpp b/src/miner.cpp index 43ebf8607..aad8d0c44 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -122,6 +122,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ 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 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) { @@ -464,7 +465,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.data(); + decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + } else { txNew.vout[1].scriptPubKey.resize(35); @@ -660,10 +668,19 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount) { - CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*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.data(); + decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + } } else if ( ASSETCHAINS_STREAM != 0 ) { diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index d3f0563f8..efd5be36f 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -756,6 +756,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) return result; } + class submitblock_StateCatcher : public CValidationInterface { public: diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 17d28aced..69c310bcf 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -49,6 +49,7 @@ extern std::string ASSETCHAINS_OVERRIDE_PUBKEY; extern int32_t ASSETCHAINS_STREAM; 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 @@ -5088,7 +5089,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" @@ -5144,7 +5145,7 @@ UniValue setpubkey(const UniValue& params, bool fHelp) if ( NOTARY_ADDRESS.empty() ) { pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); NOTARY_ADDRESS.assign(Raddress); - } + } result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); } if ( NOTARY_PUBKEY33[0] != 0 && !NOTARY_ADDRESS.empty() ) { @@ -5511,7 +5512,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)); @@ -5549,7 +5550,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; @@ -5577,7 +5578,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)) { @@ -5607,7 +5608,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)) { @@ -5750,7 +5751,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); @@ -5775,7 +5776,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 ) { @@ -5797,7 +5798,7 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) bindtxid = Parseuint256((char *)params[0].get_str().c_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 ) { @@ -5905,7 +5906,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 ) { @@ -5926,7 +5927,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 ) { @@ -6083,7 +6084,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 ) @@ -6148,7 +6149,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 ) { @@ -6184,7 +6185,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 ) { @@ -6209,7 +6210,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 ) @@ -6272,9 +6273,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()); @@ -6306,7 +6307,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); @@ -6334,7 +6335,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)) { @@ -6523,7 +6524,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");