From 6bd0c10acbc0ed1bd1017e7ed0fa772b9ea5d4e0 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Tue, 28 Aug 2018 17:32:59 +0700 Subject: [PATCH 01/14] 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 02/14] 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 03/14] 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 04/14] 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 bad5d1c3bde49ab14d8436d040020ba340d147b3 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 31 Aug 2018 17:00:27 +0700 Subject: [PATCH 05/14] Validate plan name for Rewards CC --- src/wallet/rpcwallet.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b99fffa59..6daf9d86e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4985,6 +4985,11 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); funds = atof(params[1].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 ( funds <= 0 ) { ERR_RESULT("funds must be positive"); return result; @@ -5046,6 +5051,11 @@ UniValue rewardslock(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsLock(0,name,fundingtxid,amount); + + if (!VALID_PLAN_NAME(name)) { + ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); + return(result); + } if ( CCerror != "" ){ ERR_RESULT(CCerror); } else if ( amount > 0 ) { @@ -5071,6 +5081,11 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsAddfunding(0,name,fundingtxid,amount); + + if (!VALID_PLAN_NAME(name)) { + ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); + return(result); + } if (CCerror != "") { ERR_RESULT(CCerror); } else if (amount > 0) { @@ -5099,6 +5114,11 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); + + if (!VALID_PLAN_NAME(name)) { + ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); + return(result); + } if ( params.size() > 2 ) txid = Parseuint256((char *)params[2].get_str().c_str()); else memset(&txid,0,sizeof(txid)); From 624aa78700d1152228ff88ac763333f75acdb063 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Sat, 1 Sep 2018 15:01:53 +0700 Subject: [PATCH 06/14] Added more rewards CC tests --- qa/rpc-tests/cryptoconditions.py | 90 +++++++++++++++++++------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index fbf149780..fbd650a8e 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -280,7 +280,6 @@ class CryptoConditionsTest (BitcoinTestFramework): fundinfoactual = rpc.diceinfo(diceid) assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding']))) - def run_token_tests(self): rpc = self.nodes[0] result = rpc.tokenaddress() @@ -491,14 +490,31 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo("none") assert_error(result) + # creating rewards plan with name > 8 chars, should return error + result = rpc.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0", "10", "10") + assert_error(result) + + # creating rewards plan with 0 funding + result = rpc.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10") + assert_error(result) + + # creating rewards plan with 0 maxdays + result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "0") + assert_error(result) + + # creating rewards plan with > 25% APR + result = rpc.rewardscreatefunding("STUFF", "7777", "30", "0", "10", "10") + assert_error(result) + + # creating valid rewards plan result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") assert result['hex'], 'got raw xtn' - txid = rpc.sendrawtransaction(result['hex']) - assert txid, 'got txid' + fundingtxid = rpc.sendrawtransaction(result['hex']) + assert fundingtxid, 'got txid' # confirm the above xtn rpc.generate(1) - result = rpc.rewardsinfo(txid) + result = rpc.rewardsinfo(fundingtxid) assert_success(result) assert_equal(result['name'], 'STUFF') assert_equal(result['APR'], "25.00000000") @@ -506,39 +522,38 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['maxseconds'], 864000) assert_equal(result['funding'], "7777.00000000") assert_equal(result['mindeposit'], "10.00000000") - assert_equal(result['fundingtxid'], txid) + assert_equal(result['fundingtxid'], fundingtxid) - # funding amount must be positive - result = rpc.rewardsaddfunding("STUFF", txid, "0") + # checking if new plan in rewardslist + result = rpc.rewardslist() + assert_equal(result[0], fundingtxid) + + # creating reward plan with already existing name, should return error + result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") assert_error(result) - result = rpc.rewardsaddfunding("STUFF", txid, "555") - assert_success(result) - fundingtxid = result['hex'] - assert fundingtxid, "got funding txid" - - result = rpc.rewardslock("STUFF", fundingtxid, "7") + # add funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", fundingtxid, "-1") assert_error(result) - # the previous xtn has not been broadcasted yet - result = rpc.rewardsunlock("STUFF", fundingtxid) + # add funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", fundingtxid, "0") assert_error(result) - # wrong plan name - result = rpc.rewardsunlock("SHTUFF", fundingtxid) - assert_error(result) + # adding valid funding + result = rpc.rewardsaddfunding("STUFF", fundingtxid, "555") + addfundingtxid = self.send_and_mine(result['hex']) + assert addfundingtxid, 'got funding txid' - txid = rpc.sendrawtransaction(fundingtxid) - assert txid, 'got txid from sendrawtransaction' + # checking if funding added to rewardsplan + result = rpc.rewardsinfo(fundingtxid) + assert_equal(result['funding'], "8332.00000000") - # confirm the xtn above - rpc.generate(1) - - # amount must be positive + # trying to lock funds, locking funds amount must be positive result = rpc.rewardslock("STUFF", fundingtxid, "-5") assert_error(result) - # amount must be positive + # trying to lock funds, locking funds amount must be positive result = rpc.rewardslock("STUFF", fundingtxid, "0") assert_error(result) @@ -546,25 +561,26 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardslock("STUFF", fundingtxid, "7") assert_error(result) - # not working - #result = rpc.rewardslock("STUFF", fundingtxid, "10") - #assert_success(result) - #locktxid = result['hex'] - #assert locktxid, "got lock txid" + # locking funds in rewards plan + result = rpc.rewardslock("STUFF", fundingtxid, "10") + assert_success(result) + locktxid = result['hex'] + assert locktxid, "got lock txid" # locktxid has not been broadcast yet - #result = rpc.rewardsunlock("STUFF", locktxid) - #assert_error(result) + result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) + assert_error(result) # broadcast xtn - #txid = rpc.sendrawtransaction(locktxid) - #assert txid, 'got txid from sendrawtransaction' + txid = rpc.sendrawtransaction(locktxid) + assert txid, 'got txid from sendrawtransaction' # confirm the xtn above - #rpc.generate(1) + rpc.generate(1) - #result = rpc.rewardsunlock("STUFF", locktxid) - #assert_error(result) + # will not unlock since reward amount is less than tx fee + result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) + assert_error(result) def run_test (self): From c435e32afe5b6dd9ddf699d4bdc480a214e4bb2e Mon Sep 17 00:00:00 2001 From: Capital Technologies & Research <37148079+capital-technologies@users.noreply.github.com> Date: Wed, 5 Sep 2018 19:18:08 +0300 Subject: [PATCH 07/14] [Fix] RPC Asset Chain - getblockchaininfo --- src/rpcblockchain.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 7f01c862f..1701dd4a6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1297,14 +1297,20 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) ); LOCK(cs_main); - + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip()); + } else { + int32_t longestchain = komodo_longestchain(); + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; + } UniValue obj(UniValue::VOBJ); obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty())); - obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()))); + obj.push_back(Pair("verificationprogress", progress)); obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); From 37162298241c186778b64f3c04406a5c5071b878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 5 Sep 2018 06:09:00 -1100 Subject: [PATCH 08/14] Fix --- src/rpcblockchain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1701dd4a6..08592fb67 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -31,6 +31,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(); double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty) { @@ -1299,7 +1300,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) LOCK(cs_main); double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip()); + progress = Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()); } else { int32_t longestchain = komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; From 52ff32a564a64227f9ec8d64ad13479769a6d2a8 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 4 Sep 2018 05:29:36 -0300 Subject: [PATCH 09/14] put burntx opreturn at end of vout and fix crash with import tx --- src/cc/import.cpp | 2 +- src/importcoin.cpp | 4 ++-- src/main.cpp | 17 ++++++++++------- src/test-komodo/test_coinimport.cpp | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 99418f711..ffc94ac43 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -59,7 +59,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // check burn amount { - uint64_t burnAmount = burnTx.vout[0].nValue; + uint64_t burnAmount = burnTx.vout.back().nValue; if (burnAmount == 0) return Invalid("invalid-burn-amount"); uint64_t totalOut = 0; diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 8b87cb535..d36943b5d 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -45,7 +45,7 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint { std::vector burnOpret; if (burnTx.vout.size() == 0) return false; - GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret); + GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); ss >> targetSymbol; ss >> payoutsHash); @@ -61,7 +61,7 @@ CAmount GetCoinImportValue(const CTransaction &tx) CTransaction burnTx; std::vector payouts; if (UnmarshalImportTx(tx, proof, burnTx, payouts)) { - return burnTx.vout.size() ? burnTx.vout[0].nValue : 0; + return burnTx.vout.size() ? burnTx.vout.back().nValue : 0; } return 0; } diff --git a/src/main.cpp b/src/main.cpp index e25d6419b..ce61a0e35 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1547,14 +1547,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa KOMODO_ON_DEMAND++; pool.addUnchecked(hash, entry, !IsInitialBlockDownload()); - // Add memory address index - if (fAddressIndex) { - pool.addAddressIndex(entry, view); - } + if (!tx.IsCoinImport()) + { + // Add memory address index + if (fAddressIndex) { + pool.addAddressIndex(entry, view); + } - // Add memory spent index - if (fSpentIndex) { - pool.addSpentIndex(entry, view); + // Add memory spent index + if (fSpentIndex) { + pool.addSpentIndex(entry, view); + } } } diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index eac21428a..8c1d8b0f8 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -180,7 +180,7 @@ TEST_F(TestCoinImport, testInvalidBurnOutputs) TEST_F(TestCoinImport, testInvalidBurnParams) { - burnTx.vout[0].scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(testCcid)); + burnTx.vout.back().scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(testCcid)); MoMoM = burnTx.GetHash(); // TODO: an actual branch CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); TestRunCCEval(tx); @@ -198,7 +198,7 @@ TEST_F(TestCoinImport, testWrongChainId) TEST_F(TestCoinImport, testInvalidBurnAmount) { - burnTx.vout[0].nValue = 0; + burnTx.vout.back().nValue = 0; MoMoM = burnTx.GetHash(); // TODO: an actual branch CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); TestRunCCEval(tx); From a839f9bc02da46c673b8e7e8c45676e43d8f5113 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 4 Sep 2018 06:05:26 -0300 Subject: [PATCH 10/14] shell script to document migrate process --- migratecoin.md | 61 -------------------------------------------------- migratecoin.sh | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 61 deletions(-) delete mode 100644 migratecoin.md create mode 100644 migratecoin.sh diff --git a/migratecoin.md b/migratecoin.md deleted file mode 100644 index 7859bdff2..000000000 --- a/migratecoin.md +++ /dev/null @@ -1,61 +0,0 @@ -# MigrateCoin protocol - - - -## ExportCoins tx: - - - -``` - -vin: - - [ any ] - -vout: - - - amount: {burnAmount} - - script: OP_RETURN "send to ledger {id} {voutsHash}" - -``` - - - -* ExportCoin is a standard tx which burns coins in an OP_RETURN - - - -## ImportCoins tx: - - - -``` - -vin: - - - txid: 0000000000000000000000000000000000000000000000000000000000000000 - - idx: 0 - - script: CC_EVAL(EVAL_IMPORTCOINS, {momoProof},{exportCoin}) OP_CHECKCRYPTOCONDITION_UNILATERAL - -vout: - - - [ vouts matching voutsHash in exportCoin ] - -``` - - - -* ImportCoin transaction has no signature - -* ImportCoin is non malleable - -* ImportCoin satisfies tx.IsCoinBase() - -* ImportCoin uses a new opcode which allows a one sided check (no scriptPubKey) - -* ImportCoin must contain CC opcode EVAL_IMPORTCOINS - -* ImportCoin fees are equal to the difference between burnAmount in exportCoins and the sum of outputs. diff --git a/migratecoin.sh b/migratecoin.sh new file mode 100644 index 000000000..6cd09ba04 --- /dev/null +++ b/migratecoin.sh @@ -0,0 +1,43 @@ +#!/usr/bin/bash + +# This script makes the neccesary transactions to migrate +# coin between 2 assetchains on the same -ac_cc id + +set -e + +source=TXSCL +target=TXSCL000 +address="RFw7byY4xZpZCrtkMk3nFuuG1NTs9rSGgQ" +amount=1 + +# Alias for running cli on source chain +cli_source="komodo-cli -ac_name=$source" + +# Raw tx that we will work with +txraw=`$cli_source createrawtransaction "[]" "{\"$address\":$amount}"` + +# Convert to an export tx +exportData=`$cli_source migrate_converttoexport $txraw $target $amount` +exportRaw=`echo $exportData | jq -r .exportTx` +exportPayouts=`echo $exportData | jq -r .payouts` + +# Fund +exportFundedData=`$cli_source fundrawtransaction $exportRaw` +exportFundedTx=`echo $exportFundedData | jq -r .hex` + +# Sign +exportSignedData=`$cli_source signrawtransaction $exportFundedTx` +exportSignedTx=`echo $exportSignedData | jq -r .hex` + +# Send +echo "Sending export tx" +$cli_source sendrawtransaction $exportSignedTx + +read -p "Wait for a notarisation to KMD, and then two more notarisations from the target chain, and then press enter to continue" + +# Create import +importTx=`$cli_source migrate_createimporttransaction $exportSignedTx $payouts` +importTx=`komodo-cli migrate_completeimporttransaction $importTx` + +# Send import +komodo-cli -ac_name=$target sendrawtransaction $importTx From 9325760595071868767796a535ee45eb2979cfdb Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 4 Sep 2018 17:12:04 -0300 Subject: [PATCH 11/14] fix for TXSCL data leak --- src/crosschain.cpp | 7 +++++-- src/notarisationdb.cpp | 7 ++++++- src/notarisationdb.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 197390e59..831c7bcae 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -50,6 +50,8 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh int seenOwnNotarisations = 0; + bool txscl = IsTXSCL(symbol); + for (int i=0; i kmdHeight) break; NotarisationsInBlock notarisations; @@ -72,8 +74,9 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh if (seenOwnNotarisations == 1) { BOOST_FOREACH(Notarisation& nota, notarisations) { - if (nota.second.ccId == targetCCid) - moms.push_back(nota.second.MoM); + if (IsTXSCL(nota.second.symbol) == txscl) + if (nota.second.ccId == targetCCid) + moms.push_back(nota.second.MoM); } } } diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index cdfbb82c1..de3dd75f2 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -26,7 +26,7 @@ NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight) { NotarisationData data; if (ParseNotarisationOpReturn(tx, data)) - if (strlen(data.symbol) >= 5 && strncmp(data.symbol, "TXSCL", 5) == 0) + if (IsTXSCL(data.symbol)) isTxscl = 1; } @@ -46,6 +46,11 @@ NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight) return vNotarisations; } +bool IsTXSCL(const char* symbol) +{ + return strlen(symbol) >= 5 && strncmp(symbol, "TXSCL", 5) == 0; +} + bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs) { diff --git a/src/notarisationdb.h b/src/notarisationdb.h index b8cd93691..f01a5a587 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -24,5 +24,6 @@ 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); +bool IsTXSCL(const char* symbol); #endif /* NOTARISATIONDB_H */ From 04007d500aca1f3859c47be288f5bed60c2002ff Mon Sep 17 00:00:00 2001 From: siulynot Date: Fri, 7 Sep 2018 10:17:17 -0400 Subject: [PATCH 12/14] -ac_ccactivate added to COQUI --- src/assetchains.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains.json b/src/assetchains.json index b74d953a0..15358d808 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -46,6 +46,7 @@ { "ac_name": "COQUI", "ac_supply": "72000000" + "ac_ccactivate": "200000" }, { "ac_name": "WLC", From 3ec2602dd651b8ec290dc6052b0af0560545682c Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 7 Sep 2018 16:42:06 +0200 Subject: [PATCH 13/14] modified: assetchains.json --- src/assetchains.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.json b/src/assetchains.json index 15358d808..3183eebb0 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -45,7 +45,7 @@ }, { "ac_name": "COQUI", - "ac_supply": "72000000" + "ac_supply": "72000000", "ac_ccactivate": "200000" }, { From e5714cac7bc174fbea49e3899bb73a5f362b43f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 7 Sep 2018 03:49:23 -1100 Subject: [PATCH 14/14] COQUI --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index d7a18811d..158e62cad 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -15,7 +15,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=COQUI -ac_supply=72000000 -addnode=78.47.196.146 $1 & +./komodod -pubkey=$pubkey -ac_name=COQUI -ac_supply=72000000 -ac_ccactivate=200000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=WLC -ac_supply=210000000 -addnode=148.251.190.89 $1 & ./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=CEAL -ac_supply=366666666 -addnode=78.47.196.146 $1 &