From 26bb3613751c3d55d4fd3276d03fbaae2bec14c3 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 25 Aug 2018 02:59:44 +0300 Subject: [PATCH 01/29] CCL chain, one shot --- src/assetchains.json | 10 ++++++++++ src/assetchains.old | 1 + src/dpowassets | 1 + 3 files changed, 12 insertions(+) diff --git a/src/assetchains.json b/src/assetchains.json index 5f0d3464f..b74d953a0 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -132,5 +132,15 @@ "ac_name": "SEC", "ac_supply": "1000000000", "ac_cc": "333" + }, + { + "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" } ] diff --git a/src/assetchains.old b/src/assetchains.old index cbf976dd9..a25b6f898 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -38,3 +38,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & ~/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 -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 & diff --git a/src/dpowassets b/src/dpowassets index 6506c54d0..88e6f72b8 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -39,3 +39,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\":\"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 4d61e5cd995b2c592ae51936fe0e5979ab2a4e6f Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 25 Aug 2018 04:15:55 +0300 Subject: [PATCH 02/29] CCL --- src/ac/ccl | 2 ++ src/fiat/ccl | 2 ++ 2 files changed, 4 insertions(+) create mode 100755 src/ac/ccl create mode 100755 src/fiat/ccl diff --git a/src/ac/ccl b/src/ac/ccl new file mode 100755 index 000000000..c3d03a0a4 --- /dev/null +++ b/src/ac/ccl @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=CCL $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/ccl b/src/fiat/ccl new file mode 100755 index 000000000..c3d03a0a4 --- /dev/null +++ b/src/fiat/ccl @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=CCL $1 $2 $3 $4 $5 $6 From 5016068231e99d1c0e982bb966e0d28206b7de64 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 25 Aug 2018 04:17:37 +0300 Subject: [PATCH 03/29] CCL --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index a25b6f898..d7a18811d 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -38,4 +38,4 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & ~/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 -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=CCL -ac_supply=200000000 -ac_end=1 -ac_cc=2 -addressindex=1 -spentindex=1 -addnode=142.93.136.89 -addnode=195.201.22.89 & From f4e9f4670cff7583db002983a301337c85bf4fee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:50:29 -1100 Subject: [PATCH 04/29] -print --- src/komodo.h | 2 +- src/komodo_kv.h | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index dff8b5ab6..28d3a1b9f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -600,7 +600,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { if ( scriptbuf[len] == 'K' ) { - fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); + //fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0); return(-1); } diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 2f4eadea4..c533b4976 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -151,7 +151,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { - fprintf(stderr,"(%s) already there\n",(char *)key); + //fprintf(stderr,"(%s) already there\n",(char *)key); //if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 ) { tstr = (char *)"transfer:"; diff --git a/src/main.cpp b/src/main.cpp index aa6bece16..a96b83f03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1306,7 +1306,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa string reason; if (Params().RequireStandard() && !IsStandardTx(tx, reason, nextBlockHeight)) { - fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\n",reason.c_str()); + //fprintf(stderr,"AcceptToMemoryPool reject nonstandard transaction: %s\n",reason.c_str()); return state.DoS(0,error("AcceptToMemoryPool: nonstandard transaction: %s", reason),REJECT_NONSTANDARD, reason); } // Only accept nLockTime-using transactions that can be mined in the next From 282473f1fc81a2000e3e8d9e1d3370707a8368a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:51:19 -1100 Subject: [PATCH 05/29] -print --- src/script/standard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/standard.cpp b/src/script/standard.cpp index b86dfef15..58d2bc701 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -167,7 +167,7 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector nMaxDatacarrierBytes) { - fprintf(stderr,"size.%d > nMaxDatacarrier.%d\n",(int32_t)vch1.size(),(int32_t)nMaxDatacarrierBytes); + //fprintf(stderr,"size.%d > nMaxDatacarrier.%d\n",(int32_t)vch1.size(),(int32_t)nMaxDatacarrierBytes); break; } } From 62d82abc4c431b9d4f95ee1218c682f9b910389d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:54:33 -1100 Subject: [PATCH 06/29] -print --- src/komodo_kv.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index c533b4976..1b1d92014 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -64,7 +64,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( ptr != 0 ) { duration = komodo_kvduration(ptr->flags); - fprintf(stderr,"duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + //fprintf(stderr,"duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); @@ -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]); + //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]); if ( value >= fee ) { coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); diff --git a/src/main.cpp b/src/main.cpp index a96b83f03..73cafdc1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -736,7 +736,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) if (!::IsStandard(txout.scriptPubKey, whichType)) { reason = "scriptpubkey"; - fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut); + //fprintf(stderr,">>>>>>>>>>>>>>> vout.%d nDataout.%d\n",v,nDataOut); return false; } From 19107e362e040c06626d89de2e4f9a2aca254f79 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 05:56:54 -1100 Subject: [PATCH 07/29] -print --- src/komodo_kv.h | 2 +- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 1b1d92014..4cf482116 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -142,7 +142,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) { - fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13); + //fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13); return; } } diff --git a/src/main.cpp b/src/main.cpp index 73cafdc1c..85de0effa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4187,11 +4187,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C } if ( rejects == 0 || rejects == lastrejects ) { - if ( lastrejects != 0 ) + if ( 0 && lastrejects != 0 ) fprintf(stderr,"lastrejects.%d -> all tx in mempool\n",lastrejects); break; } - fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); + //fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); lastrejects = rejects; rejects = 0; } From 7f21f769858a2db9c339387d0cd79025d0454817 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 07:29:08 -1100 Subject: [PATCH 08/29] -print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 28d3a1b9f..4b61cafa0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -311,7 +311,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long { if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) errs++; - if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) { int32_t i; for (i=0; i Date: Sat, 25 Aug 2018 09:01:05 -1100 Subject: [PATCH 09/29] Prevent unlocking fundingtxid --- src/cc/rewards.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d3d374613..33c5f01d4 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -244,7 +244,9 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t //vout.0: funding CC change or recover normal payout //vout.1: normal output to unlock address //vout.n-1: opreturn 'U' sbits fundingtxid - if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) + if ( fundingtxid == txid ) + return eval->Invalid("cant unlock fundingtxid"); + else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); for (i=0; i Date: Sat, 25 Aug 2018 09:20:57 -1100 Subject: [PATCH 10/29] +print --- src/cc/rewards.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 33c5f01d4..d50b9ffb3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -244,6 +244,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t //vout.0: funding CC change or recover normal payout //vout.1: normal output to unlock address //vout.n-1: opreturn 'U' sbits fundingtxid + char str[65],str2[65]; + fprintf(stderr,"funding.%s vs %s\n",uint256_str(str,fundingtxid),uint256_str(str2,txid)); if ( fundingtxid == txid ) return eval->Invalid("cant unlock fundingtxid"); else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) From 8254d65aa1616f7a08028de6abdfd13cc60c94ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 09:36:07 -1100 Subject: [PATCH 11/29] Prevent unlocking the fundingtxid --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d50b9ffb3..0f002ecf1 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -245,8 +245,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t //vout.1: normal output to unlock address //vout.n-1: opreturn 'U' sbits fundingtxid char str[65],str2[65]; - fprintf(stderr,"funding.%s vs %s\n",uint256_str(str,fundingtxid),uint256_str(str2,txid)); - if ( fundingtxid == txid ) + fprintf(stderr,"funding.%s vs %s\n",uint256_str(str,fundingtxid),uint256_str(str2,tx.vin[0].prevout.hash)); + if ( fundingtxid == tx.vin[0].prevout.hash ) return eval->Invalid("cant unlock fundingtxid"); else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); From 717ede079e4c14cdf159a080abfa3e5692678396 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Aug 2018 09:43:48 -1100 Subject: [PATCH 12/29] Required locked tx --- src/cc/rewards.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 0f002ecf1..8d9a9fa78 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -196,7 +196,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - uint256 txid,fundingtxid,hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; + uint256 txid,fundingtxid,hashBlock,vinfundingtxid; uint64_t vinsbits,sbits,APR,minseconds,maxseconds,mindeposit,amount,reward,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; uint8_t funcid; CScript scriptPubKey; CTransaction fundingTx,vinTx; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -244,12 +244,16 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t //vout.0: funding CC change or recover normal payout //vout.1: normal output to unlock address //vout.n-1: opreturn 'U' sbits fundingtxid - char str[65],str2[65]; - fprintf(stderr,"funding.%s vs %s\n",uint256_str(str,fundingtxid),uint256_str(str2,tx.vin[0].prevout.hash)); + //char str[65],str2[65]; + //fprintf(stderr,"funding.%s vs %s\n",uint256_str(str,fundingtxid),uint256_str(str2,tx.vin[0].prevout.hash)); if ( fundingtxid == tx.vin[0].prevout.hash ) return eval->Invalid("cant unlock fundingtxid"); else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); + else if ( DecodeRewardsOpRet(tx.vin[0].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid) != 'L' ) + return eval->Invalid("can only unlock locktxid"); + else if ( fundingtxid != vinfundingtxid ) + return eval->Invalid("mismatched vinfundingtxid"); for (i=0; iismyvin)(tx.vin[i].scriptSig) == 0 ) From 292a9a717b4753b7ffaf1d070f34cfecc6e1311d Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sat, 25 Aug 2018 22:45:23 -0300 Subject: [PATCH 13/29] RPC methods to scan notarisations DB --- src/notarisationdb.cpp | 27 +++++++++++++++++++++ src/notarisationdb.h | 1 + src/rpccrosschain.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++ src/rpcserver.cpp | 2 ++ src/rpcserver.h | 2 ++ 5 files changed, 85 insertions(+) diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 6210d88dd..cdfbb82c1 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -2,6 +2,7 @@ #include "notarisationdb.h" #include "uint256.h" #include "cc/eval.h" +#include "main.h" #include @@ -82,3 +83,29 @@ void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBa batch.Erase(n.second.txHash); } } + +/* + * Scan notarisationsdb backwards for blocks containing a notarisation + * for given symbol. Return height of matched notarisation or 0. + */ +int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out) +{ + if (height < 0 || height > chainActive.Height()) + return false; + + for (int i=0; i height) break; + NotarisationsInBlock notarisations; + uint256 blockHash = *chainActive[height-i]->phashBlock; + if (!GetBlockNotarisations(blockHash, notarisations)) + continue; + + BOOST_FOREACH(Notarisation& nota, notarisations) { + if (strcmp(nota.second.symbol, symbol.data()) == 0) { + out = nota; + return height-i; + } + } + } + return 0; +} diff --git a/src/notarisationdb.h b/src/notarisationdb.h index ce5360e7d..b8cd93691 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -23,5 +23,6 @@ bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs); bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch); void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch); +int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out); #endif /* NOTARISATIONDB_H */ diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index ea8e13aee..09f1b21d1 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -3,6 +3,7 @@ #include "chainparams.h" #include "checkpoints.h" #include "crosschain.h" +#include "notarisationdb.h" #include "importcoin.h" #include "base58.h" #include "consensus/validation.h" @@ -251,3 +252,55 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) return HexStr(E_MARSHAL(ss << importTx)); } + + +UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error("getNotarisationsForBlock blockHash\n\n" + "Takes a block hash and returns notarisation transactions " + "within the block"); + + uint256 blockHash = uint256S(params[0].get_str()); + + NotarisationsInBlock nibs; + GetBlockNotarisations(blockHash, nibs); + UniValue out(UniValue::VARR); + BOOST_FOREACH(const Notarisation& n, nibs) + { + UniValue item(UniValue::VARR); + item.push_back(n.first.GetHex()); + item.push_back(HexStr(E_MARSHAL(ss << n.second))); + out.push_back(item); + } + return out; +} + + +UniValue scanNotarisationsDB(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() < 2 || params.size() > 3) + throw runtime_error("scanNotarisationsDB blockHeight symbol [blocksLimit=1440]\n\n" + "Scans notarisationsdb backwards from height for a notarisation" + " of given symbol"); + int height = atoi(params[0].get_str().c_str()); + std::string symbol = params[1].get_str().c_str(); + + int limit = 1440; + if (params.size() > 2) { + limit = atoi(params[2].get_str().c_str()); + } + + if (height == 0) { + height = chainActive.Height(); + } + + Notarisation nota; + int matchedHeight = ScanNotarisationsDB(height, symbol, limit, nota); + if (!matchedHeight) return NullUniValue; + UniValue out(UniValue::VOBJ); + out.pushKV("height", matchedHeight); + out.pushKV("hash", nota.first.GetHex()); + out.pushKV("opreturn", HexStr(E_MARSHAL(ss << nota.second))); + return out; +} diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 41228e71a..c24525bdc 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -313,6 +313,8 @@ static const CRPCCommand vRPCCommands[] = { "crosschain", "height_MoM", &height_MoM, true }, { "crosschain", "assetchainproof", &assetchainproof, true }, { "crosschain", "crosschainproof", &crosschainproof, true }, + { "crosschain", "getNotarisationsForBlock", &getNotarisationsForBlock, true }, + { "crosschain", "scanNotarisationsDB", &scanNotarisationsDB, true }, { "crosschain", "migrate_converttoexport", &migrate_converttoexport, true }, { "crosschain", "migrate_createimporttransaction", &migrate_createimporttransaction, true }, { "crosschain", "migrate_completeimporttransaction", &migrate_completeimporttransaction, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index f88f1e571..336595156 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -361,6 +361,8 @@ extern UniValue calc_MoM(const UniValue& params, bool fHelp); extern UniValue height_MoM(const UniValue& params, bool fHelp); extern UniValue assetchainproof(const UniValue& params, bool fHelp); extern UniValue crosschainproof(const UniValue& params, bool fHelp); +extern UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp); +extern UniValue scanNotarisationsDB(const UniValue& params, bool fHelp); extern UniValue migrate_converttoexport(const UniValue& params, bool fHelp); extern UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp); extern UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp); From 124819cef50c517547aa02ee0abde1397d840d51 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 27 Aug 2018 00:48:20 +0200 Subject: [PATCH 14/29] Lots of error checking improvements and more passing tests --- qa/rpc-tests/cryptoconditions.py | 53 +++++++++++++++++++--------- src/wallet/rpcwallet.cpp | 59 +++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 24 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index f133ae28a..dd6adba76 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -78,6 +78,12 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + result = rpc.faucetaddress(self.pubkey) + assert_success(result) + # test that additional CCaddress key is returned + for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + # no funds in the faucet yet result = rpc.faucetget() assert_error(result) @@ -134,12 +140,20 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: assert_equal(dice[x][0], 'R') + dice = rpc.diceaddress(self.pubkey) + assert_equal(dice['result'], 'success') + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress', 'CCaddress']: + assert_equal(dice[x][0], 'R') + # no dice created yet result = rpc.dicelist() assert_equal(result, []) - #result = rpc.dicefund("LUCKY",10000,1,10000,10,5) - #assert_equal(result, []) + result = rpc.diceinfo("invalid") + assert_error(result) + + result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5") + assert_error(result) def run_token_tests(self): rpc = self.nodes[0] @@ -156,8 +170,15 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenlist() assert_equal(result, []) - result = rpc.tokencreate("DUKE", "1987.420", "duke") + result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply") + assert_error(result) + + result = rpc.tokencreate("NUKE123456789012345678901234567890", "1987420", "name too long") + assert_error(result) + + result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token") assert_success(result) + tokenid = self.send_and_mine(result['hex']) result = rpc.tokenlist() @@ -197,7 +218,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['owner'], self.pubkey) assert_equal(result['name'], "DUKE") assert_equal(result['supply'], 198742000000) - assert_equal(result['description'], "duke") + assert_equal(result['description'], "Duke's custom token") # invalid numtokens ask result = rpc.tokenask("-1", tokenid, "1") @@ -253,25 +274,25 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenorders() assert_equal(result, []) - # invalid numtokens bid (have to add status to CC code!) + # invalid numtokens bid result = rpc.tokenbid("-1", tokenid, "1") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); - # invalid numtokens bid (have to add status to CC code!) + # invalid numtokens bid result = rpc.tokenbid("0", tokenid, "1") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); - # invalid price bid (have to add status to CC code!) + # invalid price bid result = rpc.tokenbid("1", tokenid, "-1") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); - # invalid price bid (have to add status to CC code!) + # invalid price bid result = rpc.tokenbid("1", tokenid, "0") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); - # invalid tokenid bid (have to add status to CC code!) + # invalid tokenid bid result = rpc.tokenbid("100", "deadbeef", "1") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); # valid bid tokenbid = rpc.tokenbid("100", tokenid, "10") @@ -310,11 +331,11 @@ class CryptoConditionsTest (BitcoinTestFramework): # invalid token transfer amount (have to add status to CC code!) randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" result = rpc.tokentransfer(tokenid,randompubkey,"0") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); # invalid token transfer amount (have to add status to CC code!) result = rpc.tokentransfer(tokenid,randompubkey,"-1") - assert_equal(result['error'], 'invalid parameter') + assert_error(result); # valid token transfer sendtokens = rpc.tokentransfer(tokenid,randompubkey,"1") diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1012a0205..6a0555f54 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5234,6 +5234,12 @@ UniValue dicefund(const UniValue& params, bool fHelp) maxbet = atof(params[3].get_str().c_str()) * COIN; maxodds = atol(params[4].get_str().c_str()); timeoutblocks = atol(params[5].get_str().c_str()); + + if (!VALID_PLAN_NAME(name)) { + ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); + return(result); + } + hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks); if (CCerror != "") { ERR_RESULT(CCerror); @@ -5258,6 +5264,10 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; + if (!VALID_PLAN_NAME(name)) { + ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); + return(result); + } if ( amount > 0 ) { hex = DiceAddfunding(0,name,fundingtxid,amount); if (CCerror != "") { @@ -5283,6 +5293,11 @@ UniValue dicebet(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; odds = atol(params[3].get_str().c_str()); + + if (!VALID_PLAN_NAME(name)) { + ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); + return(result); + } if (amount > 0 && odds > 0) { hex = DiceBet(0,name,fundingtxid,amount,odds); if ( hex.size() > 0 ) @@ -5306,6 +5321,10 @@ UniValue dicefinish(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; 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)); + return(result); + } 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); @@ -5330,6 +5349,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; 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)); + return(result); + } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); memset(&bettxid,0,sizeof(bettxid)); if ( params.size() == 3 ) @@ -5453,9 +5476,14 @@ UniValue tokencreate(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = params[0].get_str(); supply = atof(params[1].get_str().c_str()) * COIN; - if ( name.size() == 0 || supply <= 0 ) + if ( name.size() == 0 || name.size() > 32) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("Token name must not be empty and up to 32 characters"); + return(result); + } + if ( supply <= 0 ) + { + ERR_RESULT("Token supply must be positive"); return(result); } if ( params.size() == 3 ) @@ -5463,7 +5491,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) description = params[2].get_str(); if ( description.size() > 4096 ) { - result.push_back(Pair("error", "token description longer than 4096")); + ERR_RESULT("Token description must be <= 4096 characters"); return(result); } } @@ -5488,9 +5516,14 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); std::vector pubkey(ParseHex(params[1].get_str().c_str())); amount = atol(params[2].get_str().c_str()); - if ( tokenid == zeroid || amount <= 0 ) + if ( tokenid == zeroid ) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("invalid tokenid"); + return(result); + } + if ( amount <= 0 ) + { + ERR_RESULT("amount must be positive"); return(result); } hex = AssetTransfer(0,tokenid,pubkey,amount); @@ -5519,9 +5552,19 @@ UniValue tokenbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[1].get_str().c_str()); price = atof(params[2].get_str().c_str()); bidamount = (price * numtokens) * COIN + 0.0000000049999; - if ( tokenid == zeroid || tokenid == zeroid || price <= 0 || bidamount <= 0 ) + if ( price <= 0 ) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("price must be positive"); + return(result); + } + if ( tokenid == zeroid ) + { + ERR_RESULT("invalid tokenid"); + return(result); + } + if ( bidamount <= 0 ) + { + ERR_RESULT("bid amount must be positive"); return(result); } hex = CreateBuyOffer(0,bidamount,tokenid,numtokens); @@ -5530,7 +5573,7 @@ UniValue tokenbid(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create bid")); + } else ERR_RESULT("couldnt create bid"); } else { ERR_RESULT("price and numtokens must be positive"); } From 820043536303738d2b21e7e601997d06cfc19181 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Aug 2018 22:30:28 +0200 Subject: [PATCH 15/29] Validate plan name in dicebet --- src/wallet/rpcwallet.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6a0555f54..b99fffa59 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -55,6 +55,9 @@ std::string CCerror; // Private method: UniValue z_getoperationstatus_IMPL(const UniValue&, bool); +#define PLAN_NAME_MAX 8 +#define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX) + std::string HelpRequiringPassphrase() { return pwalletMain && pwalletMain->IsCrypted() From 2d44c20272cba4d922943182749c822386505963 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 09:31:56 -1100 Subject: [PATCH 16/29] Mempool CC test --- src/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 85de0effa..e27738e04 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1530,18 +1530,20 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // XXX: is this neccesary for CryptoConditions? if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) { - flag = 1; + //flag = 1; KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->nHeight + 1; } if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { if ( flag != 0 ) KOMODO_CONNECTING = -1; + else KOMODO_CONNECTING &= ~(1<<30); return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); } if ( flag != 0 ) KOMODO_CONNECTING = -1; - + else KOMODO_CONNECTING &= ~(1<<30); + // Store transaction in memory if ( komodo_is_notarytx(tx) == 0 ) KOMODO_ON_DEMAND++; @@ -3468,7 +3470,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * { CCoinsViewCache view(pcoinsTip); bool rv = ConnectBlock(*pblock, state, pindexNew, view, false, true); - KOMODO_CONNECTING = -1; + //KOMODO_CONNECTING = -1; GetMainSignals().BlockChecked(*pblock, state); if (!rv) { if (state.IsInvalid()) From cf16cc42cf27ee144fe426ccdc3689eda79c4791 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 09:33:22 -1100 Subject: [PATCH 17/29] +print --- 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 a57197537..beed06574 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -266,7 +266,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param from_mempool = 1; height &= ((1<<30) - 1); } - fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d\n",height,from_mempool); + fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,KOMODO_CCACTIVATE); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) From 57c2bccd766e7705a9b679920b3ceffd62fc7396 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 09:34:20 -1100 Subject: [PATCH 18/29] Fix early activation --- 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 beed06574..3c38d04b3 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -259,7 +259,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param height = KOMODO_CONNECTING; if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); - if ( ASSETCHAINS_CC == 0 || height < KOMODO_CCACTIVATE ) + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) return eval->Invalid("CC are disabled or not active yet"); if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) { From 6e3dc787c55249fe4e36d37b3bb5de0761849b69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 09:35:17 -1100 Subject: [PATCH 19/29] Fix early activation --- 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 a57197537..8e8b103c8 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -259,7 +259,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param height = KOMODO_CONNECTING; if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); - if ( ASSETCHAINS_CC == 0 || height < KOMODO_CCACTIVATE ) + if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < KOMODO_CCACTIVATE ) return eval->Invalid("CC are disabled or not active yet"); if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) { From a5057f7e568a09872616895c9676965ce03ad80a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 09:39:12 -1100 Subject: [PATCH 20/29] Revert most of test changes --- src/main.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e27738e04..e25d6419b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1530,19 +1530,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // XXX: is this neccesary for CryptoConditions? if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) { - //flag = 1; + flag = 1; KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->nHeight + 1; } if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { if ( flag != 0 ) KOMODO_CONNECTING = -1; - else KOMODO_CONNECTING &= ~(1<<30); return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); } if ( flag != 0 ) KOMODO_CONNECTING = -1; - else KOMODO_CONNECTING &= ~(1<<30); // Store transaction in memory if ( komodo_is_notarytx(tx) == 0 ) @@ -3470,7 +3468,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * { CCoinsViewCache view(pcoinsTip); bool rv = ConnectBlock(*pblock, state, pindexNew, view, false, true); - //KOMODO_CONNECTING = -1; + KOMODO_CONNECTING = -1; GetMainSignals().BlockChecked(*pblock, state); if (!rv) { if (state.IsInvalid()) From 1a5b40c2e111cc9e215c799dc8f74898916d2dd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 09:52:32 -1100 Subject: [PATCH 21/29] Update version to 0.2.1 --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index cd99d531d..a42afbb61 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -55,7 +55,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); -#define KOMODO_VERSION "0.2.0" +#define KOMODO_VERSION "0.2.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_MAGIC; From 5139ffd3219a9e1273724afeacffc89d3a80f4a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 20:02:42 -1100 Subject: [PATCH 22/29] +prints --- src/cc/dice.cpp | 4 ++-- src/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 50b9cba78..2e4d8d23e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1154,10 +1154,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx char str[65]; if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - //fprintf(stderr,"bettx is spent\n"); + fprintf(stderr,"bettx is spent\n"); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - //fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); + fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); diff --git a/src/main.cpp b/src/main.cpp index e25d6419b..e2745a81e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3422,7 +3422,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if ( (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) + if ( ASSETCHAINS_STAKED != 0 && (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) { EraseFromWallets(tx.GetHash()); } @@ -4176,7 +4176,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C for (i=0; i Date: Mon, 27 Aug 2018 20:11:06 -1100 Subject: [PATCH 23/29] Return -1 if can't find spenttx --- 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 2e4d8d23e..b28683ad5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1164,7 +1164,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); fprintf(stderr,"%s\n", CCerror.c_str()); - return(0.); + return(-1.); } else if ( scriptPubKey == fundingPubKey ) res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,1); From f7ab3fb0f546cf28a6a3a5903f0373170b4ed991 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 27 Aug 2018 20:36:13 -1100 Subject: [PATCH 24/29] -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 b28683ad5..d603093f1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1154,10 +1154,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx char str[65]; if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - fprintf(stderr,"bettx is spent\n"); + //fprintf(stderr,"bettx is spent\n"); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); + //fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); From 6bd0c10acbc0ed1bd1017e7ed0fa772b9ea5d4e0 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 28 Aug 2018 17:32:59 +0700 Subject: [PATCH 25/29] More Dice CC tests --- qa/rpc-tests/cryptoconditions.py | 151 +++++++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 9 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index dd6adba76..c8a78c191 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -142,19 +142,149 @@ class CryptoConditionsTest (BitcoinTestFramework): dice = rpc.diceaddress(self.pubkey) assert_equal(dice['result'], 'success') - for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress', 'CCaddress']: + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: assert_equal(dice[x][0], 'R') # no dice created yet result = rpc.dicelist() assert_equal(result, []) + # creating dice plan with too long name + result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5") + assert_error(result) + + # creating dice plan with < 100 funding + result = rpc.dicefund("LUCKY","10","1","10000","10","5") + assert_error(result) + + # creating dice plan with 0 blocks timeout + result = rpc.dicefund("LUCKY","10","1","10000","10","0") + assert_error(result) + + # creating dice plan + dicefundtx = rpc.dicefund("LUCKY","1000","1","800","10","5") + diceid = self.send_and_mine(dicefundtx['hex']) + + # checking if it in plans list now + result = rpc.dicelist() + assert_equal(result[0], diceid) + + # set dice name for futher usage + dicename = "LUCKY" + + # adding zero funds to plan + result = rpc.diceaddfunds(dicename,diceid,"0") + assert_error(result) + + # adding negative funds to plan + result = rpc.diceaddfunds(dicename,diceid,"-1") + assert_error(result) + + # adding funds to plan + addfundstx = rpc.diceaddfunds(dicename,diceid,"1100") + result = self.send_and_mine(addfundstx['hex']) + + # checking if funds added to plan + result = rpc.diceinfo(diceid) + assert_equal(result["funding"], "2100.00000000") + + # not valid dice info checking result = rpc.diceinfo("invalid") assert_error(result) - result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5") + # placing 0 amount bet + result = rpc.dicebet(dicename,diceid,"0","1") assert_error(result) + # placing negative amount bet + result = rpc.dicebet(dicename,diceid,"-1","1") + assert_error(result) + + # placing bet more than maxbet + result = rpc.dicebet(dicename,diceid,"900","1") + assert_error(result) + + # placing bet with amount more than funding + result = rpc.dicebet(dicename,diceid,"3000","1") + assert_error(result) + + # placing bet with potential won more than funding + result = rpc.dicebet(dicename,diceid,"750","9") + assert_error(result) + + # placing 0 odds bet + result = rpc.dicebet(dicename,diceid,"1","0") + assert_error(result) + + # placing negative odds bet + result = rpc.dicebet(dicename,diceid,"1","-1") + assert_error(result) + + # placing bet with odds more than allowed + result = rpc.dicebet(dicename,diceid,"1","11") + assert_error(result) + + # placing bet with possible payout more than funding + result = rpc.dicebet(dicename,diceid,"500","4") + assert_error(result) + + # placing bet with not correct dice name + result = rpc.dicebet("nope",diceid,"100","1") + assert_error(result) + + # placing bet with not correct dice id + result = rpc.dicebet(dicename,self.pubkey,"100","1") + assert_error(result) + + # valid bet placing + placebet = rpc.dicebet(dicename,diceid,"100","1") + betid = self.send_and_mine(placebet["hex"]) + assert result, "bet placed" + + # check bet status + result = rpc.dicestatus(dicename,diceid,betid) + assert_success(result) + + # have to make some entropy for the next test + entropytx = 0 + fundingsum = 1 + while entropytx < 10: + fundingsuminput = str(fundingsum) + fundinghex = rpc.diceaddfunds(dicename,diceid,fundingsuminput) + result = self.send_and_mine(fundinghex['hex']) + entropytx = entropytx + 1 + fundingsum = fundingsum + 1 + + rpc.generate(2) + + # note initial dice funding state at this point. + # TODO: track player balance somehow (hard to do because of mining and fees) + diceinfo = rpc.diceinfo(diceid) + funding = float(diceinfo['funding']) + + # placing same amount bets with amount 1 and odds 1:2, checking if balance changed correct + losscounter = 0 + wincounter = 0 + betcounter = 0 + + while (betcounter < 10): + placebet = rpc.dicebet(dicename,diceid,"1","1") + betid = self.send_and_mine(placebet["hex"]) + finish = rpc.dicefinish(dicename,diceid,betid) + self.send_and_mine(finish["hex"]) + betresult = rpc.dicestatus(dicename,diceid,betid) + betcounter = betcounter + 1 + if betresult["status"] == "loss": + losscounter = losscounter + 1 + elif betresult["status"] == "win": + wincounter = wincounter + 1 + + # funding balance should increase if player loss, decrease if player won + fundbalanceguess = funding + losscounter - wincounter + fundinfoactual = rpc.diceinfo(diceid) + assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding']))) + + def run_token_tests(self): rpc = self.nodes[0] result = rpc.tokenaddress() @@ -170,12 +300,15 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenlist() assert_equal(result, []) + # trying to create token with negaive supply result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply") assert_error(result) + # creating token with name more than 16 chars result = rpc.tokencreate("NUKE123456789012345678901234567890", "1987420", "name too long") assert_error(result) + # creating valid token result = rpc.tokencreate("DUKE", "1987.420", "Duke's custom token") assert_success(result) @@ -276,23 +409,23 @@ class CryptoConditionsTest (BitcoinTestFramework): # invalid numtokens bid result = rpc.tokenbid("-1", tokenid, "1") - assert_error(result); + assert_error(result) # invalid numtokens bid result = rpc.tokenbid("0", tokenid, "1") - assert_error(result); + assert_error(result) # invalid price bid result = rpc.tokenbid("1", tokenid, "-1") - assert_error(result); + assert_error(result) # invalid price bid result = rpc.tokenbid("1", tokenid, "0") - assert_error(result); + assert_error(result) # invalid tokenid bid result = rpc.tokenbid("100", "deadbeef", "1") - assert_error(result); + assert_error(result) # valid bid tokenbid = rpc.tokenbid("100", tokenid, "10") @@ -331,11 +464,11 @@ class CryptoConditionsTest (BitcoinTestFramework): # invalid token transfer amount (have to add status to CC code!) randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" result = rpc.tokentransfer(tokenid,randompubkey,"0") - assert_error(result); + assert_error(result) # invalid token transfer amount (have to add status to CC code!) result = rpc.tokentransfer(tokenid,randompubkey,"-1") - assert_error(result); + assert_error(result) # valid token transfer sendtokens = rpc.tokentransfer(tokenid,randompubkey,"1") From 881869c081aa7be8d8413d26247e4ab61621e51f Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 28 Aug 2018 17:37:31 +0700 Subject: [PATCH 26/29] fixed local merge disorder --- 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 c8a78c191..ceb6237fd 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -142,7 +142,7 @@ class CryptoConditionsTest (BitcoinTestFramework): dice = rpc.diceaddress(self.pubkey) assert_equal(dice['result'], 'success') - for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress', 'CCaddress']: assert_equal(dice[x][0], 'R') # no dice created yet From aa54d5452917348c8c57c3bf9bac66bb019d5d2b Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 28 Aug 2018 17:48:47 +0700 Subject: [PATCH 27/29] Described tokename dicename length limits --- qa/rpc-tests/cryptoconditions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index ceb6237fd..cc88e8fac 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -149,7 +149,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.dicelist() assert_equal(result, []) - # creating dice plan with too long name + # creating dice plan with too long name (>8 chars) result = rpc.dicefund("THISISTOOLONG", "10000", "10", "10000", "10", "5") assert_error(result) @@ -304,7 +304,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokencreate("NUKE", "-1987420", "no bueno supply") assert_error(result) - # creating token with name more than 16 chars + # creating token with name more than 32 chars result = rpc.tokencreate("NUKE123456789012345678901234567890", "1987420", "name too long") assert_error(result) From de6be280c41094d997d1871c80e3bcb0f1ab0813 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 28 Aug 2018 17:58:14 +0700 Subject: [PATCH 28/29] Deleted test duplicate --- qa/rpc-tests/cryptoconditions.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index cc88e8fac..fbf149780 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -224,10 +224,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.dicebet(dicename,diceid,"1","11") assert_error(result) - # placing bet with possible payout more than funding - result = rpc.dicebet(dicename,diceid,"500","4") - assert_error(result) - # placing bet with not correct dice name result = rpc.dicebet("nope",diceid,"100","1") assert_error(result) From 189117dc763748fd8303a63279bcf9c440844df8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 28 Aug 2018 03:07:56 -1100 Subject: [PATCH 29/29] Disable dice status auto entropy --- src/cc/dice.cpp | 2 +- src/main.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d603093f1..6e5dbcad1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1138,7 +1138,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( scriptPubKey == fundingPubKey ) + if ( 0 && scriptPubKey == fundingPubKey ) { for (i=0; i<=n; i++) { diff --git a/src/main.cpp b/src/main.cpp index e2745a81e..aa6d69ffd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4182,7 +4182,6 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C continue; Tx = tx; if ( myAddtomempool(Tx) == false ) // can happen with out of order tx in block on resync - //if ( AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL) == false ) rejects++; } if ( rejects == 0 || rejects == lastrejects )