From cb2ee04b3528e91ac6da2acf4789609a25823088 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 05:46:11 -1100 Subject: [PATCH 01/45] Fix dice finish --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b00044040..62a7d1046 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -970,7 +970,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( CCchange >= fundsneeded || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + if ( CCchange >= fundsneeded+betTx.vout[1].nValue || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From 6e78d3df436e838c13b190a8a116bda379b9d7c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 21:06:49 -1100 Subject: [PATCH 02/45] KOMODO_MININGTHREADS to control staking vs PoW, delay start mining by 15 seconds --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 3 +++ src/miner.cpp | 12 ++++++------ src/rpcmining.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index c4ba26eb6..86c168a85 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 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; +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; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 747a43b72..8269ee206 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1505,6 +1505,9 @@ void komodo_args(char *argv0) extern const char *Notaries_elected1[][2]; std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); + if ( GetBoolArg("-gen", false) != 0 ) + KOMODO_MININGTHREADS = GetArg("-genproclimit",1); + else KOMODO_MININGTHREADS = 0; if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); diff --git a/src/miner.cpp b/src/miner.cpp index fb2eb2d05..874c1b4f8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" -extern int32_t KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; @@ -393,7 +393,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); @@ -453,7 +453,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); - if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || GetArg("-genproclimit", 0) > 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || KOMODO_MININGTHREADS > 0 ) { UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); @@ -788,7 +788,7 @@ void static BitcoinMiner() } if (!fvNodesEmpty )//&& !IsInitialBlockDownload()) break; - MilliSleep(5000); + MilliSleep(15000); //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); } while (true); @@ -950,7 +950,7 @@ void static BitcoinMiner() // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); arith_uint256 hashTarget; - if ( GetArg("-genproclimit", 0) > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) + if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = @@ -978,7 +978,7 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) { - //if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + //if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) // sleep(1); return false; } diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 4c4d2eed5..df58a5573 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -33,6 +33,7 @@ using namespace std; extern uint64_t ASSETCHAINS_STAKED; +extern int32_t KOMODO_MININGTHREADS; arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); /** @@ -327,6 +328,9 @@ UniValue setgenerate(const UniValue& params, bool fHelp) mapArgs["-gen"] = (fGenerate ? "1" : "0"); mapArgs ["-genproclimit"] = itostr(nGenProcLimit); + if ( fGenerate == 0 ) + KOMODO_MININGTHREADS = -1; + else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; #ifdef ENABLE_WALLET GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit); #else @@ -382,6 +386,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) obj.push_back(Pair("chain", Params().NetworkIDString())); #ifdef ENABLE_MINING obj.push_back(Pair("generate", getgenerate(params, false))); + obj.push_back(Pair("numthreads", (int64_t)KOMODO_MININGTHREADS)); #endif return obj; } @@ -647,7 +652,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) pblocktemplate = CreateNewBlockWithKey(); #endif if (!pblocktemplate) - throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); + throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking"); // Need to update only after we know CreateNewBlockWithKey succeeded pindexPrev = pindexPrevNew; From 9b940331f9f20cefe1f635bc21c493be9e96aa1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 21:31:14 -1100 Subject: [PATCH 03/45] Add segid to get block --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b76698917..c9e94438c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -121,6 +121,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits))); result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); + result.push_back(Pair("segid", (int64_t)blockindex->segid)); if (blockindex->pprev) result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); From a4885032666a7512fa0c2f7145bff0ff18cf3dbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 21:37:46 -1100 Subject: [PATCH 04/45] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c9e94438c..d870ad75e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -147,6 +147,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); + result.push_back(Pair("segid", (int64_t)blockindex->segid)); UniValue deltas(UniValue::VARR); @@ -263,6 +264,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); + result.push_back(Pair("segid", (int64_t)blockindex->segid)); UniValue txs(UniValue::VARR); BOOST_FOREACH(const CTransaction&tx, block.vtx) { From 99c3975dcb84493caddc11ffd0ef667595da850b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 23:00:06 -1100 Subject: [PATCH 05/45] Set default KOMODO_MININGTHREADS <= -1 --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8269ee206..616f7ecaa 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1507,7 +1507,7 @@ void komodo_args(char *argv0) IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( GetBoolArg("-gen", false) != 0 ) KOMODO_MININGTHREADS = GetArg("-genproclimit",1); - else KOMODO_MININGTHREADS = 0; + else KOMODO_MININGTHREADS = -1; if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); From 0e03d55920f323544b9f69b2852f05e245f98090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 02:18:44 -1100 Subject: [PATCH 06/45] Fix dice finish --- src/cc/dice.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 62a7d1046..7521df794 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -970,19 +970,21 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( CCchange >= fundsneeded+betTx.vout[1].nValue || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) + CCchange -= (fundsneeded + betTx.vout[1].nValue); + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); - mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); - mtx.vout.push_back(CTxOut((odds+1) * betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); } else { fprintf(stderr,"not enough inputs for %.8f\n",(double)fundsneeded/COIN); return(""); } + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); + mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); + mtx.vout.push_back(CTxOut((odds+1) * betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); } else { From db871af56fd0de9d2eac2c67df414914db69ffcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 03:44:36 -1100 Subject: [PATCH 07/45] Fix dice finish --- src/cc/dice.cpp | 2 +- src/komodo_bitcoind.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7521df794..669cb9007 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -968,7 +968,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); return(""); } - CCchange = betTx.vout[0].nValue; + CCchange = betTx.vout[0].nValue + betTx.vout[1]; fundsneeded = txfee + odds*betTx.vout[1].nValue; if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) CCchange -= (fundsneeded + betTx.vout[1].nValue); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bd5505c1c..13501d2a9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1327,14 +1327,16 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ave = (sum / arith_uint256(m)); if ( ave > target ) ave = target; - } else ave = easydiff; //else return(target); + } else ave = target; //easydiff; //else return(target); if ( percPoS == 0 ) percPoS = 1; if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { + //if ( oldflag != 0 ) + // bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); if ( oldflag != 0 ) - bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); - else bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); + bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); + else bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); if ( ASSETCHAINS_STAKED < 100 ) { for (i=31; i>=24; i--) @@ -1355,7 +1357,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); //bnTarget = (bnTarget * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); bnTarget = (bnTarget / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS); - } else bnTarget = (ave / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS); + } + else bnTarget = (ave / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS); if ( bnTarget > easydiff ) bnTarget = easydiff; else if ( bnTarget < ave ) // overflow From 2b4374d705f57e16a24234895fe99b7faead4ee2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 03:45:58 -1100 Subject: [PATCH 08/45] nValue --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 669cb9007..1f2c770d7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -968,7 +968,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); return(""); } - CCchange = betTx.vout[0].nValue + betTx.vout[1]; + CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) CCchange -= (fundsneeded + betTx.vout[1].nValue); From 1da742e71ecc8fa80334122faf76ae323e69231f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 04:48:07 -1100 Subject: [PATCH 09/45] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1f2c770d7..ef1b27bf3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -969,9 +969,9 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 return(""); } CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; - fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) - CCchange -= (fundsneeded + betTx.vout[1].nValue); + fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; + if ( CCchange >= fundsneeded ) + CCchange -= fundsneeded; else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) From 6ca2e998838df140e1168cdb1913ff6b8fe7ccf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:18:13 -1100 Subject: [PATCH 10/45] Backwards compatibility breaking changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assets: change tokeninfo to return "supply" in satoshis Max description length to 4096 Rewards: Fix rewardsunlock without giving it a locked txid always gives error Fix (nonconsensus) allow anybody to unlock only AFTER maxtime Fix rewards unlock to use mempool fix could you add a locked_funds value to rewardsinfo? Fix i deposited 100000 at 20% apr for one day i only got back 100000.01140669 seems like too little for 20% APR Faucet: Fix txid with 0x00 at beginning and end required for faucetget txid (65536 average iterations needed) Change reduce faucet get to 0.1 coins Can’t reproduce: it seems that if you re-run faucetget twice in the same block is when it pegs the cpu to max Dice: fix Dice status always returning loss Wont fix Profit margin for dice plan sounds good. -> use -ac_commission --- src/cc/CCassetstx.cpp | 3 +- src/cc/CCfaucet.h | 1 + src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 12 +++--- src/cc/faucet.cpp | 38 ++++++++++++++---- src/cc/rewards.cpp | 87 +++++++++++++++++++++++++++++++--------- src/rpcblockchain.cpp | 2 +- src/wallet/rpcwallet.cpp | 9 ++++- 8 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index bfd51f4b7..5869aa133 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -74,8 +74,7 @@ UniValue AssetInfo(uint256 assetid) result.push_back(Pair("tokenid",uint256_str(str,assetid))); result.push_back(Pair("owner",pubkey33_str(str,origpubkey.data()))); result.push_back(Pair("name",name)); - sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); - result.push_back(Pair("supply",numstr)); + result.push_back(Pair("supply",vintx.vout[0].nValue)); result.push_back(Pair("description",description)); return(result); } diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index f9b933255..39930cb20 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -20,6 +20,7 @@ #include "CCinclude.h" #define EVAL_FAUCET 0xe4 +#define FAUCETSIZE (COIN / 10) bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 6a1a25b35..5116c1da6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -64,6 +64,7 @@ bool myAddtomempool(CTransaction &tx); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); bool mySendrawtransaction(std::string res); +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef1b27bf3..4f162eafc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1059,9 +1059,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - if ( spenttx.vout[2].scriptPubKey == fundingPubKey ) + if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); @@ -1075,15 +1075,17 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) { - if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) + if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) + //if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); } fprintf(stderr,"didnt find dicefinish tx\n"); - } else return(-1.); + } + return(-1.); } return(0.); } diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 1adec8af8..796dfb50c 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -69,17 +69,17 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction if ( (assetoshis= IsFaucetvout(cp,tx,i)) != 0 ) outputs += assetoshis; } - if ( inputs != outputs+COIN+txfee ) + if ( inputs != outputs+FAUCETSIZE+txfee ) { fprintf(stderr,"inputs %llu vs outputs %llu\n",(long long)inputs,(long long)outputs); - return eval->Invalid("mismatched inputs != outputs + COIN + txfee"); + return eval->Invalid("mismatched inputs != outputs + FAUCETSIZE + txfee"); } else return(true); } bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -87,7 +87,6 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx return eval->Invalid("no vouts"); else { - //fprintf(stderr,"check vins\n"); for (i=0; iInvalid("invalid faucet output"); + else if ( hash[0] != 0 || hash[31] != 0 ) + return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"faucetget validated\n"); @@ -154,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,len; uint8_t hash[32],buf[32768]; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -167,7 +171,27 @@ std::string FaucetGet(uint64_t txfee) if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); + for (i=0; i<1000000; i++) + { + tmpmtx = mtx; + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,opret); // signature changes each time + if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) + { + len >>= 1; + decode_hex(buf,len,(char *)rawhex.c_str()); + vcalc_sha256(0,hash,buf,len); + fprintf(stderr,"%02x%02x ",hash[0],hash[31]); + if ( hash[0] == 0 && hash[31] == 0 ) + { + fprintf(stderr,"found valid txid after %d iterations\n",i); + return(rawhex); + } + } + rawhex.delete(); + tmpmtx.delete(); + } + fprintf(stderr,"couldnt generate valid txid\n"); + return(""); } else fprintf(stderr,"cant find faucet inputs\n"); return(""); } diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 9314f7c94..52bc82a7d 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -77,8 +77,10 @@ int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds //duration = (uint32_t)time(NULL) - (1532713903 - 3600 * 24); } else if ( duration > maxseconds ) duration = maxseconds; - reward = (((amount * APR) / COIN) * duration) / (365*24*3600LL * 100); - fprintf(stderr,"amount %.8f %.8f %llu -> duration.%llu reward %.8f\n",(double)amount/COIN,((double)amount * APR)/COIN,(long long)((amount * APR) / (COIN * 365*24*3600)),(long long)duration,(double)reward/COIN); + if ( 0 ) // amount * APR * duration / COIN * 100 * 365*24*3600 + reward = (((amount * APR) / COIN) * duration) / (365*24*3600LL * 100); + else reward = (((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000)) / 10000; + fprintf(stderr,"amount %.8f %.8f %llu -> duration.%llu reward %.8f vals %.8f %.8f\n",(double)amount/COIN,((double)amount * APR)/COIN,(long long)((amount * APR) / (COIN * 365*24*3600)),(long long)duration,(double)reward/COIN,(double)((amount * duration) / (365 * 24 * 3600LL))/COIN,(double)(((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000))/COIN); return(reward); } @@ -270,10 +272,38 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return(true); } -// 'L' vs 'F' and 'A' -int64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t refsbits,uint256 reffundingtxid,uint64_t needed) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; + uint8_t funcid; uint64_t sbits,nValue; uint256 fundingtxid; char str[65]; + memset(&txid,0,sizeof(txid)); + vout = -1; + nValue = 0; + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + if ( tx.vout.size() > 0 && tx.vout[0].nValue >= needed ) + { + const uint256 &hash = tx.GetHash(); + if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(hash,0) == 0 ) + { + if ( (funcid= DecodeRewardsOpRet(hash,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'U' && sbits == refsbits && fundingtxid == reffundingtxid ) + { + txid = hash; + vout = 0; + nValue = tx.vout[0].nValue; + fprintf(stderr,"found 'U' %s %.8f in unspent in mempool\n",uint256_str(str,txid),(double)nValue/COIN); + return(nValue); + } + } + } + } + return(nValue); +} + +// 'L' vs 'F' and 'A' +int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +{ + char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -296,13 +326,16 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontra if ( sbits != refsbits || fundingtxid != reffundingtxid ) continue; fprintf(stderr,"fundsflag.%d (%c) %.8f %.8f\n",fundsflag,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); - if ( fundsflag != 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) - continue; - else if ( fundsflag == 0 && (funcid != 'L' || tx.vout.size() < 4) ) + if ( maxseconds == 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; + else if ( maxseconds != 0 && funcid != 'L' ) + { + if ( CCduration(numblocks,txid)) < maxseconds ) + continue; + } if ( total != 0 && maxinputs != 0 ) { - if ( fundsflag == 0 ) + if ( maxseconds != 0 ) scriptPubKey = tx.vout[1].scriptPubKey; mtx.vin.push_back(CTxIn(txid,vout,CScript())); } @@ -313,13 +346,25 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontra } else fprintf(stderr,"null funcid\n"); } } + if ( maxseconds == 0 && totalinputs < total && (maxinputs == 0 || n < maxinputs-1) ) + { + fprintf(stderr,"search mempool for unlocked and unspent CC rewards output for %.8f\n",(double)(total-totalinputs)/COIN); + if ( (nValue= myIs_unlockedtx_inmempool(txid,vout,refsbits,reffundingtxid,total-totalinputs)) > 0 ) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + fprintf(stderr,"added mempool vout for %.8f\n",(double)nValue/COIN); + totalinputs += nValue; + n++; + } + } return(totalinputs); } -int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; + lockedfunds = 0; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -328,12 +373,16 @@ int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk vout = (int32_t)it->first.index; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'A' || funcid == 'U' ) + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'A' || funcid == 'U' || funcid == 'L' ) { if ( refsbits == sbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( (nValue= IsRewardsvout(cp,tx,vout,sbits,fundingtxid)) > 0 ) - totalinputs += nValue; + { + if ( funcid == 'L' ) + lockedfunds += nValue; + else totalinputs += nValue; + } else fprintf(stderr,"refsbits.%llx sbits.%llx nValue %.8f\n",(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case\n"); } else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); @@ -367,7 +416,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa UniValue RewardsInfo(uint256 rewardsid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -395,9 +444,11 @@ UniValue RewardsInfo(uint256 rewardsid) result.push_back(Pair("mindeposit",numstr)); cp = CCinit(&C,EVAL_REWARDS); rewardspk = GetUnspendable(cp,0); - funding = RewardsPlanFunds(sbits,cp,rewardspk,rewardsid); + funding = RewardsPlanFunds(lockedfunds,sbits,cp,rewardspk,rewardsid); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); + sprintf(numstr,"%.8f",(double)lockedfunds/COIN); + result.push_back(Pair("locked",numstr)); return(result); } @@ -485,7 +536,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { - CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; if ( deposit < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -507,7 +558,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t fprintf(stderr,"Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); return(""); } - if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval + if ( (funding= RewardsPlanFunds(lockedfunds,sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval { if ( AddNormalinputs(mtx,mypk,deposit+2*txfee,64) > 0 ) { @@ -536,7 +587,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); if ( locktxid == zeroid ) - amount = AddRewardsInputs(scriptPubKey,0,cp,mtx,rewardspk,(1LL << 30),1,sbits,fundingtxid); + amount = AddRewardsInputs(scriptPubKey,maxseconds,cp,mtx,rewardspk,(1LL << 30),1,sbits,fundingtxid); else { GetCCaddress(cp,coinaddr,rewardspk); @@ -558,7 +609,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) { - if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) + if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) { if ( inputs >= (reward + 2*txfee) ) CCchange = (inputs - (reward + txfee)); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d870ad75e..7f01c862f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -352,7 +352,7 @@ UniValue getdifficulty(const UniValue& params, bool fHelp) bool myIsutxo_spentinmempool(uint256 txid,int32_t vout) { //char *uint256_str(char *str,uint256); char str[65]; - LOCK(mempool.cs); + //LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { const CTransaction &tx = e.GetTx(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6329d4a52..5c16c3b9c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5319,7 +5319,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) result.push_back(Pair("status", "loss")); else result.push_back(Pair("status", "no pending bets")); } - } else result.push_back(Pair("status", "invalid bet txid")); + } else result.push_back(Pair("status", "bet still pending")); return(result); } @@ -5412,7 +5412,14 @@ UniValue tokencreate(const UniValue& params, bool fHelp) name = params[0].get_str(); supply = atof(params[1].get_str().c_str()) * COIN; if ( params.size() == 3 ) + { description = params[2].get_str(); + if ( description.size() > 4096 ) + { + result.push_back(Pair("error", "token description longer than 4096")); + return(result); + } + } hex = CreateAsset(0,supply,name,description); if ( hex.size() > 0 ) { From 76fb8636ec9c48b9d0c830fc7f66ca5871aa8d09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:22:18 -1100 Subject: [PATCH 11/45] Syntax --- src/cc/faucet.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 796dfb50c..e31ebbb25 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -187,8 +187,6 @@ std::string FaucetGet(uint64_t txfee) return(rawhex); } } - rawhex.delete(); - tmpmtx.delete(); } fprintf(stderr,"couldnt generate valid txid\n"); return(""); From 6986a67b5c41c7c7c2dfc9039de263c412fb70e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:23:23 -1100 Subject: [PATCH 12/45] Syntax --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 52bc82a7d..3c6b72ff2 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -325,12 +325,12 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont { if ( sbits != refsbits || fundingtxid != reffundingtxid ) continue; - fprintf(stderr,"fundsflag.%d (%c) %.8f %.8f\n",fundsflag,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); + fprintf(stderr,"maxseconds.%d (%c) %.8f %.8f\n",(int32_t)maxseconds,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( maxseconds == 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; else if ( maxseconds != 0 && funcid != 'L' ) { - if ( CCduration(numblocks,txid)) < maxseconds ) + if ( CCduration(numblocks,txid) < maxseconds ) continue; } if ( total != 0 && maxinputs != 0 ) From 97e4544b10ca70dee4b18bd148b0ace03ee92369 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:33:12 -1100 Subject: [PATCH 13/45] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4f162eafc..bae8ad653 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1061,6 +1061,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { + char str[65]; + fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); From f4fc4a80f9a73e661e53e3e2aaca46cc066405d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:50:04 -1100 Subject: [PATCH 14/45] Add nonceto faucet get --- src/cc/faucet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index e31ebbb25..42e767442 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -174,6 +174,7 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; + opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,opret); // signature changes each time if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { From a6c2a2fe36a667850987b307889eba9e63279b71 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:51:13 -1100 Subject: [PATCH 15/45] Test --- src/cc/faucet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 42e767442..9956733bd 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -171,7 +171,7 @@ std::string FaucetGet(uint64_t txfee) if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - for (i=0; i<1000000; i++) + for (i=0; i<1000; i++) { tmpmtx = mtx; opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); @@ -181,7 +181,9 @@ std::string FaucetGet(uint64_t txfee) len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); vcalc_sha256(0,hash,buf,len); - fprintf(stderr,"%02x%02x ",hash[0],hash[31]); + for (j=0; j<32; j++) + fprintf(stderr,"%02x",hash[i]); + fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { fprintf(stderr,"found valid txid after %d iterations\n",i); From 300b9ceeb8e2ebaa01303b5e2a8f25dfd1c06a83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:52:08 -1100 Subject: [PATCH 16/45] Test --- src/cc/faucet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 9956733bd..217d9145f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -171,6 +171,7 @@ std::string FaucetGet(uint64_t txfee) if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); for (i=0; i<1000; i++) { tmpmtx = mtx; @@ -186,12 +187,12 @@ std::string FaucetGet(uint64_t txfee) fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { - fprintf(stderr,"found valid txid after %d iterations\n",i); + fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } } } - fprintf(stderr,"couldnt generate valid txid\n"); + fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); } else fprintf(stderr,"cant find faucet inputs\n"); return(""); From b940bb4abdae315b8d74553ac605da4f026ee7b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:53:17 -1100 Subject: [PATCH 17/45] Fix --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 217d9145f..f27a90347 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,len; uint8_t hash[32],buf[32768]; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t hash[32],buf[32768]; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; From ca9af9a1f68028dcb6062f4600334ba2ca9acbbb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:54:42 -1100 Subject: [PATCH 18/45] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index f27a90347..9f5d620b7 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -183,7 +183,7 @@ std::string FaucetGet(uint64_t txfee) decode_hex(buf,len,(char *)rawhex.c_str()); vcalc_sha256(0,hash,buf,len); for (j=0; j<32; j++) - fprintf(stderr,"%02x",hash[i]); + fprintf(stderr,"%02x",hash[j]); fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { From 2accae9efdc8f6f5331941ed5032f8874597d5c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:56:14 -1100 Subject: [PATCH 19/45] Test --- src/cc/faucet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 9f5d620b7..31e4bce21 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -172,7 +172,7 @@ std::string FaucetGet(uint64_t txfee) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - for (i=0; i<1000; i++) + for (i=0; i<1000000; i++) { tmpmtx = mtx; opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); @@ -182,9 +182,9 @@ std::string FaucetGet(uint64_t txfee) len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); vcalc_sha256(0,hash,buf,len); - for (j=0; j<32; j++) - fprintf(stderr,"%02x",hash[j]); - fprintf(stderr," "); + //for (j=0; j<32; j++) + // fprintf(stderr,"%02x",hash[j]); + //fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); From 6155bc4b68d400d9309b3e343c20bbd41e17fed6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:00:43 -1100 Subject: [PATCH 20/45] tst --- src/cc/faucet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 31e4bce21..5acbb46b9 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -191,6 +191,8 @@ std::string FaucetGet(uint64_t txfee) return(rawhex); } } + if ( (i % 10000) == 9999 ) + fprintf(stderr,"."); } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); From fd39f0953539e7e99616bd2222513a6053ac5c96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:04:07 -1100 Subject: [PATCH 21/45] 0 mod 4096 for faucet get --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 5acbb46b9..fa21dc985 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( hash[0] != 0 || hash[31] != 0 ) + else if ( (hash[0] & 0x3f) != 0 || (hash[31] & 0x3f) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,7 +185,7 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( hash[0] == 0 && hash[31] == 0 ) + if ( (hash[0] & 0x3f) == 0 && (hash[31] & 0x3f) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); From 43e77d75f7d2383569a0ed33681ffdb9b9689a36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:06:19 -1100 Subject: [PATCH 22/45] Test --- src/cc/faucet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index fa21dc985..c0aae09dc 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -190,8 +190,9 @@ std::string FaucetGet(uint64_t txfee) fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } + fprintf(stderr,"%x%x ",(hash[0] & 0x3f) >> 6,(hash[31] & 0x3f) >> 6); } - if ( (i % 10000) == 9999 ) + if ( (i % 1000) == 999 ) fprintf(stderr,"."); } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); From 6f054a7708c36d4f0c9fb1e1fa6f7e2e4529386b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:11:06 -1100 Subject: [PATCH 23/45] Test --- src/cc/faucet.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index c0aae09dc..dedbbcf3f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t hash[32],buf[32768]; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -181,19 +181,17 @@ std::string FaucetGet(uint64_t txfee) { len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); - vcalc_sha256(0,hash,buf,len); + hash = bits256_doublesha256(0,buf,len); //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash[0] & 0x3f) == 0 && (hash[31] & 0x3f) == 0 ) + if ( (hash.bytes[0] & 0x3f) == 0 && (hash.bytes[31] & 0x3f) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } - fprintf(stderr,"%x%x ",(hash[0] & 0x3f) >> 6,(hash[31] & 0x3f) >> 6); + fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); } - if ( (i % 1000) == 999 ) - fprintf(stderr,"."); } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); From 135d90357fc66ddb532af65f2592624d520951e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:15:12 -1100 Subject: [PATCH 24/45] Test --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 5116c1da6..3954068e1 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -101,5 +101,6 @@ bits256 curve25519_shared(bits256 privkey,bits256 otherpub); bits256 curve25519_basepoint9(); bits256 curve25519(bits256 mysecret,bits256 basepoint); void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); +bits256 bits256_doublesha256(char *deprecated,uint8_t *data,int32_t datalen); #endif From 09bff6c967f14bb7a7ae61607d4566f5d48f23bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:18:39 -1100 Subject: [PATCH 25/45] Test --- src/cc/faucet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index dedbbcf3f..dd3b75399 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -175,8 +175,8 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; - opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,opret); // signature changes each time + //opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; From 0ac322177136f9065d2dd6d3a8b08c711a190b41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:19:17 -1100 Subject: [PATCH 26/45] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index dd3b75399..b3c115cee 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -176,7 +176,7 @@ std::string FaucetGet(uint64_t txfee) { tmpmtx = mtx; //opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; From e9a15289d7072fb68c7615d02dbb6722daefe4e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:22:22 -1100 Subject: [PATCH 27/45] Test --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index b3c115cee..a3a3b350f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( (hash[0] & 0x3f) != 0 || (hash[31] & 0x3f) != 0 ) + else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,7 +185,7 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash.bytes[0] & 0x3f) == 0 && (hash.bytes[31] & 0x3f) == 0 ) + if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); From a997e9ed74e8fb476ec6d9c8f02618d2e40df2b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:24:39 -1100 Subject: [PATCH 28/45] Test --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index a3a3b350f..90c3a7c1c 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) + else if ( (hash[0] & 0x7f) != 0 || (hash[31] & 0x7f) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,7 +185,7 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) + if ( (hash.bytes[0] & 0x7f) == 0 && (hash.bytes[31] & 0x7f) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); From 9193afd9269b65664fde52cbe660636c4ea2a086 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:25:23 -1100 Subject: [PATCH 29/45] Test --- src/cc/faucet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 90c3a7c1c..af5e458ef 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( (hash[0] & 0x7f) != 0 || (hash[31] & 0x7f) != 0 ) + else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,12 +185,12 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash.bytes[0] & 0x7f) == 0 && (hash.bytes[31] & 0x7f) == 0 ) + if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } - fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); } } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); From d614c74afb7ff1dcfd8d78ea6749ba294ffc11dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:28:08 -1100 Subject: [PATCH 30/45] Test --- src/cc/faucet.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index af5e458ef..caeb95765 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -175,16 +175,12 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; - //opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << i)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); hash = bits256_doublesha256(0,buf,len); - //for (j=0; j<32; j++) - // fprintf(stderr,"%02x",hash[j]); - //fprintf(stderr," "); if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); From 815e9937bbbf280a49af3061d61d8b49c680a7df Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:39:51 -1100 Subject: [PATCH 31/45] Test --- src/cc/dice.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bae8ad653..912b1de7b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1057,16 +1057,19 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else { + char str[65]; if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) + fprintf(stderr,"bettx is spent\n"); + if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - char str[65]; fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); - } else return(0.); + } + fprintf(stderr,"couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid)); + return(0.); } else if ( scriptPubKey == fundingPubKey ) res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,1); From e65c27b52e3476bfcc7cdedf50398fa915f296ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:47:10 -1100 Subject: [PATCH 32/45] -print --- src/cc/dice.cpp | 4 ++-- src/cc/rewards.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 912b1de7b..a697d238e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1060,10 +1060,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx char str[65]; if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - fprintf(stderr,"bettx is spent\n"); + //fprintf(stderr,"bettx is spent\n"); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); + //fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 3c6b72ff2..f625c04e7 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -313,7 +313,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont vout = (int32_t)it->first.index; if ( it->second.satoshis < 1000000 ) continue; - fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); + //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; jsecond.satoshis/COIN); if ( maxseconds == 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; else if ( maxseconds != 0 && funcid != 'L' ) @@ -333,6 +332,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont if ( CCduration(numblocks,txid) < maxseconds ) continue; } + fprintf(stderr,"maxseconds.%d (%c) %.8f %.8f\n",(int32_t)maxseconds,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( total != 0 && maxinputs != 0 ) { if ( maxseconds != 0 ) From fefaa934a9777c27f330dc9afc6b83f573684621 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:51:22 -1100 Subject: [PATCH 33/45] Cap reward to a doubling --- src/cc/rewards.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index f625c04e7..d3df9233b 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -80,6 +80,8 @@ int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds if ( 0 ) // amount * APR * duration / COIN * 100 * 365*24*3600 reward = (((amount * APR) / COIN) * duration) / (365*24*3600LL * 100); else reward = (((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000)) / 10000; + if ( reward > amount ) + reward = amount; fprintf(stderr,"amount %.8f %.8f %llu -> duration.%llu reward %.8f vals %.8f %.8f\n",(double)amount/COIN,((double)amount * APR)/COIN,(long long)((amount * APR) / (COIN * 365*24*3600)),(long long)duration,(double)reward/COIN,(double)((amount * duration) / (365 * 24 * 3600LL))/COIN,(double)(((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000))/COIN); return(reward); } From 87c119b71c63ab787617e162f935452e4ad20329 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 02:29:44 -1100 Subject: [PATCH 34/45] Add pub key to faucet get I-return --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index caeb95765..e357310ff 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -175,7 +175,7 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << i)); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << mypk << i)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; From af3024a34478e53ae103fd18302af00504408ecb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 02:44:59 -1100 Subject: [PATCH 35/45] Faucet get only for first txid --- src/cc/faucet.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index e357310ff..9c0fc0cb0 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,8 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -116,6 +117,10 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx return eval->Invalid("invalid faucet output"); else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) return eval->Invalid("invalid faucetget txid"); + Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); + SetCCtxids(txids,destaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + return eval->Invalid("faucet is only for unused addresses"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"faucetget validated\n"); From 4b3021d80bb0b124f079545f3218f90f1346dabc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 05:07:28 -1100 Subject: [PATCH 36/45] Fix mempool zombie --- src/cc/faucet.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 9c0fc0cb0..827dc2716 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,j=0; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -120,7 +120,10 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); SetCCtxids(txids,destaddr); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) - return eval->Invalid("faucet is only for unused addresses"); + { + if ( ++j > 1 ) + return eval->Invalid("faucet is only for unused addresses"); + } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"faucetget validated\n"); From f344c6933832aa2be566282366af774076ac7e86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 05:18:01 -1100 Subject: [PATCH 37/45] +prints --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d3df9233b..7bbcb3065 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -567,9 +567,9 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t mtx.vout.push_back(MakeCC1vout(cp->evalcode,deposit,rewardspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid))); - } else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)deposit/COIN); + } else fprintf(stderr,"cant find enough inputs %.8f not enough for %.8f, make sure you imported privkey for the -pubkey address\n",(double)funding/COIN,(double)deposit/COIN); } - fprintf(stderr,"cant find rewards inputs\n"); + fprintf(stderr,"cant find rewards inputs funding %.8f locked %.8f vs deposit %.8f\n",(double)funding/COIN,(double)lockedfunds/COIN,(double)deposit/COIN); return(""); } From 8d13c0ef190900c64c55bd1eaedfff478d4df8d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 07:41:28 -1100 Subject: [PATCH 38/45] Consensus stable faucet get constraint --- src/cc/faucet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 827dc2716..142100c70 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,j=0; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -121,8 +121,8 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx SetCCtxids(txids,destaddr); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - if ( ++j > 1 ) - return eval->Invalid("faucet is only for unused addresses"); + if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) + return eval->Invalid("faucet is only for brand new addresses"); } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) From 5159767093007890c1c5cd0c911193356a760e37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 08:09:21 -1100 Subject: [PATCH 39/45] +print --- src/cc/faucet.cpp | 6 +++++- src/cc/rewards.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 142100c70..a467ed311 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -121,8 +121,12 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx SetCCtxids(txids,destaddr); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { + //int height = it->first.blockHeight; if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) - return eval->Invalid("faucet is only for brand new addresses"); + { + fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); + //return eval->Invalid("faucet is only for brand new addresses"); + } } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 7bbcb3065..c98b42a17 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -69,7 +69,7 @@ int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) { int32_t numblocks; uint64_t duration,reward = 0; - fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); + //fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); if ( (duration= CCduration(numblocks,txid)) < minseconds ) { fprintf(stderr,"duration %llu < minseconds %llu\n",(long long)duration,(long long)minseconds); From c4a13b6f0d357265bafefd3257c63b1106835586 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 08:10:29 -1100 Subject: [PATCH 40/45] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index a467ed311..ba87e06b3 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -125,7 +125,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) { fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); - //return eval->Invalid("faucet is only for brand new addresses"); + return eval->Invalid("faucet is only for brand new addresses"); } } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); From 59e96a42569edfa7f283590e96e678cd28b3f3e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 08:19:58 -1100 Subject: [PATCH 41/45] -print --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index ba87e06b3..0ab51ff13 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -124,7 +124,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //int height = it->first.blockHeight; if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) { - fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); + //fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); return eval->Invalid("faucet is only for brand new addresses"); } } From 764eb2e5be573ffea8a82cb0dfe46d69fc66c422 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 22:10:55 -1100 Subject: [PATCH 42/45] +dice attack vector --- src/cc/dice.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a697d238e..c2f055d8d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -79,6 +79,12 @@ winner: timeout: same as winner, just without hentropy or proof +WARNING: there is an attack vector that precludes betting any large amounts, it goes as follows: + 1. do dicebet to get the house entropy revealed + 2. calculate bettor entropy that would win against the house entropy + 3. reorg the chain and make a big bet using the winning entropy calculated in 2. + + In order to mitigate this, the disclosure of the house entropy needs to be delayed beyond a reasonable reorg depth (notarization). It is recommended for production dice game with significant amounts of money to use such a delayed disclosure method. */ #include "../compat/endian.h" From 291a646a84610ba081019877c81a32f6c97256d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 23:47:37 -1100 Subject: [PATCH 43/45] Fix bid fill --- src/cc/CCassetsCore.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index da505db9c..9ef08348e 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -58,16 +58,20 @@ bool ValidateBidRemainder(int64_t remaining_units,int64_t remaining_nValue,int64 } else { - unitprice = (orig_nValue * COIN) / totalunits; - recvunitprice = (received_nValue * COIN) / paidunits; + //unitprice = (orig_nValue * COIN) / totalunits; + //recvunitprice = (received_nValue * COIN) / paidunits; + //if ( remaining_units != 0 ) + // newunitprice = (remaining_nValue * COIN) / remaining_units; + unitprice = (orig_nValue / totalunits); + recvunitprice = (received_nValue / paidunits); if ( remaining_units != 0 ) - newunitprice = (remaining_nValue * COIN) / remaining_units; + newunitprice = (remaining_nValue / remaining_units); if ( recvunitprice < unitprice ) { - fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN),(double)unitprice/(COIN),(double)newunitprice/(COIN)); return(false); } - fprintf(stderr,"orig %llu total %llu, recv %llu paid %llu,recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(long long)orig_nValue,(long long)totalunits,(long long)received_nValue,(long long)paidunits,(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + fprintf(stderr,"orig %llu total %llu, recv %llu paid %llu,recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(long long)orig_nValue,(long long)totalunits,(long long)received_nValue,(long long)paidunits,(double)recvunitprice/(COIN),(double)unitprice/(COIN),(double)newunitprice/(COIN)); } return(true); } @@ -89,8 +93,10 @@ bool SetBidFillamounts(int64_t &received_nValue,int64_t &remaining_units,int64_t return(true); } remaining_units = (totalunits - paidunits); - unitprice = (orig_nValue * COIN) / totalunits; - received_nValue = (paidunits * unitprice) / COIN; + //unitprice = (orig_nValue * COIN) / totalunits; + //received_nValue = (paidunits * unitprice) / COIN; + unitprice = (orig_nValue / totalunits); + received_nValue = (paidunits * unitprice); if ( unitprice > 0 && received_nValue > 0 && received_nValue <= orig_nValue ) { remaining_nValue = (orig_nValue - received_nValue); From f6160f58c13f4979c25e7b70f7a7d2ad310efd98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Aug 2018 01:06:06 -1100 Subject: [PATCH 44/45] Add rpc error checking --- src/wallet/rpcwallet.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5c16c3b9c..977aee98d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5441,6 +5441,11 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); std::vector pubkey(ParseHex(params[1].get_str().c_str())); amount = atol(params[2].get_str().c_str()); + if ( tokenid == zeroid || amount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = AssetTransfer(0,tokenid,pubkey,amount); if ( hex.size() > 0 ) { @@ -5463,6 +5468,11 @@ UniValue tokenbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[1].get_str().c_str()); price = atof(params[2].get_str().c_str()); bidamount = (price * numtokens) * COIN + 0.0000000049999; + if ( tokenid == zeroid || tokenid == zeroid || price <= 0 || bidamount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CreateBuyOffer(0,bidamount,tokenid,numtokens); if ( hex.size() > 0 ) { @@ -5483,6 +5493,11 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str()); + if ( tokenid == zeroid || bidtxid == zeroid ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CancelBuyOffer(0,tokenid,bidtxid); if ( hex.size() > 0 ) { @@ -5504,6 +5519,11 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str()); fillamount = atol(params[2].get_str().c_str()); + if ( tokenid == zeroid || bidtxid == zeroid || fillamount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = FillBuyOffer(0,tokenid,bidtxid,fillamount); if ( hex.size() > 0 ) { @@ -5526,6 +5546,11 @@ UniValue tokenask(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[1].get_str().c_str()); price = atof(params[2].get_str().c_str()); askamount = (price * numtokens) * COIN + 0.0000000049999; + if ( tokenid == zeroid || numtokens <= 0 || price <= 0 || askamount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CreateSell(0,numtokens,tokenid,askamount); if ( hex.size() > 0 ) { @@ -5537,7 +5562,6 @@ UniValue tokenask(const UniValue& params, bool fHelp) UniValue tokenswapask(const UniValue& params, bool fHelp) { - static uint256 zeroid; UniValue result(UniValue::VOBJ); uint64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid; if ( fHelp || params.size() != 4 ) throw runtime_error("tokenswapask numtokens tokenid otherid price\n"); @@ -5570,18 +5594,22 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); + if ( tokenid == zeroid || asktxid == zeroid ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CancelSell(0,tokenid,asktxid); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt cancel bid")); + } else result.push_back(Pair("error", "couldnt cancel ask")); return(result); } UniValue tokenfillask(const UniValue& params, bool fHelp) { - static uint256 zeroid; UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,asktxid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); @@ -5592,6 +5620,11 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); fillunits = atol(params[2].get_str().c_str()); + if ( tokenid == zeroid || asktxid == zeroid || fillunits <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = FillSell(0,tokenid,zeroid,asktxid,fillunits); if ( hex.size() > 0 ) { @@ -5603,7 +5636,6 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) UniValue tokenfillswap(const UniValue& params, bool fHelp) { - static uint256 zeroid; UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid; if ( fHelp || params.size() != 4 ) throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n"); From 4d47fcb9371c24507109c4427f870dcc3653db91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Aug 2018 01:07:44 -1100 Subject: [PATCH 45/45] Create nonzero tokens --- src/wallet/rpcwallet.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 977aee98d..1597051f2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5411,6 +5411,11 @@ UniValue tokencreate(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = params[0].get_str(); supply = atof(params[1].get_str().c_str()) * COIN; + if ( name.size() == 0 || supply <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } if ( params.size() == 3 ) { description = params[2].get_str();