From fde85d291fe528fcd6303524c43c89f0195eb8f4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 30 Aug 2018 10:56:06 +0200 Subject: [PATCH 001/749] Add some helpful error messages for when Diceinit fails --- src/cc/dice.cpp | 14 +++++++++----- src/wallet/rpcwallet.cpp | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 50b9cba78..4d2675d8b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -882,7 +882,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t memset(&zero,0,sizeof(zero)); if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) { - CCerror = "Diceinit error in create funding"; + CCerror = "Diceinit error in create funding, is your transaction confirmed?"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -907,8 +907,10 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { + CCerror = "Diceinit error in add funding, is your transaction confirmed?"; return(""); + } scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( 0 ) { @@ -956,8 +958,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { + CCerror = "Diceinit error in bet, is your transaction confirmed?"; return(""); + } if ( bet < minbet || bet > maxbet || odds > maxodds ) { CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); @@ -997,7 +1001,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 //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"; + CCerror = "Diceinit error in finish, is your transaction confirmed?"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1110,7 +1114,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - CCerror = "Diceinit error in status"; + CCerror = "Diceinit error in status, is your transaction confirmed?"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(0.); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b99fffa59..467298be1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5303,7 +5303,10 @@ UniValue dicebet(const UniValue& params, bool fHelp) } if (amount > 0 && odds > 0) { hex = DiceBet(0,name,fundingtxid,amount,odds); - if ( hex.size() > 0 ) + if ( CCerror != "" ) + { + ERR_RESULT(CCerror); + } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); From 85dea2c444e3fe94eed794239465638b3f597059 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Wed, 12 Sep 2018 02:45:38 +0200 Subject: [PATCH 002/749] fix kv example --- src/rpcblockchain.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 08592fb67..fce949c4a 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -820,7 +820,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp) "}\n" "\nExamples:\n" + HelpExampleCli("kvsearch", "examplekey") - + HelpExampleRpc("kvsearch", "examplekey") + + HelpExampleRpc("kvsearch", "\"examplekey\"") ); LOCK(cs_main); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6daf9d86e..cdb54a742 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -542,7 +542,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) "}\n" "\nExamples:\n" + HelpExampleCli("kvupdate", "examplekey \"examplevalue\" 2 examplepassphrase") - + HelpExampleRpc("kvupdate", "examplekey \"examplevalue\" 2 examplepassphrase") + + HelpExampleRpc("kvupdate", "\"examplekey\",\"examplevalue\",\"2\",\"examplepassphrase\"") ); if (!EnsureWalletIsAvailable(fHelp)) return 0; From 53f445159c18ca406307249876f501551d66409c Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Wed, 12 Sep 2018 03:28:39 +0200 Subject: [PATCH 003/749] fix sendmany example --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cdb54a742..fd8cb1b2d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1252,13 +1252,13 @@ UniValue sendmany(const UniValue& params, bool fHelp) " the number of addresses.\n" "\nExamples:\n" "\nSend two amounts to two different addresses:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\":0.02}\"") + "\nSend two amounts to two different addresses setting the confirmation and comment:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\" 6 \"testing\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\":0.02}\" 6 \"testing\"") + "\nSend two amounts to two different addresses, subtract fee from amount:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\",\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\"]\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\",\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\"]\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("sendmany", "\"\", \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\", 6, \"testing\"") + + HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"") ); if ( ASSETCHAINS_PRIVATE != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); From 7367534212f4751c29235d5e6fa4f3917b958420 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Wed, 12 Sep 2018 07:20:55 +0200 Subject: [PATCH 004/749] fix typo --- src/rpcmining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index df58a5573..0a2b56ca9 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -915,7 +915,7 @@ UniValue getblocksubsidy(const UniValue& params, bool fHelp) "}\n" "\nExamples:\n" + HelpExampleCli("getblocksubsidy", "1000") - + HelpExampleRpc("getblockubsidy", "1000") + + HelpExampleRpc("getblocksubsidy", "1000") ); LOCK(cs_main); From 0b61c321318016ac804c4a2475e2f13e01e753b7 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Wed, 12 Sep 2018 07:36:18 +0200 Subject: [PATCH 005/749] fix address example --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fd8cb1b2d..5a6b6d784 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1256,7 +1256,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) "\nSend two amounts to two different addresses setting the confirmation and comment:\n" + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\":0.02}\" 6 \"testing\"") + "\nSend two amounts to two different addresses, subtract fee from amount:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\",\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\"]\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\",\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\"]\"") + "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"") ); From db09c7f6274f74644cdcc9bfb6f72ff8fc7b7593 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 21:49:12 -1100 Subject: [PATCH 006/749] RECOIN_CLI in oraclefeed.c --- src/cc/dapps/oraclefeed.c | 138 ++++++++++++++++++++++---------------- src/cc/gateways.cpp | 1 + 2 files changed, 83 insertions(+), 56 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 8af31c2e4..6a0f7d30a 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -308,13 +308,25 @@ uint64_t get_btcusd() return(btcusd); } -cJSON *get_komodocli(char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2) +char *REFCOIN_CLI; + +cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2) { long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256]; sprintf(fname,"/tmp/oraclefeed.%s",method); if ( acname[0] != 0 ) + { + if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) + printf("unexpected: refcoin.(%s) acname.(%s)\n",refcoin,acname); sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,fname); - else sprintf(cmdstr,"./komodo-cli %s %s %s %s > %s\n",method,arg0,arg1,arg2,fname); + } + else if ( strcmp(refcoin,"KMD") == 0 ) + sprintf(cmdstr,"./komodo-cli %s %s %s %s > %s\n",method,arg0,arg1,arg2,fname); + else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 ) + { + sprintf(cmdstr,"%s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,fname); + printf("REFCOIN_CLI (%s)\n",cmdstr); + } system(cmdstr); *retstrp = 0; if ( (jsonstr= filestr(&fsize,fname)) != 0 ) @@ -327,13 +339,13 @@ cJSON *get_komodocli(char **retstrp,char *acname,char *method,char *arg0,char *a return(retjson); } -bits256 komodobroadcast(char *acname,cJSON *hexjson) +bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson) { char *hexstr,*retstr,str[65]; cJSON *retjson; bits256 txid; memset(txid.bytes,0,sizeof(txid)); if ( (hexstr= jstr(hexjson,"hex")) != 0 ) { - if ( (retjson= get_komodocli(&retstr,acname,"sendrawtransaction",hexstr,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","")) != 0 ) { //fprintf(stderr,"broadcast.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -352,12 +364,12 @@ bits256 komodobroadcast(char *acname,cJSON *hexjson) return(txid); } -bits256 sendtoaddress(char *acname,char *destaddr,int64_t satoshis) +bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis) { char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid; memset(txid.bytes,0,sizeof(txid)); sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN); - if ( (retjson= get_komodocli(&retstr,acname,"sendtoaddress",destaddr,numstr,"")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"")) != 0 ) { fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -375,36 +387,34 @@ bits256 sendtoaddress(char *acname,char *destaddr,int64_t satoshis) return(txid); } -int32_t get_KMDheight(char *acname) +int32_t get_coinheight(char *refcoin,char *acname) { cJSON *retjson; char *retstr; int32_t height=0; - if ( (retjson= get_komodocli(&retstr,acname,"getinfo","","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","")) != 0 ) { height = jint(retjson,"blocks"); - //fprintf(stderr,"%s height.%d\n",acname[0]!=0?acname:"KMD",height); free_json(retjson); } else if ( retstr != 0 ) { - fprintf(stderr,"get_KMDheight.(%s) error.(%s)\n",acname,retstr); + fprintf(stderr,"%s get_coinheight.(%s) error.(%s)\n",refcoin,acname,retstr); free(retstr); } return(height); } -bits256 get_KMDblockhash(int32_t height) +bits256 get_coinblockhash(char *refcoin,char *acname,int32_t height) { cJSON *retjson; char *retstr,heightstr[32]; bits256 hash; memset(hash.bytes,0,sizeof(hash)); sprintf(heightstr,"%d",height); - if ( (retjson= get_komodocli(&retstr,"","getblockhash",heightstr,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","")) != 0 ) { fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0)); free_json(retjson); } else if ( retstr != 0 ) { - //fprintf(stderr,"get_KMDblockhash.(%s) %d\n",retstr,(int32_t)strlen(retstr)); if ( strlen(retstr) >= 64 ) { retstr[64] = 0; @@ -415,11 +425,11 @@ bits256 get_KMDblockhash(int32_t height) return(hash); } -bits256 get_KMDmerkleroot(bits256 blockhash) +bits256 get_coinmerkleroot(char *refcoin,char *acname,bits256 blockhash) { cJSON *retjson; char *retstr,str[65]; bits256 merkleroot; memset(merkleroot.bytes,0,sizeof(merkleroot)); - if ( (retjson= get_komodocli(&retstr,"","getblockheader",bits256_str(str,blockhash),"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","")) != 0 ) { merkleroot = jbits256(retjson,"merkleroot"); //fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot)); @@ -427,24 +437,24 @@ bits256 get_KMDmerkleroot(bits256 blockhash) } else if ( retstr != 0 ) { - fprintf(stderr,"get_KMDmerkleroot error.(%s)\n",retstr); + fprintf(stderr,"%s %s get_coinmerkleroot error.(%s)\n",refcoin,acname,retstr); free(retstr); } return(merkleroot); } -int32_t get_KMDheader(bits256 *blockhashp,bits256 *merklerootp,int32_t prevheight) +int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *merklerootp,int32_t prevheight) { int32_t height = 0; char str[65]; if ( prevheight == 0 ) - height = get_KMDheight("") - 20; + height = get_coinheight(refcoin,acname) - 20; else height = prevheight + 1; if ( height > 0 ) { - *blockhashp = get_KMDblockhash(height); + *blockhashp = get_coinblockhash(refcoin,acname,height); if ( bits256_nonz(*blockhashp) != 0 ) { - *merklerootp = get_KMDmerkleroot(*blockhashp); + *merklerootp = get_coinmerkleroot(refcoin,acname,*blockhashp); if ( bits256_nonz(*merklerootp) != 0 ) return(height); } @@ -454,26 +464,26 @@ int32_t get_KMDheader(bits256 *blockhashp,bits256 *merklerootp,int32_t prevheigh return(0); } -cJSON *get_gatewayspending(char *acname,char *oraclestxidstr,char *coin) +cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(&retstr,acname,"gatewayspending",oraclestxidstr,coin,"")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"")) != 0 ) { //printf("pending.(%s)\n",jprint(retjson,0)); return(retjson); } else if ( retstr != 0 ) { - fprintf(stderr,"get_gatewayspending.(%s) error.(%s)\n",acname,retstr); + fprintf(stderr,"%s get_gatewayspending.(%s) error.(%s)\n",refcoin,acname,retstr); free(retstr); } return(0); } -cJSON *get_rawmempool(char *acname) +cJSON *get_rawmempool(char *refcoin,char *acname) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(&retstr,acname,"getrawmempool","","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","")) != 0 ) { //printf("mempool.(%s)\n",jprint(retjson,0)); return(retjson); @@ -486,11 +496,13 @@ cJSON *get_rawmempool(char *acname) return(0); } -cJSON *get_addressutxos(char *acname,char *coinaddr) +cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr) { cJSON *retjson; char *retstr,jsonbuf[256]; + if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) + printf("warning: assumes %s has addressindex enabled\n",refcoin); sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); - if ( (retjson= get_komodocli(&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) { //printf("addressutxos.(%s)\n",jprint(retjson,0)); return(retjson); @@ -503,10 +515,10 @@ cJSON *get_addressutxos(char *acname,char *coinaddr) return(0); } -cJSON *get_rawtransaction(char *acname,bits256 txid) +cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) { cJSON *retjson; char *retstr,str[65]; - if ( (retjson= get_komodocli(&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) { return(retjson); } @@ -518,11 +530,11 @@ cJSON *get_rawtransaction(char *acname,bits256 txid) return(0); } -void gatewaysmarkdone(char *acname,bits256 txid) +void gatewaysmarkdone(char *refcoin,char *acname,bits256 txid) { char str[65],*retstr; cJSON *retjson; printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,txid)); - if ( (retjson= get_komodocli(&retstr,acname,"gatewaysmarkdone",bits256_str(str,txid),"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,txid),"","")) != 0 ) { komodobroadcast(acname,retjson); free_json(retjson); @@ -534,10 +546,10 @@ void gatewaysmarkdone(char *acname,bits256 txid) } } -int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) +int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinaddr) { cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; - if ( (txobj= get_rawtransaction(acname,txid)) != 0 ) + if ( (txobj= get_rawtransaction(refcoin,acname,txid)) != 0 ) { if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) { @@ -566,24 +578,24 @@ int32_t tx_has_voutaddress(char *acname,bits256 txid,char *coinaddr) return(retval); } -int32_t coinaddrexists(char *acname,char *coinaddr) +int32_t coinaddrexists(char *refcoin,char *acname,char *coinaddr) { cJSON *array; bits256 txid; int32_t i,n,num=0; - if ( (array= get_addressutxos(acname,coinaddr)) != 0 ) + if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 ) { num = cJSON_GetArraySize(array); free_json(array); } else return(-1); if ( num == 0 ) { - if ( (array= get_rawmempool(acname)) != 0 ) + if ( (array= get_rawmempool(refcoin,acname)) != 0 ) { if ( (n= cJSON_GetArraySize(array)) != 0 ) { for (i=0; i 0 ) + if ( tx_has_voutaddress(refcoin,acname,txid,coinaddr) > 0 ) { num = 1; break; @@ -596,7 +608,7 @@ int32_t coinaddrexists(char *acname,char *coinaddr) return(num); } -void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) +void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) { // check queue to prevent duplicate // check KMD chain and mempool for txidaddr @@ -606,9 +618,9 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid,origtxid; int64_t satoshis; - if ( (retjson= get_gatewayspending(acname,oraclestxidstr,coin)) != 0 ) + if ( (retjson= get_gatewayspending(refcoin,acname,oraclestxidstr)) != 0 ) { - if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,coin) == 0 ) + if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) { if ( (pending= jarray(&n,retjson,"pending")) != 0 ) { @@ -621,14 +633,14 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) //process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"} if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) { - if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists(acname,txidaddr)) == 0 ) + if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists(refcoin,acname,txidaddr)) == 0 ) { // this is less errors but more expensive: ./komodo-cli z_sendmany "signeraddr" '[{"address":"","amount":0.0001},{"address":"","amount":}]' - txid = sendtoaddress(acname,txidaddr,10000); - if ( bits256_nonz(txid) != 0 && coinaddrexists(acname,txidaddr) > 0 ) + txid = sendtoaddress("KMD",acname,txidaddr,10000); + if ( bits256_nonz(txid) != 0 && coinaddrexists(refcoin,acname,txidaddr) > 0 ) { // the actual withdraw - withtxid = sendtoaddress(strcmp("KMD",coin)==0?"":coin,withdrawaddr,satoshis); + withtxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); if ( bits256_nonz(withtxid) != 0 ) { fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); @@ -639,7 +651,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) { fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } - } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(acname,txidaddr)); + } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); } else if ( retval > 0 ) { @@ -654,7 +666,7 @@ void update_gatewayspending(char *acname,char *oraclestxidstr,char *coin) } } -int32_t get_oracledata(int32_t prevheight,char *hexstr,int32_t maxsize,char *format) +int32_t get_oracledata(char *refcoin,char *acname,int32_t prevheight,char *hexstr,int32_t maxsize,char *format) { int32_t i; uint32_t height; uint64_t price; bits256 blockhash,merkleroot; hexstr[0] = 0; @@ -670,7 +682,7 @@ int32_t get_oracledata(int32_t prevheight,char *hexstr,int32_t maxsize,char *for } else if ( strcmp(format,"Ihh") == 0 ) { - if ( (height= get_KMDheader(&blockhash,&merkleroot,prevheight)) > prevheight ) + if ( (height= get_coinheader(refcoin,acname,&blockhash,&merkleroot,prevheight)) > prevheight ) { for (i=0; i<4; i++) sprintf(&hexstr[i*2],"%02x",(uint8_t)((height >> (i*8)) & 0xff)); @@ -711,17 +723,21 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 int32_t main(int32_t argc,char **argv) { - cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096]; uint64_t price; bits256 txid; - if ( argc != 6 ) + cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; + if ( argc < 6 ) { - printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID\nPowered by CoinDesk (%s) %.8f\n","https://www.coindesk.com/price/",dstr(get_btcusd())); + printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]\n"); return(-1); } + printf("Powered by CoinDesk (%s) %.8f\n","https://www.coindesk.com/price/",dstr(get_btcusd())); acname = argv[1]; oraclestr = argv[2]; pkstr = argv[3]; format = argv[4]; bindtxidstr = argv[5]; + if ( argc > 6 ) + REFCOINCLI = argv[6]; + else REFCOINCLI = "./komodo_cli"; if ( strncmp(format,"Ihh",3) != 0 && format[0] != 'L' ) { printf("only formats of L and Ihh are supported now\n"); @@ -731,8 +747,18 @@ int32_t main(int32_t argc,char **argv) while ( 1 ) { retstr = 0; - if ( prevheight < (get_KMDheight("") - 10) && (clijson= get_komodocli(&retstr,acname,"oraclesinfo",oraclestr,"","")) != 0 ) + if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","")) != 0 ) { + if ( refcoin[0] == 0 && jstr(clijson,"coin") != 0 ) + { + strcpy(refcoin,jstr(clijson,"coin")); + if ( strcmp("KMD",refcoin) != 0 && argc != 7 ) + { + printf("need to specify path to refcoin's cli as last argv\n"); + exit(0); + } + printf("set refcoin <- %s [%s]\n",refcoin,REFCOIN_CLI); + } if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) { for (i=0; i Date: Wed, 12 Sep 2018 21:51:58 -1100 Subject: [PATCH 007/749] Test --- src/cc/dapps/oraclefeed.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 6a0f7d30a..f054ac234 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -536,7 +536,7 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 txid) printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,txid)); if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,txid),"","")) != 0 ) { - komodobroadcast(acname,retjson); + komodobroadcast(refcoin,acname,retjson); free_json(retjson); } else if ( retstr != 0 ) @@ -644,7 +644,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) if ( bits256_nonz(withtxid) != 0 ) { fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone(acname,origtxid); + gatewaysmarkdone("KMD",acname,origtxid); processed++; } else @@ -656,7 +656,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) else if ( retval > 0 ) { fprintf(stderr,"already did withdraw %s %s %.8f processed\n",coin,withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone(acname,origtxid); + gatewaysmarkdone("KMD",acname,origtxid); } } } @@ -736,8 +736,8 @@ int32_t main(int32_t argc,char **argv) format = argv[4]; bindtxidstr = argv[5]; if ( argc > 6 ) - REFCOINCLI = argv[6]; - else REFCOINCLI = "./komodo_cli"; + REFCOIN_CLI = argv[6]; + else REFCOIN_CLI = "./komodo_cli"; if ( strncmp(format,"Ihh",3) != 0 && format[0] != 'L' ) { printf("only formats of L and Ihh are supported now\n"); From 932326dd45b2ea635cb62c33499e4c08b1fe50ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 21:53:04 -1100 Subject: [PATCH 008/749] Test --- src/cc/dapps/oraclefeed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index f054ac234..8df1fd381 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -643,19 +643,19 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) withtxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); if ( bits256_nonz(withtxid) != 0 ) { - fprintf(stderr,"withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); gatewaysmarkdone("KMD",acname,origtxid); processed++; } else { - fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",coin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); } else if ( retval > 0 ) { - fprintf(stderr,"already did withdraw %s %s %.8f processed\n",coin,withdrawaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"already did withdraw %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); gatewaysmarkdone("KMD",acname,origtxid); } } @@ -771,7 +771,7 @@ int32_t main(int32_t argc,char **argv) if ( (clijson2= get_komodocli("KMD",&retstr2,acname,"oraclesdata",oraclestr,hexstr,"")) != 0 ) { //printf("data.(%s)\n",jprint(clijson2,0)); - txid = komodobroadcast(acname,clijson2); + txid = komodobroadcast("KMD",acname,clijson2); if ( bits256_nonz(txid) != 0 ) { prevheight = height; From e726fec744e0d4ee73d2dbe718ee592a6d35bd8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 21:54:31 -1100 Subject: [PATCH 009/749] - --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 8df1fd381..dc112a1e7 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -737,7 +737,7 @@ int32_t main(int32_t argc,char **argv) bindtxidstr = argv[5]; if ( argc > 6 ) REFCOIN_CLI = argv[6]; - else REFCOIN_CLI = "./komodo_cli"; + else REFCOIN_CLI = "./komodo-cli"; if ( strncmp(format,"Ihh",3) != 0 && format[0] != 'L' ) { printf("only formats of L and Ihh are supported now\n"); From 66bda9d6e5b06b8457594d3dde616d9e80c506da Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 21:57:19 -1100 Subject: [PATCH 010/749] Test --- src/cc/dapps/oraclefeed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index dc112a1e7..1288b5dae 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -618,7 +618,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid,origtxid; int64_t satoshis; - if ( (retjson= get_gatewayspending(refcoin,acname,oraclestxidstr)) != 0 ) + if ( (retjson= get_gatewayspending("KMD",acname,oraclestxidstr)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) { @@ -633,11 +633,11 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) //process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"} if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) { - if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists(refcoin,acname,txidaddr)) == 0 ) + if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists("KMD",acname,txidaddr)) == 0 ) { // this is less errors but more expensive: ./komodo-cli z_sendmany "signeraddr" '[{"address":"","amount":0.0001},{"address":"","amount":}]' txid = sendtoaddress("KMD",acname,txidaddr,10000); - if ( bits256_nonz(txid) != 0 && coinaddrexists(refcoin,acname,txidaddr) > 0 ) + if ( bits256_nonz(txid) != 0 && coinaddrexists("KMD",acname,txidaddr) > 0 ) { // the actual withdraw withtxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); From 7a85c397f8a8e78e8c4767c4e0410a4f8ccb762a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 21:59:31 -1100 Subject: [PATCH 011/749] Test --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 1288b5dae..31493ffe0 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -325,7 +325,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 ) { sprintf(cmdstr,"%s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,fname); - printf("REFCOIN_CLI (%s)\n",cmdstr); + printf("ref.(%s) REFCOIN_CLI (%s)\n",refcoin,cmdstr); } system(cmdstr); *retstrp = 0; From b07595f4f6d0000d26ec2089485ab7af7f572e0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 22:01:09 -1100 Subject: [PATCH 012/749] Test --- src/cc/dapps/oraclefeed.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 31493ffe0..3ea8b3a59 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -744,6 +744,7 @@ int32_t main(int32_t argc,char **argv) return(-1); } acheight = 0; + refcoin[0] = 0; while ( 1 ) { retstr = 0; From e7795555f0adbcbaf56f868a55e9d472f304ecd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 22:02:45 -1100 Subject: [PATCH 013/749] Test --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 3ea8b3a59..068119dec 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -759,7 +759,7 @@ int32_t main(int32_t argc,char **argv) exit(0); } printf("set refcoin <- %s [%s]\n",refcoin,REFCOIN_CLI); - } + } else printf("clijson.(%s)\n",jprint(clijson,0)); if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) { for (i=0; i Date: Wed, 12 Sep 2018 22:03:30 -1100 Subject: [PATCH 014/749] Test --- src/cc/dapps/oraclefeed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 068119dec..4fdbc2176 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -750,16 +750,16 @@ int32_t main(int32_t argc,char **argv) retstr = 0; if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","")) != 0 ) { - if ( refcoin[0] == 0 && jstr(clijson,"coin") != 0 ) + if ( refcoin[0] == 0 && jstr(clijson,"name") != 0 ) { - strcpy(refcoin,jstr(clijson,"coin")); + strcpy(refcoin,jstr(clijson,"name")); if ( strcmp("KMD",refcoin) != 0 && argc != 7 ) { printf("need to specify path to refcoin's cli as last argv\n"); exit(0); } printf("set refcoin <- %s [%s]\n",refcoin,REFCOIN_CLI); - } else printf("clijson.(%s)\n",jprint(clijson,0)); + } //else printf("clijson.(%s)\n",jprint(clijson,0)); if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) { for (i=0; i Date: Wed, 12 Sep 2018 22:58:33 -1100 Subject: [PATCH 015/749] Markdone with cointxid --- src/cc/CCGateways.h | 2 +- src/cc/dapps/oraclefeed.c | 14 +++++++------- src/cc/gateways.cpp | 7 +++---- src/wallet/rpcwallet.cpp | 6 ++++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 1d7bef9d5..d4b42f8e7 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -26,7 +26,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); -std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid); +std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 4fdbc2176..8107dc055 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -617,7 +617,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) /// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws - cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,withtxid,origtxid; int64_t satoshis; + cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,cointxid,origtxid; int64_t satoshis; if ( (retjson= get_gatewayspending("KMD",acname,oraclestxidstr)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) @@ -640,16 +640,16 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) if ( bits256_nonz(txid) != 0 && coinaddrexists("KMD",acname,txidaddr) > 0 ) { // the actual withdraw - withtxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); - if ( bits256_nonz(withtxid) != 0 ) + cointxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); + if ( bits256_nonz(cointxid) != 0 ) { - fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone("KMD",acname,origtxid); + fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); processed++; } else { - fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,withtxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); } @@ -759,7 +759,7 @@ int32_t main(int32_t argc,char **argv) exit(0); } printf("set refcoin <- %s [%s]\n",refcoin,REFCOIN_CLI); - } //else printf("clijson.(%s)\n",jprint(clijson,0)); + } if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) { for (i=0; ievalcode << 'M' << cointxid << refcoin); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } @@ -825,7 +825,6 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) obj.push_back(Pair("depositaddr",depositaddr)); Getscriptaddress(signeraddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); obj.push_back(Pair("signeraddr",signeraddr)); - // numqueued += GatewaysAddQueue(refcoin,txid,tx.vout[1].scriptPubKey,tx.vout[0].nValue); } pending.push_back(obj); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d3825388c..8f94d84a5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5516,11 +5516,13 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 withdrawtxid; std::string hex; if ( fHelp || params.size() != 1 ) - throw runtime_error("gatewaysmarkdone withdrawtxid\n"); + throw runtime_error("gatewaysmarkdone withdrawtxid coin cointxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); - hex = GatewaysMarkdone(0,withdrawtxid); + coin = params[1].get_str(); + cointxid = Parseuint256((char *)params[2].get_str().c_str()); + hex = GatewaysMarkdone(0,withdrawtxid,coin,cointxid); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From 518ae45859f314dc35efc790a70ee608e046150c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 22:59:28 -1100 Subject: [PATCH 016/749] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8f94d84a5..e01d813c6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5514,7 +5514,7 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 withdrawtxid; std::string hex; + UniValue result(UniValue::VOBJ); uint256 withdrawtxid,cointxid; std::string hex,coin; if ( fHelp || params.size() != 1 ) throw runtime_error("gatewaysmarkdone withdrawtxid coin cointxid\n"); if ( ensure_CCrequirements() < 0 ) From 8c3015309f72129783f83f32fead9ee38575f85c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 23:01:38 -1100 Subject: [PATCH 017/749] Test --- src/cc/dapps/oraclefeed.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 8107dc055..536b2650b 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -617,7 +617,8 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) /// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws - cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,cointxid,origtxid; int64_t satoshis; + cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; + memset(&zeroid,0,sizeof(zeroid)); if ( (retjson= get_gatewayspending("KMD",acname,oraclestxidstr)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) @@ -656,7 +657,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) else if ( retval > 0 ) { fprintf(stderr,"already did withdraw %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone("KMD",acname,origtxid); + gatewaysmarkdone("KMD",acname,origtxid,refcoin,zeroid); } } } From 1805ffc2fae8e804218cfec7c63f5faa02b0befa Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 12 Sep 2018 23:03:54 -1100 Subject: [PATCH 018/749] Test --- src/cc/dapps/oraclefeed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 536b2650b..04a08a1d4 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -530,11 +530,11 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) return(0); } -void gatewaysmarkdone(char *refcoin,char *acname,bits256 txid) +void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bits256 cointxid) { - char str[65],*retstr; cJSON *retjson; - printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,txid)); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,txid),"","")) != 0 ) + char str[65],str2[65],*retstr; cJSON *retjson; + printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,withtxid)); + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,bits256_str(str2,cointxid))) != 0 ) { komodobroadcast(refcoin,acname,retjson); free_json(retjson); From e2f37fc6c1d1ca96b23d8aa6d86d27bd9c115f89 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Thu, 13 Sep 2018 21:46:02 +0700 Subject: [PATCH 019/749] deprecated oraclefeed compilation script --- src/cc/dapps/oracle_dapp.sh | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100755 src/cc/dapps/oracle_dapp.sh diff --git a/src/cc/dapps/oracle_dapp.sh b/src/cc/dapps/oracle_dapp.sh deleted file mode 100755 index f6efd6a2b..000000000 --- a/src/cc/dapps/oracle_dapp.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# SET AC -read -p "Enter AC name you use : " acname -sed -i "/#define ACNAME */c\#define ACNAME \"$acname\"" oraclefeed.c -# Set ORACLETXID -read -p "Enter your oracle TXID (Oracle should have L data type) : " oracletxid -sed -i "/#define ORACLETXID */c\#define ORACLETXID \"$oracletxid\"" oraclefeed.c -# SET PUBKEY -read -p "Enter your pubkey : " pubkey -sed -i "/#define MYPUBKEY */c\#define MYPUBKEY \"$pubkey\"" oraclefeed.c -# COMPILATION -echo "Great, compiling !" -gcc oraclefeed.c -lm -o oracle_dapp -mv oracle_dapp ../../oracle_dapp -echo "Oracle is ready to use !" -while true; do - read -p "Would you like to run BTCUSD oracle app? [Y/N]" yn - case $yn in - [Yy]* ) cd ../..; ./oracle_dapp; break;; - [Nn]* ) exit;; - * ) echo "Please answer yes or no.";; - esac -done From e94993253a685344ad02d2d70910dd1312f5916f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 05:57:32 -1100 Subject: [PATCH 020/749] Gatewaysinfo --- src/cc/dapps/oraclefeed.c | 64 +++++++++++++++++++++++++++++++-------- src/cc/gateways.cpp | 1 + 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 04a08a1d4..80dd2be32 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -546,6 +546,32 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit } } +int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) +{ + char *oracle,*retstr,*name; cJSON *retjson; + *Np = *Mp = 0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","")) != 0 ) + { + if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) + { + if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 ) + { + *Mp = jint(retjson,"M"); + *Np = jint(retjson,"N"); + } + } + free_json(retjson); + } + else if ( retstr != 0 ) + { + printf("error parsing get_gatewaysinfo.(%s)\n",retstr); + free(retstr); + } + if ( *Mp <= 0 || *Np <= 0 ) + return(-1); + else return(0); +} + int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinaddr) { cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; @@ -608,7 +634,7 @@ int32_t coinaddrexists(char *refcoin,char *acname,char *coinaddr) return(num); } -void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) +void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr,int32_t M,int32_t N) { // check queue to prevent duplicate // check KMD chain and mempool for txidaddr @@ -617,7 +643,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) /// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws - cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*withdrawaddr; int32_t i,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; + cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; memset(&zeroid,0,sizeof(zeroid)); if ( (retjson= get_gatewayspending("KMD",acname,oraclestxidstr)) != 0 ) { @@ -632,7 +658,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) item = jitem(pending,i); origtxid = jbits256(item,"txid"); //process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"} - if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) + if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (depositaddr= jstr(item,"depositaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) { if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && (retval= coinaddrexists("KMD",acname,txidaddr)) == 0 ) { @@ -641,16 +667,24 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) if ( bits256_nonz(txid) != 0 && coinaddrexists("KMD",acname,txidaddr) > 0 ) { // the actual withdraw - cointxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); - if ( bits256_nonz(cointxid) != 0 ) + if ( strcmp(depositaddr,signeraddr) == 0 ) { - fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); - processed++; + cointxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); + if ( bits256_nonz(cointxid) != 0 ) + { + fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); + processed++; + } + else + { + fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + } } else { - fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + // check msigmarkers + } } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); } @@ -724,7 +758,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 int32_t main(int32_t argc,char **argv) { - cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; + cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; if ( argc < 6 ) { printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]\n"); @@ -744,6 +778,7 @@ int32_t main(int32_t argc,char **argv) printf("only formats of L and Ihh are supported now\n"); return(-1); } + M = N = 1; acheight = 0; refcoin[0] = 0; while ( 1 ) @@ -759,7 +794,12 @@ int32_t main(int32_t argc,char **argv) printf("need to specify path to refcoin's cli as last argv\n"); exit(0); } - printf("set refcoin <- %s [%s]\n",refcoin,REFCOIN_CLI); + if ( get_gatewaysinfo("KMD",acname,&M,&N,bindtxidstr,refcoin,oraclestr) < 0 ) + { + printf("cant find bindtxid.(%s)\n",bindtxidstr); + exit(0); + } + printf("set refcoin <- %s [%s] M.%d of N.%d\n",refcoin,REFCOIN_CLI,M,N); } if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) { @@ -779,7 +819,7 @@ int32_t main(int32_t argc,char **argv) prevheight = height; acheight = get_coinheight(refcoin,""); printf("%s ht.%d <- %s\n",refcoin,height,hexstr); - update_gatewayspending(refcoin,acname,bindtxidstr); + update_gatewayspending(refcoin,acname,bindtxidstr,M,N); } free_json(clijson2); } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 986608fb6..765121a44 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -74,6 +74,7 @@ string oracles ./c oraclessubscribe 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 1000 f9499d8bb04ffb511fcec4838d72e642ec832558824a2ce5aed87f1f686f8102 + gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s) ./c gatewaysbind a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 KMD 100000000000000 1 1 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e From 2a4078bb5cbd9661b0793901351ad628a06954d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 05:59:06 -1100 Subject: [PATCH 021/749] Test --- src/cc/dapps/oraclefeed.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 80dd2be32..b53c308f7 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -552,6 +552,7 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char *Np = *Mp = 0; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","")) != 0 ) { + printf("got gatewaysinfo\n"); if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) { if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 ) @@ -559,7 +560,7 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); } - } + } else printf("%s != %s\n",oracle,oraclestr); free_json(retjson); } else if ( retstr != 0 ) From 81abf817501512c0d6293e740ead3e530a6ca04d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 06:02:15 -1100 Subject: [PATCH 022/749] Test --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index b53c308f7..98c7a05fa 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -559,7 +559,7 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); - } + } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); } else printf("%s != %s\n",oracle,oraclestr); free_json(retjson); } From ea17adb690ebd47a38ef3069a130122c44a47ffd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 06:04:41 -1100 Subject: [PATCH 023/749] Test --- src/cc/dapps/oraclefeed.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 98c7a05fa..9cb1af6cc 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -559,6 +559,7 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); + printf("(%s)\n",jprint(retjson,0)); } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); } else printf("%s != %s\n",oracle,oraclestr); free_json(retjson); From 1deabac47aa706ba7d5db62003af68e3d9686160 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 06:05:29 -1100 Subject: [PATCH 024/749] Test --- src/cc/dapps/oraclefeed.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 9cb1af6cc..0ae44d381 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -549,17 +549,15 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) { char *oracle,*retstr,*name; cJSON *retjson; - *Np = *Mp = 0; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","")) != 0 ) { - printf("got gatewaysinfo\n"); if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) { if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 ) { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); - printf("(%s)\n",jprint(retjson,0)); + //printf("(%s)\n",jprint(retjson,0)); } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); } else printf("%s != %s\n",oracle,oraclestr); free_json(retjson); From b71da7105ff7679f70850fea5683e34b15ac2c46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 06:06:26 -1100 Subject: [PATCH 025/749] Test --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 0ae44d381..9fa8845d5 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -553,7 +553,7 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char { if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) { - if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 ) + if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 && jint(retjson,"N") >= 1 ) { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); From d3be9b44708244d738658039972892f35fc1702c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 13 Sep 2018 23:57:57 -1100 Subject: [PATCH 026/749] Initial channels CC doc --- src/cc/CC made easy | 46 ++++++++++++++++++++++++++++++++++++++- src/cc/dapps/oraclefeed.c | 6 ++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/cc/CC made easy b/src/cc/CC made easy index 4158e061e..5784c17c5 100644 --- a/src/cc/CC made easy +++ b/src/cc/CC made easy @@ -447,7 +447,51 @@ WARNING: there is an attack vector that precludes betting any large amounts, it 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. -Chapter 10 - lotto example +Chapter 10 - channels example +It might be hard to believe, but channels CC implements an instant payment mechanism that is secured by dPoW in a way that is backward compatible with the existing wallets, explorers, etc. and channels CC does not require both nodes to be online. Its usecases are all the usecases for Lightning Network, it is just more secure, less expensive and backward compatible! The one aspect which some might consider a downside (and others another benefit) is that all payments are onchain. This means it would increase blockchain size, but the idea is for channels CC to be used on blockchains with relatively lower value coins, so a txfee of 0.0001 is not anything significant. + +Warning: very confusing blockchain reorganization issues described below. Will be confusing to most people + +From a distance, the blockchain is a chain of blocks. One block after the next, each referencing all the prior blocks. Each block containing a group of transactions. Prior to getting into a block, the transactions are broadcast to the network and if it is valid, it enters the memory pool. Each miner then constructs a valid block from these memory pool transactions and when a transaction gets mined (confirmed), it is removed from the memory pool. + +That is the simple version! + +The reality is quite a bit more complex, but the critical aspect is that the blockchain can (and is) reorganized as part of the expected protocol. This can happen even when there is no 51% attack happening and it is important to understand this process in detail, so here goes. + +What happens if two miners find a valid block at the same time? In this case the "same time" means within the time it takes for a block to propagate to the network. When a miner finds a new block, it is broadcast to the network and nodes update and start waiting for the next block. When there are two different (and valid) blocks propagating at the same time, some nodes update with one of the blocks and some the other, lets call it blockA and blockB. Now the nodes will know about both blockA and blockB, but some will consider blockA to be the chaintip and others will consider blockB to be the chaintip. + +This is where it gets confusing. Which is the correct chaintip (latest block?). It turns out that both blockA and blockB are valid at this moment in time. So there are actuall two blockchains. We have what is called a small fork! Now dont worry, the protocol will help us converge to a single chain, but in order to do that, we need the next block. + +Some miners will be mining from blockA and others from blockB. In most all cases, when the next block is found, it wont be at the "same time" again. So we will end up with a chain that is blockA+blockA2 or blockB+blockB2. Here comes the small reorg! Let's assuming blockA2 was found before blockB2, so that means all nodes that had blockB as the chaintip now see a longer chain blockA+blockA2, which trumps blockB. When that happens, it reorgs the chain so it is on blockA+blockA2. To do this properly, all the transactions that were in blockB are put back into the mempool and blockA is added, then blockA2. + +Of course, when blockB2 arrives, the nodes see it but blockB+blockB2 is the same length as blockA+blockA2, so no reorg happens. Since we postulated that blockAs arrived "before" blockB2, that means all nodes are on the same chaintip, including all the miners and the next block found would be blockA3, without any complications. + +Believe it or not, this sort of thing is happening all the time, one all blockchains. The chaintip is a volatile thing and that is why more than one confirmation is needed to avoid the small reorgs invalidating blockhash. However, it is possible for more than just the blockhash to change. When the reorg happens, all the transactions in the block are put back into the mempool and then the new blocks are processed in order. So what happens if one of the inputs to a transaction that happened in blockB, gets spent in blockA2? Based on random utxo allocation by wallets this is not impossible if an address has a lot of activity, but if it is part of a 51% attack, then this remote chance of an utxo being spent becomes a certainity! In fact, that is what a 51% attack is. + +The attack can go much deeper than just one block. For chains that use the longest chain rule, it can go quite deep indeed. So as all the reorged transactions are put back into the mempool, we feel good that it will get confirmed again. Unfortunately, there is no enforcement of a miner needing to mine any specific transaction in the mempool. And the 51% attacker is intent on mining the transaction that spends an already spent utxo in the reorganized chain. it is called a double spend, but in the reorganized chain, it is spent only once. So it is a bit of a misnomer. + +The important thing to understand is that if any transaction has inputs that are signed by a node, it is possible when the chain reorganizes for that transaction to become invalid. This is why dPoW is important as it doesnt strictly use the longest chain rule, but rather the longest notarized chain rule. Once a block is notarized, then it will refuse to reorganize that block (or any block before). So the risk is still there, but only until a notarization. Please see more detailed information about dPoW . + +Given the above, if you are wondering how can it be possible to have a mempool payment be secured by dPoW. Since it is explained how the reorgs can make valid transactions disappear, it seems unlikely any such solution is possible. However, the CC is very powerful and it can make unlikely things possible. + +The following describes how. + +We know that any payment that is utxo based can be invalidated via 51% attack, or even an unlikely but not impossible random utxo allocation from a busy wallet. Which means the payment cant be via a utxo. Since the CC system is utxo based, you might think that it means CC cant solve this. However, CC is very powerful and can implement payments that are not utxo based. But before this non-utxo payment method is explained, first we need to solve the mechanics of payment. + +At a high level, we want to lock funds into a channel, have this lock notarized so it cant be reorganized. Then payments can unlock funds. Additionally, if we are restricting the payment to just one destination, we also need a way for the sender to reclaim the unused funds. So there needs a way for a close channel notification, which when notarized allows the sender to reclaim all funds. After the channel close is notarized, then the only action possible should be a reclaim of sender funds. + +We need to assume that any payment, channel close, reclaim can be reorganized until it is notarized so great care needs to be made that a payment that is made will always be valid. With some allowances for blocks after a channelclose is notarized, we can protect the payments using the logic of "stop accepting payments after a channelclose is seen". It might be that a full notarization of wait time after the channelclose is notarized is needed to provide sufficient time for all the payments to be reprocessed. + +Now we can finally describe the requirements for the CC. The locked funds need to be able to be spent by either the sender or receiver, the former only after sufficient time after a channelclose and the latter only after a payment is seen (not just confirmed, but just seeing it should be enough). The protection from reorgs is that the payment itself reveals a secret that is needed for the payment and only the secret would be needed, so it wont matter what utxo is used. To lock funds into a CC address that can handle this we need a 1of2 CC address, which can accept a signature from either of two pubkeys. The additional CC constraints would be enforced to make sure payments are made until the channel is closed. + +A hashchain has the nice property of being able to encode a lot of secrets with a single hash. You can hash the hash, over and over and the final hash is the public value. By revealing the next to last hash, it can be verified that it hashes to the final hash. There is a restriction that a hashchain needs to be of reasonable maximum depth, say 1000. That means each iteration of the hashchain that is revealed is worth 1/1000th the total channelfunds. In fact, if the 500th hash value is revealed, half the channelfunds are released. this allows 1/1000th resolution that can be released with a single hash value. + +Now we can make the payment based on the hashvalue revealed at a specified depth before the prior released hashchain value. Both the sender and receiver can make a payment to the destination by attaching a hashchain secret. This means even if the sender's payment is reorganized, if the destination has the revealed secret, a replacement payment can be made that is valid. If the destination account isnt monitoring the blockchain, then it wont see the revealed secret, but in this case there shouldnt be value released for the payments that are reorganized. So it would be a case of no harm, no foul. In any event, all the payments end up verifiable on the blockchain to provide verifiability. + +Payments at the speed of the mempool, protected by dPoW! + +
+ Chapter 11 - oracles example Oracles CC is an example where it ended up being simpler than I first expected, but at the same time a lot more powerful. It is one of the smaller CC, but it enables creation of an arbitrary number of data markets, in a performant way. diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 9fa8845d5..915333aea 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -684,7 +684,11 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr,int3 else { // check msigmarkers - + // iterate for sigs depth and find the deepest + // if not already a signer, add signature and post to next + // if first one, then create a rawtx and sign it, ie. depth 1 + // if fully signed, broadcast + // iterate txidaddr, find highest nValue! } } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); } From f4e843946908eb1ecdab527dcf49c7abef8b8f98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 14 Sep 2018 00:16:16 -1100 Subject: [PATCH 027/749] - --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 765121a44..f3f872ebc 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -282,7 +282,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +/*int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; @@ -308,7 +308,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP } } return(totalinputs); -} +}*/ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { From 87f37301b4188efd0b6030ef8e1d8cea0aa134a5 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 14 Sep 2018 17:57:04 +0200 Subject: [PATCH 028/749] build error, fix typo --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5a6b6d784..6765d94b2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1256,7 +1256,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) "\nSend two amounts to two different addresses setting the confirmation and comment:\n" + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\":0.02}\" 6 \"testing\"") + "\nSend two amounts to two different addresses, subtract fee from amount:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\",\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\"]\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\":0.01,\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\\\",\\\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\\\"]\"") + "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"") ); From f9d85c8f86401ede94a917d70bf46e7bba49f924 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Sep 2018 21:46:46 -1100 Subject: [PATCH 029/749] Check for notarized in disconnect tip --- src/cc/CC made easy | 33 +++++++++++++++++++ src/cc/CCGateways.h | 1 + src/cc/dapps/oraclefeed.c | 69 +++++++++++++++++++++++++++++---------- src/cc/gateways.cpp | 62 +++++++++++++++++++++++++++++++++-- src/main.cpp | 9 +++++ 5 files changed, 155 insertions(+), 19 deletions(-) diff --git a/src/cc/CC made easy b/src/cc/CC made easy index 5784c17c5..895d84404 100644 --- a/src/cc/CC made easy +++ b/src/cc/CC made easy @@ -626,6 +626,39 @@ Conclusion I hope this document has helped you understand what a Komodo utxo based CC contract is and how it is different from the other smart contracts. If you are now able to dive into the cc directory and start making your own CC contract, then I am very happy! +gateways CC +gateways CC is the first CC that combines multiple CC into a single one. In order to achieve its goals, both the assets CC and the oracles CC is used, in addition to a dapp that issues regular transactions. This general approach can be used to solve quite a few different use cases, so it is important to understand how a multi-CC solution is put together. There are some tricky issues that only arise when using more than one CC at a time. + +Before the implementation details, first lets understand what the gateways CC does. At a high level it is similar to the old multigateway (from NXT AE 2014), but with improvements. The basic idea is to tokenize other crypto coins (like BTC) and then use the assets CC to transact/swap against the tokenized crypto. By enforcing a 1:1 peg between a specific token and BTC and an automated deposit/withdraw mechanism, it is possible to transact in the virtual BTC without the delay or expensive txfees. Then anybody that ends up having any of the BTC token would be able to withdraw actual BTC by redeeming the token. + +BTC -> deposit to special address -> receive token that represents BTC onchain +do onchain transactions with the BTC token +anybody who obtains the BTC token can redeem the token and get actual BTC in the withdraw address + +By bringing the operations onchain, it avoids the need for crosschain complications for each trade. The crosschain does still have to happen on the deposit and withdraw, but that is all. There is just one aspect that makes it not fully decentralized, which is the reliance on MofN multisig. However, with N trusted community members and a reasonable M value, it is not expected to be a big barrier. Since all operations are automated, the only trust needed is that M of the N multisig signers are running their nodes with the gateways dapp active and also that M of them wont collude to steal the funds locked in the multisig. In three years of operations, the MGW multigateway didnt have any incident of multisig signer misbehavior and it was only 2of3 multisig. + +How can the gatewaysCC work? First, it needs a dedicated token that can be used to represent the external crypto coin. In order to avoid any issues with misplaced tokens, it is simplest to require that 100% of all the tokens are all locked in the gatewaysCC address. We want to make it so that the only way the tokens can be released from the locked address is when a verified deposit is made. So, we also need a deposit address, which means there needs to be a set of pubkeys that control the deposit address. It turns out, we also need to post merkleroot data from the external coin so that the information is onchain to be able to validate the external deposit. Since we are already trusting the deposit address signers to safekeep the external coins via MofN multisig, trusting them to post the merkleroots doesnt increase the trust footprint needed. + +Now we have all the ingredients needed, a dedicated token, a set of multisig pubkeys and an oracle for merkleroots. + +gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s) + +With a gatewaysbind, a new gateway is defined. the pubkeys are for the custodians of the multisig funds and they also need to be posting merkleroots to the chain, so the oracle needs to be setup and funded and each of the signers needs to run the oraclefeed dapp. That posts each new merkleroot via oraclesdata and also responds to withdraw requests. + +The MofN pubkeys generates a deposit address and when funds are sent to that address along with a small amount to the claim address. With the txid from this external coin, along with the txproof and the rawtransaction, all is submitted with a gatewaysdeposit. This adds a special baton output which is a gateways CC output to invoke gateways validation and also prevents double claims by using the unspent status of the baton. + +gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount +gatewaysclaim bindtxid coin deposittxid destpub amount + +Once the gatewaysdeposit is validated, it can be claimed and now the token is sent to the claim address. A 1:1 pegging of the external crypto to the token is established. And as long as one of the deposit address signers is running the oraclefeed, then the deposit/claim process is fully automatic and under the control of the depositor. Nothing needs to be signed by any other party! Also by using the utxo from the deposittxid, double claims are prevented. + +On the withdraw side, the tokens are sent back to the address where the tokens are locked and this needs to create a redemption right that can only be used once. + +gatewayswithdraw bindtxid coin withdrawpub amount + + +And with a bit more magic in the oraclefeed, this is achieved. To be continued... + diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index d4b42f8e7..cfb3bd482 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -27,6 +27,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); +UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *unspentstr); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 915333aea..40db2882b 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -524,12 +524,29 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) } else if ( retstr != 0 ) { - fprintf(stderr,"get_rawtransaction.(%s) error.(%s)\n",acname,retstr); + fprintf(stderr,"get_rawtransaction.(%s) %s error.(%s)\n",refcoin,acname,retstr); free(retstr); } return(0); } +void importaddress(char *refcoin,char *acname,char *depositaddr) +{ + cJSON *retjson; char *retstr; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","")) != 0 ) + { + printf("importaddress.(%s)\n",jprint(retjson,0)); + free_json(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"importaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + return(0); +} + + void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bits256 cointxid) { char str[65],str2[65],*retstr; cJSON *retjson; @@ -546,17 +563,18 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit } } -int32_t get_gatewaysinfo(char *refcoin,char *acname,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) +int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) { - char *oracle,*retstr,*name; cJSON *retjson; + char *oracle,*retstr,*name,*deposit; cJSON *retjson; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","")) != 0 ) { if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) { - if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 && jint(retjson,"N") >= 1 ) + if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 && jint(retjson,"N") >= 1 && (deposit= jstr(retjson,"deposit")) != 0 ) { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); + strcpy(depositaddr,deposit); //printf("(%s)\n",jprint(retjson,0)); } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); } else printf("%s != %s\n",oracle,oraclestr); @@ -634,7 +652,7 @@ int32_t coinaddrexists(char *refcoin,char *acname,char *coinaddr) return(num); } -void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr,int32_t M,int32_t N) +void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t M,int32_t N) { // check queue to prevent duplicate // check KMD chain and mempool for txidaddr @@ -643,9 +661,9 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr,int3 /// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws - cJSON *retjson,*pending,*item; char str[65],*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; + cJSON *retjson,*pending,*item,*clijson; char str[65],*unspentstr,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; memset(&zeroid,0,sizeof(zeroid)); - if ( (retjson= get_gatewayspending("KMD",acname,oraclestxidstr)) != 0 ) + if ( (retjson= get_gatewayspending("KMD",acname,bindtxidstr)) != 0 ) { if ( jint(retjson,"queueflag") != 0 && (coinstr= jstr(retjson,"coin")) != 0 && strcmp(coinstr,refcoin) == 0 ) { @@ -681,14 +699,30 @@ void update_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr,int3 fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } } - else + else if ( (unspentstr= get_listunspent(refcoin,"",depositaddr)) != 0 ) { - // check msigmarkers - // iterate for sigs depth and find the deepest - // if not already a signer, add signature and post to next - // if first one, then create a rawtx and sign it, ie. depth 1 - // if fully signed, broadcast - // iterate txidaddr, find highest nValue! + if ( (clijson= get_komodocli("KMD",&retstr2,acname,"gatewaysmultisig",bindtxidstr,bits256_str(str,origtxid),unspentstr)) != 0 ) + { + if ( jint(clijson,"complete") != 0 ) + { + cointxid = komodobroadcast(refcoin,"",clijson2); + if ( bits256_nonz(cointxid) != 0 ) + { + fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); + processed++; + } + } + else if ( jint(clijson,"partialtx") != 0 ) + { + // 10000 + ith -> txidaddr + txid = komodobroadcast("KMD",acname,clijson2); + fprintf(stderr,"%s M.%d of N.%d partialtx %s sent\n",refcoin,M,N,bits256_str(str,txid)); + processed++; + } + free_json(clijson); + } + free(unspentstr); } } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); } @@ -762,7 +796,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 int32_t main(int32_t argc,char **argv) { - cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; + cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,depositaddr[64],hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; if ( argc < 6 ) { printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]\n"); @@ -798,12 +832,13 @@ int32_t main(int32_t argc,char **argv) printf("need to specify path to refcoin's cli as last argv\n"); exit(0); } - if ( get_gatewaysinfo("KMD",acname,&M,&N,bindtxidstr,refcoin,oraclestr) < 0 ) + if ( get_gatewaysinfo("KMD",acname,depositaddr,&M,&N,bindtxidstr,refcoin,oraclestr) < 0 ) { printf("cant find bindtxid.(%s)\n",bindtxidstr); exit(0); } - printf("set refcoin <- %s [%s] M.%d of N.%d\n",refcoin,REFCOIN_CLI,M,N); + importaddress(refcoin,"",depositaddr); + printf("set refcoin %s <- %s [%s] M.%d of N.%d\n",depositaddr,refcoin,REFCOIN_CLI,M,N); } if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index f3f872ebc..58855d253 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -695,7 +695,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui } if ( GetTransaction(deposittxid,tx,hashBlock,false) == 0 ) { - fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); + fprintf(stderr,"cant find deposittxid %s\n",uint256_str(str,bindtxid)); return(""); } if ( (depositamount= GatewaysDepositval(tx)) != amount ) @@ -710,7 +710,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui { if ( inputs > amount ) CCchange = (inputs - amount); - mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); + mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); // triggers EVAL_GATEWAYS validation mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,gatewayspk)); @@ -837,3 +837,61 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) return(result); } +std::string GatewaysMultisigUpdate(struct CCcontract_info *cp,int32_t &complete,int32_t &partialtx,CPubKey mypk,int32_t ith,uint256 withdrawtxid,uint8_t M,uint8_t N,char *unspentstr) +{ + CMutableTransaction mtx; cJSON *unspents; std::string hex,rawtx; CScript opret; uint64_t txfee = 10000; + complete = partialtx = 0; + if ( biggestrawtx == 0 ) + { + if ( (unspents= cJSON_Parse(unspentstr)) != 0 ) + { + rawtx = construct_rawtx(withdrawaddr,nValue,unspents); + free_json(unspents); + } + } + { + // iterate txidaddr, extract signatures! + // iterate for sigs depth and find the deepest + // if not already a signer, add signature and post to next + // if first one, then create a rawtx and sign it, ie. depth 1 + // if fully signed, broadcast + + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); + } + return(hex); +} + +UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *unspentstr) +{ + UniValue result(UniValue::VOBJ); std::string coin,hex; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk,mypk; struct CCcontract_info *cp,C; int32_t i,n,complete,partialtx; int64_t totalsupply; + cp = CCinit(&C,EVAL_GATEWAYS); + if ( txfee == 0 ) + txfee = 10000; + complete = partialtx = 0; + mypk = pubkey2pk(Mypubkey()); + Gatewayspk = GetUnspendable(cp,0); + _GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk); + if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) + { + depositaddr[0] = 0; + if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 1 && coin == refcoin ) + { + n = pubkeys.size(); + for (i=0; i send tx to refcoin withdraw complete + // partialtx:1 -> send partialsig to txidaddr, satoshis 10000 + ith pubkey + 1 + result.push_back(Pair("result","success")); + result.push_back(Pair("coin",refcoin)); + result.push_back(Pair("complete",complete)); + result.push_back(Pair("partialtx",partialtx)); + result.push_back(Pair("hex",hex)); + return(result); +} diff --git a/src/main.cpp b/src/main.cpp index 82f39cbda..0fc1f7bb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3375,6 +3375,15 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CBlock block; if (!ReadBlockFromDisk(block, pindexDelete,1)) return AbortNode(state, "Failed to read block"); + { + int32_t prevMoMheightp; uint256 notarizedhash,txid; + komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + if ( block.GetHash() == notarizedhash ) + { + fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->nHeight); + return(false); + } + } // Apply the block atomically to the chain state. uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor(); int64_t nStart = GetTimeMicros(); From a6a00b5ca262f9e68199c4fe5d941203dcfae95d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Sep 2018 21:47:43 -1100 Subject: [PATCH 030/749] Test --- src/cc/gateways.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 58855d253..df5c24e7c 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -841,14 +841,6 @@ std::string GatewaysMultisigUpdate(struct CCcontract_info *cp,int32_t &complete, { CMutableTransaction mtx; cJSON *unspents; std::string hex,rawtx; CScript opret; uint64_t txfee = 10000; complete = partialtx = 0; - if ( biggestrawtx == 0 ) - { - if ( (unspents= cJSON_Parse(unspentstr)) != 0 ) - { - rawtx = construct_rawtx(withdrawaddr,nValue,unspents); - free_json(unspents); - } - } { // iterate txidaddr, extract signatures! // iterate for sigs depth and find the deepest From 8ccb74fb8eec7ae6851e9791719df9da423e8d9b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Sep 2018 21:48:31 -1100 Subject: [PATCH 031/749] -p --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0fc1f7bb4..4edb4f604 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3376,7 +3376,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if (!ReadBlockFromDisk(block, pindexDelete,1)) return AbortNode(state, "Failed to read block"); { - int32_t prevMoMheightp; uint256 notarizedhash,txid; + int32_t prevMoMheight; uint256 notarizedhash,txid; komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); if ( block.GetHash() == notarizedhash ) { From 119f1c1e0c342c9c349134c4afec34a01f93aad9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 01:02:32 -1100 Subject: [PATCH 032/749] Asset chain notarization check --- src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ce61a0e35..21c803754 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3370,6 +3370,15 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CBlock block; if (!ReadBlockFromDisk(block, pindexDelete,1)) return AbortNode(state, "Failed to read block"); + { + int32_t prevMoMheight; uint256 notarizedhash,txid; + komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + if ( block.GetHash() == notarizedhash ) + { + fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->nHeight); + return(false); + } + } // Apply the block atomically to the chain state. uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor(); int64_t nStart = GetTimeMicros(); From 6b52965769535c6baf8d28633c4e26362b23c848 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 01:03:14 -1100 Subject: [PATCH 033/749] Stronger check for asset chain notarizations --- src/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ce61a0e35..21c803754 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3370,6 +3370,15 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CBlock block; if (!ReadBlockFromDisk(block, pindexDelete,1)) return AbortNode(state, "Failed to read block"); + { + int32_t prevMoMheight; uint256 notarizedhash,txid; + komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + if ( block.GetHash() == notarizedhash ) + { + fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->nHeight); + return(false); + } + } // Apply the block atomically to the chain state. uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor(); int64_t nStart = GetTimeMicros(); From 12832b1d22add227ccd6bd8a72732d519dc6e64d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 01:04:30 -1100 Subject: [PATCH 034/749] notarization check for asset chains --- resolve.sh | 12 ++++++++++++ src/main.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100755 resolve.sh diff --git a/resolve.sh b/resolve.sh new file mode 100755 index 000000000..548e71dee --- /dev/null +++ b/resolve.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +for f in $(git diff --name-only --diff-filter=U | cat); do + echo "Resolve conflict in $f ..." + git checkout --theirs $f +done + +for f in $(git diff --name-only --diff-filter=U | cat); do + echo "Adding file $f ..." + git add $f +done + diff --git a/src/main.cpp b/src/main.cpp index e25d6419b..f93cab2f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3367,6 +3367,16 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CBlock block; if (!ReadBlockFromDisk(block, pindexDelete,1)) return AbortNode(state, "Failed to read block"); + if ( ASSETCHAINS_SYMBOL[0] != 0 || pindexDelete->nHeight > 1400000 ) + { + int32_t prevMoMheight; uint256 notarizedhash,txid; + komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + if ( block.GetHash() == notarizedhash ) + { + fprintf(stderr,"DisconnectTip trying to disconnect notarized block at ht.%d\n",(int32_t)pindexDelete->nHeight); + return(false); + } + } // Apply the block atomically to the chain state. uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor(); int64_t nStart = GetTimeMicros(); From 7fccea1dab7299ea0c715d8a8be01c393300558d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 03:08:28 -1100 Subject: [PATCH 035/749] Msig suppport --- src/cc/CCGateways.h | 2 +- src/cc/dapps/oraclefeed.c | 155 ++++++++++++++++++++++++++++++++------ src/cc/gateways.cpp | 30 +------- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 20 +++++ 6 files changed, 159 insertions(+), 50 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index cfb3bd482..5d8e98228 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -27,7 +27,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); -UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *unspentstr); +UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 40db2882b..be7b14b81 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -546,6 +546,109 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) return(0); } +cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required) +{ + cJSON *vin,*item,*vins = cJSON_CreateArray(); int32_t i,n,v; int64_t satoshis; bits256 txid; + *totalp = 0; + if ( (n= cJSON_GetArraySize(unspents)) > 0 ) + { + for (i=0; i= required ) + break; + } + } + } + return(vins); +} + +char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signeraddr,char *withdrawaddr,int64_t satoshis) +{ + char *retstr,*retstr2,array[128],*txstr = 0; cJSON *retjson2,*retjson,*vins,*vouts; int64_t txfee,total,change = 0; + if ( strcmp(refcoin,"BTC") == 0 ) + txfee = 20000; + else txfee = 10000; + if ( satoshis < txfee ) + { + printf("createmultisig satoshis %.8f < txfee %.8f\n",(double)satoshis/SATOSHIDEN,(double)txfee/SATOSHIS); + return(0); + } + satoshis -= txfee; + sprintf(array,"[\"%s\"]",depositaddr); + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent",1,99999999,array,"")) != 0 ) + { + //createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} + if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 ) + { + if ( total >= satoshis ) + { + vouts = cJSON_CreatObject(); + jaddstr(vouts,withdrawaddr,(double)satoshis/SATOSHIDEN); + if ( total > satoshis+txfee ) + { + change = (total - satoshis); + jaddstr(vouts,depositaddr,(double)change/SATOSHIDEN); + } + if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",jprint(vins,0),jprint(vouts,0),"","")) != 0 ) + { + printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); + free_json(retjson2); + } + else if ( txstr == 0 ) + printf("createmultisig: null txstr and JSON2\n"); + free_json(vins); + free_json(vouts); + } + } + } + else if ( retstr != 0 ) + { + printf("createmultisig: unexpected null JSON, retstr.(%s)\n",retstr); + free(retstr); + } + else printf("createmultisig: null retstr and JSON\n"); + return(txstr); +} + +cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx) +{ + char *retstr,*hexstr; cJSON *retjson; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 ) + { + if ( jint(retjson,"complete") != 0 ) + return(retjson); + else if ( (hexstr= jstr(retjson,"hex")) != 0 && strlen(hexstr) > strlen(rawtx) ) + { + jadd(retjson,"partialtx",1)' + return(retjson); + } + free_json(retjson); + } + return(0); +} + +char *get_gatewaysmultisig(char *refcoin,char *acname,char *bindtxidstr,char *withtxidstr,char *txidaddr) +{ + char *retstr,*hexstr,*hex=0; cJSON *retjson; + if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",bindtxidstr,refcoin,withtxidstr,txidstr)) != 0 ) + { + if ( (hexstr= jstr(retjson,"hex")) != 0 ) + hex = clonestr(hexstr); + free_json(retjson); + } + return(hex); +} void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bits256 cointxid) { @@ -661,7 +764,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t /// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws - cJSON *retjson,*pending,*item,*clijson; char str[65],*unspentstr,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; + cJSON *retjson,*pending,*item,*clijson; char str[65],*rawtx,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; memset(&zeroid,0,sizeof(zeroid)); if ( (retjson= get_gatewayspending("KMD",acname,bindtxidstr)) != 0 ) { @@ -699,32 +802,38 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t fprintf(stderr,"ERROR withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); } } - else if ( (unspentstr= get_listunspent(refcoin,"",depositaddr)) != 0 ) + else { - if ( (clijson= get_komodocli("KMD",&retstr2,acname,"gatewaysmultisig",bindtxidstr,bits256_str(str,origtxid),unspentstr)) != 0 ) + if ( (rawtx= get_gatewaysmultisig(refcoin,acname,bindtxidstr,bits256_str(str,origtxid),txidaddr)) == 0 ) { - if ( jint(clijson,"complete") != 0 ) - { - cointxid = komodobroadcast(refcoin,"",clijson2); - if ( bits256_nonz(cointxid) != 0 ) - { - fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); - processed++; - } - } - else if ( jint(clijson,"partialtx") != 0 ) - { - // 10000 + ith -> txidaddr - txid = komodobroadcast("KMD",acname,clijson2); - fprintf(stderr,"%s M.%d of N.%d partialtx %s sent\n",refcoin,M,N,bits256_str(str,txid)); - processed++; - } - free_json(clijson); + rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis); } - free(unspentstr); + if ( rawtx != 0 ) + { + if ( (clijson= addmultisignature(refcoin,"",signeraddr,rawtx)) != 0 ) + { + if ( jint(clijson,"complete") != 0 ) + { + cointxid = komodobroadcast(refcoin,"",clijson); + if ( bits256_nonz(cointxid) != 0 ) + { + fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); + } + } + else if ( jint(clijson,"partialtx") != 0 ) + { + // 10000 + ith -> txidaddr + txid = komodobroadcast("KMD",acname,clijson); + fprintf(stderr,"%s M.%d of N.%d partialtx %s sent\n",refcoin,M,N,bits256_str(str,txid)); + } + free_json(clijson); + } + processed++; + free(rawtx); + } else fprintf(stderr,"couldnt create msig rawtx\n"); } - } else fprintf(stderr,"error sending %s txidaddr.%s -> %s exists.%d\n",acname,txidaddr,bits256_str(str,txid),coinaddrexists(refcoin,acname,txidaddr)); + } } else if ( retval > 0 ) { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index df5c24e7c..6a4f60413 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -837,23 +837,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) return(result); } -std::string GatewaysMultisigUpdate(struct CCcontract_info *cp,int32_t &complete,int32_t &partialtx,CPubKey mypk,int32_t ith,uint256 withdrawtxid,uint8_t M,uint8_t N,char *unspentstr) -{ - CMutableTransaction mtx; cJSON *unspents; std::string hex,rawtx; CScript opret; uint64_t txfee = 10000; - complete = partialtx = 0; - { - // iterate txidaddr, extract signatures! - // iterate for sigs depth and find the deepest - // if not already a signer, add signature and post to next - // if first one, then create a rawtx and sign it, ie. depth 1 - // if fully signed, broadcast - - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); - } - return(hex); -} - -UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *unspentstr) +std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr) { UniValue result(UniValue::VOBJ); std::string coin,hex; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk,mypk; struct CCcontract_info *cp,C; int32_t i,n,complete,partialtx; int64_t totalsupply; cp = CCinit(&C,EVAL_GATEWAYS); @@ -868,22 +852,16 @@ UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,ui depositaddr[0] = 0; if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 1 && coin == refcoin ) { + // need a decentralized way to add signatures to msig tx n = pubkeys.size(); for (i=0; i send tx to refcoin withdraw complete - // partialtx:1 -> send partialsig to txidaddr, satoshis 10000 + ith pubkey + 1 - result.push_back(Pair("result","success")); - result.push_back(Pair("coin",refcoin)); - result.push_back(Pair("complete",complete)); - result.push_back(Pair("partialtx",partialtx)); - result.push_back(Pair("hex",hex)); - return(result); + return(hex); } diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index c4c8d378b..d268ed7fa 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -418,6 +418,7 @@ static const CRPCCommand vRPCCommands[] = { "gateways", "gatewaysclaim", &gatewaysclaim, true }, { "gateways", "gatewayswithdraw", &gatewayswithdraw, true }, { "gateways", "gatewayspending", &gatewayspending, true }, + { "gateways", "gatewaysmultisig", &gatewaysmultisig, true }, { "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true }, /* dice */ diff --git a/src/rpcserver.h b/src/rpcserver.h index a697ee4ee..1ebff82ef 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -244,6 +244,7 @@ extern UniValue gatewaysclaim(const UniValue& params, bool fHelp); extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp); extern UniValue gatewayspending(const UniValue& params, bool fHelp); extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp); +extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp); extern UniValue channelsinfo(const UniValue& params, bool fHelp); extern UniValue channelsbind(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ef5b33ab5..e0afbb982 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5543,6 +5543,26 @@ UniValue gatewayspending(const UniValue& params, bool fHelp) return(GatewaysPendingWithdraws(bindtxid,coin)); } +UniValue gatewaysmultisig(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 bindtxid,withtxid; std::string coin,hex; char *txidaddr; + if ( fHelp || params.size() != 2 ) + throw runtime_error("gatewaysmultisig bindtxid coin withtxid txidaddr\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + bindtxid = Parseuint256((char *)params[0].get_str().c_str()); + coin = params[1].get_str(); + withtxid = Parseuint256((char *)params[2].get_str().c_str()); + txidaddr = params[3].get_str().c_str(); + hex = GatewaysMultisig(0,coin,bindtxid,withdrawtxid,txidaddr); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex",hex)); + } else ERR_RESULT("couldnt gatewaysmultisig"); + return(result); +} + UniValue oracleslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 791ad592f1608180788e4d181c37ab37097faeed Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 03:09:39 -1100 Subject: [PATCH 036/749] Test --- src/cc/CCGateways.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 5d8e98228..b584ba5d0 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -27,7 +27,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); -UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr); +std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); From 4f80a29cc484443b3daa92092a48d9a094a9fae3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 03:12:56 -1100 Subject: [PATCH 037/749] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e0afbb982..57c9fabc1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5553,8 +5553,8 @@ UniValue gatewaysmultisig(const UniValue& params, bool fHelp) bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withtxid = Parseuint256((char *)params[2].get_str().c_str()); - txidaddr = params[3].get_str().c_str(); - hex = GatewaysMultisig(0,coin,bindtxid,withdrawtxid,txidaddr); + txidaddr = (char *)params[3].get_str().c_str(); + hex = GatewaysMultisig(0,coin,bindtxid,withtxid,txidaddr); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From 9648870fdcdc1383567e3dac268059447b794a82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 03:16:04 -1100 Subject: [PATCH 038/749] Sync gateways --- src/cc/gateways.cpp | 100 +++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 61 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index df5c24e7c..23b600930 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -21,7 +21,7 @@ debug multisig and do partial signing validation -string oracles + string oracles */ /* @@ -58,7 +58,7 @@ string oracles 5. Now a gatewaysbind can bind an external coin to an asset, along with the oracle for the merkleroots. the txid from the bind is used in most of the other gateways CC calls usage: - ./c tokencreate KMD 1000000 KMD_equivalent_token_for_gatewaysCC + ./c tokencreate KMD 1000000 KMD_equivalent_token_for_gatewaysCC a7398a8748354dd0a3f8d07d70e65294928ecc3674674bb2d9483011ccaa9a7a transfer to gateways pubkey: 03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40 RDMqGyREkP1Gwub1Nr5Ye8a325LGZsWBCb @@ -94,7 +94,7 @@ string oracles "remaining": "1000000.00000000", "issued": "0.00000000" } - + To make a gateway deposit, send the funds to the "deposit" address, along with any amount to the same pubkey address you want to get the assetized KMD to appear in. 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 pubkey for RFpxgqff7FDHFuHa3jSX5NzqqWCcELz8ha @@ -106,16 +106,16 @@ string oracles ./komodo-cli getrawtransaction bc41a00e429db741c3199f17546a48012fd3b7eea45dfc6bc2f5228278133009 010000000149964cdcd17fe9b1cae4d0f3b5f5db301d9b4f54099fdf4d34498df281757094010000006a4730440220594f3a630dd73c123f44621aa8bb9968ab86734833453dd479af6d79ae6f584202207bb5e35f13b337ccc8a88d9a006c8c5ddb016c0a6f4f2dc44357a8128623d85d01210223154bf53cd3a75e64d86697070d6437c8f0010a09c1df35b659e31ce3d79b5dffffffff0310270000000000001976a91447d2e323a14b0c3be08698aa46a9b91489b189d688ac701de52d000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688acb0a86a00000000001976a914f9a9daf5519dae38b8b61d945f075da895df441d88ace18d965b - + gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount -./komodo-cli -ac_name=AT5 gatewaysdeposit e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e 1003776 KMD bc41a00e429db741c3199f17546a48012fd3b7eea45dfc6bc2f5228278133009 0 010000000149964cdcd17fe9b1cae4d0f3b5f5db301d9b4f54099fdf4d34498df281757094010000006a4730440220594f3a630dd73c123f44621aa8bb9968ab86734833453dd479af6d79ae6f584202207bb5e35f13b337ccc8a88d9a006c8c5ddb016c0a6f4f2dc44357a8128623d85d01210223154bf53cd3a75e64d86697070d6437c8f0010a09c1df35b659e31ce3d79b5dffffffff0310270000000000001976a91447d2e323a14b0c3be08698aa46a9b91489b189d688ac701de52d000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688acb0a86a00000000001976a914f9a9daf5519dae38b8b61d945f075da895df441d88ace18d965b 04000000232524ea04b54489eb222f8b3f566ed35504e3050488a63f0ab7b1c2030000007f91615f04835822bf6984a56482aeeb11d03814352eca9afc0a20192fdcae900000000000000000000000000000000000000000000000000000000000000000268e965ba608071d0800038e16762900000000000000000000000000000000000000000042008dd6fd4005016b4292b05df6dfd316c458c53e28fb2befb96e4870a40c6c04e733d75d8a7a18cce34fe326005efdc403bfa4644e30eeafdaeff34419edc591299e6cc5933cb2eeecbab5c4dfe97cd413b75215999a3dd02b540373581e81d8512bff1640590a6b4da4aaa9b8adc0102c38ca0022daed997b53ed192ba326e212fba5e505ce29e3ad149cef7f48d0e00948a1acd81731d84008760759211eb4abbc7b037939a7964182edb59cf9065357e864188ee5fc7316e8796963036bb99eeb9f06c95d64f78749ecec7181c12eb5d83a3b9b1c1e8a0aae9a20ce04a250b28216620bfc99bb81a6de4db80b93a5aea916de97c1a272e26644abdd683f19c5e3174a2e4513ed767d8f11a4c3074295f697839c5d9139676a813451cc7da38f68cbae5d990a79075f98903233ca04fe1b4b099e433585e5adcc45d41d54a9c648179297359c75950a5e574f13f70b728bbbf552770256315cd0a00139d6ab6934cb5ed70a4fc01a92611b096dd0028f17f4cc687b75f37dca530aa47a18321c50528dbd9272eabb3e13a87021a05918a6d2627e2caba6d7cf1a9f0b831ea3337b9a6af92746d83140078d60c72b6beacf91c9e68a34cee209e08670be1d17ff8d80b7a2285b1325461a2e33f2ee675593f1900e066a5d212615cd8da18749b0e684eee73edcc9031709be715b889c6d015cf4bd4ad5ab7e21bd3492c208930a54d353ef36a437f507ead38855633c1b88d060d9e4221ca8ce2f698e8a6ae0d41e9ace3cbd401f1e0f07650e9c126d4ef20278c8be6e85c7637513643f8d02d7ad64c09da11c16429d60e5160c345844b8158ece62794e8ad280d4e4664150e74978609ece431e51a9f9e1ce8aa49c16f36c7fd12b71acc42d893e18476b8b1e144a8175519612efc93e0aecc61f3b21212c958b0e2331d76aaa62faf11a58fe2bd91ab9ab01b906406c9bbc02df2a106e67182aae0a20b538bf19f09c57f9de5e198ba254580fb1b11e22ad526550093420cb7c68628d4c3ad329c8acc6e219093d277810ed016b6099b7e3781de412a22dacedaa2acf29e8062debcd85c7b9529a20b2782a2470763ac27cf89611a527d43ac89b8063ffb93b6ed993425194f8ee821a8493a563072c896f9584f95db28e3f2fc5fb4a6f3c39d615cd563641717cd50afb73ed3989cbf504b2043882993ce9575f56402534173b1396fbc13df80920b46788ae340ad5a91f25177cc74aa69024d76f56166199d2e4d50a053555256c4e3137ea1cee1130e916a88b6ee5cf2c85652fb8824d5dacfa485e3ef6190591ac0c2fcacc4fc7deb65aca4b0b89b76e35a46b0627e2e967cc63a5d606a984c8e63eabb98fde3e69114340ae524c974cb936e57690e98a7a74533f6f7d1d0496976496b54d14a8163efb32b70dfbb79d80a3022c4f53571c08bf044270565716b435084376714b224ab23e9817c05af8223723afc0577af5c8fc28f71036ca82528aaa4ca9bcd18a50e25d2a528f183d3a2074d968d170876d8dce434c5937261b55173ab87e03d5632ca0834fdc5387c15ab3a17d75c0f274004f289ff1bf7d14e97fdf4172eb49adfb418cc2f4794806ae7c0111c97df4d65d38679ec93fea3ef738ed565e8906a8fe1861cafe3938c772fedcfab40159938e06ef414fd299f2355c6d3369bc1bd3c4db64ce205f0a1b70a40030f505b736e28230de82e97776b5ee7b10708bb3020d28cec7a8e124549ec80c547ac4e7b52bf397c72bcfce30820554ab8fb4d1f73b209bc32a0e7e878843cdbf5f01222728ccea7e6ab7cb5e3fee3234f5b85d1985f91492f6ceaa6454a658dab5074f163ce26ed753137fa61c940679de13bd7b212cd3cf2b334f5201cecbc7473342bd7a239e09169bccd56d03000000037a9068df0625e548e71263c8361b4e904c998378f6b9e32729c3f19b10ad752e093013788222f5c26bfc5da4eeb7d32f01486a54179f19c341b79d420ea041bc8878d22fad4692b2d609c3cf190903874d3682a714c7483518c9392e07c25035010b 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 + ./komodo-cli -ac_name=AT5 gatewaysdeposit e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e 1003776 KMD bc41a00e429db741c3199f17546a48012fd3b7eea45dfc6bc2f5228278133009 0 010000000149964cdcd17fe9b1cae4d0f3b5f5db301d9b4f54099fdf4d34498df281757094010000006a4730440220594f3a630dd73c123f44621aa8bb9968ab86734833453dd479af6d79ae6f584202207bb5e35f13b337ccc8a88d9a006c8c5ddb016c0a6f4f2dc44357a8128623d85d01210223154bf53cd3a75e64d86697070d6437c8f0010a09c1df35b659e31ce3d79b5dffffffff0310270000000000001976a91447d2e323a14b0c3be08698aa46a9b91489b189d688ac701de52d000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688acb0a86a00000000001976a914f9a9daf5519dae38b8b61d945f075da895df441d88ace18d965b 04000000232524ea04b54489eb222f8b3f566ed35504e3050488a63f0ab7b1c2030000007f91615f04835822bf6984a56482aeeb11d03814352eca9afc0a20192fdcae900000000000000000000000000000000000000000000000000000000000000000268e965ba608071d0800038e16762900000000000000000000000000000000000000000042008dd6fd4005016b4292b05df6dfd316c458c53e28fb2befb96e4870a40c6c04e733d75d8a7a18cce34fe326005efdc403bfa4644e30eeafdaeff34419edc591299e6cc5933cb2eeecbab5c4dfe97cd413b75215999a3dd02b540373581e81d8512bff1640590a6b4da4aaa9b8adc0102c38ca0022daed997b53ed192ba326e212fba5e505ce29e3ad149cef7f48d0e00948a1acd81731d84008760759211eb4abbc7b037939a7964182edb59cf9065357e864188ee5fc7316e8796963036bb99eeb9f06c95d64f78749ecec7181c12eb5d83a3b9b1c1e8a0aae9a20ce04a250b28216620bfc99bb81a6de4db80b93a5aea916de97c1a272e26644abdd683f19c5e3174a2e4513ed767d8f11a4c3074295f697839c5d9139676a813451cc7da38f68cbae5d990a79075f98903233ca04fe1b4b099e433585e5adcc45d41d54a9c648179297359c75950a5e574f13f70b728bbbf552770256315cd0a00139d6ab6934cb5ed70a4fc01a92611b096dd0028f17f4cc687b75f37dca530aa47a18321c50528dbd9272eabb3e13a87021a05918a6d2627e2caba6d7cf1a9f0b831ea3337b9a6af92746d83140078d60c72b6beacf91c9e68a34cee209e08670be1d17ff8d80b7a2285b1325461a2e33f2ee675593f1900e066a5d212615cd8da18749b0e684eee73edcc9031709be715b889c6d015cf4bd4ad5ab7e21bd3492c208930a54d353ef36a437f507ead38855633c1b88d060d9e4221ca8ce2f698e8a6ae0d41e9ace3cbd401f1e0f07650e9c126d4ef20278c8be6e85c7637513643f8d02d7ad64c09da11c16429d60e5160c345844b8158ece62794e8ad280d4e4664150e74978609ece431e51a9f9e1ce8aa49c16f36c7fd12b71acc42d893e18476b8b1e144a8175519612efc93e0aecc61f3b21212c958b0e2331d76aaa62faf11a58fe2bd91ab9ab01b906406c9bbc02df2a106e67182aae0a20b538bf19f09c57f9de5e198ba254580fb1b11e22ad526550093420cb7c68628d4c3ad329c8acc6e219093d277810ed016b6099b7e3781de412a22dacedaa2acf29e8062debcd85c7b9529a20b2782a2470763ac27cf89611a527d43ac89b8063ffb93b6ed993425194f8ee821a8493a563072c896f9584f95db28e3f2fc5fb4a6f3c39d615cd563641717cd50afb73ed3989cbf504b2043882993ce9575f56402534173b1396fbc13df80920b46788ae340ad5a91f25177cc74aa69024d76f56166199d2e4d50a053555256c4e3137ea1cee1130e916a88b6ee5cf2c85652fb8824d5dacfa485e3ef6190591ac0c2fcacc4fc7deb65aca4b0b89b76e35a46b0627e2e967cc63a5d606a984c8e63eabb98fde3e69114340ae524c974cb936e57690e98a7a74533f6f7d1d0496976496b54d14a8163efb32b70dfbb79d80a3022c4f53571c08bf044270565716b435084376714b224ab23e9817c05af8223723afc0577af5c8fc28f71036ca82528aaa4ca9bcd18a50e25d2a528f183d3a2074d968d170876d8dce434c5937261b55173ab87e03d5632ca0834fdc5387c15ab3a17d75c0f274004f289ff1bf7d14e97fdf4172eb49adfb418cc2f4794806ae7c0111c97df4d65d38679ec93fea3ef738ed565e8906a8fe1861cafe3938c772fedcfab40159938e06ef414fd299f2355c6d3369bc1bd3c4db64ce205f0a1b70a40030f505b736e28230de82e97776b5ee7b10708bb3020d28cec7a8e124549ec80c547ac4e7b52bf397c72bcfce30820554ab8fb4d1f73b209bc32a0e7e878843cdbf5f01222728ccea7e6ab7cb5e3fee3234f5b85d1985f91492f6ceaa6454a658dab5074f163ce26ed753137fa61c940679de13bd7b212cd3cf2b334f5201cecbc7473342bd7a239e09169bccd56d03000000037a9068df0625e548e71263c8361b4e904c998378f6b9e32729c3f19b10ad752e093013788222f5c26bfc5da4eeb7d32f01486a54179f19c341b79d420ea041bc8878d22fad4692b2d609c3cf190903874d3682a714c7483518c9392e07c25035010b 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 -> 9d80ea79a65aaa0d464f8b762356fa01047e16e9793505a22ca04559f81a6eb6 to get the merkleroots onchain, from the multisig signers nodes run the oraclefeed program with acname oracletxid pubkey Ihh ./oraclefeed AT5 1f1aefcca2bdea8196cfd77337fb21de22d200ddea977c2f9e8742c55829d808 02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92 Ihh gatewaysclaim bindtxid coin deposittxid destpub amount -./c gatewaysclaim e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD 9d80ea79a65aaa0d464f8b762356fa01047e16e9793505a22ca04559f81a6eb6 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 + ./c gatewaysclaim e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD 9d80ea79a65aaa0d464f8b762356fa01047e16e9793505a22ca04559f81a6eb6 0223d114dededb04f253816d6ad0ce78dd08c617c94ce3c53bf50dc74a5157bef8 7.6999 now the asset is in the pubkey's asset address! it can be used, traded freely and any node who has the asset can do a gatewayswithdraw @@ -126,11 +126,11 @@ string oracles Now there is a withdraw pending, so it needs to be processed by the signing nodes on the KMD side - gatewayspending bindtxid coin + gatewayspending bindtxid coin gatewayspending will display all pending withdraws and if it is done on one of the msigpubkeys, then it will queue it for processing ./c gatewayspending e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD -*/ + */ int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) @@ -283,32 +283,32 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp /*int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) -{ - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; - std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( (nValue= IsGatewaysvout(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; - } - } - } - return(totalinputs); -}*/ + { + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + // no need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( (nValue= IsGatewaysvout(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; + } + } + } + return(totalinputs); + }*/ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { @@ -521,7 +521,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) { if ( oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()) == sizeof(hash) && - oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) + oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) { txid = batontxid; return(mhash); @@ -837,23 +837,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) return(result); } -std::string GatewaysMultisigUpdate(struct CCcontract_info *cp,int32_t &complete,int32_t &partialtx,CPubKey mypk,int32_t ith,uint256 withdrawtxid,uint8_t M,uint8_t N,char *unspentstr) -{ - CMutableTransaction mtx; cJSON *unspents; std::string hex,rawtx; CScript opret; uint64_t txfee = 10000; - complete = partialtx = 0; - { - // iterate txidaddr, extract signatures! - // iterate for sigs depth and find the deepest - // if not already a signer, add signature and post to next - // if first one, then create a rawtx and sign it, ie. depth 1 - // if fully signed, broadcast - - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); - } - return(hex); -} - -UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *unspentstr) +std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr) { UniValue result(UniValue::VOBJ); std::string coin,hex; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk,mypk; struct CCcontract_info *cp,C; int32_t i,n,complete,partialtx; int64_t totalsupply; cp = CCinit(&C,EVAL_GATEWAYS); @@ -868,22 +852,16 @@ UniValue GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,ui depositaddr[0] = 0; if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 1 && coin == refcoin ) { + // need a decentralized way to add signatures to msig tx n = pubkeys.size(); for (i=0; i send tx to refcoin withdraw complete - // partialtx:1 -> send partialsig to txidaddr, satoshis 10000 + ith pubkey + 1 - result.push_back(Pair("result","success")); - result.push_back(Pair("coin",refcoin)); - result.push_back(Pair("complete",complete)); - result.push_back(Pair("partialtx",partialtx)); - result.push_back(Pair("hex",hex)); - return(result); + return(hex); } From c5164b3c7bd21c7dd5e6b476e33e40478811c45c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 17 Sep 2018 05:58:07 -1100 Subject: [PATCH 039/749] Skip human help if longer chain is invalid due to notarization --- src/main.cpp | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4edb4f604..c99f316f1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3626,23 +3626,34 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->nHeight - (pindexFork ? pindexFork->nHeight : -1) : 0; static_assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); - if (reorgLength > MAX_REORG_LENGTH) { - auto msg = strprintf(_( - "A block chain reorganization has been detected that would roll back %d blocks! " - "This is larger than the maximum of %d blocks, and so the node is shutting down for your safety." - ), reorgLength, MAX_REORG_LENGTH) + "\n\n" + - _("Reorganization details") + ":\n" + - "- " + strprintf(_("Current tip: %s, height %d, work %s"), - pindexOldTip->phashBlock->GetHex(), pindexOldTip->nHeight, pindexOldTip->nChainWork.GetHex()) + "\n" + - "- " + strprintf(_("New tip: %s, height %d, work %s"), - pindexMostWork->phashBlock->GetHex(), pindexMostWork->nHeight, pindexMostWork->nChainWork.GetHex()) + "\n" + - "- " + strprintf(_("Fork point: %s %s, height %d"), - ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + - _("Please help, human!"); - LogPrintf("*** %s\n", msg); - uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); - StartShutdown(); - return false; + if (reorgLength > MAX_REORG_LENGTH) + { + int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + if ( pindexFork->nHeight < notarizedht ) + { + fprintf(stderr,"pindexFork->nHeight.%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->nHeight,notarizedht); + pindexFork = pindexOldTip; + } + else + { + auto msg = strprintf(_( + "A block chain reorganization has been detected that would roll back %d blocks! " + "This is larger than the maximum of %d blocks, and so the node is shutting down for your safety." + ), reorgLength, MAX_REORG_LENGTH) + "\n\n" + + _("Reorganization details") + ":\n" + + "- " + strprintf(_("Current tip: %s, height %d, work %s"), + pindexOldTip->phashBlock->GetHex(), pindexOldTip->nHeight, pindexOldTip->nChainWork.GetHex()) + "\n" + + "- " + strprintf(_("New tip: %s, height %d, work %s"), + pindexMostWork->phashBlock->GetHex(), pindexMostWork->nHeight, pindexMostWork->nChainWork.GetHex()) + "\n" + + "- " + strprintf(_("Fork point: %s %s, height %d"), + ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + + _("Please help, human!"); + LogPrintf("*** %s\n", msg); + uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); + StartShutdown(); + return false; + } } // Disconnect active blocks which are no longer in the best chain. From 403b69675c0691138de17e0fe1c9fd219c099bca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Sep 2018 03:48:44 -1100 Subject: [PATCH 040/749] 1of2 CC --- src/cc/prices.cpp | 55 ++++++++++++++++++++++++---------------- src/wallet/rpcwallet.cpp | 5 ++++ 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1465c6ee6..40a777bcf 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -28,15 +28,31 @@ Funds work like with dice, ie. there is a Prices plan that traders bet against. - PricesOpen -> oracletxid start with 'L' price, leverage, amount - funds are locked into global CC address + PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + + PricesBet -> oracletxid start with 'L', leverage, funding, direction + funds are locked into global CC address it can be closed at anytime by the trader for cash settlement the house account can close it if rekt Implementation Notes: In order to eliminate the need for worrying about sybil attacks, each prices plan would be able to specific pubkey(s?) for whitelisted publishers. It would be possible to have a non-whitelisted plan that would use 50% correlation between publishers. - delta neutral balancing of risk exposure + delta neutral balancing of riskexposure: fabs(long exposure - short exposure) + bet +B at leverage L + absval(sum(+BLi) - sum(-Bli)) + + validate: update riskexposure and it needs to be <= funds + + PricesProfits: limit withdraw to funds in excess of riskexposure + PricesFinish: payout (if winning) and update riskexposure + need long/short exposure assets + + exposure tokens + funding -> 1of2 CC global CC address and dealer address + pricebet -> user funds to 1of2 address. exposuretoken to exposure address + pricewin -> winnings from dealer funds, exposure token back to 1of2 address + priceloss -> exposuretoken back to 1of2 address + */ @@ -211,34 +227,29 @@ UniValue PricesList() return(result); } -std::string PricesCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) +// PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + +std::string PricesCreateFunding(uint64_t txfee,uint256 oracletxid,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,CPubKey pubkeys) { - CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,pricepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) + CMutableTransaction mtx; CPubKey mypk,pricespk; struct CCcontract_info *cp,C; + if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( funds < 100*COIN ) + cp = CCinit(&C,EVAL_REWARDS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + // verify long and short assets + if ( AddNormalinputs(mtx,mypk,funding+3*txfee,60) > 0 ) { - CCerror = "price plan needs at least 100 coins"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - memset(&zero,0,sizeof(zero)); - if ( (cp= Pricesinit(fundingPubKey,zero,&C,planstr,txfee,mypk,pricepk,sbits,a,b,c,d)) == 0 ) - { - CCerror = "Priceinit error in create funding"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - if ( AddNormalinputs(mtx,mypk,funds+3*txfee,60) > 0 ) - { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,pricepk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,funding,pricepk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricepk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',sbits,minbet,maxbet,maxodds,timeoutblocks))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',oracletxid,longtoken,shorttoken,funding,mode,maxleverage,pubkeys))); } CCerror = "cant find enough inputs"; fprintf(stderr,"%s\n", CCerror.c_str() ); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 57c9fabc1..48e1d75f3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4934,7 +4934,12 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); if ( params.size() == 1 ) + { pubkey = ParseHex(params[0].get_str().c_str()); + char destaddr[64]; + GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); + fprintf(stderr,"1of2 CC %s\n",destaddr); + } return(CCaddress(cp,(char *)"Prices",pubkey)); } From 08d66385b3d1802aee063ab3696846ec7f4575e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Sep 2018 04:13:43 -1100 Subject: [PATCH 041/749] Test --- src/cc/prices.cpp | 8 ++++---- src/wallet/rpcwallet.cpp | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 40a777bcf..1db14d1b9 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -48,10 +48,10 @@ PricesFinish: payout (if winning) and update riskexposure need long/short exposure assets - exposure tokens + funding -> 1of2 CC global CC address and dealer address - pricebet -> user funds to 1of2 address. exposuretoken to exposure address - pricewin -> winnings from dealer funds, exposure token back to 1of2 address - priceloss -> exposuretoken back to 1of2 address + funding -> 1of2 CC global CC address and dealer address, exposure tokens to global 1of2 assets CC address + pricebet -> user funds and exposure token to 1of2 address. + pricewin -> winnings from dealer funds, exposure token back to global address + priceloss -> exposuretoken back to global address */ diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 48e1d75f3..44965db73 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4939,6 +4939,9 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) char destaddr[64]; GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); fprintf(stderr,"1of2 CC %s\n",destaddr); + cp->evalcode = EVAL_ASSETS; + GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); + fprintf(stderr,"1of2 assets CC %s\n",destaddr); } return(CCaddress(cp,(char *)"Prices",pubkey)); } From f44cd67e8298122cf4dea84cff3685696553fb74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:04:47 -1100 Subject: [PATCH 042/749] Prices stub --- src/cc/CCPrices.h | 9 +- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 48 ++++- src/cc/CCassetstx.cpp | 4 +- src/cc/CCinclude.h | 4 +- src/cc/CCtx.cpp | 5 +- src/cc/assets.cpp | 4 +- src/cc/gateways.cpp | 26 ++- src/cc/prices.cpp | 401 ++++++++++++++++++++++++--------------- src/komodo_utils.h | 5 + src/rpcserver.cpp | 9 +- src/rpcserver.h | 7 + src/wallet/rpcwallet.cpp | 208 ++++++++++++++++++-- 13 files changed, 536 insertions(+), 196 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 8b09e9267..d35823838 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -22,6 +22,13 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); // CCcustom -UniValue PricesInfo(); +UniValue PricesList(); +UniValue PricesInfo(uint256 fundingtxid); +UniValue PricesStatus(uint64_t txfee,uint256 fundingtxid,uint256 bettxid); +std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys); +std::string PricesAddFunding(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount); +std::string PricesBet(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount,int32_t leverage); +std::string PricesFinish(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,uint256 bettxid); + #endif diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 9a0f2a0ea..afb3579cf 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -33,7 +33,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 55a4ccdcb..cd2e267e1 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -274,7 +274,29 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &or return(0); } -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) +CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage) +{ + CScript opret; uint8_t evalcode = EVAL_ASSETS; + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << bettxid << leverage); + return(opret); +} + +uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage) +{ + std::vector vopret; uint8_t funcid=0,e,f; + GetOpReturnData(scriptPubKey, vopret); + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) + { + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + return(funcid); + } + return(0); +} + +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage) { std::vector vopret; uint8_t funcid=0,*script,e,f; GetOpReturnData(scriptPubKey, vopret); @@ -297,6 +319,14 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a return(funcid); } break; + case 'T': + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) + { + assetid = revuint256(assetid); + assetid2 = revuint256(assetid2); + return(funcid); + } + break; case 's': case 'b': case 'S': case 'B': if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> price; ss >> origpubkey) != 0 ) { @@ -325,17 +355,17 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { - uint256 assetid,assetid2; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 ) + uint256 assetid,assetid2,bettxid; int32_t leverage; + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 ) return(true); else return(false); } bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { - uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + uint256 assetid,assetid2,bettxid; int32_t leverage; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) return(false); if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -344,7 +374,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid) { - uint256 assetid,assetid2; int64_t nValue=0; int32_t n; uint8_t funcid; + uint256 assetid,assetid2,bettxid; int64_t nValue=0; int32_t n,leverage; uint8_t funcid; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? { n = tx.vout.size(); @@ -352,7 +382,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); - if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) { fprintf(stderr,"null decodeopret v.%d\n",v); return(0); @@ -414,7 +444,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { - CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid; + CTransaction vinTx; int64_t nValue; int32_t leverage; uint256 assetid,assetid2,bettxid; uint8_t funcid; CCaddr[0] = origaddr[0] = 0; if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) return(0); @@ -423,7 +453,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); - if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) + if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey,bettxid,leverage)) != 'b' && funcid != 'B' ) return eval->Invalid("invalid opreturn for buyvin"); else if ( refassetid != assetid ) return eval->Invalid("invalid assetid for buyvin"); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index cbf40d603..63d1a1089 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -106,7 +106,7 @@ UniValue AssetList() UniValue AssetOrders(uint256 refassetid) { static uint256 zero; - int64_t price; uint256 txid,hashBlock,assetid,assetid2; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; + int64_t price; uint256 txid,hashBlock,assetid,assetid2,bettxid; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; int32_t leverage; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_ASSETS); SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -114,7 +114,7 @@ UniValue AssetOrders(uint256 refassetid) txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey)) != 0 ) + if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) != 0 ) { if ( refassetid != zero && assetid != refassetid ) { diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4beb722a1..4059191a7 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -110,10 +110,12 @@ uint256 OraclesBatontxid(uint256 oracletxid,CPubKey pk); int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); +CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage); +uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 50bb9616f..b26ca7cfd 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -250,14 +250,15 @@ int64_t CCfullsupply(uint256 tokenid) int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) { - int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock; std::vector origpubkey; std::vector > unspentOutputs; + int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,bettxid,hashBlock; std::vector origpubkey; int32_t leverage; + std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) + if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 && assetid == tokenid ) { sum += it->second.satoshis; } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index e5a5af4e0..bf979a1e0 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -132,12 +132,12 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { static uint256 zero; - CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; + CTxDestination address; CTransaction vinTx,createTx; uint256 bettxid,hashBlock,assetid,assetid2; int32_t i,starti,leverage,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey,bettxid,leverage)) == 0 ) return eval->Invalid("Invalid opreturn payload"); fprintf(stderr,"AssetValidate (%c)\n",funcid); if ( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 ) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 23b600930..9146a864b 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -130,6 +130,11 @@ gatewayspending will display all pending withdraws and if it is done on one of the msigpubkeys, then it will queue it for processing ./c gatewayspending e6c99f79d4afb216aa8063658b4222edb773dd24bb0f8e91bd4ef341f3e47e5e KMD + + Implementation Issues: + When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. + + */ @@ -433,19 +438,24 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t { CMutableTransaction mtx; CTransaction oracletx; uint8_t taddr,prefix,prefix2; CPubKey mypk,gatewayspk; CScript opret; uint256 hashBlock; struct CCcontract_info *cp,C; std::string name,description,format; int32_t i,numvouts; int64_t fullsupply; char destaddr[64],coinaddr[64],str[65],*fstr; cp = CCinit(&C,EVAL_GATEWAYS); + if ( strcmp((char *)"KMD",coin.c_str()) == 0 ) + { + taddr = 0; + prefix = 60; + prefix2 = 85; + } + else + { + fprintf(stderr,"set taddr, prefix, prefix2 for %s\n",coin.c_str()); + taddr = 0; + prefix = 60; + prefix2 = 85; + } if ( N == 0 || N > 15 || M > N ) { fprintf(stderr,"illegal M.%d or N.%d\n",M,N); return(""); } - if ( strcmp((char *)"KMD",coin.c_str()) != 0 ) - { - fprintf(stderr,"only KMD supported for now\n"); - return(""); - } - taddr = 0; - prefix = 60; - prefix2 = 85; if ( pubkeys.size() != N ) { fprintf(stderr,"M.%d N.%d but pubkeys[%d]\n",M,N,(int32_t)pubkeys.size()); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1db14d1b9..49e87127a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -28,7 +28,7 @@ Funds work like with dice, ie. there is a Prices plan that traders bet against. - PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + PricesFunding oracletxid, margin, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] PricesBet -> oracletxid start with 'L', leverage, funding, direction funds are locked into global CC address @@ -53,58 +53,35 @@ pricewin -> winnings from dealer funds, exposure token back to global address priceloss -> exposuretoken back to global address + exposure address, funds address */ // start of consensus code -int64_t IsPricesvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t PricesOraclePrice(int64_t &rektprice,uint64_t mode,uint256 oracletxid,std::vectorpubkeys,int32_t dir,int64_t amount,int32_t leverage) { - char destaddr[64]; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) - { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) - return(tx.vout[v].nValue); - } - return(0); + int64_t price; + // howto ensure price when block it confirms it not known + // get price from oracle + current chaintip + // normalize leveraged amount + if ( dir > 0 ) + rektprice = price * leverage / (leverage-1); + else rektprice = price * (leverage-1) / leverage; + return(price); } -bool PricesExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys) { - static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) - { - //fprintf(stderr,"vini.%d check mempool\n",i); - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - //fprintf(stderr,"vini.%d check hash and vout\n",i); - if ( hashBlock == zerohash ) - return eval->Invalid("cant Prices from mempool"); - if ( (assetoshis= IsPricesvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) - inputs += assetoshis; - } - } - } - for (i=0; iInvalid("mismatched inputs != outputs + txfee"); - } - else return(true); + CScript opret; + fprintf(stderr,"implement EncodePricesFundingOpRet\n"); + return(opret); +} + +uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &oracletxid,uint256 &longtoken,uint256 &shorttoken,int32_t &millimargin,uint64_t &mode,int32_t &maxleverage,std::vector &pubkeys,uint256 &bettoken) +{ + fprintf(stderr,"implement DecodePricesFundingOpRet\n"); + return(0); } bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) @@ -148,20 +125,20 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // helper functions for rpc calls in rpcwallet.cpp -int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); + SetCCunspents(unspentOutputs,destaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + // need to prevent dup + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < tx.vout.size() ) { - if ( (nValue= IsPricesvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + // need to verify assetid + if ( (nValue= vintx.vout[vout].nValue)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -176,49 +153,18 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub return(totalinputs); } -#ifdef later -UniValue PricesInfo(uint256 pricesid) -{ - UniValue result(UniValue::VOBJ); CPubKey pricepk; uint256 hashBlock,oracletxid; CTransaction vintx; int64_t minbet,maxbet,maxodds; uint64_t funding; char numstr[65]; struct CCcontract_info *cp,C; - if ( GetTransaction(pricesid,vintx,hashBlock,false) == 0 ) - { - fprintf(stderr,"cant find fundingtxid\n"); - ERR_RESULT("cant find fundingtxid"); - return(result); - } - if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,oracletxid,minbet,maxbet,maxodds) == 0 ) - { - fprintf(stderr,"fundingtxid isnt price creation txid\n"); - ERR_RESULT("fundingtxid isnt price creation txid"); - return(result); - } - result.push_back(Pair("result","success")); - result.push_back(Pair("pricesid",uint256_str(str,pricesid))); - result.push_back(Pair("oracletxid",uint256_str(str,oracletxid))); - sprintf(numstr,"%.8f",(double)minbet/COIN); - result.push_back(Pair("minbet",numstr)); - sprintf(numstr,"%.8f",(double)maxbet/COIN); - result.push_back(Pair("maxbet",numstr)); - result.push_back(Pair("maxodds",maxodds)); - cp = CCinit(&C,EVAL_PRICES); - pricepk = GetUnspendable(cp,0); - funding = PricePlanFunds(cp,pricepk,pricesid); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); - return(result); -} - UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid; CTransaction vintx; int64_t minbet,maxbet,maxodds; char str[65]; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); + pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,oracletxid,minbet,maxbet,maxodds) != 0 ) + if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' ) { result.push_back(uint256_str(str,txid)); } @@ -227,54 +173,165 @@ UniValue PricesList() return(result); } -// PricesFunding oracletxid, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] - -std::string PricesCreateFunding(uint64_t txfee,uint256 oracletxid,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,CPubKey pubkeys) +// longtoken satoshis limits long exposure +// shorttoken satoshis limits short exposure +// both must be in the 1of2 CC address with its total supply +// bettoken +std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { - CMutableTransaction mtx; CPubKey mypk,pricespk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C,*assetscp,C2; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - cp = CCinit(&C,EVAL_REWARDS); + cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - // verify long and short assets - if ( AddNormalinputs(mtx,mypk,funding+3*txfee,60) > 0 ) + if ( (N= (int32_t)pubkeys.size()) || N > 15 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,funding,pricepk)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricepk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',oracletxid,longtoken,shorttoken,funding,mode,maxleverage,pubkeys))); + fprintf(stderr,"too many pubkeys N.%d\n",N); + return(""); + } + for (i=0; i 0 ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',mypk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken))); + } + else + { + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); } - CCerror = "cant find enough inputs"; - fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } -std::string PricesAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) +UniValue PricesInfo(uint256 fundingtxid) { - CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; CPubKey mypk,pricepk; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds; - if ( amount < 0 ) + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64]; struct CCcontract_info *cp,C,*assetscp,C2; + cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_ASSETS); + pricespk = GetUnspendable(cp,0); + if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find fundingtxid\n"); + ERR_RESULT("cant find fundingtxid"); + return(result); + } + if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' ) + { + result.push_back(Pair("result","success")); + result.push_back(Pair("fundingtxid",uint256_str(str,fundingtxid))); + result.push_back(Pair("bettoken",uint256_str(str,bettoken))); + result.push_back(Pair("oracletxid",uint256_str(str,oracletxid))); + sprintf(numstr,"%.3f",(double)margin/1000); + result.push_back(Pair("profitmargin",numstr)); + result.push_back(Pair("maxleverage",maxleverage)); + result.push_back(Pair("mode",(int64_t)mode)); + for (i=0; i 0 ) + fprintf(stderr,"cant find fundingtxid\n"); + ERR_RESULT("cant find fundingtxid"); + return(result); + } + if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) + { + GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,pricepk)); - mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesOpRet('E',sbits,fundingtxid,hentropy,zeroid))); + if ( (inputs= AddBetAssetInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) + { + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); + if ( inputs > amount+txfee ) + CCchange = (inputs - amount); + mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange,mypk)); + // add addr2 + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey()))); + } + else + { + CCerror = "cant find enough bet inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } } else { @@ -282,66 +339,106 @@ std::string PricesAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,in fprintf(stderr,"%s\n", CCerror.c_str() ); } } - else - { - CCerror = "only fund creator can add more funds (entropy)"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - } return(""); } -std::string PricesBet(uint64_t txfee,uint256 pricesid,int64_t bet,int32_t odds) +std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,pricepk; int64_t funding,minbet,maxbet,maxodds; struct CCcontract_info *cp,C; - if ( bet < 0 ) + CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; + if ( amount < 0 ) { - CCerror = "bet must be positive"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + amount = -amount; + dir = -1; + } else dir = 1; + cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + GetCCaddress(myaddr,assetscp,mypk); + if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find fundingtxid\n"); + ERR_RESULT("cant find fundingtxid"); return(""); } - if ( odds < 1 || odds > 9999 ) + if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { - CCerror = "odds must be between 1 and 9999"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - if ( (cp= Pricesinit(fundingPubKey,pricesid,&C,txfee,mypk,pricepk,minbet,maxbet,maxodds)) == 0 ) - return(""); - if ( bet < minbet || bet > maxbet || odds > maxodds ) - { - CCerror = strprintf("Price plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - if ( (funding= PricesPlanFunds(cp,pricepk,pricesid)) >= 2*bet*odds+txfee ) - { - if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) + if ( leverage > maxleverage || leverage < 1 ) { - CCerror = "entropy txid is spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + fprintf(stderr,"illegal leverage\n"); return(""); } - if ( AddNormalinputs(mtx,mypk,bet+2*txfee+odds,60) > 0 ) + GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + if ( dir < 0 ) + tokenid = shorttoken; + else tokenid = longtoken; + exposure = leverage * amount; + longexposure = CCtoken_balance(exposureaddr,longtoken); + shortexposure = CCtoken_balance(exposureaddr,shorttoken); + netexposure = (longexposure - shortexposure + exposure*dir); + if ( netexposure < 0 ) + netexposure = -netexposure; + balance = CCtoken_balance(myaddr,bettoken) / COIN; + if ( balance < netexposure*9/10 ) // 10% extra room for dynamically closed bets in wrong direction { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,entropyval,pricepk)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,pricepk)); - mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesOpRet('B',pricesid))); - } else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN); + fprintf(stderr,"balance %lld < 90% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); + return(""); + } + if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) + { + if ( (inputs= AddTokensInputs(assetscp,mtx,houseaddr,tokenid,exposure,30)) >= exposure ) + { + if ( (inputs2= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,30)) >= amount ) + { + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,exposure,pricespk,pricespk)); + if ( inputs > exposure+txfee ) + CCchange = (inputs - exposure); + if ( inputs2 > amount+txfee ) + CCchange2 = (inputs2 - amount); + mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); + mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange2,mypk)); + // add addr2 and addr3 + return(FinalizeCCTx(mask,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,bettxid,dir*leverage))); + } + else + { + fprintf(stderr,"cant find enough bettoken inputs\n"); + return(""); + } + } + else + { + fprintf(stderr,"cant find enough exposure inputs\n"); + return(""); + } + } + else + { + CCerror = "cant find enough inputsB"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } } - if ( entropyval == 0 && funding != 0 ) - CCerror = "cant find price entropy inputs"; - else CCerror = "cant find price input"; - fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } -std::string PricesBetFinish(int32_t *resultp,uint64_t txfee,uint256 pricesid,uint256 bettxid) +UniValue PricesStatus(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid) +{ + UniValue result(UniValue::VOBJ); + // get height of bettxid + // get price and rekt + // get current height and price + // what about if rekt in the past? + return(result); +} + +std::string PricesFinish(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid) { - *resultp = -1; - CCerror = "couldnt find bettx or entropytx"; - fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } -#endif + + diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d98418c82..2441da83d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1628,6 +1628,11 @@ void komodo_args(char *argv0) { int32_t komodo_baseid(char *origbase); extern int COINBASE_MATURITY; + if ( strcmp(ASSETCHAINS_SYMBOL,"KMD") == 0 ) + { + fprintf(stderr,"cant have assetchain named KMD\n"); + exit(0); + } if ( (port= komodo_userpass(ASSETCHAINS_USERPASS,ASSETCHAINS_SYMBOL)) != 0 ) ASSETCHAINS_RPCPORT = port; else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d268ed7fa..77e53f7a1 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -398,7 +398,14 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oraclessamples", &oraclessamples, true }, /* Prices */ - { "prices", "pricesaddress", &pricesaddress, true }, + { "prices", "pricesaddress", &pricesaddress, true }, + { "prices", "priceslist", &priceslist, true }, + { "prices", "pricesinfo", &pricesinfo, true }, + { "prices", "pricescreate", &pricescreate, true }, + { "prices", "pricesaddfunding", &pricesaddfunding, true }, + { "prices", "pricesbet", &pricesbet, true }, + { "prices", "pricesstatus", &pricesstatus, true }, + { "prices", "pricesfinish", &pricesfinish, true }, /* Pegs */ { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 1ebff82ef..e0c87756f 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -232,6 +232,13 @@ extern UniValue oraclessubscribe(const UniValue& params, bool fHelp); extern UniValue oraclesdata(const UniValue& params, bool fHelp); extern UniValue oraclessamples(const UniValue& params, bool fHelp); extern UniValue pricesaddress(const UniValue& params, bool fHelp); +extern UniValue priceslist(const UniValue& params, bool fHelp); +extern UniValue pricesinfo(const UniValue& params, bool fHelp); +extern UniValue pricescreate(const UniValue& params, bool fHelp); +extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); +extern UniValue pricesbet(const UniValue& params, bool fHelp); +extern UniValue pricesstatus(const UniValue& params, bool fHelp); +extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue triggersaddress(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 44965db73..397c4f3c3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4896,7 +4896,7 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 1 ) throw runtime_error("channelsaddress destpubkey\n"); @@ -4927,23 +4927,25 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; std::vector pubkey; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); + assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) throw runtime_error("pricesaddress [pubkey]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); if ( params.size() == 1 ) - { pubkey = ParseHex(params[0].get_str().c_str()); - char destaddr[64]; - GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); - fprintf(stderr,"1of2 CC %s\n",destaddr); - cp->evalcode = EVAL_ASSETS; - GetCCaddress1of2(cp,destaddr,pubkey2pk(pubkey),pubkey2pk(pubkey)); - fprintf(stderr,"1of2 assets CC %s\n",destaddr); - } - return(CCaddress(cp,(char *)"Prices",pubkey)); + result = CCaddress(cp,(char *)"Prices",pubkey); + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + GetCCaddress(myaddr,assetscp,mypk); + GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + result.push_back(Pair("myaddr",myaddr)); // for holding my asssets + result.push_back(Pair("houseaddr",houseaddr)); // globally accessible house assets + result.push_back(Pair("exposureaddr",exposureaddr)); // tracking of exposure + return(result); } UniValue pegsaddress(const UniValue& params, bool fHelp) @@ -5121,7 +5123,8 @@ UniValue channelsopen(const UniValue& params, bool fHelp) throw runtime_error("channelsopen destpubkey numpayments payment\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); numpayments = atoi(params[1].get_str().c_str()); payment = atol(params[2].get_str().c_str()); @@ -5142,7 +5145,8 @@ UniValue channelsstop(const UniValue& params, bool fHelp) throw runtime_error("channelsstop destpubkey origtxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); hex = ChannelStop(0,pubkey2pk(destpub),origtxid); @@ -5162,7 +5166,8 @@ UniValue channelspayment(const UniValue& params, bool fHelp) throw runtime_error("channelspayment prevtxid origtxid n amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); prevtxid = Parseuint256((char *)params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); n = atoi((char *)params[2].get_str().c_str()); @@ -5184,7 +5189,8 @@ UniValue channelscollect(const UniValue& params, bool fHelp) throw runtime_error("channelscollect paytxid origtxid n amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); paytxid = Parseuint256((char *)params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); n = atoi((char *)params[2].get_str().c_str()); @@ -5206,7 +5212,8 @@ UniValue channelsrefund(const UniValue& params, bool fHelp) throw runtime_error("channelsrefund stoptxid origtxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - LOCK(cs_main); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); stoptxid = Parseuint256((char *)params[0].get_str().c_str()); origtxid = Parseuint256((char *)params[1].get_str().c_str()); hex = ChannelRefund(0,stoptxid,origtxid); @@ -5428,6 +5435,8 @@ UniValue gatewaysbind(const UniValue& params, bool fHelp) throw runtime_error("gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s)\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); oracletxid = Parseuint256((char *)params[1].get_str().c_str()); coin = params[2].get_str(); @@ -5459,6 +5468,8 @@ UniValue gatewaysdeposit(const UniValue& params, bool fHelp) throw runtime_error("gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); coin = params[2].get_str(); @@ -5486,6 +5497,8 @@ UniValue gatewaysclaim(const UniValue& params, bool fHelp) throw runtime_error("gatewaysclaim bindtxid coin deposittxid destpub amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); deposittxid = Parseuint256((char *)params[2].get_str().c_str()); @@ -5507,6 +5520,8 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) throw runtime_error("gatewayswithdraw bindtxid coin withdrawpub amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withdrawpub = ParseHex(params[2].get_str()); @@ -5527,6 +5542,8 @@ UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) throw runtime_error("gatewaysmarkdone withdrawtxid coin cointxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); withdrawtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); cointxid = Parseuint256((char *)params[2].get_str().c_str()); @@ -5558,6 +5575,8 @@ UniValue gatewaysmultisig(const UniValue& params, bool fHelp) throw runtime_error("gatewaysmultisig bindtxid coin withtxid txidaddr\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); withtxid = Parseuint256((char *)params[2].get_str().c_str()); @@ -5598,6 +5617,8 @@ UniValue oraclesregister(const UniValue& params, bool fHelp) throw runtime_error("oraclesregister oracletxid datafee\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); datafee = atol((char *)params[1].get_str().c_str()); hex = OracleRegister(0,txid,datafee); @@ -5616,6 +5637,8 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) throw runtime_error("oraclessubscribe oracletxid publisher amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); 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; @@ -5648,6 +5671,8 @@ UniValue oraclesdata(const UniValue& params, bool fHelp) throw runtime_error("oraclesdata oracletxid hexstr\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); data = ParseHex(params[1].get_str().c_str()); hex = OracleData(0,txid,data); @@ -5784,6 +5809,156 @@ UniValue faucetget(const UniValue& params, bool fHelp) return(result); } +UniValue priceslist(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() > 0 ) + throw runtime_error("priceslist\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + return(PricesList()); +} + +UniValue pricesinfo(const UniValue& params, bool fHelp) +{ + uint256 fundingtxid; + if ( fHelp || params.size() != 1 ) + throw runtime_error("pricesinfo fundingtxid\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + return(PricesInfo(fundingtxid)); +} + +UniValue pricescreate(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint64_t margin,mode; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; + if ( fHelp || params.size() < 8 ) + throw runtime_error("pricescreate bettoken oracletxid margin mode longtoken shorttoken maxleverage funding N [pubkeys]\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + bettoken = Parseuint256((char *)params[0].get_str().c_str()); + oracletxid = Parseuint256((char *)params[1].get_str().c_str()); + margin = atof(params[2].get_str().c_str()) * 1000; + mode = atol(params[3].get_str().c_str()); + 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; + n = atoi(params[8].get_str().c_str()); + if ( n > 0 ) + { + for (i=0; i 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create prices funding transaction"); + } + return(result); +} + +UniValue pricesaddfunding(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; + if ( fHelp || params.size() != 3 ) + throw runtime_error("pricesaddfunding fundingtxid bettoken amount\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + 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; + hex = PricesAddFunding(0,bettoken,fundingtxid,amount); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create pricesaddfunding transaction"); + } + return(result); +} + +UniValue pricesbet(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; int32_t leverage; + if ( fHelp || params.size() != 4 ) + throw runtime_error("pricesbet fundingtxid bettoken amount leverage\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + 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; + leverage = atoi(params[3].get_str().c_str()); + hex = PricesBet(0,bettoken,fundingtxid,amount,leverage); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create pricesbet transaction"); + } + return(result); +} + +UniValue pricesstatus(const UniValue& params, bool fHelp) +{ + uint256 fundingtxid,bettxid,bettoken; + if ( fHelp || params.size() != 3 ) + throw runtime_error("pricesstatus fundingtxid bettoken bettxid\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + bettoken = Parseuint256((char *)params[1].get_str().c_str()); + bettxid = Parseuint256((char *)params[2].get_str().c_str()); + return(PricesStatus(0,bettoken,fundingtxid,bettxid)); +} + +UniValue pricesfinish(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 fundingtxid,bettxid,bettoken; std::string hex; + if ( fHelp || params.size() != 3 ) + throw runtime_error("pricesfinish fundingtxid bettoken bettxid\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + bettoken = Parseuint256((char *)params[1].get_str().c_str()); + bettxid = Parseuint256((char *)params[2].get_str().c_str()); + hex = PricesFinish(0,bettoken,fundingtxid,bettxid); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } + else + { + ERR_RESULT("couldnt create pricesfinish transaction"); + } + return(result); +} + UniValue dicefund(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); int64_t funds,minbet,maxbet,maxodds,timeoutblocks; std::string hex; char *name; @@ -5955,7 +6130,6 @@ UniValue dicestatus(const UniValue& params, bool fHelp) UniValue dicelist(const UniValue& params, bool fHelp) { - uint256 tokenid; if ( fHelp || params.size() > 0 ) throw runtime_error("dicelist\n"); if ( ensure_CCrequirements() < 0 ) From bfd7858525db2e8b929d099b2406c940714afff2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:09:27 -1100 Subject: [PATCH 043/749] Syntax --- src/cc/prices.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 49e87127a..0c530d0aa 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -71,7 +71,7 @@ int64_t PricesOraclePrice(int64_t &rektprice,uint64_t mode,uint256 oracletxid,st return(price); } -CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys) +CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys,uint256 bettoken) { CScript opret; fprintf(stderr,"implement EncodePricesFundingOpRet\n"); @@ -104,12 +104,12 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } } //fprintf(stderr,"check amounts\n"); - if ( PricesExactAmounts(cp,eval,tx,1,10000) == false ) + //if ( PricesExactAmounts(cp,eval,tx,1,10000) == false ) { fprintf(stderr,"Pricesget invalid amount\n"); return false; } - else + //else { txid = tx.GetHash(); memcpy(hash,&txid,sizeof(hash)); @@ -135,10 +135,10 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char txid = it->first.txhash; vout = (int32_t)it->first.index; // need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < tx.vout.size() ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < vintx.vout.size() ) { // need to verify assetid - if ( (nValue= vintx.vout[vout].nValue)) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -208,7 +208,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx } if ( GetCCaddress1of2(houseaddr,cp,pricespk,mypk) == 0 ) { - fprintf(stderr,"PricesCreateFunding (%s) cant create globaladdr\n",uint256_str(str,tokenid)); + fprintf(stderr,"PricesCreateFunding cant create globaladdr\n"); return(""); } if ( CCtoken_balance(houseaddr,longtoken) != CCfullsupply(longtoken) ) From 5efdb4f325c5ae29da5fa7cc17e36142ae548b34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:10:58 -1100 Subject: [PATCH 044/749] N --- src/cc/prices.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 0c530d0aa..eb47c33db 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -206,7 +206,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx return(""); } } - if ( GetCCaddress1of2(houseaddr,cp,pricespk,mypk) == 0 ) + if ( GetCCaddress1of2(cp,houseaddr,pricespk,mypk) == 0 ) { fprintf(stderr,"PricesCreateFunding cant create globaladdr\n"); return(""); @@ -266,8 +266,8 @@ UniValue PricesInfo(uint256 fundingtxid) for (i=0; i 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { - GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); + GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { if ( (inputs= AddBetAssetInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) @@ -370,8 +370,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int fprintf(stderr,"illegal leverage\n"); return(""); } - GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); - GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); + GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); if ( dir < 0 ) tokenid = shorttoken; else tokenid = longtoken; From 816acd6719d67bb5a299e2fd9de22aacfe95dd7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:14:25 -1100 Subject: [PATCH 045/749] Test --- src/cc/prices.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index eb47c33db..935986920 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -243,7 +243,7 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64]; struct CCcontract_info *cp,C,*assetscp,C2; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C,*assetscp,C2; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_ASSETS); pricespk = GetUnspendable(cp,0); @@ -292,7 +292,7 @@ UniValue PricesInfo(uint256 fundingtxid) std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; + CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -305,7 +305,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(myaddr,assetscp,mypk); + GetCCaddress(assetscp,myaddr,mypk); if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -344,7 +344,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; + CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; @@ -356,7 +356,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(myaddr,assetscp,mypk); + GetCCaddress(assetscp,myaddr,mypk); if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); From f6b969d4b419f8563bd13ad685da517528a2518e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:17:06 -1100 Subject: [PATCH 046/749] Test --- src/cc/prices.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 935986920..174c824f3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -309,15 +309,14 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); - ERR_RESULT("cant find fundingtxid"); - return(result); + return(""); } if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ( (inputs= AddBetAssetInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) + if ( (inputs= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) { mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); @@ -344,7 +343,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*asssetcp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; @@ -360,7 +359,6 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); - ERR_RESULT("cant find fundingtxid"); return(""); } if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) @@ -384,7 +382,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int balance = CCtoken_balance(myaddr,bettoken) / COIN; if ( balance < netexposure*9/10 ) // 10% extra room for dynamically closed bets in wrong direction { - fprintf(stderr,"balance %lld < 90% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); + fprintf(stderr,"balance %lld < 90%% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); return(""); } if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) @@ -402,7 +400,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 - return(FinalizeCCTx(mask,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,bettxid,dir*leverage))); + return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,zeroid,dir*leverage))); } else { From feb11ae0389b15cc5650ebb0c65b1e9f0b21783a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:18:15 -1100 Subject: [PATCH 047/749] std::vectorpubkeys; --- src/cc/prices.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 174c824f3..d1ec9167a 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -322,7 +322,7 @@ std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); if ( inputs > amount+txfee ) CCchange = (inputs - amount); - mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange,mypk)); + mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange,mypk)); // add addr2 return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey()))); } @@ -398,7 +398,7 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int if ( inputs2 > amount+txfee ) CCchange2 = (inputs2 - amount); mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); - mtx.vout.push_back(MakeCCvout(assetscp->evalcode,CCchange2,mypk)); + mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,zeroid,dir*leverage))); } From 06c4e87ff978dfd04b1c1e88e465a5fce9292d31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:29:11 -1100 Subject: [PATCH 048/749] CCprices.h --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 397c4f3c3..68c13b2b3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4858,6 +4858,7 @@ int32_t ensure_CCrequirements() #include "../cc/CCchannels.h" #include "../cc/CCOracles.h" #include "../cc/CCGateways.h" +#include "../cc/CCPrices.h" UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) { From a51c08d1a193e609280e440e67cc6a27107c8dd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:32:22 -1100 Subject: [PATCH 049/749] Test --- src/cc/CCPrices.h | 2 +- src/wallet/rpcwallet.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index d35823838..f375ee10a 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -24,7 +24,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx // CCcustom UniValue PricesList(); UniValue PricesInfo(uint256 fundingtxid); -UniValue PricesStatus(uint64_t txfee,uint256 fundingtxid,uint256 bettxid); +UniValue PricesStatus(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid); std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys); std::string PricesAddFunding(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount); std::string PricesBet(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount,int32_t leverage); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 68c13b2b3..c1dd1c3fb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4928,7 +4928,7 @@ UniValue oraclesaddress(const UniValue& params, bool fHelp) UniValue pricesaddress(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C,*assetscp,C2; std::vector pubkey; CPubKey mypk,planpk,pricespk; char myaddr[64],houseaddr[64],exposureaddr[64]; cp = CCinit(&C,EVAL_PRICES); assetscp = CCinit(&C2,EVAL_PRICES); if ( fHelp || params.size() > 1 ) @@ -4940,9 +4940,9 @@ UniValue pricesaddress(const UniValue& params, bool fHelp) result = CCaddress(cp,(char *)"Prices",pubkey); mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(myaddr,assetscp,mypk); - GetCCaddress1of2(houseaddr,assetscp,pricespk,planpk); - GetCCaddress1of2(exposureaddr,assetscp,pricespk,pricespk); + GetCCaddress(assetscp,myaddr,mypk); + GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); + GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); result.push_back(Pair("myaddr",myaddr)); // for holding my asssets result.push_back(Pair("houseaddr",houseaddr)); // globally accessible house assets result.push_back(Pair("exposureaddr",exposureaddr)); // tracking of exposure @@ -5832,7 +5832,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) UniValue pricescreate(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t margin,mode; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; + UniValue result(UniValue::VOBJ); uint64_t mode; int64_t funding; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; if ( fHelp || params.size() < 8 ) throw runtime_error("pricescreate bettoken oracletxid margin mode longtoken shorttoken maxleverage funding N [pubkeys]\n"); if ( ensure_CCrequirements() < 0 ) From 7d6f7d7ea5d7dee6e25e4abe65ac89607cf71230 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:34:25 -1100 Subject: [PATCH 050/749] PricesAddFunding --- src/cc/prices.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d1ec9167a..e8755b53e 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -290,7 +290,7 @@ UniValue PricesInfo(uint256 fundingtxid) return(result); } -std::string PricesAddfunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) +std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) From 541e5e92491cef6df3c6b5b2e87673ae31a96aa2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 21:51:56 -1100 Subject: [PATCH 051/749] Token convert --- src/cc/CCassets.h | 2 ++ src/cc/CCassetstx.cpp | 27 +++++++++++++++++++++++++++ src/cc/gateways.cpp | 2 +- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index afb3579cf..0fb4ae6f7 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -54,6 +54,8 @@ UniValue AssetInfo(uint256 tokenid); UniValue AssetList(); std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std::string description); std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total); +std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode); + std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal); std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid); std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 63d1a1089..2ce13a1ff 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -243,6 +243,33 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des return(""); } +std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total,int32_t evalcode) +{ + CMutableTransaction mtx; CPubKey mypk; int64_t CCchange=0,inputs=0; struct CCcontract_info *cp,C; + if ( total < 0 ) + { + fprintf(stderr,"negative total %lld\n",(long long)total); + return(""); + } + cp = CCinit(&C,EVAL_ASSETS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + { + if ( (inputs= AddAssetInputs(cp,mtx,mypk,assetid,total,60)) > 0 ) + { + if ( inputs > total ) + CCchange = (inputs - total); + mtx.vout.push_back(MakeCC1vout(evalcode,total,pubkey2pk(destpubkey))); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); + } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); + } + return(""); +} + std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal) { CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; uint256 hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 9146a864b..3acc69027 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -474,7 +474,7 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t txfee = 10000; mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - if ( _GetCCaddress(destaddr,EVAL_ASSETS,gatewayspk) == 0 ) + if ( _GetCCaddress(destaddr,EVAL_GATEWAYS,gatewayspk) == 0 ) { fprintf(stderr,"Gateway bind.%s (%s) cant create globaladdr\n",coin.c_str(),uint256_str(str,tokenid)); return(""); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 77e53f7a1..8934ae717 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -454,6 +454,7 @@ static const CRPCCommand vRPCCommands[] = { "tokens", "tokencancelask", &tokencancelask, true }, { "tokens", "tokenfillask", &tokenfillask, true }, //{ "tokens", "tokenfillswap", &tokenfillswap, true }, + { "tokens", "tokenconvert", &tokenconvert, true }, /* Address index */ { "addressindex", "getaddressmempool", &getaddressmempool, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index e0c87756f..f4c502d63 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -221,6 +221,7 @@ extern UniValue tokenfillbid(const UniValue& params, bool fHelp); extern UniValue tokenask(const UniValue& params, bool fHelp); extern UniValue tokencancelask(const UniValue& params, bool fHelp); extern UniValue tokenfillask(const UniValue& params, bool fHelp); +extern UniValue tokenconvert(const UniValue& params, bool fHelp); extern UniValue mofnaddress(const UniValue& params, bool fHelp); extern UniValue channelsaddress(const UniValue& params, bool fHelp); extern UniValue oraclesaddress(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c1dd1c3fb..e8fff8904 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6279,6 +6279,42 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) return(result); } +UniValue tokenconvert(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string hex; int32_t evalcode; int64_t amount; uint256 tokenid; + if ( fHelp || params.size() != 3 ) + throw runtime_error("tokenconvert evalcode tokenid pubkey amount\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + evalcode = atoi(params[0].get_str().c_str()); + tokenid = Parseuint256((char *)params[1].get_str().c_str()); + std::vector pubkey(ParseHex(params[2].get_str().c_str())); + amount = atol(params[3].get_str().c_str()); + if ( tokenid == zeroid ) + { + ERR_RESULT("invalid tokenid"); + return(result); + } + if ( amount <= 0 ) + { + ERR_RESULT("amount must be positive"); + return(result); + } + hex = AssetConvert(0,tokenid,pubkey,amount,evalcode); + if (amount > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt convert tokens"); + } else { + ERR_RESULT("amount must be positive"); + } + return(result); +} + UniValue tokenbid(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid; From 009f09069b4433b53a8e559be2fed6f3435793cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:08:09 -1100 Subject: [PATCH 052/749] Remove dualmode for gateways --- src/cc/gateways.cpp | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 3acc69027..8e9a04c62 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -134,6 +134,7 @@ Implementation Issues: When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. + Care must be taken so that tokens are not lost and can be converted back */ @@ -382,7 +383,7 @@ UniValue GatewaysInfo(uint256 bindtxid) result.push_back(Pair("name","Gateways")); cp = CCinit(&C,EVAL_GATEWAYS); Gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk); + _GetCCaddress(gatewaysassets,EVAL_GATEWAYS,Gatewayspk); if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) { depositaddr[0] = 0; @@ -681,18 +682,12 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) { - CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C,*assetscp,C2; uint8_t M,N,taddr,prefix,prefix2,mypriv[32]; std::string coin; std::vector msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(coinaddr,EVAL_ASSETS,gatewayspk); - CCaddr2set(assetscp,EVAL_ASSETS,gatewayspk,cp->CCpriv,coinaddr); - Myprivkey(mypriv); - _GetCCaddress(coinaddr,EVAL_GATEWAYS,mypk); - CCaddr3set(assetscp,EVAL_GATEWAYS,mypk,mypriv,coinaddr); if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) { fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); @@ -716,15 +711,15 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui //fprintf(stderr,"depositaddr.(%s) vs %s\n",depositaddr,cp->unspendableaddr2); if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { - if ( (inputs= AddAssetInputs(assetscp,mtx,gatewayspk,assetid,amount,60)) > 0 ) + if ( (inputs= AddGatewaysInputs(cp,mtx,gatewayspk,assetid,amount,60)) > 0 ) { if ( inputs > amount ) CCchange = (inputs - amount); mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); // triggers EVAL_GATEWAYS validation - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); // transfer back to normal token if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,gatewayspk)); - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,gatewayspk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } } fprintf(stderr,"cant find enough inputs or mismatched total\n"); @@ -733,18 +728,12 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount) { - CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C,*assetscp,C2; uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2,mypriv[32]; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(coinaddr,EVAL_ASSETS,gatewayspk); - CCaddr2set(assetscp,EVAL_ASSETS,gatewayspk,cp->CCpriv,coinaddr); - Myprivkey(mypriv); - _GetCCaddress(coinaddr,EVAL_GATEWAYS,mypk); - CCaddr3set(assetscp,EVAL_GATEWAYS,mypk,mypriv,coinaddr); if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) { fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); @@ -757,16 +746,16 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin } if ( AddNormalinputs(mtx,mypk,3*txfee,3) > 0 ) { - if ( (inputs= AddAssetInputs(assetscp,mtx,mypk,assetid,amount,60)) > 0 ) + if ( (inputs= AddGatewaysInputs(cp,mtx,mypk,assetid,amount,60)) > 0 ) { if ( inputs > amount ) CCchange = (inputs - amount); - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,gatewayspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,amount,gatewayspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG)); if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,mypk)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } } fprintf(stderr,"cant find enough inputs or mismatched total\n"); @@ -793,7 +782,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(coinaddr,EVAL_ASSETS,gatewayspk); + _GetCCaddress(coinaddr,EVAL_GATEWAYS,gatewayspk); if ( GetTransaction(bindtxid,tx,hashBlock,false) == 0 || (numvouts= tx.vout.size()) <= 0 ) { fprintf(stderr,"cant find bindtxid %s\n",uint256_str(str,bindtxid)); @@ -856,7 +845,7 @@ std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid complete = partialtx = 0; mypk = pubkey2pk(Mypubkey()); Gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(gatewaysassets,EVAL_ASSETS,Gatewayspk); + _GetCCaddress(gatewaysassets,EVAL_GATEWAYS,Gatewayspk); if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) { depositaddr[0] = 0; From 9eece428bb7b48b53e3139301cc1e90a5783cb17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:15:50 -1100 Subject: [PATCH 053/749] Test --- src/cc/gateways.cpp | 62 +++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 8e9a04c62..effc02ea8 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -288,33 +288,41 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -/*int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) - { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; - std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); - SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( (nValue= IsGatewaysvout(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; - } - } - } - return(totalinputs); - }*/ +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +{ + char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + std::vector > unspentOutputs; + GetCCaddress(cp,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + for (j=0; junspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) + continue; + // check for gatewaysassset + if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 && 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; + } + } + } + return(totalinputs); +} int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 reftokenid) // dont forget to check mempool! { From 1605948a06c64a9aac9e5da3553c9cdb6e814c58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:18:51 -1100 Subject: [PATCH 054/749] Test --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index effc02ea8..1d57e8bc4 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -308,8 +308,8 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; - // check for gatewaysassset - if ( (nValue= IsAssetvout(price,origpubkey,vintx,vout,assetid)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + // check for gatewaysassset assetid and 't' + if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From dceeaa3dc59dfe04d87896f85cf4c0ba276f46b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:35:08 -1100 Subject: [PATCH 055/749] Test --- src/cc/gateways.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 1d57e8bc4..69594583a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -288,9 +288,9 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) +int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -308,16 +308,20 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; - // check for gatewaysassset assetid and 't' - if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); + if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 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; + assetid = revuint256(assetid); + if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && 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; + } } } } From 2884a3f64add9fec0150167aa54a92d213a4b2b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Sep 2018 22:35:50 -1100 Subject: [PATCH 056/749] Test --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 69594583a..5c06a7c54 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -290,7 +290,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; + char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); From ff3116ce3cd816007fba72e1ea8a4bd3c270eef0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 02:55:45 -1100 Subject: [PATCH 057/749] Chance for AssetConvert to validate --- src/cc/CCassetsCore.cpp | 3 ++- src/cc/CCassetstx.cpp | 3 +-- src/cc/assets.cpp | 1 - src/cc/gateways.cpp | 6 +++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index cd2e267e1..e2bcf01ff 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -490,8 +490,9 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti fprintf(stderr,"i.%d starti.%d numvins.%d\n",i,starti,numvins); return eval->Invalid("always should find vin, but didnt"); } - else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) + else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 || vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + assetoshis = vinTx.vout[i].nValue; fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); inputs += assetoshis; } diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 2ce13a1ff..70a2c76ee 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -261,9 +261,8 @@ std::string AssetConvert(int64_t txfee,uint256 assetid,std::vector dest { if ( inputs > total ) CCchange = (inputs - total); + mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); mtx.vout.push_back(MakeCC1vout(evalcode,total,pubkey2pk(destpubkey))); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index bf979a1e0..fa6d87500 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -167,7 +167,6 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //vout.n-1: opreturn [EVAL_ASSETS] ['c'] [{"":""}] return eval->Invalid("unexpected AssetValidate for createasset"); break; - case 't': // transfer //vin.0: normal input //vin.1 .. vin.n-1: valid CC outputs diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5c06a7c54..976cd1971 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -134,7 +134,11 @@ Implementation Issues: When thinking about validation, it is clear that we cant use EVAL_ASSETS for the locked coins as there wont be any enforcement of the gateways locking. This means we need a way to transfer assets into gateways outputs and back. It seems a tokenconvert rpc will be needed and hopefully that will be enough to make it all work properly. - Care must be taken so that tokens are not lost and can be converted back + Care must be taken so that tokens are not lost and can be converted back. + + This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 251 + + The gatewaysclaim automatically converts the deposit amount of tokens back to EVAL_ASSETS. */ From 627cd0f5590ff1f66bfabb4f756ce7b36677896e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:45:37 -1100 Subject: [PATCH 058/749] Assets 't' exemption --- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 71 +++++++++++++++++------------------------ src/cc/CCinclude.h | 4 +-- src/cc/CCtx.cpp | 4 +-- src/cc/assets.cpp | 4 +-- 5 files changed, 35 insertions(+), 50 deletions(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 0fb4ae6f7..4d4f30b3b 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -33,7 +33,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx CScript EncodeAssetCreateOpRet(uint8_t funcid,std::vector origpubkey,std::string name,std::string description); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx); int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid); bool ValidateBidRemainder(int64_t remaining_price,int64_t remaining_nValue,int64_t orig_nValue,int64_t received_nValue,int64_t paidprice,int64_t totalprice); diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index e2bcf01ff..f53633813 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -274,29 +274,7 @@ bool DecodeAssetCreateOpRet(const CScript &scriptPubKey,std::vector &or return(0); } -CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage) -{ - CScript opret; uint8_t evalcode = EVAL_ASSETS; - assetid = revuint256(assetid); - assetid2 = revuint256(assetid2); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << assetid << assetid2 << bettxid << leverage); - return(opret); -} - -uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage) -{ - std::vector vopret; uint8_t funcid=0,e,f; - GetOpReturnData(scriptPubKey, vopret); - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) - { - assetid = revuint256(assetid); - assetid2 = revuint256(assetid2); - return(funcid); - } - return(0); -} - -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage) +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey) { std::vector vopret; uint8_t funcid=0,*script,e,f; GetOpReturnData(scriptPubKey, vopret); @@ -319,14 +297,6 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a return(funcid); } break; - case 'T': - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> assetid2; ss >> bettxid; ss >> leverage) != 0 ) - { - assetid = revuint256(assetid); - assetid2 = revuint256(assetid2); - return(funcid); - } - break; case 's': case 'b': case 'S': case 'B': if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> price; ss >> origpubkey) != 0 ) { @@ -355,17 +325,17 @@ uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &a bool SetAssetOrigpubkey(std::vector &origpubkey,int64_t &price,const CTransaction &tx) { - uint256 assetid,assetid2,bettxid; int32_t leverage; - if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 ) + uint256 assetid,assetid2; + if ( tx.vout.size() > 0 && DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 ) return(true); else return(false); } bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,const CTransaction& tx) { - uint256 assetid,assetid2,bettxid; int32_t leverage; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; + uint256 assetid,assetid2; int64_t price,nValue=0; int32_t n; uint8_t funcid; std::vector origpubkey; CScript script; n = tx.vout.size(); - if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) + if ( n == 0 || (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) return(false); if ( GetCCaddress(cp,CCaddr,pubkey2pk(origpubkey)) != 0 && Getscriptaddress(destaddr,CScript() << origpubkey << OP_CHECKSIG) != 0 ) return(true); @@ -374,7 +344,7 @@ bool GetAssetorigaddrs(struct CCcontract_info *cp,char *CCaddr,char *destaddr,co int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTransaction& tx,int32_t v,uint256 refassetid) { - uint256 assetid,assetid2,bettxid; int64_t nValue=0; int32_t n,leverage; uint8_t funcid; + uint256 assetid,assetid2; int64_t nValue=0; int32_t n; uint8_t funcid; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) // maybe check address too? { n = tx.vout.size(); @@ -382,7 +352,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); - if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) { fprintf(stderr,"null decodeopret v.%d\n",v); return(0); @@ -444,7 +414,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *CCaddr,ch int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpprice,std::vector &tmporigpubkey,char *CCaddr,char *origaddr,const CTransaction &tx,uint256 refassetid) { - CTransaction vinTx; int64_t nValue; int32_t leverage; uint256 assetid,assetid2,bettxid; uint8_t funcid; + CTransaction vinTx; int64_t nValue; uint256 assetid,assetid2; uint8_t funcid; CCaddr[0] = origaddr[0] = 0; if ( (nValue= AssetValidateCCvin(cp,eval,CCaddr,origaddr,tx,1,vinTx)) == 0 ) return(0); @@ -453,7 +423,7 @@ int64_t AssetValidateBuyvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmppr else { //fprintf(stderr,"have %.8f checking assetid origaddr.(%s)\n",(double)nValue/COIN,origaddr); - if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey,bettxid,leverage)) != 'b' && funcid != 'B' ) + if ( vinTx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,assetid,assetid2,tmpprice,tmporigpubkey)) != 'b' && funcid != 'B' ) return eval->Invalid("invalid opreturn for buyvin"); else if ( refassetid != assetid ) return eval->Invalid("invalid assetid for buyvin"); @@ -477,7 +447,7 @@ int64_t AssetValidateSellvin(struct CCcontract_info *cp,Eval* eval,int64_t &tmpp bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti,int64_t &outputs,Eval* eval,const CTransaction &tx,uint256 assetid) { - CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; + CTransaction vinTx; uint256 hashBlock,id,id2; int32_t i,flag,numvins,numvouts; int64_t assetoshis; std::vector tmporigpubkey; int64_t tmpprice; numvins = tx.vin.size(); numvouts = tx.vout.size(); inputs = outputs = 0; @@ -490,14 +460,25 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti fprintf(stderr,"i.%d starti.%d numvins.%d\n",i,starti,numvins); return eval->Invalid("always should find vin, but didnt"); } - else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 || vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if ( (assetoshis= IsAssetvout(tmpprice,tmporigpubkey,vinTx,tx.vin[i].prevout.n,assetid)) != 0 ) { - assetoshis = vinTx.vout[i].nValue; fprintf(stderr,"vin%d %llu, ",i,(long long)assetoshis); inputs += assetoshis; } + else + { + if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + { + assetoshis = vinTx.vout[i].nValue; + fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshi); + inputs += assetoshis; + } + } } } + if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + flag = 1; + else flag = 0; for (i=0; i &origpubkey,std::string &name,std::string &description); -uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey,uint256 &bettxid,int32_t &leverage); +uint8_t DecodeAssetOpRet(const CScript &scriptPubKey,uint256 &assetid,uint256 &assetid2,int64_t &price,std::vector &origpubkey); uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint256 &batontxid,CPubKey &pk,std::vector &data); int32_t oracle_format(uint256 *hashp,int64_t *valp,char *str,uint8_t fmt,uint8_t *data,int32_t offset,int32_t datalen); CScript EncodeAssetOpRet(uint8_t funcid,uint256 assetid,uint256 assetid2,int64_t price,std::vector origpubkey); -CScript EncodeAssetOpRetExtra(uint8_t funcid,uint256 assetid,uint256 assetid2,uint256 bettxid,int32_t leverage); -uint8_t DecodeAssetOpRetExtra(CScript scriptPubKey,uint256 &assetid,uint256 &assetid2,uint256 &bettxid,int32_t leverage); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index b26ca7cfd..d651537cf 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -250,7 +250,7 @@ int64_t CCfullsupply(uint256 tokenid) int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) { - int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,bettxid,hashBlock; std::vector origpubkey; int32_t leverage; + int64_t price,sum = 0; int32_t numvouts; CTransaction tx; uint256 assetid,assetid2,txid,hashBlock; std::vector origpubkey; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -258,7 +258,7 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) txid = it->first.txhash; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage) != 0 && assetid == tokenid ) + if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) { sum += it->second.satoshis; } diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index fa6d87500..1ddbdc4f8 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -132,12 +132,12 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { static uint256 zero; - CTxDestination address; CTransaction vinTx,createTx; uint256 bettxid,hashBlock,assetid,assetid2; int32_t i,starti,leverage,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; + CTxDestination address; CTransaction vinTx,createTx; uint256 hashBlock,assetid,assetid2; int32_t i,starti,numvins,numvouts,preventCCvins,preventCCvouts; int64_t remaining_price,nValue,assetoshis,outputs,inputs,tmpprice,totalunits,ignore; std::vector origpubkey,tmporigpubkey,ignorepubkey; uint8_t funcid; char destaddr[64],origaddr[64],CCaddr[64]; numvins = tx.vin.size(); numvouts = tx.vout.size(); outputs = inputs = 0; preventCCvins = preventCCvouts = -1; - if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey,bettxid,leverage)) == 0 ) + if ( (funcid= DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,remaining_price,origpubkey)) == 0 ) return eval->Invalid("Invalid opreturn payload"); fprintf(stderr,"AssetValidate (%c)\n",funcid); if ( funcid != 'o' && funcid != 'x' && eval->GetTxUnconfirmed(assetid,createTx,hashBlock) == 0 ) From 4ab5f2f1d74883315ac93f1489166185aec4044c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:46:55 -1100 Subject: [PATCH 059/749] Test --- src/cc/CCassetsCore.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index f53633813..fadbe15ae 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -467,16 +467,16 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti } else { - if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) { assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshi); + fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshis); inputs += assetoshis; } } } } - if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == asssetid ) + if ( DecodeAssetOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) flag = 1; else flag = 0; for (i=0; i Date: Thu, 20 Sep 2018 03:47:39 -1100 Subject: [PATCH 060/749] Test --- src/cc/CCassetsCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index fadbe15ae..3a9226a27 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -470,7 +470,7 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti if ( vinTx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 && DecodeAssetOpRet(vinTx.vout[vinTx.vout.size()-1].scriptPubKey,id,id2,tmpprice,tmporigpubkey) == 't' && id == assetid ) { assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"vin%d %llu special case, ",(long long)assetoshis); + fprintf(stderr,"vin%d %llu special case, ",i,(long long)assetoshis); inputs += assetoshis; } } @@ -489,7 +489,7 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti else if ( flag != 0 && tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { assetoshis = vinTx.vout[i].nValue; - fprintf(stderr,"vout%d %llu special case, ",(long long)assetoshis); + fprintf(stderr,"vout%d %llu special case, ",i,(long long)assetoshis); outputs += assetoshis; } } From 66bee980b50965c558373fc6e733afb598e5205f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:49:07 -1100 Subject: [PATCH 061/749] Test --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index e8755b53e..f458ab4cc 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -400,7 +400,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodeAssetOpRetExtra('T',tokenid,bettoken,zeroid,dir*leverage))); + //return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); + return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,CScript opret)); } else { From 8fc335afe130681ee2f08bf0384b45f30fe2c938 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:49:47 -1100 Subject: [PATCH 062/749] Test --- src/cc/prices.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index f458ab4cc..ca945d02f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -401,7 +401,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); // add addr2 and addr3 //return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,CScript opret)); + CScript opret; + return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,opret)); } else { From 68da1c69bd9f3342d6f8fc66f718cc5ee7716648 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 03:50:58 -1100 Subject: [PATCH 063/749] Test --- src/cc/CCassetstx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 70a2c76ee..5c933bd77 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -106,7 +106,7 @@ UniValue AssetList() UniValue AssetOrders(uint256 refassetid) { static uint256 zero; - int64_t price; uint256 txid,hashBlock,assetid,assetid2,bettxid; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; int32_t leverage; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; + int64_t price; uint256 txid,hashBlock,assetid,assetid2; std::vector origpubkey; CTransaction vintx; UniValue result(UniValue::VARR); std::vector > unspentOutputs; uint8_t funcid; char numstr[32],funcidstr[16],origaddr[64],assetidstr[65]; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_ASSETS); SetCCunspents(unspentOutputs,(char *)cp->unspendableCCaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -114,7 +114,7 @@ UniValue AssetOrders(uint256 refassetid) txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey,bettxid,leverage)) != 0 ) + if ( vintx.vout.size() > 0 && (funcid= DecodeAssetOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,assetid,assetid2,price,origpubkey)) != 0 ) { if ( refassetid != zero && assetid != refassetid ) { From 71d6712d8dbe06c17421ef846f341c8506072b3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 06:47:08 -1100 Subject: [PATCH 064/749] Test --- src/wallet/rpcwallet.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e8fff8904..80f0e4e6b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4910,6 +4910,14 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) result.push_back(Pair("otherpubkey", params[0].get_str())); GetCCaddress1of2(cp,destaddr,pk,pk2); result.push_back(Pair("channeladdress",destaddr)); + { + int32_t i; + for (i=0; i<100; i++) + { + GetCCaddress1of2(cp,destaddr,pk,pk2); + fprintf(stderr,"i.%d %s\n",i,destaddr); + } + } return(result); } From 44d8e00a25fbd877d06594eecde90cee56dfec4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Sep 2018 07:52:46 -1100 Subject: [PATCH 065/749] +print --- src/cc/CCutils.cpp | 1 + src/wallet/rpcwallet.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index a91d6ffdd..01e9d35ab 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -63,6 +63,7 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2) CTxOut vout; CC *payoutCond = MakeCCcond1of2(evalcode,pk1,pk2); vout = CTxOut(nValue,CCPubKey(payoutCond)); + fprintf(stderr,"payoutCond: %s\n",cc_conditionToJSONString(payoutCond)); cc_free(payoutCond); return(vout); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 80f0e4e6b..7c2314480 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4910,6 +4910,7 @@ UniValue channelsaddress(const UniValue& params, bool fHelp) result.push_back(Pair("otherpubkey", params[0].get_str())); GetCCaddress1of2(cp,destaddr,pk,pk2); result.push_back(Pair("channeladdress",destaddr)); + if ( 0 ) { int32_t i; for (i=0; i<100; i++) From 88b5d9e46aa28912531d7db1094e03c6b4ecafd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 03:34:39 -1100 Subject: [PATCH 066/749] Fix token convert --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7c2314480..5a14370c4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6291,7 +6291,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) UniValue tokenconvert(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); std::string hex; int32_t evalcode; int64_t amount; uint256 tokenid; - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() != 4 ) throw runtime_error("tokenconvert evalcode tokenid pubkey amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 8267beff37fe0a7ff2af7a41eb02e10b9432836e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 06:56:43 -1100 Subject: [PATCH 067/749] +print --- src/cc/CCassetsCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 3a9226a27..a9bb5b71f 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -349,7 +349,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans { n = tx.vout.size(); nValue = tx.vout[v].nValue; - //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); + fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) From a4f7b6910f163282b566d5e99d89c8f4a91afdfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 07:08:47 -1100 Subject: [PATCH 068/749] Fix silly bug --- src/cc/CCassetsCore.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index a9bb5b71f..c9b975c3c 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -349,7 +349,7 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans { n = tx.vout.size(); nValue = tx.vout[v].nValue; - fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); + //fprintf(stderr,"CC vout v.%d of n.%d %.8f\n",v,n,(double)nValue/COIN); if ( v >= n-1 ) return(0); if ( (funcid= DecodeAssetOpRet(tx.vout[n-1].scriptPubKey,assetid,assetid2,price,origpubkey)) == 0 ) @@ -367,7 +367,10 @@ int64_t IsAssetvout(int64_t &price,std::vector &origpubkey,const CTrans else if ( funcid != 'E' ) { if ( assetid == refassetid ) + { + //fprintf(stderr,"returning %.8f\n",(double)nValue/COIN); return(nValue); + } } else if ( funcid == 'E' ) { @@ -488,7 +491,7 @@ bool AssetExactAmounts(struct CCcontract_info *cp,int64_t &inputs,int32_t starti } else if ( flag != 0 && tx.vout[i].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - assetoshis = vinTx.vout[i].nValue; + assetoshis = tx.vout[i].nValue; fprintf(stderr,"vout%d %llu special case, ",i,(long long)assetoshis); outputs += assetoshis; } From 9a59ff3ff14385d5323d5642b6d76197dd83458c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:25:10 -1100 Subject: [PATCH 069/749] Test --- src/rpcblockchain.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5d73e8f6b..f66b1b204 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1417,7 +1417,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ std::set setTips; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - setTips.insert(item.second); + { + if ( item != 0 ) + setTips.insert(item.second); + } BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { const CBlockIndex* pprev=0; From 2dd23a26175529a520961b544098458b2f2d5efe Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:29:18 -1100 Subject: [PATCH 070/749] Test --- src/rpcblockchain.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f66b1b204..f280cfc72 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,16 +1410,18 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); + if ( mapBlockIndex == 0 ) + throw runtime_error("mapBlockIndex is NULL\n"); LOCK(cs_main); /* Build up a list of chain tips. We start with the list of all known blocks, and successively remove blocks that appear as pprev of another block. */ + std::set setTips; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - if ( item != 0 ) - setTips.insert(item.second); + setTips.insert(item.second); } BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { From c46c04b331e4fb8175b852b49c9a570f431e7471 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:29:58 -1100 Subject: [PATCH 071/749] Test --- src/rpcblockchain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index f280cfc72..bec1692c6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,8 +1410,6 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); - if ( mapBlockIndex == 0 ) - throw runtime_error("mapBlockIndex is NULL\n"); LOCK(cs_main); /* Build up a list of chain tips. We start with the list of all From 35506c9ae6da43b94853025c9a9d0ca41f211d73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:31:19 -1100 Subject: [PATCH 072/749] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index bec1692c6..b78d46e19 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1417,8 +1417,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ std::set setTips; + int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { + fprintf(stderr,"iterator %d\n",n++); setTips.insert(item.second); } BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) From a4602c8956b770dd0c483d130f2dfeaa29f9e5b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:33:54 -1100 Subject: [PATCH 073/749] Test --- src/rpcblockchain.cpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b78d46e19..64f3d35e8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,28 +1410,29 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); - LOCK(cs_main); - - /* Build up a list of chain tips. We start with the list of all - known blocks, and successively remove blocks that appear as pprev - of another block. */ - - std::set setTips; - int32_t n = 0; - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - fprintf(stderr,"iterator %d\n",n++); - setTips.insert(item.second); + LOCK(cs_main); + + /* Build up a list of chain tips. We start with the list of all + known blocks, and successively remove blocks that appear as pprev + of another block. */ + + std::set setTips; + int32_t n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + fprintf(stderr,"iterator %d\n",n++); + setTips.insert(item.second); + } + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + const CBlockIndex* pprev=0; + if ( item.second != 0 ) + pprev = item.second->pprev; + if (pprev) + setTips.erase(pprev); + } } - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - { - const CBlockIndex* pprev=0; - if ( item.second != 0 ) - pprev = item.second->pprev; - if (pprev) - setTips.erase(pprev); - } - // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 4eafa6062d91fa76b25d77dccf38d7dfcc4c6838 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:34:54 -1100 Subject: [PATCH 074/749] Test --- src/rpcblockchain.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 64f3d35e8..0ce01d09f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1432,14 +1432,13 @@ UniValue getchaintips(const UniValue& params, bool fHelp) if (pprev) setTips.erase(pprev); } - } - // Always report the currently active tip. - setTips.insert(chainActive.LastTip()); - - /* Construct the output array. */ - UniValue res(UniValue::VARR); const CBlockIndex *forked; - BOOST_FOREACH(const CBlockIndex* block, setTips) - BOOST_FOREACH(const CBlockIndex* block, setTips) + // Always report the currently active tip. + setTips.insert(chainActive.LastTip()); + + /* Construct the output array. */ + UniValue res(UniValue::VARR); const CBlockIndex *forked; + BOOST_FOREACH(const CBlockIndex* block, setTips) + BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("height", block->nHeight)); @@ -1449,7 +1448,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) { const int branchLen = block->nHeight - forked->nHeight; obj.push_back(Pair("branchlen", branchLen)); - + string status; if (chainActive.Contains(block)) { // This block is part of the currently active chain. @@ -1474,7 +1473,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } res.push_back(obj); } - + } return res; } From bf8e9b4d66d6cae6f414a77b3263421a6459c419 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:36:22 -1100 Subject: [PATCH 075/749] Test --- src/rpcblockchain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0ce01d09f..3cfa22282 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,6 +1410,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); + UniValue res(UniValue::VARR); { LOCK(cs_main); @@ -1436,7 +1437,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.insert(chainActive.LastTip()); /* Construct the output array. */ - UniValue res(UniValue::VARR); const CBlockIndex *forked; + const CBlockIndex *forked; BOOST_FOREACH(const CBlockIndex* block, setTips) BOOST_FOREACH(const CBlockIndex* block, setTips) { From 7108bc79f56ae810ac5f6b1e3f83db103e3120bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:44:55 -1100 Subject: [PATCH 076/749] Test --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 379224b48..e355f3708 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1378,6 +1378,8 @@ void komodo_passport_iteration() fprintf(stderr,"[%s] PASSPORT iteration waiting for KOMODO_INITDONE\n",ASSETCHAINS_SYMBOL); sleep(3); } +KOMODO_PASSPORT_INITDONE = 1; +return; if ( komodo_chainactive_timestamp() > lastinterest ) { komodo_interestsum(); From 5aad1637002062efc48f629ef38cdc30d4eb49b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:48:11 -1100 Subject: [PATCH 077/749] Test --- src/komodo_gateway.h | 2 -- src/rpcblockchain.cpp | 65 ++++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e355f3708..379224b48 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1378,8 +1378,6 @@ void komodo_passport_iteration() fprintf(stderr,"[%s] PASSPORT iteration waiting for KOMODO_INITDONE\n",ASSETCHAINS_SYMBOL); sleep(3); } -KOMODO_PASSPORT_INITDONE = 1; -return; if ( komodo_chainactive_timestamp() > lastinterest ) { komodo_interestsum(); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3cfa22282..357b88426 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1410,36 +1410,39 @@ UniValue getchaintips(const UniValue& params, bool fHelp) + HelpExampleRpc("getchaintips", "") ); - UniValue res(UniValue::VARR); + LOCK(cs_main); + + /* Build up a list of chain tips. We start with the list of all + known blocks, and successively remove blocks that appear as pprev + of another block. */ + + std::set setTips; + int32_t n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { - LOCK(cs_main); - - /* Build up a list of chain tips. We start with the list of all - known blocks, and successively remove blocks that appear as pprev - of another block. */ - - std::set setTips; - int32_t n = 0; - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - { - fprintf(stderr,"iterator %d\n",n++); - setTips.insert(item.second); - } - BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) - { - const CBlockIndex* pprev=0; - if ( item.second != 0 ) - pprev = item.second->pprev; - if (pprev) - setTips.erase(pprev); - } - // Always report the currently active tip. - setTips.insert(chainActive.LastTip()); - - /* Construct the output array. */ - const CBlockIndex *forked; - BOOST_FOREACH(const CBlockIndex* block, setTips) - BOOST_FOREACH(const CBlockIndex* block, setTips) + n++; + setTips.insert(item.second); + } + fprintf(stderr,"iterations getchaintips %d\n",n); + n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + const CBlockIndex* pprev=0; + n++; + if ( item.second != 0 ) + pprev = item.second->pprev; + if (pprev) + setTips.erase(pprev); + } + fprintf(stderr,"iterations getchaintips %d\n",n); + + // Always report the currently active tip. + setTips.insert(chainActive.LastTip()); + + /* Construct the output array. */ + UniValue res(UniValue::VARR); const CBlockIndex *forked; + BOOST_FOREACH(const CBlockIndex* block, setTips) + BOOST_FOREACH(const CBlockIndex* block, setTips) { UniValue obj(UniValue::VOBJ); obj.push_back(Pair("height", block->nHeight)); @@ -1449,7 +1452,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) { const int branchLen = block->nHeight - forked->nHeight; obj.push_back(Pair("branchlen", branchLen)); - + string status; if (chainActive.Contains(block)) { // This block is part of the currently active chain. @@ -1474,7 +1477,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } res.push_back(obj); } - } + return res; } From 30ae7560030bde8432feaca53f80b080c27abc49 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:50:42 -1100 Subject: [PATCH 078/749] Test --- src/rpcblockchain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 357b88426..b5815ee0b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1415,7 +1415,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) /* Build up a list of chain tips. We start with the list of all known blocks, and successively remove blocks that appear as pprev of another block. */ - + static pthread_mutex_t mutex; static int32_t didinit; + if ( didinit == 0 ) + portable_mutex_init(&mutex); + portable_mutex_lock(&mutex); std::set setTips; int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) @@ -1435,6 +1438,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.erase(pprev); } fprintf(stderr,"iterations getchaintips %d\n",n); + portable_mutex_unlock(&mutex); // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 79d44e8ab5bbf1f5de42537f81f8e9a0489dc34c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:51:43 -1100 Subject: [PATCH 079/749] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b5815ee0b..92f0c07a8 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1377,6 +1377,8 @@ struct CompareBlocksByHeight } }; +#include + UniValue getchaintips(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 0) From 3036a2412d3cd67892193d56385281e912967e26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:52:38 -1100 Subject: [PATCH 080/749] Test --- src/rpcblockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 92f0c07a8..39f62dfa1 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1419,8 +1419,8 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) - portable_mutex_init(&mutex); - portable_mutex_lock(&mutex); + pthread_mutex_init(&mutex); + pthread_mutex_lock(&mutex); std::set setTips; int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) @@ -1440,7 +1440,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.erase(pprev); } fprintf(stderr,"iterations getchaintips %d\n",n); - portable_mutex_unlock(&mutex); + pthread_mutex_unlock(&mutex); // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 9892eb8a590907d81a83920a6775d19d42d49972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:53:44 -1100 Subject: [PATCH 081/749] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 39f62dfa1..4915bd0cf 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1419,7 +1419,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) - pthread_mutex_init(&mutex); + pthread_mutex_init(&mutex,NULL); pthread_mutex_lock(&mutex); std::set setTips; int32_t n = 0; From 4e90a436f6547e055c92fa6965701a4e612e9746 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:55:02 -1100 Subject: [PATCH 082/749] Test --- src/rpcblockchain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4915bd0cf..3c4b926a2 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1419,7 +1419,10 @@ UniValue getchaintips(const UniValue& params, bool fHelp) of another block. */ static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) + { pthread_mutex_init(&mutex,NULL); + didinit = 1; + } pthread_mutex_lock(&mutex); std::set setTips; int32_t n = 0; From 1313ac253d7ab52b94fba2cf9017227a2a44d39a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 20:56:23 -1100 Subject: [PATCH 083/749] Test --- src/rpcblockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 3c4b926a2..e9cf54bb4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1417,13 +1417,13 @@ UniValue getchaintips(const UniValue& params, bool fHelp) /* Build up a list of chain tips. We start with the list of all known blocks, and successively remove blocks that appear as pprev of another block. */ - static pthread_mutex_t mutex; static int32_t didinit; + /*static pthread_mutex_t mutex; static int32_t didinit; if ( didinit == 0 ) { pthread_mutex_init(&mutex,NULL); didinit = 1; } - pthread_mutex_lock(&mutex); + pthread_mutex_lock(&mutex);*/ std::set setTips; int32_t n = 0; BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) @@ -1443,7 +1443,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) setTips.erase(pprev); } fprintf(stderr,"iterations getchaintips %d\n",n); - pthread_mutex_unlock(&mutex); + //pthread_mutex_unlock(&mutex); // Always report the currently active tip. setTips.insert(chainActive.LastTip()); From 0c2c564c249d6333d36dc27a203aac7025e0a497 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 23:29:00 -1100 Subject: [PATCH 084/749] ac_private to allow notary p2pk bouts --- src/komodo_notary.h | 15 +++++++++++++++ src/main.cpp | 6 +++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 4711a9afc..b619c5b29 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -198,6 +198,21 @@ const char *Notaries_elected1[][2] = {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }; +int32_t komodo_isnotaryvout(CScript scriptPubKey) // from ac_private chains only +{ + uint8_t pubkey33[33],*ptr = scriptPubKey.data(); int32_t i; + if ( scriptPubKey.size() == 35 && ptr[0] == 33 && ptr[34] == 0xac ) + { + for (i=0; i 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) - return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + { + if ( komodo_isnotaryvout(txout.scriptPubKey) == 0 ) + return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + } } if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-vout-negative"); From 2682c88a7a87a7374f834a0e4077b3a2fcd38528 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 23:30:34 -1100 Subject: [PATCH 085/749] Fix --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index b619c5b29..3d22a5734 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -206,7 +206,7 @@ int32_t komodo_isnotaryvout(CScript scriptPubKey) // from ac_private chains only for (i=0; i Date: Fri, 21 Sep 2018 23:33:11 -1100 Subject: [PATCH 086/749] Fix --- src/komodo_notary.h | 8 ++++---- src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 3d22a5734..942612465 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -198,15 +198,15 @@ const char *Notaries_elected1[][2] = {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }; -int32_t komodo_isnotaryvout(CScript scriptPubKey) // from ac_private chains only +int32_t komodo_isnotaryvout(uint8_t *script) // from ac_private chains only { - uint8_t pubkey33[33],*ptr = scriptPubKey.data(); int32_t i; - if ( scriptPubKey.size() == 35 && ptr[0] == 33 && ptr[34] == 0xac ) + uint8_t pubkey33[33]; int32_t i; + if ( script[0] == 33 && script[34] == 0xac ) { for (i=0; i 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) { - if ( komodo_isnotaryvout(txout.scriptPubKey) == 0 ) + if ( txout.scriptPubKey.size() == 35 && komodo_isnotaryvout((uint8_t *)txout.scriptPubKey.data()) == 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } } From fb110781377d9b55a559c1a15d3f71d2ebe9fc5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 21 Sep 2018 23:40:08 -1100 Subject: [PATCH 087/749] Allow crypto777 pub key --- src/komodo_notary.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 942612465..7a6fb8a6b 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -197,15 +197,18 @@ const char *Notaries_elected1[][2] = {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" }, {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }; +#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" int32_t komodo_isnotaryvout(uint8_t *script) // from ac_private chains only { uint8_t pubkey33[33]; int32_t i; if ( script[0] == 33 && script[34] == 0xac ) { - for (i=0; i Date: Sat, 22 Sep 2018 00:43:19 -1100 Subject: [PATCH 088/749] PRATE halving 5x --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2441da83d..79c0b4671 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1704,6 +1704,8 @@ void komodo_args(char *argv0) { BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_RPCPORT); + if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING == 77777 ) + ASSETCHAINS_HALVING *= 5; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } From 1dee00acbf0676cb40894efa1edee85e7f14ece9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 02:12:17 -1100 Subject: [PATCH 089/749] Test --- src/cc/CCinclude.h | 1 + src/cc/gateways.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 4beb722a1..7ac0bfb98 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -138,6 +138,7 @@ uint256 Parseuint256(char *hexstr); CPubKey pubkey2pk(std::vector pubkey); int64_t CCfullsupply(uint256 tokenid); int64_t CCtoken_balance(char *destaddr,uint256 tokenid); +int64_t CCtoken_balance2(char *destaddr,uint256 tokenid); bool _GetCCaddress(char *destaddr,uint8_t evalcode,CPubKey pk); bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); bool GetCCaddress1of2(struct CCcontract_info *cp,char *destaddr,CPubKey pk,CPubKey pk2); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 976cd1971..cf9f3ff27 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -501,9 +501,9 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t fprintf(stderr,"Gateway bind.%s (%s) globaladdr.%s totalsupply %.8f != fullsupply %.8f\n",coin.c_str(),uint256_str(str,tokenid),cp->unspendableCCaddr,(double)totalsupply/COIN,(double)fullsupply/COIN); return(""); } - if ( CCtoken_balance(destaddr,tokenid) != totalsupply ) + if ( CCtoken_balance2(destaddr,tokenid) != totalsupply ) { - fprintf(stderr,"Gateway bind.%s (%s) globaladdr.%s token balance %.8f != %.8f\n",coin.c_str(),uint256_str(str,tokenid),cp->unspendableCCaddr,(double)CCtoken_balance(destaddr,tokenid)/COIN,(double)totalsupply/COIN); + fprintf(stderr,"Gateway bind.%s (%s) destaddr.%s globaladdr.%s token balance %.8f != %.8f\n",coin.c_str(),uint256_str(str,tokenid),destaddr,cp->unspendableCCaddr,(double)CCtoken_balance2(destaddr,tokenid)/COIN,(double)totalsupply/COIN); return(""); } if ( GetTransaction(oracletxid,oracletx,hashBlock,false) == 0 || (numvouts= oracletx.vout.size()) <= 0 ) From 93f31c97304180c162c6ee9458932b63b4cd7d04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 02:13:52 -1100 Subject: [PATCH 090/749] Test --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index cf9f3ff27..de01d9995 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -501,9 +501,9 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t fprintf(stderr,"Gateway bind.%s (%s) globaladdr.%s totalsupply %.8f != fullsupply %.8f\n",coin.c_str(),uint256_str(str,tokenid),cp->unspendableCCaddr,(double)totalsupply/COIN,(double)fullsupply/COIN); return(""); } - if ( CCtoken_balance2(destaddr,tokenid) != totalsupply ) + if ( CCtoken_balance(destaddr,tokenid) != totalsupply ) { - fprintf(stderr,"Gateway bind.%s (%s) destaddr.%s globaladdr.%s token balance %.8f != %.8f\n",coin.c_str(),uint256_str(str,tokenid),destaddr,cp->unspendableCCaddr,(double)CCtoken_balance2(destaddr,tokenid)/COIN,(double)totalsupply/COIN); + fprintf(stderr,"Gateway bind.%s (%s) destaddr.%s globaladdr.%s token balance %.8f != %.8f\n",coin.c_str(),uint256_str(str,tokenid),destaddr,cp->unspendableCCaddr,(double)CCtoken_balance(destaddr,tokenid)/COIN,(double)totalsupply/COIN); return(""); } if ( GetTransaction(oracletxid,oracletx,hashBlock,false) == 0 || (numvouts= oracletx.vout.size()) <= 0 ) From f2f9d6aaf9846afe79075bd1384e871bb38ff8f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 02:28:53 -1100 Subject: [PATCH 091/749] +print --- src/cc/CCtx.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d651537cf..21f5a9cc9 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -258,6 +258,7 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) txid = it->first.txhash; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { + fprintf(stderr,"check %s %.8f\n",uint256_str(str,txid),(double)it->second.satoshis/COIN); if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) { sum += it->second.satoshis; From cd40321aaf6c1cfbc3775f194c232a0070761059 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 02:31:17 -1100 Subject: [PATCH 092/749] Test --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 21f5a9cc9..a9d3f68e7 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -258,7 +258,7 @@ int64_t CCtoken_balance(char *coinaddr,uint256 tokenid) txid = it->first.txhash; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - fprintf(stderr,"check %s %.8f\n",uint256_str(str,txid),(double)it->second.satoshis/COIN); + char str[65]; fprintf(stderr,"check %s %.8f\n",uint256_str(str,txid),(double)it->second.satoshis/COIN); if ( DecodeAssetOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,assetid2,price,origpubkey) != 0 && assetid == tokenid ) { sum += it->second.satoshis; From b07000b7fd60e2017af9d91f7f85d4cef774101c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 03:09:55 -1100 Subject: [PATCH 093/749] syntax --- src/cc/dapps/oraclefeed.c | 22 ++++++++++++---------- src/cc/gateways.cpp | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index be7b14b81..4a1ece19d 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -543,7 +543,6 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) fprintf(stderr,"importaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr); free(retstr); } - return(0); } cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required) @@ -563,7 +562,7 @@ cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required) vin = cJSON_CreateObject(); jaddbits256(vin,"txid",txid); jaddnum(vin,"vout",v); - jadd(vins,vin); + jaddi(vins,vin); *totalp += satoshis; if ( (*totalp) >= required ) break; @@ -581,34 +580,37 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad else txfee = 10000; if ( satoshis < txfee ) { - printf("createmultisig satoshis %.8f < txfee %.8f\n",(double)satoshis/SATOSHIDEN,(double)txfee/SATOSHIS); + printf("createmultisig satoshis %.8f < txfee %.8f\n",(double)satoshis/SATOSHIDEN,(double)txfee/SATOSHIDEN); return(0); } satoshis -= txfee; sprintf(array,"[\"%s\"]",depositaddr); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent",1,99999999,array,"")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 ) { //createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 ) { if ( total >= satoshis ) { - vouts = cJSON_CreatObject(); - jaddstr(vouts,withdrawaddr,(double)satoshis/SATOSHIDEN); + vouts = cJSON_CreateObject(); + jaddnum(vouts,withdrawaddr,(double)satoshis/SATOSHIDEN); if ( total > satoshis+txfee ) { change = (total - satoshis); - jaddstr(vouts,depositaddr,(double)change/SATOSHIDEN); + jaddnum(vouts,depositaddr,(double)change/SATOSHIDEN); } - if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",jprint(vins,0),jprint(vouts,0),"","")) != 0 ) + char *argA,*argB; + argA = jprint(vins,1); + argB = jprint(vouts,1); + if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) { printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); free_json(retjson2); } else if ( txstr == 0 ) printf("createmultisig: null txstr and JSON2\n"); - free_json(vins); - free_json(vouts); + free(argA); + free(argB); } } } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index de01d9995..283ba91a1 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -136,7 +136,7 @@ Care must be taken so that tokens are not lost and can be converted back. - This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 251 + This changes the usage to require tokenconvert before doing the bind and also tokenconvert before doing a withdraw. EVAL_GATEWAYS has evalcode of 241 The gatewaysclaim automatically converts the deposit amount of tokens back to EVAL_ASSETS. From e2d84d81a710c950b31ae338dc5343f1f0701cbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 03:11:46 -1100 Subject: [PATCH 094/749] Test --- src/cc/dapps/oraclefeed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 4a1ece19d..3d395e91d 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -585,7 +585,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad } satoshis -= txfee; sprintf(array,"[\"%s\"]",depositaddr); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array)) != 0 ) { //createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 ) @@ -602,7 +602,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad char *argA,*argB; argA = jprint(vins,1); argB = jprint(vouts,1); - if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) + if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"")) != 0 ) { printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); free_json(retjson2); @@ -626,13 +626,13 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx) { char *retstr,*hexstr; cJSON *retjson; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","")) != 0 ) { if ( jint(retjson,"complete") != 0 ) return(retjson); else if ( (hexstr= jstr(retjson,"hex")) != 0 && strlen(hexstr) > strlen(rawtx) ) { - jadd(retjson,"partialtx",1)' + jaddnum(retjson,"partialtx",1); return(retjson); } free_json(retjson); From b72cac5111f92cf3b4ebe3e1dceeb5e519995ba5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 03:12:21 -1100 Subject: [PATCH 095/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 3d395e91d..ee31709dc 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -643,7 +643,7 @@ cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx char *get_gatewaysmultisig(char *refcoin,char *acname,char *bindtxidstr,char *withtxidstr,char *txidaddr) { char *retstr,*hexstr,*hex=0; cJSON *retjson; - if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",bindtxidstr,refcoin,withtxidstr,txidstr)) != 0 ) + if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",bindtxidstr,refcoin,withtxidstr,txidaddr)) != 0 ) { if ( (hexstr= jstr(retjson,"hex")) != 0 ) hex = clonestr(hexstr); From 2fe210a8802759c9a5d9dd19c9fd905a3f5442b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 03:14:37 -1100 Subject: [PATCH 096/749] Test --- src/cc/dapps/oraclefeed.c | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ee31709dc..673b841b6 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -310,7 +310,7 @@ uint64_t get_btcusd() char *REFCOIN_CLI; -cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2) +cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char *arg0,char *arg1,char *arg2,char *arg3) { long fsize; cJSON *retjson = 0; char cmdstr[32768],*jsonstr,fname[256]; sprintf(fname,"/tmp/oraclefeed.%s",method); @@ -318,13 +318,13 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char { if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) printf("unexpected: refcoin.(%s) acname.(%s)\n",refcoin,acname); - sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,fname); + sprintf(cmdstr,"./komodo-cli -ac_name=%s %s %s %s %s %s > %s\n",acname,method,arg0,arg1,arg2,arg3,fname); } else if ( strcmp(refcoin,"KMD") == 0 ) - sprintf(cmdstr,"./komodo-cli %s %s %s %s > %s\n",method,arg0,arg1,arg2,fname); + sprintf(cmdstr,"./komodo-cli %s %s %s %s %s > %s\n",method,arg0,arg1,arg2,arg3,fname); else if ( REFCOIN_CLI != 0 && REFCOIN_CLI[0] != 0 ) { - sprintf(cmdstr,"%s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,fname); + sprintf(cmdstr,"%s %s %s %s %s %s > %s\n",REFCOIN_CLI,method,arg0,arg1,arg2,arg3,fname); printf("ref.(%s) REFCOIN_CLI (%s)\n",refcoin,cmdstr); } system(cmdstr); @@ -345,7 +345,7 @@ bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson) memset(txid.bytes,0,sizeof(txid)); if ( (hexstr= jstr(hexjson,"hex")) != 0 ) { - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendrawtransaction",hexstr,"","","")) != 0 ) { //fprintf(stderr,"broadcast.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -369,7 +369,7 @@ bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis char numstr[32],*retstr,str[65]; cJSON *retjson; bits256 txid; memset(txid.bytes,0,sizeof(txid)); sprintf(numstr,"%.8f",(double)satoshis/SATOSHIDEN); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"sendtoaddress",destaddr,numstr,"","")) != 0 ) { fprintf(stderr,"unexpected sendrawtransaction json.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -390,7 +390,7 @@ bits256 sendtoaddress(char *refcoin,char *acname,char *destaddr,int64_t satoshis int32_t get_coinheight(char *refcoin,char *acname) { cJSON *retjson; char *retstr; int32_t height=0; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockchaininfo","","","","")) != 0 ) { height = jint(retjson,"blocks"); free_json(retjson); @@ -408,7 +408,7 @@ bits256 get_coinblockhash(char *refcoin,char *acname,int32_t height) cJSON *retjson; char *retstr,heightstr[32]; bits256 hash; memset(hash.bytes,0,sizeof(hash)); sprintf(heightstr,"%d",height); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockhash",heightstr,"","","")) != 0 ) { fprintf(stderr,"unexpected blockhash json.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -429,7 +429,7 @@ bits256 get_coinmerkleroot(char *refcoin,char *acname,bits256 blockhash) { cJSON *retjson; char *retstr,str[65]; bits256 merkleroot; memset(merkleroot.bytes,0,sizeof(merkleroot)); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getblockheader",bits256_str(str,blockhash),"","","")) != 0 ) { merkleroot = jbits256(retjson,"merkleroot"); //fprintf(stderr,"got merkleroot.(%s)\n",bits256_str(str,merkleroot)); @@ -467,7 +467,7 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"","")) != 0 ) { //printf("pending.(%s)\n",jprint(retjson,0)); return(retjson); @@ -483,7 +483,7 @@ cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) cJSON *get_rawmempool(char *refcoin,char *acname) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawmempool","","","","")) != 0 ) { //printf("mempool.(%s)\n",jprint(retjson,0)); return(retjson); @@ -502,7 +502,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr) if ( refcoin[0] != 0 && strcmp(refcoin,"KMD") != 0 ) printf("warning: assumes %s has addressindex enabled\n",refcoin); sprintf(jsonbuf,"{\\\"addresses\\\":[\\\"%s\\\"]}",coinaddr); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getaddressutxos",jsonbuf,"","","")) != 0 ) { //printf("addressutxos.(%s)\n",jprint(retjson,0)); return(retjson); @@ -518,7 +518,7 @@ cJSON *get_addressutxos(char *refcoin,char *acname,char *coinaddr) cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) { cJSON *retjson; char *retstr,str[65]; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"getrawtransaction",bits256_str(str,txid),"1","","")) != 0 ) { return(retjson); } @@ -533,7 +533,7 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) void importaddress(char *refcoin,char *acname,char *depositaddr) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","","")) != 0 ) { printf("importaddress.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -585,7 +585,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad } satoshis -= txfee; sprintf(array,"[\"%s\"]",depositaddr); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array)) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 ) { //createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} if ( (vins= getinputarray(&total,retjson,satoshis)) != 0 ) @@ -602,7 +602,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad char *argA,*argB; argA = jprint(vins,1); argB = jprint(vouts,1); - if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"")) != 0 ) + if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) { printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); free_json(retjson2); @@ -626,7 +626,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx) { char *retstr,*hexstr; cJSON *retjson; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 ) { if ( jint(retjson,"complete") != 0 ) return(retjson); @@ -656,7 +656,7 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit { char str[65],str2[65],*retstr; cJSON *retjson; printf("spend %s %s/v2 as marker\n",acname,bits256_str(str,withtxid)); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,bits256_str(str2,cointxid))) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysmarkdone",bits256_str(str,withtxid),coin,bits256_str(str2,cointxid),"")) != 0 ) { komodobroadcast(refcoin,acname,retjson); free_json(retjson); @@ -671,7 +671,7 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) { char *oracle,*retstr,*name,*deposit; cJSON *retjson; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 ) { if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) { @@ -933,7 +933,7 @@ int32_t main(int32_t argc,char **argv) while ( 1 ) { retstr = 0; - if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","")) != 0 ) + if ( (refcoin[0] == 0 || prevheight < (get_coinheight(refcoin,"") - 10)) && (clijson= get_komodocli("KMD",&retstr,acname,"oraclesinfo",oraclestr,"","","")) != 0 ) { if ( refcoin[0] == 0 && jstr(clijson,"name") != 0 ) { @@ -960,7 +960,7 @@ int32_t main(int32_t argc,char **argv) { if ( (height= get_oracledata(refcoin,"",prevheight,hexstr,sizeof(hexstr),"Ihh")) != 0 ) { - if ( (clijson2= get_komodocli("KMD",&retstr2,acname,"oraclesdata",oraclestr,hexstr,"")) != 0 ) + if ( (clijson2= get_komodocli("KMD",&retstr2,acname,"oraclesdata",oraclestr,hexstr,"","")) != 0 ) { //printf("data.(%s)\n",jprint(clijson2,0)); txid = komodobroadcast("KMD",acname,clijson2); From 7d46fc67440bd128e263de0cbde0d34c33e2a934 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 03:34:42 -1100 Subject: [PATCH 097/749] Test --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 673b841b6..fb32820e9 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -533,7 +533,7 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) void importaddress(char *refcoin,char *acname,char *depositaddr) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"importaddress",depositaddr,"","true","")) != 0 ) { printf("importaddress.(%s)\n",jprint(retjson,0)); free_json(retjson); From 3a9b6817573d3e949b09a8d929b106df4e6fea5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 22 Sep 2018 03:39:18 -1100 Subject: [PATCH 098/749] Test --- src/cc/dapps/oraclefeed.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index fb32820e9..297b92a01 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -673,13 +673,13 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M char *oracle,*retstr,*name,*deposit; cJSON *retjson; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 ) { - if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 ) + if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 && (deposit= jstr(retjson,"deposit")) != 0 ) { - if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 && jint(retjson,"N") >= 1 && (deposit= jstr(retjson,"deposit")) != 0 ) + strcpy(depositaddr,deposit); + if ( jstr(retjson,"coin") != 0 && strcmp(jstr(retjson,"coin"),coin) == 0 && jint(retjson,"N") >= 1 ) { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); - strcpy(depositaddr,deposit); //printf("(%s)\n",jprint(retjson,0)); } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); } else printf("%s != %s\n",oracle,oraclestr); From ca865ad2d471c87091ef130406a9dfa411586cd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 00:40:14 -1100 Subject: [PATCH 099/749] -prints --- src/main.cpp | 2 +- src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a256e0f36..0fdf80892 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1118,7 +1118,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio } if ( ASSETCHAINS_PRIVATE != 0 ) { - fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); + //fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) { if ( txout.scriptPubKey.size() == 35 && komodo_isnotaryvout((uint8_t *)txout.scriptPubKey.data()) == 0 ) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 70375e663..47c93545b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2121,7 +2121,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) { if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) { - LogPrintf("skip Relaying wtx %s nLockTime %u vs now.%u\n", wtx.GetHash().ToString(),(uint32_t)wtx.nLockTime,now); + //LogPrintf("skip Relaying wtx %s nLockTime %u vs now.%u\n", wtx.GetHash().ToString(),(uint32_t)wtx.nLockTime,now); continue; } } From 3372f7893c56e47d291780d8e594ba6f75ca83df Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 03:55:08 -1100 Subject: [PATCH 100/749] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5a14370c4..306ae36c8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -459,7 +459,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") ); - if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) + if ( 0 && ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); LOCK2(cs_main, pwalletMain->cs_wallet); From a7e86f3a813b1e732c416276200d517816afb91d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 04:28:04 -1100 Subject: [PATCH 101/749] Revert --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 306ae36c8..5a14370c4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -459,7 +459,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") ); - if ( 0 && ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) + if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); LOCK2(cs_main, pwalletMain->cs_wallet); From 3a36ff17764be80774984a8daa786566c64f9d42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 05:47:33 -1100 Subject: [PATCH 102/749] Test --- src/cc/CCutils.cpp | 8 ++++++++ src/komodo_globals.h | 1 + src/komodo_notary.h | 14 +++++++++----- src/main.cpp | 7 +++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 01e9d35ab..e03564971 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -198,6 +198,14 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) return(false); } +bool pubkey2addr(char *destaddr,uint8_t *pubkey33) +{ + std::vectorpk; int32_t i; + for (i=0; i<33; i++) + pk.push_back(pubkey33[i]); + return(Getscriptaddress(destaddr,CScript() << pk << OP_CHECKSIG)); +} + CPubKey CCtxidaddr(char *txidaddr,uint256 txid) { uint8_t buf33[33]; CPubKey pk; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index cc5104d12..f352b5333 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -29,6 +29,7 @@ uint64_t komodo_paxtotal(); int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); +bool pubkey2addr(char *destaddr,uint8_t *pubkey33); pthread_mutex_t komodo_mutex; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 7a6fb8a6b..2f23bfbf7 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -199,20 +199,24 @@ const char *Notaries_elected1[][2] = }; #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" -int32_t komodo_isnotaryvout(uint8_t *script) // from ac_private chains only +int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only { - uint8_t pubkey33[33]; int32_t i; - if ( script[0] == 33 && script[34] == 0xac ) + static int32_t didinit; static char notaryaddrs[65][64]; + if ( didinit == 0 ) { + uint8_t pubkey33[33]; for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) { if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); - if ( memcmp(script+1,pubkey33,33) == 0 ) - return(1); + pubkey2addr(notaryaddrs[i],pubkey33); } + didinit = 1; } + for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) + if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) + return(1); return(0); } diff --git a/src/main.cpp b/src/main.cpp index 0fdf80892..dd3a054d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,7 +60,8 @@ extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CON int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); -int32_t komodo_isnotaryvout(CScript scriptPubKey); +int32_t komodo_isnotaryvout(char *destaddr); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); BlockMap mapBlockIndex; CChain chainActive; @@ -1121,7 +1122,9 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio //fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) { - if ( txout.scriptPubKey.size() == 35 && komodo_isnotaryvout((uint8_t *)txout.scriptPubKey.data()) == 0 ) + char destaddr[65]; + Getscriptaddress(destaddr,txout.scriptPubKey); + if ( komodo_isnotaryvout(destaddr) == 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } } From 569bb55b5f039b8b006535c17b01b12ca2ce1926 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 05:48:40 -1100 Subject: [PATCH 103/749] Test --- src/komodo_notary.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 2f23bfbf7..2b929549f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -201,7 +201,8 @@ const char *Notaries_elected1[][2] = int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only { - static int32_t didinit; static char notaryaddrs[65][64]; + static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; + int32_t i; if ( didinit == 0 ) { uint8_t pubkey33[33]; From a8c6526acff093ac93d55c9fa1b4944683d16147 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 05:51:51 -1100 Subject: [PATCH 104/749] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 2b929549f..1bef3f8c6 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -211,7 +211,7 @@ int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); - pubkey2addr(notaryaddrs[i],pubkey33); + pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); } didinit = 1; } From a2e2291e265e5f3bcb6e5bfecfcf9876dd23b008 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 05:53:54 -1100 Subject: [PATCH 105/749] Test --- src/komodo_notary.h | 22 ---------------------- src/main.cpp | 23 ++++++++++++++++++++++- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1bef3f8c6..04fd30d5f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -199,28 +199,6 @@ const char *Notaries_elected1[][2] = }; #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" -int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only -{ - static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; - int32_t i; - if ( didinit == 0 ) - { - uint8_t pubkey33[33]; - for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) - { - if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) - decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); - else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); - pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); - } - didinit = 1; - } - for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) - if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) - return(1); - return(0); -} - int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1; diff --git a/src/main.cpp b/src/main.cpp index dd3a054d1..8908e811e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,7 +60,6 @@ extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CON int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); -int32_t komodo_isnotaryvout(char *destaddr); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); BlockMap mapBlockIndex; @@ -1043,6 +1042,28 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, } } +int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only +{ + static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; + int32_t i; + if ( didinit == 0 ) + { + uint8_t pubkey33[33]; + for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) + { + if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) + decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); + else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); + pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); + } + didinit = 1; + } + for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) + if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) + return(1); + return(0); +} + bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidationState &state) { // Basic checks that don't depend on any context From a510b0f883aaf561ef58c728c463306b3b4dbe40 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 23 Sep 2018 10:49:46 -0700 Subject: [PATCH 106/749] Add Hush to dpowassets --- src/dpowassets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dpowassets b/src/dpowassets index 88e6f72b8..f691533ba 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -40,3 +40,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUSH\",\"pubkey\":\"$pubkey\"}" From f425c7eea5e289f9e0e94845de461eb0033eabde Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 07:49:02 -1100 Subject: [PATCH 107/749] Support for notarizing PRIVATE --- src/komodo_notary.h | 1 + src/main.cpp | 78 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 4711a9afc..04fd30d5f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -197,6 +197,7 @@ const char *Notaries_elected1[][2] = {"webworker01_NA", "03bb7d005e052779b1586f071834c5facbb83470094cff5112f0072b64989f97d7" }, {"xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, }; +#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { diff --git a/src/main.cpp b/src/main.cpp index 21c803754..e8d0acd98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,6 +60,8 @@ extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CON int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); +void komodo_broadcast(CBlock *pblock,int32_t limit); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); BlockMap mapBlockIndex; CChain chainActive; @@ -1036,6 +1038,28 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, } } +int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only +{ + static int32_t didinit; static char notaryaddrs[sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) + 1][64]; + int32_t i; + if ( didinit == 0 ) + { + uint8_t pubkey33[33]; + for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) + { + if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) + decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); + else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); + pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); + } + didinit = 1; + } + for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) + if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) + return(1); + return(0); +} + bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidationState &state) { // Basic checks that don't depend on any context @@ -1112,9 +1136,14 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio } if ( ASSETCHAINS_PRIVATE != 0 ) { - fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); + //fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) - return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + { + char destaddr[65]; + Getscriptaddress(destaddr,txout.scriptPubKey); + if ( komodo_isnotaryvout(destaddr) == 0 ) + return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + } } if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-vout-negative"); @@ -3621,23 +3650,34 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->nHeight - (pindexFork ? pindexFork->nHeight : -1) : 0; static_assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); - if (reorgLength > MAX_REORG_LENGTH) { - auto msg = strprintf(_( - "A block chain reorganization has been detected that would roll back %d blocks! " - "This is larger than the maximum of %d blocks, and so the node is shutting down for your safety." - ), reorgLength, MAX_REORG_LENGTH) + "\n\n" + - _("Reorganization details") + ":\n" + - "- " + strprintf(_("Current tip: %s, height %d, work %s"), - pindexOldTip->phashBlock->GetHex(), pindexOldTip->nHeight, pindexOldTip->nChainWork.GetHex()) + "\n" + - "- " + strprintf(_("New tip: %s, height %d, work %s"), - pindexMostWork->phashBlock->GetHex(), pindexMostWork->nHeight, pindexMostWork->nChainWork.GetHex()) + "\n" + - "- " + strprintf(_("Fork point: %s %s, height %d"), - ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + - _("Please help, human!"); - LogPrintf("*** %s\n", msg); - uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); - StartShutdown(); - return false; + if (reorgLength > MAX_REORG_LENGTH) + { + int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; + notarizedht = komodo_notarized_height(&prevMoMheight,¬arizedhash,&txid); + if ( pindexFork->nHeight < notarizedht ) + { + fprintf(stderr,"pindexFork->nHeight.%d is < notarizedht %d, so ignore it\n",(int32_t)pindexFork->nHeight,notarizedht); + pindexFork = pindexOldTip; + } + else + { + auto msg = strprintf(_( + "A block chain reorganization has been detected that would roll back %d blocks! " + "This is larger than the maximum of %d blocks, and so the node is shutting down for your safety." + ), reorgLength, MAX_REORG_LENGTH) + "\n\n" + + _("Reorganization details") + ":\n" + + "- " + strprintf(_("Current tip: %s, height %d, work %s"), + pindexOldTip->phashBlock->GetHex(), pindexOldTip->nHeight, pindexOldTip->nChainWork.GetHex()) + "\n" + + "- " + strprintf(_("New tip: %s, height %d, work %s"), + pindexMostWork->phashBlock->GetHex(), pindexMostWork->nHeight, pindexMostWork->nChainWork.GetHex()) + "\n" + + "- " + strprintf(_("Fork point: %s %s, height %d"), + ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->nHeight) + "\n\n" + + _("Please help, human!"); + LogPrintf("*** %s\n", msg); + uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); + StartShutdown(); + return false; + } } // Disconnect active blocks which are no longer in the best chain. From 54731d91b57d33de9108c25b7793dfab4478c013 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 07:51:25 -1100 Subject: [PATCH 108/749] Pubkey2addr --- src/cc/CCutils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 3c38d04b3..6aceb5bf4 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -142,6 +142,14 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) return(false); } +bool pubkey2addr(char *destaddr,uint8_t *pubkey33) +{ + std::vectorpk; int32_t i; + for (i=0; i<33; i++) + pk.push_back(pubkey33[i]); + return(Getscriptaddress(destaddr,CScript() << pk << OP_CHECKSIG)); +} + bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) { CC *payoutCond; From 2d450767051c8a23713ece076879b9f4498a1c78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 07:52:31 -1100 Subject: [PATCH 109/749] bool pubkey2addr(char *destaddr,uint8_t *pubkey33); --- src/komodo_globals.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 918e7c4f6..02c6a2f1d 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -29,6 +29,7 @@ uint64_t komodo_paxtotal(); int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); +bool pubkey2addr(char *destaddr,uint8_t *pubkey33); pthread_mutex_t komodo_mutex; From 037c101c85229fa774fe481039cc7bc3ca5e30f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 08:11:42 -1100 Subject: [PATCH 110/749] +print --- src/komodo_utils.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 79c0b4671..75f68d87d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1705,7 +1705,10 @@ void komodo_args(char *argv0) BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_RPCPORT); if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING == 77777 ) + { ASSETCHAINS_HALVING *= 5; + fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); + } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } From b9281f45e7077b70706623fb85b43c8169a8fbdc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 08:36:47 -1100 Subject: [PATCH 111/749] 5x PIRATE halving --- src/komodo_utils.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 23e6b280e..64b283fb5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1699,6 +1699,11 @@ void komodo_args(char *argv0) { BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_RPCPORT); + if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING == 77777 ) + { + ASSETCHAINS_HALVING *= 5; + fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); + } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } From 7097b79097a3241be3373725966a928dcac7f622 Mon Sep 17 00:00:00 2001 From: SHossain Date: Sun, 23 Sep 2018 20:52:43 +0100 Subject: [PATCH 112/749] Update assetchains.json --- src/assetchains.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/assetchains.json b/src/assetchains.json index ceda4cce1..0a9a6b93c 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -146,4 +146,14 @@ "195.201.22.89" ] } + { + "ac_name": "PIRATE", + "ac_supply": "0", + "ac_reward": "25600000000", + "ac_halving": "77777", + "ac_private": "1", + "addnode": [ + "136.243.102.225" + ] + } ] From 9630b8ec9630288477e637bce9e5786dd48e63d7 Mon Sep 17 00:00:00 2001 From: SHossain Date: Sun, 23 Sep 2018 20:53:54 +0100 Subject: [PATCH 113/749] Update assetchains.old --- src/assetchains.old | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains.old b/src/assetchains.old index 158e62cad..2e9218d64 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -39,3 +39,4 @@ echo $pubkey ~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & +./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=136.243.102.225 & From 426efacd34ea8d526e47f2d6cc9328ba0c06349b Mon Sep 17 00:00:00 2001 From: SHossain Date: Sun, 23 Sep 2018 20:55:23 +0100 Subject: [PATCH 114/749] Update dpowassets --- src/dpowassets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dpowassets b/src/dpowassets index f691533ba..2b85f976f 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -41,3 +41,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUSH\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PIRATE\",\"pubkey\":\"$pubkey\"}" From 40027428e40b1026f20ae17683d8e9f11ccac0d7 Mon Sep 17 00:00:00 2001 From: himu007 Date: Sun, 23 Sep 2018 21:52:56 +0100 Subject: [PATCH 115/749] add PIRATE --- src/ac/pirate | 2 ++ src/assetchains.json | 4 ++-- src/assetchains.old | 1 + src/fiat/pirate | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100755 src/ac/pirate create mode 100755 src/fiat/pirate diff --git a/src/ac/pirate b/src/ac/pirate new file mode 100755 index 000000000..9314209da --- /dev/null +++ b/src/ac/pirate @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=PIRATE $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index 0a9a6b93c..825f606df 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -145,8 +145,8 @@ "142.93.136.89", "195.201.22.89" ] - } - { + }, + { "ac_name": "PIRATE", "ac_supply": "0", "ac_reward": "25600000000", diff --git a/src/assetchains.old b/src/assetchains.old index 2e9218d64..96f680b03 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -40,3 +40,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & ./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=136.243.102.225 & + diff --git a/src/fiat/pirate b/src/fiat/pirate new file mode 100755 index 000000000..9314209da --- /dev/null +++ b/src/fiat/pirate @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=PIRATE $1 $2 $3 $4 $5 $6 From eff8c62cb321922dbf91a45eb74c4d86d8bdb78e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:04:40 -1100 Subject: [PATCH 116/749] Test --- src/cc/gateways.cpp | 4 ++-- src/komodo_utils.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 283ba91a1..a61fe2ba4 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -554,8 +554,8 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u return(mhash); } else return(zeroid); } - batontxid = hash; - } else break; + } //else break; + batontxid = hash; } return(zeroid); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 79c0b4671..75f68d87d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1705,7 +1705,10 @@ void komodo_args(char *argv0) BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); //fprintf(stderr,"(%s) port.%u chain params initialized\n",ASSETCHAINS_SYMBOL,BITCOIND_RPCPORT); if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING == 77777 ) + { ASSETCHAINS_HALVING *= 5; + fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); + } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } From 8dab0bc78c6a9ff41bf3e34661e08bcdf1a78c12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:10:42 -1100 Subject: [PATCH 117/749] Test --- src/cc/oracles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index c24ad5a8b..a0437ed0f 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -157,7 +157,8 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 { if ( e == EVAL_ORACLES && f == 'D' ) return(f); - } + else fprintf(stderr,"DecodeOraclesData evalcode.%d f.%c\n",e,f); + } else fprintf(stderr,"DecodeOraclesData not enough opereturn data\n"); return(0); } From d4f6cde55040c8e9beea6f410698c5ad92059afb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:18:37 -1100 Subject: [PATCH 118/749] Test --- src/cc/gateways.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index a61fe2ba4..5ec01b8fd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -539,24 +539,32 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u { CTransaction tx; uint256 hash,mhash,hashBlock,oracletxid; int64_t val; int32_t numvouts; int64_t merkleht; CPubKey pk; std::vectordata; txid = zeroid; - char str[65]; fprintf(stderr,"reverse scan %s\n",uint256_str(str,batontxid)); + char str[65]; fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); while ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - fprintf(stderr,"reverse scan %s\n",uint256_str(str,batontxid)); if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,hash,pk,data) == 'D' && oracletxid == reforacletxid ) { + fprintf(stderr,"decoded %s\n",uint256_str(str,batontxid)); if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) { + fprintf(stderr,"found merkleht.%d\n",merkleht); if ( oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()) == sizeof(hash) && oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) { txid = batontxid; + fprintf(stderr,"set txid\n"); return(mhash); - } else return(zeroid); - } - } //else break; - batontxid = hash; + } + else + { + fprintf(stderr,"missing hash\n"); + return(zeroid); + } + } else fprintf(stderr,"height.%d vs search ht.%d\n",merkleht,height); + batontxid = hash; + } else break; } + fprintf(stderr,"end of loop\n"); return(zeroid); } From 36fbbfe6fcdfa56f17e4f01a5843724ff724d8dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:20:51 -1100 Subject: [PATCH 119/749] Test --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5ec01b8fd..04c585cd3 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -547,7 +547,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u fprintf(stderr,"decoded %s\n",uint256_str(str,batontxid)); if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) { - fprintf(stderr,"found merkleht.%d\n",merkleht); + fprintf(stderr,"found merkleht.%d\n",(int32_t)merkleht); if ( oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()) == sizeof(hash) && oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) { @@ -560,7 +560,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u fprintf(stderr,"missing hash\n"); return(zeroid); } - } else fprintf(stderr,"height.%d vs search ht.%d\n",merkleht,height); + } else fprintf(stderr,"height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); batontxid = hash; } else break; } From 2ca4cd6e9a791bfd4b6bd022cb1650e55270718c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:25:15 -1100 Subject: [PATCH 120/749] Test --- src/cc/gateways.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 04c585cd3..2452825f3 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -542,6 +542,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u char str[65]; fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); while ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { + fprintf(stderr,"check %s\n",uint256_str(str,batontxid)); if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,hash,pk,data) == 'D' && oracletxid == reforacletxid ) { fprintf(stderr,"decoded %s\n",uint256_str(str,batontxid)); @@ -562,6 +563,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u } } else fprintf(stderr,"height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); batontxid = hash; + fprintf(stderr,"new hash %s\n",uint256_str(str,batontxid)); } else break; } fprintf(stderr,"end of loop\n"); From b73666e2ffa061ecac897e43462666101d552ca2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:26:42 -1100 Subject: [PATCH 121/749] Test --- src/cc/gateways.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 2452825f3..ec0fb919b 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -537,13 +537,13 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,uint256 batontxid) { - CTransaction tx; uint256 hash,mhash,hashBlock,oracletxid; int64_t val; int32_t numvouts; int64_t merkleht; CPubKey pk; std::vectordata; + CTransaction tx; uint256 hash,mhash,bhash,hashBlock,oracletxid; int64_t val; int32_t numvouts; int64_t merkleht; CPubKey pk; std::vectordata; txid = zeroid; char str[65]; fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); while ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { fprintf(stderr,"check %s\n",uint256_str(str,batontxid)); - if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,hash,pk,data) == 'D' && oracletxid == reforacletxid ) + if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,bhash,pk,data) == 'D' && oracletxid == reforacletxid ) { fprintf(stderr,"decoded %s\n",uint256_str(str,batontxid)); if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) @@ -562,7 +562,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u return(zeroid); } } else fprintf(stderr,"height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); - batontxid = hash; + batontxid = bhash; fprintf(stderr,"new hash %s\n",uint256_str(str,batontxid)); } else break; } From 11b0ed84d56ee172ca7639957c61123af7a9d5ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:33:18 -1100 Subject: [PATCH 122/749] Test --- src/cc/gateways.cpp | 15 ++++++++------- src/cc/oracles.cpp | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index ec0fb919b..7c70408d8 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -537,20 +537,21 @@ std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,uint256 batontxid) { - CTransaction tx; uint256 hash,mhash,bhash,hashBlock,oracletxid; int64_t val; int32_t numvouts; int64_t merkleht; CPubKey pk; std::vectordata; + CTransaction tx; uint256 hash,mhash,bhash,hashBlock,oracletxid; int32_t len,len2,numvouts; int64_t val,merkleht; CPubKey pk; std::vectordata; txid = zeroid; - char str[65]; fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); + //char str[65]; fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); while ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - fprintf(stderr,"check %s\n",uint256_str(str,batontxid)); + //fprintf(stderr,"check %s\n",uint256_str(str,batontxid)); if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,bhash,pk,data) == 'D' && oracletxid == reforacletxid ) { - fprintf(stderr,"decoded %s\n",uint256_str(str,batontxid)); + //fprintf(stderr,"decoded %s\n",uint256_str(str,batontxid)); if ( oracle_format(&hash,&merkleht,0,'I',(uint8_t *)data.data(),0,(int32_t)data.size()) == sizeof(int32_t) && merkleht == height ) { - fprintf(stderr,"found merkleht.%d\n",(int32_t)merkleht); - if ( oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()) == sizeof(hash) && - oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()) == sizeof(hash) && mhash != zeroid ) + len = oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()); + len2 = oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()); + char str2[65]; fprintf(stderr,"found merkleht.%d len.%d len2.%d %s %s\n",(int32_t)merkleht,len,len2,uint256_str(str,hash),uint256_str(str2,mhash)); + if ( len == sizeof(hash) && len2 == sizeof(mhash) && mhash != zeroid ) { txid = batontxid; fprintf(stderr,"set txid\n"); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index a0437ed0f..6af1453ce 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -157,8 +157,8 @@ uint8_t DecodeOraclesData(const CScript &scriptPubKey,uint256 &oracletxid,uint25 { if ( e == EVAL_ORACLES && f == 'D' ) return(f); - else fprintf(stderr,"DecodeOraclesData evalcode.%d f.%c\n",e,f); - } else fprintf(stderr,"DecodeOraclesData not enough opereturn data\n"); + //else fprintf(stderr,"DecodeOraclesData evalcode.%d f.%c\n",e,f); + } //else fprintf(stderr,"DecodeOraclesData not enough opereturn data\n"); return(0); } From e072837352c08975ce67eae86e5b68e6ca67b998 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:36:45 -1100 Subject: [PATCH 123/749] Test --- src/cc/gateways.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 7c70408d8..68f639ff3 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -539,7 +539,8 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u { CTransaction tx; uint256 hash,mhash,bhash,hashBlock,oracletxid; int32_t len,len2,numvouts; int64_t val,merkleht; CPubKey pk; std::vectordata; txid = zeroid; - //char str[65]; fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); + char str[65]; + //fprintf(stderr,"start reverse scan %s\n",uint256_str(str,batontxid)); while ( GetTransaction(batontxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { //fprintf(stderr,"check %s\n",uint256_str(str,batontxid)); From b6283728906e81650d649bcc2d5fa879c83200cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:38:59 -1100 Subject: [PATCH 124/749] Test --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 68f639ff3..7d886a5b7 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -552,7 +552,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u len = oracle_format(&hash,&val,0,'h',(uint8_t *)data.data(),sizeof(int32_t),(int32_t)data.size()); len2 = oracle_format(&mhash,&val,0,'h',(uint8_t *)data.data(),(int32_t)(sizeof(int32_t)+sizeof(uint256)),(int32_t)data.size()); char str2[65]; fprintf(stderr,"found merkleht.%d len.%d len2.%d %s %s\n",(int32_t)merkleht,len,len2,uint256_str(str,hash),uint256_str(str2,mhash)); - if ( len == sizeof(hash) && len2 == sizeof(mhash) && mhash != zeroid ) + if ( len == sizeof(hash)+sizeof(int32_t) && len2 == 2*sizeof(mhash)+sizeof(int32_t) && mhash != zeroid ) { txid = batontxid; fprintf(stderr,"set txid\n"); @@ -565,7 +565,7 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u } } else fprintf(stderr,"height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); batontxid = bhash; - fprintf(stderr,"new hash %s\n",uint256_str(str,batontxid)); + //fprintf(stderr,"new hash %s\n",uint256_str(str,batontxid)); } else break; } fprintf(stderr,"end of loop\n"); From 186ce5d29dcbab3df4cc522cac33b9861bcc00fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:44:19 -1100 Subject: [PATCH 125/749] Test --- src/cc/gateways.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 7d886a5b7..53a4d8765 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -555,15 +555,15 @@ uint256 GatewaysReverseScan(uint256 &txid,int32_t height,uint256 reforacletxid,u if ( len == sizeof(hash)+sizeof(int32_t) && len2 == 2*sizeof(mhash)+sizeof(int32_t) && mhash != zeroid ) { txid = batontxid; - fprintf(stderr,"set txid\n"); + //fprintf(stderr,"set txid\n"); return(mhash); } else { - fprintf(stderr,"missing hash\n"); + //fprintf(stderr,"missing hash\n"); return(zeroid); } - } else fprintf(stderr,"height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); + } //else fprintf(stderr,"height.%d vs search ht.%d\n",(int32_t)merkleht,(int32_t)height); batontxid = bhash; //fprintf(stderr,"new hash %s\n",uint256_str(str,batontxid)); } else break; @@ -626,7 +626,7 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout { fprintf(stderr,"verify proof for cointxid in merkleroot\n"); return(nValue); - } else fprintf(stderr,"(%s) != (%s) or txid mismatch.%d or script mismatch\n",refdepositaddr,destaddr,txid != cointxid); + } else fprintf(stderr,"(%s) != (%s) or txid %s mismatch.%d or script mismatch\n",refdepositaddr,destaddr,uint256_str(str,txid),txid != cointxid); return(0); } @@ -679,7 +679,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: txids.push_back(txid); } } - fprintf(stderr,"m.%d of n.%d\n",m,n); + fprintf(stderr,"cointxid.%s m.%d of n.%d\n",uint256_str(str,cointxid),m,n); if ( merkleroot == zeroid || m < n/2 ) { //uint256 tmp; From 1826284cb3b3d3a0202f554e3a6e645ed2526814 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 22:51:01 -1100 Subject: [PATCH 126/749] Print --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 53a4d8765..be61cffc4 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -624,7 +624,7 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout } if ( txid == cointxid ) { - fprintf(stderr,"verify proof for cointxid in merkleroot\n"); + fprintf(stderr,"verified proof for cointxid in merkleroot\n"); return(nValue); } else fprintf(stderr,"(%s) != (%s) or txid %s mismatch.%d or script mismatch\n",refdepositaddr,destaddr,uint256_str(str,txid),txid != cointxid); return(0); From 5c43df8b4836825a144ddaa87c0acde52785eacc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 23:14:55 -1100 Subject: [PATCH 127/749] Test --- src/cc/gateways.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index be61cffc4..345b00f7e 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -298,6 +298,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + fprintf(stderr,"check %s for gateway inputs\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -316,6 +317,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); + char str[65]; fprintf(stderr,"check for assetid.%s\n",uint256_str(str,assetid)); if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) From 733b58f24921d5f67df9eff981715e3e944a5151 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 23:23:20 -1100 Subject: [PATCH 128/749] Test --- src/cc/gateways.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 345b00f7e..3ebe0e8e0 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -317,12 +317,13 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); - char str[65]; fprintf(stderr,"check for assetid.%s\n",uint256_str(str,assetid)); + char str[65]; fprintf(stderr,"%d:%d (%c) check for refassetid.%s vs %s %.8f\n",evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)nValue/COIN); if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { + fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; + //nValue = it->second.satoshis; totalinputs += nValue; n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) From c15c1ad2ef71a4ff991fc914a9ecb3d6a5f3fb38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 23:25:22 -1100 Subject: [PATCH 129/749] Test --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 3ebe0e8e0..aeeb85a8a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -317,7 +317,7 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); - char str[65]; fprintf(stderr,"%d:%d (%c) check for refassetid.%s vs %s %.8f\n",evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)nValue/COIN); + char str[65],str2[65]; fprintf(stderr,"%d:%d (%c) check for refassetid.%s vs %s %.8f\n",evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)nValue/COIN); if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); From c884b0f0eabdbab44580ee7fcb7e3c632c40afc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 23:30:19 -1100 Subject: [PATCH 130/749] Test --- src/cc/gateways.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index aeeb85a8a..cecb87b1a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -311,13 +311,14 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); + fprintf(stderr,"%s vout.%d %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); - char str[65],str2[65]; fprintf(stderr,"%d:%d (%c) check for refassetid.%s vs %s %.8f\n",evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)nValue/COIN); + char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)nValue/COIN); if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); From 2511d10f8a55a728895d37f8bad910d846d316a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 23:33:24 -1100 Subject: [PATCH 131/749] Test --- src/cc/gateways.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index cecb87b1a..b5c0ba6bd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -311,15 +311,15 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); - fprintf(stderr,"%s vout.%d %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN); + fprintf(stderr,"%s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); - char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)nValue/COIN); - if ( evalcode == cp->evalcode && assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN); + if ( assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); if ( total != 0 && maxinputs != 0 ) From 983ff7f46d38c42acdbf11867f7931a7b61228ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 23 Sep 2018 23:34:34 -1100 Subject: [PATCH 132/749] Test --- src/cc/gateways.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b5c0ba6bd..566177ea6 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -311,17 +311,17 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); - fprintf(stderr,"%s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); + //fprintf(stderr,"%s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); - char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN); + //char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN); if ( assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); + //fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); //nValue = it->second.satoshis; From 2ce154d60efed158f51d76eb6a8787e939097d37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 00:36:18 -1100 Subject: [PATCH 133/749] Allow sendtoaddress for PIRATE to notary --- src/wallet/rpcwallet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5a14370c4..e02cad35f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -398,7 +398,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr // Parse Zcash address CScript scriptPubKey = GetScriptForDestination(address); - + // Create and send the transaction CReserveKey reservekey(pwalletMain); CAmount nFeeRequired; @@ -430,6 +430,8 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr throw JSONRPCError(RPC_WALLET_ERROR, "Error: The transaction was rejected! This might happen if some of the coins in your wallet were already spent, such as if you used a copy of wallet.dat and coins were spent in the copy but not marked as spent here."); } +int32_t komodo_isnotaryvout(char *coinaddr); + UniValue sendtoaddress(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) @@ -460,8 +462,12 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) ); if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); - + { + if ( komodo_isnotaryvout((char *)params[0].get_str().c_ctr()) == 0 ) + { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); + } + } LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); From 10a5fd2cd0d813443fae9452cf1f616bb3f9e797 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 00:37:09 -1100 Subject: [PATCH 134/749] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e02cad35f..cf86a0ba5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -463,7 +463,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) { - if ( komodo_isnotaryvout((char *)params[0].get_str().c_ctr()) == 0 ) + if ( komodo_isnotaryvout((char *)params[0].get_str().c_str()) == 0 ) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); } From 594c9d12748b958f4c0a768fb522ae902bbc161f Mon Sep 17 00:00:00 2001 From: Jorian Date: Mon, 24 Sep 2018 15:41:03 +0200 Subject: [PATCH 135/749] add mgnx --- src/ac/mgnx | 2 ++ src/assetchains.json | 12 ++++++++++++ src/assetchains.old | 2 +- src/dpowassets | 1 + src/fiat/mgnx | 2 ++ 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100755 src/ac/mgnx create mode 100755 src/fiat/mgnx diff --git a/src/ac/mgnx b/src/ac/mgnx new file mode 100755 index 000000000..9bd85336e --- /dev/null +++ b/src/ac/mgnx @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=MGNX $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index 825f606df..7dbd7a473 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -155,5 +155,17 @@ "addnode": [ "136.243.102.225" ] + }, + { + "ac_name": "MGNX", + "ac_supply": "12465003", + "ac_staked": "90", + "ac_reward": "2000000000", + "ac_halving": "525960", + "ac_cc": "2", + "ac_end": "2629800", + "addnode": [ + "45.76.32.178" + ] } ] diff --git a/src/assetchains.old b/src/assetchains.old index 96f680b03..fcee4bf41 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -40,4 +40,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=SEC -ac_cc=333 -ac_supply=1000000000 -addnode=185.148.145.43 & ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & ./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=136.243.102.225 & - +./komodod -pubkey=$pubkey -ac_name=MGNX -ac_supply=12465003 -ac_staked=90 -ac_reward=2000000000 -ac_halving=525960 -ac_cc=2 -ac_end=2629800 -addnode=142.93.27.180 & diff --git a/src/dpowassets b/src/dpowassets index 2b85f976f..9bd17ff18 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -42,3 +42,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUSH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PIRATE\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGNX\",\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat/mgnx b/src/fiat/mgnx new file mode 100755 index 000000000..9bd85336e --- /dev/null +++ b/src/fiat/mgnx @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=MGNX $1 $2 $3 $4 $5 $6 From 966a1680374b22754393a4ed844743d6e9036512 Mon Sep 17 00:00:00 2001 From: Jorian Date: Mon, 24 Sep 2018 15:43:16 +0200 Subject: [PATCH 136/749] fix ip --- src/assetchains.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.json b/src/assetchains.json index 7dbd7a473..f78e19f87 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -165,7 +165,7 @@ "ac_cc": "2", "ac_end": "2629800", "addnode": [ - "45.76.32.178" + "142.93.27.180" ] } ] From 6b72038d2d7eb22798c2d587f9a06bb8425d978f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 03:45:08 -1100 Subject: [PATCH 137/749] add claimpubkey check --- src/cc/gateways.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 566177ea6..a0b3a7210 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -634,12 +634,12 @@ int64_t GatewaysVerify(char *refdepositaddr,uint256 oracletxid,int32_t claimvout return(0); } -int64_t GatewaysDepositval(CTransaction tx) +int64_t GatewaysDepositval(CTransaction tx,CPubKey mypk) { int32_t numvouts,height; int64_t amount; std::string coin,deposithex; std::vector publishers; std::vectortxids; uint256 bindtxid,cointxid; std::vector proof; CPubKey claimpubkey; if ( (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey,coin,bindtxid,publishers,txids,height,cointxid,deposithex,proof,claimpubkey,amount) == 'D' ) + if ( DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey,coin,bindtxid,publishers,txids,height,cointxid,deposithex,proof,claimpubkey,amount) == 'D' && claimpubkey == mypk ) { // coin, bindtxid, publishers fprintf(stderr,"need to validate deposittxid more\n"); @@ -735,7 +735,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui fprintf(stderr,"cant find deposittxid %s\n",uint256_str(str,bindtxid)); return(""); } - if ( (depositamount= GatewaysDepositval(tx)) != amount ) + if ( (depositamount= GatewaysDepositval(tx,mypk)) != amount ) { fprintf(stderr,"invalid Gateways deposittxid %s %.8f != %.8f\n",uint256_str(str,deposittxid),(double)depositamount/COIN,(double)amount/COIN); return(""); From 1f77927e6250b9fe98f7a4df782fe82a0d73724a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 07:19:21 -1100 Subject: [PATCH 138/749] Keep mining rewards indefinitely --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8908e811e..bf2ae23fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1876,7 +1876,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) return(100000000 * COIN); // ICO allocation else if ( nHeight < KOMODO_ENDOFERA ) //komodo_moneysupply(nHeight) < MAX_MONEY ) return(3 * COIN); - else return(0); + else return(COIN); } else { From 9f59de78b2e48687e9971d99f754f0cd2ff4f691 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 07:22:32 -1100 Subject: [PATCH 139/749] Ramp down blockreward over 30 years --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bf2ae23fd..0aadc130c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1874,8 +1874,10 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { if ( nHeight == 1 ) return(100000000 * COIN); // ICO allocation - else if ( nHeight < KOMODO_ENDOFERA ) //komodo_moneysupply(nHeight) < MAX_MONEY ) + else if ( nHeight < KOMODO_ENDOFERA ) return(3 * COIN); + else if ( nHeight < 2*KOMODO_ENDOFERA ) + return(2 * COIN); else return(COIN); } else From 22f4e6fd145c82d6a348d93abd6db8c36a3fdf70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 20:25:35 -1100 Subject: [PATCH 140/749] Dispflag for PoW diff --- src/komodo_bitcoind.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 13501d2a9..86ed8f7b3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1284,7 +1284,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - int32_t oldflag = 0; + int32_t oldflag = 0,dispflag = 0; CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) @@ -1303,23 +1303,23 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { n++; percPoS++; - if ( ASSETCHAINS_STAKED < 100 ) + if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); } else { - if ( ASSETCHAINS_STAKED < 100 ) + if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"1"); sum += UintToArith256(pindex->GetBlockHash()); m++; } } - if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) + if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } if ( m+n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; - if ( ASSETCHAINS_STAKED < 100 ) + if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; if ( m > 0 ) @@ -1332,12 +1332,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he 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(goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); else bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); - if ( ASSETCHAINS_STAKED < 100 ) + if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); @@ -1355,7 +1353,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( oldflag != 0 ) { 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); @@ -1367,7 +1364,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( bnTarget < ave ) bnTarget = ave; } - if ( 1 ) + if ( dispflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); From c9f93c2c95be56f2cf443daf549a03cb227f2696 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 24 Sep 2018 20:41:38 -1100 Subject: [PATCH 141/749] +print --- src/cc/gateways.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index a0b3a7210..3db4a56e2 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -311,14 +311,14 @@ int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { Getscriptaddress(destaddr,vintx.vout[vout].scriptPubKey); - //fprintf(stderr,"%s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); + fprintf(stderr,"check %s vout.%d %.8f %.8f\n",destaddr,vout,(double)vintx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( strcmp(destaddr,coinaddr) != 0 && strcmp(destaddr,cp->unspendableCCaddr) != 0 && strcmp(destaddr,cp->unspendableaddr2) != 0 ) continue; GetOpReturnData(vintx.vout[vintx.vout.size()-1].scriptPubKey, vopret); if ( E_UNMARSHAL(vopret,ss >> evalcode; ss >> funcid; ss >> assetid) != 0 ) { assetid = revuint256(assetid); - //char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN); + char str[65],str2[65]; fprintf(stderr,"vout.%d %d:%d (%c) check for refassetid.%s vs %s %.8f\n",vout,evalcode,cp->evalcode,funcid,uint256_str(str,refassetid),uint256_str(str2,assetid),(double)vintx.vout[vout].nValue/COIN); if ( assetid == refassetid && funcid == 't' && (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { //fprintf(stderr,"total %llu maxinputs.%d %.8f\n",(long long)total,maxinputs,(double)it->second.satoshis/COIN); From f9f8f4ec67ee01a7004b033e2aacc575039ef2ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Sep 2018 00:38:11 -1100 Subject: [PATCH 142/749] Fix gatewaysmarkdone --- src/cc/CCcustom.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index d9a793ddd..71644686b 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -214,7 +214,7 @@ uint8_t PaymentsCCpriv[32] = { 0x03, 0xc9, 0x73, 0xc2, 0xb8, 0x30, 0x3d, 0xbd, 0 #define FUNCNAME IsGatewaysInput #define EVALCODE EVAL_GATEWAYS const char *GatewaysCCaddr = "RKWpoK6vTRtq5b9qrRBodLkCzeURHeEk33"; -const char *GatewaysNormaladdr = "RGJKV97ZN1wBfunuMt1tebiiHENNEq73Yh"; +const char *GatewaysNormaladdr = "RGJKV97ZN1wBfunuMt1tebiiHENNEq73Yh"; // wif UxJFYqEvLAjWPPRvn8NN1fRWscBxQZXZB5BBgc3HiapKVQBYNcmo char GatewaysCChexstr[67] = { "03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40" }; uint8_t GatewaysCCpriv[32] = { 0xf7, 0x4b, 0x5b, 0xa2, 0x7a, 0x5e, 0x9c, 0xda, 0x89, 0xb1, 0xcb, 0xb9, 0xe6, 0x9c, 0x2c, 0x70, 0x85, 0x37, 0xdd, 0x00, 0x7a, 0x67, 0xff, 0x7c, 0x62, 0x1b, 0xe2, 0xfb, 0x04, 0x8f, 0x85, 0xbf }; #include "CCcustom.inc" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cf86a0ba5..8f64d093d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5554,7 +5554,7 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) UniValue gatewaysmarkdone(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 withdrawtxid,cointxid; std::string hex,coin; - if ( fHelp || params.size() != 1 ) + if ( fHelp || params.size() != 3 ) throw runtime_error("gatewaysmarkdone withdrawtxid coin cointxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 72968af153b1813c68b51201eefa59969932fbc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 27 Sep 2018 23:40:35 -1100 Subject: [PATCH 143/749] Prices --- src/cc/oracles.cpp | 2 +- src/cc/prices.cpp | 52 ++++++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 6af1453ce..255b7f034 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -804,7 +804,7 @@ std::string OracleData(int64_t txfee,uint256 oracletxid,std::vector da mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,batonpk)); mtx.vout.push_back(CTxOut(datafee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeOraclesData('D',oracletxid,batontxid,mypk,data))); - } else fprintf(stderr,"couldnt find enough oracle inputs, limit 1 per utxo\n"); + } else fprintf(stderr,"couldnt find enough oracle inputs %s, limit 1 per utxo\n",coinaddr); } else fprintf(stderr,"couldnt add normal inputs\n"); return(""); } diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index ca945d02f..6ee0364e2 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -55,6 +55,8 @@ exposure address, funds address + + */ // start of consensus code @@ -138,7 +140,7 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < vintx.vout.size() ) { // need to verify assetid - if ( (nValue= vintx.vout[vout].nValue) > 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) >= 10000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -179,7 +181,7 @@ UniValue PricesList() // bettoken std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) { - CMutableTransaction mtx; CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C,*assetscp,C2; + CMutableTransaction mtx; CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C; if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) { CCerror = "invalid parameter error"; @@ -187,7 +189,6 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx return(""); } cp = CCinit(&C,EVAL_PRICES); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); @@ -243,9 +244,8 @@ std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletx UniValue PricesInfo(uint256 fundingtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C,*assetscp,C2; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_PRICES); - assetscp = CCinit(&C2,EVAL_ASSETS); pricespk = GetUnspendable(cp,0); if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) { @@ -266,8 +266,8 @@ UniValue PricesInfo(uint256 fundingtxid) for (i=0; ipubkeys; + CMutableTransaction mtx; struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,CCchange = 0; uint64_t funding,mode; int32_t margin,maxleverage; char houseaddr[64],myaddr[64]; std::vectorpubkeys; if ( amount < 10000 ) { CCerror = "amount must be positive"; @@ -300,12 +300,11 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt return(""); } cp = CCinit(&C,EVAL_PRICES); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(assetscp,myaddr,mypk); + GetCCaddress(cp,myaddr,mypk); if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -313,16 +312,16 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt } if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) { - GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); + GetCCaddress1of2(cp,houseaddr,pricespk,planpk); if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) { - if ( (inputs= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,60)) >= amount ) + if ( (inputs= AddTokensInputs(cp,mtx,myaddr,bettoken,amount,60)) >= amount ) { - mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,amount,pricespk,planpk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); if ( inputs > amount+txfee ) CCchange = (inputs - amount); - mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange,mypk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,mypk)); // add addr2 return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',bettoken,zeroid,0,Mypubkey()))); } @@ -343,19 +342,18 @@ std::string PricesAddFunding(uint64_t txfee,uint256 refbettoken,uint256 fundingt std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) { - CMutableTransaction mtx; struct CCcontract_info *cp,C,*assetscp,C2; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; + CMutableTransaction mtx; struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; if ( amount < 0 ) { amount = -amount; dir = -1; } else dir = 1; cp = CCinit(&C,EVAL_PRICES); - assetscp = CCinit(&C2,EVAL_ASSETS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); - GetCCaddress(assetscp,myaddr,mypk); + GetCCaddress(cp,myaddr,mypk); if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -368,8 +366,8 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int fprintf(stderr,"illegal leverage\n"); return(""); } - GetCCaddress1of2(assetscp,houseaddr,pricespk,planpk); - GetCCaddress1of2(assetscp,exposureaddr,pricespk,pricespk); + GetCCaddress1of2(cp,houseaddr,pricespk,planpk); + GetCCaddress1of2(cp,exposureaddr,pricespk,pricespk); if ( dir < 0 ) tokenid = shorttoken; else tokenid = longtoken; @@ -387,22 +385,22 @@ std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int } if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) { - if ( (inputs= AddTokensInputs(assetscp,mtx,houseaddr,tokenid,exposure,30)) >= exposure ) + if ( (inputs= AddTokensInputs(cp,mtx,houseaddr,tokenid,exposure,30)) >= exposure ) { - if ( (inputs2= AddTokensInputs(assetscp,mtx,myaddr,bettoken,amount,30)) >= amount ) + if ( (inputs2= AddTokensInputs(cp,mtx,myaddr,bettoken,amount,30)) >= amount ) { - mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,amount,pricespk,planpk)); - mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,exposure,pricespk,pricespk)); + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,amount,pricespk,planpk)); + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,exposure,pricespk,pricespk)); if ( inputs > exposure+txfee ) CCchange = (inputs - exposure); if ( inputs2 > amount+txfee ) CCchange2 = (inputs2 - amount); - mtx.vout.push_back(MakeCC1of2vout(assetscp->evalcode,CCchange,pricespk,planpk)); - mtx.vout.push_back(MakeCC1vout(assetscp->evalcode,CCchange2,mypk)); + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,CCchange,pricespk,planpk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange2,mypk)); // add addr2 and addr3 - //return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); + //return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); CScript opret; - return(FinalizeCCTx(0,assetscp,mtx,mypk,txfee,opret)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } else { From e47eab188b702815dc45035329141125cb1b9265 Mon Sep 17 00:00:00 2001 From: SHossain Date: Sun, 30 Sep 2018 20:03:52 +0100 Subject: [PATCH 144/749] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8ed8c3cb..9585c7f78 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ This is the official Komodo sourcecode repository based on https://github.com/jl ## Development Resources - Komodo Website: [https://komodoplatform.com/](https://komodoplatform.com/) -- Komodo Blockexplorer: [https://kmdexplorer.io//](https://https://kmdexplorer.io/) +- Komodo Blockexplorer: [https://kmdexplorer.io//](https://kmdexplorer.io/) +- Komodo Discord: [https://komodoplatform.com/discord](https://komodoplatform.com/discord) - Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) - Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) - Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) -- Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) -- API references: [http://docs.komodoplatform.com/](http://docs.komodoplatform.com/) -- Blog: [http://blog.komodoplatform.com/](http://blog.komodoplatform.com/) +- Knowledgebase & How-to: [https://support.komodoplatform.com/en/support/solutions](https://support.komodoplatform.com/en/support/solutions) +- API references & Dev Documentation: [https://docs.komodoplatform.com/](https://docs.komodoplatform.com/) +- Blog: [https://blog.komodoplatform.com/](https://blog.komodoplatform.com/) - Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) From 5ca814d52dee0070944224b9e1a1ce5356b270a5 Mon Sep 17 00:00:00 2001 From: SHossain Date: Mon, 1 Oct 2018 10:52:36 +0100 Subject: [PATCH 145/749] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9585c7f78..92a7014f4 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,16 @@ This is the official Komodo sourcecode repository based on https://github.com/jl ## Development Resources -- Komodo Website: [https://komodoplatform.com/](https://komodoplatform.com/) -- Komodo Blockexplorer: [https://kmdexplorer.io//](https://kmdexplorer.io/) +- Komodo Website: [https://komodoplatform.com](https://komodoplatform.com/) +- Komodo Blockexplorer: [https://kmdexplorer.io](https://kmdexplorer.io/) - Komodo Discord: [https://komodoplatform.com/discord](https://komodoplatform.com/discord) -- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) +- Forum: [https://forum.komodoplatform.com](https://forum.komodoplatform.com/) - Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) - Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) - Knowledgebase & How-to: [https://support.komodoplatform.com/en/support/solutions](https://support.komodoplatform.com/en/support/solutions) -- API references & Dev Documentation: [https://docs.komodoplatform.com/](https://docs.komodoplatform.com/) -- Blog: [https://blog.komodoplatform.com/](https://blog.komodoplatform.com/) -- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) +- API references & Dev Documentation: [https://docs.komodoplatform.com](https://docs.komodoplatform.com/) +- Blog: [https://blog.komodoplatform.com](https://blog.komodoplatform.com/) +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/whitepaper) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) ## List of Komodo Platform Technologies From bd59ecd6cd8a903f4164d75da145ae5005ca4dbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Oct 2018 02:37:21 -1100 Subject: [PATCH 146/749] Require tokenid for remaining --- src/cc/gateways.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 3db4a56e2..5c82b789d 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -426,7 +426,7 @@ UniValue GatewaysInfo(uint256 bindtxid) result.push_back(Pair("tokenid",uint256_str(str,tokenid))); sprintf(numstr,"%.8f",(double)totalsupply/COIN); result.push_back(Pair("totalsupply",numstr)); - remaining = CCaddress_balance(gatewaysassets); + remaining = CCtoken_balance(gatewaysassets,tokenid); sprintf(numstr,"%.8f",(double)remaining/COIN); result.push_back(Pair("remaining",numstr)); sprintf(numstr,"%.8f",(double)(totalsupply - remaining)/COIN); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 798b991d7..9471abf0a 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -477,7 +477,7 @@ int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid uint256 hashBlock; if ( GetTransaction(txid,tx,hashBlock,false) == 0 ) return(-1); - else if ( n <= tx.vout.size() ) // vout.size() seems off by 1 + else if ( n < tx.vout.size() ) { ptr = (uint8_t *)tx.vout[n].scriptPubKey.data(); m = tx.vout[n].scriptPubKey.size(); From 450c5f7115f1832915b7ac878414906bb5e81f29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Oct 2018 02:47:25 -1100 Subject: [PATCH 147/749] Test --- src/cc/oracles.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 255b7f034..5a352afeb 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -666,6 +666,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 93cfcaa7efeb6251cddda6afe3f01fe747ce97eb Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 14 Sep 2018 15:03:44 +0200 Subject: [PATCH 148/749] - Modified AddChannelsInputs to uses inputs from CC channel for payment - Inital validate skeleton - Defined OP_RETURN format --- src/cc/channels.cpp | 326 ++++++++++++++++++++++++++++++++------------ 1 file changed, 239 insertions(+), 87 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index dc1a3f291..0ecd6a1be 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -111,11 +111,101 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti else return(true); } +CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) +{ + CScript opret; uint8_t evalcode = EVAL_CHANNELS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << opentxid << srcpub << destpub << numpayments << payment << hashchain); + return(opret); +} + +uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) +{ + std::vector vopret; uint8_t *script,e,f,funcid; + GetOpReturnData(scriptPubKey, vopret); + if ( vopret.size() > 2 ) + { + script = (uint8_t *)vopret.data(); + if ( script[0] == EVAL_CHANNELS ) + { + funcid = script[1]; + //fprintf(stderr,"decode.[%c]\n",funcid); + switch ( funcid ) + { + case 'c': + return(funcid); + break; + default: + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> opentxid; ss >> srcpub; ss >> destpub; ss >> numpayments; ss >> payment; ss >> hashchain) != 0 ) + { + return(f); + } + break; + } + } else fprintf(stderr,"script[0] %02x != EVAL_CHANNELS\n",script[0]); + } else fprintf(stderr,"not enough opret.[%d]\n",(int32_t)vopret.size()); + return(0); +} + +CScript EncodeChannelsPaymentOpRet(uint8_t funcid,uint256 opentxid,uint256 prevtxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) +{ + CScript opret; uint8_t evalcode = EVAL_CHANNELS; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << opentxid << prevtxid << srcpub << destpub << numpayments << payment << hashchain); + return(opret); +} + +uint8_t DecodeChannelsPaymentOpRet(const CScript &scriptPubKey,uint256 &opentxid,uint256 &prevtxid,CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) +{ + std::vector vopret; uint8_t *script,e,f,funcid; + GetOpReturnData(scriptPubKey, vopret); + if ( vopret.size() > 2 ) + { + script = (uint8_t *)vopret.data(); + if ( script[0] == EVAL_CHANNELS ) + { + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> opentxid; ss >> srcpub; ss >> destpub; ss >> numpayments; ss >> payment; ss >> hashchain) != 0 ) + { + return(f); + } + } else fprintf(stderr,"script[0] %02x != EVAL_CHANNELS\n",script[0]); + } else fprintf(stderr,"not enough opret.[%d]\n",(int32_t)vopret.size()); + return(0); +} + +//bool GetChannelOpenTx(struct CCcontract_info *cp, CTransaction &channelOpenTx, CPubKey srcpub, CPubKey destpub, int32_t &numpayments, int64_t &payment, uint256 &hashchain) +//{ +// uint256 txid, hashBlock, origtxid; +// char CCaddr[64]; +// std::vector > txids; +// uint8_t funcid; +// CPubKey opensrcpub, opendestpub; +// int32_t numvouts; +// +// GetCCaddress1of2(cp,CCaddr,srcpub,destpub); +// SetCCtxids(txids,CCaddr); +// +// for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) +// { +// txid=it->first.txhash; +// if (GetTransaction(txid,channelOpenTx,hashBlock,false) != 0 && (numvouts= channelOpenTx.vout.size()) > 0) +// { +// if (((funcid = DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,origtxid,opensrcpub,opendestpub,numpayments,payment,hashchain)) != 0) && (funcid == 'O') && (srcpub==opensrcpub && (destpub==opendestpub))) +// { +// return true; +// } +// } +// } +// +// return false; +//} + bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,param1,numpayments; bool retval; uint256 txid,hashblock,param3,hashchain,opentxid,prevtxid; uint8_t funcid, hash[32]; char str[65],destaddr[64]; + int64_t param2,payment; + CPubKey srcpub, destpub; std::vector > txids; + CTransaction channelOpenTx; + numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -140,6 +230,43 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { txid = tx.GetHash(); memcpy(hash,&txid,sizeof(hash)); + + if ( (funcid = DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, srcpub, destpub, param1, param2, param3)) != 0) + { + switch ( funcid ) + { + case 'O': + if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) + return eval->Invalid("vin.0 is normal for channelOpen"); + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.0 is CC for channelOpen"); + else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.1 is CC for channelOpen"); + else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.2 is CC for channelOpen"); + else if ( numpayments > 1000) + return eval->Invalid("too many payment increments"); + else if ( tx.vout[0].nValue != param1 * param2) + return eval->Invalid("tx funds do not match sum of payments"); + break; + case 'C': + break; + case 'P': + DecodeChannelsPaymentOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, prevtxid, srcpub, destpub, param1, param2, param3); + if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) + return eval->Invalid("vin.0 is normal for channelOpen"); + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.0 is CC for channelOpen"); + + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) + { + return (false); + } + break; + case 'R': + break; + } + } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"Channelsget validated\n"); @@ -152,57 +279,57 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -CScript EncodeChannelsOpRet(uint8_t funcid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) +int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, uint256 prevtxid) { - CScript opret; uint8_t evalcode = EVAL_CHANNELS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << srcpub << destpub << numpayments << payment << hashchain); - return(opret); -} - -uint8_t DecodeChannelsOpRet(uint256 txid,const CScript &scriptPubKey,CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) -{ - std::vector vopret; uint8_t *script,e,f,funcid; - GetOpReturnData(scriptPubKey, vopret); - if ( vopret.size() > 2 ) - { - script = (uint8_t *)vopret.data(); - if ( script[0] == EVAL_CHANNELS ) - { - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> srcpub; ss >> destpub; ss >> numpayments; ss >> payment; ss >> hashchain) != 0 ) - { - return(f); - } - } else fprintf(stderr,"script[0] %02x != EVAL_CHANNELS\n",script[0]); - } else fprintf(stderr,"not enough opret.[%d]\n",(int32_t)vopret.size()); - return(0); -} - -int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) -{ - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t param2,totalinputs = 0; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t funcid,param1,numvouts,vout; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); + CPubKey srcpub,destpub; + + GetCCaddress1of2(cp,coinaddr,srcpub,destpub); SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0) { - if ( (nValue= IsChannelsvout(cp,vintx,vout)) > 0 && 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) ) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 && prevtxid==tmp_txid) + if ( (totalinputs=IsChannelsvout(cp,tx,vout)) > 0) + { + txid = it->first.txhash; + vout = 0; break; + } + } + } + + if (myIsutxo_spentinmempool(txid,vout) != 0) + { + txid=zeroid; + int32_t mindepth=1000; + + BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + { + const CTransaction &txmempool = e.GetTx(); + const uint256 &hash = tx.GetHash(); + if ((numvouts=txmempool.vout.size()) > 0 && + (funcid=DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && + funcid=='P' && param1 < mindepth) + { + txid=hash; + vout=0; + totalinputs=txmempool.vout[vout].nValue; + mindepth=param1; + } } } - return(totalinputs); + + if (txid != zeroid) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + return totalinputs; + } + else return 0; } std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) @@ -232,12 +359,74 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',mypk,destpub,numpayments,payment,hashchain))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',zeroid,mypk,destpub,numpayments,payment,hashchain))); } return(""); } -std::string ChannelStop(uint64_t txfee,CPubKey destpub,uint256 origtxid) +std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 opentxid,int32_t numpayments) +{ + CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,secret,hashblock,entropy,hentropy,param3; + struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,param1; + int64_t param2,payment,change,funds; + uint8_t hash[32],hashdest[32]; + CTransaction channelOpenTx,prevTx; + + if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsPaymentOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, txid, srcpub, destpub, param1, param2, param3)) != 0) && (funcid == 'O' || funcid == 'P')) + { + if (mypk != srcpub || mypk != destpub) + { + fprintf(stderr,"this is not our channel\n"); + return(""); + } + + prevdepth=param1; + payment=param2; + } + else + { + fprintf(stderr,"invalid previous txid\n"); + return(""); + } + + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) + { + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < prevdepth-numpayments; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); + } + else + { + fprintf(stderr,"invalid channel open txid\n"); + return(""); + } + } + // verify lasttxid and origtxid match and src is me + // also verify hashchain depth and amount, set prevdepth + cp = CCinit(&C,EVAL_CHANNELS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + if ((funds=AddChannelsInputs(cp,mtx,prevtxid)) != 0 && (change=funds-numpayments*payment)>=0) { + mtx.vout.push_back(CTxOut(numpayments * payment, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS, txfee, mypk)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); + return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsPaymentOpRet('P', opentxid, prevtxid, mypk, destpub, prevdepth - numpayments, payment, secret))); + } + } + return(""); +} + +std::string ChannelClose(uint64_t txfee,uint256 prevtxid,uint256 opentxid,CPubKey destpub) { CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; // verify this is one of our outbound channels @@ -248,49 +437,12 @@ std::string ChannelStop(uint64_t txfee,CPubKey destpub,uint256 origtxid) if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',mypk,destpub,0,0,zeroid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',opentxid,mypk,destpub,0,0,zeroid))); } return(""); } -std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 origtxid,int32_t n,int64_t amount) -{ - CMutableTransaction mtx; CPubKey mypk,destpub; uint256 secret; struct CCcontract_info *cp,C; int32_t prevdepth; - // verify lasttxid and origtxid match and src is me - // also verify hashchain depth and amount, set prevdepth - cp = CCinit(&C,EVAL_CHANNELS); - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) - { - // add locked funds inputs - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('P',mypk,destpub,prevdepth-n,amount,secret))); - } - return(""); -} - -std::string ChannelCollect(uint64_t txfee,uint256 paytxid,uint256 origtxid,int32_t n,int64_t amount) -{ - CMutableTransaction mtx; CPubKey mypk,senderpub; struct CCcontract_info *cp,C; int32_t prevdepth; - // verify paytxid and origtxid match and dest is me - // also verify hashchain depth and amount - cp = CCinit(&C,EVAL_CHANNELS); - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) - { - // add locked funds inputs - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',senderpub,mypk,prevdepth-n,amount,paytxid))); - } - return(""); -} - -std::string ChannelRefund(uint64_t txfee,uint256 stoptxid,uint256 origtxid) +std::string ChannelRefund(uint64_t txfee,uint256 closetxid,uint256 opentxid) { CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t amount; // verify stoptxid and origtxid match and are mine @@ -302,14 +454,14 @@ std::string ChannelRefund(uint64_t txfee,uint256 stoptxid,uint256 origtxid) { mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',mypk,mypk,0,0,stoptxid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,mypk,0,0,closetxid))); } return(""); } UniValue ChannelsInfo() { - UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,hashBlock,hashchain; struct CCcontract_info *cp,C; uint8_t funcid; char myCCaddr[64]; int32_t vout,numvouts,numpayments; int64_t nValue,payment; CPubKey srcpub,destpub,mypk; + UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,hashBlock,hashchain,opentxid; struct CCcontract_info *cp,C; uint8_t funcid; char myCCaddr[64]; int32_t vout,numvouts,numpayments; int64_t nValue,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; result.push_back(Pair("result","success")); result.push_back(Pair("name","Channels")); @@ -325,7 +477,7 @@ UniValue ChannelsInfo() nValue = (int64_t)it->second; if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeChannelsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,srcpub,destpub,numpayments,payment,hashchain) == 'O' || funcid == 'P' ) + if ( DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'O' || funcid == 'P' ) { char str[67],str2[67]; fprintf(stderr,"%s func.%c %s -> %s %.8f num.%d of %.8f\n",mypk == srcpub ? "send" : "recv",funcid,pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(double)tx.vout[0].nValue/COIN,numpayments,(double)payment/COIN); From c2fa2759d61cc39a7e55b3365eed7a7b7cc20642 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 14 Sep 2018 22:36:10 +0200 Subject: [PATCH 149/749] Small fixes --- src/cc/CCchannels.h | 7 ++-- src/cc/channels.cpp | 78 +++++++++++++++++++++++++++++----------- src/rpcserver.cpp | 3 +- src/rpcserver.h | 4 +-- src/wallet/rpcwallet.cpp | 58 +++++++++--------------------- 5 files changed, 80 insertions(+), 70 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 26057457f..ba31883a2 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -22,10 +22,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment); -std::string ChannelStop(uint64_t txfee,CPubKey destpub,uint256 origtxid); -std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 origtxid,int32_t n,int64_t amount); -std::string ChannelCollect(uint64_t txfee,uint256 paytxid,uint256 origtxid,int32_t n,int64_t amount); -std::string ChannelRefund(uint64_t txfee,uint256 stoptxid,uint256 origtxid); +std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int64_t amount); +std::string ChannelClose(uint64_t txfee,uint256 opentxid); +std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); // CCcustom UniValue ChannelsInfo(); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 0ecd6a1be..01a422715 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -244,7 +244,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vout.1 is CC for channelOpen"); else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.2 is CC for channelOpen"); - else if ( numpayments > 1000) + else if ( numpayments > CHANNELS_MAXPAYMENTS) return eval->Invalid("too many payment increments"); else if ( tx.vout[0].nValue != param1 * param2) return eval->Invalid("tx funds do not match sum of payments"); @@ -287,7 +287,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, u GetCCaddress1of2(cp,coinaddr,srcpub,destpub); SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0) @@ -301,12 +300,10 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, u } } } - if (myIsutxo_spentinmempool(txid,vout) != 0) { txid=zeroid; int32_t mindepth=1000; - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) { const CTransaction &txmempool = e.GetTx(); @@ -323,7 +320,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, u } } } - if (txid != zeroid) { mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -344,6 +340,8 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 cp = CCinit(&C,EVAL_CHANNELS); if ( txfee == 0 ) txfee = 10000; + if (numpayments>CHANNELS_MAXPAYMENTS) + return (""); mypk = pubkey2pk(Mypubkey()); funds = numpayments * payment; if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 ) @@ -364,38 +362,78 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 return(""); } -std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 opentxid,int32_t numpayments) +std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int64_t amount) { CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,secret,hashblock,entropy,hentropy,param3; - struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,param1; + struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,param1; int64_t param2,payment,change,funds; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; - if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + if (opentxid==prevtxid) { - if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsPaymentOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, txid, srcpub, destpub, param1, param2, param3)) != 0) && (funcid == 'O' || funcid == 'P')) + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) { - if (mypk != srcpub || mypk != destpub) + if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) != 0) && funcid == 'O') + { + if (mypk == srcpub || mypk == destpub) + { + prevdepth=param1; + payment=param2; + } + else + { + fprintf(stderr,"this is not our channel\n"); + return(""); + } + } + else + { + fprintf(stderr,"invalid previous txid\n"); + return(""); + } + if (amount % payment != 0) + return (""); + numpayments=amount/payment; + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < numpayments; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); + + } + } + else if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsPaymentOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, txid, srcpub, destpub, param1, param2, param3)) != 0) && funcid == 'P') + { + if (mypk == srcpub || mypk == destpub) + { + prevdepth=param1; + payment=param2; + } + else { fprintf(stderr,"this is not our channel\n"); return(""); } - - prevdepth=param1; - payment=param2; } else { fprintf(stderr,"invalid previous txid\n"); return(""); } - + if ((numpayments=amount % payment) != 0) + return (""); + numpayments=amount/payment; if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < prevdepth-numpayments; i++) + for (i = 0; i < numpayments; i++) { vcalc_sha256(0, hashdest, hash, 32); memcpy(hash, hashdest, 32); @@ -416,8 +454,8 @@ std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 opentxid,int3 mypk = pubkey2pk(Mypubkey()); if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,prevtxid)) != 0 && (change=funds-numpayments*payment)>=0) { - mtx.vout.push_back(CTxOut(numpayments * payment, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); + if ((funds=AddChannelsInputs(cp,mtx,prevtxid)) != 0 && (change=funds-amount)>=0) { + mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS, txfee, mypk)); mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsPaymentOpRet('P', opentxid, prevtxid, mypk, destpub, prevdepth - numpayments, payment, secret))); @@ -426,7 +464,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 prevtxid,uint256 opentxid,int3 return(""); } -std::string ChannelClose(uint64_t txfee,uint256 prevtxid,uint256 opentxid,CPubKey destpub) +std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; // verify this is one of our outbound channels @@ -437,12 +475,12 @@ std::string ChannelClose(uint64_t txfee,uint256 prevtxid,uint256 opentxid,CPubKe if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',opentxid,mypk,destpub,0,0,zeroid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',opentxid,mypk,mypk,0,0,zeroid))); } return(""); } -std::string ChannelRefund(uint64_t txfee,uint256 closetxid,uint256 opentxid) +std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t amount; // verify stoptxid and origtxid match and are mine diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 8934ae717..7d2eab1e3 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -383,8 +383,7 @@ static const CRPCCommand vRPCCommands[] = { "channels", "channelsinfo", &channelsinfo, true }, { "channels", "channelsopen", &channelsopen, true }, { "channels", "channelspayment", &channelspayment, true }, - { "channels", "channelscollect", &channelscollect, true }, - { "channels", "channelsstop", &channelsstop, true }, + { "channels", "channelsclose", &channelsclose, true }, { "channels", "channelsrefund", &channelsrefund, true }, /* Oracles */ diff --git a/src/rpcserver.h b/src/rpcserver.h index f4c502d63..a78f1b6fc 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -254,11 +254,9 @@ extern UniValue gatewayspending(const UniValue& params, bool fHelp); extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp); extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp); extern UniValue channelsinfo(const UniValue& params, bool fHelp); -extern UniValue channelsbind(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); extern UniValue channelspayment(const UniValue& params, bool fHelp); -extern UniValue channelscollect(const UniValue& params, bool fHelp); -extern UniValue channelsstop(const UniValue& params, bool fHelp); +extern UniValue channelsclose(const UniValue& params, bool fHelp); extern UniValue channelsrefund(const UniValue& params, bool fHelp); //extern UniValue tokenswapask(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8f64d093d..c105b4872 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5153,42 +5153,21 @@ UniValue channelsopen(const UniValue& params, bool fHelp) return(result); } -UniValue channelsstop(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); std::vector destpub; struct CCcontract_info *cp,C; std::string hex; uint256 origtxid; - cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 2 ) - throw runtime_error("channelsstop destpubkey origtxid\n"); - if ( ensure_CCrequirements() < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - destpub = ParseHex(params[0].get_str().c_str()); - origtxid = Parseuint256((char *)params[1].get_str().c_str()); - hex = ChannelStop(0,pubkey2pk(destpub),origtxid); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelsstop transaction"); - return(result); -} - UniValue channelspayment(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 origtxid,prevtxid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,prevtxid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 4 ) - throw runtime_error("channelspayment prevtxid origtxid n amount\n"); + throw runtime_error("channelspayment opentxid prevtxid amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - prevtxid = Parseuint256((char *)params[0].get_str().c_str()); - origtxid = Parseuint256((char *)params[1].get_str().c_str()); + opentxid = Parseuint256((char *)params[0].get_str().c_str()); + prevtxid = Parseuint256((char *)params[1].get_str().c_str()); n = atoi((char *)params[2].get_str().c_str()); amount = atoi((char *)params[3].get_str().c_str()); - hex = ChannelPayment(0,prevtxid,origtxid,n,amount); + hex = ChannelPayment(0,opentxid,prevtxid,amount); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5197,42 +5176,39 @@ UniValue channelspayment(const UniValue& params, bool fHelp) return(result); } -UniValue channelscollect(const UniValue& params, bool fHelp) +UniValue channelsclose(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 origtxid,paytxid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 4 ) - throw runtime_error("channelscollect paytxid origtxid n amount\n"); + if ( fHelp || params.size() != 2 ) + throw runtime_error("channelsclose opentxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - paytxid = Parseuint256((char *)params[0].get_str().c_str()); - origtxid = Parseuint256((char *)params[1].get_str().c_str()); - n = atoi((char *)params[2].get_str().c_str()); - amount = atoi((char *)params[3].get_str().c_str()); - hex = ChannelCollect(0,paytxid,origtxid,n,amount); + opentxid = Parseuint256((char *)params[1].get_str().c_str()); + hex = ChannelClose(0,opentxid); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelscollect transaction"); + } else ERR_RESULT("couldnt create channelsstop transaction"); return(result); } UniValue channelsrefund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 origtxid,stoptxid; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,closetxid; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) - throw runtime_error("channelsrefund stoptxid origtxid\n"); + throw runtime_error("channelsrefund opentxid closetxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - stoptxid = Parseuint256((char *)params[0].get_str().c_str()); - origtxid = Parseuint256((char *)params[1].get_str().c_str()); - hex = ChannelRefund(0,stoptxid,origtxid); + opentxid = Parseuint256((char *)params[0].get_str().c_str()); + closetxid = Parseuint256((char *)params[1].get_str().c_str()); + hex = ChannelRefund(0,opentxid,closetxid); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From 5aa6428feba6f92cf4fa204e5ed476d88f5c0390 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sat, 15 Sep 2018 11:22:48 +0200 Subject: [PATCH 150/749] - Fixes --- src/cc/channels.cpp | 150 ++++++++++++++++++++++----------------- src/wallet/rpcwallet.cpp | 4 +- 2 files changed, 85 insertions(+), 69 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 01a422715..744c223d1 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -128,10 +128,9 @@ uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubK if ( script[0] == EVAL_CHANNELS ) { funcid = script[1]; - //fprintf(stderr,"decode.[%c]\n",funcid); switch ( funcid ) { - case 'c': + case 'O': return(funcid); break; default: @@ -171,37 +170,12 @@ uint8_t DecodeChannelsPaymentOpRet(const CScript &scriptPubKey,uint256 &opentxid return(0); } -//bool GetChannelOpenTx(struct CCcontract_info *cp, CTransaction &channelOpenTx, CPubKey srcpub, CPubKey destpub, int32_t &numpayments, int64_t &payment, uint256 &hashchain) -//{ -// uint256 txid, hashBlock, origtxid; -// char CCaddr[64]; -// std::vector > txids; -// uint8_t funcid; -// CPubKey opensrcpub, opendestpub; -// int32_t numvouts; -// -// GetCCaddress1of2(cp,CCaddr,srcpub,destpub); -// SetCCtxids(txids,CCaddr); -// -// for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) -// { -// txid=it->first.txhash; -// if (GetTransaction(txid,channelOpenTx,hashBlock,false) != 0 && (numvouts= channelOpenTx.vout.size()) > 0) -// { -// if (((funcid = DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,origtxid,opensrcpub,opendestpub,numpayments,payment,hashchain)) != 0) && (funcid == 'O') && (srcpub==opensrcpub && (destpub==opendestpub))) -// { -// return true; -// } -// } -// } -// -// return false; -//} - bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,param1,numpayments; bool retval; uint256 txid,hashblock,param3,hashchain,opentxid,prevtxid; uint8_t funcid, hash[32]; char str[65],destaddr[64]; - int64_t param2,payment; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,param1,depth; bool retval; + uint256 txid,hashblock,param3,opentxid,prevtxid,entropy,hentropy,secret,gensecret,genhashchain; + uint8_t funcid,hash[32],hashdest[32]; + int64_t param2,numpayments; CPubKey srcpub, destpub; std::vector > txids; CTransaction channelOpenTx; @@ -236,34 +210,72 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & switch ( funcid ) { case 'O': - if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) - return eval->Invalid("vin.0 is normal for channelOpen"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for channelOpen"); - else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for channelOpen"); - else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.2 is CC for channelOpen"); - else if ( numpayments > CHANNELS_MAXPAYMENTS) - return eval->Invalid("too many payment increments"); - else if ( tx.vout[0].nValue != param1 * param2) - return eval->Invalid("tx funds do not match sum of payments"); - break; - case 'C': + //vin.0: normal input + //vout.0: CC vout for channel funding on CC1of2 pubkey + //vout.1: CC vout marker to senders pubKey + //vout.2: CC vout marker to receiver pubkey + //vout.3: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain + return eval->Invalid("unexpected ChannelsValidate for channelopen"); break; case 'P': - DecodeChannelsPaymentOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, prevtxid, srcpub, destpub, param1, param2, param3); - if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) - return eval->Invalid("vin.0 is normal for channelOpen"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for channelOpen"); - - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) + //vin.0: normal input + //vin.1: CC input from channel funding + //vout.0: normal output of payment amount to receiver pubkey + //vout.1: CC vout change to CC1of2 pubkey + //vout.n-2: CC vout marker to payment issuer + //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret + if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for channelPayment"); + else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) + return eval->Invalid("vin.1 is CC for channelPayment"); + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 ) + return eval->Invalid("vout.0 is normal for channelPayment"); + else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.1 is CC for channelPayment"); + else if ( tx.vout.size() == 4 && tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.2 is CC for channelPayment"); + else if (DecodeChannelsPaymentOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, prevtxid, srcpub, destpub, depth, numpayments, secret) != 'P') + return eval->Invalid("invalid OP_RETURN data"); + else if ( tx.vout[0].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) + return eval->Invalid("payment funds do not go to receiver"); + else if ( param2 > CHANNELS_MAXPAYMENTS) + return eval->Invalid("too many payment increments"); + else { - return (false); + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) + { + if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, opentxid, srcpub, destpub, param1, param2, param3)) != 0 && funcid!='O') + return eval->Invalid("invalid channelopen OP_RETURN data"); + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < param1; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + if (i==depth) endiancpy((uint8_t * ) & gensecret, hashdest, 32); + } + endiancpy((uint8_t * ) & genhashchain, hashdest, 32); + + if (secret!=gensecret) + return eval->Invalid("invalid secret for payment"); + else if (param3!=genhashchain) + return eval->Invalid("invalid secret for payment, does not reach final hashchain"); + else if (tx.vout[0].nValue != numpayments*param2) + return eval->Invalid("vout amount does not match numberofpayments*payment"); + } } break; + case 'C': + //vin.0: normal input for 2*txfee (normal fee and marker) + //vout.0: CC vout marker to senders pubKey + //vout.1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 + return eval->Invalid("unexpected ChannelsValidate for channelclose"); case 'R': + //vin.0: normal input + //vin.1: CC input from channel funding + //vout.0: normal output of CC input to senders pubkey + //vout.1: CC vout marker to senders pubKey + //vout.2: opreturn - 'R' opentxid senderspubkey receiverspubkey 0 0 closetxid break; } } @@ -333,18 +345,16 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk; struct CCcontract_info *cp,C; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { - CCerror = strprintf("invalid ChannelsFund param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment); + CCerror = strprintf("invalid ChannelOpen param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment); fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } cp = CCinit(&C,EVAL_CHANNELS); if ( txfee == 0 ) txfee = 10000; - if (numpayments>CHANNELS_MAXPAYMENTS) - return (""); mypk = pubkey2pk(Mypubkey()); funds = numpayments * payment; - if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 ) + if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); endiancpy(hash,(uint8_t *)&hentropy,32); @@ -355,8 +365,6 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 } endiancpy((uint8_t *)&hashchain,hashdest,32); mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',zeroid,mypk,destpub,numpayments,payment,hashchain))); } return(""); @@ -393,7 +401,10 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int6 return(""); } if (amount % payment != 0) + { + fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); return (""); + } numpayments=amount/payment; hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); @@ -426,14 +437,17 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int6 fprintf(stderr,"invalid previous txid\n"); return(""); } - if ((numpayments=amount % payment) != 0) + if (amount % payment != 0) + { + fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); return (""); + } numpayments=amount/payment; if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < numpayments; i++) + for (i = 0; i < prevdepth-numpayments; i++) { vcalc_sha256(0, hashdest, hash, 32); memcpy(hash, hashdest, 32); @@ -452,15 +466,19 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int6 if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { if ((funds=AddChannelsInputs(cp,mtx,prevtxid)) != 0 && (change=funds-amount)>=0) { mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS, txfee, mypk)); mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsPaymentOpRet('P', opentxid, prevtxid, mypk, destpub, prevdepth - numpayments, payment, secret))); + } else + { + fprintf(stderr,"error adding CC inputs\n"); + return(""); } } + fprintf(stderr,"error adding normal inputs\n"); return(""); } @@ -472,9 +490,8 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',opentxid,mypk,mypk,0,0,zeroid))); } return(""); @@ -488,9 +505,8 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,mypk,0,0,closetxid))); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c105b4872..3aa736a16 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5157,7 +5157,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,prevtxid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 4 ) + if ( fHelp || params.size() != 3 ) throw runtime_error("channelspayment opentxid prevtxid amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5180,7 +5180,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid; cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 2 ) + if ( fHelp || params.size() != 1 ) throw runtime_error("channelsclose opentxid\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From f2cf63f98b238ca8c20d66c019ea608bdb9c02a1 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sat, 15 Sep 2018 11:42:21 +0200 Subject: [PATCH 151/749] fix --- src/wallet/rpcwallet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3aa736a16..a126c780e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5165,8 +5165,7 @@ UniValue channelspayment(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); prevtxid = Parseuint256((char *)params[1].get_str().c_str()); - n = atoi((char *)params[2].get_str().c_str()); - amount = atoi((char *)params[3].get_str().c_str()); + amount = atoi((char *)params[2].get_str().c_str()); hex = ChannelPayment(0,opentxid,prevtxid,amount); if ( hex.size() > 0 ) { From 93346f25d9341f83af6e41c86a786d363b5b0d9e Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sun, 16 Sep 2018 22:44:08 +0200 Subject: [PATCH 152/749] - Fixing payment, open, validate .... --- src/cc/CCchannels.h | 2 +- src/cc/CCinclude.h | 1 + src/cc/CCtx.cpp | 6 +- src/cc/channels.cpp | 409 ++++++++++++++++++--------------------- src/wallet/rpcwallet.cpp | 9 +- 5 files changed, 200 insertions(+), 227 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index ba31883a2..6988b5913 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -22,7 +22,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment); -std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int64_t amount); +std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount); std::string ChannelClose(uint64_t txfee,uint256 opentxid); std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 7ac0bfb98..2c3c6f5e6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -125,6 +125,7 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv); CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk); CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); +CC *MakeCCcond1of2(uint8_t evalcode,CPubKey pk1,CPubKey pk2); CC* GetCryptoCondition(CScript const& scriptSig); void CCaddr2set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); void CCaddr3set(struct CCcontract_info *cp,uint8_t evalcode,CPubKey pk,uint8_t *priv,char *coinaddr); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a9d3f68e7..f1ee0b309 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -119,12 +119,14 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran cond = othercond; //fprintf(stderr,"unspendable CC addr.(%s)\n",unspendable); } - else if ( strcmp(destaddr,cp->unspendableaddr2) == 0 ) + else if ( strcmp(destaddr,cp->unspendableaddr2) == 0) { //fprintf(stderr,"matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; - if ( othercond2 == 0 ) + if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS) othercond2 = MakeCCcond1(cp->evalcode2,cp->unspendablepk2); + else if ( othercond2 == 0 && cp->evalcode == EVAL_CHANNELS) + othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); cond = othercond2; } else if ( strcmp(destaddr,cp->unspendableaddr3) == 0 ) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 744c223d1..21249a7e9 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -62,55 +62,19 @@ Possible third iteration: // start of consensus code -int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub, CPubKey destpub,int32_t v) { - char destaddr[64]; + char destaddr[64],channeladdr[64]; + + GetCCaddress1of2(cp,channeladdr,srcpub,destpub); if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,channeladdr) == 0 ) return(tx.vout[v].nValue); } return(0); } -bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) -{ - static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) - { - //fprintf(stderr,"vini.%d check mempool\n",i); - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - //fprintf(stderr,"vini.%d check hash and vout\n",i); - if ( hashBlock == zerohash ) - return eval->Invalid("cant Channels from mempool"); - if ( (assetoshis= IsChannelsvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) - inputs += assetoshis; - } - } - } - for (i=0; iInvalid("mismatched inputs != outputs + txfee"); - } - else return(true); -} - CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) { CScript opret; uint8_t evalcode = EVAL_CHANNELS; @@ -119,40 +83,6 @@ CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubK } uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) -{ - std::vector vopret; uint8_t *script,e,f,funcid; - GetOpReturnData(scriptPubKey, vopret); - if ( vopret.size() > 2 ) - { - script = (uint8_t *)vopret.data(); - if ( script[0] == EVAL_CHANNELS ) - { - funcid = script[1]; - switch ( funcid ) - { - case 'O': - return(funcid); - break; - default: - if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> opentxid; ss >> srcpub; ss >> destpub; ss >> numpayments; ss >> payment; ss >> hashchain) != 0 ) - { - return(f); - } - break; - } - } else fprintf(stderr,"script[0] %02x != EVAL_CHANNELS\n",script[0]); - } else fprintf(stderr,"not enough opret.[%d]\n",(int32_t)vopret.size()); - return(0); -} - -CScript EncodeChannelsPaymentOpRet(uint8_t funcid,uint256 opentxid,uint256 prevtxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) -{ - CScript opret; uint8_t evalcode = EVAL_CHANNELS; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << opentxid << prevtxid << srcpub << destpub << numpayments << payment << hashchain); - return(opret); -} - -uint8_t DecodeChannelsPaymentOpRet(const CScript &scriptPubKey,uint256 &opentxid,uint256 &prevtxid,CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) { std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey, vopret); @@ -170,12 +100,61 @@ uint8_t DecodeChannelsPaymentOpRet(const CScript &scriptPubKey,uint256 &opentxid return(0); } +bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +{ + static uint256 zerohash; + uint256 txid,param3; + CPubKey srcpub,destpub; + int32_t param1; int64_t param2; uint8_t funcid; + CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; + numvins = tx.vin.size(); + numvouts = tx.vout.size(); + + if ((numvouts=tx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) !=0) + { + for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) + { + //fprintf(stderr,"vini.%d check mempool\n",i); + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else + { + //fprintf(stderr,"vini.%d check hash and vout\n",i); + if ( hashBlock == zerohash ) + return eval->Invalid("cant Channels from mempool"); + if ( (assetoshis= IsChannelsvout(cp,vinTx,srcpub,destpub,tx.vin[i].prevout.n)) != 0 ) + inputs += assetoshis; + } + } + } + } + else + { + return eval->Invalid("invalid op_return data"); + } + for (i=0; iInvalid("mismatched inputs != outputs + txfee"); + } + else return(true); +} + bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,param1,depth; bool retval; - uint256 txid,hashblock,param3,opentxid,prevtxid,entropy,hentropy,secret,gensecret,genhashchain; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,param1; bool retval; + uint256 txid,hashblock,param3,opentxid,tmp_txid,entropy,hentropy,gensecret,genhashchain,hashchain; uint8_t funcid,hash[32],hashdest[32]; - int64_t param2,numpayments; + int64_t param2,payment; CPubKey srcpub, destpub; std::vector > txids; CTransaction channelOpenTx; @@ -183,17 +162,11 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; + fprintf(stderr,"validateCC\n"); if ( numvouts < 1 ) return eval->Invalid("no vouts"); else { - for (i=0; iInvalid("illegal normal vini"); - } - } //fprintf(stderr,"check amounts\n"); if ( ChannelsExactAmounts(cp,eval,tx,1,10000) == false ) { @@ -214,7 +187,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.0: CC vout for channel funding on CC1of2 pubkey //vout.1: CC vout marker to senders pubKey //vout.2: CC vout marker to receiver pubkey - //vout.3: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain + //vout.n-2: normal change + //vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain return eval->Invalid("unexpected ChannelsValidate for channelopen"); break; case 'P': @@ -222,45 +196,48 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vin.1: CC input from channel funding //vout.0: normal output of payment amount to receiver pubkey //vout.1: CC vout change to CC1of2 pubkey - //vout.n-2: CC vout marker to payment issuer + //vout.2: CC vout marker to payment issuer + //vout.n-2: normal change //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelPayment"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelPayment"); - else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 ) - return eval->Invalid("vout.0 is normal for channelPayment"); - else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for channelPayment"); - else if ( tx.vout.size() == 4 && tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.2 is CC for channelPayment"); - else if (DecodeChannelsPaymentOpRet(tx.vout[numvouts-1].scriptPubKey, opentxid, prevtxid, srcpub, destpub, depth, numpayments, secret) != 'P') - return eval->Invalid("invalid OP_RETURN data"); - else if ( tx.vout[0].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) - return eval->Invalid("payment funds do not go to receiver"); - else if ( param2 > CHANNELS_MAXPAYMENTS) + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.0 is CC for channelPayment"); + else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) + return eval->Invalid("vout.1 is normal for channelPayment"); +// else if ( tx.vout.size() == 4 && tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) +// return eval->Invalid("vout.2 is CC for channelPayment"); + else if ( tx.vout[1].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) + return eval->Invalid("payment funds do not go to receiver -"); + else if ( param1 > CHANNELS_MAXPAYMENTS) return eval->Invalid("too many payment increments"); else { if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) { - if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, opentxid, srcpub, destpub, param1, param2, param3)) != 0 && funcid!='O') + if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') return eval->Invalid("invalid channelopen OP_RETURN data"); hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < param1; i++) + for (i = 0; i < numpayments; i++) { vcalc_sha256(0, hashdest, hash, 32); memcpy(hash, hashdest, 32); - if (i==depth) endiancpy((uint8_t * ) & gensecret, hashdest, 32); + if (i==param1-1) + { + endiancpy((uint8_t*)&gensecret,hashdest,32); + } } - endiancpy((uint8_t * ) & genhashchain, hashdest, 32); + endiancpy((uint8_t*)&genhashchain,hashdest,32); - if (secret!=gensecret) + fprintf(stderr,"gensecret=%s secret=%s genhashchain=%s hashchain=%s\n",gensecret.ToString().c_str(),param3.ToString().c_str(),genhashchain.ToString().c_str(),hashchain.ToString().c_str()); + if (param3!=gensecret) return eval->Invalid("invalid secret for payment"); - else if (param3!=genhashchain) + else if (hashchain!=genhashchain) return eval->Invalid("invalid secret for payment, does not reach final hashchain"); - else if (tx.vout[0].nValue != numpayments*param2) + else if (tx.vout[0].nValue != param1*payment) return eval->Invalid("vout amount does not match numberofpayments*payment"); } } @@ -291,31 +268,58 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & // helper functions for rpc calls in rpcwallet.cpp -int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, uint256 prevtxid) +int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid) { - char coinaddr[64]; int64_t param2,totalinputs = 0; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t funcid,param1,numvouts,vout; + char coinaddr[64]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t funcid,param1; std::vector > unspentOutputs; CPubKey srcpub,destpub; + uint8_t myprivkey[32]; + + //fprintf(stderr,"numvouts=%d decode=%c\n",numvouts=openTx.vout.size(),DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)); + + if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') + { + GetCCaddress1of2(cp,coinaddr,srcpub,destpub); + SetCCunspents(unspentOutputs,coinaddr); + Myprivkey(myprivkey); + CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr); + CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr); + } + else + { + fprintf(stderr,"invalid open tx id\n"); + return 0; + } - GetCCaddress1of2(cp,coinaddr,srcpub,destpub); - SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0) + fprintf(stderr,"txhash: %d\n",it->first.txhash); + if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 && prevtxid==tmp_txid) - if ( (totalinputs=IsChannelsvout(cp,tx,vout)) > 0) - { - txid = it->first.txhash; - vout = 0; - break; - } + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) + { + txid = it->first.txhash; + break; + } } } - if (myIsutxo_spentinmempool(txid,vout) != 0) + +// fprintf(stderr,"prevtxid=%s , GetTX=%d\n",prevtxid.ToString().c_str(),GetTransaction(prevtxid,tx,hashBlock,false)); +// if (GetTransaction(prevtxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) +// { +// fprintf(stderr,"prevtxid=%s decode=%c total=%d\n",prevtxid.ToString().c_str(),DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3),IsChannelsvout(cp,tx,srcpub,destpub,0)); +// if ((funcid=DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)) > 0) +// { +// //if (funcid='P') DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,tmp_txid,srcpub,destpub,param1,param2,param3) +// txid=prevtxid; +// fprintf(stderr,"found utxo, txid=%d, funds=%d\n",txid,totalinputs); +// } +// } + if (myIsutxo_spentinmempool(txid,0) != 0) { + fprintf(stderr,"spent in mempool\n"); txid=zeroid; - int32_t mindepth=1000; + int32_t mindepth=CHANNELS_MAXPAYMENTS; BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) { const CTransaction &txmempool = e.GetTx(); @@ -325,24 +329,25 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, u funcid=='P' && param1 < mindepth) { txid=hash; - vout=0; - totalinputs=txmempool.vout[vout].nValue; + totalinputs=txmempool.vout[0].nValue; mindepth=param1; } } } + else fprintf(stderr,"not spent in mempool\n"); if (txid != zeroid) { - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - return totalinputs; + prevtxid=txid; + mtx.vin.push_back(CTxIn(txid,0,CScript())); + return totalinputs; } else return 0; } std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) { - CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk,channelspk; struct CCcontract_info *cp,C; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { CCerror = strprintf("invalid ChannelOpen param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment); @@ -370,111 +375,77 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 return(""); } -std::string ChannelPayment(uint64_t txfee,uint256 opentxid,uint256 prevtxid,int64_t amount) +std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) { - CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,secret,hashblock,entropy,hentropy,param3; - struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,param1; - int64_t param2,payment,change,funds; + CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,secret,hashblock,entropy,hentropy,prevtxid; + struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments; + int64_t payment,change,funds; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; - if (opentxid==prevtxid) - { - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) - { - if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) != 0) && funcid == 'O') - { - if (mypk == srcpub || mypk == destpub) - { - prevdepth=param1; - payment=param2; - } - else - { - fprintf(stderr,"this is not our channel\n"); - return(""); - } - } - else - { - fprintf(stderr,"invalid previous txid\n"); - return(""); - } - if (amount % payment != 0) - { - fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); - return (""); - } - numpayments=amount/payment; - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < numpayments; i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & secret, hashdest, 32); - - } - } - else if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) - { - if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsPaymentOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, txid, srcpub, destpub, param1, param2, param3)) != 0) && funcid == 'P') - { - if (mypk == srcpub || mypk == destpub) - { - prevdepth=param1; - payment=param2; - } - else - { - fprintf(stderr,"this is not our channel\n"); - return(""); - } - } - else - { - fprintf(stderr,"invalid previous txid\n"); - return(""); - } - if (amount % payment != 0) - { - fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); - return (""); - } - numpayments=amount/payment; - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) - { - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < prevdepth-numpayments; i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & secret, hashdest, 32); - } - else - { - fprintf(stderr,"invalid channel open txid\n"); - return(""); - } - } - // verify lasttxid and origtxid match and src is me - // also verify hashchain depth and amount, set prevdepth cp = CCinit(&C,EVAL_CHANNELS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - if ((funds=AddChannelsInputs(cp,mtx,prevtxid)) != 0 && (change=funds-amount)>=0) { - mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); - return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsPaymentOpRet('P', opentxid, prevtxid, mypk, destpub, prevdepth - numpayments, payment, secret))); - } else + fprintf(stderr, "invalid channel open txid\n"); + return (""); + } + + if (AddNormalinputs(mtx,mypk,txfee,1) > 0) + { + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) { - fprintf(stderr,"error adding CC inputs\n"); + fprintf(stderr,"prevtxid=%s\n",prevtxid.ToString().c_str()); + if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, payment, hashchain)) != 0) && (funcid == 'P' || funcid=='O')) + { + if (mypk != srcpub && mypk != destpub) + { + fprintf(stderr,"this is not our channel\n"); + return(""); + } + else if (amount % payment != 0) + { + fprintf(stderr,"invalid amount, not a magnitude of payment size - %d %d\n",amount,payment); + return (""); + } + } + else + { + fprintf(stderr,"invalid previous tx\n"); + return(""); + } + + numpayments=amount/payment; + + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < prevdepth-numpayments; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); + } + else + { + fprintf(stderr, "cannot find previous tx (channel open or payment)\n"); + return (""); + } + // verify lasttxid and origtxid match and src is me + // also verify hashchain depth and amount, set prevdepth + + mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); + mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); + return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, mypk, destpub, prevdepth - numpayments, payment, secret))); + } + else + { + fprintf(stderr,"error adding CC inputs: funds=%d change=%d\n",funds,change); return(""); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a126c780e..1e342fc84 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5157,16 +5157,15 @@ UniValue channelspayment(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,prevtxid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); - if ( fHelp || params.size() != 3 ) - throw runtime_error("channelspayment opentxid prevtxid amount\n"); + if ( fHelp || params.size() != 2 ) + throw runtime_error("channelspayment opentxid amount\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); - prevtxid = Parseuint256((char *)params[1].get_str().c_str()); - amount = atoi((char *)params[2].get_str().c_str()); - hex = ChannelPayment(0,opentxid,prevtxid,amount); + amount = atoi((char *)params[1].get_str().c_str()); + hex = ChannelPayment(0,opentxid,amount); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From acd84a38985130811fb3e69a9c3799f56d693d5b Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sun, 16 Sep 2018 22:47:47 +0200 Subject: [PATCH 153/749] fix --- src/cc/channels.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 21249a7e9..a064cefa6 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -293,7 +293,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - fprintf(stderr,"txhash: %d\n",it->first.txhash); if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) @@ -410,7 +409,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) } else if (amount % payment != 0) { - fprintf(stderr,"invalid amount, not a magnitude of payment size - %d %d\n",amount,payment); + fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); return (""); } } From 352856b87faca48ebe6c38202fdbc69dfabd5b69 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sun, 16 Sep 2018 22:50:54 +0200 Subject: [PATCH 154/749] fix --- src/cc/channels.cpp | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index a064cefa6..dcbeefc2a 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -232,7 +232,6 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } endiancpy((uint8_t*)&genhashchain,hashdest,32); - fprintf(stderr,"gensecret=%s secret=%s genhashchain=%s hashchain=%s\n",gensecret.ToString().c_str(),param3.ToString().c_str(),genhashchain.ToString().c_str(),hashchain.ToString().c_str()); if (param3!=gensecret) return eval->Invalid("invalid secret for payment"); else if (hashchain!=genhashchain) @@ -275,8 +274,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C CPubKey srcpub,destpub; uint8_t myprivkey[32]; - //fprintf(stderr,"numvouts=%d decode=%c\n",numvouts=openTx.vout.size(),DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)); - if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') { GetCCaddress1of2(cp,coinaddr,srcpub,destpub); @@ -302,18 +299,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C } } } - -// fprintf(stderr,"prevtxid=%s , GetTX=%d\n",prevtxid.ToString().c_str(),GetTransaction(prevtxid,tx,hashBlock,false)); -// if (GetTransaction(prevtxid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) -// { -// fprintf(stderr,"prevtxid=%s decode=%c total=%d\n",prevtxid.ToString().c_str(),DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3),IsChannelsvout(cp,tx,srcpub,destpub,0)); -// if ((funcid=DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)) > 0) -// { -// //if (funcid='P') DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,tmp_txid,srcpub,destpub,param1,param2,param3) -// txid=prevtxid; -// fprintf(stderr,"found utxo, txid=%d, funds=%d\n",txid,totalinputs); -// } -// } if (myIsutxo_spentinmempool(txid,0) != 0) { fprintf(stderr,"spent in mempool\n"); @@ -397,7 +382,6 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) { - fprintf(stderr,"prevtxid=%s\n",prevtxid.ToString().c_str()); if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) { if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, payment, hashchain)) != 0) && (funcid == 'P' || funcid=='O')) @@ -444,7 +428,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) } else { - fprintf(stderr,"error adding CC inputs: funds=%d change=%d\n",funds,change); + fprintf(stderr,"error adding CC inputs\n"); return(""); } } From 294b79f6bd66dcfd0d1b0f1fa8a820019d5f97b5 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sun, 16 Sep 2018 22:59:00 +0200 Subject: [PATCH 155/749] fix --- src/cc/channels.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index dcbeefc2a..396be12bc 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -220,21 +220,15 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') return eval->Invalid("invalid channelopen OP_RETURN data"); hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < numpayments; i++) + endiancpy(hash, (uint8_t * ) & param3, 32); + for (i = 0; i < numpayments-param1; i++) { vcalc_sha256(0, hashdest, hash, 32); memcpy(hash, hashdest, 32); - if (i==param1-1) - { - endiancpy((uint8_t*)&gensecret,hashdest,32); - } } endiancpy((uint8_t*)&genhashchain,hashdest,32); - if (param3!=gensecret) - return eval->Invalid("invalid secret for payment"); - else if (hashchain!=genhashchain) + if (hashchain!=genhashchain) return eval->Invalid("invalid secret for payment, does not reach final hashchain"); else if (tx.vout[0].nValue != param1*payment) return eval->Invalid("vout amount does not match numberofpayments*payment"); From e741f587f5bfcc7691732d174649dfc7fa3a2f49 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sun, 16 Sep 2018 23:13:06 +0200 Subject: [PATCH 156/749] fix deadlock --- src/cc/channels.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 396be12bc..298430b1a 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -215,7 +215,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("too many payment increments"); else { - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) != 0) + if (myGetTransaction(opentxid,channelOpenTx,hashblock) != 0) { if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') return eval->Invalid("invalid channelopen OP_RETURN data"); From dd3bcadec44aae7f316c548084d1c359680a81ad Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 20 Sep 2018 17:42:24 +0200 Subject: [PATCH 157/749] - adding markers for transactions --- src/cc/channels.cpp | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 298430b1a..de2227c1b 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -189,14 +189,15 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.2: CC vout marker to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain - return eval->Invalid("unexpected ChannelsValidate for channelopen"); + return eval->Invalid("unexpected ChannelsValidate for channelsopen"); break; case 'P': //vin.0: normal input //vin.1: CC input from channel funding - //vout.0: normal output of payment amount to receiver pubkey - //vout.1: CC vout change to CC1of2 pubkey - //vout.2: CC vout marker to payment issuer + //vout.0: CC vout change to CC1of2 pubkey + //vout.1: CC vout marker to senders pubKey + //vout.2: CC vout marker to receiver pubkey + //vout.3: normal output of payment amount to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) @@ -205,11 +206,13 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.1 is CC for channelPayment"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.0 is CC for channelPayment"); - else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) + else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)"); + else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.1 is CC for channelPayment (marker to dstPub)"); + else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) return eval->Invalid("vout.1 is normal for channelPayment"); -// else if ( tx.vout.size() == 4 && tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) -// return eval->Invalid("vout.2 is CC for channelPayment"); - else if ( tx.vout[1].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) + else if ( tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) return eval->Invalid("payment funds do not go to receiver -"); else if ( param1 > CHANNELS_MAXPAYMENTS) return eval->Invalid("too many payment increments"); @@ -239,13 +242,14 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vin.0: normal input for 2*txfee (normal fee and marker) //vout.0: CC vout marker to senders pubKey //vout.1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 - return eval->Invalid("unexpected ChannelsValidate for channelclose"); + return eval->Invalid("unexpected ChannelsValidate for channelsclose"); case 'R': //vin.0: normal input //vin.1: CC input from channel funding //vout.0: normal output of CC input to senders pubkey //vout.1: CC vout marker to senders pubKey //vout.2: opreturn - 'R' opentxid senderspubkey receiverspubkey 0 0 closetxid + return eval->Invalid("unexpected ChannelsValidate for channelsrefund"); break; } } @@ -337,7 +341,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 txfee = 10000; mypk = pubkey2pk(Mypubkey()); funds = numpayments * payment; - if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) + if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 ) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); endiancpy(hash,(uint8_t *)&hentropy,32); @@ -348,6 +352,8 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 } endiancpy((uint8_t *)&hashchain,hashdest,32); mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS,funds,mypk,destpub)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('O',zeroid,mypk,destpub,numpayments,payment,hashchain))); } return(""); @@ -372,7 +378,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) return (""); } - if (AddNormalinputs(mtx,mypk,txfee,1) > 0) + if (AddNormalinputs(mtx,mypk,3*txfee,1) > 0) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) { @@ -417,6 +423,8 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) // also verify hashchain depth and amount, set prevdepth mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, mypk, destpub, prevdepth - numpayments, payment, secret))); } @@ -463,7 +471,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) UniValue ChannelsInfo() { - UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,hashBlock,hashchain,opentxid; struct CCcontract_info *cp,C; uint8_t funcid; char myCCaddr[64]; int32_t vout,numvouts,numpayments; int64_t nValue,payment; CPubKey srcpub,destpub,mypk; + UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,hashBlock,hashchain,opentxid; struct CCcontract_info *cp,C; char myCCaddr[64]; int32_t vout,numvouts,numpayments; int64_t nValue,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; result.push_back(Pair("result","success")); result.push_back(Pair("name","Channels")); @@ -479,10 +487,15 @@ UniValue ChannelsInfo() nValue = (int64_t)it->second; if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'O' || funcid == 'P' ) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { char str[67],str2[67]; - fprintf(stderr,"%s func.%c %s -> %s %.8f num.%d of %.8f\n",mypk == srcpub ? "send" : "recv",funcid,pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(double)tx.vout[0].nValue/COIN,numpayments,(double)payment/COIN); + fprintf(stderr,"%s %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelOpen",pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'P') + { + char str[67],str2[67]; + fprintf(stderr,"%s (%s) %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelPayment",opentxid.ToString().c_str(),pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); } } } From 0e7a9780129b95f68aef42d0a436e4d430ef12f9 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 20 Sep 2018 17:45:28 +0200 Subject: [PATCH 158/749] - fix --- src/cc/channels.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index de2227c1b..1aaf2612f 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -490,12 +490,12 @@ UniValue ChannelsInfo() if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { char str[67],str2[67]; - fprintf(stderr,"%s %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelOpen",pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); + fprintf(stderr,"%s %s -> %s %\" PRId64 \"sat num.%d of %.8lldsat\n","ChannelOpen",pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'P') { char str[67],str2[67]; - fprintf(stderr,"%s (%s) %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelPayment",opentxid.ToString().c_str(),pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); + fprintf(stderr,"%s (%s) %s -> %s %\" PRId64 \"sat num.%d of %.8lldsat\n","ChannelPayment",opentxid.ToString().c_str(),pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); } } } From 7394c6247432e62bc1a8c11828b3ee0185be768c Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 20 Sep 2018 17:47:47 +0200 Subject: [PATCH 159/749] - fix --- src/cc/channels.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 1aaf2612f..7086f9cf9 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -490,12 +490,12 @@ UniValue ChannelsInfo() if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { char str[67],str2[67]; - fprintf(stderr,"%s %s -> %s %\" PRId64 \"sat num.%d of %.8lldsat\n","ChannelOpen",pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); + fprintf(stderr,"%s %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelOpen",pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(long long)tx.vout[0].nValue,numpayments,(long long)payment); } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'P') { char str[67],str2[67]; - fprintf(stderr,"%s (%s) %s -> %s %\" PRId64 \"sat num.%d of %.8lldsat\n","ChannelPayment",opentxid.ToString().c_str(),pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),tx.vout[0].nValue,numpayments,payment); + fprintf(stderr,"%s (%s) %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelPayment",opentxid.ToString().c_str(),pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(long long)tx.vout[0].nValue,numpayments,(long long)payment); } } } From 7340ace3b15f9bf87bb371ee639653f15ad3436f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 20 Sep 2018 22:14:10 +0200 Subject: [PATCH 160/749] test --- src/cc/channels.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 7086f9cf9..a30b04a30 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -168,7 +168,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else { //fprintf(stderr,"check amounts\n"); - if ( ChannelsExactAmounts(cp,eval,tx,1,10000) == false ) + if ( 0) //ChannelsExactAmounts(cp,eval,tx,1,10000) == false ) { fprintf(stderr,"Channelsget invalid amount\n"); return false; @@ -274,15 +274,13 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') { + GetCCaddress1of2(cp,coinaddr,srcpub,destpub); SetCCunspents(unspentOutputs,coinaddr); - Myprivkey(myprivkey); - CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr); - CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr); } else { - fprintf(stderr,"invalid open tx id\n"); + fprintf(stderr,"invalid open txid\n"); return 0; } @@ -317,11 +315,13 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C } } } - else fprintf(stderr,"not spent in mempool\n"); if (txid != zeroid) { prevtxid=txid; mtx.vin.push_back(CTxIn(txid,0,CScript())); + Myprivkey(myprivkey); + CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr); + CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr); return totalinputs; } else return 0; @@ -329,7 +329,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) { - CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk,channelspk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk; struct CCcontract_info *cp,C; if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { CCerror = strprintf("invalid ChannelOpen param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment); From 5628e37d9eea1efe3f480e35b4f705a8571d7b6f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 21 Sep 2018 21:01:00 +0200 Subject: [PATCH 161/749] -fix --- src/cc/channels.cpp | 140 ++++++++++++++++++++++++++++++--------- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 109 insertions(+), 33 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index a30b04a30..62b3612d4 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -233,7 +233,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if (hashchain!=genhashchain) return eval->Invalid("invalid secret for payment, does not reach final hashchain"); - else if (tx.vout[0].nValue != param1*payment) + else if (tx.vout[0].nValue != param2*payment) return eval->Invalid("vout amount does not match numberofpayments*payment"); } } @@ -241,15 +241,16 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & case 'C': //vin.0: normal input for 2*txfee (normal fee and marker) //vout.0: CC vout marker to senders pubKey - //vout.1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 + //vout.1: CC vout marker to receiver pubkey + //vout.2: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 return eval->Invalid("unexpected ChannelsValidate for channelsclose"); case 'R': //vin.0: normal input //vin.1: CC input from channel funding - //vout.0: normal output of CC input to senders pubkey + //vout.0: CC vout marker to senders pubKey //vout.1: CC vout marker to senders pubKey - //vout.2: opreturn - 'R' opentxid senderspubkey receiverspubkey 0 0 closetxid - return eval->Invalid("unexpected ChannelsValidate for channelsrefund"); + //vout.2: normal output of CC input to senders pubkey + //vout.3: opreturn - 'R' opentxid senderspubkey receiverspubkey 0 0 closetxid break; } } @@ -269,12 +270,13 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { char coinaddr[64]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t funcid,param1; std::vector > unspentOutputs; - CPubKey srcpub,destpub; + CPubKey srcpub,destpub,mypk; uint8_t myprivkey[32]; + mypk = pubkey2pk(Mypubkey()); + if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') { - GetCCaddress1of2(cp,coinaddr,srcpub,destpub); SetCCunspents(unspentOutputs,coinaddr); } @@ -288,7 +290,9 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && + tmp_txid==openTx.GetHash() && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) + { txid = it->first.txhash; break; @@ -306,12 +310,11 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C const uint256 &hash = tx.GetHash(); if ((numvouts=txmempool.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && - funcid=='P' && param1 < mindepth) + funcid=='P' && tmp_txid==openTx.GetHash() && param1 < mindepth) { txid=hash; totalinputs=txmempool.vout[0].nValue; mindepth=param1; - } } } @@ -371,13 +374,11 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { fprintf(stderr, "invalid channel open txid\n"); return (""); } - if (AddNormalinputs(mtx,mypk,3*txfee,1) > 0) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) @@ -402,9 +403,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) fprintf(stderr,"invalid previous tx\n"); return(""); } - numpayments=amount/payment; - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); for (i = 0; i < prevdepth-numpayments; i++) @@ -421,12 +420,11 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) } // verify lasttxid and origtxid match and src is me // also verify hashchain depth and amount, set prevdepth - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); mtx.vout.push_back(CTxOut(amount, CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG)); - return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, mypk, destpub, prevdepth - numpayments, payment, secret))); + return (FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeChannelsOpRet('P', opentxid, mypk, destpub, prevdepth-numpayments, numpayments, secret))); } else { @@ -440,41 +438,103 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) std::string ChannelClose(uint64_t txfee,uint256 opentxid) { - CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; + CTransaction channelOpenTx; + uint256 hashblock,tmp_txid,param3; + int32_t numvouts,param1; + int64_t param2,funds; + // verify this is one of our outbound channels cp = CCinit(&C,EVAL_CHANNELS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('S',opentxid,mypk,mypk,0,0,zeroid))); + fprintf(stderr, "invalid channel open tx\n"); + return (""); + } + if ((numvouts=channelOpenTx.vout.size()) < 1 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!='O') + { + fprintf(stderr, "invalid channel open tx\n"); + return (""); + } + if ( AddNormalinputs(mtx,mypk,3*txfee,1) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,0,0,zeroid))); } return(""); } std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { - CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t amount; + CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,change,payment,param2; + int32_t i,numpayments,numvouts,param1; + uint256 hashchain,hashblock,txid,prevtxid,param3,entropy,hentropy,secret; + CTransaction channelOpenTx,prevTx; + CPubKey srcpub,destpub; + uint8_t funcid,hash[32],hashdest[32];; + // verify stoptxid and origtxid match and are mine cp = CCinit(&C,EVAL_CHANNELS); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,txfee,1) > 0 ) + if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - mtx.vout.push_back(CTxOut(amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,mypk,0,0,closetxid))); + fprintf(stderr, "invalid channel open tx\n"); + return (""); + } + if ((numvouts=channelOpenTx.vout.size()) < 1 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') + { + fprintf(stderr, "invalid channel open tx\n"); + return (""); + } + if ( AddNormalinputs(mtx,mypk,3*txfee,1) > 0 ) + { + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0) + { + if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) != 0) && (funcid == 'P' || funcid=='O')) + { + if (mypk != srcpub) + { + fprintf(stderr,"this channel is not in our ownership\n"); + return(""); + } + } + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < param1; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); + mtx.vout.push_back(CTxOut(funds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,destpub,numpayments-param1,payment,secret))); + } + } + else + { + fprintf(stderr,"error adding CC inputs\n"); + return(""); + } } return(""); } UniValue ChannelsInfo() { - UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,hashBlock,hashchain,opentxid; struct CCcontract_info *cp,C; char myCCaddr[64]; int32_t vout,numvouts,numpayments; int64_t nValue,payment; CPubKey srcpub,destpub,mypk; + UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain; struct CCcontract_info *cp,C; char myCCaddr[64],addr[64],str1[100],str2[100]; int32_t vout,numvouts,param1,numpayments; int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; result.push_back(Pair("result","success")); - result.push_back(Pair("name","Channels")); + result.push_back(Pair("name","Channel Info")); cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); GetCCaddress(cp,myCCaddr,mypk); @@ -485,17 +545,33 @@ UniValue ChannelsInfo() txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second; - if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + if ( (vout==0 || vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O') { - char str[67],str2[67]; - fprintf(stderr,"%s %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelOpen",pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(long long)tx.vout[0].nValue,numpayments,(long long)payment); + GetCCaddress1of2(cp,addr,srcpub,destpub); + sprintf(str1,"Channel - %s",addr); + result.push_back(Pair(str1,"Open")); } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,numpayments,payment,hashchain) == 'P') + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P') { - char str[67],str2[67]; - fprintf(stderr,"%s (%s) %s -> %s %lldsat num.%d of %.8lldsat\n","ChannelPayment",opentxid.ToString().c_str(),pubkey33_str(str,(uint8_t *)&srcpub),pubkey33_str(str2,(uint8_t *)&destpub),(long long)tx.vout[0].nValue,numpayments,(long long)payment); + if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + sprintf(str1,"Channel - %s",addr); + sprintf(str2,"Payment -> %s %lld payments of %lld",destpub.GetHash().ToString().c_str(),param2,payment); + result.push_back(Pair(str1,str2)); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') + { + GetCCaddress1of2(cp,addr,srcpub,destpub); + sprintf(str1,"Channel - %s",addr); + result.push_back(Pair(str1,"Close")); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') + { + GetCCaddress1of2(cp,addr,srcpub,destpub); + sprintf(str1,"Channel - %s",addr); + sprintf(str2,"Refund -> %s %lld payments of %lld",srcpub.GetHash().ToString().c_str(),param1,param2); + result.push_back(Pair(str1,"Refund")); } } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e342fc84..83a65f0f0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5184,7 +5184,7 @@ UniValue channelsclose(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); - opentxid = Parseuint256((char *)params[1].get_str().c_str()); + opentxid = Parseuint256((char *)params[0].get_str().c_str()); hex = ChannelClose(0,opentxid); if ( hex.size() > 0 ) { From e5e3d065f3e0b0b370249b8539cb128feb28f79f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 21 Sep 2018 21:03:49 +0200 Subject: [PATCH 162/749] -fix --- src/cc/channels.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 62b3612d4..ff94b77e0 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -557,7 +557,7 @@ UniValue ChannelsInfo() { if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') sprintf(str1,"Channel - %s",addr); - sprintf(str2,"Payment -> %s %lld payments of %lld",destpub.GetHash().ToString().c_str(),param2,payment); + sprintf(str2,"Payment -> %s %lld payments of %lld",destpub.GetHash().ToString().c_str(),(long long)param2,(long long)payment); result.push_back(Pair(str1,str2)); } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') @@ -570,7 +570,7 @@ UniValue ChannelsInfo() { GetCCaddress1of2(cp,addr,srcpub,destpub); sprintf(str1,"Channel - %s",addr); - sprintf(str2,"Refund -> %s %lld payments of %lld",srcpub.GetHash().ToString().c_str(),param1,param2); + sprintf(str2,"Refund -> %s %lld payments of %lld",srcpub.GetHash().ToString().c_str(),(long long)param1,(long long)param2); result.push_back(Pair(str1,"Refund")); } } From 21eb7fa7d283e6e4c996d2d9c7aad9eaf2479d91 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 21 Sep 2018 21:32:15 +0200 Subject: [PATCH 163/749] -fix --- src/cc/channels.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index ff94b77e0..550a4cbd3 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -233,8 +233,11 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if (hashchain!=genhashchain) return eval->Invalid("invalid secret for payment, does not reach final hashchain"); - else if (tx.vout[0].nValue != param2*payment) + else if (tx.vout[3].nValue != param2*payment) + { + fprintf(stderr,"%lld=%lld*%lld\n",(long long)tx.vout[3].nValue,(long long)param2,(long long)payment); return eval->Invalid("vout amount does not match numberofpayments*payment"); + } } } break; @@ -290,8 +293,8 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && - tmp_txid==openTx.GetHash() && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && fprintf(stderr,"%s - %s\n",tmp_txid.ToString().c_str(),openTx.GetHash().ToString().c_str()) && + (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) { txid = it->first.txhash; @@ -308,9 +311,10 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { const CTransaction &txmempool = e.GetTx(); const uint256 &hash = tx.GetHash(); + if ((numvouts=txmempool.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && - funcid=='P' && tmp_txid==openTx.GetHash() && param1 < mindepth) + funcid=='P' && (tmp_txid==openTx.GetHash() || txmempool.GetHash()==openTx.GetHash()) && param1 < mindepth) { txid=hash; totalinputs=txmempool.vout[0].nValue; From fea4c38edddae6e00d85e909a222429baffb1520 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sat, 22 Sep 2018 11:53:31 +0200 Subject: [PATCH 164/749] -fix --- src/cc/channels.cpp | 70 ++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 550a4cbd3..16460e8c0 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -223,21 +223,17 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') return eval->Invalid("invalid channelopen OP_RETURN data"); hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & param3, 32); + endiancpy(hash, (uint8_t * ) & hentropy, 32); for (i = 0; i < numpayments-param1; i++) { vcalc_sha256(0, hashdest, hash, 32); memcpy(hash, hashdest, 32); } endiancpy((uint8_t*)&genhashchain,hashdest,32); - if (hashchain!=genhashchain) - return eval->Invalid("invalid secret for payment, does not reach final hashchain"); + return eval->Invalid("invalid secret for payment, does not reach final hashchain!"); else if (tx.vout[3].nValue != param2*payment) - { - fprintf(stderr,"%lld=%lld*%lld\n",(long long)tx.vout[3].nValue,(long long)param2,(long long)payment); - return eval->Invalid("vout amount does not match numberofpayments*payment"); - } + return eval->Invalid("vout amount does not match number_of_payments*payment"); } } break; @@ -368,9 +364,9 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) { - CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,secret,hashblock,entropy,hentropy,prevtxid; + CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,secret,hashblock,entropy,hentropy,prevtxid,param3; struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments; - int64_t payment,change,funds; + int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; @@ -387,43 +383,46 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) { - if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, numpayments, payment, hashchain)=='O') { - if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, payment, hashchain)) != 0) && (funcid == 'P' || funcid=='O')) + + if (mypk != srcpub && mypk != destpub) { - if (mypk != srcpub && mypk != destpub) + fprintf(stderr,"this is not our channel\n"); + return(""); + } + else if (amount % payment != 0) + { + fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); + return (""); + } + + numpayments=amount/payment; + + if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 && + ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && + (funcid == 'P' || funcid=='O')) + { + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < prevdepth-numpayments; i++) { - fprintf(stderr,"this is not our channel\n"); - return(""); - } - else if (amount % payment != 0) - { - fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); - return (""); + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); } + endiancpy((uint8_t * ) & secret, hashdest, 32); } else { fprintf(stderr,"invalid previous tx\n"); return(""); } - numpayments=amount/payment; - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < prevdepth-numpayments; i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & secret, hashdest, 32); } else { - fprintf(stderr, "cannot find previous tx (channel open or payment)\n"); + fprintf(stderr, "invalid channel open tx\n"); return (""); } - // verify lasttxid and origtxid match and src is me - // also verify hashchain depth and amount, set prevdepth mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, change, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); @@ -455,7 +454,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) mypk = pubkey2pk(Mypubkey()); if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - fprintf(stderr, "invalid channel open tx\n"); + fprintf(stderr, "invalid channel open txid\n"); return (""); } if ((numvouts=channelOpenTx.vout.size()) < 1 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!='O') @@ -463,6 +462,11 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) fprintf(stderr, "invalid channel open tx\n"); return (""); } + if (mypk != srcpub) + { + fprintf(stderr,"this channel is not in our ownership\n"); + return(""); + } if ( AddNormalinputs(mtx,mypk,3*txfee,1) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); @@ -488,7 +492,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) mypk = pubkey2pk(Mypubkey()); if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { - fprintf(stderr, "invalid channel open tx\n"); + fprintf(stderr, "invalid channel open txid\n"); return (""); } if ((numvouts=channelOpenTx.vout.size()) < 1 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') From b32b682ae969366dade85d7aaa919aae85ffa001 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Sat, 22 Sep 2018 12:18:41 +0200 Subject: [PATCH 165/749] -fix --- src/cc/channels.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 16460e8c0..7bc1d8d5a 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -152,7 +152,7 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,param1; bool retval; - uint256 txid,hashblock,param3,opentxid,tmp_txid,entropy,hentropy,gensecret,genhashchain,hashchain; + uint256 txid,hashblock,param3,opentxid,tmp_txid,genhashchain,hashchain; uint8_t funcid,hash[32],hashdest[32]; int64_t param2,payment; CPubKey srcpub, destpub; @@ -222,8 +222,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & { if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') return eval->Invalid("invalid channelopen OP_RETURN data"); - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); + endiancpy(hash, (uint8_t * ) & param3, 32); for (i = 0; i < numpayments-param1; i++) { vcalc_sha256(0, hashdest, hash, 32); From d68350535dc3ed7b9abc1d803ac3070c600e8977 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 27 Sep 2018 10:46:45 +0200 Subject: [PATCH 166/749] - updated validation - added secret parameter to payment - reused marker for sender to validate creator of tx --- src/cc/CCchannels.h | 2 +- src/cc/channels.cpp | 217 +++++++++++++++++++++++++++------------ src/wallet/rpcwallet.cpp | 12 ++- 3 files changed, 163 insertions(+), 68 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 6988b5913..4754ae44e 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -22,7 +22,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment); -std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount); +std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret); std::string ChannelClose(uint64_t txfee,uint256 opentxid); std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 7bc1d8d5a..4d5d8934a 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -152,12 +152,12 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,param1; bool retval; - uint256 txid,hashblock,param3,opentxid,tmp_txid,genhashchain,hashchain; + uint256 txid,hashblock,param3,opentxid,closetxid,tmp_txid,genhashchain,hashchain; uint8_t funcid,hash[32],hashdest[32]; int64_t param2,payment; CPubKey srcpub, destpub; std::vector > txids; - CTransaction channelOpenTx; + CTransaction channelOpenTx,channelCloseTx; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -189,11 +189,10 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.2: CC vout marker to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain - return eval->Invalid("unexpected ChannelsValidate for channelsopen"); - break; + return eval->Invalid("unexpected ChannelsValidate for channelsopen!"); case 'P': //vin.0: normal input - //vin.1: CC input from channel funding + //vin.1: CC input from channel funding and src marker //vout.0: CC vout change to CC1of2 pubkey //vout.1: CC vout marker to senders pubKey //vout.2: CC vout marker to receiver pubkey @@ -201,21 +200,21 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.n-2: normal change //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) - return eval->Invalid("vin.0 is normal for channelPayment"); + return eval->Invalid("vin.0 is normal for channelPayment!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for channelPayment"); + return eval->Invalid("vin.1 is CC for channelPayment!"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.0 is CC for channelPayment"); + return eval->Invalid("vout.0 is CC for channelPayment!"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)"); + return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!"); else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for channelPayment (marker to dstPub)"); + return eval->Invalid("vout.1 is CC for channelPayment (marker to dstPub)!"); else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) - return eval->Invalid("vout.1 is normal for channelPayment"); + return eval->Invalid("vout.1 is normal for channelPayment!"); else if ( tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) - return eval->Invalid("payment funds do not go to receiver -"); + return eval->Invalid("payment funds do not go to receiver!"); else if ( param1 > CHANNELS_MAXPAYMENTS) - return eval->Invalid("too many payment increments"); + return eval->Invalid("too many payment increments!"); else { if (myGetTransaction(opentxid,channelOpenTx,hashblock) != 0) @@ -232,23 +231,71 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if (hashchain!=genhashchain) return eval->Invalid("invalid secret for payment, does not reach final hashchain!"); else if (tx.vout[3].nValue != param2*payment) - return eval->Invalid("vout amount does not match number_of_payments*payment"); + return eval->Invalid("invalid amount, does not match number_of_payments*payment!"); } } break; case 'C': - //vin.0: normal input for 2*txfee (normal fee and marker) - //vout.0: CC vout marker to senders pubKey - //vout.1: CC vout marker to receiver pubkey - //vout.2: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 - return eval->Invalid("unexpected ChannelsValidate for channelsclose"); + //vin.0: normal input + //vin.1: CC input from channel funding and src marker + //vout.0: CC vout for channel funding + //vout.1: CC vout marker to senders pubKey + //vout.2: CC vout marker to receiver pubkey + //vout.n-2: normal change + //vout.n-1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 + if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for channelClose!"); + else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) + return eval->Invalid("vin.1 is CC for channelClose!"); + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.0 is CC for channelClose!"); + else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.1 is CC for channelClose (marker to srcPub)!"); + else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.2 is CC for channelClose (marker to dstPub)!"); + else if ( param1 > CHANNELS_MAXPAYMENTS) + return eval->Invalid("too many payment increments!"); + else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) + return eval->Invalid("invalid open txid!"); + else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) == 'O') + return eval->Invalid("invalid channelopen OP_RETURN data"); + else if (tx.vout[0].nValue != param2*payment) + return eval->Invalid("vout amount does not match number_of_payments*payment!"); + break; case 'R': //vin.0: normal input //vin.1: CC input from channel funding //vout.0: CC vout marker to senders pubKey - //vout.1: CC vout marker to senders pubKey + //vout.1: CC vout marker to receiver pubKey //vout.2: normal output of CC input to senders pubkey - //vout.3: opreturn - 'R' opentxid senderspubkey receiverspubkey 0 0 closetxid + //vout.n-2: normal change + //vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpaymewnts payment closetxid + if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + return eval->Invalid("vin.0 is normal for channelRefund!"); + else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) + return eval->Invalid("vin.1 is CC for channelRefund!"); + else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.0 is CC for channelRefund (marker to srcPub)!"); + else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) + return eval->Invalid("vout.1 is CC for channelRefund (marker to dstPub)!"); + else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 ) + return eval->Invalid("vout.2 is normal for channelRefund!"); + else if ( tx.vout[2].scriptPubKey!=CScript() << ParseHex(HexStr(srcpub)) << OP_CHECKSIG) + return eval->Invalid("payment funds do not go to sender!"); + else if ( param1 > CHANNELS_MAXPAYMENTS) + return eval->Invalid("too many payment increments!"); + else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) + return eval->Invalid("invalid open txid!"); + else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) == 'O') + return eval->Invalid("invalid channelopen OP_RETURN data"); + else if (tx.vout[2].nValue != param2*payment) + return eval->Invalid("vout amount does not match number_of_payments*payment!"); + else if (myGetTransaction(param3,channelCloseTx,hashblock) == 0) + return eval->Invalid("invalid close txid!"); + else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) == 'C') + return eval->Invalid("invalid channelclose OP_RETURN data"); + else if (tmp_txid!=opentxid) + return eval->Invalid("invalid close tx, opentxid do not match on close and refund!"); break; } } @@ -268,11 +315,9 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { char coinaddr[64]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t funcid,param1; std::vector > unspentOutputs; - CPubKey srcpub,destpub,mypk; + CPubKey srcpub,destpub; uint8_t myprivkey[32]; - mypk = pubkey2pk(Mypubkey()); - if ((numvouts=openTx.vout.size()) > 0 && DecodeChannelsOpRet(openTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)=='O') { GetCCaddress1of2(cp,coinaddr,srcpub,destpub); @@ -288,9 +333,9 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { if ( (int32_t)it->first.index==0 && GetTransaction(it->first.txhash,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && fprintf(stderr,"%s - %s\n",tmp_txid.ToString().c_str(),openTx.GetHash().ToString().c_str()) && - (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0))>0) - + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && + (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && + (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsvout(cp,tx,srcpub,destpub,1))>0) { txid = it->first.txhash; break; @@ -309,10 +354,10 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C if ((numvouts=txmempool.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && - funcid=='P' && (tmp_txid==openTx.GetHash() || txmempool.GetHash()==openTx.GetHash()) && param1 < mindepth) + (tmp_txid==openTx.GetHash() || txmempool.GetHash()==openTx.GetHash()) && param1 < mindepth) { txid=hash; - totalinputs=txmempool.vout[0].nValue; + totalinputs=txmempool.vout[0].nValue+txmempool.vout[1].nValue; mindepth=param1; } } @@ -361,10 +406,10 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 return(""); } -std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) +std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint256 secret) { - CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,secret,hashblock,entropy,hentropy,prevtxid,param3; - struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments; + CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; uint256 txid,hashchain,gensecret,hashblock,entropy,hentropy,prevtxid,param3; + struct CCcontract_info *cp,C; int32_t i,funcid,prevdepth,numvouts,numpayments,totalnumpayments; int64_t payment,change,funds,param2; uint8_t hash[32],hashdest[32]; CTransaction channelOpenTx,prevTx; @@ -378,11 +423,11 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) fprintf(stderr, "invalid channel open txid\n"); return (""); } - if (AddNormalinputs(mtx,mypk,3*txfee,1) > 0) + if (AddNormalinputs(mtx,mypk,2*txfee,1) > 0) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount-2*txfee)>=0) { - if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, numpayments, payment, hashchain)=='O') + if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { if (mypk != srcpub && mypk != destpub) @@ -399,17 +444,35 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount) numpayments=amount/payment; if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 && - ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && - (funcid == 'P' || funcid=='O')) + ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && + (funcid == 'P' || funcid=='O')) { - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < prevdepth-numpayments; i++) + if (secret!=zeroid) { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < prevdepth-numpayments; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); + } + else + { + endiancpy(hash, (uint8_t * ) & secret, 32); + for (i = 0; i < totalnumpayments-(prevdepth-numpayments); i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & gensecret, hashdest, 32); + if (gensecret!=hashchain) + { + fprintf(stderr,"invalid secret supplied\n"); + return(""); + } } - endiancpy((uint8_t * ) & secret, hashdest, 32); } else { @@ -442,7 +505,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; CTransaction channelOpenTx; - uint256 hashblock,tmp_txid,param3; + uint256 hashblock,tmp_txid,prevtxid,param3; int32_t numvouts,param1; int64_t param2,funds; @@ -456,7 +519,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) fprintf(stderr, "invalid channel open txid\n"); return (""); } - if ((numvouts=channelOpenTx.vout.size()) < 1 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!='O') + if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!='O') { fprintf(stderr, "invalid channel open tx\n"); return (""); @@ -466,21 +529,31 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) fprintf(stderr,"this channel is not in our ownership\n"); return(""); } - if ( AddNormalinputs(mtx,mypk,3*txfee,1) > 0 ) + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); - mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,0,0,zeroid))); + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds, mypk, destpub)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,0,0,zeroid))); + } + else + { + fprintf(stderr,"error adding CC inputs\n"); + return(""); + } } + fprintf(stderr,"error adding normal inputs\n"); return(""); } std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { - CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,change,payment,param2; + CMutableTransaction mtx; CPubKey mypk; struct CCcontract_info *cp,C; int64_t funds,payment,param2; int32_t i,numpayments,numvouts,param1; uint256 hashchain,hashblock,txid,prevtxid,param3,entropy,hentropy,secret; - CTransaction channelOpenTx,prevTx; + CTransaction channelOpenTx,channelCloseTx,prevTx; CPubKey srcpub,destpub; uint8_t funcid,hash[32],hashdest[32];; @@ -489,30 +562,43 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); + if (GetTransaction(closetxid,channelCloseTx,hashblock,false) == 0) + { + fprintf(stderr, "invalid channel close txid\n"); + return (""); + } + if ((numvouts=channelCloseTx.vout.size()) < 1 || DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,param1,param2,param3)!='C') + { + fprintf(stderr, "invalid channel close tx\n"); + return (""); + } + if (txid!=opentxid) + { + fprintf(stderr,"%s - %s\n",txid.ToString().c_str(),opentxid.ToString().c_str()); + fprintf(stderr, "open and close txid are not from same channel\n"); + return (""); + } if (GetTransaction(opentxid,channelOpenTx,hashblock,false) == 0) { fprintf(stderr, "invalid channel open txid\n"); return (""); } - if ((numvouts=channelOpenTx.vout.size()) < 1 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') + if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,txid,srcpub,destpub,numpayments,payment,hashchain)!='O') { fprintf(stderr, "invalid channel open tx\n"); return (""); } - if ( AddNormalinputs(mtx,mypk,3*txfee,1) > 0 ) + if (mypk != srcpub) + { + fprintf(stderr,"this channel is not in our ownership\n"); + return(""); + } + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0) { - if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0) + if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) != 0) && (funcid == 'P' || funcid=='O')) { - if ((numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) != 0) && (funcid == 'P' || funcid=='O')) - { - if (mypk != srcpub) - { - fprintf(stderr,"this channel is not in our ownership\n"); - return(""); - } - } hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); for (i = 0; i < param1; i++) @@ -524,7 +610,12 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); mtx.vout.push_back(CTxOut(funds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,destpub,numpayments-param1,payment,secret))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,destpub,param1,payment,closetxid))); + } + else + { + fprintf(stderr,"previous tx is invalid\n"); + return(""); } } else diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 83a65f0f0..ff910f2c9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5155,17 +5155,21 @@ UniValue channelsopen(const UniValue& params, bool fHelp) UniValue channelspayment(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,prevtxid; int32_t n; int64_t amount; + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string hex; uint256 opentxid,secret=zeroid; int32_t n; int64_t amount; cp = CCinit(&C,EVAL_CHANNELS); if ( fHelp || params.size() != 2 ) - throw runtime_error("channelspayment opentxid amount\n"); + throw runtime_error("channelspayment opentxid amount [secret]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); amount = atoi((char *)params[1].get_str().c_str()); - hex = ChannelPayment(0,opentxid,amount); + if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty()) + { + secret = Parseuint256((char *)params[2].get_str().c_str()); + } + hex = ChannelPayment(0,opentxid,amount,secret); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5190,7 +5194,7 @@ UniValue channelsclose(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create channelsstop transaction"); + } else ERR_RESULT("couldnt create channelsclose transaction"); return(result); } From 5e1984d0d219c65d78881f3469dbd2c80199edb7 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 27 Sep 2018 16:24:55 +0200 Subject: [PATCH 167/749] -fix --- src/cc/CCinclude.h | 3 ++- src/cc/CCtx.cpp | 2 +- src/cc/CCutils.cpp | 9 +++++++ src/cc/channels.cpp | 66 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2c3c6f5e6..8be4bce29 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -54,6 +54,7 @@ extern uint32_t ASSETCHAINS_CC; extern std::string CCerror; #define SMALLVAL 0.000000000000001 +#define MIN_NOTARIZATION_CONFIRMS 2 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; @@ -149,7 +150,7 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); std::vector Mypubkey(); bool Myprivkey(uint8_t myprivkey[]); int64_t CCduration(int32_t &numblocks,uint256 txid); - +bool isCCTxNotarizedConfirmed(uint256 txid); // CCtx std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index f1ee0b309..4e8561b20 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -111,7 +111,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = myprivkey; cond = mycond; - //fprintf(stderr,"my CC addr.(%s)\n",myaddr); + fprintf(stderr,"my CC addr.(%s)\n",myaddr); } else if ( strcmp(destaddr,unspendable) == 0 ) { diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index e03564971..c149be03f 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -410,3 +410,12 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) return(duration); } +bool isCCTxNotarizedConfirmed(uint256 txid) +{ + int32_t confirms; + + CCduration(confirms,txid); + if (confirms >= MIN_NOTARIZATION_CONFIRMS) + return (true); + return (false); +} diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 4d5d8934a..460f2b91d 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -84,7 +84,7 @@ CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubK uint8_t DecodeChannelsOpRet(const CScript &scriptPubKey,uint256 &opentxid, CPubKey &srcpub,CPubKey &destpub,int32_t &numpayments,int64_t &payment,uint256 &hashchain) { - std::vector vopret; uint8_t *script,e,f,funcid; + std::vector vopret; uint8_t *script,e,f; GetOpReturnData(scriptPubKey, vopret); if ( vopret.size() > 2 ) { @@ -151,13 +151,13 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,param1; bool retval; - uint256 txid,hashblock,param3,opentxid,closetxid,tmp_txid,genhashchain,hashchain; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numpayments,p1,param1; bool retval; + uint256 txid,hashblock,p3,param3,opentxid,tmp_txid,genhashchain,hashchain; uint8_t funcid,hash[32],hashdest[32]; - int64_t param2,payment; + int64_t p2,param2,payment; CPubKey srcpub, destpub; std::vector > txids; - CTransaction channelOpenTx,channelCloseTx; + CTransaction channelOpenTx,channelCloseTx,prevTx; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -199,7 +199,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.3: normal output of payment amount to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret - if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + if (isCCTxNotarizedConfirmed(opentxid) == 0) + return eval->Invalid("channelOpen is not yet confirmed(notarised)!"); + else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelPayment!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelPayment!"); @@ -220,7 +222,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if (myGetTransaction(opentxid,channelOpenTx,hashblock) != 0) { if ((numvouts=channelOpenTx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain)) != 0 && funcid!='O') - return eval->Invalid("invalid channelopen OP_RETURN data"); + return eval->Invalid("invalid channelopen OP_RETURN data!"); endiancpy(hash, (uint8_t * ) & param3, 32); for (i = 0; i < numpayments-param1; i++) { @@ -233,6 +235,17 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if (tx.vout[3].nValue != param2*payment) return eval->Invalid("invalid amount, does not match number_of_payments*payment!"); } + if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && (DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3)) != 0) + return eval->Invalid("invalid previous tx OP_RETURN data!"); + else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) + return eval->Invalid("invalid destination for sender marker!"); + else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey) + return eval->Invalid("invalid destination for receiver marker!"); + else if (param1!=p1-p2) + return eval->Invalid("invalid payment depth!"); + } } break; case 'C': @@ -243,7 +256,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.2: CC vout marker to receiver pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 - if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + if (isCCTxNotarizedConfirmed(opentxid) == 0) + return eval->Invalid("channelOpen is not yet confirmed(notarised)!"); + else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelClose!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelClose!"); @@ -258,9 +273,20 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) return eval->Invalid("invalid open txid!"); else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) == 'O') - return eval->Invalid("invalid channelopen OP_RETURN data"); + return eval->Invalid("invalid channelopen OP_RETURN data!"); else if (tx.vout[0].nValue != param2*payment) return eval->Invalid("vout amount does not match number_of_payments*payment!"); + else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && (DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3)) != 0) + return eval->Invalid("invalid previous tx OP_RETURN data!"); + else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) + return eval->Invalid("invalid destination for sender marker!"); + else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey) + return eval->Invalid("invalid destination for receiver marker!"); + else if (tx.vout[0].nValue != prevTx.vout[0].nValue) + return eval->Invalid("invalid CC amount, input!=output!"); + } break; case 'R': //vin.0: normal input @@ -270,7 +296,11 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.2: normal output of CC input to senders pubkey //vout.n-2: normal change //vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpaymewnts payment closetxid - if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) + if (isCCTxNotarizedConfirmed(opentxid) == 0) + return eval->Invalid("channelOpen is not yet confirmed(notarised)!"); + else if (isCCTxNotarizedConfirmed(param3) == 0) + return eval->Invalid("channelClose is not yet confirmed(notarised)!"); + else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelRefund!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelRefund!"); @@ -287,15 +317,26 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) return eval->Invalid("invalid open txid!"); else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) == 'O') - return eval->Invalid("invalid channelopen OP_RETURN data"); + return eval->Invalid("invalid channelopen OP_RETURN data!"); else if (tx.vout[2].nValue != param2*payment) return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(param3,channelCloseTx,hashblock) == 0) return eval->Invalid("invalid close txid!"); else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) == 'C') - return eval->Invalid("invalid channelclose OP_RETURN data"); + return eval->Invalid("invalid channelclose OP_RETURN data!"); else if (tmp_txid!=opentxid) return eval->Invalid("invalid close tx, opentxid do not match on close and refund!"); + else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) + { + if ((numvouts=prevTx.vout.size()) > 0 && (DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3)) != 0) + return eval->Invalid("invalid previous tx OP_RETURN data!"); + else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) + return eval->Invalid("invalid destination for sender marker!"); + else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey) + return eval->Invalid("invalid destination for receiver marker!"); + else if (tx.vout[2].nValue != prevTx.vout[0].nValue) + return eval->Invalid("invalid refund amount, must transfer all funds!"); + } break; } } @@ -366,6 +407,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { prevtxid=txid; mtx.vin.push_back(CTxIn(txid,0,CScript())); + mtx.vin.push_back(CTxIn(txid,1,CScript())); Myprivkey(myprivkey); CCaddr2set(cp,EVAL_CHANNELS,srcpub,myprivkey,coinaddr); CCaddr3set(cp,EVAL_CHANNELS,destpub,myprivkey,coinaddr); From 001d7ea10188063f5372c24d95fd1b14d84266ee Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 27 Sep 2018 18:41:33 +0200 Subject: [PATCH 168/749] -fix --- src/cc/CCutils.cpp | 1 - src/cc/channels.cpp | 64 +++++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index c149be03f..cbf574532 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -63,7 +63,6 @@ CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk1,CPubKey pk2) CTxOut vout; CC *payoutCond = MakeCCcond1of2(evalcode,pk1,pk2); vout = CTxOut(nValue,CCPubKey(payoutCond)); - fprintf(stderr,"payoutCond: %s\n",cc_conditionToJSONString(payoutCond)); cc_free(payoutCond); return(vout); } diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 460f2b91d..2635fe494 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -156,7 +156,6 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & uint8_t funcid,hash[32],hashdest[32]; int64_t p2,param2,payment; CPubKey srcpub, destpub; - std::vector > txids; CTransaction channelOpenTx,channelCloseTx,prevTx; numvins = tx.vin.size(); @@ -192,7 +191,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("unexpected ChannelsValidate for channelsopen!"); case 'P': //vin.0: normal input - //vin.1: CC input from channel funding and src marker + //vin.1: CC input from channel funding + //vin.2: CC input from src marker //vout.0: CC vout change to CC1of2 pubkey //vout.1: CC vout marker to senders pubKey //vout.2: CC vout marker to receiver pubkey @@ -205,6 +205,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.0 is normal for channelPayment!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelPayment!"); + else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) + return eval->Invalid("vin.1 is CC for channelPayment!"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.0 is CC for channelPayment!"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) @@ -237,20 +239,21 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { - if ((numvouts=prevTx.vout.size()) > 0 && (DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3)) != 0) + if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey) return eval->Invalid("invalid destination for receiver marker!"); - else if (param1!=p1-p2) + else if (param1+param2!=p1) return eval->Invalid("invalid payment depth!"); } } break; case 'C': //vin.0: normal input - //vin.1: CC input from channel funding and src marker + //vin.1: CC input from channel funding + //vin.2: CC input from src marker //vout.0: CC vout for channel funding //vout.1: CC vout marker to senders pubKey //vout.2: CC vout marker to receiver pubkey @@ -262,6 +265,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.0 is normal for channelClose!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelClose!"); + else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) + return eval->Invalid("vin.2 is CC for channelClose!"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.0 is CC for channelClose!"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) @@ -278,7 +283,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { - if ((numvouts=prevTx.vout.size()) > 0 && (DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3)) != 0) + if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); @@ -291,6 +296,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & case 'R': //vin.0: normal input //vin.1: CC input from channel funding + //vin.2: CC input from src marker //vout.0: CC vout marker to senders pubKey //vout.1: CC vout marker to receiver pubKey //vout.2: normal output of CC input to senders pubkey @@ -304,6 +310,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("vin.0 is normal for channelRefund!"); else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelRefund!"); + else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) + return eval->Invalid("vin.2 is CC for channelRefund!"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.0 is CC for channelRefund (marker to srcPub)!"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) @@ -328,7 +336,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("invalid close tx, opentxid do not match on close and refund!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { - if ((numvouts=prevTx.vout.size()) > 0 && (DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3)) != 0) + if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); @@ -391,11 +399,10 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) { const CTransaction &txmempool = e.GetTx(); - const uint256 &hash = tx.GetHash(); + const uint256 &hash = txmempool.GetHash(); - if ((numvouts=txmempool.vout.size()) > 0 && - (funcid=DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)) != 0 && - (tmp_txid==openTx.GetHash() || txmempool.GetHash()==openTx.GetHash()) && param1 < mindepth) + if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 && + tmp_txid==openTx.GetHash() && param1 < mindepth) { txid=hash; totalinputs=txmempool.vout[0].nValue+txmempool.vout[1].nValue; @@ -467,7 +474,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } if (AddNormalinputs(mtx,mypk,2*txfee,1) > 0) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount-2*txfee)>=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) { if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { @@ -482,14 +489,28 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 fprintf(stderr,"invalid amount, not a magnitude of payment size\n"); return (""); } - numpayments=amount/payment; - if (GetTransaction(prevtxid,prevTx,hashblock,false) != 0 && (numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, prevdepth, param2, param3)) != 0) && (funcid == 'P' || funcid=='O')) { if (secret!=zeroid) + { + endiancpy(hash, (uint8_t * ) & secret, 32); + for (i = 0; i < totalnumpayments-(prevdepth-numpayments); i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & gensecret, hashdest, 32); + fprintf(stderr, "%d %d %d %s %s\n",(int)(totalnumpayments-(prevdepth-numpayments)),(int)prevdepth,(int)numpayments,gensecret.ToString().c_str(),hashchain.ToString().c_str()); + if (gensecret!=hashchain) + { + fprintf(stderr,"invalid secret supplied\n"); + return(""); + } + } + else { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); @@ -500,21 +521,6 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } endiancpy((uint8_t * ) & secret, hashdest, 32); } - else - { - endiancpy(hash, (uint8_t * ) & secret, 32); - for (i = 0; i < totalnumpayments-(prevdepth-numpayments); i++) - { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); - } - endiancpy((uint8_t * ) & gensecret, hashdest, 32); - if (gensecret!=hashchain) - { - fprintf(stderr,"invalid secret supplied\n"); - return(""); - } - } } else { From 2ca1bcbe215022b97557e99b5567c33f624fef8e Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 27 Sep 2018 18:52:03 +0200 Subject: [PATCH 169/749] -fix --- src/cc/channels.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 2635fe494..b525d557e 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -277,10 +277,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("too many payment increments!"); else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) return eval->Invalid("invalid open txid!"); - else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) == 'O') + else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') return eval->Invalid("invalid channelopen OP_RETURN data!"); - else if (tx.vout[0].nValue != param2*payment) - return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) @@ -324,13 +322,13 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("too many payment increments!"); else if (myGetTransaction(opentxid,channelOpenTx,hashblock) == 0) return eval->Invalid("invalid open txid!"); - else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) == 'O') + else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') return eval->Invalid("invalid channelopen OP_RETURN data!"); else if (tx.vout[2].nValue != param2*payment) return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(param3,channelCloseTx,hashblock) == 0) return eval->Invalid("invalid close txid!"); - else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) == 'C') + else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) != 'C') return eval->Invalid("invalid channelclose OP_RETURN data!"); else if (tmp_txid!=opentxid) return eval->Invalid("invalid close tx, opentxid do not match on close and refund!"); From bd632043f2b184bf287483c070629771b68dbf1d Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Thu, 27 Sep 2018 20:06:21 +0200 Subject: [PATCH 170/749] -fix --- src/cc/channels.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index b525d557e..72f995e55 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -235,7 +235,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & if (hashchain!=genhashchain) return eval->Invalid("invalid secret for payment, does not reach final hashchain!"); else if (tx.vout[3].nValue != param2*payment) - return eval->Invalid("invalid amount, does not match number_of_payments*payment!"); + return eval->Invalid("vout amount does not match number_of_payments*payment!"); } if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { @@ -247,6 +247,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("invalid destination for receiver marker!"); else if (param1+param2!=p1) return eval->Invalid("invalid payment depth!"); + else if (tx.vout[3].nValue > prevTx.vout[0].nValue) + return eval->Invalid("not enough funds in channel for that amount!"); } } break; @@ -279,6 +281,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("invalid open txid!"); else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') return eval->Invalid("invalid channelopen OP_RETURN data!"); + else if (tx.vout[0].nValue != param1*payment) + return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) @@ -288,7 +292,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey) return eval->Invalid("invalid destination for receiver marker!"); else if (tx.vout[0].nValue != prevTx.vout[0].nValue) - return eval->Invalid("invalid CC amount, input!=output!"); + return eval->Invalid("invalid CC amount, amount must match funds in channel"); } break; case 'R': @@ -299,7 +303,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & //vout.1: CC vout marker to receiver pubKey //vout.2: normal output of CC input to senders pubkey //vout.n-2: normal change - //vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpaymewnts payment closetxid + //vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpayments payment closetxid if (isCCTxNotarizedConfirmed(opentxid) == 0) return eval->Invalid("channelOpen is not yet confirmed(notarised)!"); else if (isCCTxNotarizedConfirmed(param3) == 0) @@ -324,24 +328,24 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("invalid open txid!"); else if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, numpayments, payment, hashchain) != 'O') return eval->Invalid("invalid channelopen OP_RETURN data!"); - else if (tx.vout[2].nValue != param2*payment) - return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(param3,channelCloseTx,hashblock) == 0) return eval->Invalid("invalid close txid!"); else if ((numvouts=channelCloseTx.vout.size()) > 0 && DecodeChannelsOpRet(channelCloseTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, param1, param2, param3) != 'C') return eval->Invalid("invalid channelclose OP_RETURN data!"); else if (tmp_txid!=opentxid) return eval->Invalid("invalid close tx, opentxid do not match on close and refund!"); + else if (tx.vout[2].nValue != param1*payment) + return eval->Invalid("vout amount does not match number_of_payments*payment!"); else if (myGetTransaction(tx.vin[1].prevout.hash,prevTx,hashblock) != 0) { if ((numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, tmp_txid, srcpub, destpub, p1, p2, p3) == 0) return eval->Invalid("invalid previous tx OP_RETURN data!"); - else if (tx.vout[1].scriptPubKey != prevTx.vout[1].scriptPubKey) + else if (tx.vout[0].scriptPubKey != prevTx.vout[1].scriptPubKey) return eval->Invalid("invalid destination for sender marker!"); - else if (tx.vout[2].scriptPubKey != prevTx.vout[2].scriptPubKey) + else if (tx.vout[1].scriptPubKey != prevTx.vout[2].scriptPubKey) return eval->Invalid("invalid destination for receiver marker!"); else if (tx.vout[2].nValue != prevTx.vout[0].nValue) - return eval->Invalid("invalid refund amount, must transfer all funds!"); + return eval->Invalid("invalid amount, refund amount and funds in channel must match!"); } break; } @@ -551,9 +555,9 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) { CMutableTransaction mtx; CPubKey mypk,srcpub,destpub; struct CCcontract_info *cp,C; CTransaction channelOpenTx; - uint256 hashblock,tmp_txid,prevtxid,param3; - int32_t numvouts,param1; - int64_t param2,funds; + uint256 hashblock,tmp_txid,prevtxid,hashchain; + int32_t numvouts,numpayments; + int64_t payment,funds; // verify this is one of our outbound channels cp = CCinit(&C,EVAL_CHANNELS); @@ -565,7 +569,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) fprintf(stderr, "invalid channel open txid\n"); return (""); } - if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!='O') + if ((numvouts=channelOpenTx.vout.size()) < 1 || DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain)!='O') { fprintf(stderr, "invalid channel open tx\n"); return (""); @@ -582,7 +586,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,0,0,zeroid))); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,funds/payment,payment,zeroid))); } else { @@ -643,7 +647,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0) { - if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && ((funcid = DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) != 0) && (funcid == 'P' || funcid=='O')) + if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); From 7f0ed443f1e051d98fbcfe444c0ce60cd5b8b1b9 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 1 Oct 2018 18:24:14 +0200 Subject: [PATCH 171/749] -modified ChannelsExactAmount -fixes --- src/cc/CCchannels.h | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/channels.cpp | 171 +++++++++++++++++++++++---------------- src/wallet/rpcwallet.cpp | 8 +- 4 files changed, 109 insertions(+), 74 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 4754ae44e..29b35d0e6 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -27,6 +27,6 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid); std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); // CCcustom -UniValue ChannelsInfo(); +UniValue ChannelsInfo(char *); #endif diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4e8561b20..abe65199d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -111,7 +111,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { privkey = myprivkey; cond = mycond; - fprintf(stderr,"my CC addr.(%s)\n",myaddr); + } else if ( strcmp(destaddr,unspendable) == 0 ) { diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 72f995e55..de2657dc4 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -75,6 +75,19 @@ int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey return(0); } +int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub,int32_t v) +{ + char destaddr[64],ccaddr[64]; + + GetCCaddress(cp,ccaddr,srcpub); + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + { + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,ccaddr) == 0 ) + return(tx.vout[v].nValue); + } + return(0); +} + CScript EncodeChannelsOpRet(uint8_t funcid,uint256 opentxid,CPubKey srcpub,CPubKey destpub,int32_t numpayments,int64_t payment,uint256 hashchain) { CScript opret; uint8_t evalcode = EVAL_CHANNELS; @@ -110,24 +123,15 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti numvins = tx.vin.size(); numvouts = tx.vout.size(); - if ((numvouts=tx.vout.size()) > 0 && (funcid=DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)) !=0) + if ((numvouts=tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3)!=0) { for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else { - //fprintf(stderr,"vini.%d check mempool\n",i); - if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("cant find vinTx"); - else - { - //fprintf(stderr,"vini.%d check hash and vout\n",i); - if ( hashBlock == zerohash ) - return eval->Invalid("cant Channels from mempool"); - if ( (assetoshis= IsChannelsvout(cp,vinTx,srcpub,destpub,tx.vin[i].prevout.n)) != 0 ) - inputs += assetoshis; - } + inputs += vinTx.vout[tx.vin[i].prevout.n].nValue; } } } @@ -137,9 +141,7 @@ bool ChannelsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti } for (i=0; iInvalid("no vouts"); else { - //fprintf(stderr,"check amounts\n"); - if ( 0) //ChannelsExactAmounts(cp,eval,tx,1,10000) == false ) + if (ChannelsExactAmounts(cp,eval,tx,1,10000) == false ) { fprintf(stderr,"Channelsget invalid amount\n"); return false; @@ -364,7 +365,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid) { - char coinaddr[64]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t funcid,param1; + char coinaddr[64]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t param1; std::vector > unspentOutputs; CPubKey srcpub,destpub; uint8_t myprivkey[32]; @@ -386,14 +387,14 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==openTx.GetHash() || tx.GetHash()==openTx.GetHash()) && - (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsvout(cp,tx,srcpub,destpub,1))>0) + (totalinputs=IsChannelsvout(cp,tx,srcpub,destpub,0)+IsChannelsMarkervout(cp,tx,srcpub,1))>0) { txid = it->first.txhash; break; } } } - if (myIsutxo_spentinmempool(txid,0) != 0) + if (txid!=zeroid && myIsutxo_spentinmempool(txid,0) != 0) { fprintf(stderr,"spent in mempool\n"); txid=zeroid; @@ -476,7 +477,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 } if (AddNormalinputs(mtx,mypk,2*txfee,1) > 0) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount)>=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && (change=funds-amount-txfee)>=0) { if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { @@ -505,7 +506,6 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 memcpy(hash, hashdest, 32); } endiancpy((uint8_t * ) & gensecret, hashdest, 32); - fprintf(stderr, "%d %d %d %s %s\n",(int)(totalnumpayments-(prevdepth-numpayments)),(int)prevdepth,(int)numpayments,gensecret.ToString().c_str(),hashchain.ToString().c_str()); if (gensecret!=hashchain) { fprintf(stderr,"invalid secret supplied\n"); @@ -515,13 +515,17 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 else { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); - endiancpy(hash, (uint8_t * ) & hentropy, 32); - for (i = 0; i < prevdepth-numpayments; i++) + if (prevdepth-numpayments) { - vcalc_sha256(0, hashdest, hash, 32); - memcpy(hash, hashdest, 32); + endiancpy(hash, (uint8_t * ) & hentropy, 32); + for (i = 0; i < prevdepth-numpayments; i++) + { + vcalc_sha256(0, hashdest, hash, 32); + memcpy(hash, hashdest, 32); + } + endiancpy((uint8_t * ) & secret, hashdest, 32); } - endiancpy((uint8_t * ) & secret, hashdest, 32); + else endiancpy((uint8_t * ) & secret, (uint8_t * ) & hentropy, 32); } } else @@ -581,9 +585,9 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) } if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds, mypk, destpub)); + mtx.vout.push_back(MakeCC1of2vout(EVAL_CHANNELS, funds-txfee, mypk, destpub)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('C',opentxid,mypk,destpub,funds/payment,payment,zeroid))); @@ -645,7 +649,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { - if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0) + if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0) { if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) { @@ -659,7 +663,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) endiancpy((uint8_t * ) & secret, hashdest, 32); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,mypk)); mtx.vout.push_back(MakeCC1vout(EVAL_CHANNELS,txfee,destpub)); - mtx.vout.push_back(CTxOut(funds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(funds-txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeChannelsOpRet('R',opentxid,mypk,destpub,param1,payment,closetxid))); } else @@ -677,52 +681,79 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) return(""); } -UniValue ChannelsInfo() +UniValue ChannelsInfo(char *CCaddr) { - UniValue result(UniValue::VOBJ); CTransaction tx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain; struct CCcontract_info *cp,C; char myCCaddr[64],addr[64],str1[100],str2[100]; int32_t vout,numvouts,param1,numpayments; int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; + UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; + struct CCcontract_info *cp,C; char myCCaddr[64],addr[64],str1[256],str2[64]; int32_t vout,numvouts,param1,numpayments; + int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; + result.push_back(Pair("result","success")); - result.push_back(Pair("name","Channel Info")); cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); - GetCCaddress(cp,myCCaddr,mypk); - SetCCtxids(txids,myCCaddr); - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + if (strcmp(CCaddr,"")==0) { - //int height = it->first.blockHeight; - txid = it->first.txhash; - vout = (int32_t)it->first.index; - nValue = (int64_t)it->second; - if ( (vout==0 || vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + result.push_back(Pair("name","Channels Info")); + GetCCaddress(cp,myCCaddr,mypk); + SetCCtxids(txids,myCCaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O') + //int height = it->first.blockHeight; + txid = it->first.txhash; + vout = (int32_t)it->first.index; + nValue = (int64_t)it->second; + if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - GetCCaddress1of2(cp,addr,srcpub,destpub); - sprintf(str1,"Channel - %s",addr); - result.push_back(Pair(str1,"Open")); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P') - { - if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') - sprintf(str1,"Channel - %s",addr); - sprintf(str2,"Payment -> %s %lld payments of %lld",destpub.GetHash().ToString().c_str(),(long long)param2,(long long)payment); - result.push_back(Pair(str1,str2)); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') - { - GetCCaddress1of2(cp,addr,srcpub,destpub); - sprintf(str1,"Channel - %s",addr); - result.push_back(Pair(str1,"Close")); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') - { - GetCCaddress1of2(cp,addr,srcpub,destpub); - sprintf(str1,"Channel - %s",addr); - sprintf(str2,"Refund -> %s %lld payments of %lld",srcpub.GetHash().ToString().c_str(),(long long)param1,(long long)param2); - result.push_back(Pair(str1,"Refund")); + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O') + { + GetCCaddress1of2(cp,addr,srcpub,destpub); + sprintf(str1,"%s - %lld payments of %lld satoshi",addr,(long long)param1,(long long)param2); + result.push_back(Pair("Channel", str1)); + } } } } + else + { + sprintf(str1,"Channel %s",CCaddr); + result.push_back(Pair("name",str1)); + strcpy(myCCaddr,CCaddr); + SetCCtxids(txids,myCCaddr); + prevtxid=zeroid; + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + //int height = it->first.blockHeight; + txid = it->first.txhash; + nValue = (int64_t)it->second; + if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + { + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O') + { + sprintf(str1,"%lld payments of %lld satoshi",(long long)param1,(long long)param2); + result.push_back(Pair("Open", str1)); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P') + { + if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + { + Getscriptaddress(str2,tx.vout[3].scriptPubKey); + sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1); + result.push_back(Pair("Payment",str1)); + } + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') + { + result.push_back(Pair("Close","channel")); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R') + { + Getscriptaddress(str2,tx.vout[2].scriptPubKey); + sprintf(str1,"%lld satoshi back to %s",(long long)(param1*param2),str2); + result.push_back(Pair("Refund",str1)); + } + } + prevtxid=txid; + } + } return(result); -} - +} \ No newline at end of file diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ff910f2c9..d4a83d83a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5124,11 +5124,15 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue channelsinfo(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() != 0 ) + char addr[100]; + if ( fHelp || params.size() > 1 ) throw runtime_error("channelsinfo\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - return(ChannelsInfo()); + strcpy(addr,""); + if (params.size() > 0 && !params[0].isNull() && !params[0].get_str().empty()) + strcpy(addr,params[0].get_str().c_str()); + return(ChannelsInfo(addr)); } UniValue channelsopen(const UniValue& params, bool fHelp) From 78086bc3bf538f763caea411a7306616b348b645 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 1 Oct 2018 18:52:21 +0200 Subject: [PATCH 172/749] - fix --- src/cc/CCchannels.h | 2 +- src/cc/CCutils.cpp | 2 +- src/cc/channels.cpp | 74 +++++++++++++++++++++------------------- src/wallet/rpcwallet.cpp | 10 +++--- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 29b35d0e6..f67ef9a6c 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -27,6 +27,6 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid); std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid); // CCcustom -UniValue ChannelsInfo(char *); +UniValue ChannelsInfo(uint256 opentxid); #endif diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index cbf574532..491798a98 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -405,7 +405,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) } numblocks = (pindex->nHeight - txheight); duration = (pindex->nTime - txtime); - fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight); + //fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->nHeight,txheight); return(duration); } diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index de2657dc4..236f28e03 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -681,7 +681,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) return(""); } -UniValue ChannelsInfo(char *CCaddr) +UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; struct CCcontract_info *cp,C; char myCCaddr[64],addr[64],str1[256],str2[64]; int32_t vout,numvouts,param1,numpayments; @@ -691,7 +691,7 @@ UniValue ChannelsInfo(char *CCaddr) result.push_back(Pair("result","success")); cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); - if (strcmp(CCaddr,"")==0) + if (channeltxid==zeroid) { result.push_back(Pair("name","Channels Info")); GetCCaddress(cp,myCCaddr,mypk); @@ -704,10 +704,10 @@ UniValue ChannelsInfo(char *CCaddr) nValue = (int64_t)it->second; if ( (vout == 1 || vout == 2) && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O') + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') { GetCCaddress1of2(cp,addr,srcpub,destpub); - sprintf(str1,"%s - %lld payments of %lld satoshi",addr,(long long)param1,(long long)param2); + sprintf(str1,"%s - %lld payments of %lld satoshi - %s",addr,(long long)param1,(long long)param2,tx.GetHash().ToString().c_str()); result.push_back(Pair("Channel", str1)); } } @@ -715,44 +715,48 @@ UniValue ChannelsInfo(char *CCaddr) } else { - sprintf(str1,"Channel %s",CCaddr); - result.push_back(Pair("name",str1)); - strcpy(myCCaddr,CCaddr); - SetCCtxids(txids,myCCaddr); - prevtxid=zeroid; - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + if (GetTransaction(channeltxid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 && + (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) { - //int height = it->first.blockHeight; - txid = it->first.txhash; - nValue = (int64_t)it->second; - if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) + GetCCaddress1of2(cp,addr,srcpub,destpub); + sprintf(str1,"Channel %s",addr); + result.push_back(Pair("name",str1)); + SetCCtxids(txids,addr); + prevtxid=zeroid; + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'O') + + txid = it->first.txhash; + nValue = (int64_t)it->second; + if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { - sprintf(str1,"%lld payments of %lld satoshi",(long long)param1,(long long)param2); - result.push_back(Pair("Open", str1)); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P') - { - if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) { - Getscriptaddress(str2,tx.vout[3].scriptPubKey); - sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1); - result.push_back(Pair("Payment",str1)); + sprintf(str1,"%lld payments of %lld satoshi",(long long)param1,(long long)param2); + result.push_back(Pair("Open", str1)); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) + { + if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + { + Getscriptaddress(str2,tx.vout[3].scriptPubKey); + sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1); + result.push_back(Pair("Payment",str1)); + } + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) + { + result.push_back(Pair("Close","channel")); + } + else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid) + { + Getscriptaddress(str2,tx.vout[2].scriptPubKey); + sprintf(str1,"%lld satoshi back to %s",(long long)(param1*param2),str2); + result.push_back(Pair("Refund",str1)); } } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'C') - { - result.push_back(Pair("Close","channel")); - } - else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'R') - { - Getscriptaddress(str2,tx.vout[2].scriptPubKey); - sprintf(str1,"%lld satoshi back to %s",(long long)(param1*param2),str2); - result.push_back(Pair("Refund",str1)); - } + prevtxid=txid; } - prevtxid=txid; } } return(result); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d4a83d83a..d97df5b3a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5124,15 +5124,15 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue channelsinfo(const UniValue& params, bool fHelp) { - char addr[100]; + uint256 opentxid; if ( fHelp || params.size() > 1 ) - throw runtime_error("channelsinfo\n"); + throw runtime_error("channelsinfo [opentxid]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - strcpy(addr,""); + opentxid=zeroid; if (params.size() > 0 && !params[0].isNull() && !params[0].get_str().empty()) - strcpy(addr,params[0].get_str().c_str()); - return(ChannelsInfo(addr)); + opentxid = Parseuint256((char *)params[0].get_str().c_str()); + return(ChannelsInfo(opentxid)); } UniValue channelsopen(const UniValue& params, bool fHelp) From 0cb59663e2194b52ac6519a0c1e8831856358a1e Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 2 Oct 2018 15:06:55 +0200 Subject: [PATCH 173/749] - Updated channel CC docs --- src/cc/CC made easy | 55 ++++++++++++++++++++++++++++++++++++++++++++- src/cc/channels.cpp | 1 - 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/cc/CC made easy b/src/cc/CC made easy index 895d84404..158c2907a 100644 --- a/src/cc/CC made easy +++ b/src/cc/CC made easy @@ -490,8 +490,61 @@ Now we can make the payment based on the hashvalue revealed at a specified depth Payments at the speed of the mempool, protected by dPoW! -
+RPC calls +channelsopen: + Used to open channel between two pub keys (sender and receiver). Parameters: destination_pubkey, total_number_of_payments, payment_denomination. + Example - channelsopen 03a8fe537de2ace0d9c210b0ff945085c9192c9abf56ea22f22ce7998f289bb7bb 10 10000000 +channelspayment: + Sending payment to receiver. Condition is that the channel open tx is confirmed/notarised. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender). + Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000 +channelsclose: + Marking channel as closed. This RPC only creates a tx which says that the channel is closed and will be used in refund RPC to withdraw funds from closed channel. This also notifies receiver that channel fund could be withdrawn, but the payment RPC is still available until all funds are withdrawn. Parameters: open_tx_id. + Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 +channelsrefund: + Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarised. Parameters: open_tx_id, close_tx_id + Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd +channelsinfo: + Getting info about channels in which the issuer is involved, either as sender or receiver. Call without parameters give the list of available channels. Parameters: [open_tx_id] (optional - used to get info about specific channel) +VIN/VOUT allocation +Open: + vin.0: normal input + vout.0: CC vout for channel funding on CC1of2 pubkey + vout.1: CC vout marker to senders pubKey + vout.2: CC vout marker to receiver pubkey + vout.n-2: normal change + vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain + +Payment + vin.0: normal input + vin.1: CC input from channel funding + vin.2: CC input from src marker + vout.0: CC vout change to channel funding on CC1of2 pubkey + vout.1: CC vout marker to senders pubKey + vout.2: CC vout marker to receiver pubkey + vout.3: normal output of payment amount to receiver pubkey + vout.n-2: normal change + vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret + +Close: + vin.0: normal input + vin.1: CC input from channel funding + vin.2: CC input from src marker + vout.0: CC vout for channel funding + vout.1: CC vout marker to senders pubKey + vout.2: CC vout marker to receiver pubkey + vout.n-2: normal change + vout.n-1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0 + +Refund: + vin.0: normal input + vin.1: CC input from channel funding + vin.2: CC input from src marker + vout.0: CC vout marker to senders pubKey + vout.1: CC vout marker to receiver pubKey + vout.2: normal output of CC input to senders pubkey + vout.n-2: normal change + vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpayments payment closetxid Chapter 11 - oracles example Oracles CC is an example where it ended up being simpler than I first expected, but at the same time a lot more powerful. It is one of the smaller CC, but it enables creation of an arbitrary number of data markets, in a performant way. diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 236f28e03..f6133d575 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -727,7 +727,6 @@ UniValue ChannelsInfo(uint256 channeltxid) { txid = it->first.txhash; - nValue = (int64_t)it->second; if (txid!=prevtxid && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 0 ) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) From 4c95cd4c6fa863f6b3f9c72eb93de9040e645091 Mon Sep 17 00:00:00 2001 From: SHossain Date: Tue, 2 Oct 2018 14:13:58 +0100 Subject: [PATCH 174/749] Update dpowassets --- src/dpowassets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dpowassets b/src/dpowassets index 9bd17ff18..40bf0e624 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -43,3 +43,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUSH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PIRATE\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGNX\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EMC2\",\"freq\":10,\"pubkey\":\"$pubkey\"}" From 374dbd844c2399ae82ab3b44027b7cf8a8045ccd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Oct 2018 02:23:29 -1100 Subject: [PATCH 175/749] Fix destination confusion --- src/cc/CCtx.cpp | 2 +- src/cc/dapps/oraclefeed.c | 4 ++-- src/cc/gateways.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index abe65199d..f29fd05e8 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -139,7 +139,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } else { - fprintf(stderr,"vini.%d has unknown CC address.(%s)\n",i,destaddr); + fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); continue; } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL, utxovalues[i],consensusBranchId, &txdata); diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 297b92a01..eaf488a34 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -464,10 +464,10 @@ int32_t get_coinheader(char *refcoin,char *acname,bits256 *blockhashp,bits256 *m return(0); } -cJSON *get_gatewayspending(char *refcoin,char *acname,char *oraclestxidstr) +cJSON *get_gatewayspending(char *refcoin,char *acname,char *bindtxidstr) { cJSON *retjson; char *retstr; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",oraclestxidstr,refcoin,"","")) != 0 ) + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspending",bindtxidstr,refcoin,"","")) != 0 ) { //printf("pending.(%s)\n",jprint(retjson,0)); return(retjson); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5c82b789d..b9c78a612 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -704,7 +704,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: } if ( AddNormalinputs(mtx,mypk,3*txfee,60) > 0 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,destpub)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(CCtxidaddr(txidaddr,cointxid))) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeGatewaysOpRet('D',coin,bindtxid,publishers,txids,height,cointxid,deposithex,proof,destpub,amount))); } @@ -714,7 +714,7 @@ std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std:: std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount) { - CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; int64_t totalsupply,depositamount,inputs,CCchange=0; int32_t numvouts; uint256 hashBlock,assetid,oracletxid; char str[65],depositaddr[64],coinaddr[64],destaddr[64]; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) txfee = 10000; @@ -747,6 +747,8 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui { if ( inputs > amount ) CCchange = (inputs - amount); + _GetCCaddress(destaddr,EVAL_GATEWAYS,mypk); + printf("expecting deposittxid/v0 to be to %s\n",destaddr); mtx.vin.push_back(CTxIn(deposittxid,0,CScript())); // triggers EVAL_GATEWAYS validation mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,amount,mypk)); // transfer back to normal token if ( CCchange != 0 ) From 1449ae165f6923f8dadf60f132db5fee5bbf4287 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Oct 2018 18:29:33 -1100 Subject: [PATCH 176/749] Fix bug in consensus code from miketout for small networks --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0aadc130c..d5adb5d69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -397,7 +397,7 @@ namespace { if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); - if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) + if (itOld != mapBlockIndex.end() && itOld->second != 0 && itOld->second->nChainWork > 0) { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; @@ -3876,7 +3876,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { // Remove the invalidity flag from this block and all its descendants. BlockMap::iterator it = mapBlockIndex.begin(); - while (it != mapBlockIndex.end()) { + while (it != mapBlockIndex.end() && it->second != 0) { if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) { it->second->nStatus &= ~BLOCK_FAILED_MASK; setDirtyBlockIndex.insert(it->second); @@ -4680,7 +4680,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; - if ( 1 ) + if ( 0 ) // miket's fixes in ReconsiderBlock and ProcessBlockAvailability deprecate the need { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); From eb94acf7337d4b3a701527902fe71fed55e0a70e Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sun, 7 Oct 2018 17:06:27 +0300 Subject: [PATCH 177/749] + freq:5 for EMC2 --- src/dpowassets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index 40bf0e624..2e74f9de3 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -43,4 +43,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUSH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PIRATE\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGNX\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EMC2\",\"freq\":10,\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EMC2\",\"freq\":5,\"pubkey\":\"$pubkey\"}" From 0de9262b57cd7c3795e88f0e9aeb7f59a9a84a05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Oct 2018 00:00:46 -1100 Subject: [PATCH 178/749] Change prints --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 2 +- src/komodo_kv.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b233f2ffa..e303c2bac 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -851,7 +851,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) printf("%02x",scriptPubKey[k]); printf(" scriptPubKey doesnt match any notary vini.%d of %d\n",j,numvins); } - } else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); + } //else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); } numvalid = bitweight(signedmask); if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 86ed8f7b3..8e454fd5d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1450,7 +1450,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); if ( bhash < bnTarget ) { - fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + //fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); isPoS = 0; } } diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 37e11d06d..834584e44 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -117,7 +117,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) } valueptr = &key[keylen]; fee = komodo_kvfee(flags,opretlen,keylen); - //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + //fprintf(stderr,"fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); From 30743f73336751edc3a7b578f1f865668e02d8f4 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 8 Oct 2018 17:45:53 +0200 Subject: [PATCH 179/749] Add checks for correct input data --- src/cc/channels.cpp | 17 +++++++++++++---- src/wallet/rpcwallet.cpp | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index f6133d575..57a587c44 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -207,15 +207,15 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelPayment!"); else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for channelPayment!"); + return eval->Invalid("vin.2 is CC for channelPayment!"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.0 is CC for channelPayment!"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!"); else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for channelPayment (marker to dstPub)!"); + return eval->Invalid("vout.2 is CC for channelPayment (marker to dstPub)!"); else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) - return eval->Invalid("vout.1 is normal for channelPayment!"); + return eval->Invalid("vout.3 is normal for channelPayment!"); else if ( tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) return eval->Invalid("payment funds do not go to receiver!"); else if ( param1 > CHANNELS_MAXPAYMENTS) @@ -487,7 +487,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 fprintf(stderr,"this is not our channel\n"); return(""); } - else if (amount % payment != 0) + else if (amount % payment != 0 || amount prevdepth) + { + fprintf(stderr,"not enough funds in channel for that amount\n"); + return (""); + } else if (numpayments == 0) + { + fprintf(stderr,"invalid amount\n"); + return (""); + } if (secret!=zeroid) { endiancpy(hash, (uint8_t * ) & secret, 32); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d97df5b3a..aa5392472 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5146,8 +5146,23 @@ UniValue channelsopen(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); + if (destpub.size()!= 33) + { + ERR_RESULT("invalid destination pubkey"); + return result; + } numpayments = atoi(params[1].get_str().c_str()); + if (numpayments <1) + { + ERR_RESULT("invalid number of payments, must be greater than 0"); + return result; + } payment = atol(params[2].get_str().c_str()); + if (payment <1) + { + ERR_RESULT("invalid payment amount, must be greater than 0"); + return result; + } hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment); if ( hex.size() > 0 ) { @@ -5169,6 +5184,11 @@ UniValue channelspayment(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); amount = atoi((char *)params[1].get_str().c_str()); + if (amount <1) + { + ERR_RESULT("invalid payment amount, must be greater than 0"); + return result; + } if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty()) { secret = Parseuint256((char *)params[2].get_str().c_str()); From b32790aed80987ab0fc8ba3c184ad4061b74312a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Oct 2018 09:08:55 -1100 Subject: [PATCH 180/749] -dpowassets --- src/dpowassets | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100755 src/dpowassets diff --git a/src/dpowassets b/src/dpowassets deleted file mode 100755 index 88e6f72b8..000000000 --- a/src/dpowassets +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -set -x -source pubkey.txt -echo $pubkey -sleep 3 - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}" - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SUPERNET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DEX\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PANGEA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JUMBLR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"COQUI\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WLC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHAIN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NINJA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RFOX\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" From e3eea615467a985aba205f23fe2e7ea59e7e658a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Oct 2018 09:09:23 -1100 Subject: [PATCH 181/749] -dpowassets --- src/dpowassets | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100755 src/dpowassets diff --git a/src/dpowassets b/src/dpowassets deleted file mode 100755 index 2e74f9de3..000000000 --- a/src/dpowassets +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -set -x -source pubkey.txt -echo $pubkey -sleep 3 - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}" - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SUPERNET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DEX\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PANGEA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JUMBLR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"COQUI\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WLC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHAIN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NINJA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RFOX\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUSH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PIRATE\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGNX\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EMC2\",\"freq\":5,\"pubkey\":\"$pubkey\"}" From 702658f047753930525499fa542453c8fa14e887 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 9 Oct 2018 16:22:36 +0200 Subject: [PATCH 182/749] Code clean up --- src/cc/channels.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 57a587c44..bd0b5bb7f 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -163,7 +163,6 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; - fprintf(stderr,"validateCC\n"); if ( numvouts < 1 ) return eval->Invalid("no vouts"); else @@ -353,8 +352,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) - fprintf(stderr,"Channelsget validated\n"); - else fprintf(stderr,"Channelsget invalid\n"); + fprintf(stderr,"Channel tx validated\n"); + else fprintf(stderr,"Channel tx invalid\n"); return(retval); } } @@ -377,7 +376,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C } else { - fprintf(stderr,"invalid open txid\n"); + fprintf(stderr,"invalid channel open txid\n"); return 0; } @@ -396,7 +395,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C } if (txid!=zeroid && myIsutxo_spentinmempool(txid,0) != 0) { - fprintf(stderr,"spent in mempool\n"); txid=zeroid; int32_t mindepth=CHANNELS_MAXPAYMENTS; BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) @@ -428,7 +426,9 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) { - CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; + CPubKey mypk; struct CCcontract_info *cp,C; + if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { CCerror = strprintf("invalid ChannelOpen param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment); @@ -481,7 +481,6 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { - if (mypk != srcpub && mypk != destpub) { fprintf(stderr,"this is not our channel\n"); @@ -589,7 +588,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) } if (mypk != srcpub) { - fprintf(stderr,"this channel is not in our ownership\n"); + fprintf(stderr,"cannot close, you are not channel owner\n"); return(""); } if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) @@ -637,7 +636,6 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } if (txid!=opentxid) { - fprintf(stderr,"%s - %s\n",txid.ToString().c_str(),opentxid.ToString().c_str()); fprintf(stderr, "open and close txid are not from same channel\n"); return (""); } @@ -653,14 +651,15 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } if (mypk != srcpub) { - fprintf(stderr,"this channel is not in our ownership\n"); + fprintf(stderr,"cannot refund, you are not the channel owenr\n"); return(""); } if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0) { - if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) + if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && + DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); @@ -745,7 +744,8 @@ UniValue ChannelsInfo(uint256 channeltxid) } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) { - if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && + DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { Getscriptaddress(str2,tx.vout[3].scriptPubKey); sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1); From 3cc05dc7b84b59ed9776d30565da20ca607be941 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Thu, 11 Oct 2018 04:07:04 +0300 Subject: [PATCH 183/749] PGT --- src/ac/pgt | 2 ++ src/assetchains.json | 8 ++++++++ src/assetchains.old | 1 + src/fiat/pgt | 2 ++ 4 files changed, 13 insertions(+) create mode 100755 src/ac/pgt create mode 100755 src/fiat/pgt diff --git a/src/ac/pgt b/src/ac/pgt new file mode 100755 index 000000000..8e124bbd1 --- /dev/null +++ b/src/ac/pgt @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=PGT $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains.json b/src/assetchains.json index f78e19f87..fb20b2cba 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -167,5 +167,13 @@ "addnode": [ "142.93.27.180" ] + }, +{ + "ac_name": "PGT", + "ac_supply": "10000000", + "ac_end": "1", + "addnode": [ + "190.114.254.104" + ] } ] diff --git a/src/assetchains.old b/src/assetchains.old index fcee4bf41..12c743d1d 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -41,3 +41,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & ./komodod -pubkey=$pubkey -ac_name=PIRATE -ac_supply=0 -ac_reward=25600000000 -ac_halving=77777 -ac_private=1 -addnode=136.243.102.225 & ./komodod -pubkey=$pubkey -ac_name=MGNX -ac_supply=12465003 -ac_staked=90 -ac_reward=2000000000 -ac_halving=525960 -ac_cc=2 -ac_end=2629800 -addnode=142.93.27.180 & +./komodod -pubkey=$pubkey -ac_name=PGT -ac_supply=10000000 -ac_end=1 -addnode=190.114.254.104 & diff --git a/src/fiat/pgt b/src/fiat/pgt new file mode 100755 index 000000000..8e124bbd1 --- /dev/null +++ b/src/fiat/pgt @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=PGT $1 $2 $3 $4 $5 $6 From c606ce69255c9dfd6f50a22320480a5f1790b668 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 11:56:02 -1100 Subject: [PATCH 184/749] Backward compatible dPoW enforcement! --- src/dpowassets | 42 --------------------------------------- src/komodo_bitcoind.h | 2 +- src/komodo_notary.h | 15 ++++++++++++++ src/rpcblockchain.cpp | 3 ++- src/rpcrawtransaction.cpp | 7 +++++-- src/wallet/rpcwallet.cpp | 10 +++++++--- 6 files changed, 30 insertions(+), 49 deletions(-) delete mode 100755 src/dpowassets diff --git a/src/dpowassets b/src/dpowassets deleted file mode 100755 index 88e6f72b8..000000000 --- a/src/dpowassets +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -set -x -source pubkey.txt -echo $pubkey -sleep 3 - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}" - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SUPERNET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DEX\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PANGEA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JUMBLR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"COQUI\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WLC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHAIN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NINJA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RFOX\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8e454fd5d..29992c172 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -391,7 +391,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig { if ( (item= jobj(json,(char *)"result")) != 0 ) { - txid_confirmations = jint(item,(char *)"confirmations"); + txid_confirmations = jint(item,(char *)"origconfirmations"); if ( txid_confirmations > 0 && height > txid_confirmations ) txid_height = height - txid_confirmations; else txid_height = height; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 04fd30d5f..ffe575356 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -452,6 +452,21 @@ int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 * } } +int32_t komodo_dpowconfs(int32_t txheight,int32_t numconfs) +{ + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; + if ( txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 ) + { + if ( sp->NOTARIZED_HEIGHT > 0 ) + { + if ( txheight < sp->NOTARIZED_HEIGHT ) + return(numconfs); + else return(1); + } + } + return(numconfs); +} + int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t height,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip) { struct notarized_checkpoint *np = 0; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e9cf54bb4..893c291b0 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -32,6 +32,7 @@ using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); int32_t komodo_longestchain(); +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty) { @@ -1150,7 +1151,7 @@ UniValue gettxout(const UniValue& params, bool fHelp) ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) ret.push_back(Pair("confirmations", 0)); - else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); + else ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1))); ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); uint64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->nHeight)) != 0 ) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 9471abf0a..0d2edfd52 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -34,6 +34,7 @@ using namespace std; extern char ASSETCHAINS_SYMBOL[]; +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex) { @@ -230,7 +231,8 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& if (nConfirmations > 0) { entry.push_back(Pair("height", nHeight)); - entry.push_back(Pair("confirmations", nConfirmations)); + entry.push_back(Pair("confirmations", komodo_dpowconfs(nHeight,nConfirmations))); + entry.push_back(Pair("origconfirmations", nConfirmations)); entry.push_back(Pair("time", nBlockTime)); entry.push_back(Pair("blocktime", nBlockTime)); } else { @@ -290,7 +292,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) CBlockIndex* pindex = (*mi).second; if (chainActive.Contains(pindex)) { entry.push_back(Pair("height", pindex->nHeight)); - entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight)); + entry.push_back(Pair("origconfirmations", 1 + chainActive.Height() - pindex->nHeight)); + entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->nHeight,1 + chainActive.Height() - pindex->nHeight))); entry.push_back(Pair("time", pindex->GetBlockTime())); entry.push_back(Pair("blocktime", pindex->GetBlockTime())); } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa5392472..f5b38dc57 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -47,6 +47,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); extern uint8_t ASSETCHAINS_PRIVATE; uint32_t komodo_segid32(char *coinaddr); +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -2698,7 +2699,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; - UniValue entry(UniValue::VOBJ); + UniValue entry(UniValue::VOBJ); int32_t txheight = 0; entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("vout", out.i)); entry.push_back(Pair("generated", out.tx->IsCoinBase())); @@ -2723,7 +2724,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; - uint64_t interest; uint32_t locktime; int32_t txheight; + uint64_t interest; uint32_t locktime; if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); @@ -2732,7 +2733,10 @@ UniValue listunspent(const UniValue& params, bool fHelp) } //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } - entry.push_back(Pair("confirmations",out.nDepth)); + else if ( (tipindex= chainActive.LastTip()) != 0 ) + txheight = (tipindex->nHeight - out.nDepth - 1); + entry.push_back(Pair("origconfirmations",out.nDepth)); + entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); } From 956a638a6026e68b47aea9a2e3af018986546cda Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 11:59:55 -1100 Subject: [PATCH 185/749] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f5b38dc57..2a7f7d1f3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2733,8 +2733,8 @@ UniValue listunspent(const UniValue& params, bool fHelp) } //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } - else if ( (tipindex= chainActive.LastTip()) != 0 ) - txheight = (tipindex->nHeight - out.nDepth - 1); + else if ( chainActive.LastTip() != 0 ) + txheight = (tipchainActive.LastTip()->nHeight - out.nDepth - 1); entry.push_back(Pair("origconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); From 20523c958c3e5a391fe655348a68c9cd91a2c7b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:00:58 -1100 Subject: [PATCH 186/749] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2a7f7d1f3..22aecf320 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2734,7 +2734,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } else if ( chainActive.LastTip() != 0 ) - txheight = (tipchainActive.LastTip()->nHeight - out.nDepth - 1); + txheight = (chainActive.LastTip()->nHeight - out.nDepth - 1); entry.push_back(Pair("origconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); From a079cdbc6c2f07e1e5c751cd287b2d02b9bcd475 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:39:06 -1100 Subject: [PATCH 187/749] rawconfirmations --- src/komodo_bitcoind.h | 2 +- src/rpcrawtransaction.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 29992c172..73a49e10c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -391,7 +391,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig { if ( (item= jobj(json,(char *)"result")) != 0 ) { - txid_confirmations = jint(item,(char *)"origconfirmations"); + txid_confirmations = jint(item,(char *)"rawconfirmations"); if ( txid_confirmations > 0 && height > txid_confirmations ) txid_height = height - txid_confirmations; else txid_height = height; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 0d2edfd52..a870d526c 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -232,7 +232,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& if (nConfirmations > 0) { entry.push_back(Pair("height", nHeight)); entry.push_back(Pair("confirmations", komodo_dpowconfs(nHeight,nConfirmations))); - entry.push_back(Pair("origconfirmations", nConfirmations)); + entry.push_back(Pair("rawconfirmations", nConfirmations)); entry.push_back(Pair("time", nBlockTime)); entry.push_back(Pair("blocktime", nBlockTime)); } else { @@ -292,7 +292,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) CBlockIndex* pindex = (*mi).second; if (chainActive.Contains(pindex)) { entry.push_back(Pair("height", pindex->nHeight)); - entry.push_back(Pair("origconfirmations", 1 + chainActive.Height() - pindex->nHeight)); + entry.push_back(Pair("rawconfirmations", 1 + chainActive.Height() - pindex->nHeight)); entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->nHeight,1 + chainActive.Height() - pindex->nHeight))); entry.push_back(Pair("time", pindex->GetBlockTime())); entry.push_back(Pair("blocktime", pindex->GetBlockTime())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 22aecf320..e7c8e2bdd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2735,7 +2735,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) } else if ( chainActive.LastTip() != 0 ) txheight = (chainActive.LastTip()->nHeight - out.nDepth - 1); - entry.push_back(Pair("origconfirmations",out.nDepth)); + entry.push_back(Pair("rawconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); From ade1fc54a8cf891ffcc00d67029a99a3c744e2a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:44:34 -1100 Subject: [PATCH 188/749] KOMODO_DPOWCONFS --- src/komodo_globals.h | 2 +- src/komodo_notary.h | 2 +- src/komodo_utils.h | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f352b5333..a3a4e3cae 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,7 +52,7 @@ uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT; +uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index ffe575356..8c51c7924 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -455,7 +455,7 @@ int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 * int32_t komodo_dpowconfs(int32_t txheight,int32_t numconfs) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; - if ( txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 ) + if ( KOMODO_DPOWCONFS != 0 && txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 ) { if ( sp->NOTARIZED_HEIGHT > 0 ) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 75f68d87d..0a3c6754e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1709,6 +1709,8 @@ void komodo_args(char *argv0) ASSETCHAINS_HALVING *= 5; fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); } + else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) + KOMODO_DPOWCONFS = 0; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } From cd91f5d473a9c8037251d879c9bb5ea0ca0399e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:47:14 -1100 Subject: [PATCH 189/749] -dpowconfs --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0a3c6754e..62d3b0d3a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,6 +1512,7 @@ void komodo_args(char *argv0) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); + KOMODO_DPOWCONFS = GetArg("-dpowconfs",KOMODO_DPOWCONFS); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { USE_EXTERNAL_PUBKEY = 1; From a14f4bfe51407bcf7330d95ccb06f3910f651ccb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 21:09:45 -1100 Subject: [PATCH 190/749] Msig prints --- src/cc/gateways.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b9c78a612..a659f82ab 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -189,8 +189,10 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st if ( prefix == 60 ) { if ( N > 1 ) + { Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); - else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); + fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr); + } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); } else { From e2ad1fedd33ca7425c9dbebd121476ffa9cff13e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 21:21:27 -1100 Subject: [PATCH 191/749] Test --- src/cc/gateways.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index a659f82ab..d2c43ad56 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -190,6 +190,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st { if ( N > 1 ) { + strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,pubkeys))).ToString().c_str()); Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr); } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); From fb207182c8caf10dc58509a7807bcd210d74ef2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Oct 2018 16:24:23 -1100 Subject: [PATCH 192/749] Dpowconfs default 0 for VRSC --- src/komodo_utils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 62d3b0d3a..e6f6a044d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,7 +1512,6 @@ void komodo_args(char *argv0) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); - KOMODO_DPOWCONFS = GetArg("-dpowconfs",KOMODO_DPOWCONFS); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { USE_EXTERNAL_PUBKEY = 1; @@ -1701,6 +1700,7 @@ void komodo_args(char *argv0) break; } } + int32_t dpowconfs = KOMODO_DPOWCONFS; if ( ASSETCHAINS_SYMBOL[0] != 0 ) { BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); @@ -1711,8 +1711,9 @@ void komodo_args(char *argv0) fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); } else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) - KOMODO_DPOWCONFS = 0; + dpowconfs = 0; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); + KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); } void komodo_nameset(char *symbol,char *dest,char *source) From 6be00678e5c67a6e8d55bc43d044690fe50735da Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 16 Oct 2018 00:13:39 -1100 Subject: [PATCH 193/749] Add raw confirmations for gettxout --- src/rpcblockchain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 893c291b0..01033bb4b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1151,7 +1151,11 @@ UniValue gettxout(const UniValue& params, bool fHelp) ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) ret.push_back(Pair("confirmations", 0)); - else ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1))); + else + { + ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1))); + ret.push_back(Pair("rawconfirmations", pindex->nHeight - coins.nHeight + 1)); + } ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); uint64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->nHeight)) != 0 ) From 71ab53ffb7b13178d75aa49b5f88b8c10a238b01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 16 Oct 2018 00:17:28 -1100 Subject: [PATCH 194/749] Confirmations/rawconfirmations to block rpc --- src/rpcblockchain.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 01033bb4b..815860c7d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -118,7 +118,8 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) // Only report confirmations if the block is on the main chain if (chainActive.Contains(blockindex)) confirmations = chainActive.Height() - blockindex->nHeight + 1; - result.push_back(Pair("confirmations", confirmations)); + result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations))); + result.push_back(Pair("rawconfirmations", confirmations)); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", blockindex->nVersion)); result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex())); @@ -149,7 +150,8 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) } else { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block is an orphan"); } - result.push_back(Pair("confirmations", confirmations)); + result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations))); + result.push_back(Pair("rawconfirmations", confirmations)); result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); @@ -266,7 +268,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx // Only report confirmations if the block is on the main chain if (chainActive.Contains(blockindex)) confirmations = chainActive.Height() - blockindex->nHeight + 1; - result.push_back(Pair("confirmations", confirmations)); + result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations))); + result.push_back(Pair("rawconfirmations", confirmations)); result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); From 07b1fe7785a1944e36f2f57f7515aff2f4bae579 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 16 Oct 2018 17:36:01 +0200 Subject: [PATCH 195/749] Fix oraclesinfo --- src/cc/oracles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 5a352afeb..6db1d0b6c 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -854,7 +854,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) UniValue OracleInfo(uint256 origtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ); + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector > unspentOutputs; CMutableTransaction mtx; CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); @@ -877,6 +877,7 @@ UniValue OracleInfo(uint256 origtxid) { if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid ) { + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("publisher",pubkey33_str(str,(uint8_t *)pk.begin()))); Getscriptaddress(batonaddr,regtx.vout[1].scriptPubKey); batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data); From 951627d7cb22a3e4ad4975033aad9e8ca4421626 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Thu, 18 Oct 2018 16:17:17 +0700 Subject: [PATCH 196/749] this space made tests failing --- qa/rpc-tests/cryptoconditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index e7d3065cc..cb83b7243 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -602,4 +602,4 @@ class CryptoConditionsTest (BitcoinTestFramework): if __name__ == '__main__': - CryptoConditionsTest ().main () + CryptoConditionsTest ().main() From 8b8b7f048ec8ae9110f2eeddb63db17bfcb8383e Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 19 Oct 2018 13:30:28 +0700 Subject: [PATCH 197/749] added validation for oraclesinfo --- src/cc/oracles.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 6db1d0b6c..7cccad0f6 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -859,6 +859,13 @@ UniValue OracleInfo(uint256 origtxid) CMutableTransaction mtx; CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); + if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find oracleid\n"); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant find oracleid")); + return(result); + } if ( GetTransaction(origtxid,tx,hashBlock,false) != 0 ) { if ( tx.vout.size() > 0 && DecodeOraclesCreateOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,name,description,format) == 'C' ) From a3ee81a87385539e22620bad54ae7efbdabd629a Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 19 Oct 2018 17:13:32 +0700 Subject: [PATCH 198/749] added oracle data type validation --- src/wallet/rpcwallet.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e7c8e2bdd..c7d4f8a16 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5733,6 +5733,24 @@ UniValue oraclescreate(const UniValue& params, bool fHelp) ERR_RESULT("oracles format must be <= 4096 characters"); return(result); } + // list of oracle valid formats from oracles.cpp -> oracle_format + const UniValue valid_formats[13] = {"s","S","d","D","c","C","t","T","i","I","l","L","h"}; + const UniValue header_type = "Ihh"; + // checking if oracle data type is valid + bool is_valid_format = false; + for ( int i = 0; i < 13; ++i ) { + if ( valid_formats[i].get_str() == format ) { + is_valid_format = true; + } + } + // additional check for special Ihh data type + if ( format == header_type.get_str() ) { + is_valid_format = true; + } + if ( !is_valid_format ) { + ERR_RESULT("oracles format not valid"); + return(result); + } hex = OracleCreate(0,name,description,format); if ( hex.size() > 0 ) { From 8c2c4c7ecce80d68248418a9474f0f4326e9bad4 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 19 Oct 2018 18:24:58 +0700 Subject: [PATCH 199/749] added oracles creation rpc tests --- qa/rpc-tests/cryptoconditions.py | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index cb83b7243..1d2f68777 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -3,6 +3,7 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. + from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ @@ -11,6 +12,8 @@ from test_framework.util import assert_equal, assert_greater_than, \ import time from decimal import Decimal +from random import choice +from string import ascii_uppercase def assert_success(result): assert_equal(result['result'], 'success') @@ -18,6 +21,11 @@ def assert_success(result): def assert_error(result): assert_equal(result['result'], 'error') +def generate_random_string(length): + random_string = ''.join(choice(ascii_uppercase) for i in range(length)) + return random_string + + class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): @@ -470,7 +478,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenbalance(tokenid,randompubkey) assert_equal(result["balance"], 1) - def run_rewards_tests(self): rpc = self.nodes[0] result = rpc.rewardsaddress() @@ -581,6 +588,51 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) assert_error(result) + def run_oracles_tests(self): + rpc = self.nodes[0] + result = rpc.oraclesaddress() + assert_success(result) + for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.oraclesaddress(self.pubkey) + assert_success(result) + for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + assert_equal(result[x][0], 'R') + + # there are no oracles created yet + result = rpc.oracleslist() + assert_equal(result, []) + + # looking up non-existent oracle should return error. + result = rpc.oraclesinfo("none") + assert_error(result) + + # attempt to create oracle with not valid data type should return error + result = rpc.oraclescreate("Test", "Test", "Test") + assert_error(result) + + # attempt to create oracle with description > 32 symbols should return error + too_long_name = generate_random_string(33) + result = rpc.oraclescreate(too_long_name, "Test", "s") + + + # attempt to create oracle with description > 4096 symbols should return error + too_long_description = generate_random_string(4100) + result = rpc.oraclescreate("Test", too_long_description, "s") + assert_error(result) + + # valid creating oracles of different types + # using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type) + valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"] + for f in valid_formats: + result = rpc.oraclescreate("Test", "Test", f) + assert_success(result) + globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex']) + + + + def run_test (self): print("Mining blocks...") @@ -594,11 +646,12 @@ class CryptoConditionsTest (BitcoinTestFramework): print("Importing privkey") rpc.importprivkey(self.privkey) -# self.run_faucet_tests() + #self.run_faucet_tests() self.run_rewards_tests() self.run_dice_tests() self.run_token_tests() self.run_faucet_tests() + self.run_oracles_tests() if __name__ == '__main__': From 39e950f8d87f20879829c0c94a026cb188b37104 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 19 Oct 2018 16:17:37 +0200 Subject: [PATCH 200/749] Fix oraclefeed bugs and gatewaysmultisig rpc call --- src/cc/dapps/oraclefeed.c | 7 ++++--- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index eaf488a34..3662b7742 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -332,6 +332,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char if ( (jsonstr= filestr(&fsize,fname)) != 0 ) { //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); + jsonstr[strlen(jsonstr)-1]='\0'; if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 ) *retstrp = jsonstr; else free(jsonstr); @@ -584,7 +585,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad return(0); } satoshis -= txfee; - sprintf(array,"[\"%s\"]",depositaddr); + sprintf(array,"\'[\"%s\"]\'",depositaddr); if ( (retjson= get_komodocli(refcoin,&retstr,acname,"listunspent","1","99999999",array,"")) != 0 ) { //createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} @@ -628,7 +629,7 @@ cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx char *retstr,*hexstr; cJSON *retjson; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"signrawtransaction",rawtx,"","","")) != 0 ) { - if ( jint(retjson,"complete") != 0 ) + if ( is_cJSON_True(jobj(retjson,"complete")) != 0 ) return(retjson); else if ( (hexstr= jstr(retjson,"hex")) != 0 && strlen(hexstr) > strlen(rawtx) ) { @@ -814,7 +815,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t { if ( (clijson= addmultisignature(refcoin,"",signeraddr,rawtx)) != 0 ) { - if ( jint(clijson,"complete") != 0 ) + if ( is_cJSON_True(jobj(clijson,"complete")) != 0 ) { cointxid = komodobroadcast(refcoin,"",clijson); if ( bits256_nonz(cointxid) != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e7c8e2bdd..59f0b6ba7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5593,7 +5593,7 @@ UniValue gatewayspending(const UniValue& params, bool fHelp) UniValue gatewaysmultisig(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); uint256 bindtxid,withtxid; std::string coin,hex; char *txidaddr; - if ( fHelp || params.size() != 2 ) + if ( fHelp || params.size() != 4 ) throw runtime_error("gatewaysmultisig bindtxid coin withtxid txidaddr\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From 7b8cefe19280659e2c3e7564478106b6009c23dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Oct 2018 06:37:24 -1100 Subject: [PATCH 201/749] Wallettx2json raw confirmations --- src/cc/gateways.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index d2c43ad56..1db08532a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -191,7 +191,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st if ( N > 1 ) { strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,pubkeys))).ToString().c_str()); - Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); + //Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr); } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c7d4f8a16..c9bffbb33 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -90,7 +90,8 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) { //int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; int confirms = wtx.GetDepthInMainChain(); - entry.push_back(Pair("confirmations", confirms)); + entry.push_back(Pair("rawconfirmations", confirms)); + entry.push_back(Pair("confirmations", komodo_dpowconfs((int32_t)mapBlockIndex[wtx.hashBlock]->nHeight,confirms))); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); if (confirms > 0) From 58c81292536f88491d85742fd3aa64970f40158e Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 19 Oct 2018 20:38:10 +0200 Subject: [PATCH 202/749] Another oraclefeed fix --- src/cc/dapps/oraclefeed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 3662b7742..aca027b07 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -601,8 +601,8 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad jaddnum(vouts,depositaddr,(double)change/SATOSHIDEN); } char *argA,*argB; - argA = jprint(vins,1); - argB = jprint(vouts,1); + sprintf(argA,"\'%s\'",jprint(vins,1)); + sprintf(argB,"\'%s\'",jprint(vouts,1)); if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) { printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); From 029bd0dd5d331d21b5df5c542f9afb76a735fa66 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 19 Oct 2018 20:58:26 +0200 Subject: [PATCH 203/749] Fix --- src/cc/dapps/oraclefeed.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index aca027b07..d9bda7309 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -600,9 +600,14 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad change = (total - satoshis); jaddnum(vouts,depositaddr,(double)change/SATOSHIDEN); } - char *argA,*argB; - sprintf(argA,"\'%s\'",jprint(vins,1)); - sprintf(argB,"\'%s\'",jprint(vouts,1)); + char *tmpA=jprint(vins,1); + char *tmpB=jprint(vouts,1); + char *argA=malloc(sizeof(char) * (strlen(tmpA)+3)); + char *argB=malloc(sizeof(char) * (strlen(tmpB)+3)); + sprintf(argA,"\'%s\'",tmpA); + sprintf(argB,"\'%s\'",tmpB); + printf("%s\n",argA); + printf("%s\n",argB); if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) { printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); From 0440e8a805aec3354f68ba378ecdee580800e052 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Oct 2018 08:08:12 -1100 Subject: [PATCH 204/749] %s/Komodo server stopping --- src/rpcserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 7d2eab1e3..25af4619c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -250,7 +250,7 @@ UniValue stop(const UniValue& params, bool fHelp) "\nStop Komodo server."); // Shutdown will take long enough that the response should get back StartShutdown(); - sprintf(buf,"%s Komodo server stopping",ASSETCHAINS_SYMBOL); + sprintf(buf,"%s server stopping",ASSETCHAINS_SYMBOL[0] != 0 ? ASSETCHAINS_SYMBOL : "Komodo"); return buf; } From b1c08466e9a974de8b70bf3f3e43d85fb99ecf23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Oct 2018 11:13:35 -1100 Subject: [PATCH 205/749] Initial -ac_txpow 0, 1, 2, 3 with validation, but no txcreation --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 5 +++-- src/main.cpp | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index a3a4e3cae..1ebfdd16c 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,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; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e6f6a044d..dd7082ffa 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1554,6 +1554,7 @@ void komodo_args(char *argv0) if ( name.c_str()[0] != 0 ) { MAX_BLOCK_SIGOPS = 60000; + ASSETCHAINS_TXPOW = GetArg("-ac_txpow",0) & 3; ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10); ASSETCHAINS_ENDSUBSIDY = GetArg("-ac_end",0); ASSETCHAINS_REWARD = GetArg("-ac_reward",0); @@ -1590,7 +1591,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 0; printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); } - if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) + 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 ) { 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]); extraptr = extrabuf; @@ -1599,7 +1600,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6); + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); diff --git a/src/main.cpp b/src/main.cpp index d5adb5d69..10ec346c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1128,6 +1128,18 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio // Check for negative or overflow output values CAmount nValueOut = 0; int32_t iscoinbase = tx.IsCoinBase(); + if ( ASSETCHAINS_TXPOW != 0 ) + { + uint256 txid = tx.GetHash(); + if ( ((ASSETCHAINS_TXPOW & 2) != 0 && iscoinbase != 0) || ((ASSETCHAINS_TXPOW & 1) != 0 && iscoinbase == 0) ) + { + if ( ((uint8_t)&txid)[0] != 0 || ((uint8_t)&txid)[31] != 0 ) + { + fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d\n",iscoinbase,ASSETCHAINS_TXPOW); + return state.DoS(100, error("CheckTransaction(): this is a txpow chain, must have 0x00 ends"),REJECT_INVALID, "bad-txns-actxpow-chain"); + } + } + } BOOST_FOREACH(const CTxOut& txout, tx.vout) { if (txout.nValue < 0) @@ -3185,7 +3197,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!pblocktree->UpdateSpentIndex(spentIndex)) return AbortNode(state, "Failed to write transaction index"); - if (fTimestampIndex) { + if (fTimestampIndex) + { unsigned int logicalTS = pindex->nTime; unsigned int prevLogicalTS = 0; From b8fefe8a2681de81b6bb183e95eaf476bb2ae148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Oct 2018 11:17:32 -1100 Subject: [PATCH 206/749] Syntax --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 10ec346c3..cf46b9ec9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1133,9 +1133,9 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio uint256 txid = tx.GetHash(); if ( ((ASSETCHAINS_TXPOW & 2) != 0 && iscoinbase != 0) || ((ASSETCHAINS_TXPOW & 1) != 0 && iscoinbase == 0) ) { - if ( ((uint8_t)&txid)[0] != 0 || ((uint8_t)&txid)[31] != 0 ) + if ( ((uint8_t *)&txid)[0] != 0 || ((uint8_t *)&txid)[31] != 0 ) { - fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d\n",iscoinbase,ASSETCHAINS_TXPOW); + fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d txid.%s\n",iscoinbase,ASSETCHAINS_TXPOW,txid.GetHex().c_str()); return state.DoS(100, error("CheckTransaction(): this is a txpow chain, must have 0x00 ends"),REJECT_INVALID, "bad-txns-actxpow-chain"); } } From 19e4c023b6812b3320a80c7fedd365d647e3b60b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Oct 2018 11:36:18 -1100 Subject: [PATCH 207/749] ASSETCHAINS_TXPOW for signrawtransaction --- src/komodo_defs.h | 2 + src/rpcrawtransaction.cpp | 79 ++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 7c339856c..1efd187d9 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -10,4 +10,6 @@ #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +extern uint8_t ASSETCHAINS_TXPOW; + #endif diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index a870d526c..e7d1d991d 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -1058,35 +1058,64 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) // Use CTransaction for the constant parts of the // transaction to avoid rehashing. + CMutableTransaction mergedTxsave = mergedTx; + int32_t txpow,numiters = 0; const CTransaction txConst(mergedTx); - // Sign what we can: - for (unsigned int i = 0; i < mergedTx.vin.size(); i++) { - CTxIn& txin = mergedTx.vin[i]; - const CCoins* coins = view.AccessCoins(txin.prevout.hash); - if (coins == NULL || !coins->IsAvailable(txin.prevout.n)) { - TxInErrorToJSON(txin, vErrors, "Input not found or already spent"); - continue; + if ( (txpow= ASSETCHAINS_TXPOW) != 0 ) + { + if ( txConst.IsCoinBase() != 0 ) + { + if ( (txpow & 2) == 0 ) + txpow == 0; } - const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey; - const CAmount& amount = coins->vout[txin.prevout.n].nValue; - - SignatureData sigdata; - // Only sign SIGHASH_SINGLE if there's a corresponding output: - if (!fHashSingle || (i < mergedTx.vout.size())) - ProduceSignature(MutableTransactionSignatureCreator(&keystore, &mergedTx, i, amount, nHashType), prevPubKey, sigdata, consensusBranchId); - - // ... and merge in other signatures: - BOOST_FOREACH(const CMutableTransaction& txv, txVariants) { - sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(txv, i), consensusBranchId); - } - - UpdateTransaction(mergedTx, i, sigdata); - - ScriptError serror = SCRIPT_ERR_OK; - if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount), consensusBranchId, &serror)) { - TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror)); + else + { + if ( (txpow & 1) == 0 ) + txpow == 0; } } + while ( 1 ) + { + if ( txpow != 0 ) + mergedTx = mergedTxsave; + // Sign what we can: + for (unsigned int i = 0; i < mergedTx.vin.size(); i++) { + CTxIn& txin = mergedTx.vin[i]; + const CCoins* coins = view.AccessCoins(txin.prevout.hash); + if (coins == NULL || !coins->IsAvailable(txin.prevout.n)) { + TxInErrorToJSON(txin, vErrors, "Input not found or already spent"); + continue; + } + const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey; + const CAmount& amount = coins->vout[txin.prevout.n].nValue; + + SignatureData sigdata; + // Only sign SIGHASH_SINGLE if there's a corresponding output: + if (!fHashSingle || (i < mergedTx.vout.size())) + ProduceSignature(MutableTransactionSignatureCreator(&keystore, &mergedTx, i, amount, nHashType), prevPubKey, sigdata, consensusBranchId); + + // ... and merge in other signatures: + BOOST_FOREACH(const CMutableTransaction& txv, txVariants) { + sigdata = CombineSignatures(prevPubKey, TransactionSignatureChecker(&txConst, i, amount), sigdata, DataFromTransaction(txv, i), consensusBranchId); + } + + UpdateTransaction(mergedTx, i, sigdata); + + ScriptError serror = SCRIPT_ERR_OK; + if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i, amount), consensusBranchId, &serror)) { + TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror)); + } + } + if ( txpow != 0 ) + { + uint256 txid = mergedTx.GetHash(); + if ( ((uint8_t *)&txid)[0] == 0 && ((uint8_t *)&txid)[31] == 0 ) + break; + } + numiters++; + } + if ( numiters > 0 ) + fprintf(stderr,"ASSETCHAINS_TXPOW.%d txpow.%d numiters.%d for signature\n",ASSETCHAINS_TXPOW,txpow,numiters); bool fComplete = vErrors.empty(); UniValue result(UniValue::VOBJ); From de59290f47e2d04d1dd00b1f7f80fcfced18cea1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Oct 2018 12:03:24 -1100 Subject: [PATCH 208/749] Exeption for genesis coinbase --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cf46b9ec9..f5c8280d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1130,13 +1130,18 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio int32_t iscoinbase = tx.IsCoinBase(); if ( ASSETCHAINS_TXPOW != 0 ) { + // genesis coinbase 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b uint256 txid = tx.GetHash(); if ( ((ASSETCHAINS_TXPOW & 2) != 0 && iscoinbase != 0) || ((ASSETCHAINS_TXPOW & 1) != 0 && iscoinbase == 0) ) { if ( ((uint8_t *)&txid)[0] != 0 || ((uint8_t *)&txid)[31] != 0 ) { - fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d txid.%s\n",iscoinbase,ASSETCHAINS_TXPOW,txid.GetHex().c_str()); - return state.DoS(100, error("CheckTransaction(): this is a txpow chain, must have 0x00 ends"),REJECT_INVALID, "bad-txns-actxpow-chain"); + uint256 genesistxid = ParseHex("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); + if ( txid != genesistxid ) + { + fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d txid.%s\n",iscoinbase,ASSETCHAINS_TXPOW,txid.GetHex().c_str()); + return state.DoS(100, error("CheckTransaction(): this is a txpow chain, must have 0x00 ends"),REJECT_INVALID, "bad-txns-actxpow-chain"); + } } } } From 8551533ace9f549c262eb1eb90fde05f3eb50076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Oct 2018 12:05:58 -1100 Subject: [PATCH 209/749] uint256S --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5c8280d3..98fbb378a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1136,7 +1136,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio { if ( ((uint8_t *)&txid)[0] != 0 || ((uint8_t *)&txid)[31] != 0 ) { - uint256 genesistxid = ParseHex("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); + uint256 genesistxid = uint256S("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); if ( txid != genesistxid ) { fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d txid.%s\n",iscoinbase,ASSETCHAINS_TXPOW,txid.GetHex().c_str()); From cd9d418aa25817b4ee08794dcbc08798fd8413a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Oct 2018 13:38:27 -1100 Subject: [PATCH 210/749] Fix --- src/rpcrawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index e7d1d991d..41433805f 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -1111,7 +1111,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) uint256 txid = mergedTx.GetHash(); if ( ((uint8_t *)&txid)[0] == 0 && ((uint8_t *)&txid)[31] == 0 ) break; - } + } else break; numiters++; } if ( numiters > 0 ) From a2c93c1f0d787c24d06e88791f1223b5dc8d3f39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Oct 2018 05:17:51 -1100 Subject: [PATCH 211/749] Check tx during mining --- src/main.cpp | 2 +- src/miner.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 98fbb378a..c2ce7ec60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2227,7 +2227,7 @@ namespace Consensus { // Ensure that coinbases are matured if (nSpendHeight - coins->nHeight < COINBASE_MATURITY) { return state.Invalid( - error("CheckInputs(): tried to spend coinbase at depth %d", nSpendHeight - coins->nHeight), + error("CheckInputs(): tried to spend coinbase at depth %d/%d", nSpendHeight - coins->nHeight,(int32_t)COINBASE_MATURITY), REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); } diff --git a/src/miner.cpp b/src/miner.cpp index 874c1b4f8..188cffbef 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -335,6 +335,15 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"dont have inputs\n"); continue; } + { + CValidationState state; + auto verifier = libzcash::ProofVerifier::Disabled(); + if ( !CheckTransaction(tx, state, verifier) ) + { + fprintf(stderr,"skip tx.(%s) that failed CheckTransaction\n",txid.GetHex().c_str()); + continue; + } + } CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); From 9f333d205a20347b0bb98af2771587dd9fdfda66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Oct 2018 05:19:05 -1100 Subject: [PATCH 212/749] Fix --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 188cffbef..fcc8d6127 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -340,7 +340,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) auto verifier = libzcash::ProofVerifier::Disabled(); if ( !CheckTransaction(tx, state, verifier) ) { - fprintf(stderr,"skip tx.(%s) that failed CheckTransaction\n",txid.GetHex().c_str()); + fprintf(stderr,"skip tx.(%s) that failed CheckTransaction\n",hash.GetHex().c_str()); continue; } } From 607133377cd9829e77aa7a2540d06b5f5e2efb4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Oct 2018 07:41:46 -1100 Subject: [PATCH 213/749] Randomize signature for txpow --- src/rpcrawtransaction.cpp | 1 + src/script/sign.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 41433805f..168907cff 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -1111,6 +1111,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) uint256 txid = mergedTx.GetHash(); if ( ((uint8_t *)&txid)[0] == 0 && ((uint8_t *)&txid)[31] == 0 ) break; + fprintf(stderr,"%d: tmp txid.%s\n",numiters,txid.GetHex().c_str()); } else break; numiters++; } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 1aade8477..8c152e839 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -16,6 +16,7 @@ using namespace std; typedef vector valtype; +extern uint8_t ASSETCHAINS_TXPOW; TransactionSignatureCreator::TransactionSignatureCreator(const CKeyStore* keystoreIn, const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : BaseSignatureCreator(keystoreIn), txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn) {} @@ -32,8 +33,16 @@ bool TransactionSignatureCreator::CreateSig(std::vector& vchSig, return false; } - if (!key.Sign(hash, vchSig)) - return false; + if ( ASSETCHAINS_TXPOW == 0 ) + { + if (!key.Sign(hash, vchSig)) + return false; + } + else + { + if (!key.Sign(hash, vchSig, rand())) + return false; + } vchSig.push_back((unsigned char)nHashType); return true; } From 0af33a3f0db7e5c9e497a01e9a49b590aa8a23ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Oct 2018 08:01:32 -1100 Subject: [PATCH 214/749] -print, allow ztx to be non 0x00 ends for txpow --- src/main.cpp | 36 ++++++++++++++++++------------------ src/rpcrawtransaction.cpp | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c2ce7ec60..95fdbebae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1128,23 +1128,6 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio // Check for negative or overflow output values CAmount nValueOut = 0; int32_t iscoinbase = tx.IsCoinBase(); - if ( ASSETCHAINS_TXPOW != 0 ) - { - // genesis coinbase 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b - uint256 txid = tx.GetHash(); - if ( ((ASSETCHAINS_TXPOW & 2) != 0 && iscoinbase != 0) || ((ASSETCHAINS_TXPOW & 1) != 0 && iscoinbase == 0) ) - { - if ( ((uint8_t *)&txid)[0] != 0 || ((uint8_t *)&txid)[31] != 0 ) - { - uint256 genesistxid = uint256S("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); - if ( txid != genesistxid ) - { - fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d txid.%s\n",iscoinbase,ASSETCHAINS_TXPOW,txid.GetHex().c_str()); - return state.DoS(100, error("CheckTransaction(): this is a txpow chain, must have 0x00 ends"),REJECT_INVALID, "bad-txns-actxpow-chain"); - } - } - } - } BOOST_FOREACH(const CTxOut& txout, tx.vout) { if (txout.nValue < 0) @@ -1213,7 +1196,24 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio REJECT_INVALID, "bad-txns-txouttotal-toolarge"); } } - + if ( ASSETCHAINS_TXPOW != 0 && tx.vjoinsplit.size() == 0 ) + { + // genesis coinbase 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b + uint256 txid = tx.GetHash(); + if ( ((ASSETCHAINS_TXPOW & 2) != 0 && iscoinbase != 0) || ((ASSETCHAINS_TXPOW & 1) != 0 && iscoinbase == 0) ) + { + if ( ((uint8_t *)&txid)[0] != 0 || ((uint8_t *)&txid)[31] != 0 ) + { + uint256 genesistxid = uint256S("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); + if ( txid != genesistxid ) + { + fprintf(stderr,"private chain iscoinbase.%d invalid txpow.%d txid.%s\n",iscoinbase,ASSETCHAINS_TXPOW,txid.GetHex().c_str()); + return state.DoS(100, error("CheckTransaction(): this is a txpow chain, must have 0x00 ends"),REJECT_INVALID, "bad-txns-actxpow-chain"); + } + } + } + } + // Ensure input values do not exceed MAX_MONEY // We have not resolved the txin values at this stage, // but we do know what the joinsplits claim to add diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 168907cff..e692e1c84 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -1111,7 +1111,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp) uint256 txid = mergedTx.GetHash(); if ( ((uint8_t *)&txid)[0] == 0 && ((uint8_t *)&txid)[31] == 0 ) break; - fprintf(stderr,"%d: tmp txid.%s\n",numiters,txid.GetHex().c_str()); + //fprintf(stderr,"%d: tmp txid.%s\n",numiters,txid.GetHex().c_str()); } else break; numiters++; } From 7e62f8f397a8a686939a2cfbebbfdbe206c65fb2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 16:21:43 +0800 Subject: [PATCH 215/749] show pubkey in getinfo, and enable set pubkey via RPC call. --- src/rpcmisc.cpp | 2 ++ src/rpcserver.cpp | 25 ++++++++------- src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 68 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index a42afbb61..1616a2470 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -158,6 +158,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("pubkey", pubkeystr)); if ( KOMODO_LASTMINED != 0 ) obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); + } else if ( NOTARY_PUBKEY33[0] != 0 ) { + obj.push_back(Pair("pubkey", NOTARY_PUBKEY)); } } if ( ASSETCHAINS_CC != 0 ) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 25af4619c..4bbf565a5 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -350,16 +350,16 @@ static const CRPCCommand vRPCCommands[] = #endif /* auction */ { "auction", "auctionaddress", &auctionaddress, true }, - + /* lotto */ { "lotto", "lottoaddress", &lottoaddress, true }, - + /* fsm */ { "FSM", "FSMaddress", &FSMaddress, true }, { "FSM", "FSMcreate", &FSMcreate, true }, { "FSM", "FSMlist", &FSMlist, true }, { "FSM", "FSMinfo", &FSMinfo, true }, - + /* rewards */ { "rewards", "rewardslist", &rewardslist, true }, { "rewards", "rewardsinfo", &rewardsinfo, true }, @@ -368,16 +368,16 @@ static const CRPCCommand vRPCCommands[] = { "rewards", "rewardslock", &rewardslock, true }, { "rewards", "rewardsunlock", &rewardsunlock, true }, { "rewards", "rewardsaddress", &rewardsaddress, true }, - + /* faucet */ { "faucet", "faucetinfo", &faucetinfo, true }, { "faucet", "faucetfund", &faucetfund, true }, { "faucet", "faucetget", &faucetget, true }, { "faucet", "faucetaddress", &faucetaddress, true }, - + /* MofN */ { "MofN", "mofnaddress", &mofnaddress, true }, - + /* Channels */ { "channels", "channelsaddress", &channelsaddress, true }, { "channels", "channelsinfo", &channelsinfo, true }, @@ -385,7 +385,7 @@ static const CRPCCommand vRPCCommands[] = { "channels", "channelspayment", &channelspayment, true }, { "channels", "channelsclose", &channelsclose, true }, { "channels", "channelsrefund", &channelsrefund, true }, - + /* Oracles */ { "oracles", "oraclesaddress", &oraclesaddress, true }, { "oracles", "oracleslist", &oracleslist, true }, @@ -395,7 +395,7 @@ static const CRPCCommand vRPCCommands[] = { "oracles", "oraclessubscribe", &oraclessubscribe, true }, { "oracles", "oraclesdata", &oraclesdata, true }, { "oracles", "oraclessamples", &oraclessamples, true }, - + /* Prices */ { "prices", "pricesaddress", &pricesaddress, true }, { "prices", "priceslist", &priceslist, true }, @@ -405,16 +405,16 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricesbet", &pricesbet, true }, { "prices", "pricesstatus", &pricesstatus, true }, { "prices", "pricesfinish", &pricesfinish, true }, - + /* Pegs */ { "pegs", "pegsaddress", &pegsaddress, true }, - + /* Triggers */ { "triggers", "triggersaddress", &triggersaddress, true }, - + /* Payments */ { "payments", "paymentsaddress", &paymentsaddress, true }, - + /* Gateways */ { "gateways", "gatewaysaddress", &gatewaysaddress, true }, { "gateways", "gatewayslist", &gatewayslist, true }, @@ -521,6 +521,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "sendmany", &sendmany, false }, { "wallet", "sendtoaddress", &sendtoaddress, false }, { "wallet", "setaccount", &setaccount, true }, + { "wallet", "setpubkey", &setpubkey, true }, { "wallet", "settxfee", &settxfee, true }, { "wallet", "signmessage", &signmessage, true }, { "wallet", "walletlock", &walletlock, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index a78f1b6fc..98c3357f9 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -322,6 +322,7 @@ extern UniValue walletlock(const UniValue& params, bool fHelp); extern UniValue encryptwallet(const UniValue& params, bool fHelp); extern UniValue validateaddress(const UniValue& params, bool fHelp); extern UniValue getinfo(const UniValue& params, bool fHelp); +extern UniValue setpubkey(const UniValue& params, bool fHelp); extern UniValue getwalletinfo(const UniValue& params, bool fHelp); extern UniValue getblockchaininfo(const UniValue& params, bool fHelp); extern UniValue getnetworkinfo(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c9bffbb33..06352f693 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -400,7 +400,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr // Parse Zcash address CScript scriptPubKey = GetScriptForDestination(address); - + // Create and send the transaction CReserveKey reservekey(pwalletMain); CAmount nFeeRequired; @@ -4906,6 +4906,70 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vectorcs_wallet : NULL); +#else + LOCK(cs_main); +#endif + + char Raddress[18]; + uint8_t pubkey33[33]; + extern uint8_t NOTARY_PUBKEY33[]; + extern std::string NOTARY_PUBKEY; + if ( NOTARY_PUBKEY33[0] == 0 ) { + if (strlen(params[0].get_str().c_str()) == 66) { + decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); + pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); + if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) { + result.push_back(Pair("error", "pubkey entered is invalid.")); + } else { + CBitcoinAddress address(Raddress); + bool isValid = address.IsValid(); + if (isValid) + { + CTxDestination dest = address.Get(); + string currentAddress = address.ToString(); + result.push_back(Pair("address", currentAddress)); +#ifdef ENABLE_WALLET + isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; + result.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); +#endif + } + NOTARY_PUBKEY = params[0].get_str(); + decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); + } + } else { + result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string.")); + } + } else { + result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); + } + result.push_back(Pair("pubkey", NOTARY_PUBKEY)); + return result; +} + UniValue channelsaddress(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::vector destpubkey; CPubKey pk,pk2; char destaddr[64]; @@ -5676,7 +5740,7 @@ UniValue oraclessubscribe(const UniValue& params, bool fHelp) UniValue oraclessamples(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 txid,batontxid; int32_t num; + UniValue result(UniValue::VOBJ); uint256 txid,batontxid; int32_t num; if ( fHelp || params.size() != 3 ) throw runtime_error("oraclessamples oracletxid batonutxo num\n"); if ( ensure_CCrequirements() < 0 ) From 4a407db92036ad06733bedbc7ad29f0a586e0f5a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 16:39:38 +0800 Subject: [PATCH 216/749] forgot declare --- src/rpcmisc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 1616a2470..8baf67c5d 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -60,6 +60,7 @@ extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY; +extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[]; UniValue getinfo(const UniValue& params, bool fHelp) { From 8179be4fb82817a0bf9d15b891dfc7aef0cb2a60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Oct 2018 00:09:32 -1100 Subject: [PATCH 217/749] Fix crash for disablewallet=1 --- src/wallet/rpcwallet.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 06352f693..c6ea4c8b3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4537,6 +4537,9 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) set setAddress; uint8_t *script,utxosig[128]; uint256 utxotxid; uint64_t utxovalue; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t utxovout,eligible,earliest = 0; CScript best_scriptPubKey; bool fNegative,fOverflow; bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); + if (!EnsureWalletIsAvailable(0)) + return 0; + const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4697,6 +4700,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + if (!EnsureWalletIsAvailable(0)) + return 0; + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -6668,6 +6674,9 @@ UniValue getbalance64(const UniValue& params, bool fHelp) { set setAddress; vector vecOutputs; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address; + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + const CKeyStore& keystore = *pwalletMain; CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid; assert(pwalletMain != NULL); From 0779df5d5116bdc9e494cf680e30716e27fc2057 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Oct 2018 04:53:37 -1100 Subject: [PATCH 218/749] fix get transactions crash --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c6ea4c8b3..480f73e6f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -91,16 +91,17 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) //int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; int confirms = wtx.GetDepthInMainChain(); entry.push_back(Pair("rawconfirmations", confirms)); - entry.push_back(Pair("confirmations", komodo_dpowconfs((int32_t)mapBlockIndex[wtx.hashBlock]->nHeight,confirms))); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); if (confirms > 0) { + entry.push_back(Pair("confirmations", komodo_dpowconfs((int32_t)mapBlockIndex[wtx.hashBlock]->nHeight,confirms))); entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex())); entry.push_back(Pair("blockindex", wtx.nIndex)); entry.push_back(Pair("blocktime", mapBlockIndex[wtx.hashBlock]->GetBlockTime())); entry.push_back(Pair("expiryheight", (int64_t)wtx.nExpiryHeight)); - } + } else entry.push_back(Pair("confirmations", confirms)); + uint256 hash = wtx.GetHash(); entry.push_back(Pair("txid", hash.GetHex())); UniValue conflicts(UniValue::VARR); From c83d68baaab18296887d6050aa412d5c2dc6934d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Oct 2018 22:16:45 -1100 Subject: [PATCH 219/749] Allow z_sendmany to notaryaddr --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 480f73e6f..ceb4adf1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -48,6 +48,7 @@ extern UniValue TxJoinSplitToJSON(const CTransaction& tx); extern uint8_t ASSETCHAINS_PRIVATE; 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 int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -3799,7 +3800,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address ); } } - else if ( ASSETCHAINS_PRIVATE != 0 ) + else if ( ASSETCHAINS_PRIVATE != 0 && komodo_isnotaryvout(address.c_str()) == 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (setAddress.count(address)) From 3ba309046873257ea0e4d8557b5a2072bf8d8512 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Oct 2018 22:18:54 -1100 Subject: [PATCH 220/749] syntax --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ceb4adf1f..1d9650221 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3800,7 +3800,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address ); } } - else if ( ASSETCHAINS_PRIVATE != 0 && komodo_isnotaryvout(address.c_str()) == 0 ) + else if ( ASSETCHAINS_PRIVATE != 0 && komodo_isnotaryvout((char *)address.c_str()) == 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (setAddress.count(address)) From 2fd999a2f674168cb34947f012f5f640871928cd Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 13:00:16 +0200 Subject: [PATCH 221/749] Multisig withdraw fix --- src/cc/CCGateways.h | 3 +- src/cc/dapps/oraclefeed.c | 112 +++++++++++++++++++++++--------------- src/cc/gateways.cpp | 85 +++++++++++++++++++++-------- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 34 +++++++++--- 6 files changed, 162 insertions(+), 74 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index b584ba5d0..70c50dcdb 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -27,7 +27,8 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); -std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr); +std::string GatewaysMultisig(char *txidaddr); +std::string GatewaysPartialSign(uint64_t txfee,char* txidaddr,std::string refcoin, std::string hex); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index d9bda7309..e85206071 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -615,6 +615,8 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad } else if ( txstr == 0 ) printf("createmultisig: null txstr and JSON2\n"); + free(tmpA); + free(tmpB); free(argA); free(argB); } @@ -646,10 +648,10 @@ cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx return(0); } -char *get_gatewaysmultisig(char *refcoin,char *acname,char *bindtxidstr,char *withtxidstr,char *txidaddr) +char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr) { char *retstr,*hexstr,*hex=0; cJSON *retjson; - if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",bindtxidstr,refcoin,withtxidstr,txidaddr)) != 0 ) + if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",txidaddr,"","","")) != 0 ) { if ( (hexstr= jstr(retjson,"hex")) != 0 ) hex = clonestr(hexstr); @@ -658,6 +660,21 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *bindtxidstr,char *wi return(hex); } +int32_t gatewayspartialsign(char *refcoin,char *acname,char *txidaddr,char *hex) +{ + char str[65],str2[65],*retstr; cJSON *retjson; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",txidaddr,refcoin,hex,"")) != 0 ) + { + komodobroadcast(refcoin,acname,retjson); + return(jint(retjson,"rank")); + } + else if ( retstr != 0 ) + { + printf("error parsing gatewaysmarkdone.(%s)\n",retstr); + free(retstr); + } +} + void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bits256 cointxid) { char str[65],str2[65],*retstr; cJSON *retjson; @@ -733,13 +750,20 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd return(retval); } -int32_t coinaddrexists(char *refcoin,char *acname,char *coinaddr) +int32_t sendfromthisnode(char *refcoin,char *acname,char *coinaddr) { - cJSON *array; bits256 txid; int32_t i,n,num=0; + cJSON *array,*item; bits256 txid; int32_t i,n,num=0; char *tmptxid,*retstr; if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 ) { - num = cJSON_GetArraySize(array); - free_json(array); + for (i=0; i","amount":0.0001},{"address":"","amount":}]' - txid = sendtoaddress("KMD",acname,txidaddr,10000); - if ( bits256_nonz(txid) != 0 && coinaddrexists("KMD",acname,txidaddr) > 0 ) + if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && sendfromthisnode("KMD",acname,txidaddr) == 0) + { + // the actual withdraw + if ( strcmp(depositaddr,signeraddr) == 0 ) { - // the actual withdraw - if ( strcmp(depositaddr,signeraddr) == 0 ) + txid= sendtoaddress("KMD",acname,txidaddr,10000); + if (bits256_nonz(txid) != 0) { cointxid = sendtoaddress(refcoin,"",withdrawaddr,satoshis); - if ( bits256_nonz(cointxid) != 0 ) + if ( bits256_nonz(cointxid) != 0) { fprintf(stderr,"withdraw %s %s %s %.8f processed\n",refcoin,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); @@ -812,36 +835,39 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else { - if ( (rawtx= get_gatewaysmultisig(refcoin,acname,bindtxidstr,bits256_str(str,origtxid),txidaddr)) == 0 ) - { - rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis); - } - if ( rawtx != 0 ) - { - if ( (clijson= addmultisignature(refcoin,"",signeraddr,rawtx)) != 0 ) - { - if ( is_cJSON_True(jobj(clijson,"complete")) != 0 ) - { - cointxid = komodobroadcast(refcoin,"",clijson); - if ( bits256_nonz(cointxid) != 0 ) - { - fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); - } - } - else if ( jint(clijson,"partialtx") != 0 ) - { - // 10000 + ith -> txidaddr - txid = komodobroadcast("KMD",acname,clijson); - fprintf(stderr,"%s M.%d of N.%d partialtx %s sent\n",refcoin,M,N,bits256_str(str,txid)); - } - free_json(clijson); - } - processed++; - free(rawtx); - } else fprintf(stderr,"couldnt create msig rawtx\n"); + fprintf(stderr,"ERROR sending withdraw marker %s %s to %s %.8f processed\n",refcoin,bits256_str(str,cointxid),txidaddr,(double)10000/SATOSHIDEN); } } + else + { + if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr)) == 0 ) + { + rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis); + } + if ( rawtx != 0 ) + { + if ( (clijson= addmultisignature(refcoin,"",signeraddr,rawtx)) != 0 ) + { + if ( is_cJSON_True(jobj(clijson,"complete")) != 0 ) + { + cointxid = komodobroadcast(refcoin,"",clijson); + if ( bits256_nonz(cointxid) != 0 ) + { + fprintf(stderr,"withdraw %s M.%d N.%d %s %s %.8f processed\n",refcoin,M,N,bits256_str(str,cointxid),withdrawaddr,(double)satoshis/SATOSHIDEN); + gatewaysmarkdone("KMD",acname,origtxid,refcoin,cointxid); + } + } + else if ( jint(clijson,"partialtx") != 0 ) + { + K=gatewayspartialsign(refcoin,acname,txidaddr,jstr(retjson,"hex")); + fprintf(stderr,"%d of %d partialtx %s sent\n",K,N,bits256_str(str,txid)); + } + free_json(clijson); + } + processed++; + free(rawtx); + } else fprintf(stderr,"couldnt create msig rawtx\n"); + } } else if ( retval > 0 ) { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index d2c43ad56..6d1bff5c9 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -178,6 +178,18 @@ uint8_t DecodeGatewaysOpRet(const CScript &scriptPubKey,std::string &coin,uint25 return(0); } +uint8_t DecodeGatewaysPartialOpRet(const CScript &scriptPubKey,int32_t &K, CPubKey &signerpk, std::string &coin,std::string &hex) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> K; ss >> signerpk; ss >> coin; ss >> hex) != 0 ) + { + return(f); + } + return(0); +} + uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,std::string &coin,uint256 &tokenid,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector &pubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2) { std::vector vopret; uint8_t *script,e,f; @@ -873,31 +885,60 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) return(result); } -std::string GatewaysMultisig(uint64_t txfee,std::string refcoin,uint256 bindtxid,uint256 withdrawtxid,char *txidaddr) +std::string GatewaysMultisig(char *txidaddr) { - UniValue result(UniValue::VOBJ); std::string coin,hex; char str[67],numstr[65],depositaddr[64],gatewaysassets[64]; uint8_t M,N; std::vector pubkeys; uint8_t taddr,prefix,prefix2; uint256 tokenid,oracletxid,hashBlock; CTransaction tx; CPubKey Gatewayspk,mypk; struct CCcontract_info *cp,C; int32_t i,n,complete,partialtx; int64_t totalsupply; - cp = CCinit(&C,EVAL_GATEWAYS); - if ( txfee == 0 ) - txfee = 10000; - complete = partialtx = 0; - mypk = pubkey2pk(Mypubkey()); - Gatewayspk = GetUnspendable(cp,0); - _GetCCaddress(gatewaysassets,EVAL_GATEWAYS,Gatewayspk); - if ( GetTransaction(bindtxid,tx,hashBlock,false) != 0 ) + std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K; CPubKey signerpk; + std::vector > unspentOutputs; + + SetCCunspents(unspentOutputs,txidaddr); + if (unspentOutputs.size()==0) return (""); + maxK=0; + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - depositaddr[0] = 0; - if ( tx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,tx.vout[tx.vout.size()-1].scriptPubKey,coin,tokenid,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2) != 0 && M <= N && N > 1 && coin == refcoin ) + txid = it->first.txhash; + if (GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK ) { - // need a decentralized way to add signatures to msig tx - n = pubkeys.size(); - for (i=0; i0) return(parthex); + else return (""); +} + +std::string GatewaysPartialSign(uint64_t txfee,char* txidaddr,std::string refcoin, std::string hex) +{ + CMutableTransaction mtx; CScript opret; CPubKey mypk,gatewayspk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; + std::vector > unspentOutputs; + int32_t maxK,K; uint256 txid,parttxid,hashBlock; + cp = CCinit(&C,EVAL_GATEWAYS); + if ( txfee == 0 ) + txfee = 5000; + mypk = pubkey2pk(Mypubkey()); + gatewayspk = GetUnspendable(cp,0); + SetCCunspents(unspentOutputs,txidaddr); + if (unspentOutputs.size()==0) + { + if (AddNormalinputs(mtx,mypk,2*txfee,2)==0) + fprintf(stderr,"error adding funds for partialsign\n"); + } + else + { + maxK=0; + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + if (GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK ) + { + maxK=K; + parttxid=txid; + } + } + if (maxK>0) mtx.vin.push_back(CTxIn(parttxid,0,CScript())); + else fprintf(stderr,"Error finding previous partial tx\n"); + } + + mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG)); + opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K << mypk << refcoin << hex); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 7d2eab1e3..e4dcdbbbd 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -426,6 +426,7 @@ static const CRPCCommand vRPCCommands[] = { "gateways", "gatewayspending", &gatewayspending, true }, { "gateways", "gatewaysmultisig", &gatewaysmultisig, true }, { "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true }, + { "gateways", "gatewayspartialsign", &gatewayspartialsign, true }, /* dice */ { "dice", "dicelist", &dicelist, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index a78f1b6fc..cf23f6496 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -253,6 +253,7 @@ extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp); extern UniValue gatewayspending(const UniValue& params, bool fHelp); extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp); extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp); +extern UniValue gatewayspartialsign(const UniValue& params, bool fHelp); extern UniValue channelsinfo(const UniValue& params, bool fHelp); extern UniValue channelsopen(const UniValue& params, bool fHelp); extern UniValue channelspayment(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 59f0b6ba7..014f8973e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5592,18 +5592,36 @@ UniValue gatewayspending(const UniValue& params, bool fHelp) UniValue gatewaysmultisig(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint256 bindtxid,withtxid; std::string coin,hex; char *txidaddr; - if ( fHelp || params.size() != 4 ) - throw runtime_error("gatewaysmultisig bindtxid coin withtxid txidaddr\n"); + UniValue result(UniValue::VOBJ); std::string hex; char *txidaddr; + if ( fHelp || params.size() != 1 ) + throw runtime_error("gatewaysmultisig txidaddr\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - bindtxid = Parseuint256((char *)params[0].get_str().c_str()); + LOCK2(cs_main, pwalletMain->cs_wallet); + txidaddr = (char *)params[0].get_str().c_str(); + hex = GatewaysMultisig(txidaddr); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex",hex)); + } else ERR_RESULT("couldnt gatewaysmultisig"); + return(result); +} + +UniValue gatewayspartialsign(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); std::string coin,parthex,hex; char *txidaddr; + if ( fHelp || params.size() != 3 ) + throw runtime_error("gatewayspartialsign txidaddr refcoin\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); + txidaddr = (char *)params[0].get_str().c_str(); coin = params[1].get_str(); - withtxid = Parseuint256((char *)params[2].get_str().c_str()); - txidaddr = (char *)params[3].get_str().c_str(); - hex = GatewaysMultisig(0,coin,bindtxid,withtxid,txidaddr); + coin = params[2].get_str(); + hex = GatewaysPartialSign(0,txidaddr,coin,parthex); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From 4dbfd427b712bc69bef7e8165490d8da192b0ece Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 16:40:58 +0200 Subject: [PATCH 222/749] Fix --- src/cc/dapps/oraclefeed.c | 10 +++++----- src/cc/gateways.cpp | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index e85206071..98b5664d6 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -869,11 +869,11 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else fprintf(stderr,"couldnt create msig rawtx\n"); } } - else if ( retval > 0 ) - { - fprintf(stderr,"already did withdraw %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); - gatewaysmarkdone("KMD",acname,origtxid,refcoin,zeroid); - } + // else if ( retval > 0 ) + // { + // fprintf(stderr,"already did withdraw %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); + // gatewaysmarkdone("KMD",acname,origtxid,refcoin,zeroid); + // } } } } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 6d1bff5c9..cd892e131 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -801,7 +801,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin CCchange = (inputs - amount); mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,amount,gatewayspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG)); + mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk)); if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,mypk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); @@ -818,6 +818,7 @@ std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string ref if ( txfee == 0 ) txfee = 5000; mypk = pubkey2pk(Mypubkey()); + mtx.vin.push_back(CTxIn(withdrawtxid,2,CScript())); mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'M' << cointxid << refcoin); From 32572846ded619b882a2ac70fe621e3bb6b4963b Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 16:55:36 +0200 Subject: [PATCH 223/749] Fix --- src/cc/gateways.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index cd892e131..828695a2e 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -827,7 +827,7 @@ std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string ref UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) { - UniValue result(UniValue::VOBJ),pending(UniValue::VARR),obj(UniValue::VOBJ); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector msigpubkeys; uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector msigpubkeys; uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); @@ -864,6 +864,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); if ( strcmp(destaddr,coinaddr) == 0 ) { + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid",uint256_str(str,txid))); CCtxidaddr(txidaddr,txid); obj.push_back(Pair("txidaddr",txidaddr)); From b18631ae2bd00d13c7b6a6bde39a5158834fed08 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 17:49:21 +0200 Subject: [PATCH 224/749] Fix --- src/cc/CCGateways.h | 2 +- src/cc/gateways.cpp | 46 +++++++++++++++++++++++++++++++++------- src/wallet/rpcwallet.cpp | 4 ++-- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 70c50dcdb..63f572378 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -24,7 +24,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & std::string GatewaysBind(uint64_t txfee,std::string coin,uint256 tokenid,int64_t totalsupply,uint256 oracletxid,uint8_t M,uint8_t N,std::vector pubkeys); std::string GatewaysDeposit(uint64_t txfee,uint256 bindtxid,int32_t height,std::string refcoin,uint256 cointxid,int32_t claimvout,std::string deposithex,std::vectorproof,CPubKey destpub,int64_t amount); std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,uint256 deposittxid,CPubKey destpub,int64_t amount); -std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount); +std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); std::string GatewaysMultisig(char *txidaddr); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 828695a2e..81ec4b40f 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -190,6 +190,29 @@ uint8_t DecodeGatewaysPartialOpRet(const CScript &scriptPubKey,int32_t &K, CPubK return(0); } +uint8_t DecodeGatewaysWithdrawOpRet(const CScript &scriptPubKey, uint256 &assetid, std::string &refcoin, CPubKey &withdrawpub, int64_t &amount) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> assetid; ss >> refcoin; ss >> withdrawpub; ss >> amount) != 0 ) + { + return(f); + } + return(0); +} +uint8_t DecodeGatewaysMarkdoneOpRet(const CScript &scriptPubKey, std::string &refcoin, uint256 &cointxid) +{ + std::vector vopret; uint8_t *script,e,f; + GetOpReturnData(scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> refcoin; ss >> cointxid) != 0 ) + { + return(f); + } + return(0); +} + uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,std::string &coin,uint256 &tokenid,int64_t &totalsupply,uint256 &oracletxid,uint8_t &M,uint8_t &N,std::vector &pubkeys,uint8_t &taddr,uint8_t &prefix,uint8_t &prefix2) { std::vector vopret; uint8_t *script,e,f; @@ -775,9 +798,11 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui return(""); } -std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,std::vector withdrawpub,int64_t amount) +std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount) { - CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; + CMutableTransaction mtx; CTransaction tx; CPubKey mypk,gatewayspk; struct CCcontract_info *cp,C; + uint256 assetid,hashBlock,oracletxid; int32_t numvouts; int64_t totalsupply,inputs,CCchange=0; uint8_t M,N,taddr,prefix,prefix2; std::string coin; + std::vector msigpubkeys; char depositaddr[64],str[65],coinaddr[64]; CScript opret; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) txfee = 10000; @@ -800,11 +825,12 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin if ( inputs > amount ) CCchange = (inputs - amount); mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,amount,gatewayspk)); - mtx.vout.push_back(CTxOut(txfee,CScript() << withdrawpub << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(withdrawpub)) << OP_CHECKSIG)); mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,txfee,gatewayspk)); if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_GATEWAYS,CCchange,mypk)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('t',assetid,zeroid,0,Mypubkey()))); + opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'W' << assetid << refcoin << withdrawpub << amount); + return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } } fprintf(stderr,"cant find enough inputs or mismatched total\n"); @@ -827,8 +853,12 @@ std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string ref UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) { - UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin; CPubKey mypk,gatewayspk; std::vector msigpubkeys; uint256 hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; + uint256 cointxid,hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; + char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; + int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply,amount; struct CCcontract_info *cp,C; std::vector > unspentOutputs; + cp = CCinit(&C,EVAL_GATEWAYS); mypk = pubkey2pk(Mypubkey()); gatewayspk = GetUnspendable(cp,0); @@ -851,14 +881,14 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) queueflag = 1; break; } - Getscriptaddress(withmarker,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG); - SetCCunspents(unspentOutputs,withmarker); + //Getscriptaddress(withmarker,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG); + SetCCunspents(unspentOutputs,coinaddr); numqueued = 0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'M') { Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 014f8973e..13fb81c2d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5545,10 +5545,10 @@ UniValue gatewayswithdraw(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); - coin = params[1].get_str(); + coin = params[1].get_str(); withdrawpub = ParseHex(params[2].get_str()); amount = atof((char *)params[3].get_str().c_str()) * COIN; - hex = GatewaysWithdraw(0,bindtxid,coin,withdrawpub,amount); + hex = GatewaysWithdraw(0,bindtxid,coin,pubkey2pk(withdrawpub),amount); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From 07660bb09808b2ad485f38076ffc51d60365f046 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 18:08:39 +0200 Subject: [PATCH 225/749] Fix --- src/cc/gateways.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 81ec4b40f..38062d401 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -856,7 +856,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,tmprefcoin; CPubKey mypk,gatewayspk,withdrawpub; std::vector msigpubkeys; uint256 cointxid,hashBlock,assetid,txid,oracletxid; uint8_t M,N,taddr,prefix,prefix2; char depositaddr[64],withmarker[64],coinaddr[64],destaddr[64],str[65],withaddr[64],numstr[32],txidaddr[64],signeraddr[64]; - int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply,amount; struct CCcontract_info *cp,C; + int32_t i,n,numvouts,vout,numqueued,queueflag; int64_t totalsupply,amount,nValue; struct CCcontract_info *cp,C; std::vector > unspentOutputs; cp = CCinit(&C,EVAL_GATEWAYS); @@ -888,7 +888,9 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size())>0 && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'M') + nValue = (int64_t)it->second.satoshis; + fprintf(stderr,"%s %d %ld\n",txid.ToString().c_str(),vout,(long)nValue); + if ( vout == 2 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W') { Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); From f29445f03ea24d7bd124fec93c198ca7d64b2f54 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 21:45:52 +0200 Subject: [PATCH 226/749] Fix --- src/cc/dapps/oraclefeed.c | 6 +++--- src/cc/gateways.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 98b5664d6..f6b385aa5 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -750,7 +750,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd return(retval); } -int32_t sendfromthisnode(char *refcoin,char *acname,char *coinaddr) +int32_t markerfromth(char *refcoin,char *acname,char *coinaddr) { cJSON *array,*item; bits256 txid; int32_t i,n,num=0; char *tmptxid,*retstr; if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 ) @@ -813,7 +813,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t //process item.0 {"txid":"10ec8f4dad6903df6b249b361b879ac77b0617caad7629b97e10f29fa7e99a9b","txidaddr":"RMbite4TGugVmkGmu76ytPHDEQZQGSUjxz","withdrawaddr":"RNJmgYaFF5DbnrNUX6pMYz9rcnDKC2tuAc","amount":"1.00000000","depositaddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj","signeraddr":"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj"} if ( (txidaddr= jstr(item,"txidaddr")) != 0 && (withdrawaddr= jstr(item,"withdrawaddr")) != 0 && (depositaddr= jstr(item,"depositaddr")) != 0 && (signeraddr= jstr(item,"signeraddr")) != 0 ) { - if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && sendfromthisnode("KMD",acname,txidaddr) == 0) + if ( (satoshis= jdouble(item,"amount")*SATOSHIDEN) != 0 && markerfromthisnode("KMD",acname,txidaddr) == 0) { // the actual withdraw if ( strcmp(depositaddr,signeraddr) == 0 ) @@ -859,7 +859,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else if ( jint(clijson,"partialtx") != 0 ) { - K=gatewayspartialsign(refcoin,acname,txidaddr,jstr(retjson,"hex")); + K=gatewayspartialsign(refcoin,acname,txidaddr,jstr(clijson,"hex")); fprintf(stderr,"%d of %d partialtx %s sent\n",K,N,bits256_str(str,txid)); } free_json(clijson); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 38062d401..f993a84c3 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -972,7 +972,7 @@ std::string GatewaysPartialSign(uint64_t txfee,char* txidaddr,std::string refcoi else fprintf(stderr,"Error finding previous partial tx\n"); } - mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG)); + mtx.vout.push_back(CTxOut(5000,txidaddr)); opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K << mypk << refcoin << hex); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 13fb81c2d..d7f25b50f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5613,7 +5613,7 @@ UniValue gatewayspartialsign(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); std::string coin,parthex,hex; char *txidaddr; if ( fHelp || params.size() != 3 ) - throw runtime_error("gatewayspartialsign txidaddr refcoin\n"); + throw runtime_error("gatewayspartialsign txidaddr refcoin hex\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; From 8841c81404e2e71b9ff0f962308d3336b99bbb57 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 22:02:42 +0200 Subject: [PATCH 227/749] Fix --- src/cc/CCGateways.h | 2 +- src/cc/channels.cpp | 8 ++++---- src/cc/dapps/oraclefeed.c | 8 ++++---- src/cc/gateways.cpp | 18 +++++++++--------- src/wallet/rpcwallet.cpp | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 63f572378..cd094fce0 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -28,7 +28,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); std::string GatewaysMultisig(char *txidaddr); -std::string GatewaysPartialSign(uint64_t txfee,char* txidaddr,std::string refcoin, std::string hex); +std::string GatewaysPartialSign(uint64_t txfee,uint256 txidaddr,std::string refcoin, std::string hex); // CCcustom UniValue GatewaysInfo(uint256 bindtxid); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index bd0b5bb7f..f32e9d4d1 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -64,7 +64,7 @@ Possible third iteration: int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub, CPubKey destpub,int32_t v) { - char destaddr[64],channeladdr[64]; + char destaddr[65],channeladdr[65]; GetCCaddress1of2(cp,channeladdr,srcpub,destpub); if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -77,7 +77,7 @@ int64_t IsChannelsvout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey int64_t IsChannelsMarkervout(struct CCcontract_info *cp,const CTransaction& tx,CPubKey srcpub,int32_t v) { - char destaddr[64],ccaddr[64]; + char destaddr[65],ccaddr[65]; GetCCaddress(cp,ccaddr,srcpub); if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -364,7 +364,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, CTransaction openTx, uint256 &prevtxid) { - char coinaddr[64]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t param1; + char coinaddr[65]; int64_t param2,totalinputs = 0,numvouts; uint256 txid=zeroid,tmp_txid,hashBlock,param3; CTransaction tx; int32_t param1; std::vector > unspentOutputs; CPubKey srcpub,destpub; uint8_t myprivkey[32]; @@ -692,7 +692,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; - struct CCcontract_info *cp,C; char myCCaddr[64],addr[64],str1[256],str2[64]; int32_t vout,numvouts,param1,numpayments; + struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[256],str2[65]; int32_t vout,numvouts,param1,numpayments; int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index f6b385aa5..c5dea8de9 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -660,10 +660,10 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr) return(hex); } -int32_t gatewayspartialsign(char *refcoin,char *acname,char *txidaddr,char *hex) +int32_t gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex) { - char str[65],str2[65],*retstr; cJSON *retjson; - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",txidaddr,refcoin,hex,"")) != 0 ) + char str[65],*retstr; cJSON *retjson; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),refcoin,hex,"")) != 0 ) { komodobroadcast(refcoin,acname,retjson); return(jint(retjson,"rank")); @@ -859,7 +859,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else if ( jint(clijson,"partialtx") != 0 ) { - K=gatewayspartialsign(refcoin,acname,txidaddr,jstr(clijson,"hex")); + K=gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex")); fprintf(stderr,"%d of %d partialtx %s sent\n",K,N,bits256_str(str,txid)); } free_json(clijson); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index f993a84c3..5ab78fb8e 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -940,16 +940,16 @@ std::string GatewaysMultisig(char *txidaddr) else return (""); } -std::string GatewaysPartialSign(uint64_t txfee,char* txidaddr,std::string refcoin, std::string hex) +std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) { - CMutableTransaction mtx; CScript opret; CPubKey mypk,gatewayspk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; - std::vector > unspentOutputs; - int32_t maxK,K; uint256 txid,parttxid,hashBlock; + CMutableTransaction mtx; CScript opret; CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; + std::vector > unspentOutputs; char txidaddr[65]; + int32_t maxK,K; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) txfee = 5000; mypk = pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(cp,0); + txidaddrpk=CCtxidaddr(txidaddr,txid); SetCCunspents(unspentOutputs,txidaddr); if (unspentOutputs.size()==0) { @@ -961,18 +961,18 @@ std::string GatewaysPartialSign(uint64_t txfee,char* txidaddr,std::string refcoi maxK=0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - txid = it->first.txhash; - if (GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK ) + tmptxid = it->first.txhash; + if (GetTransaction(tmptxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK ) { maxK=K; - parttxid=txid; + parttxid=tmptxid; } } if (maxK>0) mtx.vin.push_back(CTxIn(parttxid,0,CScript())); else fprintf(stderr,"Error finding previous partial tx\n"); } - mtx.vout.push_back(CTxOut(5000,txidaddr)); + mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(txidaddrpk)) << OP_CHECKSIG)); opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K << mypk << refcoin << hex); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d7f25b50f..ca3c0bea4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5611,17 +5611,17 @@ UniValue gatewaysmultisig(const UniValue& params, bool fHelp) UniValue gatewayspartialsign(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); std::string coin,parthex,hex; char *txidaddr; + UniValue result(UniValue::VOBJ); std::string coin,parthex,hex; uint256 txid; if ( fHelp || params.size() != 3 ) throw runtime_error("gatewayspartialsign txidaddr refcoin hex\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); - txidaddr = (char *)params[0].get_str().c_str(); + txid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); - coin = params[2].get_str(); - hex = GatewaysPartialSign(0,txidaddr,coin,parthex); + parthex = params[2].get_str(); + hex = GatewaysPartialSign(0,txid,coin,parthex); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From 0c3f76e992bb742c4dffd00c20826274c6d1e879 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 22:15:18 +0200 Subject: [PATCH 228/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index c5dea8de9..6d3695a5f 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -750,7 +750,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd return(retval); } -int32_t markerfromth(char *refcoin,char *acname,char *coinaddr) +int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) { cJSON *array,*item; bits256 txid; int32_t i,n,num=0; char *tmptxid,*retstr; if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 ) From ced164c07acb247962df17b0aed54a066979036e Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Fri, 26 Oct 2018 23:53:58 +0200 Subject: [PATCH 229/749] Fix --- src/cc/gateways.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5ab78fb8e..c3d09098c 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -944,7 +944,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, { CMutableTransaction mtx; CScript opret; CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; std::vector > unspentOutputs; char txidaddr[65]; - int32_t maxK,K; uint256 tmptxid,parttxid,hashBlock; + int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) txfee = 5000; @@ -953,8 +953,7 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, SetCCunspents(unspentOutputs,txidaddr); if (unspentOutputs.size()==0) { - if (AddNormalinputs(mtx,mypk,2*txfee,2)==0) - fprintf(stderr,"error adding funds for partialsign\n"); + if (AddNormalinputs(mtx,mypk,2*txfee,2)==0) fprintf(stderr,"error adding funds for partialsign\n"); } else { @@ -973,6 +972,6 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, } mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(txidaddrpk)) << OP_CHECKSIG)); - opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K << mypk << refcoin << hex); + opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K+1 << mypk << refcoin << hex); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } From b9fefbfa06f3803301e598b742ba79c7feca732c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 27 Oct 2018 00:24:19 -1100 Subject: [PATCH 230/749] Auto-reconsider block --- src/main.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 95fdbebae..a352b1ab6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4425,7 +4425,15 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (ppindex) *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) - return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + { + if ( ASSETCHAINS_CC == 0 ) + return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + else + { + fprintf(stderr,"reconsider block %s\n",hash.GetHex().c_str()); + pindex->nStatus &= ~BLOCK_FAILED_MASK; + } + } /*if ( pindex != 0 && hash == komodo_requestedhash ) { fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); From e062742886d7b3accfc69cd5de69770d40f925bf Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Sat, 27 Oct 2018 22:46:11 +0200 Subject: [PATCH 231/749] comment out oracle print --- src/cc/oracles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 7cccad0f6..0c7d9e6e2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -666,7 +666,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr); + //fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From 202873160eaef48d22aeda4efb21ae8888678df2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 05:39:36 +0800 Subject: [PATCH 232/749] entropy txs added to diceinfo --- src/cc/dice.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 20524a84a..85ac1693e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -655,7 +655,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, uint32_t &entropytxs) { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; std::vector > unspentOutputs; @@ -734,6 +734,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } } fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN); + entropytxs = n; return(totalinputs); } @@ -826,9 +827,11 @@ UniValue DiceInfo(uint256 diceid) result.push_back(Pair("timeoutblocks",timeoutblocks)); cp = CCinit(&C,EVAL_DICE); dicepk = GetUnspendable(cp,0); - funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid); + uint32_t entropytxs; + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid,entropytxs); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); + result.push_back(Pair("entropytxs",entropytxs)); return(result); } @@ -951,7 +954,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid)) >= 2*bet*odds+txfee && entropyval != 0 ) + int32_t entropytxs; + if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) { if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { From 2b31eb6fa6b184e1824861f25a61371610d21d48 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 05:44:51 +0800 Subject: [PATCH 233/749] fix --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 85ac1693e..c383c61da 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -655,7 +655,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, uint32_t &entropytxs) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs) { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; std::vector > unspentOutputs; @@ -827,7 +827,7 @@ UniValue DiceInfo(uint256 diceid) result.push_back(Pair("timeoutblocks",timeoutblocks)); cp = CCinit(&C,EVAL_DICE); dicepk = GetUnspendable(cp,0); - uint32_t entropytxs; + int32_t entropytxs; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid,entropytxs); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); From 77b6a312d51d629883b0643ecce982d82e852770 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 09:31:42 +0800 Subject: [PATCH 234/749] remove check for error --- src/cc/dice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c383c61da..10feaa4f7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -546,8 +546,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("always should find vin.0, but didnt for wlt"); + //else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) + // return eval->Invalid("always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) @@ -957,6 +957,11 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet int32_t entropytxs; if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) { + if ( entropytxs < 10 ) { + CCerror = "Your dealer is broke, find a new casino."; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { CCerror = "entropy txid is spent"; From 153227c27fdf763f65c5b74b6171b619f031b03d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:01:54 +0800 Subject: [PATCH 235/749] fix? --- src/cc/dice.cpp | 5 +- src/main.cpp | 1102 +++++++++++++++++++++++------------------------ 2 files changed, 554 insertions(+), 553 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 10feaa4f7..baaedd90a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -443,6 +443,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; + CBlockIndex block; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -546,8 +547,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - //else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) - // return eval->Invalid("always should find vin.0, but didnt for wlt"); + else if ( eval->GetTxConfirmed(tx.vin[1].prevout.hash,vinTx,block) == 0 ) + return eval->Invalid("always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) diff --git a/src/main.cpp b/src/main.cpp index a352b1ab6..11df78609 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,30 +115,30 @@ const string strMessageMagic = "Komodo Signed Message:\n"; // Internal stuff namespace { - + struct CBlockIndexWorkComparator { bool operator()(CBlockIndex *pa, CBlockIndex *pb) const { // First sort by most total work, ... if (pa->nChainWork > pb->nChainWork) return false; if (pa->nChainWork < pb->nChainWork) return true; - + // ... then by earliest time received, ... if (pa->nSequenceId < pb->nSequenceId) return false; if (pa->nSequenceId > pb->nSequenceId) return true; - + // Use pointer address as tie breaker (should only happen with blocks // loaded from disk, as those all have id 0). if (pa < pb) return false; if (pa > pb) return true; - + // Identical blocks. return false; } }; - + CBlockIndex *pindexBestInvalid; - + /** * The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself and all ancestors) and * as good as our current tip or better. Entries may be failed, though, and pruning nodes may be @@ -151,7 +151,7 @@ namespace { * Pruned nodes may have entries where B is missing data. */ multimap mapBlocksUnlinked; - + CCriticalSection cs_LastBlockFile; std::vector vinfoBlockFile; int nLastBlockFile = 0; @@ -160,7 +160,7 @@ namespace { * or if we allocate more file space when we're in prune mode */ bool fCheckForPruning = false; - + /** * Every received block is assigned a unique and increasing identifier, so we * know which one to give priority in case of a fork. @@ -168,14 +168,14 @@ namespace { CCriticalSection cs_nBlockSequenceId; /** Blocks loaded from disk are assigned id 0, so start the counter at 1. */ uint32_t nBlockSequenceId = 1; - + /** * Sources of received blocks, saved to be able to send them reject * messages or ban them when processing happens afterwards. Protected by * cs_main. */ map mapBlockSource; - + /** * Filter for transactions that were recently rejected by * AcceptToMemoryPool. These are not rerequested until the chain tip @@ -198,7 +198,7 @@ namespace { */ boost::scoped_ptr recentRejects; uint256 hashRecentRejectsChainTip; - + /** Blocks that are in flight, and that are in the queue to be downloaded. Protected by cs_main. */ struct QueuedBlock { uint256 hash; @@ -208,16 +208,16 @@ namespace { int64_t nTimeDisconnect; //! The timeout for this block request (for disconnecting a slow peer) }; map::iterator> > mapBlocksInFlight; - + /** Number of blocks in flight with validated headers. */ int nQueuedValidatedHeaders = 0; - + /** Number of preferable block download peers. */ int nPreferredDownload = 0; - + /** Dirty block index entries. */ set setDirtyBlockIndex; - + /** Dirty block file entries. */ set setDirtyFileInfo; } // anon namespace @@ -228,13 +228,13 @@ namespace { // namespace { - + struct CBlockReject { unsigned char chRejectCode; string strRejectReason; uint256 hashBlock; }; - + /** * Maintain validation-specific state about nodes, protected by cs_main, instead * by CNode's own locks. This simplifies asynchronous operation, where @@ -269,7 +269,7 @@ namespace { int nBlocksInFlightValidHeaders; //! Whether we consider this a preferred download peer. bool fPreferredDownload; - + CNodeState() { fCurrentlyConnected = false; nMisbehavior = 0; @@ -284,10 +284,10 @@ namespace { fPreferredDownload = false; } }; - + /** Map maintaining per-node state. Requires cs_main. */ map mapNodeState; - + // Requires cs_main. CNodeState *State(NodeId pnode) { map::iterator it = mapNodeState.find(pnode); @@ -295,67 +295,67 @@ namespace { return NULL; return &it->second; } - + int GetHeight() { LOCK(cs_main); return chainActive.Height(); } - + void UpdatePreferredDownload(CNode* node, CNodeState* state) { nPreferredDownload -= state->fPreferredDownload; - + // Whether this node should be marked as a preferred download node. state->fPreferredDownload = (!node->fInbound || node->fWhitelisted) && !node->fOneShot && !node->fClient; - + nPreferredDownload += state->fPreferredDownload; } - + // Returns time at which to timeout block request (nTime in microseconds) int64_t GetBlockTimeout(int64_t nTime, int nValidatedQueuedBefore, const Consensus::Params &consensusParams) { return nTime + 500000 * consensusParams.nPowTargetSpacing * (4 + nValidatedQueuedBefore); } - + void InitializeNode(NodeId nodeid, const CNode *pnode) { LOCK(cs_main); CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second; state.name = pnode->addrName; state.address = pnode->addr; } - + void FinalizeNode(NodeId nodeid) { LOCK(cs_main); CNodeState *state = State(nodeid); - + if (state->fSyncStarted) nSyncStarted--; - + if (state->nMisbehavior == 0 && state->fCurrentlyConnected) { AddressCurrentlyConnected(state->address); } - + BOOST_FOREACH(const QueuedBlock& entry, state->vBlocksInFlight) mapBlocksInFlight.erase(entry.hash); EraseOrphansFor(nodeid); nPreferredDownload -= state->fPreferredDownload; - + mapNodeState.erase(nodeid); } - + void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) { /* int expired = pool.Expire(GetTime() - age); if (expired != 0) LogPrint("mempool", "Expired %i transactions from the memory pool\n", expired); - + std::vector vNoSpendsRemaining; pool.TrimToSize(limit, &vNoSpendsRemaining); BOOST_FOREACH(const uint256& removed, vNoSpendsRemaining) pcoinsTip->Uncache(removed);*/ } - + // Requires cs_main. // Returns a bool indicating whether we requested this block. bool MarkBlockAsReceived(const uint256& hash) { @@ -372,15 +372,15 @@ namespace { } return false; } - + // Requires cs_main. void MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const Consensus::Params& consensusParams, CBlockIndex *pindex = NULL) { CNodeState *state = State(nodeid); assert(state != NULL); - + // Make sure it's not listed somewhere already. MarkBlockAsReceived(hash); - + int64_t nNow = GetTimeMicros(); QueuedBlock newentry = {hash, pindex, nNow, pindex != NULL, GetBlockTimeout(nNow, nQueuedValidatedHeaders, consensusParams)}; nQueuedValidatedHeaders += newentry.fValidatedHeaders; @@ -389,12 +389,12 @@ namespace { state->nBlocksInFlightValidHeaders += newentry.fValidatedHeaders; mapBlocksInFlight[hash] = std::make_pair(nodeid, it); } - + /** Check whether the last unknown block a peer advertized is not yet known. */ void ProcessBlockAvailability(NodeId nodeid) { CNodeState *state = State(nodeid); assert(state != NULL); - + if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); if (itOld != mapBlockIndex.end() && itOld->second != 0 && itOld->second->nChainWork > 0) @@ -405,14 +405,14 @@ namespace { } } } - + /** Update tracking information about which blocks a peer is assumed to have. */ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { CNodeState *state = State(nodeid); assert(state != NULL); - + /*ProcessBlockAvailability(nodeid); - + BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. @@ -424,7 +424,7 @@ namespace { state->hashLastUnknownBlock = hash; } } - + /** Find the last common ancestor two blocks have. * Both pa and pb must be non-NULL. */ CBlockIndex* LastCommonAncestor(CBlockIndex* pa, CBlockIndex* pb) { @@ -433,47 +433,47 @@ namespace { } else if (pb->nHeight > pa->nHeight) { pb = pb->GetAncestor(pa->nHeight); } - + while (pa != pb && pa && pb) { pa = pa->pprev; pb = pb->pprev; } - + // Eventually all chain branches meet at the genesis block. assert(pa == pb); return pa; } - + /** Update pindexLastCommonBlock and add not-in-flight missing successors to vBlocks, until it has * at most count entries. */ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vector& vBlocks, NodeId& nodeStaller) { if (count == 0) return; - + vBlocks.reserve(vBlocks.size() + count); CNodeState *state = State(nodeid); assert(state != NULL); - + // Make sure pindexBestKnownBlock is up to date, we'll need it. ProcessBlockAvailability(nodeid); - + if (state->pindexBestKnownBlock == NULL || state->pindexBestKnownBlock->nChainWork < chainActive.Tip()->nChainWork) { // This peer has nothing interesting. return; } - + if (state->pindexLastCommonBlock == NULL) { // Bootstrap quickly by guessing a parent of our best tip is the forking point. // Guessing wrong in either direction is not a problem. state->pindexLastCommonBlock = chainActive[std::min(state->pindexBestKnownBlock->nHeight, chainActive.Height())]; } - + // If the peer reorganized, our previous pindexLastCommonBlock may not be an ancestor // of its current tip anymore. Go back enough to fix that. state->pindexLastCommonBlock = LastCommonAncestor(state->pindexLastCommonBlock, state->pindexBestKnownBlock); if (state->pindexLastCommonBlock == state->pindexBestKnownBlock) return; - + std::vector vToFetch; CBlockIndex *pindexWalk = state->pindexLastCommonBlock; // Never fetch further than the best block we know the peer has, or more than BLOCK_DOWNLOAD_WINDOW + 1 beyond the last @@ -493,7 +493,7 @@ namespace { for (unsigned int i = nToFetch - 1; i > 0; i--) { vToFetch[i - 1] = vToFetch[i]->pprev; } - + // Iterate over those blocks in vToFetch (in forward direction), adding the ones that // are not yet downloaded and not in flight to vBlocks. In the meantime, update // pindexLastCommonBlock as long as all ancestors are already downloaded, or if it's @@ -527,7 +527,7 @@ namespace { } } } - + } // anon namespace bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { @@ -617,7 +617,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(c uint256 hash = tx.GetHash(); if (mapOrphanTransactions.count(hash)) return false; - + // Ignore big transactions, to avoid a // send-big-orphans memory exhaustion attack. If a peer has a legitimate // large transaction with a missing parent then we assume @@ -631,12 +631,12 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(c LogPrint("mempool", "ignoring large orphan tx (size: %u, hash: %s)\n", sz, hash.ToString()); return false; } - + mapOrphanTransactions[hash].tx = tx; mapOrphanTransactions[hash].fromPeer = peer; BOOST_FOREACH(const CTxIn& txin, tx.vin) mapOrphanTransactionsByPrev[txin.prevout.hash].insert(hash); - + LogPrint("mempool", "stored orphan tx %s (mapsz %u prevsz %u)\n", hash.ToString(), mapOrphanTransactions.size(), mapOrphanTransactionsByPrev.size()); return true; @@ -696,7 +696,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRE bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) { bool isOverwinter = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); - + if (isOverwinter) { // Overwinter standard rules apply if (tx.nVersion > CTransaction::OVERWINTER_MAX_CURRENT_VERSION || tx.nVersion < CTransaction::OVERWINTER_MIN_CURRENT_VERSION) { @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) return false; } } - + BOOST_FOREACH(const CTxIn& txin, tx.vin) { // Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed @@ -729,7 +729,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) return false; } } - + unsigned int v=0,nDataOut = 0; txnouttype whichType; BOOST_FOREACH(const CTxOut& txout, tx.vout) @@ -740,7 +740,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) //fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut); return false; } - + if (whichType == TX_NULL_DATA) { if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) @@ -760,13 +760,13 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) } v++; } - + // only one OP_RETURN txout is permitted if (nDataOut > 1) { reason = "multi-op-return"; return false; } - + return true; } @@ -781,7 +781,7 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) { if ( txin.nSequence == 0xfffffffe && (((int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime > nBlockTime) || ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD && (int64_t)tx.nLockTime > nBlockHeight)) ) { - + } else if (!txin.IsFinal()) { @@ -803,7 +803,7 @@ bool IsExpiredTx(const CTransaction &tx, int nBlockHeight) bool CheckFinalTx(const CTransaction &tx, int flags) { AssertLockHeld(cs_main); - + // By convention a negative value for flags indicates that the // current network-enforced consensus rules should be used. In // a future soft-fork scenario that would mean checking which @@ -811,7 +811,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) // appropriate flags. At the present time no soft-forks are // scheduled, so no flags are set. flags = std::max(flags, 0); - + // CheckFinalTx() uses chainActive.Height()+1 to evaluate // nLockTime because when IsFinalTx() is called within // CBlock::AcceptBlock(), the height of the block *being* @@ -819,7 +819,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) // transaction can be part of the *next* block, we need to call // IsFinalTx() with one more than chainActive.Height(). const int nBlockHeight = chainActive.Height() + 1; - + // Timestamps on the other hand don't get any special treatment, // because we can't know what timestamp the next block will have, // and there aren't timestamp applications where it matters. @@ -827,7 +827,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) const int64_t nBlockTime = (flags & LOCKTIME_MEDIAN_TIME_PAST) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - + return IsFinalTx(tx, nBlockHeight, nBlockTime); } @@ -851,7 +851,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, for (unsigned int i = 0; i < tx.vin.size(); i++) { const CTxOut& prev = mapInputs.GetOutputFor(tx.vin[i]); - + vector > vSolutions; txnouttype whichType; // get the scriptPubKey corresponding to this input: @@ -861,7 +861,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, int nArgsExpected = ScriptSigArgsExpected(whichType, vSolutions); if (nArgsExpected < 0) return false; - + // Transactions with extra stuff in their scriptSigs are // non-standard. Note that this EvalScript() call will // be quick, because if there are any operations @@ -871,7 +871,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, vector > stack; if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), consensusBranchId)) return false; - + if (whichType == TX_SCRIPTHASH) { if (stack.empty()) @@ -894,11 +894,11 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, return (sigops <= MAX_P2SH_SIGOPS); } } - + if (stack.size() != (unsigned int)nArgsExpected) return false; } - + return true; } @@ -920,7 +920,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in { if (tx.IsCoinBase() || tx.IsCoinImport()) return 0; - + unsigned int nSigOps = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { @@ -943,13 +943,13 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, { bool isOverwinter = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); bool isSprout = !isOverwinter; - + // If Sprout rules apply, reject transactions which are intended for Overwinter and beyond if (isSprout && tx.fOverwintered) { return state.DoS(dosLevel, error("ContextualCheckTransaction(): overwinter is not active yet"), REJECT_INVALID, "tx-overwinter-not-active"); } - + // If Overwinter rules apply: if (isOverwinter) { // Reject transactions with valid version but missing overwinter flag @@ -957,19 +957,19 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, return state.DoS(dosLevel, error("ContextualCheckTransaction(): overwinter flag must be set"), REJECT_INVALID, "tx-overwinter-flag-not-set"); } - + // Reject transactions with invalid version if (tx.fOverwintered && tx.nVersion > OVERWINTER_MAX_TX_VERSION ) { return state.DoS(100, error("CheckTransaction(): overwinter version too high"), REJECT_INVALID, "bad-tx-overwinter-version-too-high"); } - + // Reject transactions intended for Sprout if (!tx.fOverwintered) { return state.DoS(dosLevel, error("ContextualCheckTransaction: overwinter is active"), REJECT_INVALID, "tx-overwinter-active"); } - + // Check that all transactions are unexpired if (IsExpiredTx(tx, nHeight)) { return state.DoS(dosLevel, error("ContextualCheckTransaction(): transaction is expired"), REJECT_INVALID, "tx-overwinter-expired"); @@ -987,9 +987,9 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, return state.DoS(100, error("CheckTransaction(): error computing signature hash"), REJECT_INVALID, "error-computing-signature-hash"); } - + BOOST_STATIC_ASSERT(crypto_sign_PUBLICKEYBYTES == 32); - + // We rely on libsodium to check that the signature is canonical. // https://github.com/jedisct1/libsodium/commit/62911edb7ff2275cccd74bf1c8aefcc4d76924e0 if (crypto_sign_verify_detached(&tx.joinSplitSig[0], @@ -1027,7 +1027,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, if (!tx.IsCoinBase()) { transactionsValidated.increment(); } - + if (!CheckTransactionWithoutProofVerification(tx, state)) { return false; } else { @@ -1067,7 +1067,7 @@ int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidationState &state) { // Basic checks that don't depend on any context - + /** * Previously: * 1. The consensus rule below was: @@ -1108,7 +1108,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio REJECT_INVALID, "bad-tx-expiry-height-too-high"); } } - + // Transactions can contain empty `vin` and `vout` so long as // `vjoinsplit` is non-empty. // Migrations may also have empty `vin` @@ -1118,13 +1118,13 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio if (tx.vout.empty() && tx.vjoinsplit.empty()) return state.DoS(10, error("CheckTransaction(): vout empty"), REJECT_INVALID, "bad-txns-vout-empty"); - + // Size limits BOOST_STATIC_ASSERT(MAX_BLOCK_SIZE > MAX_TX_SIZE); // sanity if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_TX_SIZE) return state.DoS(100, error("CheckTransaction(): size limits failed"), REJECT_INVALID, "bad-txns-oversize"); - + // Check for negative or overflow output values CAmount nValueOut = 0; int32_t iscoinbase = tx.IsCoinBase(); @@ -1156,7 +1156,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio return state.DoS(100, error("CheckTransaction(): txout total out of range"), REJECT_INVALID, "bad-txns-txouttotal-toolarge"); } - + // Ensure that joinsplit values are well-formed BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) { @@ -1169,27 +1169,27 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_old negative"), REJECT_INVALID, "bad-txns-vpub_old-negative"); } - + if (joinsplit.vpub_new < 0) { return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_new negative"), REJECT_INVALID, "bad-txns-vpub_new-negative"); } - + if (joinsplit.vpub_old > MAX_MONEY) { return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_old too high"), REJECT_INVALID, "bad-txns-vpub_old-toolarge"); } - + if (joinsplit.vpub_new > MAX_MONEY) { return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_new too high"), REJECT_INVALID, "bad-txns-vpub_new-toolarge"); } - + if (joinsplit.vpub_new != 0 && joinsplit.vpub_old != 0) { return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_new and joinsplit.vpub_old both nonzero"), REJECT_INVALID, "bad-txns-vpubs-both-nonzero"); } - + nValueOut += joinsplit.vpub_old; if (!MoneyRange(nValueOut)) { return state.DoS(100, error("CheckTransaction(): txout total out of range"), @@ -1213,7 +1213,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio } } } - + // Ensure input values do not exceed MAX_MONEY // We have not resolved the txin values at this stage, // but we do know what the joinsplits claim to add @@ -1223,15 +1223,15 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio for (std::vector::const_iterator it(tx.vjoinsplit.begin()); it != tx.vjoinsplit.end(); ++it) { nValueIn += it->vpub_new; - + if (!MoneyRange(it->vpub_new) || !MoneyRange(nValueIn)) { return state.DoS(100, error("CheckTransaction(): txin total out of range"), REJECT_INVALID, "bad-txns-txintotal-toolarge"); } } } - - + + // Check for duplicate inputs set vInOutPoints; BOOST_FOREACH(const CTxIn& txin, tx.vin) @@ -1241,7 +1241,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio REJECT_INVALID, "bad-txns-inputs-duplicate"); vInOutPoints.insert(txin.prevout); } - + // Check for duplicate joinsplit nullifiers in this transaction set vJoinSplitNullifiers; BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) @@ -1251,18 +1251,18 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio if (vJoinSplitNullifiers.count(nf)) return state.DoS(100, error("CheckTransaction(): duplicate nullifiers"), REJECT_INVALID, "bad-joinsplits-nullifiers-duplicate"); - + vJoinSplitNullifiers.insert(nf); } } - + if (tx.IsMint()) { // There should be no joinsplits in a coinbase transaction if (tx.vjoinsplit.size() > 0) return state.DoS(100, error("CheckTransaction(): coinbase has joinsplits"), REJECT_INVALID, "bad-cb-has-joinsplits"); - + if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100) return state.DoS(100, error("CheckTransaction(): coinbase script size"), REJECT_INVALID, "bad-cb-length"); @@ -1274,7 +1274,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio return state.DoS(10, error("CheckTransaction(): prevout is null"), REJECT_INVALID, "bad-txns-prevout-null"); } - + return true; } @@ -1290,9 +1290,9 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF if (dPriorityDelta > 0 || nFeeDelta > 0) return 0; } - + CAmount nMinFee = ::minRelayTxFee.GetFee(nBytes); - + if (fAllowFree) { // There is a free transaction area in blocks created by most miners, @@ -1302,7 +1302,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF if (nBytes < (DEFAULT_BLOCK_PRIORITY_SIZE - 1000)) nMinFee = 0; } - + if (!MoneyRange(nMinFee)) nMinFee = MAX_MONEY; return nMinFee; @@ -1314,10 +1314,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa AssertLockHeld(cs_main); if (pfMissingInputs) *pfMissingInputs = false; - + int flag=0,nextBlockHeight = chainActive.Height() + 1; auto consensusBranchId = CurrentEpochBranchId(nextBlockHeight, Params().GetConsensus()); - + // Node operator can choose to reject tx by number of transparent inputs static_assert(std::numeric_limits::max() >= std::numeric_limits::max(), "size_t too small"); size_t limit = (size_t) GetArg("-mempooltxinputlimit", 0); @@ -1328,7 +1328,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - + auto verifier = libzcash::ProofVerifier::Strict(); if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) { @@ -1345,7 +1345,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } - + // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) { @@ -1374,7 +1374,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"already in mempool\n"); return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); } - + // Check for conflicts with in-memory transactions { LOCK(pool.cs); // protect pool.mapNextTx @@ -1402,7 +1402,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } - + { CCoinsView dummy; CCoinsViewCache view(&dummy); @@ -1412,14 +1412,14 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa LOCK(pool.cs); CCoinsViewMemPool viewMemPool(pcoinsTip, pool); view.SetBackend(viewMemPool); - + // do we already have it? if (view.HaveCoins(hash)) { //fprintf(stderr,"view.HaveCoins(hash) error\n"); return state.Invalid(false, REJECT_DUPLICATE, "already have coins"); } - + if (tx.IsCoinImport()) { // Inverse of normal case; if input exists, it's been spent @@ -1441,7 +1441,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - + // are the actual inputs available? if (!view.HaveInputs(tx)) { @@ -1455,21 +1455,21 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"accept failure.2\n"); return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); } - + // Bring the best block into scope view.GetBestBlock(); - + nValueIn = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime); if ( 0 && interest != 0 ) fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool view.SetBackend(dummy); } - + // Check for non-standard pay-to-script-hash in inputs if (Params().RequireStandard() && !AreInputsStandard(tx, view, consensusBranchId)) return error("AcceptToMemoryPool: reject nonstandard transaction input"); - + // Check that the transaction doesn't have an excessive number of // sigops, making it impossible to mine. Since the coinbase transaction // itself can contain sigops MAX_STANDARD_TX_SIGOPS is less than @@ -1482,11 +1482,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa fprintf(stderr,"accept failure.4\n"); return state.DoS(0, error("AcceptToMemoryPool: too many sigops %s, %d > %d", hash.ToString(), nSigOps, MAX_STANDARD_TX_SIGOPS),REJECT_NONSTANDARD, "bad-txns-too-many-sigops"); } - + CAmount nValueOut = tx.GetValueOut(); CAmount nFees = nValueIn-nValueOut; double dPriority = view.GetPriority(tx, chainActive.Height()); - + // Keep track of transactions that spend a coinbase, which we re-scan // during reorgs to ensure COINBASE_MATURITY is still met. bool fSpendsCoinbase = false; @@ -1499,15 +1499,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } - + // Grab the branch ID we expect this transaction to commit to. We don't // yet know if it does, but if the entry gets added to the mempool, then // it has passed ContextualCheckInputs and therefore this is correct. auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - + CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height(), mempool.HasNoInputsOf(tx), fSpendsCoinbase, consensusBranchId); unsigned int nSize = entry.GetTxSize(); - + // Accept a tx if it contains joinsplits and has at least the default fee specified by z_sendmany. if (tx.vjoinsplit.size() > 0 && nFees >= ASYNC_RPC_OPERATION_DEFAULT_MINERS_FEE) { // In future we will we have more accurate and dynamic computation of fees for tx with joinsplits. @@ -1520,13 +1520,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return state.DoS(0, error("AcceptToMemoryPool: not enough fees %s, %d < %d",hash.ToString(), nFees, txMinFee),REJECT_INSUFFICIENTFEE, "insufficient fee"); } } - + // Require that free transactions have sufficient priority to be mined in the next block. if (GetBoolArg("-relaypriority", false) && nFees < ::minRelayTxFee.GetFee(nSize) && !AllowFree(view.GetPriority(tx, chainActive.Height() + 1))) { fprintf(stderr,"accept failure.6\n"); return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "insufficient priority"); } - + // Continuously rate-limit free (really, very-low-fee) transactions // This mitigates 'penny-flooding' -- sending thousands of free transactions just to // be annoying or make others' transactions take longer to confirm. @@ -1536,9 +1536,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa static double dFreeCount; static int64_t nLastTime; int64_t nNow = GetTime(); - + LOCK(csFreeLimiter); - + // Use an exponentially decaying ~10-minute window: dFreeCount *= pow(1.0 - 1.0/600.0, (double)(nNow - nLastTime)); nLastTime = nNow; @@ -1552,13 +1552,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa LogPrint("mempool", "Rate limit dFreeCount: %g => %g\n", dFreeCount, dFreeCount+nSize); dFreeCount += nSize; } - + if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19 ) { fprintf(stderr,"accept failure.8\n"); return error("AcceptToMemoryPool: absurdly high fees %s, %d > %d",hash.ToString(), nFees, ::minRelayTxFee.GetFee(nSize) * 10000); } - + // Check against previous transactions // This is done last to help prevent CPU exhaustion denial-of-service attacks. PrecomputedTransactionData txdata(tx); @@ -1567,7 +1567,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"accept failure.9\n"); return error("AcceptToMemoryPool: ConnectInputs failed %s", hash.ToString()); } - + // Check again against just the consensus-critical mandatory script // verification flags, in case of bugs in the standard flags that cause // transactions to pass as valid when they're actually invalid. For @@ -1610,9 +1610,9 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } - + SyncWithWallets(tx, NULL); - + return true; } @@ -1697,7 +1697,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo } } //fprintf(stderr,"check disk\n"); - + if (fTxIndex) { CDiskTxPos postx; //fprintf(stderr,"ReadTxIndex\n"); @@ -1730,14 +1730,14 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, bool fAllowSlow) { CBlockIndex *pindexSlow = NULL; - + LOCK(cs_main); - + if (mempool.lookup(hash, txOut)) { return true; } - + if (fTxIndex) { CDiskTxPos postx; if (pblocktree->ReadTxIndex(hash, postx)) { @@ -1758,7 +1758,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock return true; } } - + if (fAllowSlow) { // use coin database to locate block that contains transaction, and scan it int nHeight = -1; { @@ -1770,7 +1770,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock if (nHeight > 0) pindexSlow = chainActive[nHeight]; } - + if (pindexSlow) { CBlock block; if (ReadBlockFromDisk(block, pindexSlow,1)) { @@ -1783,7 +1783,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock } } } - + return false; } @@ -1813,18 +1813,18 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::M CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION); if (fileout.IsNull()) return error("WriteBlockToDisk: OpenBlockFile failed"); - + // Write index header unsigned int nSize = fileout.GetSerializeSize(block); fileout << FLATDATA(messageStart) << nSize; - + // Write block long fileOutPos = ftell(fileout.Get()); if (fileOutPos < 0) return error("WriteBlockToDisk: ftell failed"); pos.nPos = (unsigned int)fileOutPos; fileout << block; - + return true; } @@ -1832,7 +1832,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos,bo { uint8_t pubkey33[33]; block.SetNull(); - + // Open history file to read CAutoFile filein(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION); if (filein.IsNull()) @@ -1840,7 +1840,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos,bo //fprintf(stderr,"readblockfromdisk err A\n"); return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString()); } - + // Read block try { filein >> block; @@ -1858,7 +1858,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos,bo int32_t i; for (i=0; i<33; i++) fprintf(stderr,"%02x",pubkey33[i]); fprintf(stderr," warning unexpected diff at ht.%d\n",height); - + return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); } } @@ -1958,14 +1958,14 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) nSubsidy *= (nHeight+1); return nSubsidy; } - + assert(nHeight > consensusParams.SubsidySlowStartShift()); int halvings = (nHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nSubsidyHalvingInterval;*/ // Force block reward to zero when right shift is undefined. //int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; //if (halvings >= 64) // return 0; - + // Subsidy is cut in half every 840,000 blocks which will occur approximately every 4 years. //nSubsidy >>= halvings; return nSubsidy; @@ -2019,12 +2019,12 @@ void CheckForkWarningConditions() // (we assume we don't get stuck on a fork before the last checkpoint) if (IsInitialBlockDownload()) return; - + // If our best fork is no longer within 288 blocks (+/- 12 hours if no one mines it) // of our head, drop it if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 288) pindexBestForkTip = NULL; - + if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.LastTip()->nChainWork + (GetBlockProof(*chainActive.LastTip()) * 6))) { if (!fLargeWorkForkFound && pindexBestForkBase) @@ -2069,7 +2069,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) break; pfork = pfork->pprev; } - + // We define a condition where we should warn the user about as a fork of at least 7 blocks // with a tip within 72 blocks (+/- 3 hours if no one mines it) of ours // We use 7 blocks rather arbitrarily as it represents just under 10% of sustained network @@ -2084,7 +2084,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) pindexBestForkTip = pindexNewForkTip; pindexBestForkBase = pfork; } - + CheckForkWarningConditions(); } @@ -2093,11 +2093,11 @@ void Misbehaving(NodeId pnode, int howmuch) { if (howmuch == 0) return; - + CNodeState *state = State(pnode); if (state == NULL) return; - + state->nMisbehavior += howmuch; int banscore = GetArg("-banscore", 101); if (state->nMisbehavior >= banscore && state->nMisbehavior - howmuch < banscore) @@ -2112,7 +2112,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew) { if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork) pindexBestInvalid = pindexNew; - + LogPrintf("%s: invalid block=%s height=%d log2_work=%.8g date=%s\n", __func__, pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", @@ -2152,7 +2152,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund BOOST_FOREACH(const CTxIn &txin, tx.vin) { CCoinsModifier coins = inputs.ModifyCoins(txin.prevout.hash); unsigned nPos = txin.prevout.n; - + if (nPos >= coins->vout.size() || coins->vout[nPos].IsNull()) assert(false); // mark an outpoint spent, and construct undo information @@ -2172,7 +2172,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund } } inputs.ModifyCoins(tx.GetHash())->FromTx(tx, nHeight); // add outputs - + // Unorthodox state if (tx.IsCoinImport()) { // add a tombstone for the burnTx @@ -2210,11 +2210,11 @@ namespace Consensus { // for an attacker to attempt to split the network. if (!inputs.HaveInputs(tx)) return state.Invalid(error("CheckInputs(): %s inputs unavailable", tx.GetHash().ToString())); - + // are the JoinSplit's requirements met? if (!inputs.HaveJoinSplitRequirements(tx)) return state.Invalid(error("CheckInputs(): %s JoinSplit requirements not met", tx.GetHash().ToString())); - + CAmount nValueIn = 0; CAmount nFees = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) @@ -2222,7 +2222,7 @@ namespace Consensus { const COutPoint &prevout = tx.vin[i].prevout; const CCoins *coins = inputs.AccessCoins(prevout.hash); assert(coins); - + if (coins->IsCoinBase()) { // Ensure that coinbases are matured if (nSpendHeight - coins->nHeight < COINBASE_MATURITY) { @@ -2230,7 +2230,7 @@ namespace Consensus { error("CheckInputs(): tried to spend coinbase at depth %d/%d", nSpendHeight - coins->nHeight,(int32_t)COINBASE_MATURITY), REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); } - + // Ensure that coinbases cannot be spent to transparent outputs // Disabled on regtest if (fCoinbaseEnforcedProtectionEnabled && @@ -2241,7 +2241,7 @@ namespace Consensus { REJECT_INVALID, "bad-txns-coinbase-spend-has-transparent-outputs"); } } - + // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST @@ -2261,14 +2261,14 @@ namespace Consensus { if (!MoneyRange(coins->vout[prevout.n].nValue) || !MoneyRange(nValueIn)) return state.DoS(100, error("CheckInputs(): txin values out of range"), REJECT_INVALID, "bad-txns-inputvalues-outofrange"); - + } - + nValueIn += tx.GetJoinSplitValueIn(); if (!MoneyRange(nValueIn)) return state.DoS(100, error("CheckInputs(): vpub_old values out of range"), REJECT_INVALID, "bad-txns-inputvalues-outofrange"); - + if (nValueIn < tx.GetValueOut()) { fprintf(stderr,"spentheight.%d valuein %s vs %s error\n",nSpendHeight,FormatMoney(nValueIn).c_str(), FormatMoney(tx.GetValueOut()).c_str()); @@ -2305,14 +2305,14 @@ bool ContextualCheckInputs( if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs), consensusParams)) { return false; } - + if (pvChecks) pvChecks->reserve(tx.vin.size()); - + // The first loop above does all the inexpensive checks. // Only if ALL inputs pass do we perform expensive ECDSA signature checks. // Helps prevent CPU exhaustion attacks. - + // Skip ECDSA signature verification when connecting blocks // before the last block chain checkpoint. This is safe because block merkle hashes are // still computed and checked, and any change will be caught at the next checkpoint. @@ -2321,7 +2321,7 @@ bool ContextualCheckInputs( const COutPoint &prevout = tx.vin[i].prevout; const CCoins* coins = inputs.AccessCoins(prevout.hash); assert(coins); - + // Verify signature CScriptCheck check(*coins, tx, i, flags, cacheStore, consensusBranchId, &txdata); if (pvChecks) { @@ -2369,7 +2369,7 @@ bool ContextualCheckInputs( fprintf(stderr,"ContextualCheckInputs failure.0\n"); return false; } - + if (!tx.IsCoinBase()) { // While checking, GetBestBlock() refers to the parent block. @@ -2383,60 +2383,60 @@ bool ContextualCheckInputs( // Assertion is okay because NonContextualCheckInputs ensures the inputs // are available. assert(coins); - + // If prev is coinbase, check that it's matured if (coins->IsCoinBase()) { if ( ASSETCHAINS_SYMBOL[0] == 0 ) COINBASE_MATURITY = _COINBASE_MATURITY; if (nSpendHeight - coins->nHeight < COINBASE_MATURITY) { fprintf(stderr,"ContextualCheckInputs failure.1 i.%d of %d\n",i,(int32_t)tx.vin.size()); - + return state.Invalid( error("CheckInputs(): tried to spend coinbase at depth %d", nSpendHeight - coins->nHeight),REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); } } } } - + return true; }*/ namespace { - + bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock, const CMessageHeader::MessageStartChars& messageStart) { // Open history file to append CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION); if (fileout.IsNull()) return error("%s: OpenUndoFile failed", __func__); - + // Write index header unsigned int nSize = fileout.GetSerializeSize(blockundo); fileout << FLATDATA(messageStart) << nSize; - + // Write undo data long fileOutPos = ftell(fileout.Get()); if (fileOutPos < 0) return error("%s: ftell failed", __func__); pos.nPos = (unsigned int)fileOutPos; fileout << blockundo; - + // calculate & write checksum CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION); hasher << hashBlock; hasher << blockundo; fileout << hasher.GetHash(); - + return true; } - + bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock) { // Open history file to read CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION); if (filein.IsNull()) return error("%s: OpenBlockFile failed", __func__); - + // Read block uint256 hashChecksum; try { @@ -2452,10 +2452,10 @@ namespace { hasher << blockundo; if (hashChecksum != hasher.GetHash()) return error("%s: Checksum mismatch", __func__); - + return true; } - + /** Abort with a message */ bool AbortNode(const std::string& strMessage, const std::string& userMessage="") { @@ -2467,13 +2467,13 @@ namespace { StartShutdown(); return false; } - + bool AbortNode(CValidationState& state, const std::string& strMessage, const std::string& userMessage="") { AbortNode(strMessage, userMessage); return state.Error(strMessage); } - + } // anon namespace /** @@ -2486,7 +2486,7 @@ namespace { static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const COutPoint& out) { bool fClean = true; - + CCoinsModifier coins = view.ModifyCoins(out.hash); if (undo.nHeight != 0) { // undo data contains height: this is the last output of the prevout tx being spent @@ -2505,7 +2505,7 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const CO if (coins->vout.size() < out.n+1) coins->vout.resize(out.n+1); coins->vout[out.n] = undo.txout; - + return fClean; } @@ -2543,10 +2543,10 @@ void DisconnectNotarisations(const CBlock &block) bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean) { assert(pindex->GetBlockHash() == view.GetBestBlock()); - + if (pfClean) *pfClean = false; - + bool fClean = true; komodo_disconnect(pindex,block); CBlockUndo blockUndo; @@ -2555,7 +2555,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex return error("DisconnectBlock(): no undo data available"); if (!UndoReadFromDisk(blockUndo, pos, pindex->pprev->GetBlockHash())) return error("DisconnectBlock(): failure reading undo data"); - + if (blockUndo.vtxundo.size() + 1 != block.vtx.size()) return error("DisconnectBlock(): block and undo data inconsistent"); std::vector > addressIndex; @@ -2593,23 +2593,23 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } else if (out.scriptPubKey.IsPayToPublicKey()) { vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); - + // undo receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); - + // undo unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue())); - + } else if (out.scriptPubKey.IsPayToCryptoCondition()) { vector hashBytes(out.scriptPubKey.begin(), out.scriptPubKey.end()); - + // undo receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); - + // undo unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue())); - + } else { continue; @@ -2624,7 +2624,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex { CCoinsModifier outs = view.ModifyCoins(hash); outs->ClearUnspendable(); - + CCoins outsBlock(tx, pindex->nHeight); // The CCoins serialization does not serialize negative numbers. // No network rules currently depend on the version here, so an inconsistency is harmless @@ -2633,18 +2633,18 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex outs->nVersion = outsBlock.nVersion; if (*outs != outsBlock) fClean = fClean && error("DisconnectBlock(): added transaction mismatch? database corrupted"); - + // remove outputs outs->Clear(); } - + // unspend nullifiers BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { view.SetNullifier(nf, false); } } - + // restore inputs if (!tx.IsMint()) { const CTxUndo &txundo = blockUndo.vtxundo[i-1]; @@ -2688,23 +2688,23 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } else if (prevout.scriptPubKey.IsPayToPublicKey()) { vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); - + // undo spending activity addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); - + // restore unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); - + } else if (prevout.scriptPubKey.IsPayToCryptoCondition()) { vector hashBytes(prevout.scriptPubKey.begin(), prevout.scriptPubKey.end()); - + // undo spending activity addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); - + // restore unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); - + } else { continue; @@ -2720,10 +2720,10 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // set the old best anchor back view.PopAnchor(blockUndo.old_tree_root); - + // move best block pointer to prevout block view.SetBestBlock(pindex->pprev->GetBlockHash()); - + if (pfClean) { *pfClean = fClean; return true; @@ -2744,9 +2744,9 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex void static FlushBlockFile(bool fFinalize = false) { LOCK(cs_LastBlockFile); - + CDiskBlockPos posOld(nLastBlockFile, 0); - + FILE *fileOld = OpenBlockFile(posOld); if (fileOld) { if (fFinalize) @@ -2754,7 +2754,7 @@ void static FlushBlockFile(bool fFinalize = false) FileCommit(fileOld); fclose(fileOld); } - + fileOld = OpenUndoFile(posOld); if (fileOld) { if (fFinalize) @@ -2782,20 +2782,20 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const int64_t nPowTargetSpacing) { if (bestHeader == NULL || initialDownloadCheck()) return; - + static int64_t lastAlertTime = 0; int64_t now = GetAdjustedTime(); if (lastAlertTime > now-60*60*24) return; // Alert at most once per day - + const int SPAN_HOURS=4; const int SPAN_SECONDS=SPAN_HOURS*60*60; int BLOCKS_EXPECTED = SPAN_SECONDS / nPowTargetSpacing; - + boost::math::poisson_distribution poisson(BLOCKS_EXPECTED); - + std::string strWarning; int64_t startTime = GetAdjustedTime()-SPAN_SECONDS; - + LOCK(cs); const CBlockIndex* i = bestHeader; int nBlocks = 0; @@ -2804,17 +2804,17 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const i = i->pprev; if (i == NULL) return; // Ran out of chain, we must not be fully synced } - + // How likely is it to find that many by chance? double p = boost::math::pdf(poisson, nBlocks); - + LogPrint("partitioncheck", "%s : Found %d blocks in the last %d hours\n", __func__, nBlocks, SPAN_HOURS); LogPrint("partitioncheck", "%s : likelihood: %g\n", __func__, p); - + // Aim for one false-positive about every fifty years of normal running: const int FIFTY_YEARS = 50*365*24*60*60; double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS); - + if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED) { // Many fewer blocks than expected: alert! @@ -2866,7 +2866,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - + // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); if ( hashPrevBlock != view.GetBestBlock() ) @@ -2876,7 +2876,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin REJECT_INVALID, "hashPrevBlock-not-bestblock"); } assert(hashPrevBlock == view.GetBestBlock()); - + // Special case for the genesis block, skipping connection of its transactions // (its coinbase is unspendable) if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) { @@ -2890,7 +2890,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } return true; } - + bool fScriptChecks = (!fCheckpointsEnabled || pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints())); //if ( KOMODO_TESTNET_EXPIRATION != 0 && pindex->nHeight > KOMODO_TESTNET_EXPIRATION ) // "testnet" // return(false); @@ -2902,13 +2902,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): tried to overwrite transaction"), REJECT_INVALID, "bad-txns-BIP30"); } - + unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY; - + // DERSIG (BIP66) is also always enforced, but does not have a flag. - + CBlockUndo blockundo; - + if ( ASSETCHAINS_CC != 0 ) { if ( scriptcheckqueue.IsIdle() == 0 ) @@ -2918,7 +2918,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } } CCheckQueueControl control(fExpensiveChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); - + int64_t nTimeStart = GetTimeMicros(); CAmount nFees = 0; int nInputs = 0; @@ -2942,16 +2942,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // This should never fail: we should always be able to get the root // that is on the tip of our chain assert(view.GetAnchorAt(old_tree_root, tree)); - + { // Consistency check: the root of the tree we're given should // match what we asked for. assert(tree.root() == old_tree_root); } - + // Grab the consensus branch ID for the block's height auto consensusBranchId = CurrentEpochBranchId(pindex->nHeight, Params().GetConsensus()); - + std::vector txdata; txdata.reserve(block.vtx.size()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated for (unsigned int i = 0; i < block.vtx.size(); i++) @@ -3029,14 +3029,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): too many sigops"), REJECT_INVALID, "bad-blk-sigops"); } - + txdata.emplace_back(tx); - + if (!tx.IsCoinBase()) { nFees += view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime) - tx.GetValueOut(); sum += interest; - + std::vector vChecks; if (!ContextualCheckInputs(tx, state, view, fExpensiveChecks, flags, false, txdata[i], chainparams.GetConsensus(), consensusBranchId, nScriptCheckThreads ? &vChecks : NULL)) return false; @@ -3069,23 +3069,23 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } else if (out.scriptPubKey.IsPayToPublicKey()) { vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); - + // record receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); - + // record unspent output addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); - + } else if (out.scriptPubKey.IsPayToCryptoCondition()) { vector hashBytes(out.scriptPubKey.begin(), out.scriptPubKey.end()); - + // record receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); - + // record unspent output addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); - + } else { continue; @@ -3101,28 +3101,28 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin blockundo.vtxundo.push_back(CTxUndo()); } UpdateCoins(tx, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->nHeight); - + BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 ¬e_commitment, joinsplit.commitments) { // Insert the note commitments into our temporary tree. - + tree.append(note_commitment); } } - + vPos.push_back(std::make_pair(tx.GetHash(), pos)); pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); } - + view.PushAnchor(tree); if (!fJustCheck) { pindex->hashAnchorEnd = tree.root(); } blockundo.old_tree_root = old_tree_root; - + int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart; 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 ) { @@ -3149,10 +3149,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, false); int64_t nTime2 = GetTimeMicros(); nTimeVerify += nTime2 - nTimeStart; LogPrint("bench", " - Verify %u txins: %.2fms (%.3fms/txin) [%.2fs]\n", nInputs - 1, 0.001 * (nTime2 - nTimeStart), nInputs <= 1 ? 0 : 0.001 * (nTime2 - nTimeStart) / (nInputs-1), nTimeVerify * 0.000001); - + if (fJustCheck) return true; - + // Write undo information to disk if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS)) { @@ -3162,12 +3162,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return error("ConnectBlock(): FindUndoPos failed"); if (!UndoWriteToDisk(blockundo, pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) return AbortNode(state, "Failed to write undo data"); - + // update nUndoPos in block index pindex->nUndoPos = pos.nPos; pindex->nStatus |= BLOCK_HAVE_UNDO; } - + // Now that all consensus rules have been validated, set nCachedBranchId. // Move this if BLOCK_VALID_CONSENSUS is ever altered. static_assert(BLOCK_VALID_CONSENSUS == BLOCK_VALID_SCRIPTS, @@ -3178,13 +3178,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } else if (pindex->pprev) { pindex->nCachedBranchId = pindex->pprev->nCachedBranchId; } - + pindex->RaiseValidity(BLOCK_VALID_SCRIPTS); setDirtyBlockIndex.insert(pindex); } ConnectNotarisations(block, pindex->nHeight); - + if (fTxIndex) if (!pblocktree->WriteTxIndex(vPos)) return AbortNode(state, "Failed to write transaction index"); @@ -3226,18 +3226,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // add this block to the view's block chain view.SetBestBlock(pindex->GetBlockHash()); - + int64_t nTime3 = GetTimeMicros(); nTimeIndex += nTime3 - nTime2; LogPrint("bench", " - Index writing: %.2fms [%.2fs]\n", 0.001 * (nTime3 - nTime2), nTimeIndex * 0.000001); - + // Watch for changes to the previous coinbase transaction. static uint256 hashPrevBestCoinBase; GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase); hashPrevBestCoinBase = block.vtx[0].GetHash(); - + int64_t nTime4 = GetTimeMicros(); nTimeCallbacks += nTime4 - nTime3; LogPrint("bench", " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime4 - nTime3), nTimeCallbacks * 0.000001); - + //FlushStateToDisk(); komodo_connectblock(pindex,*(CBlock *)&block); return true; @@ -3367,7 +3367,7 @@ void PruneAndFlush() { void static UpdateTip(CBlockIndex *pindexNew) { const CChainParams& chainParams = Params(); chainActive.SetTip(pindexNew); - + // New best block nTimeBestReceived = GetTime(); mempool.AddTransactionsUpdated(1); @@ -3385,9 +3385,9 @@ void static UpdateTip(CBlockIndex *pindexNew) { log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.LastTip()->nChainTx, DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress, pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); - + cvBlockChange.notify_all(); - + // Check the version of the last 100 blocks to see if we need to upgrade: static bool fWarned = false; if (!IsInitialBlockDownload() && !fWarned) @@ -3451,7 +3451,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // Write the chain state to disk, if necessary. if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) return false; - + if (!fBare) { // Resurrect mempool transactions from the disconnected block. @@ -3471,7 +3471,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { mempool.removeWithAnchor(anchorBeforeDisconnect); } } - + // Update chainActive and related variables. UpdateTip(pindexDelete->pprev); // Get the current commitment tree @@ -3512,7 +3512,7 @@ static int64_t nTimePostConnect = 0; * You probably want to call mempool.removeWithoutBranchId after this, with cs_main held. */ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *pblock) { - + assert(pindexNew->pprev == chainActive.Tip()); // Read block from disk. int64_t nTime1 = GetTimeMicros(); @@ -3555,10 +3555,10 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * // Remove conflicting transactions from the mempool. list txConflicted; mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, txConflicted, !IsInitialBlockDownload()); - + // Remove transactions that expire at new block height from mempool mempool.removeExpired(pindexNew->nHeight); - + // Update chainActive & related variables. UpdateTip(pindexNew); // Tell wallet about transactions that went from mempool @@ -3573,9 +3573,9 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * // Update cached incremental witnesses //fprintf(stderr,"chaintip true\n"); GetMainSignals().ChainTip(pindexNew, pblock, oldTree, true); - + EnforceNodeDeprecation(pindexNew->nHeight); - + int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); @@ -3595,7 +3595,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * static CBlockIndex* FindMostWorkChain() { do { CBlockIndex *pindexNew = NULL; - + // Find the best candidate header. { std::set::reverse_iterator it = setBlockIndexCandidates.rbegin(); @@ -3603,14 +3603,14 @@ static CBlockIndex* FindMostWorkChain() { return NULL; pindexNew = *it; } - + // Check whether all blocks on the path between the currently active chain and the candidate are valid. // Just going until the active chain is an optimization, as we know all blocks in it are valid already. CBlockIndex *pindexTest = pindexNew; bool fInvalidAncestor = false; while (pindexTest && !chainActive.Contains(pindexTest)) { assert(pindexTest->nChainTx || pindexTest->nHeight == 0); - + // Pruned nodes may have entries in setBlockIndexCandidates for // which block files have been deleted. Remove those as candidates // for the most work chain if we come across them; we can't switch @@ -3667,7 +3667,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo bool fInvalidFound = false; const CBlockIndex *pindexOldTip = chainActive.Tip(); const CBlockIndex *pindexFork = chainActive.FindFork(pindexMostWork); - + // - On ChainDB initialization, pindexOldTip will be null, so there are no removable blocks. // - If pindexMostWork is in a chain that doesn't have the same genesis block as our chain, // then pindexFork will be null, and we would need to remove the entire chain including @@ -3703,7 +3703,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo return false; } } - + // Disconnect active blocks which are no longer in the best chain. bool fBlocksDisconnected = false; while (chainActive.Tip() && chainActive.Tip() != pindexFork) { @@ -3745,7 +3745,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo pindexIter = pindexIter->pprev; } nHeight = nTargetHeight; - + // Connect new blocks. BOOST_REVERSE_FOREACH(CBlockIndex *pindexConnect, vpindexToConnect) { if (!ConnectTip(state, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL)) { @@ -3771,20 +3771,20 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } } } - + if (fBlocksDisconnected) { mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS); } mempool.removeWithoutBranchId( CurrentEpochBranchId(chainActive.Tip()->nHeight + 1, Params().GetConsensus())); mempool.check(pcoinsTip); - + // Callbacks/notifications for a new best chain. if (fInvalidFound) CheckForkWarningConditionsOnNewFork(vpindexToConnect.back()); else CheckForkWarningConditions(); - + return true; } @@ -3799,23 +3799,23 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) { const CChainParams& chainParams = Params(); do { boost::this_thread::interruption_point(); - + bool fInitialDownload; { LOCK(cs_main); pindexMostWork = FindMostWorkChain(); - + // Whether we have anything to do at all. if (pindexMostWork == NULL || pindexMostWork == chainActive.Tip()) return true; - + if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : NULL)) return false; pindexNewTip = chainActive.Tip(); fInitialDownload = IsInitialBlockDownload(); } // When we reach this point, we switched to a new tip (stored in pindexNewTip). - + // Notifications/callbacks that can run without cs_main if (!fInitialDownload) { uint256 hashNewTip = pindexNewTip->GetBlockHash(); @@ -3837,23 +3837,23 @@ bool ActivateBestChain(CValidationState &state, CBlock *pblock) { } //else fprintf(stderr,"initial download skips propagation\n"); } while(pindexMostWork != chainActive.Tip()); CheckBlockIndex(); - + // Write changes periodically to disk, after relay. if (!FlushStateToDisk(state, FLUSH_STATE_PERIODIC)) { return false; } - + return true; } bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { AssertLockHeld(cs_main); - + // Mark the block itself as invalid. pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex); setBlockIndexCandidates.erase(pindex); - + while (chainActive.Contains(pindex)) { CBlockIndex *pindexWalk = chainActive.Tip(); pindexWalk->nStatus |= BLOCK_FAILED_CHILD; @@ -3869,7 +3869,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { } } //LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); - + // The resulting new best tip may not be in setBlockIndexCandidates anymore, so // add it again. BlockMap::iterator it = mapBlockIndex.begin(); @@ -3879,7 +3879,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { } it++; } - + InvalidChainFound(pindex); mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS); mempool.removeWithoutBranchId( @@ -3889,9 +3889,9 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { AssertLockHeld(cs_main); - + int nHeight = pindex->nHeight; - + // Remove the invalidity flag from this block and all its descendants. BlockMap::iterator it = mapBlockIndex.begin(); while (it != mapBlockIndex.end() && it->second != 0) { @@ -3908,7 +3908,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { } it++; } - + // Remove the invalidity flag from all ancestors too. while (pindex != NULL) { if (pindex->nStatus & BLOCK_FAILED_MASK) { @@ -3960,7 +3960,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) pindexNew->RaiseValidity(BLOCK_VALID_TREE); if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork) pindexBestHeader = pindexNew; - + setDirtyBlockIndex.insert(pindexNew); //fprintf(stderr,"added to block index %s %p\n",hash.ToString().c_str(),pindexNew); mi->second = pindexNew; @@ -3987,12 +3987,12 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl pindexNew->nStatus |= BLOCK_HAVE_DATA; pindexNew->RaiseValidity(BLOCK_VALID_TRANSACTIONS); setDirtyBlockIndex.insert(pindexNew); - + if (pindexNew->pprev == NULL || pindexNew->pprev->nChainTx) { // If pindexNew is the genesis block or all parents are BLOCK_VALID_TRANSACTIONS. deque queue; queue.push_back(pindexNew); - + // Recursively process any descendant blocks that now may be eligible to be connected. while (!queue.empty()) { CBlockIndex *pindex = queue.front(); @@ -4027,19 +4027,19 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl mapBlocksUnlinked.insert(std::make_pair(pindexNew->pprev, pindexNew)); } } - + return true; } bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) { LOCK(cs_LastBlockFile); - + unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile; if (vinfoBlockFile.size() <= nFile) { vinfoBlockFile.resize(nFile + 1); } - + if (!fKnown) { while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { nFile++; @@ -4050,7 +4050,7 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd pos.nFile = nFile; pos.nPos = vinfoBlockFile[nFile].nSize; } - + if (nFile != nLastBlockFile) { if (!fKnown) { LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString()); @@ -4058,13 +4058,13 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd FlushBlockFile(!fKnown); nLastBlockFile = nFile; } - + vinfoBlockFile[nFile].AddBlock(nHeight, nTime); if (fKnown) vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize); else vinfoBlockFile[nFile].nSize += nAddSize; - + if (!fKnown) { unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; unsigned int nNewChunks = (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; @@ -4083,7 +4083,7 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd return state.Error("out of disk space"); } } - + setDirtyFileInfo.insert(nFile); return true; } @@ -4091,14 +4091,14 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize) { pos.nFile = nFile; - + LOCK(cs_LastBlockFile); - + unsigned int nNewSize; pos.nPos = vinfoBlockFile[nFile].nUndoSize; nNewSize = vinfoBlockFile[nFile].nUndoSize += nAddSize; setDirtyFileInfo.insert(nFile); - + unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; unsigned int nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; if (nNewChunks > nOldChunks) { @@ -4115,7 +4115,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne else return state.Error("out of disk space"); } - + return true; } @@ -4160,7 +4160,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, // Check block version if (height > 0 && blockhdr.nVersion < MIN_BLOCK_VERSION) return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low"); - + // Check Equihash solution is valid if ( fCheckPOW ) { @@ -4215,7 +4215,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if (block.hashMerkleRoot != hashMerkleRoot2) return state.DoS(100, error("CheckBlock: hashMerkleRoot mismatch"), REJECT_INVALID, "bad-txnmrklroot", true); - + // Check for merkle tree malleability (CVE-2012-2459): repeating sequences // of transactions in a block without affecting the merkle root of a block, // while still invalidating it. @@ -4223,16 +4223,16 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C return state.DoS(100, error("CheckBlock: duplicate transaction"), REJECT_INVALID, "bad-txns-duplicate", true); } - + // All potential-corruption validation must be done before we do any // transaction validation, as otherwise we may mark the header as invalid // because we receive the wrong transactions for it. - + // Size limits if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE) return state.DoS(100, error("CheckBlock: size limits failed"), REJECT_INVALID, "bad-blk-length"); - + // First transaction must be coinbase, the rest must not be if (block.vtx.empty() || !block.vtx[0].IsCoinBase()) return state.DoS(100, error("CheckBlock: first tx is not coinbase"), @@ -4241,7 +4241,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if (block.vtx[i].IsCoinBase()) return state.DoS(100, error("CheckBlock: more than one coinbase"), REJECT_INVALID, "bad-cb-multiple"); - + // Check transactions if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { @@ -4305,11 +4305,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta uint256 hash = block.GetHash(); if (hash == consensusParams.hashGenesisBlock) return true; - + assert(pindexPrev); - + int nHeight = pindexPrev->nHeight+1; - + // Check proof of work if ( (ASSETCHAINS_SYMBOL[0] != 0 || nHeight < 235300 || nHeight > 236000) && block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) { @@ -4317,12 +4317,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta return state.DoS(100, error("%s: incorrect proof of work", __func__), REJECT_INVALID, "bad-diffbits"); } - + // Check timestamp against prev if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) return state.Invalid(error("%s: block's timestamp is too early", __func__), REJECT_INVALID, "time-too-old"); - + if (fCheckpointsEnabled) { // Check that the block chain matches the known block chain up to a checkpoint @@ -4365,7 +4365,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta if (block.nVersion < 4) return state.Invalid(error("%s : rejected nVersion<4 block", __func__), REJECT_OBSOLETE, "bad-version"); - + return true; } @@ -4373,15 +4373,15 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn { const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1; const Consensus::Params& consensusParams = Params().GetConsensus(); - + // Check that all transactions are finalized BOOST_FOREACH(const CTransaction& tx, block.vtx) { - + // Check transaction contextually against consensus rules at block height if (!ContextualCheckTransaction(tx, state, nHeight, 100)) { return false; // Failure reason has been set in validation state object } - + int nLockTimeFlags = 0; int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST) ? pindexPrev->GetMedianTimePast() @@ -4390,7 +4390,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } } - + // Enforce BIP 34 rule that the coinbase starts with serialized block height. // In Zcash this has been enforced since launch, except that the genesis // block didn't include the height in the coinbase (see Zcash protocol spec @@ -4403,7 +4403,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return state.DoS(100, error("%s: block height mismatch in coinbase", __func__), REJECT_INVALID, "bad-cb-height"); } } - + return true; } @@ -4504,7 +4504,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C { const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); - + CBlockIndex *&pindex = *ppindex; if (!AcceptBlockHeader(futureblockp,block, state, &pindex)) { @@ -4531,7 +4531,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // regardless of whether pruning is enabled; it should generally be safe to // not process unrequested blocks. bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW)); //MIN_BLOCKS_TO_KEEP)); - + // TODO: deal better with return value and error conditions for duplicate // and unrequested blocks. //fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead); @@ -4541,7 +4541,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if (!fHasMoreWork) return true; // Don't process less-work chains if (fTooFarAhead) return true; // Block height is too high } - + // See method docstring for why this is always disabled auto verifier = libzcash::ProofVerifier::Disabled(); if ((!CheckBlock(futureblockp,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) @@ -4556,7 +4556,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C return false; } } - + int nHeight = pindex->nHeight; // Write block to history file try { @@ -4574,7 +4574,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); } - + if (fCheckForPruning) FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files if ( *futureblockp == 0 ) @@ -4720,7 +4720,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo return error("%s: AcceptBlock FAILED", __func__); //else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); } - + if (futureblock == 0 && !ActivateBestChain(state, pblock)) return error("%s: ActivateBestChain failed", __func__); //fprintf(stderr,"finished ProcessBlock %d\n",(int32_t)chainActive.LastTip()->nHeight); @@ -4732,7 +4732,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex { AssertLockHeld(cs_main); assert(pindexPrev == chainActive.Tip()); - + CCoinsViewCache viewNew(pcoinsTip); CBlockIndex indexDummy(block); indexDummy.pprev = pindexPrev; @@ -4793,7 +4793,7 @@ void PruneOneBlockFile(const int fileNumber) pindex->nDataPos = 0; pindex->nUndoPos = 0; setDirtyBlockIndex.insert(pindex); - + // Prune from mapBlocksUnlinked -- any block we prune would have // to be downloaded again in order to consider its chain, at which // point it would be considered as a candidate for @@ -4808,7 +4808,7 @@ void PruneOneBlockFile(const int fileNumber) } } } - + vinfoBlockFile[fileNumber].SetNull(); setDirtyFileInfo.insert(fileNumber); } @@ -4842,21 +4842,21 @@ void FindFilesToPrune(std::set& setFilesToPrune) uint64_t nBuffer = BLOCKFILE_CHUNK_SIZE + UNDOFILE_CHUNK_SIZE; uint64_t nBytesToPrune; int count=0; - + if (nCurrentUsage + nBuffer >= nPruneTarget) { for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) { nBytesToPrune = vinfoBlockFile[fileNumber].nSize + vinfoBlockFile[fileNumber].nUndoSize; - + if (vinfoBlockFile[fileNumber].nSize == 0) continue; - + if (nCurrentUsage + nBuffer < nPruneTarget) // are we below our target? break; - + // don't prune files that could have a block within MIN_BLOCKS_TO_KEEP of the main chain's tip but keep scanning if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune) continue; - + PruneOneBlockFile(fileNumber); // Queue up the files for removal setFilesToPrune.insert(fileNumber); @@ -4864,7 +4864,7 @@ void FindFilesToPrune(std::set& setFilesToPrune) count++; } } - + LogPrint("prune", "Prune: target=%dMiB actual=%dMiB diff=%dMiB max_prune_height=%d removed %d blk/rev pairs\n", nPruneTarget/1024/1024, nCurrentUsage/1024/1024, ((int64_t)nPruneTarget - (int64_t)nCurrentUsage)/1024/1024, @@ -4874,11 +4874,11 @@ void FindFilesToPrune(std::set& setFilesToPrune) bool CheckDiskSpace(uint64_t nAdditionalBytes) { uint64_t nFreeBytesAvailable = boost::filesystem::space(GetDataDir()).available; - + // Check for nMinDiskSpace bytes (currently 50MB) if (nFreeBytesAvailable < nMinDiskSpace + nAdditionalBytes) return AbortNode("Disk space is low!", _("Error: Disk space is low!")); - + return true; } @@ -4928,12 +4928,12 @@ CBlockIndex * InsertBlockIndex(uint256 hash) { if (hash.IsNull()) return NULL; - + // Return existing BlockMap::iterator mi = mapBlockIndex.find(hash); if (mi != mapBlockIndex.end()) return (*mi).second; - + // Create new CBlockIndex* pindexNew = new CBlockIndex(); if (!pindexNew) @@ -4955,7 +4955,7 @@ bool static LoadBlockIndexDB() return false; LogPrintf("%s: loaded guts\n", __func__); boost::this_thread::interruption_point(); - + // Calculate nChainWork vector > vSortedByHeight; vSortedByHeight.reserve(mapBlockIndex.size()); @@ -5034,7 +5034,7 @@ bool static LoadBlockIndexDB() break; } } - + // Check presence of blk files LogPrintf("Checking all blk files are present...\n"); set setBlkDataFiles; @@ -5054,17 +5054,17 @@ bool static LoadBlockIndexDB() return false; } } - + // Check whether we have ever pruned block & undo files pblocktree->ReadFlag("prunedblockfiles", fHavePruned); if (fHavePruned) LogPrintf("LoadBlockIndexDB(): Block files have previously been pruned\n"); - + // Check whether we need to continue reindexing bool fReindexing = false; pblocktree->ReadReindexing(fReindexing); fReindex |= fReindexing; - + // Check whether we have a transaction index pblocktree->ReadFlag("txindex", fTxIndex); LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled"); @@ -5094,7 +5094,7 @@ bool static LoadBlockIndexDB() } //komodo_pindex_init(pindex,(int32_t)pindex->nHeight); } - + // Load pointer to end of best chain BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); if (it == mapBlockIndex.end()) @@ -5102,7 +5102,7 @@ bool static LoadBlockIndexDB() chainActive.SetTip(it->second); // Set hashAnchorEnd for the end of best chain it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor(); - + PruneBlockIndexCandidates(); double progress; @@ -5114,14 +5114,14 @@ bool static LoadBlockIndexDB() // runs, which makes it return 0, so we guess 50% for now progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 0.5; } - + LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress); - + EnforceNodeDeprecation(chainActive.Height(), true); - + return true; } @@ -5140,7 +5140,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth LOCK(cs_main); if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL) return true; - + // Verify blocks in the best chain if (nCheckDepth <= 0) nCheckDepth = 1000000000; // suffices until the year 19000 @@ -5197,7 +5197,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth //fprintf(stderr,"end VerifyDB %u\n",(uint32_t)time(NULL)); if (pindexFailure) return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainActive.Height() - pindexFailure->nHeight + 1, nGoodTransactions); - + // check level 4: try reconnecting blocks if (nCheckLevel >= 4) { CBlockIndex *pindex = pindexState; @@ -5212,16 +5212,16 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); } } - + LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->nHeight, nGoodTransactions); - + return true; } bool RewindBlockIndex(const CChainParams& params) { LOCK(cs_main); - + // RewindBlockIndex is called after LoadBlockIndex, so at this point every block // index will have nCachedBranchId set based on the values previously persisted // to disk. By definition, a set nCachedBranchId means that the block was @@ -5239,7 +5239,7 @@ bool RewindBlockIndex(const CChainParams& params) pindex->nCachedBranchId && *pindex->nCachedBranchId == CurrentEpochBranchId(pindex->nHeight, consensus); }; - + int nHeight = 1; while (nHeight <= chainActive.Height()) { if (!sufficientlyValidated(chainActive[nHeight])) { @@ -5247,7 +5247,7 @@ bool RewindBlockIndex(const CChainParams& params) } nHeight++; } - + // nHeight is now the height of the first insufficiently-validated block, or tipheight + 1 auto rewindLength = chainActive.Height() - nHeight; if (rewindLength > 0 && rewindLength > MAX_REORG_LENGTH) { @@ -5268,7 +5268,7 @@ bool RewindBlockIndex(const CChainParams& params) StartShutdown(); return false; } - + CValidationState state; CBlockIndex* pindex = chainActive.Tip(); while (chainActive.Height() >= nHeight) { @@ -5287,13 +5287,13 @@ bool RewindBlockIndex(const CChainParams& params) if (!FlushStateToDisk(state, FLUSH_STATE_PERIODIC)) return false; } - + // Reduce validity flag and have-data flags. // We do this after actual disconnecting, otherwise we'll end up writing the lack of data // to disk before writing the chainstate, resulting in a failure to continue if interrupted. for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); it++) { CBlockIndex* pindexIter = it->second; - + // Note: If we encounter an insufficiently validated block that // is on chainActive, it must be because we are a pruning node, and // this block or some successor doesn't HAVE_DATA, so we were unable to @@ -5326,7 +5326,7 @@ bool RewindBlockIndex(const CChainParams& params) //fprintf(stderr,"Reset invalid block marker if it was pointing to this block\n"); pindexBestInvalid = NULL; } - + // Update indices setBlockIndexCandidates.erase(pindexIter); auto ret = mapBlocksUnlinked.equal_range(pindexIter->pprev); @@ -5341,15 +5341,15 @@ bool RewindBlockIndex(const CChainParams& params) setBlockIndexCandidates.insert(pindexIter); } } - + PruneBlockIndexCandidates(); - + CheckBlockIndex(); - + if (!FlushStateToDisk(state, FLUSH_STATE_ALWAYS)) { return false; } - + return true; } @@ -5376,7 +5376,7 @@ void UnloadBlockIndex() setDirtyFileInfo.clear(); mapNodeState.clear(); recentRejects.reset(NULL); - + BOOST_FOREACH(BlockMap::value_type& entry, mapBlockIndex) { delete entry.second; } @@ -5401,7 +5401,7 @@ bool LoadBlockIndex() bool InitBlockIndex() { const CChainParams& chainparams = Params(); LOCK(cs_main); - + // Initialize global variables that cannot be constructed at startup. recentRejects.reset(new CRollingBloomFilter(120000, 0.000001)); // Check whether we're already initialized @@ -5419,12 +5419,12 @@ bool InitBlockIndex() { // Use the provided setting for -timestampindex in the new database fTimestampIndex = GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX); pblocktree->WriteFlag("timestampindex", fTimestampIndex); - + fSpentIndex = GetBoolArg("-spentindex", DEFAULT_SPENTINDEX); pblocktree->WriteFlag("spentindex", fSpentIndex); fprintf(stderr,"fAddressIndex.%d/%d fSpentIndex.%d/%d\n",fAddressIndex,DEFAULT_ADDRESSINDEX,fSpentIndex,DEFAULT_SPENTINDEX); LogPrintf("Initializing databases...\n"); - + // Only add the genesis block if not reindexing (in which case we reuse the one already on disk) if (!fReindex) { try { @@ -5450,7 +5450,7 @@ bool InitBlockIndex() { return error("LoadBlockIndex(): failed to initialize block database: %s", e.what()); } } - + return true; } @@ -5462,7 +5462,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) // Map of disk positions for blocks with unknown parent (only used for reindex) static std::multimap mapBlocksUnknownParent; int64_t nStart = GetTimeMillis(); - + int nLoaded = 0; try { // This takes over fileIn and calls fclose() on it in the CBufferedFile destructor @@ -5471,7 +5471,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) uint64_t nRewind = blkdat.GetPos(); while (!blkdat.eof()) { boost::this_thread::interruption_point(); - + blkdat.SetPos(nRewind); nRewind++; // start one byte further next time, in case of failure blkdat.SetLimit(); // remove former limit @@ -5502,7 +5502,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) CBlock block; blkdat >> block; nRewind = blkdat.GetPos(); - + // detect out of order blocks, and store them for later uint256 hash = block.GetHash(); if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex.find(block.hashPrevBlock) == mapBlockIndex.end()) { @@ -5512,7 +5512,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) mapBlocksUnknownParent.insert(std::make_pair(block.hashPrevBlock, *dbp)); continue; } - + // process in case the block isn't known yet if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) { CValidationState state; @@ -5523,7 +5523,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) } else if (hash != chainparams.GetConsensus().hashGenesisBlock && mapBlockIndex[hash]->nHeight % 1000 == 0) { LogPrintf("Block Import: already had block %s at height %d\n", hash.ToString(), mapBlockIndex[hash]->nHeight); } - + // Recursively process earlier encountered successors of this block deque queue; queue.push_back(hash); @@ -5566,9 +5566,9 @@ void static CheckBlockIndex() if (!fCheckBlockIndex) { return; } - + LOCK(cs_main); - + // During a reindex, we read the genesis block and call CheckBlockIndex before ActivateBestChain, // so we have the genesis block in mapBlockIndex but no active chain. (A few of the tests when // iterating the block tree require that chainActive has been initialized.) @@ -5576,7 +5576,7 @@ void static CheckBlockIndex() assert(mapBlockIndex.size() <= 1); return; } - + // Build forward-pointing map of the entire block tree. std::multimap forward; for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); it++) { @@ -5585,12 +5585,12 @@ void static CheckBlockIndex() } if ( Params().NetworkIDString() != "regtest" ) assert(forward.size() == mapBlockIndex.size()); - + std::pair::iterator,std::multimap::iterator> rangeGenesis = forward.equal_range(NULL); CBlockIndex *pindex = rangeGenesis.first->second; rangeGenesis.first++; assert(rangeGenesis.first == rangeGenesis.second); // There is only one index entry with parent NULL. - + // Iterate over the entire block tree, using depth-first search. // Along the way, remember whether there are blocks on the path from genesis // block being explored which are the first to have certain properties. @@ -5612,7 +5612,7 @@ void static CheckBlockIndex() if (pindex->pprev != NULL && pindexFirstNotTransactionsValid == NULL && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_TRANSACTIONS) pindexFirstNotTransactionsValid = pindex; if (pindex->pprev != NULL && pindexFirstNotChainValid == NULL && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_CHAIN) pindexFirstNotChainValid = pindex; if (pindex->pprev != NULL && pindexFirstNotScriptsValid == NULL && (pindex->nStatus & BLOCK_VALID_MASK) < BLOCK_VALID_SCRIPTS) pindexFirstNotScriptsValid = pindex; - + // Begin: actual consistency checks. if (pindex->pprev == NULL) { // Genesis block checks. @@ -5698,7 +5698,7 @@ void static CheckBlockIndex() } // assert(pindex->GetBlockHash() == pindex->GetBlockHeader().GetHash()); // Perhaps too slow // End: actual consistency checks. - + // Try descending into the first subnode. std::pair::iterator,std::multimap::iterator> range = forward.equal_range(pindex); if (range.first != range.second) { @@ -5741,7 +5741,7 @@ void static CheckBlockIndex() } } } - + // Check that we actually traversed the entire map. assert(nNodes == forward.size()); } @@ -5756,20 +5756,20 @@ std::string GetWarnings(const std::string& strFor) int nPriority = 0; string strStatusBar; string strRPC; - + if (!CLIENT_VERSION_IS_RELEASE) strStatusBar = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"); - + if (GetBoolArg("-testsafemode", false)) strStatusBar = strRPC = "testsafemode enabled"; - + // Misc warnings like out of disk space and clock is wrong if (strMiscWarning != "") { nPriority = 1000; strStatusBar = strMiscWarning; } - + if (fLargeWorkForkFound) { nPriority = 2000; @@ -5780,7 +5780,7 @@ std::string GetWarnings(const std::string& strFor) nPriority = 2000; strStatusBar = strRPC = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."); } - + // Alerts { LOCK(cs_mapAlerts); @@ -5797,7 +5797,7 @@ std::string GetWarnings(const std::string& strFor) } } } - + if (strFor == "statusbar") return strStatusBar; else if (strFor == "rpc") @@ -5835,7 +5835,7 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main) hashRecentRejectsChainTip = chainActive.Tip()->GetBlockHash(); recentRejects->reset(); } - + return recentRejects->contains(inv.hash) || mempool.exists(inv.hash) || mapOrphanTransactions.count(inv.hash) || @@ -5851,21 +5851,21 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main) void static ProcessGetData(CNode* pfrom) { std::deque::iterator it = pfrom->vRecvGetData.begin(); - + vector vNotFound; - + LOCK(cs_main); - + while (it != pfrom->vRecvGetData.end()) { // Don't bother if send buffer is too full to respond anyway if (pfrom->nSendSize >= SendBufferSize()) break; - + const CInv &inv = *it; { boost::this_thread::interruption_point(); it++; - + if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK) { bool send = false; @@ -5969,17 +5969,17 @@ void static ProcessGetData(CNode* pfrom) vNotFound.push_back(inv); } } - + // Track requests for our stuff. GetMainSignals().Inventory(inv.hash); - + if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK) break; } } - + pfrom->vRecvGetData.erase(pfrom->vRecvGetData.begin(), it); - + if (!vNotFound.empty()) { // Let the peer know that we didn't find what it asked for, so it doesn't // have to wait around forever. Currently only SPV clients actually care @@ -6002,10 +6002,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); return true; } - - - - + + + + if (strCommand == "version") { // Each connection can only send one version message @@ -6015,7 +6015,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 1); return false; } - + int64_t nTime; CAddress addrMe; CAddress addrFrom; @@ -6030,7 +6030,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->fDisconnect = true; return false; } - + // When Overwinter is active, reject incoming connections from non-Overwinter nodes const Consensus::Params& params = Params().GetConsensus(); if (NetworkUpgradeActive(GetHeight(), params, Consensus::UPGRADE_OVERWINTER) @@ -6043,7 +6043,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->fDisconnect = true; return false; } - + if (pfrom->nVersion == 10300) pfrom->nVersion = 300; if (!vRecv.empty()) @@ -6058,7 +6058,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, vRecv >> pfrom->fRelayTxes; // set to true after we get the first filter* message else pfrom->fRelayTxes = true; - + // Disconnect if we connected to ourself if (nNonce == nLocalHostNonce && nNonce > 1) { @@ -6066,26 +6066,26 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->fDisconnect = true; return true; } - + pfrom->addrLocal = addrMe; if (pfrom->fInbound && addrMe.IsRoutable()) { SeenLocal(addrMe); } - + // Be shy and don't send version until we hear if (pfrom->fInbound) pfrom->PushVersion(); - + pfrom->fClient = !(pfrom->nServices & NODE_NETWORK); - + // Potentially mark this peer as a preferred download peer. UpdatePreferredDownload(pfrom, State(pfrom->GetId())); - + // Change version pfrom->PushMessage("verack"); pfrom->ssSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); - + if (!pfrom->fInbound) { // Advertise our address @@ -6102,7 +6102,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->PushAddress(addr); } } - + // Get recent addresses if (pfrom->fOneShot || pfrom->nVersion >= CADDR_TIME_VERSION || addrman.size() < 1000) { @@ -6117,51 +6117,51 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, addrman.Good(addrFrom); } } - + // Relay alerts { LOCK(cs_mapAlerts); BOOST_FOREACH(PAIRTYPE(const uint256, CAlert)& item, mapAlerts) item.second.RelayTo(pfrom); } - + pfrom->fSuccessfullyConnected = true; - + string remoteAddr; if (fLogIPs) remoteAddr = ", peeraddr=" + pfrom->addr.ToString(); - + LogPrintf("receive version message: %s: version %d, blocks=%d, us=%s, peer=%d%s\n", pfrom->cleanSubVer, pfrom->nVersion, pfrom->nStartingHeight, addrMe.ToString(), pfrom->id, remoteAddr); - + int64_t nTimeOffset = nTime - GetTime(); pfrom->nTimeOffset = nTimeOffset; AddTimeData(pfrom->addr, nTimeOffset); } - - + + else if (pfrom->nVersion == 0) { // Must have a version message before anything else Misbehaving(pfrom->GetId(), 1); return false; } - - + + else if (strCommand == "verack") { pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); - + // Mark this node as currently connected, so we update its timestamp later. if (pfrom->fNetworkNode) { LOCK(cs_main); State(pfrom->GetId())->fCurrentlyConnected = true; } } - - + + // Disconnect existing peer connection when: // 1. The version message has been received // 2. Overwinter is active @@ -6176,13 +6176,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->fDisconnect = true; return false; } - - + + else if (strCommand == "addr") { vector vAddr; vRecv >> vAddr; - + // Don't want addr from older versions unless seeding if (pfrom->nVersion < CADDR_TIME_VERSION && addrman.size() > 1000) return true; @@ -6191,7 +6191,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 20); return error("message addr size() = %u", vAddr.size()); } - + // Store the new addresses vector vAddrOk; int64_t nNow = GetAdjustedTime(); @@ -6199,7 +6199,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, BOOST_FOREACH(CAddress& addr, vAddr) { boost::this_thread::interruption_point(); - + if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60) addr.nTime = nNow - 5 * 24 * 60 * 60; pfrom->AddAddressKnown(addr); @@ -6243,8 +6243,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pfrom->fOneShot) pfrom->fDisconnect = true; } - - + + else if (strCommand == "inv") { vector vInv; @@ -6254,24 +6254,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 20); return error("message inv size() = %u", vInv.size()); } - + LOCK(cs_main); - + std::vector vToFetch; - + for (unsigned int nInv = 0; nInv < vInv.size(); nInv++) { const CInv &inv = vInv[nInv]; - + boost::this_thread::interruption_point(); pfrom->AddInventoryKnown(inv); - + bool fAlreadyHave = AlreadyHave(inv); LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); - + if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK) pfrom->AskFor(inv); - + if (inv.type == MSG_BLOCK) { UpdateBlockAvailability(pfrom->GetId(), inv.hash); if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { @@ -6295,21 +6295,21 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); } } - + // Track requests for our stuff GetMainSignals().Inventory(inv.hash); - + if (pfrom->nSendSize > (SendBufferSize() * 2)) { Misbehaving(pfrom->GetId(), 50); return error("send buffer size() = %u", pfrom->nSendSize); } } - + if (!vToFetch.empty()) pfrom->PushMessage("getdata", vToFetch); } - - + + else if (strCommand == "getdata") { vector vInv; @@ -6319,29 +6319,29 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 20); return error("message getdata size() = %u", vInv.size()); } - + if (fDebug || (vInv.size() != 1)) LogPrint("net", "received getdata (%u invsz) peer=%d\n", vInv.size(), pfrom->id); - + if ((fDebug && vInv.size() > 0) || (vInv.size() == 1)) LogPrint("net", "received getdata for: %s peer=%d\n", vInv[0].ToString(), pfrom->id); - + pfrom->vRecvGetData.insert(pfrom->vRecvGetData.end(), vInv.begin(), vInv.end()); ProcessGetData(pfrom); } - - + + else if (strCommand == "getblocks") { CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; - + LOCK(cs_main); - + // Find the last block the caller has in the main chain CBlockIndex* pindex = FindForkInGlobalIndex(chainActive, locator); - + // Send the rest of the chain if (pindex) pindex = chainActive.Next(pindex); @@ -6365,19 +6365,19 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } } } - - + + else if (strCommand == "getheaders") { CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; - + LOCK(cs_main); - + if (IsInitialBlockDownload()) return true; - + CBlockIndex* pindex = NULL; if (locator.IsNull()) { @@ -6394,7 +6394,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pindex) pindex = chainActive.Next(pindex); } - + // we must use CBlocks, as CBlockHeaders won't include the 0x00 nTx count at the end vector vHeaders; int nLimit = MAX_HEADERS_RESULTS; @@ -6417,37 +6417,37 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, fprintf(stderr,"you can ignore redundant getheaders from peer.%d %d prev.%d\n",(int32_t)pfrom->id,(int32_t)(pindex ? pindex->nHeight : -1),pfrom->lasthdrsreq); }*/ } - - + + else if (strCommand == "tx") { vector vWorkQueue; vector vEraseQueue; CTransaction tx; vRecv >> tx; - + CInv inv(MSG_TX, tx.GetHash()); pfrom->AddInventoryKnown(inv); - + LOCK(cs_main); - + bool fMissingInputs = false; CValidationState state; - + pfrom->setAskFor.erase(inv.hash); mapAlreadyAskedFor.erase(inv); - + if (!AlreadyHave(inv) && AcceptToMemoryPool(mempool, state, tx, true, &fMissingInputs)) { mempool.check(pcoinsTip); RelayTransaction(tx); vWorkQueue.push_back(inv.hash); - + LogPrint("mempool", "AcceptToMemoryPool: peer=%d %s: accepted %s (poolsz %u)\n", pfrom->id, pfrom->cleanSubVer, tx.GetHash().ToString(), mempool.mapTx.size()); - + // Recursively process any orphan transactions that depended on this one set setMisbehaving; for (unsigned int i = 0; i < vWorkQueue.size(); i++) @@ -6467,8 +6467,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // resolution (that is, feeding people an invalid transaction based on LegitTxX in order to get // anyone relaying LegitTxX banned) CValidationState stateDummy; - - + + if (setMisbehaving.count(fromPeer)) continue; if (AcceptToMemoryPool(mempool, stateDummy, orphanTx, true, &fMissingInputs2)) @@ -6498,7 +6498,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, mempool.check(pcoinsTip); } } - + BOOST_FOREACH(uint256 hash, vEraseQueue) EraseOrphanTx(hash); } @@ -6506,7 +6506,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (fMissingInputs && tx.vjoinsplit.size() == 0) { AddOrphanTx(tx, pfrom->GetId()); - + // DoS prevention: do not allow mapOrphanTransactions to grow unbounded unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS)); unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx); @@ -6515,7 +6515,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } else { assert(recentRejects); recentRejects->insert(tx.GetHash()); - + if (pfrom->fWhitelisted) { // Always relay transactions received from whitelisted peers, even // if they were already in the mempool or rejected from it due @@ -6547,12 +6547,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), nDoS); } } - - + + else if (strCommand == "headers" && !fImporting && !fReindex) // Ignore headers received while importing { std::vector headers; - + // Bypass the normal CBlock deserialization, as we don't want to risk deserializing 2000 full blocks. unsigned int nCount = ReadCompactSize(vRecv); if (nCount > MAX_HEADERS_RESULTS) { @@ -6564,14 +6564,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, vRecv >> headers[n]; ReadCompactSize(vRecv); // ignore tx count; assume it is 0. } - + LOCK(cs_main); - + if (nCount == 0) { // Nothing interesting. Stop asking this peers for more headers. return true; } - + CBlockIndex *pindexLast = NULL; BOOST_FOREACH(const CBlockHeader& header, headers) { CValidationState state; @@ -6590,10 +6590,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } } } - + if (pindexLast) UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash()); - + if (nCount == MAX_HEADERS_RESULTS && pindexLast) { // Headers message had its maximum size; the peer may have more headers. // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue @@ -6605,20 +6605,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->PushMessage("getheaders", chainActive.GetLocator(pindexLast), uint256()); } } - + CheckBlockIndex(); } - + else if (strCommand == "block" && !fImporting && !fReindex) // Ignore blocks received while importing { CBlock block; vRecv >> block; - + CInv inv(MSG_BLOCK, block.GetHash()); LogPrint("net", "received block %s peer=%d\n", inv.hash.ToString(), pfrom->id); - + pfrom->AddInventoryKnown(inv); - + CValidationState state; // Process all blocks from whitelisted peers, even if not requested, // unless we're still syncing with the network. @@ -6635,10 +6635,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), nDoS); } } - + } - - + + // This asymmetric behavior for inbound and outbound connections was introduced // to prevent a fingerprinting attack: an attacker can send specific fake addresses // to users' AddrMan and later request them by sending getaddr messages. @@ -6653,18 +6653,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return true; } pfrom->fSentAddr = true; - + pfrom->vAddrToSend.clear(); vector vAddr = addrman.GetAddr(); BOOST_FOREACH(const CAddress &addr, vAddr) pfrom->PushAddress(addr); } - - + + else if (strCommand == "mempool") { LOCK2(cs_main, pfrom->cs_filter); - + std::vector vtxid; mempool.queryHashes(vtxid); vector vInv; @@ -6684,8 +6684,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (vInv.size() > 0) pfrom->PushMessage("inv", vInv); } - - + + else if (strCommand == "ping") { if (pfrom->nVersion > BIP0031_VERSION) @@ -6706,8 +6706,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->PushMessage("pong", nonce); } } - - + + else if (strCommand == "pong") { int64_t pingUsecEnd = nTimeReceived; @@ -6715,10 +6715,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, size_t nAvail = vRecv.in_avail(); bool bPingFinished = false; std::string sProblem; - + if (nAvail >= sizeof(nonce)) { vRecv >> nonce; - + // Only process pong message if there is an outstanding ping (old ping without nonce should never pong) if (pfrom->nPingNonceSent != 0) { if (nonce == pfrom->nPingNonceSent) { @@ -6750,7 +6750,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, bPingFinished = true; sProblem = "Short payload"; } - + if (!(sProblem.empty())) { LogPrint("net", "pong peer=%d %s: %s, %x expected, %x received, %u bytes\n", pfrom->id, @@ -6764,13 +6764,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->nPingNonceSent = 0; } } - - + + else if (fAlerts && strCommand == "alert") { CAlert alert; vRecv >> alert; - + uint256 alertHash = alert.GetHash(); if (pfrom->setKnown.count(alertHash) == 0) { @@ -6795,13 +6795,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } } } - - + + else if (strCommand == "filterload") { CBloomFilter filter; vRecv >> filter; - + if (!filter.IsWithinSizeConstraints()) // There is no excuse for sending a too-large filter Misbehaving(pfrom->GetId(), 100); @@ -6814,13 +6814,13 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } pfrom->fRelayTxes = true; } - - + + else if (strCommand == "filteradd") { vector vData; vRecv >> vData; - + // Nodes must NEVER send a data item > 520 bytes (the max size for a script data object, // and thus, the maximum size any matched object can have) in a filteradd message if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) @@ -6834,8 +6834,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 100); } } - - + + else if (strCommand == "filterclear") { LOCK(pfrom->cs_filter); @@ -6843,18 +6843,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, pfrom->pfilter = new CBloomFilter(); pfrom->fRelayTxes = true; } - - + + else if (strCommand == "reject") { if (fDebug) { try { string strMsg; unsigned char ccode; string strReason; vRecv >> LIMITED_STRING(strMsg, CMessageHeader::COMMAND_SIZE) >> ccode >> LIMITED_STRING(strReason, MAX_REJECT_MESSAGE_LENGTH); - + ostringstream ss; ss << strMsg << " code " << itostr(ccode) << ": " << strReason; - + if (strMsg == "block" || strMsg == "tx") { uint256 hash; @@ -6872,14 +6872,14 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // We do not care about the NOTFOUND message, but logging an Unknown Command // message would be undesirable as we transmit it ourselves. } - + else { // Ignore unknown commands for extensibility LogPrint("net", "Unknown command \"%s\" from peer=%d\n", SanitizeString(strCommand), pfrom->id); } - - - + + + return true; } @@ -6888,7 +6888,7 @@ bool ProcessMessages(CNode* pfrom) { //if (fDebug) // LogPrintf("%s(%u messages)\n", __func__, pfrom->vRecvMsg.size()); - + // // Message format // (4) message start @@ -6898,41 +6898,41 @@ bool ProcessMessages(CNode* pfrom) // (x) data // bool fOk = true; - + if (!pfrom->vRecvGetData.empty()) ProcessGetData(pfrom); - + // this maintains the order of responses if (!pfrom->vRecvGetData.empty()) return fOk; - + std::deque::iterator it = pfrom->vRecvMsg.begin(); while (!pfrom->fDisconnect && it != pfrom->vRecvMsg.end()) { // Don't bother if send buffer is too full to respond anyway if (pfrom->nSendSize >= SendBufferSize()) break; - + // get next message CNetMessage& msg = *it; - + //if (fDebug) // LogPrintf("%s(message %u msgsz, %u bytes, complete:%s)\n", __func__, // msg.hdr.nMessageSize, msg.vRecv.size(), // msg.complete() ? "Y" : "N"); - + // end, if an incomplete message is found if (!msg.complete()) break; - + // at this point, any failure means we can delete the current message it++; - + // Scan for message start if (memcmp(msg.hdr.pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE) != 0) { LogPrintf("PROCESSMESSAGE: INVALID MESSAGESTART %s peer=%d\n", SanitizeString(msg.hdr.GetCommand()), pfrom->id); fOk = false; break; } - + // Read header CMessageHeader& hdr = msg.hdr; if (!hdr.IsValid(Params().MessageStart())) @@ -6941,10 +6941,10 @@ bool ProcessMessages(CNode* pfrom) continue; } string strCommand = hdr.GetCommand(); - + // Message size unsigned int nMessageSize = hdr.nMessageSize; - + // Checksum CDataStream& vRecv = msg.vRecv; uint256 hash = Hash(vRecv.begin(), vRecv.begin() + nMessageSize); @@ -6955,7 +6955,7 @@ bool ProcessMessages(CNode* pfrom) SanitizeString(strCommand), nMessageSize, nChecksum, hdr.nChecksum); continue; } - + // Process message bool fRet = false; try @@ -6989,17 +6989,17 @@ bool ProcessMessages(CNode* pfrom) } catch (...) { PrintExceptionContinue(NULL, "ProcessMessages()"); } - + if (!fRet) LogPrintf("%s(%s, %u bytes) FAILED peer=%d\n", __func__, SanitizeString(strCommand), nMessageSize, pfrom->id); - + break; } - + // In case the connection got shut down, its receive buffer was wiped if (!pfrom->fDisconnect) pfrom->vRecvMsg.erase(pfrom->vRecvMsg.begin(), it); - + return fOk; } @@ -7011,7 +7011,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Don't send anything until we get its version message if (pto->nVersion == 0) return true; - + // // Message: ping // @@ -7040,11 +7040,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->PushMessage("ping"); } } - + TRY_LOCK(cs_main, lockMain); // Acquire cs_main for IsInitialBlockDownload() and CNodeState() if (!lockMain) return true; - + // Address refresh broadcast static int64_t nLastRebroadcast; if (!IsInitialBlockDownload() && (GetTime() - nLastRebroadcast > 24 * 60 * 60)) @@ -7055,14 +7055,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle) // Periodically clear addrKnown to allow refresh broadcasts if (nLastRebroadcast) pnode->addrKnown.reset(); - + // Rebroadcast our address AdvertizeLocal(pnode); } if (!vNodes.empty()) nLastRebroadcast = GetTime(); } - + // // Message: addr // @@ -7088,7 +7088,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!vAddr.empty()) pto->PushMessage("addr", vAddr); } - + CNodeState &state = *State(pto->GetId()); if (state.fShouldBan) { if (pto->fWhitelisted) @@ -7104,11 +7104,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } state.fShouldBan = false; } - + BOOST_FOREACH(const CBlockReject& reject, state.rejects) pto->PushMessage("reject", (string)"block", reject.chRejectCode, reject.strRejectReason, reject.hashBlock); state.rejects.clear(); - + // Start block sync if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); @@ -7123,7 +7123,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } } - + // Resend wallet transactions that haven't gotten in a block yet // Except during reindex, importing and IBD, when old wallet // transactions become unconfirmed and spams other nodes. @@ -7131,7 +7131,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) { GetMainSignals().Broadcast(nTimeBestReceived); } - + // // Message: inventory // @@ -7145,7 +7145,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) { if (pto->setInventoryKnown.count(inv)) continue; - + // trickle out tx inv to protect privacy if (inv.type == MSG_TX && !fSendTrickle) { @@ -7156,14 +7156,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle) uint256 hashRand = ArithToUint256(UintToArith256(inv.hash) ^ UintToArith256(hashSalt)); hashRand = Hash(BEGIN(hashRand), END(hashRand)); bool fTrickleWait = ((UintToArith256(hashRand) & 3) != 0); - + if (fTrickleWait) { vInvWait.push_back(inv); continue; } } - + // returns true if wasn't already contained in the set if (pto->setInventoryKnown.insert(inv).second) { @@ -7179,7 +7179,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } if (!vInv.empty()) pto->PushMessage("inv", vInv); - + // Detect whether we're stalling int64_t nNow = GetTimeMicros(); if (!pto->fDisconnect && state.nStallingSince && state.nStallingSince < nNow - 1000000 * BLOCK_STALLING_TIMEOUT) { @@ -7211,7 +7211,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pto->fDisconnect = true; } } - + // // Message: getdata (blocks) // @@ -7248,7 +7248,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) komodo_requestedcount = 0; } }*/ - + // // Message: getdata (non-blocks) // @@ -7273,7 +7273,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } if (!vGetData.empty()) pto->PushMessage("getdata", vGetData); - + } return true; } @@ -7294,7 +7294,7 @@ public: for (; it1 != mapBlockIndex.end(); it1++) delete (*it1).second; mapBlockIndex.clear(); - + // orphan transactions mapOrphanTransactions.clear(); mapOrphanTransactionsByPrev.clear(); @@ -7311,14 +7311,14 @@ extern "C" const char* getDataDir() CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight) { CMutableTransaction mtx; - + bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER); if (isOverwintered) { mtx.fOverwintered = true; mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID; mtx.nVersion = 3; // Expiry height is not set. Only fields required for a parser to treat as a valid Overwinter V3 tx. - + // TODO: In future, when moving from Overwinter to Sapling, it will be useful // to set the expiry height to: min(activation_height - 1, default_expiry_height) } From 3f069630787f6eeec573c5b1012617732ca5fdb3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:12:36 +0800 Subject: [PATCH 236/749] try --- src/cc/dice.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index baaedd90a..61aa47708 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -547,8 +547,10 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - else if ( eval->GetTxConfirmed(tx.vin[1].prevout.hash,vinTx,block) == 0 ) - return eval->Invalid("always should find vin.0, but didnt for wlt"); + else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { + if (hashBlock.IsNull() || !GetBlock(hashBlock, block)) + return eval->Invalid("always should find vin.0, but didnt for wlt"); + } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) From 6046afc2eb4c647711bc24ab53201e2283a48306 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:15:16 +0800 Subject: [PATCH 237/749] ry --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 61aa47708..96cce3f90 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -14,6 +14,7 @@ ******************************************************************************/ #include "CCdice.h" +bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const // timeout From d23a74de923424bfa1b921648ee586fb2bcdb2e8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:16:14 +0800 Subject: [PATCH 238/749] lol --- 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 96cce3f90..86d62ba61 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -14,7 +14,7 @@ ******************************************************************************/ #include "CCdice.h" -bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const +bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const; // timeout From b2ec72ec8940989afdb86bbbb83344836acbf671 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:19:22 +0800 Subject: [PATCH 239/749] try --- 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 86d62ba61..5c3d0ef99 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -14,7 +14,7 @@ ******************************************************************************/ #include "CCdice.h" -bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx) const; +bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx); // timeout From 474065ed9903a09d3ff30c08ca9a7581826f6ccb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:21:34 +0800 Subject: [PATCH 240/749] wtf --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5c3d0ef99..98df4bf0d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -14,7 +14,6 @@ ******************************************************************************/ #include "CCdice.h" -bool Eval::GetBlock(uint256 hash, CBlockIndex& blockIdx); // timeout @@ -549,7 +548,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - if (hashBlock.IsNull() || !GetBlock(hashBlock, block)) + if (hashBlock.IsNull() || !Eval::GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From 79a61099715bd73e32c4f8570a3b38958fd13405 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:23:27 +0800 Subject: [PATCH 241/749] fix? --- src/cc/dice.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 98df4bf0d..2c433d1ae 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -440,6 +440,17 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } +bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const +{ + auto r = mapBlockIndex.find(hash); + if (r != mapBlockIndex.end()) { + blockIdx = *r->second; + return true; + } + fprintf(stderr, "CC Eval Error: Can't get block from index\n"); + return false; +} + bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; @@ -548,7 +559,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - if (hashBlock.IsNull() || !Eval::GetBlock(hashBlock, block)) + if (hashBlock.IsNull() || !GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From b5e3297073188573d8cfe902d43f83ccc3c1141c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:24:22 +0800 Subject: [PATCH 242/749] fix --- 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 2c433d1ae..b13700db4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -440,7 +440,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } -bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const +bool GetBlock(uint256 hash, CBlockIndex& blockIdx) { auto r = mapBlockIndex.find(hash); if (r != mapBlockIndex.end()) { From 877360794b5672f1f8addb96860fbfb068f0580b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 12:36:39 +0800 Subject: [PATCH 243/749] fix? --- 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 b13700db4..03da81269 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -971,7 +971,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet int32_t entropytxs; if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) { - if ( entropytxs < 10 ) { + if ( entropytxs < 2 ) { CCerror = "Your dealer is broke, find a new casino."; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); From b30cf0e25ed3924e73cc8078e36f0bb50665ee0d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 13:30:02 +0800 Subject: [PATCH 244/749] try --- src/cc/dice.cpp | 5 +++-- src/wallet/rpcwallet.cpp | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 03da81269..92cbed9db 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -945,7 +945,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 return(""); } -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, char *error) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) @@ -974,6 +974,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( entropytxs < 2 ) { CCerror = "Your dealer is broke, find a new casino."; fprintf(stderr,"%s\n", CCerror.c_str() ); + error = CCerror.c_str(); return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) @@ -990,7 +991,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); - } else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN); + } else CCerror = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; } if ( entropyval == 0 && funding != 0 ) CCerror = "cant find dice entropy inputs"; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1d9650221..19a14efdb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4541,7 +4541,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); if (!EnsureWalletIsAvailable(0)) return 0; - + const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4704,7 +4704,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; if (!EnsureWalletIsAvailable(0)) return 0; - + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -6135,7 +6135,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) UniValue dicebet(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name; + UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name, *error; if ( fHelp || params.size() != 4 ) throw runtime_error("dicebet name fundingtxid amount odds\n"); if ( ensure_CCrequirements() < 0 ) @@ -6157,7 +6157,9 @@ UniValue dicebet(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create dice bet transaction. make sure your address has funds"); + } else if ( error[0] != 0 ) { + ERR_RESULT(error); + } } else { ERR_RESULT("amount and odds must be positive"); } @@ -6678,7 +6680,7 @@ UniValue getbalance64(const UniValue& params, bool fHelp) UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address; if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + const CKeyStore& keystore = *pwalletMain; CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid; assert(pwalletMain != NULL); From 5c9845bb0f1eaf1cd57e65bb90f49f37147df73d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 13:32:19 +0800 Subject: [PATCH 245/749] fix --- src/cc/dice.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 92cbed9db..cdd8b6d70 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,7 +974,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( entropytxs < 2 ) { CCerror = "Your dealer is broke, find a new casino."; fprintf(stderr,"%s\n", CCerror.c_str() ); - error = CCerror.c_str(); + error = (char *)CCerror.c_str(); return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 19a14efdb..d8848b681 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6152,7 +6152,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) return(result); } if (amount > 0 && odds > 0) { - hex = DiceBet(0,name,fundingtxid,amount,odds); + hex = DiceBet(0,name,fundingtxid,amount,odds,error); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From e1ae559a777169e57a808b9ae1498b3e3e878f44 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 13:35:33 +0800 Subject: [PATCH 246/749] fix --- src/cc/CCdice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 16b2f6136..5b809ccf2 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -23,7 +23,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,char *error); std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); From beb8b742bebf00ca9a2dad96f201494d6d78242b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 13:42:11 +0800 Subject: [PATCH 247/749] fix --- 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 cdd8b6d70..92cbed9db 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,7 +974,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( entropytxs < 2 ) { CCerror = "Your dealer is broke, find a new casino."; fprintf(stderr,"%s\n", CCerror.c_str() ); - error = (char *)CCerror.c_str(); + error = CCerror.c_str(); return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) From aa45c19c973c8c84991a87e59ed69cc95c0671b2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 13:49:52 +0800 Subject: [PATCH 248/749] try --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d8848b681..e3a84395d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6158,6 +6158,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else if ( error[0] != 0 ) { + fprintf(stderr, "%s\n",error ); ERR_RESULT(error); } } else { From 5d90ceb45ca1c02e040cc7797463d6d06d30817e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 13:52:04 +0800 Subject: [PATCH 249/749] fix? --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 5b809ccf2..e84252201 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -23,7 +23,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,char *error); +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,const char *error); std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 92cbed9db..6c5485e1c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -945,7 +945,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 return(""); } -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, char *error) +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, const char *error) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) From 5e25d091e2c5eb1d76c24be696be24dff6f15791 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 14:09:19 +0800 Subject: [PATCH 250/749] try --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index e84252201..d9db490c3 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -23,7 +23,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,const char *error); +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6c5485e1c..7e0946d72 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -945,7 +945,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 return(""); } -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, const char *error) +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, std::string &error) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) @@ -974,7 +974,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( entropytxs < 2 ) { CCerror = "Your dealer is broke, find a new casino."; fprintf(stderr,"%s\n", CCerror.c_str() ); - error = CCerror.c_str(); + error = CCerror; return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e3a84395d..238ddb7d3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6135,7 +6135,7 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) UniValue dicebet(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name, *error; + UniValue result(UniValue::VOBJ); std::string hex,error; uint256 fundingtxid; int64_t amount,odds; char *name; if ( fHelp || params.size() != 4 ) throw runtime_error("dicebet name fundingtxid amount odds\n"); if ( ensure_CCrequirements() < 0 ) @@ -6158,7 +6158,6 @@ UniValue dicebet(const UniValue& params, bool fHelp) result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else if ( error[0] != 0 ) { - fprintf(stderr, "%s\n",error ); ERR_RESULT(error); } } else { From d48df7dc33ce48a09661ccb81e86914a55a5ab3a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 14:30:55 +0800 Subject: [PATCH 251/749] return json to dicestatus --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 34 ++++++++++++---------------------- src/wallet/rpcwallet.cpp | 10 +++++----- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index d9db490c3..a01ddd295 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -25,7 +25,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); -double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7e0946d72..3a2d3129c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -950,37 +950,31 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) { - CCerror = "bet must be positive"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + error = "bet must be positive"; return(""); } if ( odds < 1 || odds > 9999 ) { - CCerror = "odds must be between 1 and 9999"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + error = "odds must be between 1 and 9999"; return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); if ( bet < minbet || bet > maxbet || odds > maxodds ) { - CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); - fprintf(stderr,"%s\n", CCerror.c_str() ); + error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } int32_t entropytxs; if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) { if ( entropytxs < 2 ) { - CCerror = "Your dealer is broke, find a new casino."; - fprintf(stderr,"%s\n", CCerror.c_str() ); - error = CCerror; + error = "Your dealer is broke, find a new casino."; return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { - CCerror = "entropy txid is spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + error = "entropy txid is spent"; return(""); } mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); @@ -991,13 +985,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); - } else CCerror = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; + } else error = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; } if ( entropyval == 0 && funding != 0 ) - CCerror = "cant find dice entropy inputs"; + error = "cant find dice entropy inputs"; else - CCerror = "cant find dice input"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + error = "cant find dice input"; return(""); } @@ -1116,13 +1109,12 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 return(""); } -double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - CCerror = "Diceinit error in status"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + error = "Diceinit error in status"; return(0.); } fundingpk = DiceFundingPk(fundingPubKey); @@ -1173,8 +1165,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(0.); else return((double)spenttx.vout[2].nValue/COIN); } - CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); - fprintf(stderr,"%s\n", CCerror.c_str()); + error = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); return(-1.); } else if ( scriptPubKey == fundingPubKey ) @@ -1194,8 +1185,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); } - CCerror = "didnt find dicefinish tx"; - fprintf(stderr,"%s\n", CCerror.c_str()); + error = "didnt find dicefinish tx"; } return(-1.); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 238ddb7d3..6469b3e43 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6196,7 +6196,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) UniValue dicestatus(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status; double winnings; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status,error; double winnings; if ( fHelp || (params.size() != 2 && params.size() != 3) ) throw runtime_error("dicestatus name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -6212,10 +6212,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp) memset(&bettxid,0,sizeof(bettxid)); if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); - winnings = DiceStatus(0,name,fundingtxid,bettxid); - if (CCerror != "") { - ERR_RESULT(CCerror); - return result; + winnings = DiceStatus(0,name,fundingtxid,bettxid,error); + if ( error[0] != 0 ) { + ERR_RESULT(error); + return(result); } result.push_back(Pair("result", "success")); if ( winnings >= 0. ) From 11e854b9247119032e1a45740e712514abd5d17e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 27 Oct 2018 21:15:31 -1100 Subject: [PATCH 252/749] Handle 10 simul dice bet spammers --- 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 3a2d3129c..5d1620edf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -968,7 +968,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet int32_t entropytxs; if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) { - if ( entropytxs < 2 ) { + if ( entropytxs < 10 ) { error = "Your dealer is broke, find a new casino."; return(""); } From e09099a178423db57d936a6fbd02cf862b1c97ba Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 16:26:56 +0800 Subject: [PATCH 253/749] fix dice status error message after mempool entopy is invalidated --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3a2d3129c..d1b207ce0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1104,9 +1104,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } } *resultp = -1; - CCerror = "couldnt find bettx or entropytx"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); + return("couldnt find bettx or entropytx"); } double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) @@ -1137,6 +1135,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySendrawtransaction(res); n++; + } else + { + error = res; } } } From b19a3d5217f4f7e823732ee3f9019e2e4ca5dba2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 19:11:23 +0800 Subject: [PATCH 254/749] try --- src/cc/dice.cpp | 17 ++--------------- src/cc/eval.cpp | 13 +++++++++++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d1b207ce0..d914be251 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -440,17 +440,6 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) return(numblocks >= timeoutblocks); } -bool GetBlock(uint256 hash, CBlockIndex& blockIdx) -{ - auto r = mapBlockIndex.find(hash); - if (r != mapBlockIndex.end()) { - blockIdx = *r->second; - return true; - } - fprintf(stderr, "CC Eval Error: Can't get block from index\n"); - return false; -} - bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; @@ -558,10 +547,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - if (hashBlock.IsNull() || !GetBlock(hashBlock, block)) + else if ( eval->GetTxConfirmedDICE(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt for wlt"); - } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) @@ -968,7 +955,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet int32_t entropytxs; if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) { - if ( entropytxs < 2 ) { + if ( entropytxs < 10 ) { error = "Your dealer is broke, find a new casino."; return(""); } diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index b6fcf57dd..b2bc80d9e 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -76,11 +76,11 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) case EVAL_IMPORTPAYOUT: return ImportPayout(vparams, txTo, nIn); break; - + case EVAL_IMPORTCOIN: return ImportCoin(vparams, txTo, nIn); break; - + default: return(ProcessCC(cp,this, vparams, txTo, nIn)); break; @@ -115,6 +115,15 @@ bool Eval::GetTxConfirmed(const uint256 &hash, CTransaction &txOut, CBlockIndex return true; } +bool Eval::GetTxConfirmedDICE(const uint256 &hash, CTransaction &txOut,uint256 &hashBlock) const +{ + CBlockIndex block; + if (!GetTxUnconfirmed(hash, txOut, hashBlock)) + return false; + if (hashBlock.IsNull() || !GetBlock(hashBlock, block)) + return false; + return true; +} unsigned int Eval::GetCurrentHeight() const { From cf4ddfaf5d513e016b801745f282ae03987984a2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 19:18:07 +0800 Subject: [PATCH 255/749] try --- src/cc/dice.cpp | 4 +++- src/cc/eval.cpp | 10 ---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d914be251..0ec2d1043 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -547,8 +547,10 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - else if ( eval->GetTxConfirmedDICE(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) + else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { + if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); + } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index b2bc80d9e..113c4a6e8 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -115,16 +115,6 @@ bool Eval::GetTxConfirmed(const uint256 &hash, CTransaction &txOut, CBlockIndex return true; } -bool Eval::GetTxConfirmedDICE(const uint256 &hash, CTransaction &txOut,uint256 &hashBlock) const -{ - CBlockIndex block; - if (!GetTxUnconfirmed(hash, txOut, hashBlock)) - return false; - if (hashBlock.IsNull() || !GetBlock(hashBlock, block)) - return false; - return true; -} - unsigned int Eval::GetCurrentHeight() const { return chainActive.Height(); From 0f2c1a42606c08cd44782e93820ed6b61c569d1f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 19:24:14 +0800 Subject: [PATCH 256/749] fix --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0ec2d1043..7961d3809 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -547,6 +547,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); + CBlockIndex block; else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); From 5096e57c8017f7d1d642ba88877b434caa68a337 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 19:28:58 +0800 Subject: [PATCH 257/749] fix --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7961d3809..1e99ece58 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -547,9 +547,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - CBlockIndex block; else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) + CBlockIndex block; + if (hashBlock.IsNull() || eval->!GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From 54ffcaee4656f0d99ba0cde94c47dd40822c7caf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 28 Oct 2018 19:31:18 +0800 Subject: [PATCH 258/749] fix --- 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 1e99ece58..48413005f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -549,7 +549,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { CBlockIndex block; - if (hashBlock.IsNull() || eval->!GetBlock(hashBlock, block)) + if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From 69339af2368f2fe2de8aa0bfac1f35ed13773bc5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:00:11 +0800 Subject: [PATCH 259/749] fix --- src/cc/dice.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 48413005f..4de099ab4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -659,9 +659,9 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { - char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; @@ -674,6 +674,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropyval = 0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { + if (random) { + if ( (rand() % 100) < 90 ) + continue; + } txid = it->first.txhash; vout = (int32_t)it->first.index; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) @@ -735,7 +739,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } else fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case funcid (%c) %d %s vs %s\n",funcid,funcid,uint256_str(str,reffundingtxid),uint256_str(str2,fundingtxid)); } //else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); - } + } i = i + 1; } fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN); entropytxs = n; @@ -832,7 +836,7 @@ UniValue DiceInfo(uint256 diceid) cp = CCinit(&C,EVAL_DICE); dicepk = GetUnspendable(cp,0); int32_t entropytxs; - funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid,entropytxs); + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,diceid,entropytxs,false); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); result.push_back(Pair("entropytxs",entropytxs)); @@ -955,10 +959,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } - int32_t entropytxs; - if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs)) >= 2*bet*odds+txfee && entropyval != 0 ) + int32_t entropytxs=0,emptyva=0; + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false)); + DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true)); + if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) { - if ( entropytxs < 10 ) { + if ( entropytxs < 100 ) { error = "Your dealer is broke, find a new casino."; return(""); } From 31ea0b1abbbc31c72bff2dd03250f416992bc9a9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:02:12 +0800 Subject: [PATCH 260/749] lel --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4de099ab4..d60fc3ba4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -960,8 +960,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyva=0; - funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false)); - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true)); + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) { if ( entropytxs < 100 ) { From 58302a3d409751d6a01d0c12bd618e8a31807c50 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:04:14 +0800 Subject: [PATCH 261/749] fix --- 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 d60fc3ba4..b8b2791ff 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -959,7 +959,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } - int32_t entropytxs=0,emptyva=0; + int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) From 5d7c92006eb5ccedcdfa5100c9d500dd49cebd67 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:05:19 +0800 Subject: [PATCH 262/749] lol --- 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 b8b2791ff..3da482e1b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -962,7 +962,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) + if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { error = "Your dealer is broke, find a new casino."; From dcc207075f7b37d23b40d633f3fa780ae2058c74 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:12:46 +0800 Subject: [PATCH 263/749] fix! --- src/cc/dice.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3da482e1b..d4777e5ca 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -741,9 +741,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } //else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); } i = i + 1; } - fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN); - entropytxs = n; - return(totalinputs); + if (!random) { + fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN); + entropytxs = n; + return(totalinputs); + } else { + return(0); + } } bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) From d7c442f9bb24700e0918aeab8001690aee5392b2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:32:49 +0800 Subject: [PATCH 264/749] try --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 491798a98..8cff5d98c 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -398,7 +398,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid)); return(0); } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight ) + else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime+1 || pindex->nHeight <= txheight ) { fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); return(0); From 0e898d9e5521e3bdedbfa6808e5ee62c70a94065 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:48:44 +0800 Subject: [PATCH 265/749] no? --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 8cff5d98c..491798a98 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -398,7 +398,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid)); return(0); } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime+1 || pindex->nHeight <= txheight ) + else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight ) { fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); return(0); From e65938c35e9557895e799b6275e022bb867a4ddc Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:16:12 +0800 Subject: [PATCH 266/749] fix? --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d4777e5ca..1643d8ad5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,6 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { + printf("%s\n",uint256_str(str,entropy); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From 22a613b99a57a3d9e3bae5c14122232b6ecf7a27 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:19:58 +0800 Subject: [PATCH 267/749] try --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1643d8ad5..3f1b3e903 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,6 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { + char str[65]; printf("%s\n",uint256_str(str,entropy); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); From 0b52093a3be9e0bc41bc1a78ac5b54f8d9c3584d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:21:30 +0800 Subject: [PATCH 268/749] w --- 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 3f1b3e903..2377a2689 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -414,7 +414,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction if ( hentropy == hentropy2 ) { char str[65]; - printf("%s\n",uint256_str(str,entropy); + printf("%s\n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From 7a4eb1733243bc0d702614ae19b53dfd8855b15d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:22:27 +0800 Subject: [PATCH 269/749] w --- 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 2377a2689..2c2525ad8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,7 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - char str[65]; + //char str[65]; printf("%s\n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); From 39dd777cf2ca845eaa2557fe46b52629eaa7f8a6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:27:42 +0800 Subject: [PATCH 270/749] w --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2c2525ad8..fa36051dc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,8 +413,8 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - //char str[65]; - printf("%s\n",uint256_str(str,entropy)); + char *str; + fprintf(stderr, "%s\n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From f3916237387bff9700f4cc1b0d249d4032e06472 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:30:04 +0800 Subject: [PATCH 271/749] w --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fa36051dc..14adc28d6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,8 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - char *str; - fprintf(stderr, "%s\n",uint256_str(str,entropy)); + fprintf(stderr, "%s something \n",uint256_str(str2,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From 15e09a681e96546a1cc73bc9ef652b1de4011001 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:31:15 +0800 Subject: [PATCH 272/749] lel --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 14adc28d6..ef9e9c7ca 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,9 +413,9 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - fprintf(stderr, "%s something \n",uint256_str(str2,entropy)); + fprintf(stderr, "%s something \n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + //har str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { From dc5420fb4b5eba433eb8a359efef2bc37e608f51 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:32:37 +0800 Subject: [PATCH 273/749] a --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef9e9c7ca..109d12ea4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,9 +413,10 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { + char str[65]; fprintf(stderr, "%s something \n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - //har str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { From 1889b058b62ac5e5048bf0cddffb12fb6af836a2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:58:50 +0800 Subject: [PATCH 274/749] w --- 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 109d12ea4..6f8c597f9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -599,11 +599,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } if ( iswin != 0 ) { - //char str[65],str2[65]; + char str[65],str2[65]; entropy = DiceGetEntropy(vinTx,'B'); vcalc_sha256(0,(uint8_t *)&hash,(uint8_t *)&proof,32); - //fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); - //fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); + fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); + fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); winnings = DiceCalc(vinTx.vout[1].nValue,vinTx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,proof,entropy); if ( (winnings == 0 && iswin > 0) || (winnings > 0 && iswin < 0) ) return eval->Invalid("DiceCalc mismatch for win/loss"); From 4b1061a8a284f9c4ef7cebcdba492dc9e35a76d8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 02:49:43 +0800 Subject: [PATCH 275/749] w --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6f8c597f9..971b3bc57 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,6 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + fprintf(stderr, "vout value: %ld txfee: %ld\n", vinTx.vout[2].nValue,txfee); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 030fce32a9401df4bb9dcc6ceba910b14e5c44b8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:00:03 +0800 Subject: [PATCH 276/749] w --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 971b3bc57..868858519 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,8 +578,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "vout value: %ld txfee: %ld\n", vinTx.vout[2].nValue,txfee); - odds = vinTx.vout[2].nValue - txfee; + fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); + //odds = vinTx.vout[2].nValue - txfee; + odds = 1; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) From cee9c7d9cf73755397f0b3ff90eac910a4790a4e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:06:49 +0800 Subject: [PATCH 277/749] w --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 868858519..88b2b65c0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -579,8 +579,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); - //odds = vinTx.vout[2].nValue - txfee; - odds = 1; + odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) From a6a648d1ca3110a0d849269fe56a7cb1025053eb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:21:36 +0800 Subject: [PATCH 278/749] a --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 88b2b65c0..564ac83f4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,6 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + LOCK2(cs_main, pwalletMain->cs_wallet); fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) From 767c232780b2657cfaf765d701ba7a67be1c986f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:28:06 +0800 Subject: [PATCH 279/749] w --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 564ac83f4..702709aa3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,8 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - LOCK2(cs_main, pwalletMain->cs_wallet); - fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); + LOCK2(cs_main); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 36342965cb3e203205d1fc3dd6451630146bc941 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:30:12 +0800 Subject: [PATCH 280/749] w --- 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 702709aa3..b1375f12c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - LOCK2(cs_main); + LOCK(cs_main); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 936e2ff4a5f68dae67c5b67a466099b097ba05b6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:35:30 +0800 Subject: [PATCH 281/749] w --- 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 b1375f12c..6dfe5b1d0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - LOCK(cs_main); + usleep(5000) odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From d3e25cfd6b57e8ffd9e66e07758e6db9eef0cd12 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:36:48 +0800 Subject: [PATCH 282/749] poo --- 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 6dfe5b1d0..298cee932 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - usleep(5000) + usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 1a9784d156e85848cdf69a4ef16302666d8b57c1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 09:49:23 +0800 Subject: [PATCH 283/749] try --- 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 298cee932..790475b66 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -552,7 +552,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { CBlockIndex block; if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid("always should find vin.0, but didnt for wlt"); + return eval->Invalid("always should find vin.0, but didnt for wlt"); + fprintf(stderr, "vout2.nvalue = %d\n", vinTx.vout[2].nValue); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); @@ -578,6 +579,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + fprintf(stderr, "%d\n",txfee); usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) @@ -600,11 +602,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } if ( iswin != 0 ) { - char str[65],str2[65]; + //char str[65],str2[65]; entropy = DiceGetEntropy(vinTx,'B'); vcalc_sha256(0,(uint8_t *)&hash,(uint8_t *)&proof,32); - fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); - fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); + //fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); + //fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); winnings = DiceCalc(vinTx.vout[1].nValue,vinTx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,proof,entropy); if ( (winnings == 0 && iswin > 0) || (winnings > 0 && iswin < 0) ) return eval->Invalid("DiceCalc mismatch for win/loss"); From 21f53468f33c5af5f13a95bc895d26171cbf84b8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 09:51:01 +0800 Subject: [PATCH 284/749] try --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 790475b66..ff6214e6b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -553,7 +553,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) CBlockIndex block; if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); - fprintf(stderr, "vout2.nvalue = %d\n", vinTx.vout[2].nValue); + fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); @@ -579,7 +579,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "%d\n",txfee); + fprintf(stderr, "%ld\n",txfee); usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) From 09d3bd8cb21d66330dc802190458e230348a3d29 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 10:21:51 +0800 Subject: [PATCH 285/749] a --- src/cc/dice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ff6214e6b..66a2c15bf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,9 +551,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { CBlockIndex block; + fprintf(stderr, "Got tx unconfirmed!\n"); if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); - fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); + char str[65]; + fprintf(stderr, "Got tx confirmed in block: %s \n", uint256_str(str,hashBlock)); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); @@ -561,6 +563,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("sbits or fundingtxid mismatch for wlt"); else if ( fundingPubKey != tx.vout[1].scriptPubKey ) return eval->Invalid("tx.vout[1] != fundingPubKey for wlt"); + fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); if ( funcid == 'L' ) { //vout.0: funding CC to entropy owner @@ -579,7 +582,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "%ld\n",txfee); + fprintf(stderr, "tx fee: %ld\n",txfee); usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) From adbb327574ac3ce430a73cfc3865cc318f020ff2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 11:05:58 +0800 Subject: [PATCH 286/749] fix finally --- src/cc/dice.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 66a2c15bf..b4ad2dde7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -544,19 +544,16 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vin.3+: funding CC vout.0 from 'F', 'E', 'W', 'L' or 'T' //vout.1: tag to owner address for entropy funds preventCCvouts = 1; + CBlockIndex block; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - CBlockIndex block; - fprintf(stderr, "Got tx unconfirmed!\n"); - if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid("always should find vin.0, but didnt for wlt"); - char str[65]; - fprintf(stderr, "Got tx confirmed in block: %s \n", uint256_str(str,hashBlock)); - } + return eval->Invalid("always should find vin.0, but didnt for wlt"); + } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) + return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) From 05dc40eb3e9195b6eef83223690828b32cb8bf26 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 11:18:34 +0800 Subject: [PATCH 287/749] remove prints --- src/cc/dice.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b4ad2dde7..05cb306cb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,7 +551,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - return eval->Invalid("always should find vin.0, but didnt for wlt"); + return eval->Invalid("always should find vin.0, but didnt for wlt"); } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -560,7 +560,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("sbits or fundingtxid mismatch for wlt"); else if ( fundingPubKey != tx.vout[1].scriptPubKey ) return eval->Invalid("tx.vout[1] != fundingPubKey for wlt"); - fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); if ( funcid == 'L' ) { //vout.0: funding CC to entropy owner @@ -579,8 +578,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "tx fee: %ld\n",txfee); - usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 2e05c9efce9410113b135f0aace303ecf58c7b94 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 11:55:42 +0800 Subject: [PATCH 288/749] try --- src/cc/dice.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05cb306cb..00888e230 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,7 +551,14 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - return eval->Invalid("always should find vin.0, but didnt for wlt"); + int tries = 0; + while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { + tries++; + sleep(1); + if ( tries > 60 ) { + return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); + } + } } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From e2408f31c351dddc1c2e31c3234d8c9a1a89abea Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:15:12 +0800 Subject: [PATCH 289/749] try --- src/cc/dice.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 00888e230..33efff005 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -745,7 +745,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr," (%c) tx vin.%d fundingPubKey mismatch %s\n",funcid,tx.vin[0].prevout.n,uint256_str(str,tx.vin[0].prevout.hash)); } } - } else fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); + } //else fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case funcid (%c) %d %s vs %s\n",funcid,funcid,uint256_str(str,reffundingtxid),uint256_str(str2,fundingtxid)); } //else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); } i = i + 1; @@ -770,7 +770,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac //fprintf(stderr,"check fundingtxid\n"); if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { - if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) + if ( DecodeiningOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { fundingPubKey = tx.vout[1].scriptPubKey; return(true); @@ -974,7 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + printf("first entropy val found: %ld\n",entropyval,); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + printf("second entropy val found: %ld\n",entropyval,); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From f72bf9aaf08ab9c17ba3e34a51cdf9a27407f9a0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:17:27 +0800 Subject: [PATCH 290/749] fix prints --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 33efff005..92a0a9952 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -698,13 +698,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { - fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); + //fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid != 'F' && funcid != 'T' ) n++; totalinputs += nValue; if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) { - fprintf(stderr,"check first\n"); + //fprintf(stderr,"check first\n"); if ( fundingPubKey == tx.vout[1].scriptPubKey ) { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) From e4737a39b3ae17100b54c61cafd7d71bca0a8663 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:19:10 +0800 Subject: [PATCH 291/749] test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 92a0a9952..2d7055782 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,9 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - printf("first entropy val found: %ld\n",entropyval,); + printf("first entropy val found: %ld\n",entropyval); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - printf("second entropy val found: %ld\n",entropyval,); + printf("second entropy val found: %ld\n",entropyval); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From b8069b78390f085df8adc4a22faf36dc1079eb08 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:22:51 +0800 Subject: [PATCH 292/749] wtf --- 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 2d7055782..9c7bc31b7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -770,7 +770,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac //fprintf(stderr,"check fundingtxid\n"); if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { - if ( DecodeiningOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) + if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { fundingPubKey = tx.vout[1].scriptPubKey; return(true); From 57797961db87b6024decd121e685fdb3eb01af98 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:27:37 +0800 Subject: [PATCH 293/749] try --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9c7bc31b7..1f31ff652 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -973,10 +973,11 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; + char str[65]; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - printf("first entropy val found: %ld\n",entropyval); + printf("first entropy tx found: %s\n",uint256_str(str,entropytxid)); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - printf("second entropy val found: %ld\n",entropyval); + printf("second entropy tx found: %s\n",uint256_str(str,entropytxid)); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From dc4d2cd7c79462bcee6abf3b6d3cbea31a5b25ba Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:38:02 +0800 Subject: [PATCH 294/749] test --- src/cc/dice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1f31ff652..81d9231a1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -681,8 +681,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit GetCCaddress(cp,coinaddr,dicepk); SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; + int loops = 0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { + loops++; if (random) { if ( (rand() % 100) < 90 ) continue; @@ -731,6 +733,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropytxid = txid; entropyval = tx.vout[0].nValue; first = 1; + fprintf(stderr, "chosen entropy on loop: %d\n",loops); } else { From cdd74f5bb3da7450f3f842cd1915fafeb2e87fec Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:44:09 +0800 Subject: [PATCH 295/749] a --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 81d9231a1..9cb1efced 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -682,6 +682,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; + fprintf(stderr, "number of unspents: %ld\n",unspentOutputs.size()); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; From 7600093c2fce0bfc7e1816e1b5ffb3d68954bb8a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:53:03 +0800 Subject: [PATCH 296/749] fix --- src/cc/dice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9cb1efced..ab2a27a34 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -682,13 +682,18 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - fprintf(stderr, "number of unspents: %ld\n",unspentOutputs.size()); + if (random) { + int startfrom = rand()%((unspentOutputs.size()\2)-1 + 1) + 1; + fprintf(stderr, "start from loop: %d\n",startfrom); + } for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; if (random) { + if ( loops < startfrom ) + continue; if ( (rand() % 100) < 90 ) - continue; + continue; } txid = it->first.txhash; vout = (int32_t)it->first.index; From 8b0a16daff2fe2e2c769d78fc300aa6de20e0043 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:54:46 +0800 Subject: [PATCH 297/749] ? --- 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 ab2a27a34..459cd28a1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -683,7 +683,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropyval = 0; int loops = 0; if (random) { - int startfrom = rand()%((unspentOutputs.size()\2)-1 + 1) + 1; + int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; fprintf(stderr, "start from loop: %d\n",startfrom); } for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) From da7291922e02da9b2e8a73485c6154dfa7b2e789 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:56:07 +0800 Subject: [PATCH 298/749] try --- src/cc/dice.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 459cd28a1..2e20139c2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -682,10 +682,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - if (random) { - int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; - fprintf(stderr, "start from loop: %d\n",startfrom); - } + int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; + fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; From 9fc43996cd04e91cb6dee43028da88bdd2bbcd47 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:03:40 +0800 Subject: [PATCH 299/749] fix? --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2e20139c2..3f166eb9f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -555,7 +555,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { tries++; sleep(1); - if ( tries > 60 ) { + char str[65]; + fprintf(stderr, "tx.%s hashBlock.%s\n",uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); + if ( tries > 20 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } } From cf7d67cb53674561898f83e60d3e1428f0e39958 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:28:53 +0800 Subject: [PATCH 300/749] try --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3f166eb9f..b1629b72d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -556,7 +556,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) tries++; sleep(1); char str[65]; - fprintf(stderr, "tx.%s hashBlock.%s\n",uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",txid,uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); if ( tries > 20 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } @@ -684,7 +684,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; + int startfrom = rand()%(unspentOutputs.size()%2); fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 300626dc0c69fc43cadf021d4327e2738c59bc86 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:30:59 +0800 Subject: [PATCH 301/749] fix --- 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 b1629b72d..b39f39dbf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -556,7 +556,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) tries++; sleep(1); char str[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",txid,uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); if ( tries > 20 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } From 4aea265846f80efd11a8fd80586c721613a13836 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:34:27 +0800 Subject: [PATCH 302/749] try --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b39f39dbf..cb6103040 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -684,7 +684,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int startfrom = rand()%(unspentOutputs.size()%2); + int numtxs = unspentOutputs.size()/2; + int startfrom = rand()%numtxs; fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 9f39af9cdd765867cb34fb425950b3a2b1eec07d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 15:40:02 +0800 Subject: [PATCH 303/749] try --- src/cc/CCtx.cpp | 16 +++++++++++++--- src/cc/dice.cpp | 4 ---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index f29fd05e8..d8c0ceb1d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -17,12 +17,12 @@ /* FinalizeCCTx is a very useful function that will properly sign both CC and normal inputs, adds normal change and the opreturn. - + This allows the contract transaction functions to create the appropriate vins and vouts and have FinalizeCCTx create a properly signed transaction. - + By using -addressindex=1, it allows tracking of all the CC addresses */ - + bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { #ifdef ENABLE_WALLET @@ -274,8 +274,18 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; + int loops = 0; + int numtxs = numunspents/2; + int startfrom = rand()%numtxs; for (above=below=i=0; i 300 ) { + if ( loops < startfrom ) + continue; + if ( (rand() % 100) < 75 ) + continue; + } if ( (atx_value= utxos[i].nValue) <= 0 ) continue; if ( atx_value == value ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cb6103040..aecfa17d1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -686,7 +686,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit int loops = 0; int numtxs = unspentOutputs.size()/2; int startfrom = rand()%numtxs; - fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; @@ -983,11 +982,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; - char str[65]; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - printf("first entropy tx found: %s\n",uint256_str(str,entropytxid)); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - printf("second entropy tx found: %s\n",uint256_str(str,entropytxid)); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 44c1c99ffada44345cfd6817abb48ae70254f818 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:01:27 +0800 Subject: [PATCH 304/749] fix --- src/cc/CCtx.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d8c0ceb1d..5c2c42e97 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -274,16 +274,10 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; - int loops = 0; - int numtxs = numunspents/2; - int startfrom = rand()%numtxs; for (above=below=i=0; i 300 ) { - if ( loops < startfrom ) - continue; - if ( (rand() % 100) < 75 ) + if ( numunspents > 150 ) { + if ( (rand() % 100) < 80 ) continue; } if ( (atx_value= utxos[i].nValue) <= 0 ) From e054db050515fa644a0dbc8ed5b44eb4b1758cc7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:15:04 +0800 Subject: [PATCH 305/749] ? --- 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 aecfa17d1..96d372523 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -555,9 +555,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { tries++; sleep(1); - char str[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); - if ( tries > 20 ) { + char str[65],str2[65],str3[65] + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); + if ( tries > 10 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } } From b888ef1af1df13924da3a82cbb6cf9ce03ac4ee6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:16:56 +0800 Subject: [PATCH 306/749] ; --- 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 96d372523..e2c5c2caf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -555,7 +555,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { tries++; sleep(1); - char str[65],str2[65],str3[65] + char str[65],str2[65],str3[65]; fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); if ( tries > 10 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); From 95bb8b29f2be313170525cdeb8d461364b4d5f19 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:30:07 +0800 Subject: [PATCH 307/749] try --- src/cc/dice.cpp | 57 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e2c5c2caf..7566fa2f6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -545,22 +545,18 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.1: tag to owner address for entropy funds preventCCvouts = 1; CBlockIndex block; + int skipped = 0; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - int tries = 0; - while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - tries++; - sleep(1); - char str[65],str2[65],str3[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - if ( tries > 10 ) { - return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); - } - } + char str[65],str2[65],str3[65]; + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); + //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); + skipped = 1; + } } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -584,27 +580,30 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - //vout.0: funding CC change to entropy owner - //vout.2: normal output to bettor's address - //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - odds = vinTx.vout[2].nValue - txfee; - if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) - return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); - else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) - return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); - else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) - return eval->Invalid("vout[2] payut mismatch for win/timeout"); - else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) + if ( skipped == 0) { - fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); - return eval->Invalid("CC funds mismatch for win/timeout"); + //vout.0: funding CC change to entropy owner + //vout.2: normal output to bettor's address + //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + odds = vinTx.vout[2].nValue - txfee; + if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); + else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) + return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); + else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) + return eval->Invalid("vout[2] payut mismatch for win/timeout"); + else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) + { + fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); + return eval->Invalid("CC funds mismatch for win/timeout"); + } + else if ( tx.vout[3].scriptPubKey != fundingPubKey ) + { + if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) + return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); + } + iswin = (funcid == 'W'); } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } - iswin = (funcid == 'W'); } if ( iswin != 0 ) { From be37ffee83dff9c4eef6f1597df1f26ffbd69418 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:32:47 +0800 Subject: [PATCH 308/749] fix --- src/cc/dice.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7566fa2f6..86483d008 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -445,7 +445,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; - CBlockIndex block; + CBlockIndex block; int skipped = 0; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -545,7 +545,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.1: tag to owner address for entropy funds preventCCvouts = 1; CBlockIndex block; - int skipped = 0; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); @@ -556,7 +555,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); skipped = 1; - } } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From 48aa70ceccfd0ae9cef8ded086fdda84ea5c2ee7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 17:16:52 +0800 Subject: [PATCH 309/749] maybe this will works --- src/cc/dice.cpp | 46 +++++++++++++++++++++------------------------- src/cc/eval.cpp | 7 +++---- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 86483d008..b1e369344 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -445,7 +445,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; - CBlockIndex block; int skipped = 0; + CBlockIndex block; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -553,8 +553,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { char str[65],str2[65],str3[65]; fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); - skipped = 1; + return eval->Invalid("always should find looking vin.0, but didnt for wlt"); } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -578,30 +577,27 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - if ( skipped == 0) + //vout.0: funding CC change to entropy owner + //vout.2: normal output to bettor's address + //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + odds = vinTx.vout[2].nValue - txfee; + if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); + else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) + return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); + else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) + return eval->Invalid("vout[2] payut mismatch for win/timeout"); + else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) { - //vout.0: funding CC change to entropy owner - //vout.2: normal output to bettor's address - //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - odds = vinTx.vout[2].nValue - txfee; - if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) - return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); - else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) - return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); - else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) - return eval->Invalid("vout[2] payut mismatch for win/timeout"); - else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) - { - fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); - return eval->Invalid("CC funds mismatch for win/timeout"); - } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } - iswin = (funcid == 'W'); + fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); + return eval->Invalid("CC funds mismatch for win/timeout"); } + else if ( tx.vout[3].scriptPubKey != fundingPubKey ) + { + if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) + return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); + } + iswin = (funcid == 'W'); } if ( iswin != 0 ) { diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 113c4a6e8..9ae6d4626 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -98,10 +98,9 @@ bool Eval::GetSpendsConfirmed(uint256 hash, std::vector &spends) c bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const { - // there is a LOCK(cs_main) in the normal GetTransaction(), which leads to deadlocks - //bool fAllowSlow = false; // Don't allow slow - //return GetTransaction(hash, txOut, hashBlock, fAllowSlow); - return myGetTransaction(hash, txOut,hashBlock); + if (!myGetTransaction(hash, txOut,hashBlock)) { + return(GetTransaction(hash, txOut,hashBlock)); + } else return(true); } From e36c6f65ee56169df909a2c49b025fb87ec453c6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 18:04:29 +0800 Subject: [PATCH 310/749] posibly stable --- src/cc/CCtx.cpp | 2 +- src/cc/dice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5c2c42e97..3326e9447 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -276,7 +276,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * abovei = belowi = -1; for (above=below=i=0; i 150 ) { + if ( numunspents > 500 ) { if ( (rand() % 100) < 80 ) continue; } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 86483d008..927ab7b95 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - if ( skipped == 0) + if ( skipped == 0 ) { //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address From d72c39339362553b98c0ebd77ef4cd393439223b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 18:36:22 +0800 Subject: [PATCH 311/749] done? --- src/cc/CCtx.cpp | 4 ---- src/cc/dice.cpp | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 3326e9447..71669a0a6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -276,10 +276,6 @@ 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 ) - continue; - } if ( (atx_value= utxos[i].nValue) <= 0 ) continue; if ( atx_value == value ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 927ab7b95..afebfd4e4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1203,6 +1203,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } error = "didnt find dicefinish tx"; } + error = res; return(-1.); } return(0.); From 71d9c82c7ab7593281f9010e4bd803065dffaac1 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 12:46:51 +0100 Subject: [PATCH 312/749] Check mempool for markdone in pending --- src/cc/gateways.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c3d09098c..b49d51664 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -880,8 +880,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) { queueflag = 1; break; - } - //Getscriptaddress(withmarker,CScript() << ParseHex(HexStr(gatewayspk)) << OP_CHECKSIG); + } SetCCunspents(unspentOutputs,coinaddr); numqueued = 0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -890,7 +889,8 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; fprintf(stderr,"%s %d %ld\n",txid.ToString().c_str(),vout,(long)nValue); - if ( vout == 2 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W') + if ( vout == 2 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) && + DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W' && myIsutxo_spentinmempool(txid,vout) != 0) { Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); From 6756a2f4f2f39aaee88174ad81f3e84d52d895a2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 20:00:04 +0800 Subject: [PATCH 313/749] done --- src/cc/dice.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index afebfd4e4..67d251bcc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,10 +413,8 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - char str[65]; - fprintf(stderr, "%s something \n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { @@ -736,7 +734,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropytxid = txid; entropyval = tx.vout[0].nValue; first = 1; - fprintf(stderr, "chosen entropy on loop: %d\n",loops); + if (random) { + fprintf(stderr, "chosen entropy on loop: %d\n",loops); + } } else { @@ -1202,8 +1202,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else return(0.); } error = "didnt find dicefinish tx"; - } - error = res; + } else error = res; return(-1.); } return(0.); From a96dafc837b141e1f0a7d6c448a8048a05193eb6 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 13:03:24 +0100 Subject: [PATCH 314/749] Fix --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b49d51664..8a04a1b30 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -890,7 +890,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) nValue = (int64_t)it->second.satoshis; fprintf(stderr,"%s %d %ld\n",txid.ToString().c_str(),vout,(long)nValue); if ( vout == 2 && nValue == 10000 && GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) && - DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W' && myIsutxo_spentinmempool(txid,vout) != 0) + DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,assetid,tmprefcoin,withdrawpub,amount) == 'W' && myIsutxo_spentinmempool(txid,vout) == 0) { Getscriptaddress(destaddr,tx.vout[0].scriptPubKey); Getscriptaddress(withaddr,tx.vout[1].scriptPubKey); From c57612e01bf8191673dd9f59eda36aa0e24bd02c Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 13:24:38 +0100 Subject: [PATCH 315/749] Check mempool in Gateways Multisig --- src/cc/gateways.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 8a04a1b30..2f554b47a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -921,7 +921,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) std::string GatewaysMultisig(char *txidaddr) { - std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K; CPubKey signerpk; + std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K,numvouts; CPubKey signerpk; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,txidaddr); @@ -930,12 +930,25 @@ std::string GatewaysMultisig(char *txidaddr) for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; - if (GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK ) + if (GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts=tx.vout.size()) > 0 && DecodeGatewaysPartialOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK ) { maxK=K; parthex=hex; } } + + BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + { + const CTransaction &txmempool = e.GetTx(); + const uint256 &hash = txmempool.GetHash(); + + if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysPartialOpRet(txmempool.vout[numvouts-1].scriptPubKey,K,signerpk,refcoin,hex) == 'P' && K>maxK) + { + maxK=K; + parthex=hex; + } + } + if (maxK>0) return(parthex); else return (""); } From 16e69092d98ff90aa360cac66515d8cfd548c114 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:17:09 +0800 Subject: [PATCH 316/749] first try --- src/main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 11df78609..676c77cdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,6 +92,7 @@ unsigned int expiryDelta = DEFAULT_TX_EXPIRY_DELTA; CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); CTxMemPool mempool(::minRelayTxFee); +CTxMemPool tmpmempool(::minRelayTxFee); struct COrphanTx { CTransaction tx; @@ -1697,7 +1698,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo } } //fprintf(stderr,"check disk\n"); - + if (fTxIndex) { CDiskTxPos postx; //fprintf(stderr,"ReadTxIndex\n"); @@ -4247,6 +4248,17 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { CValidationState stateDummy; int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); + // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. + LOCK(mempool.cs); + BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); + tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); + fprintf(stderr, "added mempool tx to temp mempool\n"); + } + // clear the mempool before importing all block txs to mempool. + mempool.clear(); + // add all the txs in the block to the empty mempool. while ( 1 ) { for (i=0; i Date: Mon, 29 Oct 2018 21:19:15 +0800 Subject: [PATCH 317/749] more --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 676c77cdc..cb07c181b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4310,7 +4310,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { const CTransaction &tx = e.GetTx(); - if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival. + if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } From 7a0832ebb09153978d96c36eec3533ecb67aa6d6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:31:31 +0800 Subject: [PATCH 318/749] fix --- src/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cb07c181b..1b160097b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4307,16 +4307,19 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - int invalidtxs = 0; - BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - const CTransaction &tx = e.GetTx(); - if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. - invalidtxs++; - fprintf(stderr, "added mempool tx back to mempool\n"); + if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + { + int invalidtxs = 0; + BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { + const CTransaction &tx = e.GetTx(); + if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. + invalidtxs++; + fprintf(stderr, "added mempool tx back to mempool\n"); + } + fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); + // empty the temp mempool for next time. + tmpmempool.clear(); } - fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); - // empty the temp mempool for next time. - tmpmempool.clear(); return true; } From eae3058c515ac9b3675838e71a504ae7a6d9ef80 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:34:45 +0800 Subject: [PATCH 319/749] try --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1b160097b..ac22d7dd5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4251,8 +4251,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { - const CTransaction &tx = e.GetTx(); - const uint256 &hash = tx.GetHash(); + CTransaction &tx = e.GetTx(); + uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); fprintf(stderr, "added mempool tx to temp mempool\n"); } @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - const CTransaction &tx = e.GetTx(); + CTransaction &tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From 22bbf1477c258b75efc930172df2d73f4ca87fd0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:40:12 +0800 Subject: [PATCH 320/749] try --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ac22d7dd5..db2e9a3f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4251,8 +4251,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { - CTransaction &tx = e.GetTx(); - uint256 &hash = tx.GetHash(); + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); fprintf(stderr, "added mempool tx to temp mempool\n"); } @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction &tx = e.GetTx(); + CTransaction &tx = e->GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From bb2a48ab545d10b23853d68cc77e0d995fee1456 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:43:13 +0800 Subject: [PATCH 321/749] try --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index db2e9a3f4..3ec949b21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction &tx = e->GetTx(); + CTransaction &tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From 441240215fc3365499a3493ccbf2cd2a559a2903 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:43:37 +0800 Subject: [PATCH 322/749] this --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3ec949b21..0ed53e0c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction &tx = e.GetTx(); + CTransaction tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From 624d0e81cbc06ea573031b15ccaf5088a260a756 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:43:58 +0800 Subject: [PATCH 323/749] a --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0ed53e0c7..801432a71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction tx = e.GetTx(); + CTransaction& tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From b64c592e07dc6ad1fb07852de5a8fd521af73db1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:46:24 +0800 Subject: [PATCH 324/749] try --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 801432a71..0ed53e0c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction& tx = e.GetTx(); + CTransaction tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From f8074b70496e72cacdd2fabc3b50e1f8dce987d4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:57:48 +0800 Subject: [PATCH 325/749] remove hack --- src/cc/dice.cpp | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 67d251bcc..c5f289487 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -443,7 +443,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; - CBlockIndex block; int skipped = 0; + CBlockIndex block; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -551,8 +551,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { char str[65],str2[65],str3[65]; fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); - skipped = 1; + return eval->Invalid("always should find looking vin.0, but didnt for wlt"); } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -576,30 +575,27 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - if ( skipped == 0 ) + //vout.0: funding CC change to entropy owner + //vout.2: normal output to bettor's address + //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + odds = vinTx.vout[2].nValue - txfee; + if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); + else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) + return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); + else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) + return eval->Invalid("vout[2] payut mismatch for win/timeout"); + else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) { - //vout.0: funding CC change to entropy owner - //vout.2: normal output to bettor's address - //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - odds = vinTx.vout[2].nValue - txfee; - if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) - return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); - else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) - return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); - else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) - return eval->Invalid("vout[2] payut mismatch for win/timeout"); - else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) - { - fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); - return eval->Invalid("CC funds mismatch for win/timeout"); - } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } - iswin = (funcid == 'W'); + fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); + return eval->Invalid("CC funds mismatch for win/timeout"); } + else if ( tx.vout[3].scriptPubKey != fundingPubKey ) + { + if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) + return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); + } + iswin = (funcid == 'W'); } if ( iswin != 0 ) { From 98eeeff0014ec84a2d705bcbda18700d92b830ef Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 22:14:55 +0800 Subject: [PATCH 326/749] temp disable random entropy to try and brake mempool --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c5f289487..39a433efb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,9 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } - int32_t entropytxs=0,emptyvar=0; + int32_t entropytxs=0; //,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + //DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 916986cd544bd6dfc2edfcd12690e4c238a63fac Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 22:55:43 +0800 Subject: [PATCH 327/749] enabled utxo selection. --- src/cc/CCtx.cpp | 5 +++++ src/cc/dice.cpp | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 71669a0a6..60b52fba0 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -276,6 +276,11 @@ 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 ) + // continue; + //} if ( (atx_value= utxos[i].nValue) <= 0 ) continue; if ( atx_value == value ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 39a433efb..c5f289487 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,9 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } - int32_t entropytxs=0; //,emptyvar=0; + int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - //DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 07cfded72b2305f8e70d2a8014a512ff552fe302 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 22:58:41 +0800 Subject: [PATCH 328/749] remoce getblock, redundant --- src/cc/dice.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c5f289487..ef0b7675b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -548,12 +548,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); - else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - char str[65],str2[65],str3[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); + else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find looking vin.0, but didnt for wlt"); - } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) From b88f5e1484d113f0631563ae8d69ae9503dedfd2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:00:38 +0800 Subject: [PATCH 329/749] missed --- src/cc/dice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef0b7675b..29e36e968 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -542,7 +542,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vin.3+: funding CC vout.0 from 'F', 'E', 'W', 'L' or 'T' //vout.1: tag to owner address for entropy funds preventCCvouts = 1; - CBlockIndex block; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); From b655a5ff0e13639060c964c41c3ac34ec07355c7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:03:18 +0800 Subject: [PATCH 330/749] more --- src/cc/dice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 29e36e968..7e013ffe2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -443,7 +443,6 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; - CBlockIndex block; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; From 94153cd13539dbd53537f38b1116b6ba11115136 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 16:05:32 +0100 Subject: [PATCH 331/749] Fix import of multisig address --- src/cc/dapps/oraclefeed.c | 43 ++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 6d3695a5f..a1c917ca3 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -546,6 +546,24 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) } } +void admultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr) +{ + cJSON *retjson; char *retstr,Mstr[10]; + + printf("%d %s\n",M,pubkeys); + sprintf(Mstr,"%d",M); + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,bindtxidstr,"")) != 0 ) + { + printf("addmultisigaddress.(%s)\n",jprint(retjson,0)); + free_json(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"addmultisigaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } +} + cJSON *getinputarray(int64_t *totalp,cJSON *unspents,int64_t required) { cJSON *vin,*item,*vins = cJSON_CreateArray(); int32_t i,n,v; int64_t satoshis; bits256 txid; @@ -691,9 +709,9 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit } } -int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr) +int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr, char *pubkeys) { - char *oracle,*retstr,*name,*deposit; cJSON *retjson; + char *oracle,*retstr,*name,*deposit; cJSON *retjson,*pubarray; int32_t n; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 ) { if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 && (deposit= jstr(retjson,"deposit")) != 0 ) @@ -705,6 +723,18 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M *Np = jint(retjson,"N"); //printf("(%s)\n",jprint(retjson,0)); } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); + if (jarray(&n,retjson,"pubkeys")!=0) + { + pubkeys=malloc((sizeof(char)*70*n)+5); + sprintf(pubkeys,"\"["); + for (int i=0;i Date: Mon, 29 Oct 2018 16:09:11 +0100 Subject: [PATCH 332/749] Fix --- src/cc/dapps/oraclefeed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index a1c917ca3..dc9a0f342 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -546,7 +546,7 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) } } -void admultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr) +void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr) { cJSON *retjson; char *retstr,Mstr[10]; @@ -969,7 +969,7 @@ oraclesdata 17a841a919c284cea8a676f34e793da002e606f19a9258a3190bed12d5aaa3ff 034 int32_t main(int32_t argc,char **argv) { - cJSON *clijson,*clijson2,*regjson,*item,*pubkeys; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,depositaddr[64],hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; + cJSON *clijson,*clijson2,*regjson,*item; int32_t acheight,i,retval,M,N,n,height,prevheight = 0; char *pubkeys,*format,*acname,*oraclestr,*bindtxidstr,*pkstr,*pubstr,*retstr,*retstr2,depositaddr[64],hexstr[4096],refcoin[64]; uint64_t price; bits256 txid; if ( argc < 6 ) { printf("usage: oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]\n"); From 38e5f55f1c9117b0bd5cfc81893631580c40880f Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 16:19:51 +0100 Subject: [PATCH 333/749] Add check if address exists in wallet --- src/cc/dapps/oraclefeed.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index dc9a0f342..74c47ea90 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -531,6 +531,23 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) return(0); } +int32_t validateaddress(char *refcoin,char *acname,char *depositaddr) +{ + cJSON *retjson; char *retstr; int32_t res=0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 ) + { + if (is_cJSON_True(jobj(retjson,"ismine")) != 0 ) res=1; + free_json(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"validateaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr); + free(retstr); + } + + return (res); +} + void importaddress(char *refcoin,char *acname,char *depositaddr) { cJSON *retjson; char *retstr; @@ -1011,8 +1028,11 @@ int32_t main(int32_t argc,char **argv) printf("cant find bindtxid.(%s)\n",bindtxidstr); exit(0); } - if (M==N==1) importaddress(refcoin,"",depositaddr); - else addmultisigaddress(refcoin,"",M,pubkeys,bindtxidstr); + if (validateaddress(refcoin,"",depositaddr)==0) + { + if (M==N==1) importaddress(refcoin,"",depositaddr); + else addmultisigaddress(refcoin,"",M,pubkeys,bindtxidstr); + } if (pubkeys!=NULL) free(pubkeys); printf("set refcoin %s <- %s [%s] M.%d of N.%d\n",depositaddr,refcoin,REFCOIN_CLI,M,N); } From 6ba8c494e6925db53e8bbebf0e80866bd7206b86 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:26:41 +0800 Subject: [PATCH 334/749] try optional to disable nullifiers check --- src/main.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0ed53e0c7..2f90f161d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1310,7 +1310,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF } -bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee) +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) { AssertLockHeld(cs_main); if (pfMissingInputs) @@ -1391,14 +1391,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) + if (!bool_nullifiers) { - BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) + BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { - if (pool.mapNullifiers.count(nf)) + BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - fprintf(stderr,"pool.mapNullifiers.count\n"); - return false; + if (pool.mapNullifiers.count(nf)) + { + fprintf(stderr,"pool.mapNullifiers.count\n"); + return false; + } } } } @@ -1678,11 +1681,15 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx) +bool myAddtomempool(CTransaction &tx,boost:optional bool_nullifiers) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; - if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); + if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { + if (bool_nullifiers) + return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,bool_nullifiers)); + else + return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); + } else return(true); } @@ -4312,7 +4319,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); - if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. + if ( myAddtomempool(tx,1) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } From 5010217b996a86edddd5b1603cc0473e7772235f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:29:35 +0800 Subject: [PATCH 335/749] bootst include --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 2f90f161d..31becb7d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ #include #include #include +#include using namespace std; From 2c98a4f5fea89b776b7fe20fc262cbd1f45436ed Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:40:05 +0800 Subject: [PATCH 336/749] try --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 31becb7d2..ea5255928 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1310,6 +1310,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF return nMinFee; } +using boost::optional; bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) { From 30d0a58a1ad8dce1b82b032ee7d91311d7d9b57d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:41:54 +0800 Subject: [PATCH 337/749] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ea5255928..2ccc9aa17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1683,7 +1683,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx,boost:optional bool_nullifiers) +bool myAddtomempool(CTransaction &tx,boost::optional bool_nullifiers) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { From 06bdc769992bb6f94b33390f7ab19ce346bf9d02 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:52:17 +0800 Subject: [PATCH 338/749] try --- src/main.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2ccc9aa17..5415705c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,7 +42,6 @@ #include #include #include -#include using namespace std; @@ -1310,7 +1309,6 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF return nMinFee; } -using boost::optional; bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) { @@ -1683,15 +1681,11 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx,boost::optional bool_nullifiers) +bool myAddtomempool(CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; - if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { - if (bool_nullifiers) - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,bool_nullifiers)); - else - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); - } + if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) + return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); else return(true); } @@ -4321,7 +4315,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); - if ( myAddtomempool(tx,1) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. + CValidationState state; bool fMissingInputs,fOverrideFees = false; + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,1) == false ); invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } From 71c57902668e87ff3fa88a9ebcacc09205961435 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:56:53 +0800 Subject: [PATCH 339/749] maybe --- src/main.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.h b/src/main.h index fd418502a..7e2c0fe9f 100644 --- a/src/main.h +++ b/src/main.h @@ -180,11 +180,11 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals); /** Unregister a network node */ void UnregisterNodeSignals(CNodeSignals& nodeSignals); -/** +/** * Process an incoming block. This only returns after the best known valid * block is made active. Note that it does not, however, guarantee that the * specific block passed to it has been checked for validity! - * + * * @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever *any* block completes validation. * @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid. * @param[in] pblock The block we want to process. @@ -267,7 +267,7 @@ void PruneAndFlush(); /** (try to) add transaction to memory pool **/ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, - bool* pfMissingInputs, bool fRejectAbsurdFee=false); + bool* pfMissingInputs, bool fRejectAbsurdFee=false, boost::optional bool_nullifiers); struct CNodeStateStats { @@ -640,7 +640,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF /** * Check transaction inputs, and make sure any * pay-to-script-hash transactions are evaluating IsStandard scripts - * + * * Why bother? To avoid denial-of-service attacks; an attacker * can submit a standard HASH... OP_EQUAL transaction, * which will get accepted into blocks. The redemption @@ -649,14 +649,14 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF * DUP CHECKSIG DROP ... repeated 100 times... OP_1 */ -/** +/** * Check for standard transaction types * @param[in] mapInputs Map of previous transactions that have outputs we're spending * @return True if all inputs (scriptSigs) use only standard transaction forms */ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, uint32_t consensusBranchId); -/** +/** * Count ECDSA signature operations the old-fashioned (pre-0.6) way * @return number of sigops this transaction's outputs will produce when spent * @see CTransaction::FetchInputs @@ -665,7 +665,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx); /** * Count ECDSA signature operations in pay-to-script-hash inputs. - * + * * @param[in] mapInputs Map of previous transactions that have outputs we're spending * @return maximum number of sigops required to validate this transaction's inputs * @see CTransaction::FetchInputs @@ -732,9 +732,9 @@ bool IsExpiredTx(const CTransaction &tx, int nBlockHeight); */ bool CheckFinalTx(const CTransaction &tx, int flags = -1); -/** +/** * Closure representing one script verification - * Note that this stores references to the spending transaction + * Note that this stores references to the spending transaction */ class CScriptCheck { From 6f84a8cb23871049ba37449298edd6e2b204de26 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 00:10:41 +0800 Subject: [PATCH 340/749] try --- src/main.cpp | 6 +++--- src/main.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5415705c7..e6cca73bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1310,7 +1310,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF } -bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, bool fNullifiers) { AssertLockHeld(cs_main); if (pfMissingInputs) @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if (!bool_nullifiers) + if (fNullifiers == true) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { @@ -4316,7 +4316,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); CValidationState state; bool fMissingInputs,fOverrideFees = false; - if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,1) == false ); + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ); invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } diff --git a/src/main.h b/src/main.h index 7e2c0fe9f..244817a61 100644 --- a/src/main.h +++ b/src/main.h @@ -267,7 +267,7 @@ void PruneAndFlush(); /** (try to) add transaction to memory pool **/ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, - bool* pfMissingInputs, bool fRejectAbsurdFee=false, boost::optional bool_nullifiers); + bool* pfMissingInputs, bool fRejectAbsurdFee=false, bool fNullifiers=false); struct CNodeStateStats { From 87d899fb9aeac1f4437cc57e9a6ee44392decdd2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 00:13:02 +0800 Subject: [PATCH 341/749] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e6cca73bc..a8405aaad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if (fNullifiers == true) + if (fNullifiers == false) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { From 53476dff15227ff38134acf198ff275e5132b94b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 00:23:15 +0800 Subject: [PATCH 342/749] fix --- src/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a8405aaad..d8a32f3c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1454,12 +1454,14 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } // are the joinsplit's requirements met? - if (!view.HaveJoinSplitRequirements(tx)) + if ( fNullifiers == true ) { - //fprintf(stderr,"accept failure.2\n"); - return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); + if (!view.HaveJoinSplitRequirements(tx)) + { + //fprintf(stderr,"accept failure.2\n"); + return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); + } } - // Bring the best block into scope view.GetBestBlock(); From e7208f084971ea03a3cf1e6bb7b5a6f8bbf1393a Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 17:30:53 +0100 Subject: [PATCH 343/749] Fix --- src/cc/dapps/oraclefeed.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 74c47ea90..12a78dd2b 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -565,11 +565,12 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr) { - cJSON *retjson; char *retstr,Mstr[10]; + cJSON *retjson; char *retstr,Mstr[10],tmp[128]; printf("%d %s\n",M,pubkeys); sprintf(Mstr,"%d",M); - if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,bindtxidstr,"")) != 0 ) + sprintf(tmp,"\"%s\"",bindtxidstr); + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,tmp,"")) != 0 ) { printf("addmultisigaddress.(%s)\n",jprint(retjson,0)); free_json(retjson); @@ -726,9 +727,9 @@ void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bit } } -int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr, char *pubkeys) +int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *Mp,int32_t *Np,char *bindtxidstr,char *coin,char *oraclestr, char **pubkeys) { - char *oracle,*retstr,*name,*deposit; cJSON *retjson,*pubarray; int32_t n; + char *oracle,*retstr,*name,*deposit,temp[128]; cJSON *retjson,*pubarray; int32_t n; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewaysinfo",bindtxidstr,"","","")) != 0 ) { if ( (oracle= jstr(retjson,"oracletxid")) != 0 && strcmp(oracle,oraclestr) == 0 && (deposit= jstr(retjson,"deposit")) != 0 ) @@ -738,21 +739,23 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M { *Mp = jint(retjson,"M"); *Np = jint(retjson,"N"); - //printf("(%s)\n",jprint(retjson,0)); - } else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); - if (jarray(&n,retjson,"pubkeys")!=0) + } + else printf("coin.%s vs %s\n",jstr(retjson,"coin"),coin); + if ((pubarray=jarray(&n,retjson,"pubkeys"))!=0) { - pubkeys=malloc((sizeof(char)*70*n)+5); - sprintf(pubkeys,"\"["); + *pubkeys=malloc((sizeof(char)*70*n)+64); + sprintf(*pubkeys,"\"["); for (int i=0;i Date: Mon, 29 Oct 2018 17:35:59 +0100 Subject: [PATCH 344/749] Fix --- src/cc/dapps/oraclefeed.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 12a78dd2b..6f921e747 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -536,7 +536,7 @@ int32_t validateaddress(char *refcoin,char *acname,char *depositaddr) cJSON *retjson; char *retstr; int32_t res=0; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 ) { - if (is_cJSON_True(jobj(retjson,"ismine")) != 0 ) res=1; + if (is_cJSON_True(jobj(retjson,"iswatchonly")) != 0 ) res=1; free_json(retjson); } else if ( retstr != 0 ) @@ -572,13 +572,13 @@ void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char sprintf(tmp,"\"%s\"",bindtxidstr); if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,tmp,"")) != 0 ) { - printf("addmultisigaddress.(%s)\n",jprint(retjson,0)); - free_json(retjson); + fprintf(stderr,"unexpected addmultisigaddress json.(%s)\n",jprint(retjson,0)); + free(retstr); } else if ( retstr != 0 ) { - fprintf(stderr,"addmultisigaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr); - free(retstr); + printf("addmultisigaddress.(%s)\n",jprint(retjson,0)); + free_json(retjson); } } From a19d3e7881461b82e94c423861e08c1cec8d3af2 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 17:38:05 +0100 Subject: [PATCH 345/749] Fix --- src/cc/dapps/oraclefeed.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 6f921e747..355ed1c2a 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -566,8 +566,7 @@ void importaddress(char *refcoin,char *acname,char *depositaddr) void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char *bindtxidstr) { cJSON *retjson; char *retstr,Mstr[10],tmp[128]; - - printf("%d %s\n",M,pubkeys); + sprintf(Mstr,"%d",M); sprintf(tmp,"\"%s\"",bindtxidstr); if ( (retjson= get_komodocli(refcoin,&retstr,acname,"addmultisigaddress",Mstr,pubkeys,tmp,"")) != 0 ) @@ -577,7 +576,7 @@ void addmultisigaddress(char *refcoin,char *acname,int32_t M, char *pubkeys,char } else if ( retstr != 0 ) { - printf("addmultisigaddress.(%s)\n",jprint(retjson,0)); + printf("addmultisigaddress.(%s)\n",retstr); free_json(retjson); } } From 6721141bc053c5f7e4c103b9d7572c25f2a81656 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 17:52:30 +0100 Subject: [PATCH 346/749] Fix --- src/cc/dapps/oraclefeed.c | 8 ++++---- src/cc/gateways.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 355ed1c2a..ef05fdcff 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -683,7 +683,7 @@ cJSON *addmultisignature(char *refcoin,char *acname,char *signeraddr,char *rawtx return(0); } -char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr) +char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K) { char *retstr,*hexstr,*hex=0; cJSON *retjson; if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",txidaddr,"","","")) != 0 ) @@ -889,7 +889,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else { - if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr)) == 0 ) + if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0 ) { rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis); } @@ -908,8 +908,8 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else if ( jint(clijson,"partialtx") != 0 ) { - K=gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex")); - fprintf(stderr,"%d of %d partialtx %s sent\n",K,N,bits256_str(str,txid)); + gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex")); + fprintf(stderr,"%d of %d partialtx %s sent\n",K+1,N,bits256_str(str,txid)); } free_json(clijson); } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 2f554b47a..5bc897e68 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -922,7 +922,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) std::string GatewaysMultisig(char *txidaddr) { std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K,numvouts; CPubKey signerpk; - std::vector > unspentOutputs; + std::vector > unspentOutputs; UniValue result(UniValue::VOBJ); SetCCunspents(unspentOutputs,txidaddr); if (unspentOutputs.size()==0) return (""); @@ -949,15 +949,15 @@ std::string GatewaysMultisig(char *txidaddr) } } - if (maxK>0) return(parthex); - else return (""); + result.push_back(Pair("hex",parthex)); + result.push_back(Pair("number_of_signs",K)); } std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) { CMutableTransaction mtx; CScript opret; CPubKey mypk,txidaddrpk,signerpk; struct CCcontract_info *cp,C; CTransaction tx; std::vector > unspentOutputs; char txidaddr[65]; - int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; + int32_t maxK,K=0; uint256 tmptxid,parttxid,hashBlock; cp = CCinit(&C,EVAL_GATEWAYS); if ( txfee == 0 ) txfee = 5000; @@ -985,6 +985,6 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, } mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(txidaddrpk)) << OP_CHECKSIG)); - opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K+1 << mypk << refcoin << hex); + opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K+1 << mypk << refcoin << hex); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } From 52bd617b1b574971c21df9c48f9a8b1e6d249866 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 18:17:30 +0100 Subject: [PATCH 347/749] Fix --- src/cc/dapps/oraclefeed.c | 1 + src/wallet/rpcwallet.cpp | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ef05fdcff..ce075443e 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -690,6 +690,7 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K) { if ( (hexstr= jstr(retjson,"hex")) != 0 ) hex = clonestr(hexstr); + *K=jint(retjson,"number_of_signs"); free_json(retjson); } return(hex); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ca3c0bea4..fdeaea2ff 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5600,13 +5600,7 @@ UniValue gatewaysmultisig(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txidaddr = (char *)params[0].get_str().c_str(); - hex = GatewaysMultisig(txidaddr); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex",hex)); - } else ERR_RESULT("couldnt gatewaysmultisig"); - return(result); + return(GatewaysMultisig(txidaddr)); } UniValue gatewayspartialsign(const UniValue& params, bool fHelp) From b6a9ea6c3a6fc4c06cff2b4897f0972b4f7d8c87 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 01:19:44 +0800 Subject: [PATCH 348/749] fix --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d8a32f3c7..16994e0e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4320,7 +4320,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; bool fMissingInputs,fOverrideFees = false; if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ); invalidtxs++; - fprintf(stderr, "added mempool tx back to mempool\n"); + else + fprintf(stderr, "added mempool tx back to mempool\n"); } fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. From edff8a648aa6c0efc8433fe40c1b5a636308d9ab Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 18:21:14 +0100 Subject: [PATCH 349/749] Fix --- src/cc/gateways.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5bc897e68..4bb2d13e3 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -951,6 +951,7 @@ std::string GatewaysMultisig(char *txidaddr) result.push_back(Pair("hex",parthex)); result.push_back(Pair("number_of_signs",K)); + return (result); } std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, std::string hex) From 41c207787054a62a71ed800d3269d3e07f36e045 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 29 Oct 2018 18:23:27 +0100 Subject: [PATCH 350/749] Fix --- src/cc/CCGateways.h | 2 +- src/cc/gateways.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index cd094fce0..e82add62b 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -27,7 +27,7 @@ std::string GatewaysClaim(uint64_t txfee,uint256 bindtxid,std::string refcoin,ui std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin,CPubKey withdrawpub,int64_t amount); UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin); std::string GatewaysMarkdone(uint64_t txfee,uint256 withdrawtxid,std::string refcoin,uint256 cointxid); -std::string GatewaysMultisig(char *txidaddr); +UniValue GatewaysMultisig(char *txidaddr); std::string GatewaysPartialSign(uint64_t txfee,uint256 txidaddr,std::string refcoin, std::string hex); // CCcustom diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 4bb2d13e3..2ff633a99 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -919,7 +919,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) return(result); } -std::string GatewaysMultisig(char *txidaddr) +UniValue GatewaysMultisig(char *txidaddr) { std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K,numvouts; CPubKey signerpk; std::vector > unspentOutputs; UniValue result(UniValue::VOBJ); From 3d7a5f943409165446225c7c14a83a3c6b585bc4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 01:26:59 +0800 Subject: [PATCH 351/749] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 16994e0e3..34492dc9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4318,7 +4318,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); CValidationState state; bool fMissingInputs,fOverrideFees = false; - if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ); + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); From d83a8593b22725cb4cd81f96e4a23b57884e0e64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Oct 2018 07:03:09 -1100 Subject: [PATCH 352/749] -print --- src/cc/dice.cpp | 5 +++++ src/main.cpp | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7e013ffe2..ee41dca17 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -85,6 +85,11 @@ WARNING: there is an attack vector that precludes betting any large amounts, it 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. + + Actually a much better solution to this is possible, which allows to retain the realtime response aspect of dice CC, which is critical to its usage. + + + */ #include "../compat/endian.h" diff --git a/src/main.cpp b/src/main.cpp index 34492dc9f..ae8f92887 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4320,10 +4320,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; bool fMissingInputs,fOverrideFees = false; if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; - else - fprintf(stderr, "added mempool tx back to mempool\n"); + //else fprintf(stderr, "added mempool tx back to mempool\n"); } - fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); + if ( invalidtxs > 0 ) + fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); } From 79429720dc3ba341d24de628ea385c9905813181 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Oct 2018 07:09:21 -1100 Subject: [PATCH 353/749] -prints --- src/cc/CCutils.cpp | 2 +- src/cc/dice.cpp | 2 +- src/main.cpp | 4 ++-- src/script/standard.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 491798a98..d4de992f7 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -193,7 +193,7 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) strcpy(destaddr,(char *)CBitcoinAddress(address).ToString().c_str()); return(true); } - fprintf(stderr,"ExtractDestination failed\n"); + //fprintf(stderr,"ExtractDestination failed\n"); return(false); } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ee41dca17..e456ea6ae 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -284,7 +284,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); + //fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } diff --git a/src/main.cpp b/src/main.cpp index ae8f92887..938cfdfe0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - fprintf(stderr, "added mempool tx to temp mempool\n"); + //fprintf(stderr, "added mempool tx to temp mempool\n"); } // clear the mempool before importing all block txs to mempool. mempool.clear(); @@ -4322,7 +4322,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C invalidtxs++; //else fprintf(stderr, "added mempool tx back to mempool\n"); } - if ( invalidtxs > 0 ) + if ( 0 && invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); diff --git a/src/script/standard.cpp b/src/script/standard.cpp index fde836154..c7999a7de 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -246,7 +246,7 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet) CPubKey pubKey(vSolutions[0]); if (!pubKey.IsValid()) { - fprintf(stderr,"TX_PUBKEY invalid pubkey\n"); + //fprintf(stderr,"TX_PUBKEY invalid pubkey\n"); return false; } From a2ccb2118e359c093c30afd79bfcdf256d057ec6 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 10:59:12 +0100 Subject: [PATCH 354/749] Fix --- src/cc/dapps/oraclefeed.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ce075443e..83c13e440 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -531,12 +531,12 @@ cJSON *get_rawtransaction(char *refcoin,char *acname,bits256 txid) return(0); } -int32_t validateaddress(char *refcoin,char *acname,char *depositaddr) +int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* compare) { cJSON *retjson; char *retstr; int32_t res=0; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 ) { - if (is_cJSON_True(jobj(retjson,"iswatchonly")) != 0 ) res=1; + if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1; free_json(retjson); } else if ( retstr != 0 ) @@ -802,16 +802,20 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) { - cJSON *array,*item; bits256 txid; int32_t i,n,num=0; char *tmptxid,*retstr; + cJSON *array,*item,*rawtx,*vins,*vin; bits256 txid,tmptxid; int32_t i,n,m,num=0; char *retstr; if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 ) { for (i=0; i Date: Tue, 30 Oct 2018 11:32:47 +0100 Subject: [PATCH 355/749] Fix --- src/cc/dapps/oraclefeed.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 83c13e440..f506b2c28 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -805,6 +805,7 @@ int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) cJSON *array,*item,*rawtx,*vins,*vin; bits256 txid,tmptxid; int32_t i,n,m,num=0; char *retstr; if ( (array= get_addressutxos(refcoin,acname,coinaddr)) != 0 ) { + n=cJSON_GetArraySize(array); for (i=0; i 0 ) - // { - // fprintf(stderr,"already did withdraw %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); - // gatewaysmarkdone("KMD",acname,origtxid,refcoin,zeroid); - // } + else if ( retval > 0 ) + { + fprintf(stderr,"already did withdraw/signing %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); + } } } } From ee49162c75a11879a890992627356065f7849ae5 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 12:20:55 +0100 Subject: [PATCH 356/749] Fix --- src/cc/dapps/oraclefeed.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index f506b2c28..ff9f7920a 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -810,11 +810,10 @@ int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) { item = jitem(array,i); if ((bits256_nonz(tmptxid=jbits256(item,"txid")))!=0 && (rawtx=get_rawtransaction(refcoin,acname,tmptxid))!=0 && (vins=jarray(&m,rawtx,"vin"))!=0) - { - num=1; + { for (int j=0;j Date: Tue, 30 Oct 2018 12:34:11 +0100 Subject: [PATCH 357/749] Fix --- src/cc/dapps/oraclefeed.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ff9f7920a..42a078b37 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -828,11 +828,25 @@ int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) for (i=0; i 0 ) - { - num = 1; - break; + if ((bits256_nonz(tmptxid=jbits256(item,"txid")))!=0 && (rawtx=get_rawtransaction(refcoin,acname,tmptxid))!=0 && (vins=jarray(&m,rawtx,"vin"))!=0) + { + for (int j=0;j 0 ) + // { + // num = 1; + // break; + // } } } free_json(array); From 124778ceff0c81078d6b152d50b4a08a9b34befb Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 12:37:15 +0100 Subject: [PATCH 358/749] Fix --- src/cc/dapps/oraclefeed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 42a078b37..d4eb55c76 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -827,8 +827,8 @@ int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) { for (i=0; i Date: Tue, 30 Oct 2018 12:45:59 +0100 Subject: [PATCH 359/749] Fix --- src/cc/dapps/oraclefeed.c | 49 ++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index d4eb55c76..c011229d6 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -770,12 +770,12 @@ int32_t get_gatewaysinfo(char *refcoin,char *acname,char *depositaddr,int32_t *M int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinaddr) { - cJSON *txobj,*vouts,*vout,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numvouts,retval = 0; + cJSON *txobj,*vouts,*vout,*vins,*vin,*sobj,*addresses; char *addr,str[65]; int32_t i,j,n,numarray,retval = 0, hasvout=0; if ( (txobj= get_rawtransaction(refcoin,acname,txid)) != 0 ) { - if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) + if ( (vouts= jarray(&numarray,txobj,"vout")) != 0 ) { - for (i=0; i 0 ) + { + num = 1; + break; } - - if (num==1) break; - // if ( tx_has_voutaddress(refcoin,acname,txid,coinaddr) > 0 ) - // { - // num = 1; - // break; - // } } } free_json(array); From 113dcd93080c0640a62442cc9b27f5db7f84c1de Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 12:49:57 +0100 Subject: [PATCH 360/749] Fix --- src/cc/dapps/oraclefeed.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index c011229d6..09f0f67f1 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -795,7 +795,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd } } } - if (vins=jarray(&numarray,txobj,"vin")!=0) + if ((vins=jarray(&numarray,txobj,"vin"))!=0) { for (int i=0;j Date: Tue, 30 Oct 2018 12:57:58 +0100 Subject: [PATCH 361/749] Fix --- src/cc/dapps/oraclefeed.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 09f0f67f1..82c013973 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -799,7 +799,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd { for (int i=0;j Date: Tue, 30 Oct 2018 13:07:00 +0100 Subject: [PATCH 362/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 82c013973..bf99af1ee 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -795,7 +795,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd } } } - if ((vins=jarray(&numarray,txobj,"vin"))!=0) + if (hasvout==1 && (vins=jarray(&numarray,txobj,"vin"))!=0) { for (int i=0;j Date: Tue, 30 Oct 2018 16:33:42 +0100 Subject: [PATCH 363/749] Fix --- src/cc/dapps/oraclefeed.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index bf99af1ee..256704fe4 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -776,9 +776,8 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd if ( (vouts= jarray(&numarray,txobj,"vout")) != 0 ) { for (i=0; i Date: Tue, 30 Oct 2018 17:03:55 +0100 Subject: [PATCH 364/749] Fix --- src/cc/dapps/oraclefeed.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 256704fe4..d047c45a7 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -788,10 +788,12 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd { //fprintf(stderr,"found %s in %s v%d\n",coinaddr,bits256_str(str,txid),i); hasvout = 1; + break; } } } } + if (hasvout==1) break; } } if (hasvout==1 && (vins=jarray(&numarray,txobj,"vin"))!=0) @@ -853,6 +855,7 @@ int32_t markerfromthisnode(char *refcoin,char *acname,char *coinaddr) free_json(array); } else return(-1); } + printf("NUM=%d\n",num); return(num); } From 6d1ab84a05f9d3ec363338ba14aba06db9a63197 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 17:06:50 +0100 Subject: [PATCH 365/749] Fix --- src/cc/dapps/oraclefeed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index d047c45a7..6535f47ea 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -330,9 +330,9 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char system(cmdstr); *retstrp = 0; if ( (jsonstr= filestr(&fsize,fname)) != 0 ) - { - //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); + { jsonstr[strlen(jsonstr)-1]='\0'; + fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 ) *retstrp = jsonstr; else free(jsonstr); From 49479d233ba54c7bbe0a875226d821d6a1fb78df Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 17:18:12 +0100 Subject: [PATCH 366/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 6535f47ea..50faf5cf7 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -798,7 +798,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd } if (hasvout==1 && (vins=jarray(&numarray,txobj,"vin"))!=0) { - for (int i=0;j Date: Tue, 30 Oct 2018 17:39:25 +0100 Subject: [PATCH 367/749] Fix --- src/cc/gateways.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 2ff633a99..7dc4234b8 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -924,8 +924,7 @@ UniValue GatewaysMultisig(char *txidaddr) std::string parthex,hex,refcoin; uint256 txid,hashBlock; CTransaction tx; int32_t i,maxK,K,numvouts; CPubKey signerpk; std::vector > unspentOutputs; UniValue result(UniValue::VOBJ); - SetCCunspents(unspentOutputs,txidaddr); - if (unspentOutputs.size()==0) return (""); + SetCCunspents(unspentOutputs,txidaddr); maxK=0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From f5f90e0c6b3742061c6c7c292abe73936565003c Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 17:51:42 +0100 Subject: [PATCH 368/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- src/cc/gateways.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 50faf5cf7..7a906318a 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -332,7 +332,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char if ( (jsonstr= filestr(&fsize,fname)) != 0 ) { jsonstr[strlen(jsonstr)-1]='\0'; - fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); + //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 ) *retstrp = jsonstr; else free(jsonstr); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 7dc4234b8..d3352a460 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -964,13 +964,13 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, mypk = pubkey2pk(Mypubkey()); txidaddrpk=CCtxidaddr(txidaddr,txid); SetCCunspents(unspentOutputs,txidaddr); + maxK=0; if (unspentOutputs.size()==0) { if (AddNormalinputs(mtx,mypk,2*txfee,2)==0) fprintf(stderr,"error adding funds for partialsign\n"); } else { - maxK=0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { tmptxid = it->first.txhash; @@ -985,6 +985,6 @@ std::string GatewaysPartialSign(uint64_t txfee,uint256 txid,std::string refcoin, } mtx.vout.push_back(CTxOut(5000,CScript() << ParseHex(HexStr(txidaddrpk)) << OP_CHECKSIG)); - opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << K+1 << mypk << refcoin << hex); + opret << OP_RETURN << E_MARSHAL(ss << cp->evalcode << 'P' << maxK+1 << mypk << refcoin << hex); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } From 2964ae2da6271d530e61a707f8750f342163fcd7 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 18:02:17 +0100 Subject: [PATCH 369/749] Fix --- src/cc/gateways.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index d3352a460..2829706ff 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -949,7 +949,7 @@ UniValue GatewaysMultisig(char *txidaddr) } result.push_back(Pair("hex",parthex)); - result.push_back(Pair("number_of_signs",K)); + result.push_back(Pair("number_of_signs",maxK)); return (result); } From 78ab663601cc6c3610ac874ef8cf2f0dca2d0281 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 18:14:13 +0100 Subject: [PATCH 370/749] Fix --- src/cc/dapps/oraclefeed.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 7a906318a..86273828e 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -796,23 +796,23 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd if (hasvout==1) break; } } - if (hasvout==1 && (vins=jarray(&numarray,txobj,"vin"))!=0) - { - for (int i=0;i Date: Tue, 30 Oct 2018 18:16:00 +0100 Subject: [PATCH 371/749] ... --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 86273828e..12926a54c 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -332,7 +332,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char if ( (jsonstr= filestr(&fsize,fname)) != 0 ) { jsonstr[strlen(jsonstr)-1]='\0'; - //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); + fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 ) *retstrp = jsonstr; else free(jsonstr); From 743f21e6e48294358f37d6b2f37a1b3896cfbd52 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 18:22:13 +0100 Subject: [PATCH 372/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 12926a54c..d6bd1f53c 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -809,7 +809,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd // } free_json(txobj); } - return(retval); + return(hasvout); } int32_t markerfromthisnodeorunconfirmed(char *refcoin,char *acname,char *coinaddr) From e88f0f9dfb660106272c83b9504acaeeb2c99ea7 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 30 Oct 2018 18:55:45 +0100 Subject: [PATCH 373/749] ... --- src/cc/dapps/oraclefeed.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index d6bd1f53c..b99954d39 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -688,8 +688,11 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K) char *retstr,*hexstr,*hex=0; cJSON *retjson; if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",txidaddr,"","","")) != 0 ) { - if ( (hexstr= jstr(retjson,"hex")) != 0 ) + if ((hexstr=jstr(retjson,"hex")) != 0 ) + { + printf("!%s!%s!%ld\n",jstr(retjson,"hex"),hexstr,strlen(hexstr)); hex = clonestr(hexstr); + } *K=jint(retjson,"number_of_signs"); free_json(retjson); } From 47ab0296d6ca68aab23e4824120dbac3f9541729 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Oct 2018 02:48:42 -1100 Subject: [PATCH 374/749] Oraclesregister, allow using floating point for < 1.0 data fee --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6469b3e43..c7a11fe1a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5715,7 +5715,8 @@ UniValue oraclesregister(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); - datafee = atol((char *)params[1].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; hex = OracleRegister(0,txid,datafee); if ( hex.size() > 0 ) { From f51ee9a916d3bf9f046e31552e4e316c4c93d014 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 15:58:32 +0100 Subject: [PATCH 375/749] Fix clonestr --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index b99954d39..ed2d27304 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -139,7 +139,7 @@ long _stripwhite(char *buf,int accept) char *clonestr(char *str) { char *clone; - if ( str == 0 || str[0] == 0 ) + if ( str == 0) { printf("warning cloning nullstr.%p\n",str); //#ifdef __APPLE__ From 922dc2ba1e912dd0d402537db31911c4e0cf532e Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 16:00:32 +0100 Subject: [PATCH 376/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index ed2d27304..b59bfd8de 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -915,7 +915,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else { - if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0 ) + if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0 && strlen(rawtx)>0) { rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis); } From 70aaec105819ccea2ee54ce5f24b074c579cc736 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 16:05:24 +0100 Subject: [PATCH 377/749] Fix --- src/cc/dapps/oraclefeed.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index b59bfd8de..8a633bb01 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -139,7 +139,7 @@ long _stripwhite(char *buf,int accept) char *clonestr(char *str) { char *clone; - if ( str == 0) + if ( str == 0 || str[0]==0) { printf("warning cloning nullstr.%p\n",str); //#ifdef __APPLE__ @@ -689,9 +689,8 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K) if ( (retjson= get_komodocli("KMD",&retstr,acname,"gatewaysmultisig",txidaddr,"","","")) != 0 ) { if ((hexstr=jstr(retjson,"hex")) != 0 ) - { - printf("!%s!%s!%ld\n",jstr(retjson,"hex"),hexstr,strlen(hexstr)); - hex = clonestr(hexstr); + { + if (strlen(hex)>0) hex = clonestr(hexstr); } *K=jint(retjson,"number_of_signs"); free_json(retjson); @@ -915,7 +914,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else { - if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0 && strlen(rawtx)>0) + if ( (rawtx= get_gatewaysmultisig(refcoin,acname,txidaddr,&K)) == 0) { rawtx = createmultisig(refcoin,"",depositaddr,signeraddr,withdrawaddr,satoshis); } From 55d887fa757f21f6f243e928ec8914f9af90b001 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 16:07:26 +0100 Subject: [PATCH 378/749] Fix --- src/cc/dapps/oraclefeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 8a633bb01..d2809eb12 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -690,7 +690,7 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K) { if ((hexstr=jstr(retjson,"hex")) != 0 ) { - if (strlen(hex)>0) hex = clonestr(hexstr); + if (strlen(hexstr)>0) hex = clonestr(hexstr); } *K=jint(retjson,"number_of_signs"); free_json(retjson); From 7778f46ed8c01689d9584fb7f4e475d81374f700 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 16:11:28 +0100 Subject: [PATCH 379/749] Fix --- src/cc/dapps/oraclefeed.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index d2809eb12..99a693e9b 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -332,7 +332,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char if ( (jsonstr= filestr(&fsize,fname)) != 0 ) { jsonstr[strlen(jsonstr)-1]='\0'; - fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); + //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 ) *retstrp = jsonstr; else free(jsonstr); @@ -942,11 +942,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t free(rawtx); } else fprintf(stderr,"couldnt create msig rawtx\n"); } - } - else if ( retval > 0 ) - { - fprintf(stderr,"already did withdraw/signing %s %s %.8f processed\n",refcoin,withdrawaddr,(double)satoshis/SATOSHIDEN); - } + } } } } From 725d549f6d968285305a0ef857c7a3270f16ec4b Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 16:25:12 +0100 Subject: [PATCH 380/749] Fix --- src/cc/dapps/oraclefeed.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 99a693e9b..60e435874 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -19,6 +19,8 @@ #include #include "cJSON.c" +bits256 zeroid; + char hexbyte(int32_t c) { c &= 0xf; @@ -698,19 +700,19 @@ char *get_gatewaysmultisig(char *refcoin,char *acname,char *txidaddr,int32_t *K) return(hex); } -int32_t gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex) +bits256 gatewayspartialsign(char *refcoin,char *acname,bits256 txid,char *hex) { char str[65],*retstr; cJSON *retjson; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"gatewayspartialsign",bits256_str(str,txid),refcoin,hex,"")) != 0 ) { - komodobroadcast(refcoin,acname,retjson); - return(jint(retjson,"rank")); + return(komodobroadcast(refcoin,acname,retjson)); } else if ( retstr != 0 ) { - printf("error parsing gatewaysmarkdone.(%s)\n",retstr); + printf("error parsing gatewayspartialsing.(%s)\n",retstr); free(retstr); } + return (zeroid); } void gatewaysmarkdone(char *refcoin,char *acname,bits256 withtxid,char *coin,bits256 cointxid) @@ -856,8 +858,7 @@ int32_t markerfromthisnodeorunconfirmed(char *refcoin,char *acname,char *coinadd } free_json(array); } else return(-1); - } - printf("NUM=%d\n",num); + } return(num); } @@ -870,7 +871,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t /// if enough sigs, sendrawtransaction and when it confirms spend marker (txid.2) /// if not enough sigs, post partially signed to acname with marker2 // monitor marker2, for the partially signed withdraws - cJSON *retjson,*pending,*item,*clijson; char str[65],*rawtx,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,K,retval,processed = 0; bits256 txid,cointxid,origtxid,zeroid; int64_t satoshis; + cJSON *retjson,*pending,*item,*clijson; char str[65],*rawtx,*coinstr,*txidaddr,*signeraddr,*depositaddr,*withdrawaddr; int32_t i,j,n,K,retval,processed = 0; bits256 txid,cointxid,origtxid; int64_t satoshis; memset(&zeroid,0,sizeof(zeroid)); if ( (retjson= get_gatewayspending("KMD",acname,bindtxidstr)) != 0 ) { @@ -933,7 +934,7 @@ void update_gatewayspending(char *refcoin,char *acname,char *bindtxidstr,int32_t } else if ( jint(clijson,"partialtx") != 0 ) { - gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex")); + txid=gatewayspartialsign(refcoin,acname,origtxid,jstr(clijson,"hex")); fprintf(stderr,"%d of %d partialtx %s sent\n",K+1,N,bits256_str(str,txid)); } free_json(clijson); From 127ee64e48f304237889022f9ab5485105c25d81 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 16:54:18 +0100 Subject: [PATCH 381/749] Fix --- src/cc/channels.cpp | 2 +- src/cc/dapps/oraclefeed.c | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index f32e9d4d1..d92186d26 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -692,7 +692,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; - struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[256],str2[65]; int32_t vout,numvouts,param1,numpayments; + struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[256],str2[256]; int32_t vout,numvouts,param1,numpayments; int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 60e435874..0ff12bee5 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -360,7 +360,7 @@ bits256 komodobroadcast(char *refcoin,char *acname,cJSON *hexjson) retstr[64] = 0; decode_hex(txid.bytes,32,retstr); } - fprintf(stderr,"broadcast %s txid.(%s)\n",acname,bits256_str(str,txid)); + fprintf(stderr,"broadcast %s txid.(%s)\n",strlen(acname)>0?acname:refcoin,bits256_str(str,txid)); free(retstr); } } @@ -637,14 +637,12 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad change = (total - satoshis); jaddnum(vouts,depositaddr,(double)change/SATOSHIDEN); } - char *tmpA=jprint(vins,1); - char *tmpB=jprint(vouts,1); + char *tmpA=jprint(vins,0); + char *tmpB=jprint(vouts,0); char *argA=malloc(sizeof(char) * (strlen(tmpA)+3)); char *argB=malloc(sizeof(char) * (strlen(tmpB)+3)); sprintf(argA,"\'%s\'",tmpA); - sprintf(argB,"\'%s\'",tmpB); - printf("%s\n",argA); - printf("%s\n",argB); + sprintf(argB,"\'%s\'",tmpB); if ( (retjson2= get_komodocli(refcoin,&txstr,acname,"createrawtransaction",argA,argB,"","")) != 0 ) { printf("createmultisig: unexpected JSON2.(%s)\n",jprint(retjson2,0)); @@ -658,6 +656,7 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad free(argB); } } + free_json(retjson); } else if ( retstr != 0 ) { From d988726d5ffb11a93b4315d2213dc64361b5a3b2 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 17:14:29 +0100 Subject: [PATCH 382/749] Fix --- src/cc/dapps/oraclefeed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 0ff12bee5..62f9c3254 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -637,8 +637,8 @@ char *createmultisig(char *refcoin,char *acname,char *depositaddr,char *signerad change = (total - satoshis); jaddnum(vouts,depositaddr,(double)change/SATOSHIDEN); } - char *tmpA=jprint(vins,0); - char *tmpB=jprint(vouts,0); + char *tmpA=jprint(vins,1); + char *tmpB=jprint(vouts,1); char *argA=malloc(sizeof(char) * (strlen(tmpA)+3)); char *argB=malloc(sizeof(char) * (strlen(tmpB)+3)); sprintf(argA,"\'%s\'",tmpA); From c6069e78595693ad750c8baf6c5d00b8c56d8650 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Wed, 31 Oct 2018 17:17:37 +0100 Subject: [PATCH 383/749] Fix --- src/cc/dapps/oraclefeed.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dapps/oraclefeed.c b/src/cc/dapps/oraclefeed.c index 62f9c3254..a0930bae4 100644 --- a/src/cc/dapps/oraclefeed.c +++ b/src/cc/dapps/oraclefeed.c @@ -1044,7 +1044,7 @@ int32_t main(int32_t argc,char **argv) printf("need to specify path to refcoin's cli as last argv\n"); exit(0); } - pubkeys=NULL; + pubkeys=0; if ( get_gatewaysinfo("KMD",acname,depositaddr,&M,&N,bindtxidstr,refcoin,oraclestr,&pubkeys) < 0 ) { printf("cant find bindtxid.(%s)\n",bindtxidstr); @@ -1055,7 +1055,7 @@ int32_t main(int32_t argc,char **argv) if (M==N==1) importaddress(refcoin,"",depositaddr); else addmultisigaddress(refcoin,"",M,pubkeys,bindtxidstr); } - if (pubkeys!=NULL) free(pubkeys); + if (pubkeys!=0) free(pubkeys); printf("set refcoin %s <- %s [%s] M.%d of N.%d\n",depositaddr,refcoin,REFCOIN_CLI,M,N); } if ( (regjson= jarray(&n,clijson,"registered")) != 0 ) From 20441562c3a70f0989832c8eadeda155908f4dc3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 17:05:31 +0800 Subject: [PATCH 384/749] fix --- src/cc/dice.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a7c412e1c..c5bebeba0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,17 +551,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); -<<<<<<< HEAD - else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - char str[65],str2[65],str3[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - return eval->Invalid("always should find looking vin.0, but didnt for wlt"); - } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); -======= else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("always should find looking vin.0, but didnt for wlt"); ->>>>>>> 19d614c8344b70a0d4a7da8620a2dd1168016abc + return eval->Invalid("always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) @@ -597,21 +588,12 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); return eval->Invalid("CC funds mismatch for win/timeout"); -<<<<<<< HEAD } else if ( tx.vout[3].scriptPubKey != fundingPubKey ) { if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); } -======= - } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } ->>>>>>> 19d614c8344b70a0d4a7da8620a2dd1168016abc iswin = (funcid == 'W'); } if ( iswin != 0 ) From ada693f7d3912f8bc50bb7682530ae658e88a346 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 19:09:26 +0800 Subject: [PATCH 385/749] add prints back --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 938cfdfe0..957060373 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - //fprintf(stderr, "added mempool tx to temp mempool\n"); + fprintf(stderr, "added mempool tx to temp mempool\n"); } // clear the mempool before importing all block txs to mempool. mempool.clear(); @@ -4320,7 +4320,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; bool fMissingInputs,fOverrideFees = false; if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; - //else fprintf(stderr, "added mempool tx back to mempool\n"); + else fprintf(stderr, "added mempool tx back to mempool\n"); } if ( 0 && invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); From bc2c46ebd74f5988ba8740db23cc27f1fc09ebe9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 21:23:15 +0800 Subject: [PATCH 386/749] true != false :) --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 957060373..5817525d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if (fNullifiers == false) + if ( fNullifiers == true ) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { From 39837a7c8c73689b8cf8e7d1a1f106672cb9a29a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 21:36:37 +0800 Subject: [PATCH 387/749] false is the default --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5817525d2..57f4a3ebc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if ( fNullifiers == true ) + if ( fNullifiers == false ) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { @@ -1454,7 +1454,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } // are the joinsplit's requirements met? - if ( fNullifiers == true ) + if ( fNullifiers == false ) { if (!view.HaveJoinSplitRequirements(tx)) { From 0e9c871b74b1864f95a5f5de1b1ee17ac72f6cf1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 21:59:05 +0800 Subject: [PATCH 388/749] mmm --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 57f4a3ebc..1c9a860f1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1404,7 +1404,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } - } + } else fprintf(stderr, "bool = true"); } { @@ -4318,6 +4318,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); CValidationState state; bool fMissingInputs,fOverrideFees = false; + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); From 993ada0a73574268826ab54ab55b7e4a8abd8d14 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:29:36 +0800 Subject: [PATCH 389/749] try to get vjoinsplit size --- src/main.cpp | 41 +++++++++++++++++++---------------------- src/main.h | 2 +- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c9a860f1..a5e02cb30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1310,7 +1310,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF } -bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, bool fNullifiers) +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee) { AssertLockHeld(cs_main); if (pfMissingInputs) @@ -1391,20 +1391,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if ( fNullifiers == false ) + BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { - BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) + BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) + if (pool.mapNullifiers.count(nf)) { - if (pool.mapNullifiers.count(nf)) - { - fprintf(stderr,"pool.mapNullifiers.count\n"); - return false; - } + fprintf(stderr,"pool.mapNullifiers.count\n"); + return false; } } - } else fprintf(stderr, "bool = true"); + } } { @@ -1454,13 +1451,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } // are the joinsplit's requirements met? - if ( fNullifiers == false ) + if (!view.HaveJoinSplitRequirements(tx)) { - if (!view.HaveJoinSplitRequirements(tx)) - { - //fprintf(stderr,"accept failure.2\n"); - return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); - } + //fprintf(stderr,"accept failure.2\n"); + return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); + } } // Bring the best block into scope view.GetBestBlock(); @@ -4258,11 +4253,13 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - fprintf(stderr, "added mempool tx to temp mempool\n"); + int vjoinsplit_size = tx.vjoinsplit.size(); + + //tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); + fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); } // clear the mempool before importing all block txs to mempool. - mempool.clear(); + //mempool.clear(); // add all the txs in the block to the empty mempool. while ( 1 ) { @@ -4312,14 +4309,14 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + /*if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); CValidationState state; bool fMissingInputs,fOverrideFees = false; - if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees) == false ) invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); } @@ -4327,7 +4324,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); - } + } */ return true; } diff --git a/src/main.h b/src/main.h index 244817a61..76e0f73ae 100644 --- a/src/main.h +++ b/src/main.h @@ -267,7 +267,7 @@ void PruneAndFlush(); /** (try to) add transaction to memory pool **/ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, - bool* pfMissingInputs, bool fRejectAbsurdFee=false, bool fNullifiers=false); + bool* pfMissingInputs, bool fRejectAbsurdFee=false); struct CNodeStateStats { From 536ba8f5dc9da035c3bffc92051d3d8b9e1018cc Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:32:45 +0800 Subject: [PATCH 390/749] } --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a5e02cb30..7597eee95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1456,7 +1456,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"accept failure.2\n"); return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); } - } // Bring the best block into scope view.GetBestBlock(); From a8b0ae0d111b45a882b054232958f8a6a148a5c2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:44:53 +0800 Subject: [PATCH 391/749] try this to stop ztx beig removed from mempool --- src/main.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7597eee95..3c5acd464 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4249,16 +4249,20 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C //fprintf(stderr,"put block's tx into mempool\n"); // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); + BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - int vjoinsplit_size = tx.vjoinsplit.size(); - - //tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); + int vjoinsplit_size = ; + if ( tx.vjoinsplit.size() == 0 ) { + tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); + list removed; + mempool.remove(tx, removed, false); + } else { + // is a z-tx so leave it alone! + fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); + } } - // clear the mempool before importing all block txs to mempool. - //mempool.clear(); // add all the txs in the block to the empty mempool. while ( 1 ) { @@ -4308,7 +4312,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - /*if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { @@ -4319,11 +4323,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); } - if ( 0 && invalidtxs > 0 ) + if ( invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); - } */ + } return true; } From b5a999bc46ae3b7d80f37770ee6c42a51e962ce1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:46:49 +0800 Subject: [PATCH 392/749] fix --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3c5acd464..271d8e2cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4253,7 +4253,6 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - int vjoinsplit_size = ; if ( tx.vjoinsplit.size() == 0 ) { tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); list removed; From b3ab073a7a1ad1a8d9a4116ca08f9fe5147f91be Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:48:19 +0800 Subject: [PATCH 393/749] oops --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 271d8e2cc..2c28b3914 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); + fprintf(stderr, "tx vjoinsplit size: %d\n",tx.vjoinsplit.size()); } } // add all the txs in the block to the empty mempool. From fac4fbdee443ea6aa8c9b78fa9fa0a54fd74b68e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:49:40 +0800 Subject: [PATCH 394/749] ld --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2c28b3914..3561130bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",tx.vjoinsplit.size()); + fprintf(stderr, "tx vjoinsplit size: %ld\n",tx.vjoinsplit.size()); } } // add all the txs in the block to the empty mempool. From 8370c8d5bbdd6d4fda059e01e9dae185743652f0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:53:10 +0800 Subject: [PATCH 395/749] seg fault fix --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3561130bc..a28629528 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4253,13 +4253,14 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); + int txsize = tx.vjoinsplit.size(); if ( tx.vjoinsplit.size() == 0 ) { tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); list removed; mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %ld\n",tx.vjoinsplit.size()); + fprintf(stderr, "tx vjoinsplit size: %d\n",txsize; } } // add all the txs in the block to the empty mempool. From 3e3ce74e966ea15d54d7b13ee9d82051a25ed4a8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:54:35 +0800 Subject: [PATCH 396/749] ) --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a28629528..73cf8a7df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4260,7 +4260,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",txsize; + fprintf(stderr, "tx vjoinsplit size: %d\n",txsize); } } // add all the txs in the block to the empty mempool. From 5d5ec3d25f0ca0cab7d7e115ac4171ebaeb3686b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 23:03:35 +0800 Subject: [PATCH 397/749] try again --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 73cf8a7df..2b33ddef5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4249,20 +4249,23 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C //fprintf(stderr,"put block's tx into mempool\n"); // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); - + list transactionsToRemove; BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); int txsize = tx.vjoinsplit.size(); if ( tx.vjoinsplit.size() == 0 ) { + transactionsToRemove.push_back(tx); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - list removed; - mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! fprintf(stderr, "tx vjoinsplit size: %d\n",txsize); } } + BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { + list removed; + remove(tx, removed, false); + } // add all the txs in the block to the empty mempool. while ( 1 ) { From 6c7f8711d4cf8ecac4be0faf15883ba88c089963 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 23:05:19 +0800 Subject: [PATCH 398/749] oops --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2b33ddef5..560bd55ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4264,7 +4264,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C } BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { list removed; - remove(tx, removed, false); + mempool.remove(tx, removed, false); } // add all the txs in the block to the empty mempool. while ( 1 ) From 134db2dad7eeedc2a40e1b0ab61426b5f3629417 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 23:17:16 +0800 Subject: [PATCH 399/749] and we are done here --- src/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 560bd55ef..f6c8520d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4247,19 +4247,15 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { CValidationState stateDummy; int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); - // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. + // Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); list transactionsToRemove; BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - int txsize = tx.vjoinsplit.size(); if ( tx.vjoinsplit.size() == 0 ) { transactionsToRemove.push_back(tx); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - } else { - // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",txsize); } } BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { @@ -4315,8 +4311,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + if ( ASSETCHAINS_CC != 0 ) { + // here we add back all txs from the temp mempool to the main mempool. + // which removes any tx locally that were invalid after the block arrives. int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); @@ -4326,7 +4324,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); } - if ( invalidtxs > 0 ) + if ( 0 && invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); From 8d61613402578446cb27e05215734f1f25e805e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 04:45:20 -1100 Subject: [PATCH 400/749] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f6c8520d8..837e380de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4322,7 +4322,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees) == false ) invalidtxs++; - else fprintf(stderr, "added mempool tx back to mempool\n"); + //else fprintf(stderr, "added mempool tx back to mempool\n"); } if ( 0 && invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); From 7287d8c59011c0f9f321bd708d574ed54da38d6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 06:26:15 -1100 Subject: [PATCH 401/749] Return value in crosschainproof --- src/rpccrosschain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 09f1b21d1..2059ab452 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -50,7 +50,9 @@ UniValue assetchainproof(const UniValue& params, bool fHelp) UniValue crosschainproof(const UniValue& params, bool fHelp) { - + UniValue ret(UniValue::VOBJ); + fprintf(stderr,"crosschainproof needs to be implemented\n"); + return(ret); } From 1a0239ba0dde4911a1b83886d976f79de7d12943 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 06:49:02 -1100 Subject: [PATCH 402/749] Fix compiler issues --- src/komodo_bitcoind.h | 2 +- src/komodo_globals.h | 2 +- src/rpcserver.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 73a49e10c..76216efee 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) return(segid); } -int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) +void komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) { static uint8_t prevhashbuf[100]; static int32_t prevheight; int32_t i; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 1ebfdd16c..6d0b10328 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -58,7 +58,7 @@ uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; +char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d41d77056..f9abbc44f 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -242,7 +242,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; UniValue stop(const UniValue& params, bool fHelp) { - char buf[64]; + char buf[66]; // Accept the deprecated and ignored 'detach' boolean argument if (fHelp || params.size() > 1) throw runtime_error( diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6ca3c8ed4..4ec42d117 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4532,7 +4532,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); -int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); +void komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { From 8fded6d999a34433e7374c239b816d68291862aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:02:39 -1100 Subject: [PATCH 403/749] Fix compiler warning --- src/rpcserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index f9abbc44f..393545a63 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -242,7 +242,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; UniValue stop(const UniValue& params, bool fHelp) { - char buf[66]; + char buf[66+128]; // Accept the deprecated and ignored 'detach' boolean argument if (fHelp || params.size() > 1) throw runtime_error( From 7fe7c221581bbb84a6e54c74b40570d2e3204f55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:11:29 -1100 Subject: [PATCH 404/749] fix Compiler warnings --- src/cc/CCtx.cpp | 3 +-- src/cc/CCutils.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 60b52fba0..eb606f385 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -33,9 +33,8 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip UpdateTransaction(mtx,vini,sigdata); return(true); } else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); -#else - return(false); #endif + return(false); } std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index d4de992f7..ce736ba7a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -74,6 +74,7 @@ CC* GetCryptoCondition(CScript const& scriptSig) std::vector ffbin; if (scriptSig.GetOp(pc, opcode, ffbin)) return cc_readFulfillmentBinary((uint8_t*)ffbin.data(), ffbin.size()-1); + else return(0); } bool IsCCInput(CScript const& scriptSig) From 0d888fcd328d535e4744dc0fdd6c19d6b4d5728f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 1 Nov 2018 11:16:57 -0700 Subject: [PATCH 405/749] Add jsindex to z_listreceivedbyaddress to uniquely identify them --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e7c8e2bdd..3d419a734 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3419,6 +3419,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) " \"txid\": xxxxx, (string) the transaction id\n" " \"amount\": xxxxx, (numeric) the amount of value in the note\n" " \"memo\": xxxxx, (string) hexademical string representation of memo field\n" + " \"jsindex\": xxxxx, (numeric) the JoinSplit index\n" "}\n" "\nExamples:\n" + HelpExampleCli("z_listreceivedbyaddress", "\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") @@ -3460,6 +3461,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value)))); std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end()); obj.push_back(Pair("memo", HexStr(data))); + obj.push_back(Pair("jsindex", entry.jsop.js)); result.push_back(obj); } return result; From 0751d17dadb127c0c2fc41e585e5bf7d428dec3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:17:40 -1100 Subject: [PATCH 406/749] Fix --- src/cc/lotto.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 7129bfcd8..dcde90e78 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -295,6 +295,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,funding,lottopk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_LOTTO << (uint8_t)'F' << sbits << ticketsize << odds << firstheight << period << hentropy))); } + return(""); } std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) From 0cf7cae07c6d9afb96acc563a7954f2fd2255e91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:25:45 -1100 Subject: [PATCH 407/749] Syntax --- src/cc/channels.cpp | 4 ++-- src/cc/gateways.cpp | 2 +- src/cc/oracles.cpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index d92186d26..ec5f7aa9c 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -692,7 +692,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; - struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[256],str2[256]; int32_t vout,numvouts,param1,numpayments; + struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[512],str2[256]; int32_t vout,numvouts,param1,numpayments; int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; @@ -768,4 +768,4 @@ UniValue ChannelsInfo(uint256 channeltxid) } } return(result); -} \ No newline at end of file +} diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 26c800a98..b6fcb2136 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -143,7 +143,7 @@ */ -int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) +void GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) { char destaddr[64],str[65]; Getscriptaddress(destaddr,scriptPubKey); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 0c7d9e6e2..524eba9c2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -440,6 +440,7 @@ int64_t correlate_price(int32_t height,int64_t *prices,int32_t n) for (i=0; i %llu ht.%d\n",(long long)price,height); + return(price); } int64_t OracleCorrelatedPrice(int32_t height,std::vector origprices) From dbf864cfccf2aa063062b369add8bca8c404ff55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:33:41 -1100 Subject: [PATCH 408/749] Return 0 for unfound epoch --- src/consensus/upgrades.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index c913c7ea0..1dd3fe706 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -69,6 +69,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) { return idxInt; } } + return(0); // jl777 seems the right value to return } uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) { From 74bb69faef553d4b798a64dd20c189fad8ea00e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 02:08:56 -1100 Subject: [PATCH 409/749] Disable checktx in miner loop --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index fcc8d6127..ee3f7e680 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -335,6 +335,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"dont have inputs\n"); continue; } + if ( 0 ) { CValidationState state; auto verifier = libzcash::ProofVerifier::Disabled(); From 62259bc366c61b2862b4cabbd5779ee685e26279 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 02:14:53 -1100 Subject: [PATCH 410/749] +print --- src/miner.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ee3f7e680..17e39cf7e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -194,7 +194,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { - //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); continue; } if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) @@ -272,7 +272,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) porphan->feeRate = feeRate; } else + { vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); + fprintf(stderr,"."); + } } // Collect transactions into block @@ -299,7 +302,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx { - //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } @@ -307,7 +310,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) { - //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); continue; } // Skip free transactions if we're past the minimum block size: @@ -317,7 +320,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) { - //fprintf(stderr,"fee rate skip\n"); + fprintf(stderr,"fee rate skip\n"); continue; } // Prioritise by fee once past the priority size or we run out of high-priority @@ -332,7 +335,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (!view.HaveInputs(tx)) { - //fprintf(stderr,"dont have inputs\n"); + fprintf(stderr,"dont have inputs\n"); continue; } if ( 0 ) From fa2254513b791ff3c81ac3120d920d98a06b5afb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 04:22:14 -1100 Subject: [PATCH 411/749] -prints --- src/miner.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 17e39cf7e..ee3f7e680 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -194,7 +194,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { - fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); continue; } if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) @@ -272,10 +272,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) porphan->feeRate = feeRate; } else - { vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); - fprintf(stderr,"."); - } } // Collect transactions into block @@ -302,7 +299,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx { - fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } @@ -310,7 +307,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) { - fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); continue; } // Skip free transactions if we're past the minimum block size: @@ -320,7 +317,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) { - fprintf(stderr,"fee rate skip\n"); + //fprintf(stderr,"fee rate skip\n"); continue; } // Prioritise by fee once past the priority size or we run out of high-priority @@ -335,7 +332,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (!view.HaveInputs(tx)) { - fprintf(stderr,"dont have inputs\n"); + //fprintf(stderr,"dont have inputs\n"); continue; } if ( 0 ) From 744882bedf9b198edabf16fe7b7c2010b6c79e94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 05:09:29 -1100 Subject: [PATCH 412/749] Fix txfee for 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 c5bebeba0..58dac192e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1025,7 +1025,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 winlosetimeout = 0; } } - if ( AddNormalinputs(mtx,mypk,txfee,1) == 0 ) + if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 7f34ac4227d4b5266289d09d4a3d6a864a6aa478 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 05:11:03 -1100 Subject: [PATCH 413/749] Reallocate utxo --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 58dac192e..247ac9f7f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1025,7 +1025,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 winlosetimeout = 0; } } - if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) + if ( AddNormalinputs(mtx,mypk,2*txfee,4) == 0 ) { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1077,7 +1077,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 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 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,56,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From c680de514ac64fa25560a7eda46ed9b32042b162 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:19:20 -1100 Subject: [PATCH 414/749] +prints --- src/cc/dice.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 247ac9f7f..9c35e3947 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1016,7 +1016,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 return(""); } fundingpk = DiceFundingPk(fundingPubKey); - if ( winlosetimeout != 0 ) + if ( winlosetimeout != 0 ) // must be dealernode { scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( scriptPubKey != fundingPubKey ) @@ -1033,39 +1033,49 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { + if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) + { + CCerror = "bettxid already spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - if ( winlosetimeout != 0 ) - winlosetimeout = iswin; - if ( iswin == winlosetimeout ) + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) - { - CCerror = "bettxid already spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - //fprintf(stderr,"iswin.%d matches\n",iswin); + CCerror = "bettxid already spent in mempool"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + if ( winlosetimeout != 0 ) // dealernode + { + fprintf(stderr,"set winlosetimeout <- %d\n",winlosetimeout,iswin); + if ( (winlosetimeout= iswin) > 0 ) + funcid = 'W'; + else funcid = 'L'; + } + if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here + { + fprintf(stderr,"iswin.%d matches\n",iswin); mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); - if ( iswin == 0 ) + if ( iswin == 0 && funcid != 'L' && funcid != 'W' ) // normal node path { - funcid = 'T'; if ( DiceVerifyTimeout(betTx,timeoutblocks) == 0 ) // hasnt timed out yet { return(""); } else { + funcid = 'T'; hentropy = hentropyproof = zeroid; iswin = 1; + fprintf(stderr,"set timeout win T\n"); } } - if ( iswin > 0 ) + if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { - if ( funcid != 'T' ) - funcid = 'W'; odds = (betTx.vout[2].nValue - txfee); if ( odds < 1 || odds > maxodds ) { @@ -1092,13 +1102,13 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); mtx.vout.push_back(CTxOut((odds+1) * betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); } - else + else // dealernode 'L' path { funcid = 'L'; mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue + betTx.vout[1].nValue,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } - if ( winlosetimeout != 0 ) + if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; //char str[65],str2[65]; From f437dbbd26ab6127e4cbfe0b08ff3596de6faebb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:20:42 -1100 Subject: [PATCH 415/749] Fix --- 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 9c35e3947..005fcd69b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1050,7 +1050,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( winlosetimeout != 0 ) // dealernode { - fprintf(stderr,"set winlosetimeout <- %d\n",winlosetimeout,iswin); + fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); if ( (winlosetimeout= iswin) > 0 ) funcid = 'W'; else funcid = 'L'; From ba7490562d73cdf227e375348ec700b60241be22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:28:09 -1100 Subject: [PATCH 416/749] spentindex --- src/cc/dice.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 005fcd69b..c1fe8962a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1033,12 +1033,25 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { - if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) + CSpentIndexKey key(bettxid, 0); + CSpentIndexValue value; + CSpentIndexKey key2(bettxid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + /*if ( CCtxidvalue(cp->unspendableCCaddr,bettxid,0) != 0 && CCtxidvalue(cp->unspendableCCaddr,bettxid,1) != 0 ) // already confirmed + { + if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) // but not unspent -> spent + { + CCerror = "bettxid already spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { From 3e4aad6087a23fdabec81277698a524ced115d1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:41:32 -1100 Subject: [PATCH 417/749] -print --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c1fe8962a..7d3c15fb8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -641,13 +641,15 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { char str[65],sstr[16]; unstringbits(sstr,sbits); - fprintf(stderr,"(%c) %.8f %s %s\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); if ( sbits == refsbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' ) { if ( total != 0 && maxinputs != 0 ) + { + fprintf(stderr,"use (%c) %.8f %s %s\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); mtx.vin.push_back(CTxIn(txid,vout,CScript())); + } totalinputs += it->second.satoshis; n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) From 5d593cb7f8037ea4bc41f8bf943b35ff60422a84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:44:33 -1100 Subject: [PATCH 418/749] +print --- 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 7d3c15fb8..160646daf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -284,7 +284,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - //fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); + fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From 65e3f4086a53219338995a9aaf5d6ac82c197958 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:50:02 -1100 Subject: [PATCH 419/749] Test --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 160646daf..30a9ea4f5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -242,7 +242,6 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t fprintf(stderr,"%s\n", CCerror.c_str() ); return(0); } - //fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,houseentropy),uint256_str(str2,bettorentropy)); endiancpy(buf,(uint8_t *)&houseentropy,32); endiancpy(&buf[32],(uint8_t *)&bettorentropy,32); @@ -254,6 +253,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; + fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256 *)&house),uint256_str(str2,(uint256 *)&bettor)); if ( odds > 1 ) { if ( 0 ) @@ -1123,6 +1123,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue + betTx.vout[1].nValue,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } + fprintf(stderr,"make tx.%c\n",funcid); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; From 83944791499608c58bf1e539a2cf60c6ef9416c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:52:06 -1100 Subject: [PATCH 420/749] Fix --- 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 30a9ea4f5..de542485e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -253,7 +253,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; - fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256 *)&house),uint256_str(str2,(uint256 *)&bettor)); + fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256)house),uint256_str(str2,(uint256)bettor)); if ( odds > 1 ) { if ( 0 ) From 4475f431782cac1e070c8d68e95616d01649999f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:53:13 -1100 Subject: [PATCH 421/749] Test --- 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 de542485e..6646a78f4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -253,7 +253,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; - fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256)house),uint256_str(str2,(uint256)bettor)); + fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,*(uint256 *)&house),uint256_str(str2,*(uint256 *)&bettor)); if ( odds > 1 ) { if ( 0 ) From 6d402bbec6790de17ffd5aba42cef100d026adaa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:07:29 -1100 Subject: [PATCH 422/749] Track entropy used --- src/cc/dice.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6646a78f4..56b4da4a0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -103,19 +103,19 @@ struct dicefinish_info int32_t iswin; }; -bool mySendrawtransaction(std::string res) +bool mySendrawtransaction(std::string res,uint256 entropyused) { CTransaction tx; char str[65]; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { - fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); + //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); - fprintf(stderr,"added to mempool and broadcast\n"); + fprintf(stderr,"added to mempool and broadcast entropy.%s txid.%s\n",entropyused.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); @@ -125,7 +125,7 @@ bool mySendrawtransaction(std::string res) void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; + char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; sleep(3); // wait for bettxid to be in mempool for (i=0; iiswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); if ( duplicate == 0 ) { - res = DiceBetFinish(&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySendrawtransaction(res); + mySendrawtransaction(res,entropyused); } free(ptr); return(0); @@ -1006,9 +1006,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,entropyused; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + entropyused = zeriod; *resultp = 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 ) @@ -1065,6 +1066,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( winlosetimeout != 0 ) // dealernode { + entropyused = hentropyproof; fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); if ( (winlosetimeout= iswin) > 0 ) funcid = 'W'; @@ -1145,7 +1147,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropy,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1166,10 +1168,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - res = DiceBetFinish(&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySendrawtransaction(res); + mySendrawtransaction(res,entropyused); n++; } else { @@ -1206,11 +1208,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); + else res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySendrawtransaction(res); + mySendrawtransaction(res,entropyused); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From 2931bccdfa2a8f243a1f82c0d4f56f550109e2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:20:38 -1100 Subject: [PATCH 423/749] Track entropy/bettxid/finishtx --- src/cc/CCinclude.h | 1 - src/cc/dice.cpp | 30 +++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 8be4bce29..2a2d41ef0 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -96,7 +96,6 @@ bool myAddtomempool(CTransaction &tx); //uint64_t myGettxout(uint256 hash,int32_t n); 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); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 56b4da4a0..471401588 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -103,7 +103,7 @@ struct dicefinish_info int32_t iswin; }; -bool mySendrawtransaction(std::string res,uint256 entropyused) +bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) { CTransaction tx; char str[65]; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -115,7 +115,7 @@ bool mySendrawtransaction(std::string res,uint256 entropyused) if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); - fprintf(stderr,"added to mempool and broadcast entropy.%s txid.%s\n",entropyused.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + fprintf(stderr,"added to mempool and broadcast entropyused.%s bettxid.%s -> txid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); @@ -151,7 +151,7 @@ void *dicefinish(void *_ptr) { res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySendrawtransaction(res,entropyused); + mySenddicetransaction(res,entropyused,ptr->bettxid); } free(ptr); return(0); @@ -224,12 +224,15 @@ int32_t dice_5nibbles(uint8_t *fivevals) return(((int32_t)fivevals[0]<<16) + ((int32_t)fivevals[1]<<12) + ((int32_t)fivevals[2]<<8) + ((int32_t)fivevals[3]<<4) + ((int32_t)fivevals[4])); } -uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) +uint64_t DiceCalc(int64_t bet,int64_t vout2,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) { - uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 house,bettor; char str[65],str2[65]; int32_t i,modval; - if ( odds < 10000 ) + uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t odds,winnings; arith_uint256 house,bettor; char str[65],str2[65]; int32_t i,modval; + if ( vout2 <= 10000 ) + { + fprintf(stderr,"unexpected vout2.%llu\n",(long long)vout2); return(0); - else odds -= 10000; + } + else odds = (vout2 - 10000); if ( bet < minbet || bet > maxbet ) { CCerror = strprintf("bet size violation %.8f",(double)bet/COIN); @@ -963,7 +966,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = "bet must be positive"; return(""); } - if ( odds < 1 || odds > 9999 ) + if ( odds < 2 || odds > 9999 ) { error = "odds must be between 1 and 9999"; return(""); @@ -1036,6 +1039,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { + entropytxid = betTx.vin[0].prevout.hash; CSpentIndexKey key(bettxid, 0); CSpentIndexValue value; CSpentIndexKey key2(bettxid, 1); @@ -1171,7 +1175,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySendrawtransaction(res,entropyused); + mySenddicetransaction(res,entropyused,txid); n++; } else { @@ -1180,15 +1184,15 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( 0 && scriptPubKey == fundingPubKey ) + /*if ( 0 && scriptPubKey == fundingPubKey ) { for (i=0; i<=n; i++) { res = DiceAddfunding(txfee,planstr,fundingtxid,COIN); fprintf(stderr,"ENTROPY tx:\n"); - mySendrawtransaction(res); + mySenddicetransaction(res,entropyused,bettxid); } - } + }*/ return(n); } else @@ -1212,7 +1216,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySendrawtransaction(res,entropyused); + mySenddicetransaction(res,entropyused,bettxid); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From 159985c954c106f9a6607c2ea34553c15b3e91eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:23:08 -1100 Subject: [PATCH 424/749] Fix --- src/cc/CCdice.h | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index a01ddd295..0a4cf21ee 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); -std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1811ff7dc..52409f4c3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6183,7 +6183,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicefinish(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string hex; int32_t r; + UniValue result(UniValue::VOBJ); char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -6197,7 +6197,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1); + hex = DiceBetFinish(entropyused,&r,0,name,fundingtxid,bettxid,1); if ( CCerror != "" ) { ERR_RESULT(CCerror); From 6a0e165e304ef34d040383299a082449830c4315 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:25:02 -1100 Subject: [PATCH 425/749] 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 471401588..c5af7f37c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1011,8 +1011,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,entropyused; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; - entropyused = zeriod; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + entropyused = zeroid; *resultp = 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 ) @@ -1151,7 +1151,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropy,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropyused,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; From add9d4fe7eda25fe662760caad4f50424bdba57d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:26:24 -1100 Subject: [PATCH 426/749] 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 c5af7f37c..57e04c6a5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1172,7 +1172,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { mySenddicetransaction(res,entropyused,txid); @@ -1212,8 +1212,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); + else res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid); From f66948660d1d0bad6b0e1ce7bb91b5c11d38ecc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:39:40 -1100 Subject: [PATCH 427/749] -print --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 57e04c6a5..fb7e5cda3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -256,7 +256,7 @@ uint64_t DiceCalc(int64_t bet,int64_t vout2,int64_t minbet,int64_t maxbet,int64_ vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; - fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,*(uint256 *)&house),uint256_str(str2,*(uint256 *)&bettor)); + //fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,*(uint256 *)&house),uint256_str(str2,*(uint256 *)&bettor)); if ( odds > 1 ) { if ( 0 ) @@ -968,7 +968,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } if ( odds < 2 || odds > 9999 ) { - error = "odds must be between 1 and 9999"; + error = "odds must be between 2 and 9999"; return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) From 912ab71c94e0bd08c879916048a847c3e66d8f7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:10:09 -1100 Subject: [PATCH 428/749] Detect reused entropy --- src/cc/dice.cpp | 60 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fb7e5cda3..0b7bdd6be 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -94,7 +94,9 @@ WARNING: there is an attack vector that precludes betting any large amounts, it #include "../compat/endian.h" -static uint256 bettxids[128]; +#define MAX_ENTROPYUSED 8192 + +static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable struct dicefinish_info { @@ -103,6 +105,21 @@ struct dicefinish_info int32_t iswin; }; +int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) +{ + int32_t i; + if ( entropyused == zeroid || bettxid == zeroid ) + return(0); + for (i=0; i txid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) + { + for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); @@ -128,7 +162,7 @@ void *dicefinish(void *_ptr) char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; sleep(3); // wait for bettxid to be in mempool - for (i=0; ibettxid ) { duplicate = 1; @@ -136,13 +170,13 @@ void *dicefinish(void *_ptr) } if ( duplicate == 0 ) { - for (i=0; ibettxid; break; } - if ( i == sizeof(bettxids)/sizeof(*bettxids) ) + if ( i == MAX_ENTROPYUSED ) bettxids[rand() % i] = ptr->bettxid; } unstringbits(name,ptr->sbits); @@ -510,7 +544,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vout[0] != entropy nValue for bet"); else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[1] constrain violation for bet"); - else if ( tx.vout[2].nValue > txfee+maxodds || tx.vout[2].nValue < txfee ) + else if ( tx.vout[2].nValue > txfee+maxodds || tx.vout[2].nValue <= txfee ) return eval->Invalid("vout[2] nValue violation for bet"); else if ( eval->GetTxUnconfirmed(vinTx.vin[0].prevout.hash,vinofvinTx,hashBlock) == 0 || vinofvinTx.vout.size() < 1 ) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); @@ -884,7 +918,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) + if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 2 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1071,14 +1105,20 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); + if ( DiceEntropyUsed(entropyused,bettxid) < 0 ) + { + CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + //fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); if ( (winlosetimeout= iswin) > 0 ) funcid = 'W'; else funcid = 'L'; } if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here { - fprintf(stderr,"iswin.%d matches\n",iswin); + //fprintf(stderr,"iswin.%d matches\n",iswin); mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); if ( iswin == 0 && funcid != 'L' && funcid != 'W' ) // normal node path @@ -1098,7 +1138,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); - if ( odds < 1 || odds > maxodds ) + if ( odds < 2 || odds > maxodds ) { CCerror = strprintf("illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); fprintf(stderr,"%s\n", CCerror.c_str() ); From edbc54c0725cca87b5fe52f8b341a510e4dced6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:10:52 -1100 Subject: [PATCH 429/749] Test --- 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 0b7bdd6be..a780a883b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -122,7 +122,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) { - CTransaction tx; char str[65]; + CTransaction tx; char str[65]; int32_t i; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) From 5e90003b1304cf2391d0d74412e36acda9e180f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:11:30 -1100 Subject: [PATCH 430/749] Test --- 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 a780a883b..b28178b58 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -135,7 +135,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) { for (i=0; i Date: Tue, 6 Nov 2018 01:15:39 -1100 Subject: [PATCH 431/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b28178b58..c328c552b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -94,7 +94,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it #include "../compat/endian.h" -#define MAX_ENTROPYUSED 8192 +#define MAX_ENTROPYUSED 3 static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -321,7 +321,7 @@ uint64_t DiceCalc(int64_t bet,int64_t vout2,int64_t minbet,int64_t maxbet,int64_ break; } } - fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); + //fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From 6933a0c17b5a19c9c6bb6c36212e5764b14cbdde Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:30:19 -1100 Subject: [PATCH 432/749] Test --- src/cc/dice.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c328c552b..bd4c2950c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1210,6 +1210,20 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx vout = (int32_t)it->first.index; if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + CSpentIndexKey key(txid, 0); + CSpentIndexValue value; + CSpentIndexKey key2(txid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); + continue; + } + if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; + } if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); @@ -1217,10 +1231,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid); n++; - } else - { - error = res; - } + } else error = res; } } } From 0e887331d3c5ed38515ad367576a7681864ca772 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:51:06 -1100 Subject: [PATCH 433/749] Test --- src/cc/dice.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bd4c2950c..c14245577 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -94,7 +94,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it #include "../compat/endian.h" -#define MAX_ENTROPYUSED 3 +#define MAX_ENTROPYUSED 8192 static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -1208,24 +1208,24 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - CSpentIndexKey key(txid, 0); - CSpentIndexValue value; - CSpentIndexKey key2(txid, 1); - CSpentIndexValue value2; - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); - continue; - } - if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; - } if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { + CSpentIndexKey key(txid, 0); + CSpentIndexValue value; + CSpentIndexKey key2(txid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); + continue; + } + if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; + } res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { From 1f168f18da10fa737200bfa7e0520ba636867687 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:57:24 -1100 Subject: [PATCH 434/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c14245577..b7f97725d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1138,7 +1138,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); - if ( odds < 2 || odds > maxodds ) + if ( odds < 1 || odds > maxodds ) { CCerror = strprintf("illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1218,7 +1218,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx CSpentIndexValue value2; if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); + //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) From e057cde6ea39445307304c9e4c66a7d13e78cdb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 02:28:05 -1100 Subject: [PATCH 435/749] Prevent double spending entropy --- 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 b7f97725d..e864612f1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -131,9 +131,9 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { - RelayTransaction(tx); if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) { + RelayTransaction(tx); for (i=0; i Date: Tue, 6 Nov 2018 02:29:49 -1100 Subject: [PATCH 436/749] Fix --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e864612f1..12143acc2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -128,10 +128,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - LOCK(cs_main); - if ( myAddtomempool(tx) != 0 ) + if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) { - if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) + LOCK(cs_main); + if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + return(true); } - return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); } From 4ed6e1d12d51f7ecc01d1604c3dbb0f33eb757f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 02:30:51 -1100 Subject: [PATCH 437/749] Test --- 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 12143acc2..e00a46c40 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1268,7 +1268,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid); - sleep(1); + usleep(100000); 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 ) From 587899e2dcf3a08253ffebc558aa05b5c42d8425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 02:57:41 -1100 Subject: [PATCH 438/749] Test --- src/cc/dice.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e00a46c40..0af61f02d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -109,12 +109,16 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) { int32_t i; if ( entropyused == zeroid || bettxid == zeroid ) + { + fprintf(stderr,"null entropyused or bettxid\n"); return(0); + } for (i=0; i= 0 ) { LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) From 8f8100e3d0820c6c99291832cba45db9efe4bf53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 04:47:54 -1100 Subject: [PATCH 439/749] Test --- src/cc/dice.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0af61f02d..53ff64e23 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -658,6 +658,16 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return(true); } +// jl777: need to make it bestfit +/* fix: bidTx.0281db86a2b45bf73a0e674ec40ca4866fc54298c677d42c5dd8c71254d127f1 +entropyTx.671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c v0 +entropyTx vin0 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 v0 +76a9141f64ce357cb254464c2d5a9c06ca8d0c0ca9be9488ac script vs 210354ad90c26923962bbdfc7fd4956cb52db73682b58df9ee3ffc4751e61c8d465dac (B) entropy vin.0 fundingPubKey mismatch 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 +CC Eval EVAL_DICE Invalid: vin1 of entropy tx not fundingPubKey for bet spending tx 671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c*/ + +/*make tx.L +CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae96b78bd46965066fed7f7fa5838faed9588e62bcd4a406f478eecd5*/ + uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; @@ -668,7 +678,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 1000000 ) + if ( it->second.satoshis < 10000 ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j Date: Tue, 6 Nov 2018 04:55:23 -1100 Subject: [PATCH 440/749] Test --- src/cc/CCtx.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index eb606f385..d323c7e63 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -341,6 +341,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { + fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { for (i=0; itxid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; - //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); + fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); if ( n >= maxutxos ) break; } From 37aa6f8a7255bb87e2c23c6388a9254c28dff40d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 04:59:35 -1100 Subject: [PATCH 441/749] Test --- src/cc/CCtx.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d323c7e63..ea1136e00 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -341,6 +341,8 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { + if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/64 ) + continue; fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { @@ -365,7 +367,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); - if ( n >= maxutxos ) + if ( n >= maxinputs ) break; } } From 2efca535933955c84a93b2ba5612c504627bf59d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 05:05:10 -1100 Subject: [PATCH 442/749] Test --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ea1136e00..4787903c2 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -367,7 +367,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); - if ( n >= maxinputs ) + if ( n >= maxutxos ) break; } } From 9f9e730f0346fb891642508928de953d32c23408 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 05:11:30 -1100 Subject: [PATCH 443/749] Test --- 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 53ff64e23..fbf1baa73 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -627,7 +627,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vout[2] payut mismatch for win/timeout"); else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) { - fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); + fprintf(stderr,"inputs %.8f != outputs %.8f (%.8f %.8f %.8f %.8f)\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[0].nValue/COIN,(double)tx.vout[1].nValue/COIN,(double)tx.vout[2].nValue/COIN,(double)tx.vout[3].nValue/COIN); return eval->Invalid("CC funds mismatch for win/timeout"); } else if ( tx.vout[3].scriptPubKey != fundingPubKey ) From 22a5147c2ef556df0e8b92e77875ff88bce92ed3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 05:14:26 -1100 Subject: [PATCH 444/749] -print --- src/cc/CCtx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4787903c2..6db32ddc4 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -341,9 +341,9 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/64 ) + if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/16 ) continue; - fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); + //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { for (i=0; itxid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; - fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); + //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); if ( n >= maxutxos ) break; } From 5d4f7deada3a1a97d7db5876fca68690bd2b3042 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 09:34:27 -1100 Subject: [PATCH 445/749] Add inputs thresholding --- src/cc/CCtx.cpp | 5 +++-- src/cc/dice.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 6db32ddc4..9603d68fd 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -326,13 +326,14 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); + threshold = total/maxinputs; BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) @@ -341,7 +342,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/16 ) + if ( (out.tx->vout[out.i].nValue < threshold ) continue; //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fbf1baa73..26d33545f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -670,15 +670,18 @@ CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + if ( maxinputs > 0 ) + threshold = total / maxinputs; + else threshold = total / 64; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 10000 ) + if ( it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j Date: Tue, 6 Nov 2018 09:35:02 -1100 Subject: [PATCH 446/749] -( --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 9603d68fd..cee9d3a81 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -342,7 +342,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( (out.tx->vout[out.i].nValue < threshold ) + if ( out.tx->vout[out.i].nValue < threshold ) continue; //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) From ce99447bb48643e19dee8fdd0a523377485718ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 11:54:11 -1100 Subject: [PATCH 447/749] Threshold check in all CC addinputs --- src/cc/CCassetstx.cpp | 6 ++++-- src/cc/MofN.cpp | 1 + src/cc/auction.cpp | 1 + src/cc/dice.cpp | 19 ++++++------------- src/cc/faucet.cpp | 5 ++++- src/cc/fsm.cpp | 1 + src/cc/gateways.cpp | 5 ++++- src/cc/lotto.cpp | 1 + src/cc/payments.cpp | 1 + src/cc/pegs.cpp | 1 + src/cc/prices.cpp | 1 + src/cc/rewards.cpp | 5 +++-- src/cc/triggers.cpp | 1 + 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 5c933bd77..4bc1adc42 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,15 +17,17 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; for (j=0; j origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 7b5f106d0..d0d8db0bb 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -120,6 +120,7 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 26d33545f..1f1164a0d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -88,7 +88,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it Actually a much better solution to this is possible, which allows to retain the realtime response aspect of dice CC, which is critical to its usage. - +What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy */ @@ -138,6 +138,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); + // check to make sure it got accepted + for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } - } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } return(false); @@ -202,6 +204,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr->bettxid = bettxid; ptr->sbits = sbits; ptr->iswin = iswin; + // check for duplicates here!!! if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); @@ -658,16 +661,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return(true); } -// jl777: need to make it bestfit -/* fix: bidTx.0281db86a2b45bf73a0e674ec40ca4866fc54298c677d42c5dd8c71254d127f1 -entropyTx.671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c v0 -entropyTx vin0 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 v0 -76a9141f64ce357cb254464c2d5a9c06ca8d0c0ca9be9488ac script vs 210354ad90c26923962bbdfc7fd4956cb52db73682b58df9ee3ffc4751e61c8d465dac (B) entropy vin.0 fundingPubKey mismatch 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 -CC Eval EVAL_DICE Invalid: vin1 of entropy tx not fundingPubKey for bet spending tx 671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c*/ - -/*make tx.L -CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae96b78bd46965066fed7f7fa5838faed9588e62bcd4a406f478eecd5*/ - uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 676cb152c..3bf8a3476 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -142,14 +142,17 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 41601b437..9f9accbb5 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -122,6 +122,7 @@ bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b6fcb2136..a9fc6a4cd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -332,15 +332,18 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; fprintf(stderr,"check %s for gateway inputs\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; for (j=0; j origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 6cd751b8d..f3cd40ba2 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -115,6 +115,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index d9074bd49..21e371b4a 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -122,6 +122,7 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6ee0364e2..3d69ceec1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -129,6 +129,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { + // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,destaddr); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a70071af9..e7a3750f3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -325,15 +325,16 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r // '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; + char coinaddr[64],str[65]; uint64_t threshold,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); + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 1000000 ) + if ( it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); From e3df80b29ce1ece5553406f90812fa270ca080f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 11:57:28 -1100 Subject: [PATCH 448/749] -print --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1f1164a0d..63d429ffb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -463,7 +463,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + //char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { @@ -1179,7 +1179,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue + betTx.vout[1].nValue,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } - fprintf(stderr,"make tx.%c\n",funcid); + //fprintf(stderr,"make tx.%c\n",funcid); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; From 6e8402f5c15d824f7220f50d124f0ed6804bf4ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:06:22 -1100 Subject: [PATCH 449/749] Test --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 63d429ffb..84e15f282 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -95,6 +95,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 +extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -577,7 +578,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) if ( (iswin= DiceIsWinner(entropy,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { // will only happen for fundingPubKey - DiceQueue(iswin,sbits,fundingtxid,txid); + if ( KOMODO_INSYNC != 0 ) + DiceQueue(iswin,sbits,fundingtxid,txid); } break; // make sure all funding txid are from matching sbits and fundingtxid!! From 7a4eb293dd2a24b7ba2a688087c22d4ddebc68e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:07:42 -1100 Subject: [PATCH 450/749] +print --- 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 84e15f282..ee1d04f22 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -157,7 +157,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) } fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } From cd67001ea6adcd0119e725e8868407ba7aa1111c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:20:44 -1100 Subject: [PATCH 451/749] Timing prints --- src/cc/dice.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ee1d04f22..3cd0d3fde 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -90,6 +90,8 @@ WARNING: there is an attack vector that precludes betting any large amounts, it What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy + need to speed up dealer dicestatus loop (or in parallel) + */ #include "../compat/endian.h" @@ -1220,28 +1222,37 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; + fprintf(stderr,"A "); if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + fprintf(stderr,"B "); if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { + fprintf(stderr,"C "); CSpentIndexKey key(txid, 0); CSpentIndexValue value; CSpentIndexKey key2(txid, 1); CSpentIndexValue value2; + fprintf(stderr,"D "); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } + fprintf(stderr,"E "); if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } + fprintf(stderr,"["); res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + fprintf(stderr,"]"); if ( result > 0 ) { + fprintf(stderr,"("); mySenddicetransaction(res,entropyused,txid); + fprintf(stderr,"("); n++; } else error = res; } @@ -1280,7 +1291,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid); - usleep(100000); + sleep(1); 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 ) From 7e65cfea526e48c443438b4bb55d5593c2daac11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:27:49 -1100 Subject: [PATCH 452/749] +prints --- src/cc/dice.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3cd0d3fde..c26304092 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1069,6 +1069,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + fprintf(stderr,"0 "); fundingpk = DiceFundingPk(fundingPubKey); if ( winlosetimeout != 0 ) // must be dealernode { @@ -1079,14 +1080,17 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c winlosetimeout = 0; } } + fprintf(stderr,"1 "); if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + fprintf(stderr,"2 "); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { + fprintf(stderr,"3 "); entropytxid = betTx.vin[0].prevout.hash; CSpentIndexKey key(bettxid, 0); CSpentIndexValue value; @@ -1107,15 +1111,18 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c return(""); } }*/ + fprintf(stderr,"4 "); bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { + fprintf(stderr,"5 "); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { CCerror = "bettxid already spent in mempool"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + fprintf(stderr,"6 "); if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; @@ -1130,6 +1137,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c funcid = 'W'; else funcid = 'L'; } + fprintf(stderr,"7 "); if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here { //fprintf(stderr,"iswin.%d matches\n",iswin); @@ -1149,6 +1157,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"set timeout win T\n"); } } + fprintf(stderr,"8 "); if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); @@ -1184,11 +1193,13 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } //fprintf(stderr,"make tx.%c\n",funcid); + fprintf(stderr,"9 "); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; //char str[65],str2[65]; //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); + fprintf(stderr,"z "); return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); } else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout); } @@ -1222,24 +1233,24 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - fprintf(stderr,"A "); + //fprintf(stderr,"A "); if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - fprintf(stderr,"B "); + //fprintf(stderr,"B "); if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - fprintf(stderr,"C "); + //fprintf(stderr,"C "); CSpentIndexKey key(txid, 0); CSpentIndexValue value; CSpentIndexKey key2(txid, 1); CSpentIndexValue value2; - fprintf(stderr,"D "); + //fprintf(stderr,"D "); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } - fprintf(stderr,"E "); + //fprintf(stderr,"E "); if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); From 0173de95240baf2a77219cd93a7aad34d44adb86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:53:58 -1100 Subject: [PATCH 453/749] Remove mutex inside mutex --- src/cc/CCtx.cpp | 4 ++-- src/cc/dice.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index cee9d3a81..29942377e 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -330,7 +330,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); threshold = total/maxinputs; @@ -340,7 +340,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { txid = out.tx->GetHash(); vout = out.i; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( out.tx->vout[out.i].nValue < threshold ) continue; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c26304092..bf36d48c1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1263,7 +1263,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { fprintf(stderr,"("); mySenddicetransaction(res,entropyused,txid); - fprintf(stderr,"("); + fprintf(stderr,")"); n++; } else error = res; } From d8b84e4ef760502f170def437d2aad8144b8ef8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:00:15 -1100 Subject: [PATCH 454/749] Speed up addnormalinputs --- src/cc/CCtx.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 29942377e..e6a31fff6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -326,14 +326,16 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); threshold = total/maxinputs; + if ( maxinputs > maxutxos ) + maxutxos = maxinputs; BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) From 44a4e411eb48d119a48f83cc12f6641bcf30f3eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:09:53 -1100 Subject: [PATCH 455/749] Test --- src/cc/CCtx.cpp | 10 +++++----- src/cc/dice.cpp | 24 ------------------------ 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index e6a31fff6..320cd967d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -326,7 +326,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); @@ -336,16 +336,15 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 threshold = total/maxinputs; if ( maxinputs > maxutxos ) maxutxos = maxinputs; + sum = 0; BOOST_FOREACH(const COutput& out, vecOutputs) { - if ( out.fSpendable != 0 ) + if ( out.fSpendable != 0 && out.tx->vout[out.i].nValue >= threshold ) { txid = out.tx->GetHash(); vout = out.i; if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( out.tx->vout[out.i].nValue < threshold ) - continue; //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { @@ -369,8 +368,9 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->txid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; + sum += up->nValue; //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); - if ( n >= maxutxos ) + if ( n >= maxutxos || sum >= total ) break; } } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bf36d48c1..8084d1890 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1069,7 +1069,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - fprintf(stderr,"0 "); fundingpk = DiceFundingPk(fundingPubKey); if ( winlosetimeout != 0 ) // must be dealernode { @@ -1080,17 +1079,14 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c winlosetimeout = 0; } } - fprintf(stderr,"1 "); if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - fprintf(stderr,"2 "); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { - fprintf(stderr,"3 "); entropytxid = betTx.vin[0].prevout.hash; CSpentIndexKey key(bettxid, 0); CSpentIndexValue value; @@ -1102,27 +1098,15 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - /*if ( CCtxidvalue(cp->unspendableCCaddr,bettxid,0) != 0 && CCtxidvalue(cp->unspendableCCaddr,bettxid,1) != 0 ) // already confirmed - { - if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) // but not unspent -> spent - { - CCerror = "bettxid already spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - }*/ - fprintf(stderr,"4 "); bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - fprintf(stderr,"5 "); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { CCerror = "bettxid already spent in mempool"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - fprintf(stderr,"6 "); if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; @@ -1137,7 +1121,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c funcid = 'W'; else funcid = 'L'; } - fprintf(stderr,"7 "); if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here { //fprintf(stderr,"iswin.%d matches\n",iswin); @@ -1157,7 +1140,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"set timeout win T\n"); } } - fprintf(stderr,"8 "); if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); @@ -1193,13 +1175,11 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } //fprintf(stderr,"make tx.%c\n",funcid); - fprintf(stderr,"9 "); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; //char str[65],str2[65]; //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); - fprintf(stderr,"z "); return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); } else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout); } @@ -1256,14 +1236,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - fprintf(stderr,"["); res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); - fprintf(stderr,"]"); if ( result > 0 ) { - fprintf(stderr,"("); mySenddicetransaction(res,entropyused,txid); - fprintf(stderr,")"); n++; } else error = res; } From 22496dcbc3e57b5cee8745efacf09b956f768006 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:22:43 -1100 Subject: [PATCH 456/749] Remove lock from DiceStatus rpc, rely on internal locks --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 52409f4c3..15eb594bd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6217,7 +6217,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); From 82ee887ff66543610b23efd6094761335eff2b5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:29:59 -1100 Subject: [PATCH 457/749] +print --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8084d1890..b6323eaef 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -208,6 +208,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr->sbits = sbits; ptr->iswin = iswin; // check for duplicates here!!! + fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); From 284107e4de9bbe8a3cec702c41bde4a9d93e4ee3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 14:04:29 -1100 Subject: [PATCH 458/749] Limit dicestatus to 100 at a time --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b6323eaef..f5c0e2791 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -170,7 +170,7 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - sleep(3); // wait for bettxid to be in mempool + sleep(1); // wait for bettxid to be in mempool for (i=0; ibettxid ) { @@ -1242,6 +1242,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid); n++; + if ( n >= 100 ) + break; } else error = res; } } From b4568046f05d09126a2b164a98be1683f7ced3cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:43:01 -1100 Subject: [PATCH 459/749] Dicequeue dealer betstatus --- src/cc/dice.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f5c0e2791..5acf2ba94 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1197,7 +1197,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropyused,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1214,37 +1214,39 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - //fprintf(stderr,"A "); - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { - //fprintf(stderr,"B "); if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - //fprintf(stderr,"C "); CSpentIndexKey key(txid, 0); CSpentIndexValue value; CSpentIndexKey key2(txid, 1); CSpentIndexValue value2; - //fprintf(stderr,"D "); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } - //fprintf(stderr,"E "); if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + DiceQueue(iswin,sbits,fundingtxid,txid); + if ( n++ >= 100 ) + break; + } + /*res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { mySenddicetransaction(res,entropyused,txid); n++; if ( n >= 100 ) break; - } else error = res; + } else error = res;*/ } } } From 73b7c27c92940b8b69d2b2aa900fd599e0dc00c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:47:10 -1100 Subject: [PATCH 460/749] Revert --- src/cc/dice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5acf2ba94..e4cca9218 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1232,21 +1232,21 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - bettorentropy = DiceGetEntropy(betTx,'B'); + /*bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { DiceQueue(iswin,sbits,fundingtxid,txid); - if ( n++ >= 100 ) + if ( ++n >= 100 ) break; - } - /*res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + }*/ + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { mySenddicetransaction(res,entropyused,txid); n++; if ( n >= 100 ) break; - } else error = res;*/ + } else error = res; } } } From 2ade69f479c65373ccb71a0785822647e3da54e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:54:51 -1100 Subject: [PATCH 461/749] Filter dice queue --- src/cc/dice.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e4cca9218..ffa7e6dd8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -202,12 +202,26 @@ void *dicefinish(void *_ptr) void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) { - struct dicefinish_info *ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); + struct dicefinish_info *ptr; CSpentIndexValue value,value2; + CSpentIndexKey key(bettxid, 0); + CSpentIndexKey key2(bettxid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",txid.GetHex().c_str()); + return; + } + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + { + fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; + } + // check for duplicates here!!! + ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); ptr->fundingtxid = fundingtxid; ptr->bettxid = bettxid; ptr->sbits = sbits; ptr->iswin = iswin; - // check for duplicates here!!! fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { From 80f325e58ac45af93231e88467ae5e723f92ba7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:57:24 -1100 Subject: [PATCH 462/749] Syntax --- 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 ffa7e6dd8..202425f10 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -214,7 +214,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; + return; } // check for duplicates here!!! ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); From ed84dd46eb3d2f28d9c824739dc6672b3c6ee8f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:57:56 -1100 Subject: [PATCH 463/749] Syntax --- src/cc/dice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 202425f10..69e06a258 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -205,7 +205,6 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) struct dicefinish_info *ptr; CSpentIndexValue value,value2; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); - CSpentIndexValue value2; if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",txid.GetHex().c_str()); From 2c081ed1ba419343d24888176614be6bdf43e6c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:58:19 -1100 Subject: [PATCH 464/749] Syntax --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 69e06a258..283941101 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -207,12 +207,12 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",txid.GetHex().c_str()); + fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); return; } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",bettxid.GetHex().c_str()); return; } // check for duplicates here!!! From 3e7c0e4aa8b5ca495b7d56fc70054672cb7b66a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:59:41 -1100 Subject: [PATCH 465/749] -print --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e303c2bac..efbc4ddad 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -112,7 +112,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) ) errs++; - if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else @@ -257,7 +257,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long errs++; if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) ) errs++; - if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else From b80e05fd3865913df3609d5d8555fa474a9a62e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 20:00:35 -1100 Subject: [PATCH 466/749] +2 seconds sleep --- 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 283941101..2a4b4626b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -170,7 +170,7 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - sleep(1); // wait for bettxid to be in mempool + sleep(3); // wait for bettxid to be in mempool for (i=0; ibettxid ) { From f19d264d502a2c0eecf5761d3c9f9dc328e845ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 20:08:49 -1100 Subject: [PATCH 467/749] +print --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2a4b4626b..b89a1eb59 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -170,7 +170,8 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - sleep(3); // wait for bettxid to be in mempool + usleep(1000000 + (rand() % 4000000)); // wait for bettxid to be in mempool + fprintf(stderr,"process Queue dicefinish %s\n",ptr->bettxid.GetHex().c_str()); for (i=0; ibettxid ) { From 1d6bc78c1ae10c927ddc98df3947856924d208fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 20:22:23 -1100 Subject: [PATCH 468/749] Reduce dice status and dice queue collisions --- src/cc/dice.cpp | 141 ++++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 64 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b89a1eb59..87cbdd049 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -168,42 +168,21 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; usleep(1000000 + (rand() % 4000000)); // wait for bettxid to be in mempool - fprintf(stderr,"process Queue dicefinish %s\n",ptr->bettxid.GetHex().c_str()); - for (i=0; ibettxid ) - { - duplicate = 1; - break; - } - if ( duplicate == 0 ) - { - for (i=0; ibettxid; - break; - } - if ( i == MAX_ENTROPYUSED ) - bettxids[rand() % i] = ptr->bettxid; - } unstringbits(name,ptr->sbits); - //fprintf(stderr,"duplicate.%d dicefinish.%d %s funding.%s bet.%s\n",duplicate,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - if ( duplicate == 0 ) - { - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid); - } + fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid); free(ptr); return(0); } void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) { - struct dicefinish_info *ptr; CSpentIndexValue value,value2; + struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) @@ -217,16 +196,33 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) return; } // check for duplicates here!!! - ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); - ptr->fundingtxid = fundingtxid; - ptr->bettxid = bettxid; - ptr->sbits = sbits; - ptr->iswin = iswin; - fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); - if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) + for (i=0; ifundingtxid = fundingtxid; + ptr->bettxid = bettxid; + ptr->sbits = sbits; + ptr->iswin = iswin; + fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); + if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) + { + //fprintf(stderr,"DiceQueue.%d\n",iswin); + } // small memory leak per DiceQueue + } } CPubKey DiceFundingPk(CScript scriptPubKey) @@ -1211,7 +1207,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1232,35 +1228,52 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - CSpentIndexKey key(txid, 0); - CSpentIndexValue value; - CSpentIndexKey key2(txid, 1); - CSpentIndexValue value2; - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) - { - //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); - continue; - } - if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; - } - /*bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) - { - DiceQueue(iswin,sbits,fundingtxid,txid); - if ( ++n >= 100 ) + for (i=0; i 0 ) + } + if ( duplicate == 0 ) { - mySenddicetransaction(res,entropyused,txid); - n++; - if ( n >= 100 ) - break; - } else error = res; + for (i=0; i= 100 ) + break; + }*/ + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + if ( result > 0 ) + { + mySenddicetransaction(res,entropyused,txid); + n++; + if ( n >= 100 ) + break; + } //else error = res; + } } } } From 9c54755c5d487173ac415a84e17b969f742662b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:25:52 -1100 Subject: [PATCH 469/749] Store betTx --- src/cc/dice.cpp | 56 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 87cbdd049..d11abe234 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -100,15 +100,17 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable +static CTransaction betTxs[MAX_ENTROPYUSED]; struct dicefinish_info { uint256 fundingtxid,bettxid; uint64_t sbits; int32_t iswin; + CTransaction betTx; }; -int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) +int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; if ( entropyused == zeroid || bettxid == zeroid ) @@ -117,6 +119,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) return(0); } for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( DiceEntropyUsed(entropyused,bettxid) >= 0 ) + if ( DiceEntropyUsed(entropyused,bettxid,betTx) >= 0 ) { LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); // check to make sure it got accepted - - for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -170,24 +171,24 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - usleep(1000000 + (rand() % 4000000)); // wait for bettxid to be in mempool + usleep(1000000 + (rand() % 3000000)); // wait for bettxid to be in mempool unstringbits(name,ptr->sbits); fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid); + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); free(ptr); return(0); } -void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) +void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); + //fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); return; } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -215,9 +216,10 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); ptr->fundingtxid = fundingtxid; ptr->bettxid = bettxid; + ptr->betTx = betTx; ptr->sbits = sbits; ptr->iswin = iswin; - fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); + //fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); @@ -1121,7 +1123,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( DiceEntropyUsed(entropyused,bettxid) < 0 ) + if ( DiceEntropyUsed(entropyused,bettxid,betTx) < 0 ) { CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1268,7 +1270,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,txid); + mySenddicetransaction(res,entropyused,txid,betTx); n++; if ( n >= 100 ) break; @@ -1309,7 +1311,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid); + mySenddicetransaction(res,entropyused,bettxid,betTx); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From cd5fa72d42cedd2a1dba3fe7106def2e66d02727 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:29:21 -1100 Subject: [PATCH 470/749] Test --- src/cc/dice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d11abe234..7b6bf07e9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -132,15 +132,16 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) entropytxids[i][0] = entropyused; entropytxids[i][1] = bettxid; betTxs[i] = betTx; - return(0); + fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); + return(0); } } i = (rand() % MAX_ENTROPYUSED); - fprintf(stderr,"entropytxids full, pick rand.%d\n",i); entropytxids[i][0] = entropyused; entropytxids[i][1] = bettxid; betTxs[i] = betTx; - return(0); + fprintf(stderr,"added to rand mempool.[%d] and broadcast entropyused.%s bettxid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); + return(0); } bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx) @@ -154,11 +155,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C if ( DiceEntropyUsed(entropyused,bettxid,betTx) >= 0 ) { LOCK(cs_main); + RelayTransaction(tx); if ( myAddtomempool(tx) != 0 ) { - RelayTransaction(tx); - // check to make sure it got accepted - fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + //RelayTransaction(tx); return(true); } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); @@ -594,7 +594,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) - DiceQueue(iswin,sbits,fundingtxid,txid); + DiceQueue(iswin,sbits,fundingtxid,txid,tx); } break; // make sure all funding txid are from matching sbits and fundingtxid!! From 00f28499e9c80bdf7a53f9ac1967722b96b5387f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:38:36 -1100 Subject: [PATCH 471/749] Check bettxid in mempool --- src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 22 ++++++++++++++++------ src/rpcblockchain.cpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2a2d41ef0..749d676e9 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -95,6 +95,7 @@ int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx); //uint64_t myGettxout(uint256 hash,int32_t n); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); +bool mytxid_inmempool(uint256 txid); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7b6bf07e9..ae3e90c21 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -169,14 +169,24 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - usleep(1000000 + (rand() % 3000000)); // wait for bettxid to be in mempool unstringbits(name,ptr->sbits); - fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + usleep((rand() % 100000) + 10000); + for (i=0; i<600; i++) + { + usleep(100000); + if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + { + fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + break; + } + } + if ( i == 100 ) + fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 815860c7d..868431f6f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -378,6 +378,18 @@ bool myIsutxo_spentinmempool(uint256 txid,int32_t vout) return(false); } +bool mytxid_inmempool(uint256 txid) +{ + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); + if ( txid == hash ) + return(true); + } + return(false); +} + UniValue mempoolToJSON(bool fVerbose = false) { if (fVerbose) From a6b21d0d44c3f9c4efb499050723618883d51534 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:58:18 -1100 Subject: [PATCH 472/749] Guard adding to entropyused list --- src/cc/dice.cpp | 51 +++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ae3e90c21..29e9f9985 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -116,7 +116,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) if ( entropyused == zeroid || bettxid == zeroid ) { fprintf(stderr,"null entropyused or bettxid\n"); - return(0); + return(1); } for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( DiceEntropyUsed(entropyused,bettxid,betTx) >= 0 ) + if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) >= 0 ) { + if ( retval == 0 ) + { + for (i=0; i %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); @@ -172,7 +175,7 @@ void *dicefinish(void *_ptr) char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); - usleep((rand() % 100000) + 10000); + usleep((rand() % 1000000) + 100000); for (i=0; i<600; i++) { usleep(100000); @@ -185,7 +188,7 @@ void *dicefinish(void *_ptr) break; } } - if ( i == 100 ) + if ( i == 600 ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); @@ -1082,7 +1085,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); @@ -1133,9 +1136,11 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( DiceEntropyUsed(entropyused,bettxid,betTx) < 0 ) + if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) != 0 ) { - CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; + if ( retval < 0 ) + CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; + else CCerror = "DiceBetFinish: duplicate betTx"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } From e101468702fdb6b84738d4af4961e5a47f8d45b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:05:51 -1100 Subject: [PATCH 473/749] Test --- src/cc/dice.cpp | 6 +++++- src/main.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 29e9f9985..4056caa44 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -123,12 +123,16 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) if ( entropytxids[i][0] == entropyused ) { if ( bettxid == entropytxids[i][1] ) + { + fprintf(stderr,"found identical entropy used.%d\n",i); return(i+1); + } fprintf(stderr,"duplicate entropyused %s\n",entropyused.GetHex().c_str()); return(-1); } } - return(0); + fprintf(stderr,"cant find entropy used\n"); + return(0); } bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx) diff --git a/src/main.cpp b/src/main.cpp index 837e380de..1ba872d93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1681,8 +1681,10 @@ bool myAddtomempool(CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) + { + fprintf(stderr,"call AcceptToMemoryPool\n"); return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); - else return(true); + } else return(true); } bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) From 4a2e5ecded4bbb09ce4b2a2436a598c4a4184aa8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:17:27 -1100 Subject: [PATCH 474/749] +print --- src/cc/dice.cpp | 2 +- src/main.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4056caa44..8054b798d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -131,7 +131,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) return(-1); } } - fprintf(stderr,"cant find entropy used\n"); + //fprintf(stderr,"cant find entropy used\n"); return(0); } diff --git a/src/main.cpp b/src/main.cpp index 1ba872d93..65b0afa9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1331,7 +1331,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) { //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -1387,7 +1387,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //static uint32_t counter; // Disable replacement feature for now //if ( counter++ < 100 ) - //fprintf(stderr,"Disable replacement feature for now\n"); + fprintf(stderr,"Disable replacement feature for now\n"); return false; } } @@ -1438,7 +1438,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { if (pfMissingInputs) *pfMissingInputs = true; - //fprintf(stderr,"missing inputs\n"); + fprintf(stderr,"missing inputs\n"); return false; } } @@ -1682,7 +1682,7 @@ bool myAddtomempool(CTransaction &tx) CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { - fprintf(stderr,"call AcceptToMemoryPool\n"); + //fprintf(stderr,"call AcceptToMemoryPool\n"); return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); } else return(true); } From da58ee102bf32ca1ca019ed6795de5539514ba42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:34:33 -1100 Subject: [PATCH 475/749] -print --- src/cc/dice.cpp | 29 +++++++++++++---------------- src/main.cpp | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8054b798d..7d297c87a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -127,7 +127,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) fprintf(stderr,"found identical entropy used.%d\n",i); return(i+1); } - fprintf(stderr,"duplicate entropyused %s\n",entropyused.GetHex().c_str()); + fprintf(stderr,"duplicate entropyused %s bettxid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); return(-1); } } @@ -145,29 +145,26 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) >= 0 ) { - if ( retval == 0 ) - { - for (i=0; i %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } @@ -176,23 +173,23 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); usleep((rand() % 1000000) + 100000); - for (i=0; i<600; i++) + for (i=0; ibettxid) != 0 ) // wait for bettxid to be in mempool { - fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); break; } } - if ( i == 600 ) + if ( i == maxiters ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); diff --git a/src/main.cpp b/src/main.cpp index 65b0afa9c..cc69c215b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1387,7 +1387,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //static uint32_t counter; // Disable replacement feature for now //if ( counter++ < 100 ) - fprintf(stderr,"Disable replacement feature for now\n"); + //fprintf(stderr,"Disable replacement feature for now\n"); return false; } } @@ -1438,7 +1438,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { if (pfMissingInputs) *pfMissingInputs = true; - fprintf(stderr,"missing inputs\n"); + //fprintf(stderr,"missing inputs\n"); return false; } } From 1242e65eff39a01c944db3add0410d861dc25766 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:50:13 -1100 Subject: [PATCH 476/749] make unsupported funcid illegal --- src/cc/assets.cpp | 9 +++++++-- src/cc/channels.cpp | 4 ++++ src/cc/dice.cpp | 7 +++++++ src/cc/oracles.cpp | 4 ++++ src/cc/rewards.cpp | 4 ++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 1ddbdc4f8..b1896ad9c 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -249,8 +249,8 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } fprintf(stderr,"fillbuy validated\n"); break; - case 'e': // selloffer - break; // disable swaps + //case 'e': // selloffer + // break; // disable swaps case 's': // selloffer //vin.0: normal input //vin.1+: valid CC output for sale @@ -322,6 +322,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"fill validated\n"); break; case 'E': // fillexchange + return(false); break; // disable asset swaps //vin.0: normal input //vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0] @@ -371,6 +372,10 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } fprintf(stderr,"fill validated\n"); break; + default: + fprintf(stderr,"illegal assets funcid.(%c)\n",funcid); + return(false); + break; } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index ec5f7aa9c..7218177d7 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -348,6 +348,10 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("invalid amount, refund amount and funds in channel must match!"); } break; + default: + fprintf(stderr,"illegal channels funcid.(%c)\n",funcid); + return(false); + break; } } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7d297c87a..8c5640cfd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -685,6 +685,13 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( DiceVerifyTimeout(vinTx,timeoutblocks) == 0 ) return eval->Invalid("invalid timeout claim for timeout"); break; + case 'R': + fprintf(stderr,"add validation for refunds\n"); + break; + default: + fprintf(stderr,"illegal dice funcid.(%c)\n",funcid); + return(false); + break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 524eba9c2..6ee5b2400 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -651,6 +651,10 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; + default: + fprintf(stderr,"illegal oracles funcid.(%c)\n",funcid); + return(false); + break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index e7a3750f3..1f3408252 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -287,6 +287,10 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.2 isnt 0"); preventCCvouts = 1; break; + default: + fprintf(stderr,"illegal rewards funcid.(%c)\n",funcid); + return(false); + break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); From 69e54d0cfd6761bcca13e6935b1e5c60d5c92a81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:51:55 -1100 Subject: [PATCH 477/749] Syntax --- src/cc/oracles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 6ee5b2400..0f636551c 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -652,7 +652,7 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; default: - fprintf(stderr,"illegal oracles funcid.(%c)\n",funcid); + fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); return(false); break; } From a9545b529eca0a9cf5b429b6feba1655e35b80b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:24:27 -1100 Subject: [PATCH 478/749] Issue refund when entropy is compromised --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 53 +++++++++++++++++++++++++--------------- src/wallet/rpcwallet.cpp | 11 +++++++-- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 0a4cf21ee..47ecd1d88 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); -std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint8_t funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8c5640cfd..293473c4d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -110,9 +110,10 @@ struct dicefinish_info CTransaction betTx; }; -int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) +int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; + oldbettxid = zeroid; if ( entropyused == zeroid || bettxid == zeroid ) { fprintf(stderr,"null entropyused or bettxid\n"); @@ -127,7 +128,9 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) fprintf(stderr,"found identical entropy used.%d\n",i); return(i+1); } - fprintf(stderr,"duplicate entropyused %s bettxid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); + oldbettxid = entropytxids[i][1]; + oldbetTx = betTxs[i]; + fprintf(stderr,"duplicate entropyused %s oldbettxid.%s\n",entropyused.GetHex().c_str(),oldbettxid.GetHex().c_str()); return(-1); } } @@ -135,15 +138,15 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) return(0); } -bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx) +bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx,uint8_t funcid) { - CTransaction tx; int32_t i=0,retval; + CTransaction tx; int32_t i=0,retval=-1; uint256 oldbettxid; CTransaction oldBetTx; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) >= 0 ) + if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) { LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) @@ -173,7 +176,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; uint8_t funcid; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); usleep((rand() % 1000000) + 100000); @@ -183,9 +186,9 @@ void *dicefinish(void *_ptr) if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool { //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); break; } } @@ -1091,11 +1094,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbetxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; 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 ) { @@ -1144,11 +1148,19 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) != 0 ) + if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) { if ( retval < 0 ) - CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; - else CCerror = "DiceBetFinish: duplicate betTx"; + { + fprintf(stderr,"orphan that reveals entropy, generate refund tx with proofs\n"); + mtx.vin.push_back(CTxIn(bettxid,0,CScript())); + mtx.vin.push_back(CTxIn(bettxid,1,CScript())); + funcid = 'R'; + mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey)); + mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); + *resultp = 1; + return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,entropyused,oldbettxid))); // need to change opreturn to include oldbetTx to allow validation + } else CCerror = "DiceBetFinish: duplicate betTx"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1232,7 +1244,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1283,17 +1295,18 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - /*bettorentropy = DiceGetEntropy(betTx,'B'); + /*following didnt work: + bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { DiceQueue(iswin,sbits,fundingtxid,txid); if ( ++n >= 100 ) break; }*/ - res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,txid,betTx); + mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; if ( n >= 100 ) break; @@ -1330,11 +1343,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); + else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid,betTx); + mySenddicetransaction(res,entropyused,bettxid,betTx,funcid); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 15eb594bd..02d8f36fd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6183,7 +6183,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicefinish(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; + UniValue result(UniValue::VOBJ); uint8_t funcid; char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -6197,7 +6197,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(entropyused,&r,0,name,fundingtxid,bettxid,1); + hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1); if ( CCerror != "" ) { ERR_RESULT(CCerror); @@ -6205,6 +6205,13 @@ UniValue dicefinish(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); + if ( funcid != 0 ) + { + char funcidstr[2]; + funcidstr[0] = funcid; + funcidstr[1] = 0; + result.push_back(Pair("funcid", funcidstr)); + } } else ERR_RESULT( "couldnt create dicefinish transaction"); return(result); } From 59921a1d9b6618dd6380b1215d7da9e49792ca93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:27:00 -1100 Subject: [PATCH 479/749] Send 'R' refund tx --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 293473c4d..3a4a9ddbc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -164,10 +164,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C entropytxids[i][0] = entropyused; entropytxids[i][1] = bettxid; betTxs[i] = betTx; - fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); } + fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } else fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } From 21eaa7ce8af644507b8d154d6e058e3a92cd5ae9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:28:48 -1100 Subject: [PATCH 480/749] & --- src/cc/CCdice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 47ecd1d88..692d31462 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); -std::string DiceBetFinish(uint8_t funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); From ef8c10382b413e54265a8455b7e634b548e20869 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:30:23 -1100 Subject: [PATCH 481/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3a4a9ddbc..2f48330c4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -140,7 +140,7 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx,uint8_t funcid) { - CTransaction tx; int32_t i=0,retval=-1; uint256 oldbettxid; CTransaction oldBetTx; + CTransaction tx; int32_t i=0,retval=-1; uint256 oldbettxid; CTransaction oldbetTx; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) @@ -1096,7 +1096,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbetxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; From 0e364b89b1d0fba406c1426960a10c279d140ffa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:32:50 -1100 Subject: [PATCH 482/749] Use vout2 for refund --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2f48330c4..e57accbae 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1157,6 +1157,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, mtx.vin.push_back(CTxIn(bettxid,1,CScript())); funcid = 'R'; mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey)); + mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); *resultp = 1; return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,entropyused,oldbettxid))); // need to change opreturn to include oldbetTx to allow validation From 154528f0a18d9f3880a688f247912acf248b1e44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:49:41 -1100 Subject: [PATCH 483/749] Test --- src/cc/dice.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e57accbae..046696997 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -176,24 +176,31 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; uint8_t funcid; + char str[65],str2[65],name[32]; std::string res; int32_t i=0,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); - usleep((rand() % 1000000) + 100000); - for (i=0; ibettxid,betTx,hashBlock,false) == 0 || hashBlock == zeroid ) { - usleep(100000); - if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + usleep((rand() % 1000000) + 100000); + for (i=0; iiswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - break; + usleep(100000); + if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + { + //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + break; + } } - } + } else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); if ( i == maxiters ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); + else + { + res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + } free(ptr); return(0); } @@ -417,7 +424,7 @@ uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits } else if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> sbits; ss >> fundingtxid; ss >> hash; ss >> proof) != 0 ) { - if ( e == EVAL_DICE && (f == 'B' || f == 'W' || f == 'L' || f == 'T' || f == 'E') ) + if ( e == EVAL_DICE && (f == 'R' || f == 'B' || f == 'W' || f == 'L' || f == 'T' || f == 'E') ) return(f); else fprintf(stderr,"mismatched e.%02x f.(%c)\n",e,f); } From 86cecf71d1cef43d5223c65e54b67989494d3f87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:09:14 -1100 Subject: [PATCH 484/749] Test --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 046696997..c96545e7d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -597,7 +597,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { - if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) + //if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; fprintf(stderr,"bidTx.%s\n",uint256_str(str,txid)); From 4148e39f731e500e0dd4d5a182fab5139b64e76d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:29:34 -1100 Subject: [PATCH 485/749] Return eval->error --- src/cc/assets.cpp | 4 ++-- src/cc/channels.cpp | 2 +- src/cc/dice.cpp | 8 ++++---- src/cc/oracles.cpp | 2 +- src/cc/rewards.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index b1896ad9c..a421f9e44 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -322,7 +322,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"fill validated\n"); break; case 'E': // fillexchange - return(false); + return eval->Invalid("unexpected assets fillexchange funcid"); break; // disable asset swaps //vin.0: normal input //vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0] @@ -374,7 +374,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx break; default: fprintf(stderr,"illegal assets funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected assets funcid"); break; } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 7218177d7..4a209fb36 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -350,7 +350,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & break; default: fprintf(stderr,"illegal channels funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected channels funcid"); break; } } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c96545e7d..70f686725 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -597,11 +597,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { - if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) - //if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + //if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) + if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - fprintf(stderr,"bidTx.%s\n",uint256_str(str,txid)); + fprintf(stderr,"betTx.%s\n",uint256_str(str,txid)); fprintf(stderr,"entropyTx.%s v%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n); fprintf(stderr,"entropyTx vin0 %s v%d\n",uint256_str(str,vinTx.vin[0].prevout.hash),(int32_t)vinTx.vin[0].prevout.n); ptr0 = (uint8_t *)vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey.data(); @@ -701,7 +701,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) break; default: fprintf(stderr,"illegal dice funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected dice funcid"); break; } } diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 0f636551c..2955ad6a2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -653,7 +653,7 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t break; default: fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); - return(false); + return eval->Invalid("unexpected OraclesValidate funcid"); break; } } diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 1f3408252..99046e51c 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -289,7 +289,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t break; default: fprintf(stderr,"illegal rewards funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected rewards funcid"); break; } } From 9bd498e60e9ae82674213ec6ab09b32aa8570121 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:41:45 -1100 Subject: [PATCH 486/749] Revert default case in oracles --- src/cc/dice.cpp | 3 ++- src/cc/oracles.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 70f686725..dbf2fca1e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -801,7 +801,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) { //fprintf(stderr,"check first\n"); - if ( fundingPubKey == tx.vout[1].scriptPubKey ) + if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { @@ -826,6 +826,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } //else fprintf(stderr,"not E or is funding\n"); entropytxid = txid; entropyval = tx.vout[0].nValue; + fprintf(stderr,"entropytxid.%s val %.8f\n",txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 2955ad6a2..89ad89ff2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -651,10 +651,10 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; - default: - fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); - return eval->Invalid("unexpected OraclesValidate funcid"); - break; + //default: + // fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); + // return eval->Invalid("unexpected OraclesValidate funcid"); + // break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); From 013c54955c3e562011439f3748dcb414dc568dd4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:53:32 -1100 Subject: [PATCH 487/749] Better error checking --- src/cc/channels.cpp | 2 +- src/cc/dice.cpp | 2 +- src/cc/oracles.cpp | 10 +++++----- src/cc/rewards.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 4a209fb36..672e426a8 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -353,7 +353,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("unexpected channels funcid"); break; } - } + } else return eval->Invalid("unexpected channels missing funcid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"Channel tx validated\n"); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dbf2fca1e..645af3f67 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -704,7 +704,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("unexpected dice funcid"); break; } - } + } else return eval->Invalid("unexpected dice missing funcid"); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } return(true); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 89ad89ff2..8fe1fe6d3 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -651,12 +651,12 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; - //default: - // fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); - // return eval->Invalid("unexpected OraclesValidate funcid"); - // break; + default: + fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); + return eval->Invalid("unexpected OraclesValidate funcid"); + break; } - } + } else return eval->Invalid("unexpected oracles missing funcid"); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } return(true); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 99046e51c..649a9a9e6 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -292,7 +292,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unexpected rewards funcid"); break; } - } + } else return eval->Invalid("unexpected rewards missing funcid"); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } return(true); From 15e05e69f23441f2cef613908443d6ef0174ee82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:07:07 -1100 Subject: [PATCH 488/749] Fix dicestatus for specific bettxid from dealer node --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 645af3f67..203a59395 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -826,7 +826,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } //else fprintf(stderr,"not E or is funding\n"); entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"entropytxid.%s val %.8f\n",txid.GetHex().c_str(),(double)entropyval/COIN); + fprintf(stderr,"first.%d entropytxid.%s val %.8f\n",first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); @@ -1363,7 +1363,7 @@ 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 ) { - if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) + if ( funcid == 'L' )//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); From 56691a028a3a7f907f34ba48818d3e3d94b0b7ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:30:47 -1100 Subject: [PATCH 489/749] test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 203a59395..cebc48d23 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,9 +805,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.isCoinBase() != 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d]\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size()); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),vinTx.isCoinBase()); continue; } if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) From 8858150393daee9f0adf9d75ae8362e1785655f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:33:44 -1100 Subject: [PATCH 490/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cebc48d23..6d1b5392b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,9 +805,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.isCoinBase() != 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin[0].prevout.n < 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),vinTx.isCoinBase()); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin[0].prevout.n); continue; } if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) From 6c7532d1ecdb80048f725fbb0709b3dd2ac59b6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:43:21 -1100 Subject: [PATCH 491/749] Test --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6d1b5392b..06a843483 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,11 +805,12 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin[0].prevout.n < 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin[0].prevout.n); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } + printf("vinsize.%d\n",(int32_t)vinTx.vin.size()); if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; From ef17e6579d9844a1d4afd0bfaa6ead6142956ee2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:46:37 -1100 Subject: [PATCH 492/749] Test --- 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 06a843483..117de98b9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -803,7 +803,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) + if ( fundingtxid != tx.vin[0].prevout.hash ) { if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) { From dac41d3209fda980b19b6c3e9824fb24d3ec3c20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:50:08 -1100 Subject: [PATCH 493/749] Test --- src/cc/dice.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 117de98b9..fd9bc37c1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -803,14 +803,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( fundingtxid != tx.vin[0].prevout.hash ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) + { + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); + continue; + } + if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) - { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); - continue; - } - printf("vinsize.%d\n",(int32_t)vinTx.vin.size()); if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; From d16e3918e3485e519aae9becd43df04bb2d70b5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:59:34 -1100 Subject: [PATCH 494/749] Test --- src/cc/dice.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fd9bc37c1..f8cbb74db 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -808,9 +808,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } - if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) + if ( funcid == 'E' ) { - if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; ptr0 = (uint8_t *)vinTx.vout[tx.vin[0].prevout.n].scriptPubKey.data(); @@ -823,7 +823,16 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr," (%c) entropy vin.%d fundingPubKey mismatch %s\n",funcid,tx.vin[0].prevout.n,uint256_str(str,tx.vin[0].prevout.hash)); continue; } - } //else fprintf(stderr,"not E or is funding\n"); + } + else + { + fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n); + if ( vinTx.vin[0].prevout.n < 0 ) + { + fprintf(stderr,"skip coinbase\n"); + continue; + } + } entropytxid = txid; entropyval = tx.vout[0].nValue; fprintf(stderr,"first.%d entropytxid.%s val %.8f\n",first,txid.GetHex().c_str(),(double)entropyval/COIN); From 47ed5efd3380020449526cc62fa2e29fddf587cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 02:06:13 -1100 Subject: [PATCH 495/749] Test --- src/cc/dice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f8cbb74db..a6a0a4fd1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -469,7 +469,7 @@ int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *c return eval->Invalid("always should find vin, but didnt"); else { - if ( (assetoshis= IsDicevout(cp,vinTx,tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) + if ( (assetoshis= IsDicevout(cp,vinTx,(int32_t)tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) inputs += assetoshis; } } @@ -587,7 +587,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vin.0, but didnt for bet"); else if ( vinTx.vout[1].scriptPubKey != fundingPubKey ) return eval->Invalid("entropy tx not fundingPubKey for bet"); - else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) + else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) return eval->Invalid("vout[0] != entropy nValue for bet"); else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[1] constrain violation for bet"); @@ -598,7 +598,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { //if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) - if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; fprintf(stderr,"betTx.%s\n",uint256_str(str,txid)); @@ -803,9 +803,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || (int32_t)tx.vin[0].prevout.n < 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } if ( funcid == 'E' ) @@ -826,8 +826,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } else { - fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n); - if ( vinTx.vin[0].prevout.n < 0 ) + fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); + if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) { fprintf(stderr,"skip coinbase\n"); continue; From a33d12fcbd1e5f6c3761a48972c596529224ae40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 02:09:54 -1100 Subject: [PATCH 496/749] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a6a0a4fd1..1eef3f44f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -826,10 +826,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } else { - fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); + //fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) { - fprintf(stderr,"skip coinbase\n"); + //fprintf(stderr,"skip coinbase\n"); continue; } } @@ -1082,8 +1082,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; - funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + //funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 385f323d76cb5911ab08bc4bc45e09576004cba5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 02:12:05 -1100 Subject: [PATCH 497/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1eef3f44f..cefb8a2f8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1082,8 +1082,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; - //funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 77fb34804d56265acec751378c80c5d208349283 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 03:42:31 -1100 Subject: [PATCH 498/749] Test --- src/cc/dice.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cefb8a2f8..76715fc0d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -792,10 +792,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) + if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { //fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); - if ( funcid != 'F' && funcid != 'T' ) + if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; totalinputs += nValue; if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) @@ -808,6 +808,11 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } + if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) + { + //fprintf(stderr,"skip coinbase\n"); + continue; + } if ( funcid == 'E' ) { if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) @@ -824,18 +829,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit continue; } } - else - { - //fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); - if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) - { - //fprintf(stderr,"skip coinbase\n"); - continue; - } - } entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"first.%d entropytxid.%s val %.8f\n",first,txid.GetHex().c_str(),(double)entropyval/COIN); + fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); From c68644d19c2ec93686a47eda6953cbfc677f47dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:04:05 -1100 Subject: [PATCH 499/749] Test --- src/cc/dice.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 76715fc0d..228404ad8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -813,19 +813,20 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"skip coinbase\n"); continue; } - if ( funcid == 'E' ) + //if ( funcid == 'E' ) { - if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - ptr0 = (uint8_t *)vinTx.vout[tx.vin[0].prevout.n].scriptPubKey.data(); + ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); ptr1 = (uint8_t *)fundingPubKey.data(); - for (i=0; i Date: Wed, 7 Nov 2018 04:25:53 -1100 Subject: [PATCH 500/749] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 228404ad8..3c17e9b1f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -407,6 +407,8 @@ CScript EncodeDiceOpRet(uint8_t funcid,uint64_t sbits,uint256 fundingtxid,uint25 uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits,uint256 &fundingtxid,uint256 &hash,uint256 &proof) { std::vector vopret; uint8_t *script,e,f,funcid; int64_t minbet,maxbet,maxodds,timeoutblocks; + script = (uint8_t *)scriptPubKey.data(); + fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); GetOpReturnData(scriptPubKey,vopret); if ( vopret.size() > 2 ) { From bcc7be98b14e36877732afaddd66427ca803f2bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:31:57 -1100 Subject: [PATCH 501/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3c17e9b1f..142b70e22 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -408,9 +408,9 @@ uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits { std::vector vopret; uint8_t *script,e,f,funcid; int64_t minbet,maxbet,maxodds,timeoutblocks; script = (uint8_t *)scriptPubKey.data(); - fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); + //fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 ) + if ( vopret.size() > 2 && script[0] == 0x6a ) { script = (uint8_t *)vopret.data(); if ( script[0] == EVAL_DICE ) From b14d87fa6bd484e98ae5032bb6426bc506a96dbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:44:32 -1100 Subject: [PATCH 502/749] Auto entropy on dealer dice status --- src/cc/dice.cpp | 54 ++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 142b70e22..6001e2702 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -815,22 +815,19 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"skip coinbase\n"); continue; } - //if ( funcid == 'E' ) + //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { - //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) - if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) - { - uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); - ptr1 = (uint8_t *)fundingPubKey.data(); - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) + { + if ( DecodeHexTx(tx,res) != 0 ) + { + //LOCK(cs_main); + if ( myAddtomempool(tx) != 0 ) + { + fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,mintxs - entropytxs); + RelayTransaction(tx); + } + } + } + } } - }*/ + } return(n); } else From e37833a3444ace90990388491af6e06c0592e73b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:52:13 -1100 Subject: [PATCH 503/749] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6001e2702..dbf49ea10 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1040,7 +1040,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 } if ( scriptPubKey == fundingPubKey ) { - if ( AddNormalinputs(mtx,mypk,amount+2*txfee,60) > 0 ) + if ( AddNormalinputs(mtx,mypk,amount+2*txfee,10) > 0 ) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); @@ -1348,9 +1348,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,mintxs - entropytxs); RelayTransaction(tx); - } - } - } + } else break; + } else break; + } else break; } } } From 481667776c79a0af97e90405722637801c643050 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 05:12:01 -1100 Subject: [PATCH 504/749] Test --- src/cc/dice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dbf49ea10..644ddadde 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -590,7 +590,10 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( vinTx.vout[1].scriptPubKey != fundingPubKey ) return eval->Invalid("entropy tx not fundingPubKey for bet"); else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) + { + fprintf(stderr,"prevout.%d %.8f\n",(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); return eval->Invalid("vout[0] != entropy nValue for bet"); + } else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[1] constrain violation for bet"); else if ( tx.vout[2].nValue > txfee+maxodds || tx.vout[2].nValue <= txfee ) From a4cd90f11381a3cf374bc995426108d172c1a2d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 05:12:54 -1100 Subject: [PATCH 505/749] Test --- 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 644ddadde..3be553873 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -591,7 +591,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("entropy tx not fundingPubKey for bet"); else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) { - fprintf(stderr,"prevout.%d %.8f\n",(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); + fprintf(stderr,"%s prevout.%d %.8f\n",tx.vin[0].prevout.hash.GetHex().c_str(),(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); return eval->Invalid("vout[0] != entropy nValue for bet"); } else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) From ccea0f71143f5fde25f55f52049aa85d2d4fdf2e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 05:20:05 -1100 Subject: [PATCH 506/749] Int64 != int32 --- 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 3be553873..12f4f8dd6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -589,7 +589,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vin.0, but didnt for bet"); else if ( vinTx.vout[1].scriptPubKey != fundingPubKey ) return eval->Invalid("entropy tx not fundingPubKey for bet"); - else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) + else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int64_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) { fprintf(stderr,"%s prevout.%d %.8f\n",tx.vin[0].prevout.hash.GetHex().c_str(),(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); return eval->Invalid("vout[0] != entropy nValue for bet"); From b2004c4a6d2e8237fa34d2ccae8043cf8e241bc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:02:23 -1100 Subject: [PATCH 507/749] Test --- src/cc/dice.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 12f4f8dd6..6e7607360 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -407,10 +407,10 @@ CScript EncodeDiceOpRet(uint8_t funcid,uint64_t sbits,uint256 fundingtxid,uint25 uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits,uint256 &fundingtxid,uint256 &hash,uint256 &proof) { std::vector vopret; uint8_t *script,e,f,funcid; int64_t minbet,maxbet,maxodds,timeoutblocks; - script = (uint8_t *)scriptPubKey.data(); + //script = (uint8_t *)scriptPubKey.data(); //fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && script[0] == 0x6a ) + if ( vopret.size() > 2 )//&& script[0] == 0x6a ) { script = (uint8_t *)vopret.data(); if ( script[0] == EVAL_DICE ) @@ -792,14 +792,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit vout = (int32_t)it->first.index; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - //char str[65],str2[65]; if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { - //fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); + fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; totalinputs += nValue; From 280a6285f9bab3b06c812f1886c7ec89aed57087 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:07:54 -1100 Subject: [PATCH 508/749] Test --- 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 6e7607360..18a104ff3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -790,6 +790,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } txid = it->first.txhash; vout = (int32_t)it->first.index; + fprintf(stderr,"%d: %s.(%c %.8f) total %.8f\n",n,uint256_str(str,txid),funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN); if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) @@ -798,7 +799,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { - fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; totalinputs += nValue; From d3738119ee64739a39f4779ffee185db64590e1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:16:25 -1100 Subject: [PATCH 509/749] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 18a104ff3..d57182e14 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -781,6 +781,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit int startfrom = rand()%numtxs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + sum += it->second.satoshis; + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); loops++; if (random) { if ( loops < startfrom ) @@ -788,9 +792,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - txid = it->first.txhash; - vout = (int32_t)it->first.index; - fprintf(stderr,"%d: %s.(%c %.8f) total %.8f\n",n,uint256_str(str,txid),funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN); if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) From 1285c77569d91421faf58a5bf8f281eb6c1a93f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:17:22 -1100 Subject: [PATCH 510/749] Test --- 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 d57182e14..f86da8163 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -784,7 +784,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit txid = it->first.txhash; vout = (int32_t)it->first.index; sum += it->second.satoshis; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); loops++; if (random) { if ( loops < startfrom ) @@ -796,6 +795,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) From 9d94f533f41b2c903e7f04bba1503abada4e6096 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:18:31 -1100 Subject: [PATCH 511/749] Test --- 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 f86da8163..cbc1dec40 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -765,7 +765,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { - char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; From ad92d45ca15985d47c843397ae37164e35918142 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:37:39 -1100 Subject: [PATCH 512/749] test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cbc1dec40..1331aa4e2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1326,8 +1326,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 100 ) - break; + //if ( n >= 100 ) + // break; } //else error = res; } } From ae262835506b12c6778eccc635d695e864ebb43d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:40:29 -1100 Subject: [PATCH 513/749] Test --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1331aa4e2..77b3d0956 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1283,6 +1283,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { + duplicate = 0; for (i=0; i Date: Wed, 7 Nov 2018 06:40:53 -1100 Subject: [PATCH 514/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 77b3d0956..7b7f5dc60 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1327,8 +1327,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - //if ( n >= 100 ) - // break; + if ( n >= 100 ) + break; } //else error = res; } } From 853848e0c75c630ae3b2401a32f0f767f901945c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:43:04 -1100 Subject: [PATCH 515/749] Test --- 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 7b7f5dc60..05e39a900 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1327,7 +1327,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 100 ) + if ( n >= 1000 ) break; } //else error = res; } From 4b586cc17efb4a23baebaaa0c869e9a01c3de374 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 07:03:23 -1100 Subject: [PATCH 516/749] Test --- src/cc/dice.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05e39a900..589a73a17 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -765,7 +765,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { - char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0,pendingbets=0; uint8_t funcid; std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; @@ -795,7 +795,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + if ( funcid == 'B' ) + pendingbets++; + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) @@ -859,7 +861,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } i = i + 1; } if (!random) { - fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN); + fprintf(stderr,"pendingbets.%d numentropy tx %d: %.8f\n",pendingbets,n,(double)totalinputs/COIN); entropytxs = n; return(totalinputs); } else { From 80a625e1262119bdb8a7cb54e94bf54b7e7a6108 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 07:56:31 -1100 Subject: [PATCH 517/749] Test --- src/cc/dice.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 589a73a17..98b9d2ec1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -91,6 +91,8 @@ WARNING: there is an attack vector that precludes betting any large amounts, it What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy need to speed up dealer dicestatus loop (or in parallel) + validate refund + change to hashtables */ @@ -796,8 +798,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { if ( funcid == 'B' ) + { pendingbets++; - //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) From 318fa91646f94e808001cb5bc8e1c38325e82a57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:01:51 -1100 Subject: [PATCH 518/749] Test --- src/cc/dice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 98b9d2ec1..5e50e5dfc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -780,7 +780,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropyval = 0; int loops = 0; int numtxs = unspentOutputs.size()/2; - int startfrom = rand()%numtxs; + int startfrom = rand() % (numtxs+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -1289,23 +1289,23 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - duplicate = 0; + /*duplicate = 0; for (i=0; i Date: Wed, 7 Nov 2018 08:02:18 -1100 Subject: [PATCH 519/749] Test --- 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 5e50e5dfc..c2264e68c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -800,7 +800,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { From 1ca7f316acbde97494b51a629fa5785a780d59a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:12:10 -1100 Subject: [PATCH 520/749] Test --- src/cc/dice.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c2264e68c..58f26a06b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1289,23 +1289,15 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - /*duplicate = 0; + duplicate = 0; for (i=0; i 0 ) { + for (i=0; i= 1000 ) From 9092cc4b0bd78ac3b7248561b91a50dd3c67d556 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:15:22 -1100 Subject: [PATCH 521/749] Test --- 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 58f26a06b..213ac0d1d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1342,7 +1342,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } if ( scriptPubKey == fundingPubKey ) { - CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=5000; + CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < mintxs ) { From 2303eb840af19b0127ac8e059633e09fac87d5d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:24:09 -1100 Subject: [PATCH 522/749] test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 213ac0d1d..18c79ff90 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1290,12 +1290,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { duplicate = 0; - for (i=0; i Date: Wed, 7 Nov 2018 08:27:08 -1100 Subject: [PATCH 523/749] test --- 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 18c79ff90..d35907c09 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 8192 +#define MAX_ENTROPYUSED 512 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable From af49ac2489746db393b9674d0c1585a1bf430b1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:35:57 -1100 Subject: [PATCH 524/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d35907c09..135198d0a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 512 +#define MAX_ENTROPYUSED 128 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -1333,7 +1333,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx bettxids[rand() % MAX_ENTROPYUSED] = txid; mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 1000 ) + if ( n >= 100 ) break; } //else error = res; } From b15d0d99b840da16589dfdcd8f125ee5e64df279 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:44:31 -1100 Subject: [PATCH 525/749] Test --- src/cc/dice.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 135198d0a..52cec336a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -223,22 +223,22 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } // check for duplicates here!!! - for (i=0; ifundingtxid = fundingtxid; ptr->bettxid = bettxid; @@ -1323,14 +1323,14 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - for (i=0; i= 100 ) From bb396525cbebf77697683a870e19b18b7fbab9fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:48:26 -1100 Subject: [PATCH 526/749] Test --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 52cec336a..805a364df 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,6 +121,7 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro fprintf(stderr,"null entropyused or bettxid\n"); return(1); } + return(1); for (i=0; i Date: Wed, 7 Nov 2018 08:54:30 -1100 Subject: [PATCH 527/749] 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 805a364df..3b4f9dc08 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,7 +121,7 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro fprintf(stderr,"null entropyused or bettxid\n"); return(1); } - return(1); + return(0); for (i=0; i %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); From 1698dba1f713c433687242b1cafe93de74bebff7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:58:43 -1100 Subject: [PATCH 528/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3b4f9dc08..691d24d8b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -195,7 +195,7 @@ void *dicefinish(void *_ptr) break; } } - } else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); + } //else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); if ( i == maxiters ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); else @@ -801,7 +801,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { From 528ed2ecb68f2c7a0a49f344cb8f0b6164ff7c91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:01:34 -1100 Subject: [PATCH 529/749] Test --- 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 691d24d8b..a732c5e1b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1286,7 +1286,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 3 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { From 1a78c1143700d87ad86cdf2f7d62909e2882a9a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:10:50 -1100 Subject: [PATCH 530/749] Test --- src/cc/dice.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a732c5e1b..7c1a9890d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 128 +#define MAX_ENTROPYUSED 1024 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -154,6 +154,14 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { + for (i=0; i 0 ) { - /*for (i=0; i= 100 ) From 16770709d9ba2de481a2811de049dbafefc09624 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:14:36 -1100 Subject: [PATCH 531/749] Test --- 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 7c1a9890d..282fe21a1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1334,7 +1334,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 100 ) + if ( n >= 1000 ) break; } //else error = res; } From db555c55f3d017901cebd141dbe3fb4019d173f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:21:24 -1100 Subject: [PATCH 532/749] Test --- 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 282fe21a1..365ae2181 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1234,7 +1234,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,56,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,6,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From a9fef224190a36eb892b9dd88614b3e6688254c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:54:07 -1100 Subject: [PATCH 533/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 365ae2181..bd5c3a185 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -739,7 +739,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < threshold ) + if ( vout != 0 || it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; jsecond.satoshis; From ec76cfdbd19bf6ff25bff2a1baf2326aeea44b06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:09:57 -1100 Subject: [PATCH 534/749] 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 bd5c3a185..4af122da3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1277,7 +1277,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1294,17 +1294,18 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; + sum += it->second.satoshis; if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 3 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { duplicate = 0; - for (i=0; i= 1000 ) break; } //else error = res; } + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } } From 88fadf9a014e39a4c0b6072d8b55c4511fdda271 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:10:39 -1100 Subject: [PATCH 535/749] Test --- 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 4af122da3..f99741f51 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1340,7 +1340,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx break; } //else error = res; } - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } } From d5749db5e660430ab7950d935eab35a3dbd582a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:23:14 -1100 Subject: [PATCH 536/749] Test --- src/cc/dice.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f99741f51..fc7ffffd6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,7 +121,6 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro fprintf(stderr,"null entropyused or bettxid\n"); return(1); } - return(0); for (i=0; i %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); From d3f0b4269dd367d453ccdf27ede86ccadd1ca3af Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 7 Nov 2018 13:30:29 -0800 Subject: [PATCH 537/749] Clean up dicebet/dicestatus error handling and add new macro to make things easier --- src/cc/dice.cpp | 32 +++++++++++++++++--------------- src/wallet/rpcwallet.cpp | 9 +++------ src/wallet/wallet.h | 2 ++ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dbf49ea10..3fe258f54 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1057,24 +1057,26 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 return(""); } -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, std::string &error) +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) { - error = "bet must be positive"; + CCerror = "bet must be positive"; return(""); } if ( odds < 2 || odds > 9999 ) { - error = "odds must be between 2 and 9999"; + CCerror = "odds must be between 2 and 9999"; return(""); } - if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { + CCerror = "error in Diceinit"; return(""); + } if ( bet < minbet || bet > maxbet || odds > maxodds ) { - error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); + CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } int32_t entropytxs=0,emptyvar=0; @@ -1083,12 +1085,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { - error = "Your dealer is broke, find a new casino."; + CCerror = "Your dealer is broke, find a new casino."; return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { - error = "entropy txid is spent"; + CCerror = "entropy txid is spent"; return(""); } mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); @@ -1099,12 +1101,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); - } else error = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; + } else CCerror = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; } if ( entropyval == 0 && funding != 0 ) - error = "cant find dice entropy inputs"; + CCerror = "cant find dice entropy inputs"; else - error = "cant find dice input"; + CCerror = "cant find dice input"; return(""); } @@ -1257,12 +1259,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return("couldnt find bettx or entropytx"); } -double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - error = "Diceinit error in status"; + CCerror = "Diceinit error in status"; return(0.); } fundingpk = DiceFundingPk(fundingPubKey); @@ -1369,7 +1371,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(0.); else return((double)spenttx.vout[2].nValue/COIN); } - error = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); + CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); return(-1.); } else if ( scriptPubKey == fundingPubKey ) @@ -1389,8 +1391,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); } - error = "didnt find dicefinish tx"; - } else error = res; + CCerror = "didnt find dicefinish tx"; + } else CCerror = res; return(-1.); } return(0.); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 02d8f36fd..0a1c04d1e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6168,12 +6168,11 @@ UniValue dicebet(const UniValue& params, bool fHelp) } if (amount > 0 && odds > 0) { hex = DiceBet(0,name,fundingtxid,amount,odds,error); + RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else if ( error[0] != 0 ) { - ERR_RESULT(error); } } else { ERR_RESULT("amount and odds must be positive"); @@ -6235,10 +6234,8 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); winnings = DiceStatus(0,name,fundingtxid,bettxid,error); - if ( error[0] != 0 ) { - ERR_RESULT(error); - return(result); - } + RETURN_IF_ERROR(CCerror); + result.push_back(Pair("result", "success")); if ( winnings >= 0. ) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 70df32bef..67b81ea77 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1208,4 +1208,6 @@ public: /** Error status printout */ #define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); +#define RETURN_IF_ERROR(CCerror) if ( CCerror != "" ) { ERR_RESULT(CCerror); return(result); } + #endif // BITCOIN_WALLET_WALLET_H From 5eda38a264bc83f337f5a17e0fd8e8eb75bc80f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:48:11 -1100 Subject: [PATCH 538/749] Test --- 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 29f8d7539..6d4ea7e90 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -150,7 +150,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) { - LOCK(cs_main); + //LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { for (i=0; i Date: Wed, 7 Nov 2018 10:49:34 -1100 Subject: [PATCH 539/749] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0a1c04d1e..f7fad3dc1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6167,7 +6167,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) return(result); } if (amount > 0 && odds > 0) { - hex = DiceBet(0,name,fundingtxid,amount,odds,error); + hex = DiceBet(0,name,fundingtxid,amount,odds); RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) { @@ -6233,7 +6233,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) memset(&bettxid,0,sizeof(bettxid)); if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); - winnings = DiceStatus(0,name,fundingtxid,bettxid,error); + winnings = DiceStatus(0,name,fundingtxid,bettxid); RETURN_IF_ERROR(CCerror); result.push_back(Pair("result", "success")); From b1c61bbc95b4e51dde2e64dc318959c2755311cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:52:36 -1100 Subject: [PATCH 540/749] syntax --- src/cc/CCdice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 692d31462..4a848b40f 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -23,9 +23,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); -double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); From 1ef2ca6e19c70cc090be60f504ef20f8a5c5337b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 17:55:11 -1100 Subject: [PATCH 541/749] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f7fad3dc1..b1c27fe2e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6223,7 +6223,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); From e0e3f61f15afd8000783c5b4cca49466b139b948 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 22:19:19 -1100 Subject: [PATCH 542/749] Streamline --- src/cc/dice.cpp | 79 +++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6d4ea7e90..840f893bd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1150,12 +1150,6 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, winlosetimeout = 0; } } - if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! - { - CCerror = "no txfee inputs for win/lose"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; @@ -1165,7 +1159,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, CSpentIndexValue value2; if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - //CCerror = "bettxid already spent"; + CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1178,6 +1172,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! + { + CCerror = "no txfee inputs for win/lose"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; @@ -1295,54 +1295,37 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( vout != 0 ) + continue; sum += it->second.satoshis; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 3 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - duplicate = 0; - /*for (i=0; i= 100 ) - break; - }*/ - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); - if ( result > 0 ) - { - mySenddicetransaction(res,entropyused,txid,betTx,funcid); - n++; - fprintf(stderr,"send "); - if ( n >= 1000 ) - break; - } //else error = res; + fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; } - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + /*following didnt work: + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + DiceQueue(iswin,sbits,fundingtxid,txid); + if ( ++n >= 100 ) + break; + }*/ + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + if ( result > 0 ) + { + mySenddicetransaction(res,entropyused,txid,betTx,funcid); + n++; + fprintf(stderr,"send "); + if ( n >= 100 ) + break; + } //else error = res; } + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } if ( scriptPubKey == fundingPubKey ) From 001b6c97098e9c08806035c7dc3b9283e6c0669c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 22:44:34 -1100 Subject: [PATCH 543/749] Test --- src/cc/dice.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 840f893bd..d13707ead 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -101,6 +101,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #define MAX_ENTROPYUSED 1024 extern int32_t KOMODO_INSYNC; + static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; @@ -112,6 +113,12 @@ struct dicefinish_info CTransaction betTx; }; +struct dicebet_info +{ + struct dicebet_info *prev,*next; + struct dicefinish_info D; +}; + int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; @@ -787,12 +794,14 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int numtxs = unspentOutputs.size()/2; + int numtxs = unspentOutputs.size()/8; int startfrom = rand() % (numtxs+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( vout != 0 ) + continue; sum += it->second.satoshis; loops++; if (random) { @@ -801,7 +810,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 )//&& myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { From 0fe89bda151c0cebc993b423b6a5e5745e986e77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 22:54:48 -1100 Subject: [PATCH 544/749] Test --- src/cc/dice.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d13707ead..a390835fd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1316,14 +1316,14 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - /*following didnt work: - bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) - { - DiceQueue(iswin,sbits,fundingtxid,txid); - if ( ++n >= 100 ) - break; - }*/ + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + fprintf(stderr,"%d: iswin.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + n++; + //DiceQueue(iswin,sbits,fundingtxid,txid); + } + /* res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { @@ -1332,9 +1332,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"send "); if ( n >= 100 ) break; - } //else error = res; + } //else error = res;*/ } - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } if ( scriptPubKey == fundingPubKey ) From 1903c351c62424ca72f27c84bafaa5362cdd844d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 23:03:24 -1100 Subject: [PATCH 545/749] Test --- src/cc/dice.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a390835fd..f5313c4c6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1287,12 +1287,13 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; return(0.); } + win = loss = 0; fundingpk = DiceFundingPk(fundingPubKey); scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; GetCCaddress(cp,coinaddr,dicepk); @@ -1319,7 +1320,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - fprintf(stderr,"%d: iswin.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + if ( iswin > 0 ) + win++; + else if ( iswin < 0 ) + loss++; + fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; //DiceQueue(iswin,sbits,fundingtxid,txid); } @@ -1342,7 +1347,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < mintxs ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From f3a1581fd1178e18989b5c4a6ce6c00d1fc41a31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:36:36 -1100 Subject: [PATCH 546/749] Add queueing --- src/cc/dice.cpp | 211 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 170 insertions(+), 41 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f5313c4c6..472e0403c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,30 +98,33 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 1024 +#define MAX_ENTROPYUSED 8192 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; +pthread_mutex_t DICE_MUTEX,DICEWIN_MUTEX; + +struct dicefinish_utxo { uint256 txid; int32_t vout; }; + struct dicefinish_info { + struct dicefinish_info *prev,*next; + struct dicefinish_utxo vin0; uint256 fundingtxid,bettxid; uint64_t sbits; + int64_t winamount; int32_t iswin; + uint32_t bettxid_ready; CTransaction betTx; -}; - -struct dicebet_info -{ - struct dicebet_info *prev,*next; - struct dicefinish_info D; -}; +} *DICEFINISH_LIST,*DICEWIN_LIST; int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; + return(0); oldbettxid = zeroid; if ( entropyused == zeroid || bettxid == zeroid ) { @@ -191,10 +194,126 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C return(false); } +int32_t _dicehash_find(uint256 bettxid) +{ + for (i=0; i > unspentOutputs; + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + if ( myIsutxo_spentinmempool(it->first.txhash,utxos[n].vout) == 0 ) + { + if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) + continue; + utxos[n].txid = it->first.txhash; + utxos[n].vout = (int32_t)it->first.index; + if ( ++n >= max ) + break; + } + } + return(n); +} + +void *dicewin(void *_ptr) +{ + char CCaddr[64]; struct CCcontract_info *cp; int32_t n; struct dicefinish_info *ptr,*tmp; + sleep(3); + cp = CCinit(C,EVAL_DICE); + GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); + fprintf(stderr,"start dicewin thread %s\n",CCaddr); + while ( 1 ) + { + n = 0; + DL_FOREACH_SAFE(DICEWIN_LIST,ptr,tmp) + { + DL_DELETE(DICEWIN_LIST,ptr); + free(ptr); + n++; + } + if ( n > 0 ) + fprintf(stderr,"freed %d wins\n",n); + sleep(1); + } +} + void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i=0,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - ptr = (struct dicefinish_info *)_ptr; + std::vector mypk; char str[65],str2[65],name[32],coinaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result,maxiters=600; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + sleep(3); + mypk = Mypubkey(); + pubkey2addr(coinaddr,mypk.data()); + fprintf(stderr,"start dicefinish thread %s\n",coinaddr); + while ( 1 ) + { + vins_needed = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + { + if ( ptr->bettxid_ready == 0 ) + { + if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) != 0 && hashBlock != zeroid ) + ptr->bettxid_ready = (uint32_t)time(NULL); + else if ( mytxid_inmempool(ptr->bettxid) != 0 ) + ptr->bettxid_ready = (uint32_t)time(NULL); + } + if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin < 0 ) + vin0_needed++; + } + if ( vin0_needed > 0 ) + { + utxos = calloc(vin0_needed,sizeof(*utxos)); + if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) + { + m = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + { + if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin != 0 ) + { + DL_DELETE(DICEFINISH_LIST,ptr); + if ( ptr->iswin > 0 ) + { + pthread_mutex_lock(&DICEWIN_MUTEX); + DL_APPEND(DICEWIN_LIST,ptr); + pthread_mutex_unlock(&DICEWIN_MUTEX); + fprintf(stderr,"queue win %s %.8f\n",ptr->bettxid.GetHex().c_str(),(double)ptr->winamount/COIN); + } + else + { + ptr->vin0.txid = utxos[m].txid; + ptr->vin0.vout = utxos[m].vout; + fprintf(stderr,"%d of %d process loss using %s/v%d\n",m,n,ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); + free(ptr); + if ( ++m >= n ) + break; + } + } + } + } + free(utxos); + } + usleep(100000); + } + /*ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); hashBlock = zeroid; if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) == 0 || hashBlock == zeroid ) @@ -218,18 +337,19 @@ void *dicefinish(void *_ptr) if ( result > 0 ) mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); } - free(ptr); + free(ptr);*/ return(0); } void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { + static int32_t didinit; struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - //fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); + fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); return; } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -237,35 +357,44 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",bettxid.GetHex().c_str()); return; } - // check for duplicates here!!! - for (i=0; ifundingtxid = fundingtxid; - ptr->bettxid = bettxid; - ptr->betTx = betTx; - ptr->sbits = sbits; - ptr->iswin = iswin; - //fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); - if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) + if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicewin,0) != 0 ) { - //fprintf(stderr,"DiceQueue.%d\n",iswin); - } // small memory leak per DiceQueue + pthread_mutex_init(&DICE_MUTEX); + pthread_mutex_init(&DICEWIN_MUTEX); + didinit = 1; + } + else + { + fprintf(stderr,"error launching dicefinish thread\n"); + return; + } } + pthread_mutex_lock(&DICE_MUTEX); + if ( _dicehash_find(bettxid) != 0 ) + { + pthread_mutex_unlock(&DICE_MUTEX); + fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + return; + } + if ( _dicehash_add(bettxid) == 0 ) + { + pthread_mutex_unlock(&DICE_MUTEX); + fprintf(stderr,"DiceQueue status error adding bettxid.%s\n",bettxid.GetHex().c_str()); + return; + } + ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); + ptr->fundingtxid = fundingtxid; + ptr->bettxid = bettxid; + ptr->betTx = betTx; + ptr->sbits = sbits; + ptr->iswin = iswin; + ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->vin0.vout = -1; + DL_APPEND(DICEFINISH_LIST,ptr); + pthread_mutex_unlock(&DICE_MUTEX); + fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } CPubKey DiceFundingPk(CScript scriptPubKey) @@ -1312,11 +1441,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) + /*if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; - } + }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { @@ -1326,7 +1455,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx loss++; fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; - //DiceQueue(iswin,sbits,fundingtxid,txid); + DiceQueue(iswin,sbits,fundingtxid,txid,betTx); } /* res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); From ef1cd183f209f28ce1a32426bdcdc1042ca11a1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:39:37 -1100 Subject: [PATCH 547/749] Test --- src/cc/CCinclude.h | 3 +++ src/cc/dice.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 749d676e9..9a1f41b31 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -48,6 +48,8 @@ one other technical note is that komodod has the insight-explorer extensions bui #include #include #include "../komodo_defs.h" +#include "../utlist.h" +#include "../uthash.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; extern uint32_t ASSETCHAINS_CC; @@ -134,6 +136,7 @@ bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); uint64_t stringbits(char *str); uint256 revuint256(uint256 txid); +bool pubkey2addr(char *destaddr,uint8_t *pubkey33); char *uint256_str(char *dest,uint256 txid); char *pubkey33_str(char *dest,uint8_t *pubkey33); uint256 Parseuint256(char *hexstr); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 472e0403c..d9b214c15 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -196,6 +196,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C int32_t _dicehash_find(uint256 bettxid) { + int32_t i; for (i=0; i Date: Thu, 8 Nov 2018 00:44:49 -1100 Subject: [PATCH 548/749] Test --- src/cc/dice.cpp | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d9b214c15..53c11c75d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -240,7 +240,7 @@ void *dicewin(void *_ptr) { char CCaddr[64]; struct CCcontract_info *cp,C; int32_t n; struct dicefinish_info *ptr,*tmp; sleep(3); - cp = CCinit(C,EVAL_DICE); + cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicewin thread %s\n",CCaddr); while ( 1 ) @@ -267,7 +267,7 @@ void *dicefinish(void *_ptr) fprintf(stderr,"start dicefinish thread %s\n",coinaddr); while ( 1 ) { - vins_needed = 0; + vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { if ( ptr->bettxid_ready == 0 ) @@ -282,7 +282,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { - utxos = calloc(vin0_needed,sizeof(*utxos)); + utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) { m = 0; @@ -362,8 +362,8 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, { if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicewin,0) != 0 ) { - pthread_mutex_init(&DICE_MUTEX); - pthread_mutex_init(&DICEWIN_MUTEX); + pthread_mutex_init(&DICE_MUTEX,NULL); + pthread_mutex_init(&DICEWIN_MUTEX,NULL); didinit = 1; } else @@ -373,29 +373,21 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, } } pthread_mutex_lock(&DICE_MUTEX); - if ( _dicehash_find(bettxid) != 0 ) + if ( _dicehash_find(bettxid) == 0 ) { - pthread_mutex_unlock(&DICE_MUTEX); - fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); - return; - } - if ( _dicehash_add(bettxid) == 0 ) - { - pthread_mutex_unlock(&DICE_MUTEX); - fprintf(stderr,"DiceQueue status error adding bettxid.%s\n",bettxid.GetHex().c_str()); - return; - } - ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); - ptr->fundingtxid = fundingtxid; - ptr->bettxid = bettxid; - ptr->betTx = betTx; - ptr->sbits = sbits; - ptr->iswin = iswin; - ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); - ptr->vin0.vout = -1; - DL_APPEND(DICEFINISH_LIST,ptr); + _dicehash_add(bettxid); + ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); + ptr->fundingtxid = fundingtxid; + ptr->bettxid = bettxid; + ptr->betTx = betTx; + ptr->sbits = sbits; + ptr->iswin = iswin; + ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->vin0.vout = -1; + DL_APPEND(DICEFINISH_LIST,ptr); + fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); - fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } CPubKey DiceFundingPk(CScript scriptPubKey) @@ -1064,7 +1056,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { struct CCcontract_info *cp; int32_t cmpflag; - cp = CCinit(C,EVAL_DICE); + cp = CCinit(&C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); From f1b829ca29ee5b292748c172325c33a1cab8ce33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:46:28 -1100 Subject: [PATCH 549/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 53c11c75d..9c65f26ea 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -345,7 +345,7 @@ void *dicefinish(void *_ptr) void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { static int32_t didinit; - struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; + struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; uint64_t txfee = 10000; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) @@ -1056,7 +1056,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { struct CCcontract_info *cp; int32_t cmpflag; - cp = CCinit(&C,EVAL_DICE); + cp = CCinit(C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); From 409b36b5fed41234d9c478928b5c1ca40a9c1536 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:54:17 -1100 Subject: [PATCH 550/749] Test --- src/cc/dice.cpp | 79 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9c65f26ea..c19fcb9a0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,6 +121,61 @@ struct dicefinish_info CTransaction betTx; } *DICEFINISH_LIST,*DICEWIN_LIST; +int32_t _dicehash_find(uint256 bettxid) +{ + int32_t i; + for (i=0; i Date: Thu, 8 Nov 2018 00:55:20 -1100 Subject: [PATCH 551/749] Test --- 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 c19fcb9a0..326a9612c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1496,7 +1496,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( scriptPubKey == fundingPubKey ) + if ( 0 && scriptPubKey == fundingPubKey ) { CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); From 585306789a39832255cd181a8b4b5d92bfdcaee7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:56:24 -1100 Subject: [PATCH 552/749] Test --- src/cc/dice.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 326a9612c..4a7893b2c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -163,17 +163,16 @@ int32_t _dicerevealed_find(uint256 entropyused,uint256 bettxid) void _dicerevealed_add(uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; + for (i=0; i Date: Thu, 8 Nov 2018 01:00:13 -1100 Subject: [PATCH 553/749] Test --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4a7893b2c..1c4a1d903 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -293,7 +293,8 @@ void *dicewin(void *_ptr) void *dicefinish(void *_ptr) { std::vector mypk; char str[65],str2[65],name[32],coinaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result,maxiters=600; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - sleep(3); + fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); + sleep(10); mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); fprintf(stderr,"start dicefinish thread %s\n",coinaddr); @@ -314,6 +315,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { + fprintf(stderr,"vin0_needed.%d\n",vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) { From 76d0c0d0df3b047507e1c2dc504d5a2c9e6d34c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:01:48 -1100 Subject: [PATCH 554/749] Test --- 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 1c4a1d903..0aac0bfda 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -336,7 +336,7 @@ void *dicefinish(void *_ptr) { ptr->vin0.txid = utxos[m].txid; ptr->vin0.vout = utxos[m].vout; - fprintf(stderr,"%d of %d process loss using %s/v%d\n",m,n,ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); + fprintf(stderr,"%d of %d process loss %s using %s/v%d\n",m,n,ptr->bettxid.GetHex().c_str(),ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); free(ptr); if ( ++m >= n ) break; From 1f51d14dcc472f3b55656b62b555c40015e0e3aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:04:01 -1100 Subject: [PATCH 555/749] Test --- 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 0aac0bfda..8d8f21add 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,7 +255,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( myIsutxo_spentinmempool(it->first.txhash,utxos[n].vout) == 0 ) + if ( myIsutxo_spentinmempool(it->first.txhash,(int32_t)it->first.index) == 0 ) { if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) continue; From bf8e5c4189fb8b495d024877b469def847131bf9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:22:08 -1100 Subject: [PATCH 556/749] Test --- src/cc/dice.cpp | 69 +++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8d8f21add..ca146649a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -105,21 +105,20 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; -pthread_mutex_t DICE_MUTEX,DICEWIN_MUTEX; +pthread_mutex_t DICE_MUTEX; struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; - struct dicefinish_utxo vin0; uint256 fundingtxid,bettxid; uint64_t sbits; int64_t winamount; int32_t iswin; uint32_t bettxid_ready; CTransaction betTx; -} *DICEFINISH_LIST,*DICEWIN_LIST; +} *DICEFINISH_LIST; int32_t _dicehash_find(uint256 bettxid) { @@ -268,7 +267,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin return(n); } -void *dicewin(void *_ptr) +/*void *dicewin(void *_ptr) { char CCaddr[64]; struct CCcontract_info *cp,C; int32_t n; struct dicefinish_info *ptr,*tmp; sleep(3); @@ -288,7 +287,7 @@ void *dicewin(void *_ptr) fprintf(stderr,"freed %d wins\n",n); sleep(1); } -} +}*/ void *dicefinish(void *_ptr) { @@ -300,51 +299,42 @@ void *dicefinish(void *_ptr) fprintf(stderr,"start dicefinish thread %s\n",coinaddr); while ( 1 ) { - vin0_needed = 0; - DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + for (iter=-1; iter<=1; iter+=2) { - if ( ptr->bettxid_ready == 0 ) + vin0_needed = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) != 0 && hashBlock != zeroid ) - ptr->bettxid_ready = (uint32_t)time(NULL); - else if ( mytxid_inmempool(ptr->bettxid) != 0 ) - ptr->bettxid_ready = (uint32_t)time(NULL); - } - if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin < 0 ) - vin0_needed++; - } - if ( vin0_needed > 0 ) - { - fprintf(stderr,"vin0_needed.%d\n",vin0_needed); - utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); - if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) - { - m = 0; - DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + if ( ptr->bettxid_ready == 0 ) { - if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin != 0 ) + if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) != 0 && hashBlock != zeroid ) + ptr->bettxid_ready = (uint32_t)time(NULL); + else if ( mytxid_inmempool(ptr->bettxid) != 0 ) + ptr->bettxid_ready = (uint32_t)time(NULL); + } + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) + vin0_needed++; + } + if ( vin0_needed > 0 ) + { + fprintf(stderr,"vin0_needed.%d\n",vin0_needed); + utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); + if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) + { + m = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - DL_DELETE(DICEFINISH_LIST,ptr); - if ( ptr->iswin > 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { - pthread_mutex_lock(&DICEWIN_MUTEX); - DL_APPEND(DICEWIN_LIST,ptr); - pthread_mutex_unlock(&DICEWIN_MUTEX); - fprintf(stderr,"queue win %s %.8f\n",ptr->bettxid.GetHex().c_str(),(double)ptr->winamount/COIN); - } - else - { - ptr->vin0.txid = utxos[m].txid; - ptr->vin0.vout = utxos[m].vout; - fprintf(stderr,"%d of %d process loss %s using %s/v%d\n",m,n,ptr->bettxid.GetHex().c_str(),ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); + DL_DELETE(DICEFINISH_LIST,ptr); + fprintf(stderr,"%d of %d process %s %s using %s/v%d\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout); free(ptr); if ( ++m >= n ) break; } } } + free(utxos); } - free(utxos); } usleep(100000); } @@ -394,10 +384,9 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, } if ( didinit == 0 ) { - if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicewin,0) == 0 ) + if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 ) { pthread_mutex_init(&DICE_MUTEX,NULL); - pthread_mutex_init(&DICEWIN_MUTEX,NULL); didinit = 1; } else From f29012df356cc54f4977a45aaa1e0acf11dd1a8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:24:34 -1100 Subject: [PATCH 557/749] Test --- src/cc/dice.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ca146649a..7a4966441 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -291,12 +291,14 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { - std::vector mypk; char str[65],str2[65],name[32],coinaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result,maxiters=600; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); sleep(10); mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); - fprintf(stderr,"start dicefinish thread %s\n",coinaddr); + cp = CCinit(&C,EVAL_DICE); + GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); + fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); while ( 1 ) { for (iter=-1; iter<=1; iter+=2) @@ -326,7 +328,7 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); - fprintf(stderr,"%d of %d process %s %s using %s/v%d\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout); + fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); free(ptr); if ( ++m >= n ) break; From 83dcf61cd66a430b5aed5eb1a9a0ab7dc561c36a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:24:59 -1100 Subject: [PATCH 558/749] Test --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7a4966441..6892dd16b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -291,7 +291,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); sleep(10); mypk = Mypubkey(); @@ -408,7 +408,6 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); - ptr->vin0.vout = -1; DL_APPEND(DICEFINISH_LIST,ptr); fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); From 2ea2821c6aed53e686ad6075ec08c882f2bda40d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:40:05 -1100 Subject: [PATCH 559/749] Vin0 utxo --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 33 +++++++++++++++++++++++---------- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 4a848b40f..bd8d1d5fa 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); -std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6892dd16b..33e4df7d2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -292,7 +292,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); + fprintf(stderr,"wait dicefinish thread\n"); sleep(10); mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); @@ -329,6 +329,11 @@ void *dicefinish(void *_ptr) { DL_DELETE(DICEFINISH_LIST,ptr); fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + unstringbits(name,ptr->sbits); + result = 0; + res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + //if ( result > 0 ) + // mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); free(ptr); if ( ++m >= n ) break; @@ -409,7 +414,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); - fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } @@ -1282,7 +1287,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; @@ -1327,11 +1332,19 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! + if ( vin0txid == zeroid || vin0vout < 0 ) { - CCerror = "no txfee inputs for win/lose"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); + if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! + { + CCerror = "no txfee inputs for win/lose"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + } + else + { + fprintf(stderr,"use vin0 %s/%d\n",vin0txid.GetHex().c_str(),vin0vout); + mtx.vin.push_back(CTxIn(vin0txid,vin0vout,CScript())); } if ( winlosetimeout != 0 ) // dealernode { @@ -1390,7 +1403,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,6,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); @@ -1530,8 +1543,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1,zeroid,-1); + else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0,zeroid,-1); if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid,betTx,funcid); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b1c27fe2e..4b5ef8a1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6196,7 +6196,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1); + hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1,zeroid,-1); if ( CCerror != "" ) { ERR_RESULT(CCerror); From dae973ae0fba77734c4138e1b4cab28fd5522ab2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:58:01 -1100 Subject: [PATCH 560/749] Test --- src/cc/dice.cpp | 97 +++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 68 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 33e4df7d2..3ce5ec689 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -105,7 +105,7 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; -pthread_mutex_t DICE_MUTEX; +pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; struct dicefinish_utxo { uint256 txid; int32_t vout; }; @@ -141,7 +141,7 @@ void _dicehash_add(uint256 bettxid) bettxids[rand() % MAX_ENTROPYUSED] = bettxid; } -int32_t _dicerevealed_find(uint256 entropyused,uint256 bettxid) +int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) { int32_t i; for (i=0; i %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); @@ -267,28 +240,6 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin return(n); } -/*void *dicewin(void *_ptr) -{ - char CCaddr[64]; struct CCcontract_info *cp,C; int32_t n; struct dicefinish_info *ptr,*tmp; - sleep(3); - cp = CCinit(&C,EVAL_DICE); - GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); - fprintf(stderr,"start dicewin thread %s\n",CCaddr); - while ( 1 ) - { - n = 0; - DL_FOREACH_SAFE(DICEWIN_LIST,ptr,tmp) - { - DL_DELETE(DICEWIN_LIST,ptr); - free(ptr); - n++; - } - if ( n > 0 ) - fprintf(stderr,"freed %d wins\n",n); - sleep(1); - } -}*/ - void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; @@ -318,7 +269,6 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { - fprintf(stderr,"vin0_needed.%d\n",vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) { @@ -332,8 +282,10 @@ void *dicefinish(void *_ptr) unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); - //if ( result > 0 ) + if ( result > 0 ) + { // mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + } else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) break; @@ -394,6 +346,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 ) { pthread_mutex_init(&DICE_MUTEX,NULL); + pthread_mutex_init(&DICEREVEALED_MUTEX,NULL); didinit = 1; } else @@ -1403,16 +1356,24 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) >= fundsneeded ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); } else { - CCerror = strprintf("not enough inputs for %.8f\n",(double)fundsneeded/COIN); - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); + if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + { + if ( inputs > fundsneeded ) + CCchange += (inputs - fundsneeded); + } + else + { + CCerror = strprintf("not enough inputs for %.8f\n",(double)fundsneeded/COIN); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } } mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); @@ -1551,7 +1512,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sleep(1); 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 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) { if ( funcid == 'L' )//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 ) From 2ea6863c0862d0b0e4e6af0e958526d960e2e014 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:06:40 -1100 Subject: [PATCH 561/749] Test --- src/cc/dice.cpp | 53 +++++++++++-------------------------------------- src/main.cpp | 2 +- src/miner.cpp | 2 +- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3ce5ec689..2ef16df7d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -242,9 +242,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - fprintf(stderr,"wait dicefinish thread\n"); - sleep(10); + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -252,6 +250,13 @@ void *dicefinish(void *_ptr) fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); while ( 1 ) { + if ( (newht= KOMODO_INSYNC) == 0 || lastheight == newht ) + { + sleep(1); + continue; + } + lastheight = newht; + fprintf(stderr,"process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; @@ -278,14 +283,15 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); - fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { - // mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } else fprintf(stderr,"error doing the dicefinish\n"); + //mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + } + else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) break; @@ -297,31 +303,6 @@ void *dicefinish(void *_ptr) } usleep(100000); } - /*ptr = (struct dicefinish_info *)_ptr; - unstringbits(name,ptr->sbits); - hashBlock = zeroid; - if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) == 0 || hashBlock == zeroid ) - { - usleep((rand() % 1000000) + 100000); - for (i=0; ibettxid) != 0 ) // wait for bettxid to be in mempool - { - //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - break; - } - } - } //else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); - if ( i == maxiters ) - fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); - else - { - res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } - free(ptr);*/ return(0); } @@ -1448,16 +1429,6 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); } - /* - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); - if ( result > 0 ) - { - mySenddicetransaction(res,entropyused,txid,betTx,funcid); - n++; - fprintf(stderr,"send "); - if ( n >= 100 ) - break; - } //else error = res;*/ } } } diff --git a/src/main.cpp b/src/main.cpp index cc69c215b..115920264 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3582,7 +3582,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); if ( KOMODO_LONGESTCHAIN != 0 && pindexNew->nHeight >= KOMODO_LONGESTCHAIN ) - KOMODO_INSYNC = 1; + KOMODO_INSYNC = (int32_t)pindexNew->nHeight; else KOMODO_INSYNC = 0; //fprintf(stderr,"connect.%d insync.%d\n",(int32_t)pindexNew->nHeight,KOMODO_INSYNC); if ( ASSETCHAINS_SYMBOL[0] == 0 && KOMODO_INSYNC != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index ee3f7e680..3b245b286 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -940,7 +940,7 @@ void static BitcoinMiner() { fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height); if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN ) - KOMODO_INSYNC = 1; + KOMODO_INSYNC = Mining_height; sleep(3); } // Hash state From 25ccf7fb27223a587ee9e059735a3b88569c7496 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:18:33 -1100 Subject: [PATCH 562/749] Test --- src/cc/dice.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2ef16df7d..bf5b9f332 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -220,9 +220,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C return(false); } -int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coinaddr) +int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t max,char *coinaddr) { int32_t n = 0; int64_t threshold = 2 * 10000; + total = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -231,18 +232,25 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin { if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) continue; - utxos[n].txid = it->first.txhash; - utxos[n].vout = (int32_t)it->first.index; - if ( ++n >= max ) - break; + total++; + if ( n < max ) + { + if ( utxos != 0 ) + { + utxos[n].txid = it->first.txhash; + utxos[n].vout = (int32_t)it->first.index; + } + n++; + } } } + total -= n; return(n); } void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -275,7 +283,7 @@ void *dicefinish(void *_ptr) if ( vin0_needed > 0 ) { utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); - if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) + if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) @@ -902,7 +910,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { @@ -1432,7 +1440,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( 0 && scriptPubKey == fundingPubKey ) + if ( scriptPubKey == fundingPubKey ) { CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); @@ -1455,6 +1463,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else break; } } + pubkey2addr(coinaddr,mypk.data()); + dicefinish_utxosget(entropytx,0,0,coinaddr); + if ( entropytx < mintxs ) + { + fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytx); + } } return(n); } From e1d687adf1df4843b61bed92b5ae223b06753ee0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:19:28 -1100 Subject: [PATCH 563/749] 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 bf5b9f332..a7af1cc3b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1463,9 +1463,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else break; } } - pubkey2addr(coinaddr,mypk.data()); - dicefinish_utxosget(entropytx,0,0,coinaddr); - if ( entropytx < mintxs ) + pubkey2addr(coinaddr,mypk.ptr()); + dicefinish_utxosget(entropytxs,0,0,coinaddr); + if ( entropytxs < mintxs ) { fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytx); } From f8f1896625e6ac35341b0300420eecfbebbfd4ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:20:12 -1100 Subject: [PATCH 564/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a7af1cc3b..ad0592870 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1463,11 +1463,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else break; } } - pubkey2addr(coinaddr,mypk.ptr()); + pubkey2addr(coinaddr,Mypubkey().data()); dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytx); + fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytxs); } } return(n); From 2c467cf6e9ea743edf2ef6e48ca9bbfffcd5755f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:23:46 -1100 Subject: [PATCH 565/749] Test --- src/cc/dice.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ad0592870..203f2d2a5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -291,15 +291,14 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); - //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { + fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); //mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } - else fprintf(stderr,"error doing the dicefinish\n"); + } else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) break; @@ -1285,7 +1284,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, } else { - fprintf(stderr,"use vin0 %s/%d\n",vin0txid.GetHex().c_str(),vin0vout); + //fprintf(stderr,"use vin0 %s/%d\n",vin0txid.GetHex().c_str(),vin0vout); mtx.vin.push_back(CTxIn(vin0txid,vin0vout,CScript())); } if ( winlosetimeout != 0 ) // dealernode @@ -1421,11 +1420,6 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - /*if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; - }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { From 02e4584f809a94d1bd8e3192e800937b03a15150 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:24:08 -1100 Subject: [PATCH 566/749] Test --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 203f2d2a5..bcee97b0a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -256,6 +256,7 @@ void *dicefinish(void *_ptr) cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); + sleep(10); while ( 1 ) { if ( (newht= KOMODO_INSYNC) == 0 || lastheight == newht ) From 09c4edb1c3e51b335f224d280f72e41dc2a1546b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:30:00 -1100 Subject: [PATCH 567/749] Test --- src/cc/dice.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bcee97b0a..685c80ccc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -256,14 +256,11 @@ void *dicefinish(void *_ptr) cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); + while ( (newht= KOMODO_INSYNC) == 0 ) + sleep(1); sleep(10); while ( 1 ) { - if ( (newht= KOMODO_INSYNC) == 0 || lastheight == newht ) - { - sleep(1); - continue; - } lastheight = newht; fprintf(stderr,"process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) @@ -309,7 +306,11 @@ void *dicefinish(void *_ptr) free(utxos); } } - usleep(100000); + while ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) + { + sleep(1); + continue; + } } return(0); } From 8cf8f3688c939cc2377f864f3e84179d085abf97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:35:03 -1100 Subject: [PATCH 568/749] Test --- src/cc/dice.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 685c80ccc..3dee0a31d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,6 +268,13 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { + if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + { + fprintf(stderr,"dicefinish loop bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + continue; + } if ( ptr->bettxid_ready == 0 ) { if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) != 0 && hashBlock != zeroid ) @@ -286,6 +293,13 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { + if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + { + fprintf(stderr,"dicefinish loop2 bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + continue; + } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); @@ -904,7 +918,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 )//&& myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { From 9d5b969fd6b9e8e9d01de5902970fa7e7437f32a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:46:16 -1100 Subject: [PATCH 569/749] Test --- src/cc/dice.cpp | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3dee0a31d..01ed33085 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -248,9 +248,28 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t return(n); } +int32_t dice_betspent(char *debugstr,uint256 bettxid) +{ + CSpentIndexValue value,value2; + CSpentIndexKey key(bettxid,0); + CSpentIndexKey key2(bettxid,1); + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + return(-1); + } + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + { + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); + return(-1); + } + return(0); +} + void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -268,9 +287,8 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + if ( dice_betspent("dicefinish loop",ptr->bettxid) < 0 ) { - fprintf(stderr,"dicefinish loop bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); continue; @@ -293,9 +311,8 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + if ( dice_betspent("dicefinish loop2",ptr->bettxid) < 0 ) { - fprintf(stderr,"dicefinish loop2 bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); continue; @@ -332,19 +349,7 @@ void *dicefinish(void *_ptr) void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { static int32_t didinit; - struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; uint64_t txfee = 10000; - CSpentIndexKey key(bettxid, 0); - CSpentIndexKey key2(bettxid, 1); - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) - { - fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); - return; - } - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) - { - fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",bettxid.GetHex().c_str()); - return; - } + struct dicefinish_info *ptr; int32_t i,duplicate=0; uint64_t txfee = 10000; if ( didinit == 0 ) { if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 ) @@ -359,6 +364,8 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } + if ( dice_betspent("DiceQueue",ptr->bettxid) < 0 ) + return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) { @@ -861,7 +868,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK break; if ( j != mtx.vin.size() ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { @@ -894,7 +901,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; - if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) + if ( myGetTransaction(reffundingtxid,tx,hashBlock) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) { fundingPubKey = tx.vout[1].scriptPubKey; } else return(0); @@ -918,7 +925,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { @@ -939,7 +946,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || (int32_t)tx.vin[0].prevout.n < 0 ) + if ( myGetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 || (int32_t)tx.vin[0].prevout.n < 0 ) { fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; @@ -1007,7 +1014,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan { //fprintf(stderr,"check fundingtxid\n"); - if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) + if ( myGetTransaction(fundingtxid,tx,hashBlock) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { @@ -1023,7 +1030,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac txid = it->first.txhash; if ( fundingtxid != zeroid && txid != fundingtxid ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' ) { @@ -1062,7 +1069,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s UniValue DiceInfo(uint256 diceid) { UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CCcontract_info *cp,C; - if ( GetTransaction(diceid,vintx,hashBlock,false) == 0 ) + if ( myGetTransaction(diceid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); ERR_RESULT("cant find fundingtxid"); @@ -1103,7 +1110,7 @@ UniValue DiceList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeDiceFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) != 0 ) { @@ -1267,14 +1274,10 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, winlosetimeout = 0; } } - if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - CSpentIndexKey key(bettxid, 0); - CSpentIndexValue value; - CSpentIndexKey key2(bettxid, 1); - CSpentIndexValue value2; - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + if ( dice_betspent("DiceBetFinish",bettxid) < 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1283,12 +1286,6 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) - { - CCerror = "bettxid already spent in mempool"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } if ( vin0txid == zeroid || vin0vout < 0 ) { if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! @@ -1432,7 +1429,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( vout != 0 ) continue; sum += it->second.satoshis; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { @@ -1488,7 +1485,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { //fprintf(stderr,"bettx is spent\n"); - if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) + if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 2 ) { //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 ) @@ -1507,7 +1504,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( myGetTransaction(txid,betTx,hashBlock) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() >= 2 ) { if ( funcid == 'L' )//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 ) From 4a957f42ff6b795ac3ef9e095bf0a21526751383 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:47:42 -1100 Subject: [PATCH 570/749] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 01ed33085..e79150208 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -287,7 +287,7 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent("dicefinish loop",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) < 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); @@ -311,7 +311,7 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent("dicefinish loop2",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) < 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); @@ -364,7 +364,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent("DiceQueue",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"DiceQueue",ptr->bettxid) < 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1277,7 +1277,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent("DiceBetFinish",bettxid) < 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid) < 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From d1df996b5373080b0e310aad2eba78e2cf4109e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:49:20 -1100 Subject: [PATCH 571/749] Fix --- 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 e79150208..9c1452da4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -364,7 +364,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) < 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) From 2ca168e4e61a2721e3afe9f2ecfdb7bbc960e783 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:50:57 -1100 Subject: [PATCH 572/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9c1452da4..1656aa4e4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -325,8 +325,8 @@ void *dicefinish(void *_ptr) res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { - fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - //mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); } else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) From 9f5075e53dc17023ef8e552be0f606a620b493a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:09:51 -1100 Subject: [PATCH 573/749] Test --- src/cc/dice.cpp | 55 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1656aa4e4..4cd22742e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -112,12 +112,14 @@ struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; - uint256 fundingtxid,bettxid; + uint256 fundingtxid,bettxid,entropyused; uint64_t sbits; int64_t winamount; int32_t iswin; uint32_t bettxid_ready; CTransaction betTx; + std::string rawtx; + uint8_t funcid; } *DICEFINISH_LIST; int32_t _dicehash_find(uint256 bettxid) @@ -210,10 +212,17 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C pthread_mutex_lock(&DICEREVEALED_MUTEX); _dicerevealed_add(entropyused,bettxid,betTx); pthread_mutex_unlock(&DICEREVEALED_MUTEX); + fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } - fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + return(true); - } else fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } + else + { + ptr->rawtx.clear(); + fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); + } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } @@ -256,7 +265,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); - return(-1); + return(1); } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { @@ -268,8 +277,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -281,13 +289,13 @@ void *dicefinish(void *_ptr) while ( 1 ) { lastheight = newht; - fprintf(stderr,"process ht.%d\n",newht); + fprintf(stderr,"dicefinish process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) > 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); @@ -301,7 +309,12 @@ void *dicefinish(void *_ptr) ptr->bettxid_ready = (uint32_t)time(NULL); } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) - vin0_needed++; + { + if ( ptr->rawtx.size() > 0 ) + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + if ( ptr->rawtx.size() == 0 ) + vin0_needed++; + } } if ( vin0_needed > 0 ) { @@ -311,24 +324,28 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) > 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) { - DL_DELETE(DICEFINISH_LIST,ptr); unstringbits(name,ptr->sbits); result = 0; - res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + res = DiceBetFinish(ptr->funcid,ptr->entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { - //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } else fprintf(stderr,"error doing the dicefinish\n"); - free(ptr); + ptr->rawtx = res; + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + } + else + { + fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + } if ( ++m >= n ) break; } @@ -364,7 +381,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) < 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1277,7 +1294,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid) < 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 7393776cddf1a241d757310b4807227fa4286de9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:21:59 -1100 Subject: [PATCH 574/749] Test --- src/cc/dice.cpp | 58 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4cd22742e..b849a5c1e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -145,16 +145,26 @@ void _dicehash_add(uint256 bettxid) int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) { - int32_t i; + int32_t i; struct dicefinish_info *ptr,*tmp; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + { + if ( ptr->entropyused == entropyused ) + { + if ( ptr->bettxid == bettxid ) + return(i+1); + fprintf(stderr,"found identical entropy used.%d different bettxid!\n",i); + oldbettxid = ptr->bettxid; + oldbetTx = ptr->betTx; + return(-1); + } + } for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -209,9 +219,14 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C RelayTransaction(tx); if ( retval == 0 ) { - pthread_mutex_lock(&DICEREVEALED_MUTEX); - _dicerevealed_add(entropyused,bettxid,betTx); - pthread_mutex_unlock(&DICEREVEALED_MUTEX); + if ( ptr != 0 ) + ptr->revealed = (uint32_t)time(NULL); + else + { + pthread_mutex_lock(&DICEREVEALED_MUTEX); + _dicerevealed_add(entropyused,bettxid,betTx); + pthread_mutex_unlock(&DICEREVEALED_MUTEX); + } fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -297,8 +312,12 @@ void *dicefinish(void *_ptr) { if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) > 0 ) { - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) + { + fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + } continue; } if ( ptr->bettxid_ready == 0 ) @@ -311,7 +330,7 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( ptr->rawtx.size() > 0 ) - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); if ( ptr->rawtx.size() == 0 ) vin0_needed++; } @@ -326,8 +345,12 @@ void *dicefinish(void *_ptr) { if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) > 0 ) { - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) + { + fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + } continue; } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) @@ -338,13 +361,14 @@ void *dicefinish(void *_ptr) if ( result > 0 ) { ptr->rawtx = res; - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + ptr->rawtx.clear(); + //DL_DELETE(DICEFINISH_LIST,ptr); + //free(ptr); } if ( ++m >= n ) break; @@ -1517,7 +1541,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0,zeroid,-1); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid,betTx,funcid); + mySenddicetransaction(res,entropyused,bettxid,betTx,funcid,0); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From 52e473dd6cd8a793c1b074109edbe06a0f2aba21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:22:37 -1100 Subject: [PATCH 575/749] Test --- 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 b849a5c1e..c115c7af3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -116,7 +116,7 @@ struct dicefinish_info uint64_t sbits; int64_t winamount; int32_t iswin; - uint32_t bettxid_ready; + uint32_t bettxid_ready,revealed; CTransaction betTx; std::string rawtx; uint8_t funcid; From 79e277533ab4ea83024ebc8234624f119bae4d74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:24:48 -1100 Subject: [PATCH 576/749] Test --- 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 c115c7af3..17da7d110 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -405,7 +405,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) > 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) From 6f67a6c3b14ebc590f782e1faae5e1b6c985cc63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:27:24 -1100 Subject: [PATCH 577/749] Test --- 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 17da7d110..c013908a2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1318,7 +1318,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid) != 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid) > 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 17e9e78da657cc2a42c1f26ca3ae2c238f0a616d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:33:05 -1100 Subject: [PATCH 578/749] Test --- src/cc/dice.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c013908a2..5616f2b83 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -272,20 +272,33 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t return(n); } -int32_t dice_betspent(char *debugstr,uint256 bettxid) +int32_t dice_betspent(char *debugstr,uint256 bettxid,int32_t mode) { - CSpentIndexValue value,value2; + int32_t numblocks; + /*CSpentIndexValue value,value2; CSpentIndexKey key(bettxid,0); CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); - } - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + }*/ + if ( mode > 0 ) { - fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); - return(-1); + CCduration(numblocks,bettxid); + if ( numblocks > 0 ) + { + fprintf(stderr,"%s bettxid.%s already confirmed %d\n",debugstr,bettxid.GetHex().c_str(),numblocks); + return(1); + } + } + else + { + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + { + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); + return(-1); + } } return(0); } @@ -310,7 +323,7 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) > 0 ) + if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid,1) > 0 ) { if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { @@ -343,7 +356,7 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) > 0 ) + if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid,1) != 0 ) { if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { @@ -405,7 +418,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) > 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid,1) != 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1318,7 +1331,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid) > 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid,1) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 2874830f6e094b9e92cdbaa6c30d478f139fabc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:41:41 -1100 Subject: [PATCH 579/749] Test --- src/cc/dice.cpp | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5616f2b83..500621b6f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -112,7 +112,7 @@ struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; - uint256 fundingtxid,bettxid,entropyused; + uint256 fundingtxid,bettxid,entropyused,txid; uint64_t sbits; int64_t winamount; int32_t iswin; @@ -210,6 +210,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C { if ( DecodeHexTx(tx,res) != 0 ) { + if ( ptr != 0 ) + ptr->txid = tx.GetHash(); //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) { @@ -236,6 +238,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C else { ptr->rawtx.clear(); + ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); @@ -272,31 +275,31 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t return(n); } -int32_t dice_betspent(char *debugstr,uint256 bettxid,int32_t mode) +int32_t dice_betspent(char *debugstr,uint256 bettxid) { - int32_t numblocks; + /*int32_t numblocks; /*CSpentIndexValue value,value2; - CSpentIndexKey key(bettxid,0); - CSpentIndexKey key2(bettxid,1); + CSpentIndexKey key(txid,0); + CSpentIndexKey key2(txid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + fprintf(stderr,"%s txid.%s already spent\n",debugstr,txid.GetHex().c_str()); return(1); - }*/ + } if ( mode > 0 ) { - CCduration(numblocks,bettxid); + CCduration(numblocks,txid); if ( numblocks > 0 ) { - fprintf(stderr,"%s bettxid.%s already confirmed %d\n",debugstr,bettxid.GetHex().c_str(),numblocks); + fprintf(stderr,"%s txid.%s already confirmed %d\n",debugstr,txid.GetHex().c_str(),numblocks); return(1); } } - else + else*/ { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,txid.GetHex().c_str()); return(-1); } } @@ -323,14 +326,11 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid,1) > 0 ) + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { - if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) - { - fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); - } + fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); continue; } if ( ptr->bettxid_ready == 0 ) @@ -356,14 +356,11 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid,1) != 0 ) + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { - if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) - { - fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); - } + fprintf(stderr,"purge2 %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); continue; } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) @@ -380,6 +377,7 @@ void *dicefinish(void *_ptr) { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); ptr->rawtx.clear(); + ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); //free(ptr); } @@ -418,7 +416,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid,1) != 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1331,12 +1329,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid,1) != 0 ) + /*if ( dice_betspent((char *)"DiceBetFinish",bettxid) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); - } + }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { From 0cc5c16676af6dd418508c214d2d0ca650cbadba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:42:16 -1100 Subject: [PATCH 580/749] Fix --- 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 500621b6f..877430a81 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -299,7 +299,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,txid.GetHex().c_str()); + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); return(-1); } } From 40ffbabbc0dec5dfd460b202fb38f52425992d0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:43:49 -1100 Subject: [PATCH 581/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 877430a81..9e633730c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -416,8 +416,8 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) - return; + //if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) + // return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) { From 00f45e5f2f7c01d7992446b37862db09db7c5d09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:48:27 -1100 Subject: [PATCH 582/749] Test --- src/cc/dice.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9e633730c..c30a2bc51 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -145,19 +145,7 @@ void _dicehash_add(uint256 bettxid) int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) { - int32_t i; struct dicefinish_info *ptr,*tmp; - DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) - { - if ( ptr->entropyused == entropyused ) - { - if ( ptr->bettxid == bettxid ) - return(i+1); - fprintf(stderr,"found identical entropy used.%d different bettxid!\n",i); - oldbettxid = ptr->bettxid; - oldbetTx = ptr->betTx; - return(-1); - } - } + int32_t i; for (i=0; irevealed = (uint32_t)time(NULL); - else - { - pthread_mutex_lock(&DICEREVEALED_MUTEX); - _dicerevealed_add(entropyused,bettxid,betTx); - pthread_mutex_unlock(&DICEREVEALED_MUTEX); - } + pthread_mutex_lock(&DICEREVEALED_MUTEX); + _dicerevealed_add(entropyused,bettxid,betTx); + pthread_mutex_unlock(&DICEREVEALED_MUTEX); fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -429,6 +414,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->rawtx.clear(); DL_APPEND(DICEFINISH_LIST,ptr); //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); From 5e41721ecb47aaeed67a7ce4e438e0418ece45b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:53:34 -1100 Subject: [PATCH 583/749] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c30a2bc51..4110c11d4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,7 +222,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C } else { - ptr->rawtx.clear(); + if ( ptr->rawtx != 0 ) + ptr->rawtx.clear(); ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); } @@ -361,7 +362,8 @@ void *dicefinish(void *_ptr) else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - ptr->rawtx.clear(); + if ( ptr->rawtx != 0 ) + ptr->rawtx.clear(); ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); //free(ptr); @@ -414,7 +416,6 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); - ptr->rawtx.clear(); DL_APPEND(DICEFINISH_LIST,ptr); //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); From 489049a7371f172bd49e88690179a1ac82337563 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:54:24 -1100 Subject: [PATCH 584/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4110c11d4..467ceaf50 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,7 +222,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C } else { - if ( ptr->rawtx != 0 ) + if ( ptr->rawtx.IsNull() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); @@ -362,7 +362,7 @@ void *dicefinish(void *_ptr) else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - if ( ptr->rawtx != 0 ) + if ( ptr->rawtx.IsNull() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); From fcdbc5abb8734016790a37ded21a3088a38b2fe2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:56:06 -1100 Subject: [PATCH 585/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 467ceaf50..14c9fb08d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,7 +222,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C } else { - if ( ptr->rawtx.IsNull() == 0 ) + if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); @@ -362,7 +362,7 @@ void *dicefinish(void *_ptr) else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - if ( ptr->rawtx.IsNull() == 0 ) + if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); From 2f62195ccd49c53d408e4bca68618e4b085038c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:01:16 -1100 Subject: [PATCH 586/749] Test --- src/cc/dice.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 14c9fb08d..38d435313 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -294,7 +294,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -328,9 +328,13 @@ void *dicefinish(void *_ptr) } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { - if ( ptr->rawtx.size() > 0 ) - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); - if ( ptr->rawtx.size() == 0 ) + if ( ptr->txid != zeroid ) + { + CCduration(numblocks,ptr->txid); + if ( numblocks == 0 ) + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + } + if ( ptr->txid == zeroid ) vin0_needed++; } } From 1796fc60f5aa813829830aa790a3c9365088022a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:09:44 -1100 Subject: [PATCH 587/749] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 38d435313..e812194c5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -217,15 +217,16 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); - return(true); } else { - if ( ptr->rawtx.empty() == 0 ) + RelayTransaction(tx); + fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + /*if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; - fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); + fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size());*/ } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); From 00da0164e812d30be434a2f5e11f0f0cff75f04d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:14:31 -1100 Subject: [PATCH 588/749] 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 e812194c5..5f529a26f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,11 +222,11 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C else { RelayTransaction(tx); - fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); - /*if ( ptr->rawtx.empty() == 0 ) + fprintf(stderr,"rebroadcast.%c and clear [%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; - fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size());*/ + //fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); From 6f8f7bff118b4072f146cd13c6fd7cb616a66b55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:21:01 -1100 Subject: [PATCH 589/749] Test --- src/cc/dice.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5f529a26f..8e296185f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -215,8 +215,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C _dicerevealed_add(entropyused,bettxid,betTx); pthread_mutex_unlock(&DICEREVEALED_MUTEX); fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); - } - else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else @@ -295,7 +294,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -306,7 +305,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { - lastheight = newht; + if ( newht != 0 && lastheight != newht ) + { + lastheight = newht; + newblock = 1; + } else newblock = 0; fprintf(stderr,"dicefinish process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { @@ -329,7 +332,7 @@ void *dicefinish(void *_ptr) } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { - if ( ptr->txid != zeroid ) + if ( newblock != 0 && ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); if ( numblocks == 0 ) @@ -370,8 +373,6 @@ void *dicefinish(void *_ptr) if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; - //DL_DELETE(DICEFINISH_LIST,ptr); - //free(ptr); } if ( ++m >= n ) break; @@ -381,11 +382,8 @@ void *dicefinish(void *_ptr) free(utxos); } } - while ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) - { + if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) sleep(1); - continue; - } } return(0); } From 23e5c2663431a2dc546dae3e27899eae3421fedb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:39:29 -1100 Subject: [PATCH 590/749] Test --- src/cc/dice.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8e296185f..e80950917 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -263,8 +263,7 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t int32_t dice_betspent(char *debugstr,uint256 bettxid) { - /*int32_t numblocks; - /*CSpentIndexValue value,value2; + CSpentIndexValue value,value2; CSpentIndexKey key(txid,0); CSpentIndexKey key2(txid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) @@ -272,7 +271,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) fprintf(stderr,"%s txid.%s already spent\n",debugstr,txid.GetHex().c_str()); return(1); } - if ( mode > 0 ) + /*if ( mode > 0 ) { CCduration(numblocks,txid); if ( numblocks > 0 ) @@ -305,12 +304,12 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; } else newblock = 0; - fprintf(stderr,"dicefinish process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; @@ -357,7 +356,13 @@ void *dicefinish(void *_ptr) free(ptr); continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) + if ( ptr->txid != zeroid ) + { + CCduration(numblocks,ptr->txid); + if ( numblocks > 0 ) + continue; + } + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent("dicefinish",ptr->bettxid) == 0 ) { unstringbits(name,ptr->sbits); result = 0; From 2bbf50e165fa1e2c96b92aa4dfef306d44026e7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:41:13 -1100 Subject: [PATCH 591/749] Test --- src/cc/dice.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e80950917..754b9a900 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -264,11 +264,11 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t int32_t dice_betspent(char *debugstr,uint256 bettxid) { CSpentIndexValue value,value2; - CSpentIndexKey key(txid,0); - CSpentIndexKey key2(txid,1); + CSpentIndexKey key(bettxid,0); + CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s txid.%s already spent\n",debugstr,txid.GetHex().c_str()); + fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -362,7 +362,7 @@ void *dicefinish(void *_ptr) if ( numblocks > 0 ) continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent("dicefinish",ptr->bettxid) == 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) == 0 ) { unstringbits(name,ptr->sbits); result = 0; @@ -1006,7 +1006,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { - uint8_t *ptr0,*ptr1; int32_t i; char str[65]; + /*uint8_t *ptr0,*ptr1; int32_t i; char str[65]; ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); ptr1 = (uint8_t *)fundingPubKey.data(); for (i=0; i Date: Thu, 8 Nov 2018 04:46:51 -1100 Subject: [PATCH 592/749] Test --- src/cc/CCutils.cpp | 5 +++-- src/cc/dice.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index ce736ba7a..889b6fdd4 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -391,7 +391,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) } else if ( hashBlock == zeroid ) { - fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid)); + //fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid)); return(0); } else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->nHeight) <= 0 ) @@ -401,7 +401,8 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) } else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight ) { - fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); + if ( pindex->nTime < txtime ) + fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); return(0); } numblocks = (pindex->nHeight - txheight); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 754b9a900..d2ef49587 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,7 +268,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -304,11 +304,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { - fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; for (iter=-1; iter<=1; iter+=2) { @@ -360,7 +360,10 @@ void *dicefinish(void *_ptr) { CCduration(numblocks,ptr->txid); if ( numblocks > 0 ) + { + fprintf(stderr,"alread confirmed %s\n",ptr->txid.GetHex().c_str()); continue; + } } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) == 0 ) { @@ -426,7 +429,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); - } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } From 5b8a3ef0a061c06b8075aa94ed1b87e3b17866c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:57:41 -1100 Subject: [PATCH 593/749] Test --- src/cc/dice.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d2ef49587..553c0326f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,7 +268,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -304,11 +304,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; - fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; for (iter=-1; iter<=1; iter+=2) { @@ -343,9 +343,11 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { + fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { + fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -359,9 +361,9 @@ void *dicefinish(void *_ptr) if ( ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); + fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); if ( numblocks > 0 ) { - fprintf(stderr,"alread confirmed %s\n",ptr->txid.GetHex().c_str()); continue; } } From d9cdfd351c0a6d53e421e9e949c754ae6520e1a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:07:23 -1100 Subject: [PATCH 594/749] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 553c0326f..6db95049d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -304,11 +304,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { - fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; for (iter=-1; iter<=1; iter+=2) { @@ -336,6 +336,7 @@ void *dicefinish(void *_ptr) CCduration(numblocks,ptr->txid); if ( numblocks == 0 ) mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + else continue; } if ( ptr->txid == zeroid ) vin0_needed++; @@ -347,7 +348,7 @@ void *dicefinish(void *_ptr) utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { - fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); + //fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -367,7 +368,7 @@ void *dicefinish(void *_ptr) continue; } } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) == 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 ) { unstringbits(name,ptr->sbits); result = 0; From 8ceead3cc848bb8367ded771a5ad31bd45ceec5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:12:43 -1100 Subject: [PATCH 595/749] Test --- 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 6db95049d..e79186842 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -431,7 +431,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); - //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } From 139fd784f3ca1bbb7cce5a616b0677007869d7b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:21:08 -1100 Subject: [PATCH 596/749] -print --- src/cc/dice.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e79186842..d530727af 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -362,11 +362,9 @@ void *dicefinish(void *_ptr) if ( ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); - fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); + //fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); if ( numblocks > 0 ) - { continue; - } } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 ) { From a8dd451570f30be1105ef8382ad4d70dd4b554a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:25:19 -1100 Subject: [PATCH 597/749] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d530727af..015749207 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -299,9 +299,9 @@ void *dicefinish(void *_ptr) cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); - while ( (newht= KOMODO_INSYNC) == 0 ) - sleep(1); - sleep(10); + if ( (newht= KOMODO_INSYNC) == 0 ) + sleep(7); + sleep(3); while ( 1 ) { if ( newht != 0 && lastheight != newht ) @@ -1023,7 +1023,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); + //fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); From 4446bdb00f15a924b0ae66ba9226077592c251c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:26:10 -1100 Subject: [PATCH 598/749] Test --- 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 015749207..66e31b965 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1491,7 +1491,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx win++; else if ( iswin < 0 ) loss++; - fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); } From c395355cd004168e018c04c66d89b156574079e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:29:55 -1100 Subject: [PATCH 599/749] -print --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 66e31b965..06265778c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,7 +268,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -344,7 +344,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { - fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); + //fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { From 80c20a679a535d2db1e664913ace4a385ccf09dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:37:43 -1100 Subject: [PATCH 600/749] Test --- src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 9a1f41b31..aa5e731b3 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -53,6 +53,7 @@ one other technical note is that komodod has the insight-explorer extensions bui extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; extern uint32_t ASSETCHAINS_CC; +extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; #define SMALLVAL 0.000000000000001 diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 06265778c..c1d1d3acb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1525,7 +1525,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytxs); + char *cmd = malloc(100 * 128); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + printf("%s\n",cmd); + //for (i=0; i<=(mintxs - entropytxs)/100; i++) + system(cmd); + free(cmd); } } return(n); From f232fc4b1332bce80b5d14fd73d17625c7170d93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:42:12 -1100 Subject: [PATCH 601/749] Test --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c1d1d3acb..0d3dd769d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1525,11 +1525,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - char *cmd = malloc(100 * 128); + char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); printf("%s\n",cmd); //for (i=0; i<=(mintxs - entropytxs)/100; i++) - system(cmd); + if (system(cmd) != 0 ) + fprintf(stderr,"system error issuing.(%s)\n",cmd); free(cmd); } } From 2e646703126ad9a38b0dd0761db845677115472e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:45:52 -1100 Subject: [PATCH 602/749] Test --- 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 0d3dd769d..b03439899 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1526,7 +1526,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( entropytxs < mintxs ) { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); printf("%s\n",cmd); //for (i=0; i<=(mintxs - entropytxs)/100; i++) if (system(cmd) != 0 ) From b46196bd400dd456addc6d690b2815abdbdd63de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:49:21 -1100 Subject: [PATCH 603/749] esc --- 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 b03439899..8f46338ac 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1526,7 +1526,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( entropytxs < mintxs ) { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); printf("%s\n",cmd); //for (i=0; i<=(mintxs - entropytxs)/100; i++) if (system(cmd) != 0 ) From 84aa184a5f52f7c66009a7f2623d4c83b1841a77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:00:18 -1100 Subject: [PATCH 604/749] Test --- src/cc/dice.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8f46338ac..4aafc6541 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1525,13 +1525,17 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - char *cmd = (char *)malloc(100 * 128); + /*char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - printf("%s\n",cmd); - //for (i=0; i<=(mintxs - entropytxs)/100; i++) - if (system(cmd) != 0 ) - fprintf(stderr,"system error issuing.(%s)\n",cmd); - free(cmd); + printf("%s\n",cmd);*/ + for (i=0; i<=(mintxs - entropytxs)/100; i++) + { + if ( system("./sendmany") != 0 ) + { + fprintf(stderr,"system error issuing.(./sendmany)\n"); + break; + } + } } } return(n); From b7d5bb40f1e7d6b47148ad6eb6739f57c90252a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:05:42 -1100 Subject: [PATCH 605/749] scripts --- src/cc/dapps/diceloop | 7 +++++++ src/cc/dapps/sendmany | 3 +++ src/cc/dice.cpp | 1 + 3 files changed, 11 insertions(+) create mode 100755 src/cc/dapps/diceloop create mode 100755 src/cc/dapps/sendmany diff --git a/src/cc/dapps/diceloop b/src/cc/dapps/diceloop new file mode 100755 index 000000000..07d320c3b --- /dev/null +++ b/src/cc/dapps/diceloop @@ -0,0 +1,7 @@ +cat loop +while true +do +./c dicestatus KMDICE 5be49570c56d036abb08b6d084da93a8a86f58fc48db4a1086be95540d752d6f + +sleep 10 +done diff --git a/src/cc/dapps/sendmany b/src/cc/dapps/sendmany new file mode 100755 index 000000000..3941c2c89 --- /dev/null +++ b/src/cc/dapps/sendmany @@ -0,0 +1,3 @@ +export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo" +./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" + diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4aafc6541..fbdda9c42 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1530,6 +1530,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx printf("%s\n",cmd);*/ for (i=0; i<=(mintxs - entropytxs)/100; i++) { + fprintf(stderr,"sendmany.%d of %d\n",i,1 + (mintxs - entropytxs)/100); if ( system("./sendmany") != 0 ) { fprintf(stderr,"system error issuing.(./sendmany)\n"); From 9d271fd991a4318eb85dc785a2b9941ed2aadc32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:09:38 -1100 Subject: [PATCH 606/749] test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fbdda9c42..653324146 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1531,9 +1531,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx for (i=0; i<=(mintxs - entropytxs)/100; i++) { fprintf(stderr,"sendmany.%d of %d\n",i,1 + (mintxs - entropytxs)/100); - if ( system("./sendmany") != 0 ) + if ( system("cc/dapps/sendmany") != 0 ) { - fprintf(stderr,"system error issuing.(./sendmany)\n"); + fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n"); break; } } From b8f6ec6be7847961988caa5552c5fc64b440b179 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:10:13 -1100 Subject: [PATCH 607/749] Test --- 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 653324146..863f67673 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1232,7 +1232,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 } if ( scriptPubKey == fundingPubKey ) { - if ( AddNormalinputs(mtx,mypk,amount+2*txfee,10) > 0 ) + if ( AddNormalinputs(mtx,mypk,amount+2*txfee,1) > 0 ) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); From c79be9fc441ccff4e4e713d8129e93139d2a3122 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:33:16 -1100 Subject: [PATCH 608/749] Reduce --- src/cc/dapps/diceloop | 1 - src/cc/dapps/sendmany | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dapps/diceloop b/src/cc/dapps/diceloop index 07d320c3b..44550b46a 100755 --- a/src/cc/dapps/diceloop +++ b/src/cc/dapps/diceloop @@ -1,4 +1,3 @@ -cat loop while true do ./c dicestatus KMDICE 5be49570c56d036abb08b6d084da93a8a86f58fc48db4a1086be95540d752d6f diff --git a/src/cc/dapps/sendmany b/src/cc/dapps/sendmany index 3941c2c89..08ad34269 100755 --- a/src/cc/dapps/sendmany +++ b/src/cc/dapps/sendmany @@ -1,3 +1,3 @@ export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo" -./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" +./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" From f8ec508842abb852256fcbd1fcaf6b734b48bf5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:43:37 -1100 Subject: [PATCH 609/749] Test --- src/cc/dice.cpp | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 863f67673..1c671c3b3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -99,6 +99,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 +#define DICE_MINUTXOS 2500 extern int32_t KOMODO_INSYNC; @@ -344,6 +345,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { + num = 0; //fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) @@ -389,6 +391,18 @@ void *dicefinish(void *_ptr) } } free(utxos); + if ( newblock != 0 && num < DICE_MINUTXOS ) + { + char *cmd = (char *)malloc(100 * 128); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); + if ( system(cmd) != 0 ) + { + fprintf(stderr,"system error issuing.(%s)\n",cmd); + break; + } + free(cmd); + } } } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) @@ -1500,11 +1514,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } if ( scriptPubKey == fundingPubKey ) { - CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; + CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - if ( entropytxs < mintxs ) + if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -1514,30 +1528,13 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx //LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { - fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,mintxs - entropytxs); + fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,DICE_MINUTXOS - entropytxs); RelayTransaction(tx); } else break; } else break; } else break; } } - pubkey2addr(coinaddr,Mypubkey().data()); - dicefinish_utxosget(entropytxs,0,0,coinaddr); - if ( entropytxs < mintxs ) - { - /*char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - printf("%s\n",cmd);*/ - for (i=0; i<=(mintxs - entropytxs)/100; i++) - { - fprintf(stderr,"sendmany.%d of %d\n",i,1 + (mintxs - entropytxs)/100); - if ( system("cc/dapps/sendmany") != 0 ) - { - fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n"); - break; - } - } - } } return(n); } From 55a94d56dd3dc8fa8256100d63cbea098523b44b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 07:06:02 -1100 Subject: [PATCH 610/749] Test --- 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 1c671c3b3..cb26f0466 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -389,7 +389,7 @@ void *dicefinish(void *_ptr) break; } } - } + } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); if ( newblock != 0 && num < DICE_MINUTXOS ) { From 3db0fd1d4811aaffe5021a62b3321444123a8e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 07:40:32 -1100 Subject: [PATCH 611/749] Ignore <0 syncheight peers in longest chain calc --- src/rpcnet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index db6ffbc14..97bf5001d 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -179,6 +179,8 @@ int32_t komodo_longestchain() //fprintf(stderr,"komodo_longestchain iter.%d\n",n); CNodeStateStats statestats; bool fStateStats = GetNodeStateStats(stats.nodeid,statestats); + if ( statestats.nSyncHeight < 0 ) + continue; ht = 0; if ( stats.nStartingHeight > ht ) ht = stats.nStartingHeight; @@ -190,7 +192,6 @@ int32_t komodo_longestchain() maxheight = ht, num = 1; else if ( ht > maxheight*0.99 ) num++; - n++; if ( ht > height ) height = ht; } From 85700b4d387a21266df6545906c6036688d23201 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 07:53:44 -1100 Subject: [PATCH 612/749] Boost minute --- 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 cb26f0466..19c3cd33c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -99,7 +99,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 -#define DICE_MINUTXOS 2500 +#define DICE_MINUTXOS 7777 extern int32_t KOMODO_INSYNC; From 4435d2a327f0a76c7893c68e46adcc6b02b21dc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:12:27 -1100 Subject: [PATCH 613/749] Limit to 10 entropy per dice status --- 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 19c3cd33c..858336484 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1518,7 +1518,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From b8893893bb3f6147028837e4ddf0497056ba3e60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:18:36 -1100 Subject: [PATCH 614/749] 1 entropy per iter --- 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 858336484..8cfa3aef7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1518,7 +1518,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From 80671b17bd65d5b3ddb91ec8d06035acb0ac2a64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:36:56 -1100 Subject: [PATCH 615/749] Sendrawtransaction --- src/cc/dice.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8cfa3aef7..def8b932d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -105,6 +105,7 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; +static std::string DICE_ENTROPYTX; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -403,6 +404,15 @@ void *dicefinish(void *_ptr) } free(cmd); } + res = DICE_ENTROPYTX; + if ( res.empty() == 0 && res.size() > 64 ) + { + char cmdbuf[8192]; std::string res; + sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,res.c_str()); + fprintf(stderr,"(%s)\n",cmdbuf); + if ( system(cmdbuf) != 0 ) + fprintf(stderr,"error (%s)\n",cmdbuf); + } } } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) @@ -1523,6 +1533,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceAddfunding(txfee,planstr,fundingtxid,COIN/100); if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { + DICE_ENTROPYTX = res; if ( DecodeHexTx(tx,res) != 0 ) { //LOCK(cs_main); From 60152b4ea6f9c9efd7c860027311249ead637987 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:42:46 -1100 Subject: [PATCH 616/749] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index def8b932d..0515cdc0a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -404,11 +404,11 @@ void *dicefinish(void *_ptr) } free(cmd); } - res = DICE_ENTROPYTX; - if ( res.empty() == 0 && res.size() > 64 ) + std::string entropyrawtx = DICE_ENTROPYTX; + if ( entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) { - char cmdbuf[8192]; std::string res; - sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,res.c_str()); + char cmdbuf[8192]; + sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); fprintf(stderr,"(%s)\n",cmdbuf); if ( system(cmdbuf) != 0 ) fprintf(stderr,"error (%s)\n",cmdbuf); From 8753790c0f793583ab174309584628023eba5b10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:43:32 -1100 Subject: [PATCH 617/749] Test --- 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 0515cdc0a..f18202a82 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -405,7 +405,7 @@ void *dicefinish(void *_ptr) free(cmd); } std::string entropyrawtx = DICE_ENTROPYTX; - if ( entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) + if ( newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) { char cmdbuf[8192]; sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); From 25d97099312bbb084b631086c4a766180da099df Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:47:11 -1100 Subject: [PATCH 618/749] -print --- 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 f18202a82..9ee5414d9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -409,7 +409,7 @@ void *dicefinish(void *_ptr) { char cmdbuf[8192]; sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); - fprintf(stderr,"(%s)\n",cmdbuf); + //fprintf(stderr,"(%s)\n",cmdbuf); if ( system(cmdbuf) != 0 ) fprintf(stderr,"error (%s)\n",cmdbuf); } From 97a4ab754d90830544a10388aa9dd5c2bd8b2d23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:48:21 -1100 Subject: [PATCH 619/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9ee5414d9..a434a40ea 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -405,7 +405,7 @@ void *dicefinish(void *_ptr) free(cmd); } std::string entropyrawtx = DICE_ENTROPYTX; - if ( newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) + if ( 0 && newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) { char cmdbuf[8192]; sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); @@ -1528,7 +1528,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From 097324e1b0bd7f5dd4237087a769b58588109304 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 10:28:49 -1100 Subject: [PATCH 620/749] Test --- src/cc/dice.cpp | 24 ++++++++++++++---------- src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a434a40ea..fedb8a25c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -241,21 +241,24 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t total = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( myIsutxo_spentinmempool(it->first.txhash,(int32_t)it->first.index) == 0 ) + LOCK(mempool.cs); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) - continue; - total++; - if ( n < max ) + if ( myIsutxo_spentinmempool(it->first.txhash,(int32_t)it->first.index) == 0 ) { - if ( utxos != 0 ) + if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) + continue; + total++; + if ( n < max ) { - utxos[n].txid = it->first.txhash; - utxos[n].vout = (int32_t)it->first.index; + if ( utxos != 0 ) + { + utxos[n].txid = it->first.txhash; + utxos[n].vout = (int32_t)it->first.index; + } + n++; } - n++; } } } @@ -284,6 +287,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) } else*/ { + LOCK(mempool.cs); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4b5ef8a1f..4aaaef33c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6188,6 +6188,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; + LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { @@ -6223,6 +6224,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; + LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { From 071796aeabc556eabd64c84416f9a7fbba09c356 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 10:33:37 -1100 Subject: [PATCH 621/749] Test --- src/wallet/rpcwallet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4aaaef33c..4b5ef8a1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6188,7 +6188,6 @@ UniValue dicefinish(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { @@ -6224,7 +6223,6 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { From 18780bac5464b7201e273ef7c92ad840bc379813 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 11:01:58 -1100 Subject: [PATCH 622/749] Test --- 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 fedb8a25c..e71477836 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -287,7 +287,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) } else*/ { - LOCK(mempool.cs); + //LOCK(mempool.cs); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); From 452a53884c3ddf7cfb4aff48fd488febf85440c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 11:20:07 -1100 Subject: [PATCH 623/749] Test --- src/cc/dice.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e71477836..655282f8d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -335,6 +335,13 @@ void *dicefinish(void *_ptr) else if ( mytxid_inmempool(ptr->bettxid) != 0 ) ptr->bettxid_ready = (uint32_t)time(NULL); } + else if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) + { + fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + continue; + } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( newblock != 0 && ptr->txid != zeroid ) From 0cfa09657d15f8b68e1f1d53b9e864d94befad01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:01:23 -1100 Subject: [PATCH 624/749] +print --- src/cc/dice.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 655282f8d..7af6eba0e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -90,10 +90,9 @@ WARNING: there is an attack vector that precludes betting any large amounts, it What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy - need to speed up dealer dicestatus loop (or in parallel) - validate refund change to hashtables - + validate refund + */ #include "../compat/endian.h" @@ -276,16 +275,6 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } - /*if ( mode > 0 ) - { - CCduration(numblocks,txid); - if ( numblocks > 0 ) - { - fprintf(stderr,"%s txid.%s already confirmed %d\n",debugstr,txid.GetHex().c_str(),numblocks); - return(1); - } - } - else*/ { //LOCK(mempool.cs); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -464,7 +453,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); - fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } @@ -1018,7 +1007,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { From 0a14ecfbc82a68ccbd986042c85e63fad9aab0cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:09:42 -1100 Subject: [PATCH 625/749] Test --- src/cc/dice.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7af6eba0e..b7d952585 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -132,6 +132,18 @@ int32_t _dicehash_find(uint256 bettxid) return(0); } +int32_t _dicehash_clear(uint256 bettxid) +{ + int32_t i; + for (i=0; ibettxid); + pthread_mutex_unlock(&DICE_MUTEX); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); +} + void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; @@ -313,8 +334,7 @@ void *dicefinish(void *_ptr) if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + dicefinish_delete(ptr); continue; } if ( ptr->bettxid_ready == 0 ) @@ -327,8 +347,7 @@ void *dicefinish(void *_ptr) else if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + dicefinish_delete(ptr); continue; } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) @@ -358,8 +377,7 @@ void *dicefinish(void *_ptr) if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { fprintf(stderr,"purge2 %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + dicefinish_delete(ptr); continue; } if ( ptr->txid != zeroid ) From f9da823ed128131561afade6f229c2edbb2470de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:20:03 -1100 Subject: [PATCH 626/749] Test --- src/cc/dice.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b7d952585..a64ae898d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -472,7 +472,12 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); - } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + } + else + { + fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + _dicehash_clear(bettxid); + } pthread_mutex_unlock(&DICE_MUTEX); } From c485a6e2be7f66eb0c5a4f5f0f718a586c3d3ce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:34:28 -1100 Subject: [PATCH 627/749] Test --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a64ae898d..6a3ab4b33 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1538,10 +1538,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx win++; else if ( iswin < 0 ) loss++; - //fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } + } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } } From e2fff7f788315b5e97fb5ecaa2049554d88f5699 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:42:38 -1100 Subject: [PATCH 628/749] +print --- src/cc/dice.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6a3ab4b33..99d14d9e1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1527,20 +1527,23 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( vout != 0 ) continue; sum += it->second.satoshis; - if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { - if ( iswin > 0 ) - win++; - else if ( iswin < 0 ) - loss++; - n++; - DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + if ( iswin > 0 ) + win++; + else if ( iswin < 0 ) + loss++; + n++; + DiceQueue(iswin,sbits,fundingtxid,txid,betTx); + } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + } else fprintf(stderr,"bettxid.%s cant find entropyTx.%s\n",txid.GetHex().c_str(),betTx.vin[0].prevout.hash.GetHex().c_str()); } } } From bdb4fe1df37c48514fb358dd0939143028562aa4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:50:31 -1100 Subject: [PATCH 629/749] Test --- 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 99d14d9e1..0f17d5916 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -749,7 +749,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction } } else fprintf(stderr,"hentropy != hentropy2\n"); } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); - } //else fprintf(stderr,"notmine or not CC\n"); + } else fprintf(stderr,"notmine.%d or not CC\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); } From 0536c75beb99706a05fcf4e5487a58421c468148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:51:17 -1100 Subject: [PATCH 630/749] Test --- 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 0f17d5916..51046a818 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -749,7 +749,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction } } else fprintf(stderr,"hentropy != hentropy2\n"); } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); - } else fprintf(stderr,"notmine.%d or not CC\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); + } else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); } From 44b59c3cf6478adf1dabc6495937acecd08a116e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:06:38 -1100 Subject: [PATCH 631/749] Test --- src/cc/dice.cpp | 50 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 51046a818..10e16c5d9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -855,7 +855,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) DiceQueue(iswin,sbits,fundingtxid,txid,tx); - } + } // else return eval->Invalid(); break; // make sure all funding txid are from matching sbits and fundingtxid!! case 'L': @@ -1049,9 +1049,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } - if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) + if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinTx.vout.size() < 2 ) { - //fprintf(stderr,"skip coinbase\n"); + //fprintf(stderr,"skip coinbase or strange entropy tx\n"); continue; } //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) @@ -1382,7 +1382,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return(""); }*/ bettorentropy = DiceGetEntropy(betTx,'B'); - if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( winlosetimeout == 0 || ((iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 || iswin == 0) ) { if ( vin0txid == zeroid || vin0vout < 0 ) { @@ -1401,7 +1401,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) + if ( iswin == 0 ) + { + retval = -1; + fprintf(stderr,"invalid dicebet %s\n",bettxid.GetHex().c_str()); + } else retval = 0; + if ( retval < 0 || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) { if ( retval < 0 ) { @@ -1506,7 +1511,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; @@ -1533,16 +1538,31 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { - bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + flag = 0; + if ( scriptPubKey == fundingPubKey ) { - if ( iswin > 0 ) - win++; - else if ( iswin < 0 ) - loss++; - n++; - DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + if ( iswin > 0 ) + win++; + else if ( iswin < 0 ) + loss++; + n++; + DiceQueue(iswin,sbits,fundingtxid,txid,betTx); + } else flag = 1; + } + if ( flag != 0 || scriptPubKey != fundingPubKey ) + { + if ( flag != 0 ) + fprintf(stderr,"illegal bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + res = DiceBetFinish(&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + if ( result > 0 ) + { + mySendrawtransaction(res); + n++; + } + } } else fprintf(stderr,"bettxid.%s cant find entropyTx.%s\n",txid.GetHex().c_str(),betTx.vin[0].prevout.hash.GetHex().c_str()); } } From 2c574a7ed03044d0bdee5d5cac9004673d8a3bb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:09:29 -1100 Subject: [PATCH 632/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 10e16c5d9..7e4178618 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1556,10 +1556,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( flag != 0 ) fprintf(stderr,"illegal bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); - res = DiceBetFinish(&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey,zeroid,-1); if ( result > 0 ) { - mySendrawtransaction(res); + mySenddicetransaction(res,entropyused,txid,betTx,funcid,0); n++; } } From da81001b821d48b90a09f352641546c1d77b7fd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:22:21 -1100 Subject: [PATCH 633/749] Test --- src/cc/dice.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7e4178618..2783896e9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -763,7 +763,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { - uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; + uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -772,7 +772,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else { txid = tx.GetHash(); - if ( (funcid= DecodeDiceOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) + if ( (funcid= DecodeDiceOpRet(txid,tx.vout[numvouts-1].scriptPubKey,refsbits,fundingtxid,hash,proof)) != 0 ) { if ( eval->GetTxUnconfirmed(fundingtxid,fundingTx,hashBlock) == 0 ) return eval->Invalid("cant find fundingtxid"); @@ -781,6 +781,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) if ( maxodds > 9999 ) return eval->Invalid("maxodds too big"); fundingPubKey = fundingTx.vout[1].scriptPubKey; + if ( sbits != refsbits ) + { + fprintf(stderr,"VALIDATION ERROR: sbits %llx != refsbits %llx\n",(long long)sbits,(long long)refsbits)); + //return eval->Invalid("mismatched diceplan"); + } switch ( funcid ) { case 'F': @@ -855,7 +860,12 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) DiceQueue(iswin,sbits,fundingtxid,txid,tx); - } // else return eval->Invalid(); + } + else + { + fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid\n"); + //return eval->Invalid("invalid dicebet bettxid"); + } break; // make sure all funding txid are from matching sbits and fundingtxid!! case 'L': @@ -1025,7 +1035,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) { - if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) + if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits ) { if ( funcid == 'B' ) { @@ -1382,7 +1392,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return(""); }*/ bettorentropy = DiceGetEntropy(betTx,'B'); - if ( winlosetimeout == 0 || ((iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 || iswin == 0) ) + if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { if ( vin0txid == zeroid || vin0vout < 0 ) { @@ -1401,16 +1411,17 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( iswin == 0 ) + /*if ( iswin == 0 ) { retval = -1; fprintf(stderr,"invalid dicebet %s\n",bettxid.GetHex().c_str()); - } else retval = 0; - if ( retval < 0 || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) + } else retval = 0;*/ + if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) { if ( retval < 0 ) { fprintf(stderr,"orphan that reveals entropy, generate refund tx with proofs\n"); + // make sure we dont refund wrong amounts mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); funcid = 'R'; @@ -1511,8 +1522,8 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; - if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; return(0.); @@ -1534,7 +1545,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sum += it->second.satoshis; if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) + if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' && sbits == refsbits ) { if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { @@ -1550,7 +1561,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx loss++; n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } else flag = 1; + } //else flag = 1; } if ( flag != 0 || scriptPubKey != fundingPubKey ) { @@ -1570,7 +1581,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( scriptPubKey == fundingPubKey ) { CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs; - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { for (i=0; i Date: Thu, 8 Nov 2018 13:23:06 -1100 Subject: [PATCH 634/749] Test --- 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 2783896e9..f38cd42e5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -783,7 +783,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) fundingPubKey = fundingTx.vout[1].scriptPubKey; if ( sbits != refsbits ) { - fprintf(stderr,"VALIDATION ERROR: sbits %llx != refsbits %llx\n",(long long)sbits,(long long)refsbits)); + fprintf(stderr,"VALIDATION ERROR: sbits %llx != refsbits %llx\n",(long long)sbits,(long long)refsbits); //return eval->Invalid("mismatched diceplan"); } switch ( funcid ) From 025f3658ebda8b984980679bb74d00af219d9757 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:33:14 -1100 Subject: [PATCH 635/749] Test --- src/cc/dice.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f38cd42e5..c4021bcdf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -397,7 +397,7 @@ void *dicefinish(void *_ptr) ptr->rawtx = res; mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } - else + else if ( result != -2 ) { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); if ( ptr->rawtx.empty() == 0 ) @@ -749,7 +749,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction } } else fprintf(stderr,"hentropy != hentropy2\n"); } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); - } else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); + } //else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); } @@ -863,7 +863,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid\n"); + fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; @@ -1430,8 +1430,13 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); *resultp = 1; return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,entropyused,oldbettxid))); // need to change opreturn to include oldbetTx to allow validation - } else CCerror = "DiceBetFinish: duplicate betTx"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + } + else + { + CCerror = "DiceBetFinish: duplicate betTx"; + *resultp = -2; // demote error to warning + } + //fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } //fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); From c9a55cd48ac63479ec6e4e6634a5716f66dad3fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 14:19:28 -1100 Subject: [PATCH 636/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c4021bcdf..edf07f38b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -476,7 +476,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, else { fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); - _dicehash_clear(bettxid); + //_dicehash_clear(bettxid); } pthread_mutex_unlock(&DICE_MUTEX); } @@ -863,7 +863,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); + //fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; From 8ae9e63b092958ef13389c02bc18f768312af0f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 14:56:27 -1100 Subject: [PATCH 637/749] Test --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index edf07f38b..9a8f36341 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -435,6 +435,7 @@ void *dicefinish(void *_ptr) } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) sleep(1); + else usleep(100000); } return(0); } @@ -863,7 +864,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - //fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); + fprintf(stderr,"why does node1 get VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; From c0a342250e13483a8883cd53579860159f6d75e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 14:56:55 -1100 Subject: [PATCH 638/749] Test --- 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 9a8f36341..30dadcc65 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -864,7 +864,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - fprintf(stderr,"why does node1 get VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); + //fprintf(stderr,"why does node1 get VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; From b7a556e8382d56f2b41417a5791ec310e07a5ac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 19:42:44 -1100 Subject: [PATCH 639/749] -komodo_interestsum() for non-KMD --- src/bitcoind.cpp | 2 +- src/komodo_gateway.h | 3 ++- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 36fea57bf..f05b522fa 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -62,7 +62,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) } else { - komodo_interestsum(); + //komodo_interestsum(); komodo_longestchain(); MilliSleep(20000); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 379224b48..400ded593 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1380,7 +1380,8 @@ void komodo_passport_iteration() } if ( komodo_chainactive_timestamp() > lastinterest ) { - komodo_interestsum(); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + komodo_interestsum(); komodo_longestchain(); lastinterest = komodo_chainactive_timestamp(); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4b5ef8a1f..5f5cb5b28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2750,7 +2750,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { #ifdef ENABLE_WALLET - if ( GetBoolArg("-disablewallet", false) == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 ) { uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; From 6d5a5a0195de2f1cf5e6beb3e631b6b71955e974 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 19:52:48 -1100 Subject: [PATCH 640/749] Check for orphaned finish taxied --- src/cc/dice.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 30dadcc65..2678e2f46 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -350,6 +350,13 @@ void *dicefinish(void *_ptr) dicefinish_delete(ptr); continue; } + else if ( ptr->txid != zeroid && myGetTransaction(ptr->txid,betTx,hashBlock) == 0 ) + { + fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( ptr->rawtx.empty() == 0 ) + ptr->rawtx.clear(); + ptr->txid = zeroid; + } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( newblock != 0 && ptr->txid != zeroid ) From 4806dcf059276aee4d99447b7233fa07c63ddc53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:06:00 -1100 Subject: [PATCH 641/749] Test --- src/cc/dice.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2678e2f46..a30d678db 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -309,7 +309,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -350,18 +350,23 @@ void *dicefinish(void *_ptr) dicefinish_delete(ptr); continue; } - else if ( ptr->txid != zeroid && myGetTransaction(ptr->txid,betTx,hashBlock) == 0 ) + else if ( ptr->txid != zeroid ) { - fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); - if ( ptr->rawtx.empty() == 0 ) - ptr->rawtx.clear(); - ptr->txid = zeroid; + fprintf(stderr,"monitoring finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) + { + fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( ptr->rawtx.empty() == 0 ) + ptr->rawtx.clear(); + ptr->txid = zeroid; + } } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( newblock != 0 && ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); + fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); if ( numblocks == 0 ) mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); else continue; @@ -394,7 +399,7 @@ void *dicefinish(void *_ptr) if ( numblocks > 0 ) continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 && ptr->txid == zeroid ) { unstringbits(name,ptr->sbits); result = 0; From 9ca2a941365661d5537360080f1ab5990860f966 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:14:14 -1100 Subject: [PATCH 642/749] Print --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a30d678db..37bd3308c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -352,7 +352,6 @@ void *dicefinish(void *_ptr) } else if ( ptr->txid != zeroid ) { - fprintf(stderr,"monitoring finish txid.%s\n",ptr->txid.GetHex().c_str()); if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); @@ -422,7 +421,7 @@ void *dicefinish(void *_ptr) } } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( newblock != 0 && num < DICE_MINUTXOS ) + if ( num < DICE_MINUTXOS ) //newblock != 0 && { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); From 630f95cca4d7c227dc1304f959c1f6c72deadf30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:22:53 -1100 Subject: [PATCH 643/749] Gen utxos --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 37bd3308c..5809c2c22 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -421,10 +421,10 @@ void *dicefinish(void *_ptr) } } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( num < DICE_MINUTXOS ) //newblock != 0 && + if ( newblock != 0 && num < DICE_MINUTXOS ) // { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.023,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) { From 1bb800272e85fd647d86582c27a38a9bd781cce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:28:52 -1100 Subject: [PATCH 644/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5809c2c22..ef989dce3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -421,10 +421,10 @@ void *dicefinish(void *_ptr) } } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( newblock != 0 && num < DICE_MINUTXOS ) // + if ( newblock != 0 && num < DICE_MINUTXOS ) { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.023,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) { From f81a6da8372a4e12435f2b70287d376f63044d11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:46:37 -1100 Subject: [PATCH 645/749] Minimal validation of refund --- src/cc/dice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef989dce3..5280c5b0e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -425,7 +425,7 @@ void *dicefinish(void *_ptr) { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); + fprintf(stderr,"num normal 0.0002 utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) { fprintf(stderr,"system error issuing.(%s)\n",cmd); @@ -954,7 +954,12 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("invalid timeout claim for timeout"); break; case 'R': - fprintf(stderr,"add validation for refunds\n"); + if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("always should find vin.0, but didnt for refund"); + else if ( vinTx.vout[tx.vin[0].prevout.].scriptPubKey != fundingPubKey ) + return eval->Invalid("vin.0 not from fundingPubKey for refund"); + if ( (rand() % 100) == 0 ) + fprintf(stderr,"add more validation for refunds\n"); break; default: fprintf(stderr,"illegal dice funcid.(%c)\n",funcid); From 1969001bf258a5347d83d3f0d2250ca4be389f2e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:47:43 -1100 Subject: [PATCH 646/749] N --- 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 5280c5b0e..1e2e8931f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -956,7 +956,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) case 'R': if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt for refund"); - else if ( vinTx.vout[tx.vin[0].prevout.].scriptPubKey != fundingPubKey ) + else if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) return eval->Invalid("vin.0 not from fundingPubKey for refund"); if ( (rand() % 100) == 0 ) fprintf(stderr,"add more validation for refunds\n"); From 696af1e532d3fc56ed073e6ba1a22eecf0edd647 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:51:56 -1100 Subject: [PATCH 647/749] Test --- src/cc/dapps/sendmany | 2 +- src/cc/dice.cpp | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/cc/dapps/sendmany b/src/cc/dapps/sendmany index 08ad34269..45560b505 100755 --- a/src/cc/dapps/sendmany +++ b/src/cc/dapps/sendmany @@ -1,3 +1,3 @@ export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo" -./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" +./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023}" diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1e2e8931f..f49c92d3a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -104,7 +104,6 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; -static std::string DICE_ENTROPYTX; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -427,20 +426,14 @@ void *dicefinish(void *_ptr) sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); fprintf(stderr,"num normal 0.0002 utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) - { fprintf(stderr,"system error issuing.(%s)\n",cmd); - break; - } free(cmd); - } - std::string entropyrawtx = DICE_ENTROPYTX; - if ( 0 && newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) - { - char cmdbuf[8192]; - sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); - //fprintf(stderr,"(%s)\n",cmdbuf); - if ( system(cmdbuf) != 0 ) - fprintf(stderr,"error (%s)\n",cmdbuf); + if ( (rand() % 100) == 0 ) + { + fprintf(stderr,"make 0.023 utxos\n"); + if ( system("cc/dapps/sendmany") != 0 ) + fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n"); + } } } } @@ -1611,7 +1604,6 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceAddfunding(txfee,planstr,fundingtxid,COIN/100); if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { - DICE_ENTROPYTX = res; if ( DecodeHexTx(tx,res) != 0 ) { //LOCK(cs_main); From eafdbeb6ed33b6168001a16d31b5da48a5adad24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:52:28 -1100 Subject: [PATCH 648/749] Test --- 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 f49c92d3a..f83b1d1f5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -428,7 +428,7 @@ void *dicefinish(void *_ptr) if ( system(cmd) != 0 ) fprintf(stderr,"system error issuing.(%s)\n",cmd); free(cmd); - if ( (rand() % 100) == 0 ) + //if ( (rand() % 100) == 0 ) { fprintf(stderr,"make 0.023 utxos\n"); if ( system("cc/dapps/sendmany") != 0 ) From eb36c925f19b4ab6d115880df05d2c64e0ef44bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 21:04:47 -1100 Subject: [PATCH 649/749] Cmp refund to fundingaddr --- src/cc/dice.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f83b1d1f5..ac8be528b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -842,7 +842,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { - //if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; @@ -950,7 +949,16 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt for refund"); else if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) - return eval->Invalid("vin.0 not from fundingPubKey for refund"); + { + char fundingaddr[64],cmpaddr[64]; + Getscriptaddress(fundingaddr,fundingPubKey); + Getscriptaddress(cmpaddr,vinTx.vout[tx.vin[0].prevout.n].scriptPubKey); + if ( strcmp(cmpaddr,fundingaddr) != 0 ) + { + fprintf(stderr,"cmpaddr.%s != fundingaddr.%s\n",cmpaddr,fundingaddr); + return eval->Invalid("vin.0 not from fundingPubKey for refund"); + } + } if ( (rand() % 100) == 0 ) fprintf(stderr,"add more validation for refunds\n"); break; From c11899560869df55c5e63df85a6735d61b2546a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 21:06:57 -1100 Subject: [PATCH 650/749] -prints --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ac8be528b..425cc03f8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -428,7 +428,7 @@ void *dicefinish(void *_ptr) if ( system(cmd) != 0 ) fprintf(stderr,"system error issuing.(%s)\n",cmd); free(cmd); - //if ( (rand() % 100) == 0 ) + if ( (rand() % 100) == 0 ) { fprintf(stderr,"make 0.023 utxos\n"); if ( system("cc/dapps/sendmany") != 0 ) @@ -959,7 +959,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin.0 not from fundingPubKey for refund"); } } - if ( (rand() % 100) == 0 ) + if ( (rand() % 1000) == 0 ) fprintf(stderr,"add more validation for refunds\n"); break; default: From 9780765e5154e730e6db6ad095e5efefe09bf826 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 21:18:43 -1100 Subject: [PATCH 651/749] Reduce CPU usage --- src/cc/dice.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 425cc03f8..95056509d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -308,7 +308,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -325,12 +325,15 @@ void *dicefinish(void *_ptr) newblock = 1; fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; + now = (uint32_t)time(NULL); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) + if ( ptr->iswin != iter ) + continue; + if ( ptr->revealed != 0 && now > ptr->revealed+3600 ) { fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); dicefinish_delete(ptr); @@ -359,7 +362,7 @@ void *dicefinish(void *_ptr) ptr->txid = zeroid; } } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) + if ( ptr->bettxid_ready != 0 ) { if ( newblock != 0 && ptr->txid != zeroid ) { @@ -384,6 +387,8 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { + if ( ptr->iswin != iter ) + continue; if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { fprintf(stderr,"purge2 %s\n",ptr->bettxid.GetHex().c_str()); @@ -397,7 +402,7 @@ void *dicefinish(void *_ptr) if ( numblocks > 0 ) continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 && ptr->txid == zeroid ) + if ( ptr->bettxid_ready != 0 && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 && ptr->txid == zeroid ) { unstringbits(name,ptr->sbits); result = 0; @@ -418,7 +423,9 @@ void *dicefinish(void *_ptr) break; } } - } else dicefinish_utxosget(num,0,0,coinaddr); + } + else if ( newblock != 0 ) + dicefinish_utxosget(num,0,0,coinaddr); free(utxos); if ( newblock != 0 && num < DICE_MINUTXOS ) { @@ -438,8 +445,8 @@ void *dicefinish(void *_ptr) } } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) - sleep(1); - else usleep(100000); + sleep(3); + else usleep(500000); } return(0); } From 06353f85ec42ddf3ede92e39042f4f06d12b0eab Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 00:00:26 -1100 Subject: [PATCH 652/749] Test --- 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 95056509d..ddcc37b2d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -357,9 +357,11 @@ void *dicefinish(void *_ptr) if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); - if ( ptr->rawtx.empty() == 0 ) - ptr->rawtx.clear(); - ptr->txid = zeroid; + dicefinish_delete(ptr); + continue; + //if ( ptr->rawtx.empty() == 0 ) + // ptr->rawtx.clear(); + //ptr->txid = zeroid; } } if ( ptr->bettxid_ready != 0 ) @@ -488,7 +490,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, else { fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); - //_dicehash_clear(bettxid); + _dicehash_clear(bettxid); } pthread_mutex_unlock(&DICE_MUTEX); } From ee72233ba500385c77621b3388efd916268620cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 00:11:49 -1100 Subject: [PATCH 653/749] +print --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ddcc37b2d..b8d462442 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -423,7 +423,7 @@ void *dicefinish(void *_ptr) } if ( ++m >= n ) break; - } + } else fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str()); } } else if ( newblock != 0 ) @@ -490,7 +490,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, else { fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); - _dicehash_clear(bettxid); + //_dicehash_clear(bettxid); } pthread_mutex_unlock(&DICE_MUTEX); } From 37cb15f85758ca68d88c7928be0dc0613616cafb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 00:14:26 -1100 Subject: [PATCH 654/749] Test --- 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 b8d462442..7f184e0fd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -423,7 +423,7 @@ void *dicefinish(void *_ptr) } if ( ++m >= n ) break; - } else fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str()); + } else fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); } } else if ( newblock != 0 ) From f8c49d3871f07a5393e10a219220ccb8937e3dcb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 01:17:17 -1100 Subject: [PATCH 655/749] Test --- src/cc/dice.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7f184e0fd..218825500 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -357,11 +357,11 @@ void *dicefinish(void *_ptr) if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); - dicefinish_delete(ptr); - continue; - //if ( ptr->rawtx.empty() == 0 ) - // ptr->rawtx.clear(); - //ptr->txid = zeroid; + //dicefinish_delete(ptr); + //continue; + if ( ptr->rawtx.empty() == 0 ) + ptr->rawtx.clear(); + ptr->txid = zeroid; } } if ( ptr->bettxid_ready != 0 ) @@ -423,7 +423,11 @@ void *dicefinish(void *_ptr) } if ( ++m >= n ) break; - } else fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); + } + else + { + fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); + } } } else if ( newblock != 0 ) From 5e4bff9a829b67440921faacf8720d839b248259 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 01:20:51 -1100 Subject: [PATCH 656/749] Test --- 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 218825500..5aabccbe9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -426,7 +426,7 @@ void *dicefinish(void *_ptr) } else { - fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); + //fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); } } } From de7200a2abb768e2b2785dcd661bd47221886021 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 01:49:48 -1100 Subject: [PATCH 657/749] Fix CCassetstx --- src/cc/CCassetstx.cpp | 2 +- src/cc/dice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 4bc1adc42..64b380900 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -21,7 +21,7 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - threshold = total/maxinputs; + threshold = total/(maxinputs!=0?maxinputs:64); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5aabccbe9..aa7cb6447 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -493,7 +493,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, } else { - fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + //fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); //_dicehash_clear(bettxid); } pthread_mutex_unlock(&DICE_MUTEX); From 587d01f78a20e2cf35e79ff431636a939ec55c01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 01:56:16 -1100 Subject: [PATCH 658/749] Test --- 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 aa7cb6447..8b39f09b6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1048,7 +1048,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int numtxs = unspentOutputs.size()/8; + int numtxs = unspentOutputs.size()/2; int startfrom = rand() % (numtxs+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 70780561e024815a10c2ba85f528169da5464d67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 02:03:01 -1100 Subject: [PATCH 659/749] Test --- src/cc/dice.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8b39f09b6..e70bc88bb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1064,7 +1064,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits ) { @@ -1109,12 +1109,15 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr," (%c) entropy vin.%d fundingPubKey mismatch %s\n",funcid,1,uint256_str(str,tx.vin[0].prevout.hash));*/ continue; } - entropytxid = txid; - entropyval = tx.vout[0].nValue; - //fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); - first = 1; - if (random) { - fprintf(stderr, "chosen entropy on loop: %d\n",loops); + if ( myIsutxo_spentinmempool(txid,vout) == 0 ) + { + entropytxid = txid; + entropyval = tx.vout[0].nValue; + //fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); + first = 1; + if (random) { + fprintf(stderr, "chosen entropy on loop: %d\n",loops); + } } } else @@ -1339,7 +1342,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { - CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval,entropyval2; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropytxid2,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) { CCerror = "bet must be positive"; @@ -1361,7 +1364,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + DicePlanFunds(entropyval2,entropytxid2,sbits,cp,dicepk,fundingtxid,emptyvar,true); + if ( entropyval2 != 0 && entropytxid2 != zeroid ) + { + entropyval = entropyval2; + entropytxid = entropytxid2; + } if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 7335bfe2fc3ced155006944652cde1ad2bb22816 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 02:04:54 -1100 Subject: [PATCH 660/749] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e70bc88bb..a44d7f943 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1054,6 +1054,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { txid = it->first.txhash; vout = (int32_t)it->first.index; + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + if ( vout != 0 ) continue; sum += it->second.satoshis; From 7eb4d6c526900c66005b7887b8cfeaec646da090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 02:06:56 -1100 Subject: [PATCH 661/749] Test --- src/cc/dice.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a44d7f943..372cea0f7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1054,8 +1054,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { txid = it->first.txhash; vout = (int32_t)it->first.index; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); - if ( vout != 0 ) continue; sum += it->second.satoshis; @@ -1077,7 +1075,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + if ( (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; From ab86de1c712019c6bf80083523ccc38c0dc2c205 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 02:09:36 -1100 Subject: [PATCH 662/749] Test --- src/cc/dice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 372cea0f7..3423afdbb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1093,13 +1093,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinTx.vout.size() < 2 ) { - //fprintf(stderr,"skip coinbase or strange entropy tx\n"); + fprintf(stderr,"skip coinbase or strange entropy tx\n"); continue; } //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { - /*uint8_t *ptr0,*ptr1; int32_t i; char str[65]; + uint8_t *ptr0,*ptr1; int32_t i; char str[65]; ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); ptr1 = (uint8_t *)fundingPubKey.data(); for (i=0; i Date: Fri, 9 Nov 2018 02:15:38 -1100 Subject: [PATCH 663/749] Allow p2pkh as entropy vin --- src/cc/dice.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3423afdbb..31b50c848 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1099,16 +1099,21 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { - uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); - ptr1 = (uint8_t *)fundingPubKey.data(); - for (i=0; i Date: Fri, 9 Nov 2018 02:20:03 -1100 Subject: [PATCH 664/749] Allow p2pkh in validation --- src/cc/dice.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 31b50c848..0316384ab 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -857,19 +857,24 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { - uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - fprintf(stderr,"betTx.%s\n",uint256_str(str,txid)); - fprintf(stderr,"entropyTx.%s v%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n); - fprintf(stderr,"entropyTx vin0 %s v%d\n",uint256_str(str,vinTx.vin[0].prevout.hash),(int32_t)vinTx.vin[0].prevout.n); - ptr0 = (uint8_t *)vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey.data(); - ptr1 = (uint8_t *)fundingPubKey.data(); - for (i=0; iInvalid("vin1 of entropy tx not fundingPubKey for bet"); + uint8_t *ptr0,*ptr1; int32_t i; char str[65],addr0[64],addr1[64]; + Getscriptaddress(addr0,vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey); + Getscriptaddress(addr1,fundingPubKey); + if ( strcmp(addr0,addr1) != 0 ) + { + fprintf(stderr,"%s != %s betTx.%s\n",addr0,addr1,uint256_str(str,txid)); + fprintf(stderr,"entropyTx.%s v%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n); + fprintf(stderr,"entropyTx vin0 %s v%d\n",uint256_str(str,vinTx.vin[0].prevout.hash),(int32_t)vinTx.vin[0].prevout.n); + ptr0 = (uint8_t *)vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey.data(); + ptr1 = (uint8_t *)fundingPubKey.data(); + for (i=0; iInvalid("vin1 of entropy tx not fundingPubKey for bet"); + } } } if ( (iswin= DiceIsWinner(entropy,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) @@ -1075,7 +1080,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); if ( (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) From b2d48fc125110986e13b1c303487891f5c57814c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 03:15:52 -1100 Subject: [PATCH 665/749] Fix netinfo balance --- src/rpcmisc.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 8baf67c5d..e538ec8e7 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -122,9 +122,15 @@ UniValue getinfo(const UniValue& params, bool fHelp) #ifdef ENABLE_WALLET if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); - obj.push_back(Pair("balance", ValueFromAmount(KOMODO_WALLETBALANCE))); //pwalletMain->GetBalance() if ( ASSETCHAINS_SYMBOL[0] == 0 ) - obj.push_back(Pair("interest", ValueFromAmount(KOMODO_INTERESTSUM))); //komodo_interestsum() + { + obj.push_back(Pair("interest", ValueFromAmount(KOMODO_INTERESTSUM))); + obj.push_back(Pair("balance", ValueFromAmount(KOMODO_WALLETBALANCE))); //pwalletMain->GetBalance() + } + else + { + obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); // + } } #endif //fprintf(stderr,"after wallet %u\n",(uint32_t)time(NULL)); From c472dec4319729d61b9c45ec65a2bb181435c7be Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 9 Nov 2018 07:31:58 -1100 Subject: [PATCH 666/749] P2p and roc port in getinfo --- src/rpcmisc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index e538ec8e7..e4f1ffdf0 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -172,11 +172,11 @@ UniValue getinfo(const UniValue& params, bool fHelp) if ( ASSETCHAINS_CC != 0 ) obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC)); obj.push_back(Pair("name", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)); + obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT)); + obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT)); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { //obj.push_back(Pair("name", ASSETCHAINS_SYMBOL)); - obj.push_back(Pair("p2pport", ASSETCHAINS_P2PPORT)); - obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT)); obj.push_back(Pair("magic", (int)ASSETCHAINS_MAGIC)); if ( ASSETCHAINS_SUPPLY != 0 ) obj.push_back(Pair("premine", ASSETCHAINS_SUPPLY)); From 96073d7981d23300bcdcf205ab93ba263afa783f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:07:16 -1100 Subject: [PATCH 667/749] -ac_founders --- src/komodo_bitcoind.h | 19 ++++++++++++++----- src/komodo_globals.h | 2 +- src/komodo_utils.h | 28 ++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 76216efee..553b7dea4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1110,14 +1110,23 @@ uint64_t komodo_commission(const CBlock *pblock) { int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; txn_count = pblock->vtx.size(); - for (i=0; ivtx[i].vout.size(); + n = pblock->vtx[0].vout.size(); for (j=0; jvtx[i].vout[j].nValue; + } + else + { + for (i=0; ivtx[i].vout[j].nValue; + n = pblock->vtx[i].vout.size(); + for (j=0; jvtx[i].vout[j].nValue; + } } } //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 6d0b10328..057fec6c6 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,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,ASSETCHAINS_TXPOW; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index dd7082ffa..50f3ac651 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1555,6 +1555,7 @@ void komodo_args(char *argv0) { MAX_BLOCK_SIGOPS = 60000; ASSETCHAINS_TXPOW = GetArg("-ac_txpow",0) & 3; + ASSETCHAINS_FOUNDERS = GetArg("-ac_founders",0) & 1; ASSETCHAINS_SUPPLY = GetArg("-ac_supply",10); ASSETCHAINS_ENDSUBSIDY = GetArg("-ac_end",0); ASSETCHAINS_REWARD = GetArg("-ac_reward",0); @@ -1585,13 +1586,28 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) - decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); - else if ( ASSETCHAINS_COMMISSION != 0 ) { - ASSETCHAINS_COMMISSION = 0; - printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); + decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); + if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 ) + { + ASSETCHAINS_COMMISSION = 35000000; + printf("ASSETCHAINS_COMMISSION defaulted to 35% when founders reward active\n"); + } } - 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 ) + else + { + if ( ASSETCHAINS_COMMISSION != 0 ) + { + ASSETCHAINS_COMMISSION = 0; + printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); + } + if ( ASSETCHAINS_FOUNDERS != 0 ) + { + ASSETCHAINS_FOUNDERS = 0; + printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); + } + } + 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 ) { 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]); extraptr = extrabuf; @@ -1600,7 +1616,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW || (ASSETCHAINS_FOUNDERS & 1) << 2); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); From 6bbd32f7bb1013137c77f2378056af2f98b7761a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:13:22 -1100 Subject: [PATCH 668/749] ( --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 50f3ac651..bb447a4d3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1591,7 +1591,7 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 ) { ASSETCHAINS_COMMISSION = 35000000; - printf("ASSETCHAINS_COMMISSION defaulted to 35% when founders reward active\n"); + printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } } else @@ -1616,7 +1616,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW || (ASSETCHAINS_FOUNDERS & 1) << 2); + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW || ((ASSETCHAINS_FOUNDERS & 1) << 2); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); From 0b4e6bb9f82b1906e458ab450599d65ab8cdb77c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:39:59 -1100 Subject: [PATCH 669/749] Min MAX_MONEY for CC chains, set to 1 million --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index bb447a4d3..ef0bbb75f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1629,6 +1629,8 @@ void komodo_args(char *argv0) MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN; else MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; + if ( ASSETCHAINS_CC != 0 && MAX_MONEY < 1000000LL*COIN ) + MAX_MONEY = 1000000LL*COIN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From 4c19084cd7b512bbc0c597ed4d7ac9d7df315045 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:45:04 -1100 Subject: [PATCH 670/749] SATOSHIDEN --- 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 ef0bbb75f..d71b8cbee 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1629,7 +1629,7 @@ void komodo_args(char *argv0) MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN; else MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; - if ( ASSETCHAINS_CC != 0 && MAX_MONEY < 1000000LL*COIN ) + if ( ASSETCHAINS_CC != 0 && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*COIN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); From 10b571ddfde5ab482a1183b24c1090465748c69e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:46:45 -1100 Subject: [PATCH 671/749] Fix --- 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 d71b8cbee..9ceb69f78 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1630,7 +1630,7 @@ void komodo_args(char *argv0) else MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; if ( ASSETCHAINS_CC != 0 && MAX_MONEY < 1000000LL*SATOSHIDEN ) - MAX_MONEY = 1000000LL*COIN; + MAX_MONEY = 1000000LL*SATOSHIDEN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From a2c903014097346206138bf2e2c64fb0bd7ea63d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:55:36 -1100 Subject: [PATCH 672/749] if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) --- 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 9ceb69f78..d1c927787 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1629,7 +1629,7 @@ void komodo_args(char *argv0) MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN; else MAX_MONEY = (ASSETCHAINS_SUPPLY+100) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; - if ( ASSETCHAINS_CC != 0 && MAX_MONEY < 1000000LL*SATOSHIDEN ) + if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); From 9a4e737db3b21ad01f7750d154019289551b3bf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 01:57:22 -1100 Subject: [PATCH 673/749] #define KOMODO_FIRSTFUNGIBLEID 100 --- src/komodo_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 1efd187d9..ca9a05c37 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -9,6 +9,7 @@ #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +#define KOMODO_FIRSTFUNGIBLEID 100 extern uint8_t ASSETCHAINS_TXPOW; From 27a25b20731924ad8f97c3ffd0b369aa666b4606 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 02:06:04 -1100 Subject: [PATCH 674/749] Allow p2pkh for ac_pubkey chains --- src/komodo_bitcoind.h | 3 +++ src/komodo_globals.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 553b7dea4..ae16d513c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1482,7 +1482,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + { + if ( script[0] != 25 || script[0] != OP_DUP || script[1] != OP_HASH160 || script[23] != OP_EQUALVERIFY || script[24] != OP_CHECKSIG || memcmp(script+2,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) != 0 ) return(-1); + } if ( pblock->vtx[0].vout[1].nValue != checktoshis ) { fprintf(stderr,"ht.%d checktoshis %.8f vs actual vout[1] %.8f\n",height,dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 057fec6c6..78f1e1cac 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,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,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; From c29bc5d02e608c2eb02c45b63164a04cb2b002a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 02:10:11 -1100 Subject: [PATCH 675/749] Calculate rmd160 for ac_pubkey --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d1c927787..2e0c45549 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1588,6 +1588,7 @@ void komodo_args(char *argv0) if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) { 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 ) { ASSETCHAINS_COMMISSION = 35000000; From 8cb45c21edf50cc470179b78244f8420181b0119 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 02:27:37 -1100 Subject: [PATCH 676/749] Test --- src/komodo_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2e0c45549..265f79248 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1617,8 +1617,10 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW || ((ASSETCHAINS_FOUNDERS & 1) << 2); + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); + if ( ASSETCHAINS_FOUNDERS != 0 ) + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); } addn = GetArg("-seednode",""); if ( strlen(addn.c_str()) > 0 ) From 093f5ffa73a57332ae61ac9412d014ff0195ff0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 02:29:55 -1100 Subject: [PATCH 677/749] Test --- 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 265f79248..8fb50c23e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1617,7 +1617,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW); + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); From 6c1588f663491ad7028bd5a5e5b2234fc1be900b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 02:57:18 -1100 Subject: [PATCH 678/749] Entropyvout --- src/cc/dice.cpp | 74 ++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0316384ab..05f448550 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -104,6 +104,7 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; +static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -115,7 +116,7 @@ struct dicefinish_info uint256 fundingtxid,bettxid,entropyused,txid; uint64_t sbits; int64_t winamount; - int32_t iswin; + int32_t iswin,entropyvout; uint32_t bettxid_ready,revealed; CTransaction betTx; std::string rawtx; @@ -155,25 +156,26 @@ void _dicehash_add(uint256 bettxid) bettxids[rand() % MAX_ENTROPYUSED] = bettxid; } -int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) +int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &oldentropyvout,uint256 entropyused,uint256 bettxid,int32_t entropyvout) { int32_t i; for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) @@ -213,7 +216,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C if ( ptr != 0 ) ptr->txid = tx.GetHash(); //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) + if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,oldentropyvout,entropyused,bettxid,betTx,entropyvout)) >= 0 ) { //LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) @@ -371,7 +374,7 @@ void *dicefinish(void *_ptr) CCduration(numblocks,ptr->txid); fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); if ( numblocks == 0 ) - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); else continue; } if ( ptr->txid == zeroid ) @@ -408,11 +411,11 @@ void *dicefinish(void *_ptr) { unstringbits(name,ptr->sbits); result = 0; - res = DiceBetFinish(ptr->funcid,ptr->entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + res = DiceBetFinish(ptr->funcid,ptr->entropyused,ptr->entropyvout,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { ptr->rawtx = res; - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } else if ( result != -2 ) { @@ -457,7 +460,7 @@ void *dicefinish(void *_ptr) return(0); } -void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) +void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx,int32_t entropyvout) { static int32_t didinit; struct dicefinish_info *ptr; int32_t i,duplicate=0; uint64_t txfee = 10000; @@ -488,6 +491,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->entropyvout = entropyvout; DL_APPEND(DICEFINISH_LIST,ptr); fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); } @@ -512,7 +516,7 @@ CPubKey DiceFundingPk(CScript scriptPubKey) return(pk); } -uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv) // max 1 vout per txid used +uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout) { int32_t i; uint8_t _entropy[32],_hentropy[32]; bits256 tmp256,txidpub,txidpriv,mypriv,mypub,ssecret,ssecret2; uint256 hentropy; memset(&hentropy,0,32); @@ -741,7 +745,7 @@ bool DiceIsmine(const CScript scriptPubKey) return(strcmp(destaddr,myaddr) == 0); } -int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction vinTx,uint256 bettorentropy,uint64_t sbits,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 fundingtxid) +int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransaction tx,CTransaction vinTx,uint256 bettorentropy,uint64_t sbits,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 fundingtxid) { uint64_t vinsbits,winnings; uint256 vinproof,vinfundingtxid,hentropy,hentropy2; uint8_t funcid; //char str[65],str2[65]; @@ -749,7 +753,9 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction { if ( ((funcid= DecodeDiceOpRet(txid,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,hentropy,vinproof)) == 'E' || funcid == 'W' || funcid == 'L') && sbits == vinsbits && fundingtxid == vinfundingtxid ) { - hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); + hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n); + entropyvout = vinTx.vin[0].prevout.n; + fprintf(stderr,"bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); @@ -781,7 +787,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { - uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; + uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,entropyvout,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -877,11 +883,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } } } - if ( (iswin= DiceIsWinner(entropy,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( (iswin= DiceIsWinner(entropy,entropyvout,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) - DiceQueue(iswin,sbits,fundingtxid,txid,tx); + DiceQueue(iswin,sbits,fundingtxid,txid,tx,entropyvout); } else { @@ -1336,7 +1342,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 { if ( AddNormalinputs(mtx,mypk,amount+2*txfee,1) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('E',sbits,fundingtxid,hentropy,zeroid))); @@ -1395,7 +1401,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); if ( AddNormalinputs(mtx,mypk,bet+2*txfee+odds,60) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); mtx.vout.push_back(MakeCC1vout(cp->evalcode,entropyval,dicepk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -1409,9 +1415,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,entropyvout,retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; @@ -1442,7 +1448,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return(""); }*/ bettorentropy = DiceGetEntropy(betTx,'B'); - if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,entropyvout,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { if ( vin0txid == zeroid || vin0vout < 0 ) { @@ -1466,7 +1472,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, retval = -1; fprintf(stderr,"invalid dicebet %s\n",bettxid.GetHex().c_str()); } else retval = 0;*/ - if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) + if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,oldentropyvout,entropyused,bettxid,betTx,entropyvout)) != 0 ) { if ( retval < 0 ) { @@ -1557,7 +1563,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, } //fprintf(stderr,"make tx.%c\n",funcid); if ( funcid == 'L' || funcid == 'W' ) // dealernode only - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); *resultp = 1; //char str[65],str2[65]; //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); @@ -1577,7 +1583,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,entropyvout,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; @@ -1608,24 +1614,24 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( scriptPubKey == fundingPubKey ) { bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( (iswin= DiceIsWinner(hentropyproof,entropyvout,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { if ( iswin > 0 ) win++; else if ( iswin < 0 ) loss++; n++; - DiceQueue(iswin,sbits,fundingtxid,txid,betTx); + DiceQueue(iswin,sbits,fundingtxid,txid,betTx,entropyvout); } //else flag = 1; } if ( flag != 0 || scriptPubKey != fundingPubKey ) { if ( flag != 0 ) fprintf(stderr,"illegal bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey,zeroid,-1); + res = DiceBetFinish(funcid,entropyused,entropyvout,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey,zeroid,-1); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,txid,betTx,funcid,0); + mySenddicetransaction(res,entropyused,entropyvout,txid,betTx,funcid,0); n++; } } @@ -1676,11 +1682,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1,zeroid,-1); - else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0,zeroid,-1); + res = DiceBetFinish(funcid,entropyused,entropyvout,&result,txfee,planstr,fundingtxid,bettxid,1,zeroid,-1); + else res = DiceBetFinish(funcid,entropyused,entropyvout,&result,txfee,planstr,fundingtxid,bettxid,0,zeroid,-1); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid,betTx,funcid,0); + mySenddicetransaction(res,entropyused,entropyvout,bettxid,betTx,funcid,0); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From f82a0196dbbdaa209993fd79b51590bf68d39b3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:02:53 -1100 Subject: [PATCH 679/749] Fix --- src/cc/dice.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05f448550..7f1f728eb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -227,7 +227,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,int32_t entropyvo if ( ptr != 0 ) ptr->revealed = (uint32_t)time(NULL); pthread_mutex_lock(&DICEREVEALED_MUTEX); - _dicerevealed_add(entropyused,bettxid,betTx); + _dicerevealed_add(entropyused,bettxid,betTx,entropyvout); pthread_mutex_unlock(&DICEREVEALED_MUTEX); fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -411,7 +411,11 @@ void *dicefinish(void *_ptr) { unstringbits(name,ptr->sbits); result = 0; - res = DiceBetFinish(ptr->funcid,ptr->entropyused,ptr->entropyvout,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + res = DiceBetFinish(ptr->funcid,entropyused,entropyvout,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + if ( entropyused != ptr->entropyused || entropyvout != ptr->entropyvout ) + { + fprintf(stderr,"WARNING entropy %s != %s || %d != %d\n",entropyused.GetHex().c_str(),ptr->entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); + } if ( result > 0 ) { ptr->rawtx = res; @@ -1417,7 +1421,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,entropyvout,retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; From 1fdbde84b8151d93aedd57d35680f230daec68d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:03:56 -1100 Subject: [PATCH 680/749] Fix --- 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 7f1f728eb..535621b6d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -311,7 +311,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CTransaction betTx,finishTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); From 6390d04064ac6aabf9027ccc925aab059b64bda9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:07:16 -1100 Subject: [PATCH 681/749] Test --- src/cc/CCdice.h | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index bd8d1d5fa..8c67d86fe 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); -std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5f5cb5b28..394ff4a35 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6182,7 +6182,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicefinish(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint8_t funcid; char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; + UniValue result(UniValue::VOBJ); uint8_t funcid; char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r,entropyvout; if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -6196,7 +6196,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1,zeroid,-1); + hex = DiceBetFinish(funcid,entropyused,entropyvout,&r,0,name,fundingtxid,bettxid,1,zeroid,-1); if ( CCerror != "" ) { ERR_RESULT(CCerror); From 9841d2984e853a06ccc736cfa9d91e5b8405bbe6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:10:10 -1100 Subject: [PATCH 682/749] Test --- src/cc/CCinclude.h | 2 +- src/cc/channels.cpp | 6 +++--- src/cc/lotto.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index aa5e731b3..41f5ccacd 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -125,7 +125,7 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); // CCutils CPubKey buf2pk(uint8_t *buf33); void endiancpy(uint8_t *dest,uint8_t *src,int32_t len); -uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv); +uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t entropyvout); CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk); CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 672e426a8..e5b77feb2 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -446,7 +446,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 funds = numpayments * payment; if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); endiancpy(hash,(uint8_t *)&hentropy,32); for (i=0; i 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) { - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash, channelOpenTx.vin[0].prevout.n); endiancpy(hash, (uint8_t * ) & hentropy, 32); for (i = 0; i < param1; i++) { diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index d6d881603..6361b9291 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -292,7 +292,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic sbits = stringbits(planstr); if ( AddNormalinputs(mtx,mypk,funding+txfee,60) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,funding,lottopk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_LOTTO << (uint8_t)'F' << sbits << ticketsize << odds << firstheight << period << hentropy))); } From ca9e12808036f20ca05af06bf59adef2a3bc6b0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:23:16 -1100 Subject: [PATCH 683/749] Test --- src/cc/dice.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 535621b6d..034977a1d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -412,6 +412,11 @@ void *dicefinish(void *_ptr) unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(ptr->funcid,entropyused,entropyvout,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + if ( ptr->entropyused == zeroid ) + { + ptr->entropyused = entropyused; + ptr->entropyvout = entropyvout; + } if ( entropyused != ptr->entropyused || entropyvout != ptr->entropyvout ) { fprintf(stderr,"WARNING entropy %s != %s || %d != %d\n",entropyused.GetHex().c_str(),ptr->entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); From 3fb115a5a06dbf7258eb9351daa8599d9a9866e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:32:29 -1100 Subject: [PATCH 684/749] Test --- src/cc/dice.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 034977a1d..98a507ea0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -102,7 +102,7 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; -static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable +static uint256 bettxids[MAX_ENTROPYUSED],entropyused[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; static int32_t entropyvouts[MAX_ENTROPYUSED]; @@ -161,15 +161,18 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o int32_t i; for (i=0; i Date: Sat, 10 Nov 2018 03:34:37 -1100 Subject: [PATCH 685/749] Test --- src/cc/dice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 98a507ea0..818efbfab 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -102,7 +102,7 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; -static uint256 bettxids[MAX_ENTROPYUSED],entropyused[MAX_ENTROPYUSED][2]; // change to hashtable +static uint256 bettxids[MAX_ENTROPYUSED],Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; static int32_t entropyvouts[MAX_ENTROPYUSED]; @@ -161,14 +161,14 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o int32_t i; for (i=0; i Date: Sat, 10 Nov 2018 03:40:44 -1100 Subject: [PATCH 686/749] Test --- 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 818efbfab..fdd3a9bd4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -767,7 +767,7 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac { hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n); entropyvout = vinTx.vin[0].prevout.n; - fprintf(stderr,"bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + fprintf(stderr,"%d bettxid %s -> vin0 %s/v%d -> %s\n",KOMODO_CONNECTING,txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); From 70b30de84b3e11cdf6dd25e75d4f49ebfdd769ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:44:29 -1100 Subject: [PATCH 687/749] Test --- 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 fdd3a9bd4..f5b342cec 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -767,7 +767,7 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac { hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n); entropyvout = vinTx.vin[0].prevout.n; - fprintf(stderr,"%d bettxid %s -> vin0 %s/v%d -> %s\n",KOMODO_CONNECTING,txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + fprintf(stderr,"%d bettxid %s -> vin0 %s/v%d -> %s\n",KOMODO_CONNECTING & ((1<<30) - 1),txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); From dcbcc65cba37d817a3f9f122db8f55d96cf57401 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:45:05 -1100 Subject: [PATCH 688/749] +print --- 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 f5b342cec..d2c3c85dd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -767,7 +767,7 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac { hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n); entropyvout = vinTx.vin[0].prevout.n; - fprintf(stderr,"%d bettxid %s -> vin0 %s/v%d -> %s\n",KOMODO_CONNECTING & ((1<<30) - 1),txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + fprintf(stderr,"%d mem.%d bettxid %s -> vin0 %s/v%d -> %s\n",KOMODO_CONNECTING & ((1<<30) - 1),(KOMODO_CONNECTING & (1<<30)) != 0,txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); From 6c357b930fcda111160b92c61ae0efe46b48f081 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 03:49:20 -1100 Subject: [PATCH 689/749] -print --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d2c3c85dd..9f5d83979 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1162,7 +1162,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr," (%c) tx vin.%d fundingPubKey mismatch %s\n",funcid,tx.vin[0].prevout.n,uint256_str(str,tx.vin[0].prevout.hash)); } } - } else fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); + } + else if ( funcid != 'B' ) + fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case funcid (%c) %d %s vs %s\n",funcid,funcid,uint256_str(str,reffundingtxid),uint256_str(str2,fundingtxid)); } //else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); } i = i + 1; From 37229257354bfdc9a591ea77acb819f5dba7680b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 04:33:05 -1100 Subject: [PATCH 690/749] +print --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8fb50c23e..9be15277d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1634,6 +1634,7 @@ void komodo_args(char *argv0) MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; + fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From e1f20c0b202be1a9008ca3ca796552a5ac85fa99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 04:35:46 -1100 Subject: [PATCH 691/749] Cap MAX_MONEY --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9be15277d..e669e1368 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1634,6 +1634,8 @@ void komodo_args(char *argv0) MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; + if ( MAX_MONEY < 0 || MAX_MONEY > 1000000000LL*SATOSHIDEN ) + MAX_MONEY = 1000000000LL*SATOSHIDEN; fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); From fa7e40ac2872e048fd7fb0648b4e45e09d7af89d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 04:36:03 -1100 Subject: [PATCH 692/749] <= --- 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 e669e1368..2b1846850 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1634,7 +1634,7 @@ void komodo_args(char *argv0) MAX_MONEY += (MAX_MONEY * ASSETCHAINS_COMMISSION) / SATOSHIDEN; if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; - if ( MAX_MONEY < 0 || MAX_MONEY > 1000000000LL*SATOSHIDEN ) + if ( MAX_MONEY <= 0 || MAX_MONEY > 1000000000LL*SATOSHIDEN ) MAX_MONEY = 1000000000LL*SATOSHIDEN; fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); From d19cb2c8a74a512e1713010c6ef3c1cb361b3f12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 04:54:17 -1100 Subject: [PATCH 693/749] Fix founders reward --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae16d513c..67b583f96 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1114,7 +1114,7 @@ uint64_t komodo_commission(const CBlock *pblock) { n = pblock->vtx[0].vout.size(); for (j=0; jvtx[i].vout[j].nValue; + total += pblock->vtx[0].vout[j].nValue; } else { From f69b32b9645ae7abb034b39081d45b0a1d8237a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 05:09:29 -1100 Subject: [PATCH 694/749] Test --- src/cc/dice.cpp | 25 ++++++++++++++++++------- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9f5d83979..e165127df 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -528,11 +528,13 @@ CPubKey DiceFundingPk(CScript scriptPubKey) return(pk); } -uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout) +uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout,int32_t usevout) { int32_t i; uint8_t _entropy[32],_hentropy[32]; bits256 tmp256,txidpub,txidpriv,mypriv,mypub,ssecret,ssecret2; uint256 hentropy; memset(&hentropy,0,32); endiancpy(txidpriv.bytes,(uint8_t *)&_txidpriv,32); + if ( usevout != 0 ) + txidpriv.ints[1] = vout; txidpriv.bytes[0] &= 0xf8, txidpriv.bytes[31] &= 0x7f, txidpriv.bytes[31] |= 0x40; txidpub = curve25519(txidpriv,curve25519_basepoint9()); @@ -765,9 +767,14 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac { if ( ((funcid= DecodeDiceOpRet(txid,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,hentropy,vinproof)) == 'E' || funcid == 'W' || funcid == 'L') && sbits == vinsbits && fundingtxid == vinfundingtxid ) { - hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n); + hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n,0); entropyvout = vinTx.vin[0].prevout.n; - fprintf(stderr,"%d mem.%d bettxid %s -> vin0 %s/v%d -> %s\n",KOMODO_CONNECTING & ((1<<30) - 1),(KOMODO_CONNECTING & (1<<30)) != 0,txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + fprintf(stderr,"bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + if ( hentropy != hentropy2 ) + { + hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n,1); + fprintf(stderr,"alt bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + } if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); @@ -783,7 +790,11 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac // queue 'W' winning tx return(1); } - } else fprintf(stderr,"hentropy != hentropy2\n"); + } + else + { + fprintf(stderr,"both hentropy != hentropy2\n"); + } } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); } //else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); @@ -1356,7 +1367,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 { if ( AddNormalinputs(mtx,mypk,amount+2*txfee,1) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1); mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('E',sbits,fundingtxid,hentropy,zeroid))); @@ -1415,7 +1426,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); if ( AddNormalinputs(mtx,mypk,bet+2*txfee+odds,60) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1); mtx.vout.push_back(MakeCC1vout(cp->evalcode,entropyval,dicepk)); mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -1577,7 +1588,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv } //fprintf(stderr,"make tx.%c\n",funcid); if ( funcid == 'L' || funcid == 'W' ) // dealernode only - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1); *resultp = 1; //char str[65],str2[65]; //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 67b583f96..eb5d02e76 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1476,9 +1476,9 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock); - if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) + /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) return(-1); - else if ( checktoshis != 0 ) + else*/ if ( checktoshis != 0 ) { script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index 3b245b286..71a22b7d8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -749,7 +749,7 @@ void static BitcoinMiner() unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); - uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; + uint8_t *script; uint64_t total; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) { sleep(1); From 02a1c3a7dd3aefa8e43b25be07428ebed6097fd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 05:10:46 -1100 Subject: [PATCH 695/749] Fix --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e165127df..491c37118 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -533,8 +533,8 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout,int32_t int32_t i; uint8_t _entropy[32],_hentropy[32]; bits256 tmp256,txidpub,txidpriv,mypriv,mypub,ssecret,ssecret2; uint256 hentropy; memset(&hentropy,0,32); endiancpy(txidpriv.bytes,(uint8_t *)&_txidpriv,32); - if ( usevout != 0 ) - txidpriv.ints[1] = vout; + //if ( usevout != 0 ) + // txidpriv.ints[1] = vout; txidpriv.bytes[0] &= 0xf8, txidpriv.bytes[31] &= 0x7f, txidpriv.bytes[31] |= 0x40; txidpub = curve25519(txidpriv,curve25519_basepoint9()); From bd19a3867b58b65caf3078dcc7378d104722c8cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 05:14:50 -1100 Subject: [PATCH 696/749] Usevout --- src/cc/CCinclude.h | 2 +- src/cc/channels.cpp | 6 +++--- src/cc/dice.cpp | 4 ++-- src/cc/lotto.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 41f5ccacd..83642f020 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -125,7 +125,7 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); // CCutils CPubKey buf2pk(uint8_t *buf33); void endiancpy(uint8_t *dest,uint8_t *src,int32_t len); -uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t entropyvout); +uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t entropyvout,int32_t usevout); CTxOut MakeCC1vout(uint8_t evalcode,CAmount nValue,CPubKey pk); CTxOut MakeCC1of2vout(uint8_t evalcode,CAmount nValue,CPubKey pk,CPubKey pk2); CC *MakeCCcond1(uint8_t evalcode,CPubKey pk); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index e5b77feb2..a03a602d5 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -446,7 +446,7 @@ std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64 funds = numpayments * payment; if ( AddNormalinputs(mtx,mypk,funds+3*txfee,64) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1); endiancpy(hash,(uint8_t *)&hentropy,32); for (i=0; i 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) { - hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash, channelOpenTx.vin[0].prevout.n); + hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash, channelOpenTx.vin[0].prevout.n,1); endiancpy(hash, (uint8_t * ) & hentropy, 32); for (i = 0; i < param1; i++) { diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 491c37118..017353dcf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -533,8 +533,8 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout,int32_t int32_t i; uint8_t _entropy[32],_hentropy[32]; bits256 tmp256,txidpub,txidpriv,mypriv,mypub,ssecret,ssecret2; uint256 hentropy; memset(&hentropy,0,32); endiancpy(txidpriv.bytes,(uint8_t *)&_txidpriv,32); - //if ( usevout != 0 ) - // txidpriv.ints[1] = vout; + if ( usevout != 0 ) + txidpriv.uints[1] ^= vout; txidpriv.bytes[0] &= 0xf8, txidpriv.bytes[31] &= 0x7f, txidpriv.bytes[31] |= 0x40; txidpub = curve25519(txidpriv,curve25519_basepoint9()); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 6361b9291..652ea9d0d 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -292,7 +292,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic sbits = stringbits(planstr); if ( AddNormalinputs(mtx,mypk,funding+txfee,60) > 0 ) { - hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n); + hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash,mtx.vin[0].prevout.n,1); mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,funding,lottopk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_LOTTO << (uint8_t)'F' << sbits << ticketsize << odds << firstheight << period << hentropy))); } From df5b020b34b392c49a5589ffd8b71091875d2983 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 05:28:52 -1100 Subject: [PATCH 697/749] Endian fix --- src/cc/dice.cpp | 5 ++++- src/komodo_utils.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 017353dcf..604433e0b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -534,7 +534,10 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout,int32_t memset(&hentropy,0,32); endiancpy(txidpriv.bytes,(uint8_t *)&_txidpriv,32); if ( usevout != 0 ) - txidpriv.uints[1] ^= vout; + { + txidpriv.bytes[1] ^= (vout & 0xff); + txidpriv.bytes[2] ^= ((vout>>8) & 0xff); + } txidpriv.bytes[0] &= 0xf8, txidpriv.bytes[31] &= 0x7f, txidpriv.bytes[31] |= 0x40; txidpub = curve25519(txidpriv,curve25519_basepoint9()); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2b1846850..09c5622af 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1636,7 +1636,7 @@ void komodo_args(char *argv0) MAX_MONEY = 1000000LL*SATOSHIDEN; if ( MAX_MONEY <= 0 || MAX_MONEY > 1000000000LL*SATOSHIDEN ) MAX_MONEY = 1000000000LL*SATOSHIDEN; - fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); + //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_P2PPORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From b045472360d66cde0d44aa83f873b6c78fa36ced Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 05:38:52 -1100 Subject: [PATCH 698/749] +print --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 604433e0b..5eb3605ae 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -391,7 +391,7 @@ void *dicefinish(void *_ptr) utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { - //fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); + fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -406,7 +406,7 @@ void *dicefinish(void *_ptr) if ( ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); - //fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); + fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); if ( numblocks > 0 ) continue; } @@ -441,7 +441,7 @@ void *dicefinish(void *_ptr) } else { - //fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); + fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); } } } @@ -772,7 +772,7 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac { hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n,0); entropyvout = vinTx.vin[0].prevout.n; - fprintf(stderr,"bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + //fprintf(stderr,"bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); if ( hentropy != hentropy2 ) { hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n,1); From e75be5869492b8b350e02d0ef5fe4414eefd2bb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 05:43:38 -1100 Subject: [PATCH 699/749] -print --- 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 5eb3605ae..1f9070d9f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -391,7 +391,7 @@ void *dicefinish(void *_ptr) utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { - fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); + //fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -406,7 +406,7 @@ void *dicefinish(void *_ptr) if ( ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); - fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); + //fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); if ( numblocks > 0 ) continue; } @@ -441,7 +441,7 @@ void *dicefinish(void *_ptr) } else { - fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); + //fprintf(stderr,"error ready.%d dicefinish %d of %d process %s %s using need %.8f finish.%s size.%d betspent.%d\n",ptr->bettxid_ready,m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),(double)(iter<0 ? 0 : ptr->winamount)/COIN,ptr->txid.GetHex().c_str(),(int32_t)ptr->rawtx.size(),dice_betspent((char *)"dicefinish",ptr->bettxid)); } } } From 6e555c9c158dbf09de9456c5681e1c0ae433a89d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 06:02:05 -1100 Subject: [PATCH 700/749] +print --- src/cc/dice.cpp | 2 +- src/komodo_bitcoind.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1f9070d9f..038fb55bf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -375,7 +375,7 @@ void *dicefinish(void *_ptr) if ( newblock != 0 && ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); - fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); + //fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); if ( numblocks == 0 ) mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); else continue; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eb5d02e76..4c633ede4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1476,6 +1476,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock); + fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) return(-1); else*/ if ( checktoshis != 0 ) From fcdfc0ea32366c8ccad3d025da50ce177c8dfd03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 06:13:50 -1100 Subject: [PATCH 701/749] Skip commission bout --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4c633ede4..e4678f90e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1114,7 +1114,8 @@ uint64_t komodo_commission(const CBlock *pblock) { n = pblock->vtx[0].vout.size(); for (j=0; jvtx[0].vout[j].nValue; + if ( j != 1 ) + total += pblock->vtx[0].vout[j].nValue; } else { From 17d91e14f1324edbd2385cfb02bd14c42a981ddf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 06:28:15 -1100 Subject: [PATCH 702/749] -print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e4678f90e..f1ea95d7c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1477,8 +1477,8 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock); - fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); - /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) + //fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); + /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here return(-1); else*/ if ( checktoshis != 0 ) { From 2d853d1959c3d745c12c435ac994f774ae520f29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 07:10:22 -1100 Subject: [PATCH 703/749] Change orphan handling --- src/cc/dice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 038fb55bf..0a7d9eb02 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -363,11 +363,11 @@ void *dicefinish(void *_ptr) if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); - //dicefinish_delete(ptr); - //continue; - if ( ptr->rawtx.empty() == 0 ) - ptr->rawtx.clear(); - ptr->txid = zeroid; + dicefinish_delete(ptr); + continue; + //if ( ptr->rawtx.empty() == 0 ) + // ptr->rawtx.clear(); + //ptr->txid = zeroid; } } if ( ptr->bettxid_ready != 0 ) From e17d90abfc5da8da099478da3d2fc29f7eece54e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 07:30:59 -1100 Subject: [PATCH 704/749] Founders reward just on block subsidy --- src/cc/dice.cpp | 4 ++-- src/komodo_bitcoind.h | 5 +++-- src/main.cpp | 2 +- src/miner.cpp | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0a7d9eb02..479229b4f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -776,7 +776,7 @@ int32_t DiceIsWinner(uint256 &entropy,int32_t &entropyvout,uint256 txid,CTransac if ( hentropy != hentropy2 ) { hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash,vinTx.vin[0].prevout.n,1); - fprintf(stderr,"alt bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); + //fprintf(stderr,"alt bettxid %s -> vin0 %s/v%d -> %s\n",txid.GetHex().c_str(),vinTx.vin[0].prevout.hash.GetHex().c_str(),entropyvout,entropy.GetHex().c_str()); } if ( hentropy == hentropy2 ) { @@ -1156,7 +1156,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); + //fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f1ea95d7c..c2f6ef933 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1106,12 +1106,13 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ PoS stake must be without txfee and in the last tx in the block at vout[0] */ -uint64_t komodo_commission(const CBlock *pblock) +uint64_t komodo_commission(const CBlock *pblock,int32_t height) { int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; txn_count = pblock->vtx.size(); if ( ASSETCHAINS_FOUNDERS != 0 ) { + return(GetBlockSubsidy(height,chainparams.GetConsensus())); n = pblock->vtx[0].vout.size(); for (j=0; j 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here return(-1); diff --git a/src/main.cpp b/src/main.cpp index 115920264..aa055068a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3129,7 +3129,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) { uint64_t checktoshis; - if ( (checktoshis= komodo_commission((CBlock *)&block)) != 0 ) + 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 ) blockReward += checktoshis; diff --git a/src/miner.cpp b/src/miner.cpp index 71a22b7d8..65a00861b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -119,7 +119,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33, int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize); int32_t komodo_baseid(char *origbase); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); -uint64_t komodo_commission(const CBlock *block); +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); @@ -438,7 +438,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; - if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); From e196f1aa9c45b2fe7d3a9b4de24a791dd3b30939 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 07:32:31 -1100 Subject: [PATCH 705/749] Params --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c2f6ef933..7abaa298e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1112,7 +1112,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) txn_count = pblock->vtx.size(); if ( ASSETCHAINS_FOUNDERS != 0 ) { - return(GetBlockSubsidy(height,chainparams.GetConsensus())); + return(GetBlockSubsidy(height,Params.GetConsensus())); n = pblock->vtx[0].vout.size(); for (j=0; j Date: Sat, 10 Nov 2018 07:33:19 -1100 Subject: [PATCH 706/749] () --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7abaa298e..2c885b546 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1112,7 +1112,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) txn_count = pblock->vtx.size(); if ( ASSETCHAINS_FOUNDERS != 0 ) { - return(GetBlockSubsidy(height,Params.GetConsensus())); + return(GetBlockSubsidy(height,Params().GetConsensus())); n = pblock->vtx[0].vout.size(); for (j=0; j Date: Sat, 10 Nov 2018 07:34:43 -1100 Subject: [PATCH 707/749] Apply percentage --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2c885b546..0dec50eb6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1112,7 +1112,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) txn_count = pblock->vtx.size(); if ( ASSETCHAINS_FOUNDERS != 0 ) { - return(GetBlockSubsidy(height,Params().GetConsensus())); + return((GetBlockSubsidy(height,Params().GetConsensus()) * ASSETCHAINS_COMMISSION) / COIN); n = pblock->vtx[0].vout.size(); for (j=0; j Date: Sat, 10 Nov 2018 08:28:27 -1100 Subject: [PATCH 708/749] +print --- src/komodo_bitcoind.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0dec50eb6..414959455 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1108,11 +1108,13 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint64_t komodo_commission(const CBlock *pblock,int32_t height) { - int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; + int32_t i,j,n=0,txn_count; int64_t nSubsidy; uint64_t commission,total = 0; txn_count = pblock->vtx.size(); if ( ASSETCHAINS_FOUNDERS != 0 ) { - return((GetBlockSubsidy(height,Params().GetConsensus()) * ASSETCHAINS_COMMISSION) / COIN); + nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); + fprintf(stderr,"nSubsidy %.8f prod %llu\n",(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); + return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); n = pblock->vtx[0].vout.size(); for (j=0; j 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here return(-1); else*/ if ( checktoshis != 0 ) From 1c31ecbaa84bd6ca147cd9950f7e28047fb0785e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:29:04 -1100 Subject: [PATCH 709/749] -print --- src/rpccrosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 2059ab452..02ab34c0d 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -51,7 +51,7 @@ UniValue assetchainproof(const UniValue& params, bool fHelp) UniValue crosschainproof(const UniValue& params, bool fHelp) { UniValue ret(UniValue::VOBJ); - fprintf(stderr,"crosschainproof needs to be implemented\n"); + //fprintf(stderr,"crosschainproof needs to be implemented\n"); return(ret); } From 7b6f5044deb78b2c6a5b0679ef8d20d5ffd81105 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:31:25 -1100 Subject: [PATCH 710/749] +print --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 414959455..966dcd6a2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1106,6 +1106,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ PoS stake must be without txfee and in the last tx in the block at vout[0] */ +CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); + uint64_t komodo_commission(const CBlock *pblock,int32_t height) { int32_t i,j,n=0,txn_count; int64_t nSubsidy; uint64_t commission,total = 0; @@ -1113,7 +1115,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) if ( ASSETCHAINS_FOUNDERS != 0 ) { nSubsidy = GetBlockSubsidy(height,Params().GetConsensus()); - fprintf(stderr,"nSubsidy %.8f prod %llu\n",(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); + fprintf(stderr,"ht.%d nSubsidy %.8f prod %llu\n",height,(double)nSubsidy/COIN,(long long)(nSubsidy * ASSETCHAINS_COMMISSION)); return((nSubsidy * ASSETCHAINS_COMMISSION) / COIN); n = pblock->vtx[0].vout.size(); for (j=0; j Date: Sat, 10 Nov 2018 08:38:24 -1100 Subject: [PATCH 711/749] Fix p2pkh check --- src/komodo_bitcoind.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 966dcd6a2..11c9cf7b9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1478,7 +1478,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { - int64_t checktoshis=0; uint8_t *script; + int64_t checktoshis=0; uint8_t *script; int32_t scriptlen,matched = 0; if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock,height); @@ -1488,10 +1488,16 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) else*/ if ( checktoshis != 0 ) { script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); + if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) == 0 ) + matched = 1; + else if ( scriptlen == 25 && script[0] == OP_DUP && script[1] == OP_HASH160 && script[23] == OP_EQUALVERIFY && script[24] == OP_CHECKSIG && memcmp(script+2,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) == 0 ) + matched = 2; + if ( matched == 0 ) { - if ( script[0] != 25 || script[0] != OP_DUP || script[1] != OP_HASH160 || script[23] != OP_EQUALVERIFY || script[24] != OP_CHECKSIG || memcmp(script+2,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) != 0 ) + fprintf(stderr,"payment to wrong pubkey\n"); return(-1); + } if ( pblock->vtx[0].vout[1].nValue != checktoshis ) { From 0df9cddf668f519e2aa0a8049bc863033c7882d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:40:10 -1100 Subject: [PATCH 712/749] Fix --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 11c9cf7b9..c2892865c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1491,7 +1491,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) == 0 ) matched = 1; - else if ( scriptlen == 25 && script[0] == OP_DUP && script[1] == OP_HASH160 && script[23] == OP_EQUALVERIFY && script[24] == OP_CHECKSIG && memcmp(script+2,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) == 0 ) + else if ( scriptlen == 25 && script[0] == OP_DUP && script[1] == OP_HASH160 && script[2] == 20 && script[23] == OP_EQUALVERIFY && script[24] == OP_CHECKSIG && memcmp(script+3,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) == 0 ) matched = 2; if ( matched == 0 ) { From 9328dae04f654bec3d8d828bdb1ae6b5a9281171 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:51:13 -1100 Subject: [PATCH 713/749] Refund orphans --- src/cc/dice.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 479229b4f..f1914dc53 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -363,11 +363,29 @@ void *dicefinish(void *_ptr) if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); - dicefinish_delete(ptr); + if ( ptr->rawtx.empty() == 0 ) + ptr->rawtx.clear(); + ptr->txid = zeroid; + unstringbits(name,ptr->sbits); + result = 0; + res = DiceBetFinish(ptr->funcid,entropyused,entropyvout,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,zeroid,-2); + if ( ptr->entropyused == zeroid ) + { + ptr->entropyused = entropyused; + ptr->entropyvout = entropyvout; + } + if ( entropyused != ptr->entropyused || entropyvout != ptr->entropyvout ) + { + fprintf(stderr,"WARNING entropy %s != %s || %d != %d\n",entropyused.GetHex().c_str(),ptr->entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); + } + if ( result > 0 ) + { + ptr->rawtx = res; + fprintf(stderr,"send refund!\n"); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + } + //dicefinish_delete(ptr); continue; - //if ( ptr->rawtx.empty() == 0 ) - // ptr->rawtx.clear(); - //ptr->txid = zeroid; } } if ( ptr->bettxid_ready != 0 ) @@ -1495,12 +1513,14 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; + if ( vin0vout == -2 ) + retval = -1; /*if ( iswin == 0 ) { retval = -1; fprintf(stderr,"invalid dicebet %s\n",bettxid.GetHex().c_str()); } else retval = 0;*/ - if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,oldentropyvout,entropyused,bettxid,betTx,entropyvout)) != 0 ) + if ( retval < 0 || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,oldentropyvout,entropyused,bettxid,betTx,entropyvout)) != 0 ) { if ( retval < 0 ) { From 4ee48bc646fbb15bdf909453cfa58de36e83aa4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:56:32 -1100 Subject: [PATCH 714/749] Print script --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c2892865c..43f8230b7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1495,7 +1495,9 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 2; if ( matched == 0 ) { - fprintf(stderr,"payment to wrong pubkey\n"); + for (i=0; i<25; i++) + fprintf(stderr,"%02x",script[i]); + fprintf(stderr," payment to wrong pubkey scriptlen.%d\n",scriptlen); return(-1); } From a5191f399b84f1e4981d81698933a60c61b992f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:58:35 -1100 Subject: [PATCH 715/749] Fix --- 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 f1914dc53..f27dbcb0e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1463,7 +1463,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyvout,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t oldentropyvout,retval=0,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; From e1e4bc52772c2061cc9c6d8c8501bb8a85ab6460 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 08:59:27 -1100 Subject: [PATCH 716/749] Fix --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 43f8230b7..ddaea9460 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1495,6 +1495,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 2; 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\n",scriptlen); From 78ba3255a7de866322b4175d4fbe14e97cf11bf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:09:55 -1100 Subject: [PATCH 717/749] newblock != 0 --- src/cc/dice.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f27dbcb0e..a6e8e6146 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -352,13 +352,13 @@ void *dicefinish(void *_ptr) else if ( mytxid_inmempool(ptr->bettxid) != 0 ) ptr->bettxid_ready = (uint32_t)time(NULL); } - else if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) + else if ( newblock != 0 && myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); dicefinish_delete(ptr); continue; } - else if ( ptr->txid != zeroid ) + else if ( newblock != 0 && ptr->txid != zeroid ) { if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { @@ -384,7 +384,6 @@ void *dicefinish(void *_ptr) fprintf(stderr,"send refund!\n"); mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } - //dicefinish_delete(ptr); continue; } } From 27c8492618a6920c3da4f036bf95bbd1464af38e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:25:26 -1100 Subject: [PATCH 718/749] Orphaned count --- 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 a6e8e6146..4da8e2d7b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -113,12 +113,12 @@ struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; + CTransaction betTx; uint256 fundingtxid,bettxid,entropyused,txid; uint64_t sbits; int64_t winamount; - int32_t iswin,entropyvout; + int32_t iswin,entropyvout,orphaned; uint32_t bettxid_ready,revealed; - CTransaction betTx; std::string rawtx; uint8_t funcid; } *DICEFINISH_LIST; @@ -362,7 +362,10 @@ void *dicefinish(void *_ptr) { if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { - fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); + ptr->orphaned++; + fprintf(stderr,"ORPHANED.%d finish txid.%s\n",ptr->orphaned,ptr->txid.GetHex().c_str()); + if ( ptr->orphaned < 10 ) + continue; if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; From e2445cb37b765717c1e44ec1df40a88367cb6535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:49:18 -1100 Subject: [PATCH 719/749] -ac_script --- src/komodo_globals.h | 4 ++-- src/komodo_utils.h | 14 ++++++++++---- src/miner.cpp | 19 ++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 78f1e1cac..e2cbedd33 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -47,8 +47,8 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; +std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS,ASSETCHAINS_SCRIPTPUBKEY[256]; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 09c5622af..8a4fff6dd 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1563,6 +1563,7 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = GetArg("-ac_decay",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); + ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 ) @@ -1585,13 +1586,18 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = 0; printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); } - if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || (ASSETCHAINS_SCRIPTPUB.size() > 16 && ASSETCHAINS_SCRIPTPUB.size() < 256*2) ) { - decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); - calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33); + if ( ASSETCHAINS_OVERRIDE_PUBKEY.c_str() == 66 ) + { + decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); + calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33); + } + if ( ASSETCHAINS_SCRIPTPUB.size() > 0 ) + decode_hex(ASSETCHAINS_SCRIPTPUBKEY,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 ) { - ASSETCHAINS_COMMISSION = 35000000; + ASSETCHAINS_COMMISSION = 53846154; // maps to 35% printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); } } diff --git a/src/miner.cpp b/src/miner.cpp index 65a00861b..c604c59e2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -438,17 +438,22 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; - if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUBKEY[0] != 0) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); txNew.vout[1].nValue = commission; - txNew.vout[1].scriptPubKey.resize(35); - ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); - ptr[0] = 33; - for (i=0; i<33; i++) - ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; - ptr[34] = OP_CHECKSIG; + if ( ASSETCHAINS_SCRIPTPUBKEY[0] != 0 ) + txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB); + else + { + txNew.vout[1].scriptPubKey.resize(35); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + ptr[0] = 33; + for (i=0; i<33; i++) + ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; + ptr[34] = OP_CHECKSIG; + } //printf("autocreate commision vout\n"); pblock->vtx[0] = txNew; } From 1d0ca47a217dbca60624114d75d3f3661eaca387 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:51:24 -1100 Subject: [PATCH 720/749] Fix --- 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 8a4fff6dd..77bcecd84 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1588,7 +1588,7 @@ void komodo_args(char *argv0) } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || (ASSETCHAINS_SCRIPTPUB.size() > 16 && ASSETCHAINS_SCRIPTPUB.size() < 256*2) ) { - if ( ASSETCHAINS_OVERRIDE_PUBKEY.c_str() == 66 ) + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) { decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33); From d71ca09221c2dde851f1c07936c53f850f8e9557 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:53:26 -1100 Subject: [PATCH 721/749] Fix --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c604c59e2..45b7da2e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -109,7 +109,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, 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; +extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; @@ -438,12 +438,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; - if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUBKEY[0] != 0) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() != 0) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); txNew.vout[1].nValue = commission; - if ( ASSETCHAINS_SCRIPTPUBKEY[0] != 0 ) + if ( ASSETCHAINS_SCRIPTPUB.size() != 0 ) txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB); else { From bba4bf660773f8d3b776f102d2ddb4db7e4a4798 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:55:10 -1100 Subject: [PATCH 722/749] Fix --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index e2cbedd33..453576b8b 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS,ASSETCHAINS_SCRIPTPUBKEY[256]; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_FOUNDERS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 77bcecd84..f817d0cdd 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1586,15 +1586,13 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = 0; printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); } - if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || (ASSETCHAINS_SCRIPTPUB.size() > 16 && ASSETCHAINS_SCRIPTPUB.size() < 256*2) ) + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) { decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33); } - if ( ASSETCHAINS_SCRIPTPUB.size() > 0 ) - decode_hex(ASSETCHAINS_SCRIPTPUBKEY,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 ) { ASSETCHAINS_COMMISSION = 53846154; // maps to 35% From 1d8477869540354f54acabc3b8db9a91c30b479e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 09:58:57 -1100 Subject: [PATCH 723/749] Set ac hash --- src/komodo_utils.h | 6 ++++-- src/miner.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f817d0cdd..838461ee2 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1503,7 +1503,7 @@ void komodo_args(char *argv0) { extern int64_t MAX_MONEY; 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; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],*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); @@ -1612,7 +1612,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - 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 ) + 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]); extraptr = extrabuf; @@ -1625,6 +1625,8 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_FOUNDERS),(void *)&ASSETCHAINS_FOUNDERS); + if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) + extralen += iguana_rwnum(1,&extraptr[extralen],(int32_t)ASSETCHAINS_SCRIPTPUB.size(),(void *)ASSETCHAINS_SCRIPTPUB.c_str()); } addn = GetArg("-seednode",""); if ( strlen(addn.c_str()) > 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index 45b7da2e1..a8c6e087c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -438,12 +438,12 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; - if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() != 0) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) + if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); txNew.vout[1].nValue = commission; - if ( ASSETCHAINS_SCRIPTPUB.size() != 0 ) + if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB); else { From 84efe780fe0575ab950e40f7fe3c48a86e3da343 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 10:05:24 -1100 Subject: [PATCH 724/749] Check ASSETCHAINS_SCRIPTPUB --- src/komodo_bitcoind.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ddaea9460..25aa09eea 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1478,7 +1478,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { - int64_t checktoshis=0; uint8_t *script; int32_t scriptlen,matched = 0; + int64_t checktoshis=0; uint8_t *script,scripthex[8192]; int32_t scriptlen,matched = 0; if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock,height); @@ -1489,16 +1489,25 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); - if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) == 0 ) - matched = 1; + if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) + { + if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) + { + decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + if ( memcmp(scripthex,script,scriptlen) == 0 ) + matched = scriptlen; + } + } + else if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) == 0 ) + matched = 35; else if ( scriptlen == 25 && script[0] == OP_DUP && script[1] == OP_HASH160 && script[2] == 20 && script[23] == OP_EQUALVERIFY && script[24] == OP_CHECKSIG && memcmp(script+3,ASSETCHAINS_OVERRIDE_PUBKEYHASH,20) == 0 ) - matched = 2; + 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\n",scriptlen); + fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); return(-1); } From 064a97f021c3c3b142e7634d9eddfd18601085cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 10:25:34 -1100 Subject: [PATCH 725/749] MofN -> Heir --- src/Makefile.am | 2 +- src/cc/CC made easy | 2 +- src/cc/CCMofN.h | 10 ++--- src/cc/CCcustom.cpp | 30 ++++++------- src/cc/eval.h | 2 +- src/cc/{MofN.cpp => heir.cpp} | 81 ++++++++++++++--------------------- src/rpcserver.cpp | 4 +- src/rpcserver.h | 2 +- src/wallet/rpcwallet.cpp | 8 ++-- 9 files changed, 63 insertions(+), 78 deletions(-) rename src/cc/{MofN.cpp => heir.cpp} (72%) diff --git a/src/Makefile.am b/src/Makefile.am index 5252b1fa0..694d67278 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -267,7 +267,7 @@ libbitcoin_server_a_SOURCES = \ cc/dice.cpp \ cc/lotto.cpp \ cc/fsm.cpp \ - cc/MofN.cpp \ + cc/heir.cpp \ cc/oracles.cpp \ cc/prices.cpp \ cc/pegs.cpp \ diff --git a/src/cc/CC made easy b/src/cc/CC made easy index 158c2907a..3f15a6b6b 100644 --- a/src/cc/CC made easy +++ b/src/cc/CC made easy @@ -95,7 +95,7 @@ EVAL(EVAL_DICE, 0xe6) \ EVAL(EVAL_FSM, 0xe7) \ EVAL(EVAL_AUCTION, 0xe8) \ EVAL(EVAL_LOTTO, 0xe9) \ -EVAL(EVAL_MOFN, 0xea) \ +EVAL(EVAL_HEIR, 0xea) \ EVAL(EVAL_CHANNELS, 0xeb) \ EVAL(EVAL_ORACLES, 0xec) \ EVAL(EVAL_PRICES, 0xed) \ diff --git a/src/cc/CCMofN.h b/src/cc/CCMofN.h index 170200d77..c86bf3b6b 100644 --- a/src/cc/CCMofN.h +++ b/src/cc/CCMofN.h @@ -14,16 +14,16 @@ ******************************************************************************/ -#ifndef CC_MOFN_H -#define CC_MOFN_H +#ifndef CC_HEIR_H +#define CC_HEIR_H #include "CCinclude.h" -#define EVAL_MOFN 0xea +#define EVAL_HEIR 0xea -bool MofNValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); +bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); // CCcustom -UniValue MofNInfo(); +UniValue HeirInfo(); #endif diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 71644686b..3cd3625e7 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -21,7 +21,7 @@ #include "CCauction.h" #include "CClotto.h" #include "CCfsm.h" -#include "CCMofN.h" +#include "CCHeir.h" #include "CCchannels.h" #include "CCOracles.h" #include "CCPrices.h" @@ -133,13 +133,13 @@ uint8_t AuctionCCpriv[32] = { 0x8c, 0x1b, 0xb7, 0x8c, 0x02, 0xa3, 0x9d, 0x21, 0x #undef FUNCNAME #undef EVALCODE -// MofN -#define FUNCNAME IsMofNInput -#define EVALCODE EVAL_MOFN -const char *MofNCCaddr = "RDVHcSekmXgeYBqRupNTmqo3Rn8QRXNduy"; -const char *MofNNormaladdr = "RTPwUjKYECcGn6Y4KYChLhgaht1RSU4jwf"; -char MofNCChexstr[67] = { "03c91bef3d7cc59c3a89286833a3446b29e52a5e773f738a1ad2b09785e5f4179e" }; -uint8_t MofNCCpriv[32] = { 0x9d, 0xa1, 0xf8, 0xf7, 0xba, 0x0a, 0x91, 0x36, 0x89, 0x9a, 0x86, 0x30, 0x63, 0x20, 0xd7, 0xdf, 0xaa, 0x35, 0xe3, 0x99, 0x32, 0x2b, 0x63, 0xc0, 0x66, 0x9c, 0x93, 0xc4, 0x5e, 0x9d, 0xb9, 0xce }; +// Heir +#define FUNCNAME IsHeirInput +#define EVALCODE EVAL_HEIR +const char *HeirCCaddr = "RDVHcSekmXgeYBqRupNTmqo3Rn8QRXNduy"; +const char *HeirNormaladdr = "RTPwUjKYECcGn6Y4KYChLhgaht1RSU4jwf"; +char HeirCChexstr[67] = { "03c91bef3d7cc59c3a89286833a3446b29e52a5e773f738a1ad2b09785e5f4179e" }; +uint8_t HeirCCpriv[32] = { 0x9d, 0xa1, 0xf8, 0xf7, 0xba, 0x0a, 0x91, 0x36, 0x89, 0x9a, 0x86, 0x30, 0x63, 0x20, 0xd7, 0xdf, 0xaa, 0x35, 0xe3, 0x99, 0x32, 0x2b, 0x63, 0xc0, 0x66, 0x9c, 0x93, 0xc4, 0x5e, 0x9d, 0xb9, 0xce }; #include "CCcustom.inc" #undef FUNCNAME #undef EVALCODE @@ -282,13 +282,13 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp,uint8_t evalcode) cp->validate = AuctionValidate; cp->ismyvin = IsAuctionInput; break; - case EVAL_MOFN: - strcpy(cp->unspendableCCaddr,MofNCCaddr); - strcpy(cp->normaladdr,MofNNormaladdr); - strcpy(cp->CChexstr,MofNCChexstr); - memcpy(cp->CCpriv,MofNCCpriv,32); - cp->validate = MofNValidate; - cp->ismyvin = IsMofNInput; + case EVAL_HEIR: + strcpy(cp->unspendableCCaddr,HeirCCaddr); + strcpy(cp->normaladdr,HeirNormaladdr); + strcpy(cp->CChexstr,HeirCChexstr); + memcpy(cp->CCpriv,HeirCCpriv,32); + cp->validate = HeirValidate; + cp->ismyvin = IsHeirInput; break; case EVAL_CHANNELS: strcpy(cp->unspendableCCaddr,ChannelsCCaddr); diff --git a/src/cc/eval.h b/src/cc/eval.h index 9ff0ca623..9c788422e 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -47,7 +47,7 @@ EVAL(EVAL_FSM, 0xe7) \ EVAL(EVAL_AUCTION, 0xe8) \ EVAL(EVAL_LOTTO, 0xe9) \ - EVAL(EVAL_MOFN, 0xea) \ + EVAL(EVAL_HEIR, 0xea) \ EVAL(EVAL_CHANNELS, 0xeb) \ EVAL(EVAL_ORACLES, 0xec) \ EVAL(EVAL_PRICES, 0xed) \ diff --git a/src/cc/MofN.cpp b/src/cc/heir.cpp similarity index 72% rename from src/cc/MofN.cpp rename to src/cc/heir.cpp index c22c48263..d4aab932a 100644 --- a/src/cc/MofN.cpp +++ b/src/cc/heir.cpp @@ -13,30 +13,15 @@ * * ******************************************************************************/ -#include "CCMofN.h" +#include "CCHeir.h" /* - The idea of MofN CC is to allow non-interactive multisig, preferably in a cross chain compatible way, ie. for actual bitcoin multisig. - - full redeemscript in an initial tx with opreturn - ability to post partial signatures and construct a full transaction from M such partial signatures - a new transaction would refer to the initialtx and other partial would refer to both - - There is no need for a CC contract to use it for normal multisig as normal multisig transactions are already supported. - - In order to take advantage of CC powers, we can create a more powerful multisig using shamir's secret MofN (up to 255) algo to allow spends. Using the same non-interactive partial signing is possible. also, in addition to spending, data payload can have additional data that is also revealed when the funds are spent. - - rpc calls needed: - 1) create msig address (normal or shamir) - 2) post payment with partial sig - 3) add partial sig to 2) - 4) combine and submit M partial sigs - + The idea of Heir CC is to allow crypto inheritance */ // start of consensus code -int64_t IsMofNvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsHeirvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -47,7 +32,7 @@ int64_t IsMofNvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) return(0); } -bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool HeirExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -65,8 +50,8 @@ bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & { //fprintf(stderr,"vini.%d check hash and vout\n",i); if ( hashBlock == zerohash ) - return eval->Invalid("cant MofN from mempool"); - if ( (assetoshis= IsMofNvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + return eval->Invalid("cant Heir from mempool"); + if ( (assetoshis= IsHeirvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) inputs += assetoshis; } } @@ -74,7 +59,7 @@ bool MofNExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & for (i=0; i origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -140,7 +125,7 @@ int64_t AddMofNInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsMofNvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= IsHeirvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -155,27 +140,27 @@ int64_t AddMofNInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKe return(totalinputs); } -std::string MofNGet(uint64_t txfee,int64_t nValue) +std::string HeirGet(uint64_t txfee,int64_t nValue) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,mofnpk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_MOFN); + CMutableTransaction mtx,tmpmtx; CPubKey mypk,Heirpk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + cp = CCinit(&C,EVAL_HEIR); if ( txfee == 0 ) txfee = 10000; - mofnpk = GetUnspendable(cp,0); + Heirpk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddMofNInputs(cp,mtx,mofnpk,nValue+txfee,60)) > 0 ) + if ( (inputs= AddHeirInputs(cp,mtx,Heirpk,nValue+txfee,60)) > 0 ) { if ( inputs > nValue ) CCchange = (inputs - nValue - txfee); if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_MOFN,CCchange,mofnpk)); + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,CCchange,Heirpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); j = rand() & 0xfffffff; for (i=0; i<1000000; i++,j++) { tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MOFN << (uint8_t)'G' << j)); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_HEIR << (uint8_t)'G' << j)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; @@ -191,35 +176,35 @@ std::string MofNGet(uint64_t txfee,int64_t nValue) } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); - } else fprintf(stderr,"cant find mofn inputs\n"); + } else fprintf(stderr,"cant find Heir inputs\n"); return(""); } -std::string MofNFund(uint64_t txfee,int64_t funds) +std::string HeirFund(uint64_t txfee,int64_t funds) { - CMutableTransaction mtx; CPubKey mypk,mofnpk; CScript opret; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_MOFN); + CMutableTransaction mtx; CPubKey mypk,Heirpk; CScript opret; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_HEIR); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - mofnpk = GetUnspendable(cp,0); + Heirpk = GetUnspendable(cp,0); if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_MOFN,funds,mofnpk)); + mtx.vout.push_back(MakeCC1vout(EVAL_HEIR,funds,Heirpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } return(""); } -UniValue MofNInfo() +UniValue HeirInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx; CPubKey mofnpk; struct CCcontract_info *cp,C; int64_t funding; + CMutableTransaction mtx; CPubKey Heirpk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); - result.push_back(Pair("name","MofN")); - cp = CCinit(&C,EVAL_MOFN); - mofnpk = GetUnspendable(cp,0); - funding = AddMofNInputs(cp,mtx,mofnpk,0,0); + result.push_back(Pair("name","Heir")); + cp = CCinit(&C,EVAL_HEIR); + Heirpk = GetUnspendable(cp,0); + funding = AddHeirInputs(cp,mtx,Heirpk,0,0); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); return(result); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 393545a63..5a59543c5 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -375,8 +375,8 @@ static const CRPCCommand vRPCCommands[] = { "faucet", "faucetget", &faucetget, true }, { "faucet", "faucetaddress", &faucetaddress, true }, - /* MofN */ - { "MofN", "mofnaddress", &mofnaddress, true }, + /* Heir */ + { "heir", "heiraddress", &heiraddress, true }, /* Channels */ { "channels", "channelsaddress", &channelsaddress, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 4778ae36b..8157260aa 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -222,7 +222,7 @@ extern UniValue tokenask(const UniValue& params, bool fHelp); extern UniValue tokencancelask(const UniValue& params, bool fHelp); extern UniValue tokenfillask(const UniValue& params, bool fHelp); extern UniValue tokenconvert(const UniValue& params, bool fHelp); -extern UniValue mofnaddress(const UniValue& params, bool fHelp); +extern UniValue heiraddress(const UniValue& params, bool fHelp); extern UniValue channelsaddress(const UniValue& params, bool fHelp); extern UniValue oraclesaddress(const UniValue& params, bool fHelp); extern UniValue oracleslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 394ff4a35..1d3ff6a1e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5095,17 +5095,17 @@ UniValue gatewaysaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Gateways",pubkey)); } -UniValue mofnaddress(const UniValue& params, bool fHelp) +UniValue heiraddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; - cp = CCinit(&C,EVAL_MOFN); + cp = CCinit(&C,EVAL_HEIR); if ( fHelp || params.size() > 1 ) - throw runtime_error("mofnaddress [pubkey]\n"); + throw runtime_error("heiraddress [pubkey]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); - return(CCaddress(cp,(char *)"MofN",pubkey)); + return(CCaddress(cp,(char *)"Heir",pubkey)); } UniValue lottoaddress(const UniValue& params, bool fHelp) From feed1b566bed5b66f893786f5b567f02dead3d84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 10:28:11 -1100 Subject: [PATCH 726/749] CCHeir.h --- src/cc/{CCMofN.h => CCHeir.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/cc/{CCMofN.h => CCHeir.h} (100%) diff --git a/src/cc/CCMofN.h b/src/cc/CCHeir.h similarity index 100% rename from src/cc/CCMofN.h rename to src/cc/CCHeir.h From 880fda004f9487b7ca227f54d2f733f3139d935e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Nov 2018 11:00:23 -1100 Subject: [PATCH 727/749] Orphan at 3 --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4da8e2d7b..235ad6569 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -364,13 +364,14 @@ void *dicefinish(void *_ptr) { ptr->orphaned++; fprintf(stderr,"ORPHANED.%d finish txid.%s\n",ptr->orphaned,ptr->txid.GetHex().c_str()); - if ( ptr->orphaned < 10 ) + if ( ptr->orphaned < 3 ) continue; if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; unstringbits(name,ptr->sbits); result = 0; + ptr->orphaned = 0; res = DiceBetFinish(ptr->funcid,entropyused,entropyvout,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,zeroid,-2); if ( ptr->entropyused == zeroid ) { From 30a8281f2f39aad686270f1c77f7f9a1dc335fbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 00:43:45 -1100 Subject: [PATCH 728/749] -print --- src/cc/CCutils.cpp | 2 +- src/cc/dice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 889b6fdd4..cbd4fba7a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -386,7 +386,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) numblocks = 0; if ( myGetTransaction(txid,tx,hashBlock) == 0 ) { - fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid)); + //fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid)); return(0); } else if ( hashBlock == zeroid ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0a6995db1..b36482e3e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -364,7 +364,7 @@ void *dicefinish(void *_ptr) { ptr->orphaned++; fprintf(stderr,"ORPHANED.%d finish txid.%s\n",ptr->orphaned,ptr->txid.GetHex().c_str()); - if ( ptr->orphaned < 3 ) + if ( ptr->orphaned < 4 ) continue; if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); From 83040356f58745e685cf38a4d867cf52611c3264 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 00:51:34 -1100 Subject: [PATCH 729/749] Allow 1:1 betting --- 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 b36482e3e..9460bcdc3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -526,7 +526,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); ptr->entropyvout = entropyvout; DL_APPEND(DICEFINISH_LIST,ptr); - fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); + fprintf(stderr,"queued %dx iswin.%d %.8f -> %.8f %s\n",(int32_t)(betTx.vout[2].nValue - txfee),iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); } else { @@ -1332,7 +1332,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 2 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) + if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1416,7 +1416,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet CCerror = "bet must be positive"; return(""); } - if ( odds < 2 || odds > 9999 ) + if ( odds < 1 || odds > 9999 ) { CCerror = "odds must be between 2 and 9999"; return(""); From 955d299551c8fbf8dc1e45cbe586815684564d16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 01:15:34 -1100 Subject: [PATCH 730/749] HASH_TABLE for betted --- src/cc/dice.cpp | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9460bcdc3..4109cedc3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -102,14 +102,13 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; -static uint256 bettxids[MAX_ENTROPYUSED],Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable +//static uint256 bettxids[MAX_ENTROPYUSED]; +static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; -struct dicefinish_utxo { uint256 txid; int32_t vout; }; - struct dicefinish_info { struct dicefinish_info *prev,*next; @@ -123,37 +122,61 @@ struct dicefinish_info uint8_t funcid; } *DICEFINISH_LIST; +struct dicehash_entry +{ + UT_hash_handle hh; + uint256 bettxid; +} *DICEHASH_TABLE; + int32_t _dicehash_find(uint256 bettxid) { - int32_t i; + struct dicehash_entry *ptr; + HASH_FIND(hh,DICEHASH_TABLE,&bettxid,sizeof(bettxid),ptr); + if ( ptr != 0 ) + { + fprintf(stderr,"hash_find %s got %s\n",bettxid.GetHex().c_str(),ptr->bettxid.GetHex().c_str()); + return(1); + } + return(0); + /*int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:16:52 -1100 Subject: [PATCH 731/749] struct dicefinish_utxo { uint256 txid; int32_t vout; }; --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4109cedc3..13d9156d3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -109,6 +109,8 @@ static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; +struct dicefinish_utxo { uint256 txid; int32_t vout; }; + struct dicefinish_info { struct dicefinish_info *prev,*next; From 5240f2793f91d518ebedca268277806767da076c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 01:19:32 -1100 Subject: [PATCH 732/749] struct dicehash_entry * --- src/cc/dice.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 13d9156d3..fa229bd48 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -168,8 +168,9 @@ int32_t _dicehash_clear(uint256 bettxid) return(0);*/ } -void _dicehash_add(uint256 bettxid) +struct dicehash_entry *_dicehash_add(uint256 bettxid) { + struct dicehash_entry *ptr; /*int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:23:27 -1100 Subject: [PATCH 733/749] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fa229bd48..a02d3e5b8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -171,6 +171,8 @@ int32_t _dicehash_clear(uint256 bettxid) struct dicehash_entry *_dicehash_add(uint256 bettxid) { struct dicehash_entry *ptr; + ptr = (struct dicehash_entry *)calloc(1,sizeof(*ptr)); + ptr->bettxid = bettxid; /*int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:40:21 -1100 Subject: [PATCH 734/749] Entropy hash table --- src/cc/dice.cpp | 84 ++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a02d3e5b8..748811a04 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -102,10 +102,9 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; -//static uint256 bettxids[MAX_ENTROPYUSED]; -static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable -static CTransaction betTxs[MAX_ENTROPYUSED]; -static int32_t entropyvouts[MAX_ENTROPYUSED]; +//static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable +//static CTransaction betTxs[MAX_ENTROPYUSED]; +//static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -130,21 +129,19 @@ struct dicehash_entry uint256 bettxid; } *DICEHASH_TABLE; -int32_t _dicehash_find(uint256 bettxid) +struct dice_entropy +{ + UT_hash_handle hh; + uint256 entropyused,bettxid; + CTransaction betTx; + int32_t entropyvout; +} *DICE_ENTROPY; + +struct dicehash_entry *_dicehash_find(uint256 bettxid) { struct dicehash_entry *ptr; HASH_FIND(hh,DICEHASH_TABLE,&bettxid,sizeof(bettxid),ptr); - if ( ptr != 0 ) - { - fprintf(stderr,"hash_find %s got %s\n",bettxid.GetHex().c_str(),ptr->bettxid.GetHex().c_str()); - return(1); - } - return(0); - /*int32_t i; - for (i=0; ibettxid = bettxid; - /*int32_t i; - for (i=0; ientropyvout ) + { + if ( bettxid == ptr->bettxid ) + { + fprintf(stderr,"identical %s E.%s v.%d\n",bettxid.GetHex().c_str(),entropyused.GetHex().c_str(),entropyvout); + return(entropyvout+1); + } + else + { + fprintf(stderr,"found identical entropy used.%s %s vs %s v.%d vs %d\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),ptr->bettxid.GetHex().c_str(),entropyvout,ptr->entropyvout); + oldbettxid = ptr->bettxid; + oldbetTx = ptr->betTx; + oldentropyvout = ptr->entropyvout; + return(-1); + } + } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,entropyvouts[i]); + } + return(0); + /*int32_t i; for (i=0; ientropyused = entropyused; + ptr->bettxid = bettxid; + ptr->betTx = betTx; + ptr->entropyvout = entropyvout; + HASH_ADD(hh,DICE_ENTROPY,entropyused,sizeof(entropyused),ptr); + return(ptr); +/* int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:41:18 -1100 Subject: [PATCH 735/749] Fix --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 748811a04..fe42620c9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -168,7 +168,7 @@ struct dicehash_entry *_dicehash_add(uint256 bettxid) int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &oldentropyvout,uint256 entropyused,uint256 bettxid,int32_t entropyvout) { - struct dicehash_entry *ptr; + struct dice_entropy *ptr; HASH_FIND(hh,DICE_ENTROPY,&entropyused,sizeof(entropyused),ptr); if ( ptr != 0 ) { @@ -187,7 +187,7 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o oldentropyvout = ptr->entropyvout; return(-1); } - } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,entropyvouts[i]); + } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); } return(0); /*int32_t i; From 31bcb93378767902f2adc65096ba2ed94e430298 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 01:47:51 -1100 Subject: [PATCH 736/749] Entropy hash table --- src/cc/dice.cpp | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fe42620c9..e925ba3dd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -101,11 +101,6 @@ What is needed is for the dealer node to track the entropy tx that was already b #define DICE_MINUTXOS 7777 extern int32_t KOMODO_INSYNC; - -//static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable -//static CTransaction betTxs[MAX_ENTROPYUSED]; -//static int32_t entropyvouts[MAX_ENTROPYUSED]; - pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; struct dicefinish_utxo { uint256 txid; int32_t vout; }; @@ -176,7 +171,7 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o { if ( bettxid == ptr->bettxid ) { - fprintf(stderr,"identical %s E.%s v.%d\n",bettxid.GetHex().c_str(),entropyused.GetHex().c_str(),entropyvout); + //fprintf(stderr,"identical %s E.%s v.%d\n",bettxid.GetHex().c_str(),entropyused.GetHex().c_str(),entropyvout); return(entropyvout+1); } else @@ -190,24 +185,6 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); } return(0); - /*int32_t i; - for (i=0; ientropyvout = entropyvout; HASH_ADD(hh,DICE_ENTROPY,entropyused,sizeof(entropyused),ptr); return(ptr); -/* - int32_t i; - for (i=0; i Date: Sun, 11 Nov 2018 02:44:10 -1100 Subject: [PATCH 737/749] Tweak orphan handling --- src/cc/dice.cpp | 2 +- src/cc/heir.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e925ba3dd..c97d7111b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -357,7 +357,7 @@ void *dicefinish(void *_ptr) else if ( mytxid_inmempool(ptr->bettxid) != 0 ) ptr->bettxid_ready = (uint32_t)time(NULL); } - else if ( newblock != 0 && myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) + else if ( newblock != 0 && (myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 || now > ptr->bettxid_ready+600) ) { fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); dicefinish_delete(ptr); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index d4aab932a..c3e7d03e1 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -16,7 +16,8 @@ #include "CCHeir.h" /* - The idea of Heir CC is to allow crypto inheritance + The idea of Heir CC is to allow crypto inheritance. + A special 1of2 CC address is created that is freely spendable by the creator. The heir is only allowed to spend after the specified amount of idle blocks. The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. The design requires the heir to spend all the funds at once */ // start of consensus code From 84fff7e0972995b5f56792dbf521bef21ef77b28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 03:47:06 -1100 Subject: [PATCH 738/749] Disable odds 1 as it is broken --- 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 c97d7111b..ced82a4eb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1421,7 +1421,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet CCerror = "bet must be positive"; return(""); } - if ( odds < 1 || odds > 9999 ) + if ( odds < 2 || odds > 9999 ) { CCerror = "odds must be between 2 and 9999"; return(""); From 34b1a40307c0202ac0ac4c41f8a4b91ebbb57405 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 04:38:29 -1100 Subject: [PATCH 739/749] Remove longest chain mutex --- src/rpcnet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 97bf5001d..cf76ac9d3 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -171,7 +171,7 @@ int32_t komodo_longestchain() int32_t ht,n=0,num=0,maxheight=0,height = 0; vector vstats; { - LOCK(cs_main); + //LOCK(cs_main); CopyNodeStats(vstats); } BOOST_FOREACH(const CNodeStats& stats, vstats) From 58b0fc23ace899f702bf5e9bcabf81ca186d0c66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 05:06:36 -1100 Subject: [PATCH 740/749] Guard longest chain and GetNodeStateStats --- src/main.cpp | 33 ++++++++++++++-------- src/rpcnet.cpp | 76 ++++++++++++++++++++++++++++---------------------- 2 files changed, 64 insertions(+), 45 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 64d48d7ae..bc371e4eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -532,17 +532,28 @@ namespace { } // anon namespace -bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { - LOCK(cs_main); - CNodeState *state = State(nodeid); - if (state == NULL) - return false; - stats.nMisbehavior = state->nMisbehavior; - stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1; - stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1; - BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) { - if (queue.pindex) - stats.vHeightInFlight.push_back(queue.pindex->nHeight); +bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) +{ + static int32_t depth; + if ( depth < 0 ) + depth = 0; + if ( depth == 0 ) + { + LOCK(cs_main); + CNodeState *state = State(nodeid); + if (state == NULL) + { + depth--; + return false; + } + stats.nMisbehavior = state->nMisbehavior; + stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1; + stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1; + BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) { + if (queue.pindex) + stats.vHeightInFlight.push_back(queue.pindex->nHeight); + } + depth--; } return true; } diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index cf76ac9d3..3dcf52b59 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -168,43 +168,51 @@ UniValue getpeerinfo(const UniValue& params, bool fHelp) int32_t KOMODO_LONGESTCHAIN; int32_t komodo_longestchain() { + static int32_t depth; int32_t ht,n=0,num=0,maxheight=0,height = 0; - vector vstats; + if ( depth < 0 ) + depth = 0; + if ( depth == 0 ) { - //LOCK(cs_main); - CopyNodeStats(vstats); + depth++; + vector vstats; + { + //LOCK(cs_main); + CopyNodeStats(vstats); + } + BOOST_FOREACH(const CNodeStats& stats, vstats) + { + //fprintf(stderr,"komodo_longestchain iter.%d\n",n); + CNodeStateStats statestats; + bool fStateStats = GetNodeStateStats(stats.nodeid,statestats); + if ( statestats.nSyncHeight < 0 ) + continue; + ht = 0; + if ( stats.nStartingHeight > ht ) + ht = stats.nStartingHeight; + if ( statestats.nSyncHeight > ht ) + ht = statestats.nSyncHeight; + if ( statestats.nCommonHeight > ht ) + ht = statestats.nCommonHeight; + if ( maxheight == 0 || ht > maxheight*1.01 ) + maxheight = ht, num = 1; + else if ( ht > maxheight*0.99 ) + num++; + if ( ht > height ) + height = ht; + } + depth--; + if ( num > (n >> 1) ) + { + extern char ASSETCHAINS_SYMBOL[]; + if ( 0 && height != KOMODO_LONGESTCHAIN ) + fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height); + KOMODO_LONGESTCHAIN = height; + return(height); + } + KOMODO_LONGESTCHAIN = 0; } - BOOST_FOREACH(const CNodeStats& stats, vstats) - { - //fprintf(stderr,"komodo_longestchain iter.%d\n",n); - CNodeStateStats statestats; - bool fStateStats = GetNodeStateStats(stats.nodeid,statestats); - if ( statestats.nSyncHeight < 0 ) - continue; - ht = 0; - if ( stats.nStartingHeight > ht ) - ht = stats.nStartingHeight; - if ( statestats.nSyncHeight > ht ) - ht = statestats.nSyncHeight; - if ( statestats.nCommonHeight > ht ) - ht = statestats.nCommonHeight; - if ( maxheight == 0 || ht > maxheight*1.01 ) - maxheight = ht, num = 1; - else if ( ht > maxheight*0.99 ) - num++; - if ( ht > height ) - height = ht; - } - if ( num > (n >> 1) ) - { - extern char ASSETCHAINS_SYMBOL[]; - if ( 0 && height != KOMODO_LONGESTCHAIN ) - fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height); - KOMODO_LONGESTCHAIN = height; - return(height); - } - KOMODO_LONGESTCHAIN = 0; - return(0); + return(KOMODO_LONGESTCHAIN); } UniValue addnode(const UniValue& params, bool fHelp) From f7dc8fe3e7b27ed8606ea19a6439dfbc0b373318 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 05:15:27 -1100 Subject: [PATCH 741/749] Skip longest chain call, since it is in connect tip --- src/komodo_gateway.h | 2 +- src/rpcblockchain.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 400ded593..96d4ea121 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1382,7 +1382,7 @@ void komodo_passport_iteration() { if ( ASSETCHAINS_SYMBOL[0] == 0 ) komodo_interestsum(); - komodo_longestchain(); + //komodo_longestchain(); lastinterest = komodo_chainactive_timestamp(); } refsp = komodo_stateptr(symbol,dest); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 868431f6f..91cd82303 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -33,6 +33,7 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); int32_t komodo_longestchain(); int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); +extern int32_t KOMODO_LONGESTCHAIN; double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty) { @@ -1327,7 +1328,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) if ( ASSETCHAINS_SYMBOL[0] == 0 ) { progress = Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()); } else { - int32_t longestchain = komodo_longestchain(); + int32_t longestchain = KOMODO_LONGESTCHAIN;//komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } UniValue obj(UniValue::VOBJ); From 47538c0995747c5a03f5484205b68d48df31982b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 05:27:38 -1100 Subject: [PATCH 742/749] Revert depth guard --- src/main.cpp | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bc371e4eb..64d48d7ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -532,28 +532,17 @@ namespace { } // anon namespace -bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) -{ - static int32_t depth; - if ( depth < 0 ) - depth = 0; - if ( depth == 0 ) - { - LOCK(cs_main); - CNodeState *state = State(nodeid); - if (state == NULL) - { - depth--; - return false; - } - stats.nMisbehavior = state->nMisbehavior; - stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1; - stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1; - BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) { - if (queue.pindex) - stats.vHeightInFlight.push_back(queue.pindex->nHeight); - } - depth--; +bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { + LOCK(cs_main); + CNodeState *state = State(nodeid); + if (state == NULL) + return false; + stats.nMisbehavior = state->nMisbehavior; + stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1; + stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1; + BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) { + if (queue.pindex) + stats.vHeightInFlight.push_back(queue.pindex->nHeight); } return true; } From f1c84619bfb283290df891662951bd2425f120a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 05:35:42 -1100 Subject: [PATCH 743/749] increase number of 0.0002 utxos --- src/cc/dice.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ced82a4eb..4ad9146b5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -319,7 +319,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CTransaction betTx,finishTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CTransaction betTx,finishTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -478,9 +478,13 @@ void *dicefinish(void *_ptr) { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - fprintf(stderr,"num normal 0.0002 utxos.%d < %d\n",num,DICE_MINUTXOS); - if ( system(cmd) != 0 ) - fprintf(stderr,"system error issuing.(%s)\n",cmd); + n = sqrt((DICE_MINUTXOS - num) / 100) + 1; + fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS); + for (i=0; i Date: Sun, 11 Nov 2018 05:36:32 -1100 Subject: [PATCH 744/749] N --- 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 4ad9146b5..8aee316f8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -479,7 +479,7 @@ void *dicefinish(void *_ptr) char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); n = sqrt((DICE_MINUTXOS - num) / 100) + 1; - fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS); + fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n); for (i=0; i Date: Sun, 11 Nov 2018 06:04:19 -1100 Subject: [PATCH 745/749] Sqrt limit for entropy --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8aee316f8..62dffb7f7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1708,7 +1708,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -1718,7 +1719,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx //LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { - fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,DICE_MINUTXOS - entropytxs); + fprintf(stderr,"ENTROPY %s: %d of %d, %d\n",tx.GetHash().GetHex().c_str(),i,n,DICE_MINUTXOS - entropytxs); RelayTransaction(tx); } else break; } else break; From ff905c4fa719cca5642a4cf4d7769c23c1d29d33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 06:32:39 -1100 Subject: [PATCH 746/749] Double vins --- 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 62dffb7f7..5234dd162 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -478,7 +478,7 @@ void *dicefinish(void *_ptr) { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - n = sqrt((DICE_MINUTXOS - num) / 100) + 1; + n = sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n); for (i=0; i Date: Sun, 11 Nov 2018 06:53:30 -1100 Subject: [PATCH 747/749] Dont call longest chain in background loop --- src/bitcoind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index f05b522fa..80fef2c0f 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -63,7 +63,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) else { //komodo_interestsum(); - komodo_longestchain(); + //komodo_longestchain(); MilliSleep(20000); } fShutdown = ShutdownRequested(); From 818165d7a3ccba7ab8741e6ea5e2f52bd5d2c670 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 07:09:17 -1100 Subject: [PATCH 748/749] Test --- 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 5234dd162..0602c78d4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -478,7 +478,7 @@ void *dicefinish(void *_ptr) { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - n = sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; + n = 1;//sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n); for (i=0; i Date: Sun, 11 Nov 2018 07:13:41 -1100 Subject: [PATCH 749/749] Test --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0602c78d4..0f96228e2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -478,7 +478,7 @@ void *dicefinish(void *_ptr) { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - n = 1;//sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; + n = sqrt((DICE_MINUTXOS - num) / 100)*2 + 1; fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n); for (i=0; i