From f005240c4fcaad778e66d122a7fded11b95a78ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Mar 2019 07:19:56 -1100 Subject: [PATCH 01/56] Remove voutsum check --- src/cc/rogue_rpc.cpp | 18 +++--------------- src/main.cpp | 6 +++--- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index bfcdf1f92..4e604cc84 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1499,9 +1499,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C case 'R': if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) != 'R' ) { - //fprintf(stderr,"height.%d couldnt decode register opret\n",height); - //if ( height > 20000 ) - return eval->Invalid("couldnt decode register opret"); + return eval->Invalid("couldnt decode register opret"); } // baton is created // validation is done below @@ -1509,23 +1507,13 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C case 'K': if ( (funcid= rogue_keystrokesopretdecode(gametxid,batontxid,pk,keystrokes,scriptPubKey)) != 'K' ) { - //fprintf(stderr,"height.%d couldnt decode keystrokes opret\n",height); - //if ( height > 20000 ) - return eval->Invalid("couldnt decode keystrokes opret"); + return eval->Invalid("couldnt decode keystrokes opret"); } // spending the baton proves it is the user if the pk is the signer return(true); break; case 'H': case 'Q': - /*if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) != funcid ) - { - //fprintf(stderr,"height.%d couldnt decode H/Q opret\n",height); - //if ( height > 20000 ) - return eval->Invalid("couldnt decode H/Q opret"); - } - fprintf(stderr,"height.%d decoded H/Q opret\n",height); - // spending the baton proves it is the user if the pk is the signer - // rest of validation is done below*/ + // done in the next switch statement as there are some H/Q tx with playerdata which would skip this section break; default: return eval->Invalid("illegal rogue non-decoded funcid"); diff --git a/src/main.cpp b/src/main.cpp index 8ea3a499b..ce0760cf5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3506,9 +3506,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin fprintf(stderr,"voutsum %.8f too big\n",(double)voutsum/COIN); return state.DoS(100, error("ConnectBlock(): voutsum too big"),REJECT_INVALID,"tx valueout is too big"); } - else*/ - if ( voutsum < prevsum ) - return state.DoS(100, error("ConnectBlock(): voutsum less after adding valueout"),REJECT_INVALID,"tx valueout is too big"); + else + if ( voutsum < prevsum ) // PRLPAY overflows this and it isnt a conclusive test anyway + return state.DoS(100, error("ConnectBlock(): voutsum less after adding valueout"),REJECT_INVALID,"tx valueout is too big");*/ if (!tx.IsCoinBase()) { nFees += view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime) - valueout; From c99801952b06ee192aff6b87ae6577438c8c36ce Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 3 Mar 2019 18:27:50 -0500 Subject: [PATCH 02/56] Teach RPC interface about dpow-enabled minconfs (#1231) * Make minconfs dpow-aware in z_listunspent + z_listreceivedbyaddress * Add dpow-related test files to test suite * Add dpow simulation to regtest every 7 blocks * Fix compiler errors * Fix link error * Fix stdout spam when running regtests * Dpowminconfs for listreceivedbyaddress * dpowconfs tests * Start adding specific tests for dpowminconfs in listreceivedbyaddress * Get dpowminconfs tests for listreceivedbyaddress working * Add dpowminconfs to getreceivedbyaddress + listunspent * Add test for listtransactions + getreceivedbyaddress support * Reliably passing dpowminconf tests. We only check for notarized-ness now, not exact confirmation numbers, to avoid race conditions * Poll for the expected notarization info before running further tests; add support for getbalance * Migrate tx_height() to a place where asyncrpcoperation_sendmany.cpp can use it * fix * Teach GetFilteredNotes about dpowconfs Many RPCs rely on this internal function, which now correctly uses dpowconfs to filter by the minconf/maxconf parameters. * Fix sendmany when using non-default minconf * inline seems to make things happy * cleanup * Add some code to test z_sendmany, which points out https://github.com/jl777/komodo/issues/1247 * try this * Use already calculated value of dpowconfs instead of calculating it again --- qa/pull-tester/rpc-tests.sh | 2 + qa/rpc-tests/dpowconfs.py | 151 +++++++++++++++++ qa/rpc-tests/test_framework/util.py | 10 +- src/komodo.h | 9 + src/komodo_bitcoind.h | 19 +++ src/komodo_defs.h | 1 + src/komodo_notary.h | 1 - src/komodo_utils.h | 3 +- src/wallet/asyncrpcoperation_sendmany.cpp | 14 +- src/wallet/rpcwallet.cpp | 190 ++++++++++++---------- src/wallet/wallet.cpp | 21 ++- src/wallet/wallet.h | 1 + 12 files changed, 324 insertions(+), 98 deletions(-) create mode 100755 qa/rpc-tests/dpowconfs.py diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 226c16b11..c4775fa85 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -11,6 +11,8 @@ export BITCOIND=${REAL_BITCOIND} #Run the tests testScripts=( + 'dpow.py' + 'dpowconfs.py' 'ac_private.py' 'verushash.py' 'paymentdisclosure.py' diff --git a/qa/rpc-tests/dpowconfs.py b/qa/rpc-tests/dpowconfs.py new file mode 100755 index 000000000..9c449923e --- /dev/null +++ b/qa/rpc-tests/dpowconfs.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 The Hush developers +# Copyright (c) 2019 The SuperNET developers +# 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.util import * +import time + +class DPoWConfsTest(BitcoinTestFramework): + def debug_info(self): + rpc = self.nodes[0] + print "-- DEBUG --" + getinfo = rpc.getinfo() + getwalletinfo = rpc.getwalletinfo() + listreceivedbyaddress = rpc.listreceivedbyaddress() + print "notarized=", getinfo['notarized'], " blocks=", getinfo['blocks'] + #print "getinfo=", getinfo + print "balance=", getwalletinfo['balance'] + #print "getwalletinfo=", getwalletinfo + print "listreceivedbyaddress=", listreceivedbyaddress + print "-- DEBUG --" + + def setup_chain(self): + self.num_nodes = 1 + print("Initializing DPoWconfs test directory "+self.options.tmpdir) + initialize_chain_clean(self.options.tmpdir, self.num_nodes) + + def setup_network(self): + print("Setting up network...") + self.nodes = [] + self.is_network_split = False + self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf" + self.nodes = start_nodes( self.num_nodes, self.options.tmpdir, + extra_args=[[ + '-ac_name=REGTEST', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-port=64367', + '-rpcport=64368', + '-regtest', + '-addressindex=1', + '-spentindex=1', + '-ac_supply=5555555', + '-ac_reward=10000000000000', + #'-pubkey=' + self.pubkey, + '-ac_cc=2', + '-whitelist=127.0.0.1', + '-debug', + '--daemon', + '-rpcuser=rt', + '-rpcpassword=rt' + ]] + ) + self.sync_all() + + def run_test(self): + rpc = self.nodes[0] + # 98 is notarized, next will be 105. Must mine at least 101 + # blocks for 100 block maturity rule + blockhashes = rpc.generate(101) + # block 98, this is 0 indexed + notarizedhash = blockhashes[97] + self.debug_info() + + taddr = rpc.getnewaddress() + txid = rpc.sendtoaddress(taddr, 5.55) + # blocks 102,103 + rpc.generate(2) + self.debug_info() + + info = rpc.getinfo() + print "notarizedhash=", notarizedhash, "\n" + print "info[notarizedhash]", info['notarizedhash'], "\n" + assert_equal( info['notarizedhash'], notarizedhash) + + result = rpc.listunspent() + + # this xtn has 2 raw confs, but not in a notarized block, + # so dpowconfs holds it at 1 + for res in result: + if (res['address'] == taddr and res['generated'] == 'false'): + assert_equal( result[0]['confirmations'], 1 ) + assert_equal( result[0]['rawconfirmations'], 2 ) + + # we will now have 3 rawconfs but confirmations=1 because not notarized + # block 104 + rpc.generate(1) + self.debug_info() + minconf = 2 + result = rpc.listreceivedbyaddress(minconf) + print "listreceivedbyaddress(2)=", result, "\n" + + # nothing is notarized, so we should see no results for minconf=2 + assert len(result) == 0 + + print "getreceivedaddress" + received = rpc.getreceivedbyaddress(taddr, minconf) + assert_equal( received, 0.00000000) + + #received = rpc.getreceivedbyaddress(taddr) + #assert_equal( received, "5.55000000") + taddr = rpc.getnewaddress() + zaddr = rpc.z_getnewaddress() + # should get insufficient funds error + recipients = [ { "amount" : Decimal('4.20'), "address" : zaddr } ] + txid = rpc.z_sendmany( taddr, recipients, minconf) + + # generate a notarized block, block 105 and block 106 + # only generating the notarized block seems to have + # race conditions about whether the block is notarized + txids = rpc.generate(2) + self.debug_info() + + getinfo = rpc.getinfo() + # try to allow notarization data to update + print "Sleeping" + while (getinfo['blocks'] != 106) or (getinfo['notarized'] != 105): + printf(".") + time.sleep(1) + getinfo = rpc.getinfo() + + # make sure this block was notarized as we expect + #assert_equal(getinfo['blocks'], getinfo['notarized']) + #assert_equal(getinfo['notarizedhash'], txids[0]) + + result = rpc.listreceivedbyaddress(minconf) + print "listreceivedbyaddress(2)=", result + + assert_equal( len(result), 1, 'got one xtn with minconf=2' ) + + # verify we see the correct dpowconfs + rawconfs + assert_greater_than( result[0]['confirmations'], 1) + assert_greater_than( result[0]['rawconfirmations'], 1) + + print "listtransactions" + xtns = rpc.listtransactions() + # verify this rpc agrees with listreceivedbyaddress + assert_greater_than(xtns[0]['confirmations'], 1) + assert_greater_than(xtns[0]['rawconfirmations'], 1) + + print "getreceivedaddress" + received = rpc.getreceivedbyaddress(taddr, minconf) + assert_equal( "%.8f" % received, "5.55000000") + + received = rpc.getreceivedbyaddress(taddr) + assert_equal( "%.8f" % received, "5.55000000") + +if __name__ == '__main__': + DPoWConfsTest().main() diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index e9130171b..6bcf4cd18 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -1,9 +1,7 @@ # Copyright (c) 2014 The Bitcoin Core developers -# Copyright (c) 2018 The SuperNET developers +# Copyright (c) 2018-2019 The SuperNET developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. - - # # Helpful routines for regression testing # @@ -415,10 +413,16 @@ def assert_true(condition, message = ""): def assert_false(condition, message = ""): assert_true(not condition, message) +# assert thing2 > thing1 def assert_greater_than(thing1, thing2): if thing1 <= thing2: raise AssertionError("%s <= %s"%(str(thing1),str(thing2))) +# assert thing2 >= thing1 +def assert_greater_than_or_equal(thing1, thing2): + if thing1 < thing2: + raise AssertionError("%s < %s"%(str(thing1),str(thing2))) + def assert_raises(exc, fun, *args, **kwds): try: fun(*args, **kwds) diff --git a/src/komodo.h b/src/komodo.h index bd3550e38..791adba33 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -27,6 +27,8 @@ #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) +extern int32_t NOTARIZED_HEIGHT; +uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; #include #include @@ -930,6 +932,13 @@ int32_t komodo_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) } notarized = 1; } + // simulate DPoW in regtest mode for dpowconfs tests/etc + if ( Params().NetworkIDString() == "regtest" && ( height%7 == 0) ) { + notarized = 1; + sp->NOTARIZED_HEIGHT = height; + sp->NOTARIZED_HASH = block.GetHash(); + sp->NOTARIZED_DESTTXID = txhash; + } if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("(tx.%d: ",i); for (j=0; jptr[0] = '\0'; } +int tx_height( const uint256 &hash ){ + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + if (!GetTransaction(hash, tx, hashBlock, true)) { + fprintf(stderr,"tx hash %s does not exist!\n", hash.ToString().c_str() ); + } + + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } + return nHeight; +} + + /************************************************************************ * * Use the "writer" to accumulate text until done diff --git a/src/komodo_defs.h b/src/komodo_defs.h index f17e14ebf..cbf84b7f0 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -78,6 +78,7 @@ extern int32_t VERUS_MIN_STAKEAGE; extern std::string DONATION_PUBKEY; extern uint8_t ASSETCHAINS_PRIVATE; extern int32_t USE_EXTERNAL_PUBKEY; +int tx_height( const uint256 &hash ); extern char NOTARYADDRS[64][36]; extern uint8_t NUM_NOTARIES; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c4984cee2..5cdbf237d 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -15,7 +15,6 @@ #include "komodo_defs.h" - #include "komodo_cJSON.h" #include "notaries_staked.h" diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2c4a2d040..079ce1eea 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1366,7 +1366,8 @@ void komodo_statefname(char *fname,char *symbol,char *str) fname[len - n] = 0; else { - printf("unexpected fname.(%s) vs %s [%s] n.%d len.%d (%s)\n",fname,symbol,ASSETCHAINS_SYMBOL,n,len,&fname[len - n]); + if ( strcmp(symbol,"REGTEST") != 0 ) + printf("unexpected fname.(%s) vs %s [%s] n.%d len.%d (%s)\n",fname,symbol,ASSETCHAINS_SYMBOL,n,len,&fname[len - n]); return; } } diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index d4c5077cc..0ea17a5f8 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -54,6 +54,8 @@ using namespace libzcash; extern char ASSETCHAINS_SYMBOL[65]; +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); +int tx_height( const uint256 &hash ); extern UniValue signrawtransaction(const UniValue& params, bool fHelp); extern UniValue sendrawtransaction(const UniValue& params, bool fHelp); @@ -1049,8 +1051,16 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) { continue; } - if (out.nDepth < mindepth_) { - continue; + if( mindepth_ > 1 ) { + int nHeight = tx_height(out.tx->GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, out.nDepth); + if (dpowconfs < mindepth_) { + continue; + } + } else { + if (out.nDepth < mindepth_) { + continue; + } } const CScript &scriptPubKey = out.tx->vout[out.i].scriptPubKey; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6bd1802f0..2397be883 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -84,6 +84,8 @@ UniValue z_getoperationstatus_IMPL(const UniValue&, bool); #define PLAN_NAME_MAX 8 #define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX) +int tx_height( const uint256 &hash ); + std::string HelpRequiringPassphrase() { return pwalletMain && pwalletMain->IsCrypted() @@ -933,9 +935,20 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) continue; BOOST_FOREACH(const CTxOut& txout, wtx.vout) - if (txout.scriptPubKey == scriptPubKey) - if (wtx.GetDepthInMainChain() >= nMinDepth) - nAmount += txout.nValue; // komodo_interest? + if (txout.scriptPubKey == scriptPubKey) { + int nDepth = wtx.GetDepthInMainChain(); + if( nMinDepth > 1 ) { + int nHeight = tx_height(wtx.GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, nDepth); + if (dpowconfs >= nMinDepth) { + nAmount += txout.nValue; // komodo_interest? + } + } else { + if (nDepth >= nMinDepth) { + nAmount += txout.nValue; // komodo_interest? + } + } + } } return ValueFromAmount(nAmount); @@ -1013,8 +1026,18 @@ CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi CAmount nReceived, nSent, nFee; wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter); - if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) - nBalance += nReceived; + int nDepth = wtx.GetDepthInMainChain(); + if( nMinDepth > 1 ) { + int nHeight = tx_height(wtx.GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, nDepth); + if (nReceived != 0 && dpowconfs >= nMinDepth) { + nBalance += nReceived; + } + } else { + if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) { + nBalance += nReceived; + } + } nBalance -= nSent + nFee; } @@ -1186,10 +1209,20 @@ UniValue getbalance(const UniValue& params, bool fHelp) list listReceived; list listSent; wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount, filter); - if (wtx.GetDepthInMainChain() >= nMinDepth) - { - BOOST_FOREACH(const COutputEntry& r, listReceived) - nBalance += r.amount; + + int nDepth = wtx.GetDepthInMainChain(); + if( nMinDepth > 1 ) { + int nHeight = tx_height(wtx.GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, nDepth); + if (dpowconfs >= nMinDepth) { + BOOST_FOREACH(const COutputEntry& r, listReceived) + nBalance += r.amount; + } + } else { + if (nDepth >= nMinDepth) { + BOOST_FOREACH(const COutputEntry& r, listReceived) + nBalance += r.amount; + } } BOOST_FOREACH(const COutputEntry& s, listSent) nBalance -= s.amount; @@ -1460,8 +1493,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds - CAmount nBalance = pwalletMain->GetBalance(); - //CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); + CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); @@ -1572,9 +1604,16 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts) if (wtx.IsCoinBase() || !CheckFinalTx(wtx)) continue; - int nDepth = wtx.GetDepthInMainChain(); - if (nDepth < nMinDepth) - continue; + int nDepth = wtx.GetDepthInMainChain(); + if( nMinDepth > 1 ) { + int nHeight = tx_height(wtx.GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, nDepth); + if (dpowconfs < nMinDepth) + continue; + } else { + if (nDepth < nMinDepth) + continue; + } BOOST_FOREACH(const CTxOut& txout, wtx.vout) { @@ -2851,8 +2890,16 @@ UniValue listunspent(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); BOOST_FOREACH(const COutput& out, vecOutputs) { - if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) - continue; + int nDepth = out.tx->GetDepthInMainChain(); + if( nMinDepth > 1 ) { + int nHeight = tx_height(out.tx->GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, nDepth); + if (dpowconfs < nMinDepth || dpowconfs > nMaxDepth) + continue; + } else { + if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth) + continue; + } CTxDestination address; const CScript& scriptPubKey = out.tx->vout[out.i].scriptPubKey; @@ -3068,28 +3115,17 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) for (auto & entry : sproutEntries) { UniValue obj(UniValue::VOBJ); - int nHeight = 0; - CTransaction tx; - uint256 hashBlock; + + int nHeight = tx_height(entry.jsop.hash); + int dpowconfs = komodo_dpowconfs(nHeight, entry.confirmations); + // Only return notarized results when minconf>1 + if (nMinDepth > 1 && dpowconfs == 1) + continue; obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("jsindex", (int)entry.jsop.js )); obj.push_back(Pair("jsoutindex", (int)entry.jsop.n)); - - if (!GetTransaction(entry.jsop.hash, tx, hashBlock, true)) { - // TODO: should we throw JSONRPCError ? - fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() ); - } - - BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); - if (it != mapBlockIndex.end()) { - nHeight = it->second->GetHeight(); - //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); - } else { - // TODO: should we throw JSONRPCError ? - fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); - } - obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); + obj.push_back(Pair("confirmations", dpowconfs)); obj.push_back(Pair("rawconfirmations", entry.confirmations)); bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get(entry.address)); obj.push_back(Pair("spendable", hasSproutSpendingKey)); @@ -3105,25 +3141,17 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) for (auto & entry : saplingEntries) { UniValue obj(UniValue::VOBJ); + + int nHeight = tx_height(entry.op.hash); + int dpowconfs = komodo_dpowconfs(nHeight, entry.confirmations); + + // Only return notarized results when minconf>1 + if (nMinDepth > 1 && dpowconfs == 1) + continue; + obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("outindex", (int)entry.op.n)); - int nHeight = 0; - CTransaction tx; - uint256 hashBlock; - if (!GetTransaction(entry.op.hash, tx, hashBlock, true)) { - // TODO: should we throw JSONRPCError ? - fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() ); - } - - BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); - if (it != mapBlockIndex.end()) { - nHeight = it->second->GetHeight(); - //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); - } else { - // TODO: should we throw JSONRPCError ? - fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); - } - obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); + obj.push_back(Pair("confirmations", dpowconfs)); obj.push_back(Pair("rawconfirmations", entry.confirmations)); libzcash::SaplingIncomingViewingKey ivk; libzcash::SaplingFullViewingKey fvk; @@ -3144,7 +3172,6 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) return results; } - UniValue fundrawtransaction(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) @@ -3795,8 +3822,17 @@ CAmount getBalanceTaddr(std::string transparentAddress, int minDepth=1, bool ign pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); BOOST_FOREACH(const COutput& out, vecOutputs) { - if (out.nDepth < minDepth) { - continue; + int nDepth = out.tx->GetDepthInMainChain(); + if( minDepth > 1 ) { + int nHeight = tx_height(out.tx->GetHash()); + int dpowconfs = komodo_dpowconfs(nHeight, nDepth); + if (dpowconfs < minDepth) { + continue; + } + } else { + if (out.nDepth < minDepth) { + continue; + } } if (ignoreUnspendable && !out.fSpendable) { @@ -3901,21 +3937,11 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) if (boost::get(&zaddr) != nullptr) { for (CSproutNotePlaintextEntry & entry : sproutEntries) { UniValue obj(UniValue::VOBJ); - int nHeight = 0; - CTransaction tx; - uint256 hashBlock; - - if (GetTransaction(entry.jsop.hash, tx, hashBlock, true)) { - BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); - if (it != mapBlockIndex.end()) { - nHeight = it->second->GetHeight(); - //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); - } else { - fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); - } - } else { - fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() ); - } + int nHeight = tx_height(entry.jsop.hash); + int dpowconfs = komodo_dpowconfs(nHeight, entry.confirmations); + // Only return notarized results when minconf>1 + if (nMinDepth > 1 && dpowconfs == 1) + continue; obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value())))); @@ -3924,7 +3950,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("jsindex", entry.jsop.js)); obj.push_back(Pair("jsoutindex", entry.jsop.n)); obj.push_back(Pair("rawconfirmations", entry.confirmations)); - obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); + obj.push_back(Pair("confirmations", dpowconfs)); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop))); } @@ -3933,27 +3959,19 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) } else if (boost::get(&zaddr) != nullptr) { for (SaplingNoteEntry & entry : saplingEntries) { UniValue obj(UniValue::VOBJ); - int nHeight = 0; - CTransaction tx; - uint256 hashBlock; - if (GetTransaction(entry.op.hash, tx, hashBlock, true)) { - BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); - if (it != mapBlockIndex.end()) { - nHeight = it->second->GetHeight(); - //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); - } else { - fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); - } - } else { - fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() ); - } + int nHeight = tx_height(entry.op.hash); + int dpowconfs = komodo_dpowconfs(nHeight, entry.confirmations); + // Only return notarized results when minconf>1 + if (nMinDepth > 1 && dpowconfs == 1) + continue; + obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value())))); obj.push_back(Pair("memo", HexStr(entry.memo))); obj.push_back(Pair("outindex", (int)entry.op.n)); obj.push_back(Pair("rawconfirmations", entry.confirmations)); - obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); + obj.push_back(Pair("confirmations", dpowconfs)); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op))); } @@ -8024,8 +8042,6 @@ UniValue test_heirmarker(const UniValue& params, bool fHelp) cp = CCinit(&C, EVAL_HEIR); return(FinalizeCCTx(0, cp, mtx, myPubkey, 10000, opret)); - - } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 82642df00..9cf2a86cb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -60,6 +60,9 @@ bool fPayAtLeastCustomFee = true; #include "komodo_defs.h" CBlockIndex *komodo_chainactive(int32_t height); +extern std::string DONATION_PUBKEY; +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); +int tx_height( const uint256 &hash ); /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) @@ -4966,11 +4969,21 @@ void CWallet::GetFilteredNotes( CWalletTx wtx = p.second; // Filter the transactions before checking for notes - if (!CheckFinalTx(wtx) || - wtx.GetBlocksToMaturity() > 0 || - wtx.GetDepthInMainChain() < minDepth || - wtx.GetDepthInMainChain() > maxDepth) { + if (!CheckFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0) continue; + + if (minDepth > 1) { + int nHeight = tx_height(wtx.GetHash()); + int nDepth = wtx.GetDepthInMainChain(); + int dpowconfs = komodo_dpowconfs(nHeight,nDepth); + if ( dpowconfs < minDepth || dpowconfs > maxDepth) { + continue; + } + } else { + if ( wtx.GetDepthInMainChain() < minDepth || + wtx.GetDepthInMainChain() > maxDepth) { + continue; + } } for (auto & pair : wtx.mapSproutNoteData) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 663e60367..10aa83ce6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -60,6 +60,7 @@ extern bool bSpendZeroConfChange; extern bool fSendFreeTransactions; extern bool fPayAtLeastCustomFee; + //! -paytxfee default static const CAmount DEFAULT_TRANSACTION_FEE = 0; //! -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB From a3b4e026dae1ca7660a1799250ececb43ff125b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Mar 2019 21:21:55 -1100 Subject: [PATCH 03/56] Cleanup .pack file --- src/cc/rogue/main.c | 2 ++ src/cc/rogue_rpc.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 4e6221aa1..5e79e399e 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -763,6 +763,8 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * } free(rs->keystrokeshex), rs->keystrokeshex = 0; } + // extract and get keystrokes field and compare it to pastkeys + // if not matching... panic? if ( (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) { free(pastkeys); diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 4e604cc84..c92a52725 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1071,7 +1071,7 @@ UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) { static uint32_t good,bad; static uint256 prevgame; - char str[512],*keystrokes,rogueaddr[64],str2[67]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed,mult = 10; CPubKey roguepk; struct rogue_player P; + char str[512],*keystrokes,rogueaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed,mult = 10; CPubKey roguepk; struct rogue_player P; *cashoutp = 0; roguepk = GetUnspendable(cp,0); GetCCaddress1of2(cp,rogueaddr,roguepk,pk); @@ -1080,6 +1080,9 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C { //fprintf(stderr,"numkeys.%d rogue_extractgame %s\n",numkeys,gametxid.GetHex().c_str()); free(keystrokes); + sprintf(fname,"rogue.%llu.pack",(long long)seed); + boost::filesystem::remove(fname); + //fprintf(stderr,"extracted.(%s)\n",str); for (i=0; i Date: Sun, 3 Mar 2019 21:22:39 -1100 Subject: [PATCH 04/56] Remove --- src/cc/rogue_rpc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index c92a52725..7bd7a160a 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1081,7 +1081,7 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C //fprintf(stderr,"numkeys.%d rogue_extractgame %s\n",numkeys,gametxid.GetHex().c_str()); free(keystrokes); sprintf(fname,"rogue.%llu.pack",(long long)seed); - boost::filesystem::remove(fname); + remove(fname); //fprintf(stderr,"extracted.(%s)\n",str); for (i=0; i Date: Sun, 3 Mar 2019 21:40:04 -1100 Subject: [PATCH 05/56] Remove .pack --- src/cc/rogue_rpc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 7bd7a160a..f765a17b9 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1138,7 +1138,9 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,rogueaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); } } - //fprintf(stderr,"no keys rogue_extractgame %s\n",gametxid.GetHex().c_str()); + sprintf(fname,"rogue.%llu.pack",(long long)seed); + remove(fname); + //fprintf(stderr,"no keys rogue_extractgame %s\n",gametxid.GetHex().c_str()); return(-1); } From 1d048ad5fc26441774fab6f27e51d46d9dbd249e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Mar 2019 21:56:17 -1100 Subject: [PATCH 06/56] Disable passkeys --- src/cc/rogue/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 5e79e399e..6b466e9a0 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -765,7 +765,7 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * } // extract and get keystrokes field and compare it to pastkeys // if not matching... panic? - if ( (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) + if ( 0 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) { free(pastkeys); } From 2188a603186e35670493cba8b97688523b0f6878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Mar 2019 23:58:08 -1100 Subject: [PATCH 07/56] Rvalidate --- src/cc/CCinclude.h | 1 + src/cc/cclib.cpp | 25 ++++++++++ src/cc/dilithium.c | 119 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 136 insertions(+), 9 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 91e9467dd..f5877c711 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -201,6 +201,7 @@ CScript EncodeTokenCreateOpRet(uint8_t funcid, std::vector origpubkey, CScript EncodeTokenImportOpRet(std::vector origpubkey, std::string name, std::string description, uint256 srctokenid, std::vector> oprets); CScript EncodeTokenOpRet(uint256 tokenid, std::vector voutPubkeys, std::pair opretWithId); CScript EncodeTokenOpRet(uint256 tokenid, std::vector voutPubkeys, std::vector> oprets); +int64_t AddCClibtxfee(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk); uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description); uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description, std::vector> &oprets); uint8_t DecodeTokenImportOpRet(const CScript &scriptPubKey, std::vector &origpubkey, std::string &name, std::string &description, uint256 &srctokenid, std::vector> &oprets); diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 121a16475..695ccd16b 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -504,6 +504,31 @@ int64_t AddCClibInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } +int64_t AddCClibtxfee(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk) +{ + char coinaddr[64]; int64_t txfee = 10000; uint256 txid,hashBlock; CTransaction vintx; int32_t vout; + 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; + //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f vs %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN,(double)threshold/COIN); + if ( it->second.satoshis < txfee ) + continue; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( (nValue= IsCClibvout(cp,vintx,vout,coinaddr)) != 0 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + return(it->second.satoshis); + } //else fprintf(stderr,"nValue %.8f too small or already spent in mempool\n",(double)nValue/COIN); + } else fprintf(stderr,"couldnt get tx\n"); + } + return(0); +} + std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index e36ea807e..4136b0bca 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2929,6 +2929,29 @@ int32_t main(void) void calc_rmd160_sha256(uint8_t rmd160[20],uint8_t *data,int32_t datalen); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); +struct dilithium_handle +{ + UT_hash_handle hh; + uint256 destpubtxid; + char handle[32]; +} *Dilithium_handles; + +struct dilithium_handle *dilithium_handlenew(std::string handle) +{ + struct dilithium_handle *hashstr = 0; + if ( handle.size() < sizeof(Dilithium_handles[0].handle)-1 ) + { + HASH_FIND(hh,Dilithium_handles,handle,(int32_t)handle.size(),hashstr); + if ( hashstr == 0 ) + { + hashstr = calloc(1,sizeof(*hashstr)); + strncpy(hashstr->handle,handle.c_str(),sizeof(hashstr->handle)); + HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,(int32_t)handle.size(),hashstr); + } + } + return(hashstr); +} + int32_t dilithium_Qmsghash(uint8_t *msg,CTransaction tx,int32_t numvouts,std::vector voutpubtxids) { CScript data; uint256 hash; int32_t i,numvins,len = 0; std::vector vintxids; std::vector vinprevns; std::vector vouts; @@ -3110,12 +3133,20 @@ UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *para return(result); } +CPubKey Faucet_pubkeyget() +{ + struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_FAUCET); + return(GetUnspendable(cp,0)); +} + UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,dilithiumpk; uint8_t seed[SEEDBYTES],pk[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES]; char coinaddr[64],str[CRYPTO_SECRETKEYBYTES*2+1]; std::vector bigpub; int32_t i,n,warningflag = 0; + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey faucetpk,mypk,dilithiumpk; uint8_t seed[SEEDBYTES],pk[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES]; char coinaddr[64],str[CRYPTO_SECRETKEYBYTES*2+1]; int64_t CCchange,inputs; std::vector bigpub; int32_t i,n,warningflag = 0; if ( txfee == 0 ) txfee = DILITHIUM_TXFEE; + faucetpk = Faucet_pubkeyget(); mypk = pubkey2pk(Mypubkey()); dilithiumpk = GetUnspendable(cp,0); if ( params != 0 && ((n= cJSON_GetArraySize(params)) == 1 || n == 2) ) @@ -3132,14 +3163,23 @@ UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *par result.push_back(Pair("skaddr",dilithium_addr(coinaddr,sk,CRYPTO_SECRETKEYBYTES))); for (i=0; i= 3*txfee ) + if ( (inputs= AddCClibtxfee(cp,mtx,dilithiumpk)) > 0 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,dilithiumpk)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_registeropret(handle,mypk,bigpub)); - return(musig_rawtxresult(result,rawtx)); - } else return(cclib_error(result,"couldnt find enough funds")); - } else return(cclib_error(result,"not enough parameters")); + if ( inputs > txfee ) + CCchange = (inputs - txfee); + else CCchange = 0; + if ( AddNormalinputs(mtx,mypk,COIN+3*txfee,64) >= 3*txfee ) + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode,2*txfee,dilithiumpk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,COIN,faucetpk)); + if ( CCchange != 0 ) + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dilithiumpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_registeropret(handle,mypk,bigpub)); + return(musig_rawtxresult(result,rawtx)); + } else return(cclib_error(result,"couldnt find enough funds")); + } else return(cclib_error(result,"not enough parameters")); + } else return(cclib_error(result,"not dilithiumpk funds")); } UniValue dilithium_sign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) @@ -3452,6 +3492,65 @@ bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co } else return eval->Invalid("unexpected zero signerpubtxid"); } +bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) +{ + static int32_t didinit; + std::vector > txids; + uint256 txid,hashBlock; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CTransaction txi; CPubKey pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64]; + dilithiumpk = GetUnspendable(cp,0); + if ( didinit == 0 ) + { + GetCCaddress(cp,CCaddr,dilithiumpk); + SetCCtxids(txids,CCaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + txid = it->first.txhash; + if ( myGetTransaction(txid,txi,hashBlock) != 0 && (numvouts= txi.vout.size()) > 1 ) + { + if ( dilithium_registeropretdecode(handle,pub33,bigpub,txi.vout[numvouts-1].scriptPubKey) == 'R' ) + { + if ( (hashstr= dilithium_handlenew(handle)) != 0 ) + { + if ( hashstr->destpubtxid != txid ) + { + if ( hashstr->destpubtxid != zeroid ) + fprintf(stderr,"overwriting %s %s with %s\n",handle.c_str(),hashstr->destpubtxid.GetHex().c_str(),txid.GetHex().c_str()); + fprintf(stderr,"%s <- %s\n",handle.c_str(),txid.GetHex().c_str()); + hashstr->destpubtxid = txid; + } + } + } + } + } + didinit = 1; + } + if ( (numvouts= tx.vout.size()) <= 1 ) + return eval->Invalid("not enough vouts for registration tx"); + else if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) + { + // relies on all current block tx to be put into mempool + txid = tx.GetHash(); + vout0 = MakeCC1vout(cp->evalcode,2*DILITHIUM_TXFEE,dilithiumpk); + vout = MakeCC1vout(EVAL_FAUCET,COIN,Faucet_pubkeyget()); + if ( tx.vout[0] != vout0 ) + return eval->Invalid("mismatched vout0 for register"); + else if ( tx.vout[1].nValue != DILITHIUM_TXFEE ) + return eval->Invalid("vout1 for register not txfee"); + else if ( tx.vout[2] != vout ) + return eval->Invalid("register not sending to faucet"); + else if ( (hashstr= dilithium_handlenew(handle)) == 0 ) + return eval->Invalid("error creating dilithium handle"); + else if ( hashstr->destpubtxid == zeroid ) + { + hashstr->destpubtxid = txid; + return(true); + } + else if ( hashstr->destpubtxid == txid ) + return(true); + else return eval->Invalid("duplicate dilithium handle rejected"); + } else return eval->Invalid("couldnt decode register opret"); +} + bool dilithium_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { CPubKey destpub33; std::string handle; uint256 hashBlock,destpubtxid,checktxid; CTransaction vintx; int32_t numvouts,mlen,smlen=CRYPTO_BYTES+32; std::vector sig,vopret; uint8_t msg[32],msg2[CRYPTO_BYTES+32],pk[CRYPTO_PUBLICKEYBYTES],*script; @@ -3459,7 +3558,9 @@ bool dilithium_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,con numvouts = tx.vout.size(); GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); script = (uint8_t *)vopret.data(); - if ( script[1] == 'Q' ) + if ( script[1] == 'R' ) + return(dilithium_Rvalidate(cp,height,eval,tx)); + else if ( script[1] == 'Q' ) return(dilithium_Qvalidate(cp,height,eval,tx)); else if ( tx.vout.size() != 2 ) return eval->Invalid("numvouts != 2"); From d6534d9069a286563e5549f96d9cd3e31149d328 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Mar 2019 23:59:55 -1100 Subject: [PATCH 08/56] Syntax --- src/cc/cclib.cpp | 2 +- src/cc/dilithium.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 695ccd16b..3a6fba108 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -506,7 +506,7 @@ int64_t AddCClibInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK int64_t AddCClibtxfee(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk) { - char coinaddr[64]; int64_t txfee = 10000; uint256 txid,hashBlock; CTransaction vintx; int32_t vout; + char coinaddr[64]; int64_t nValue,txfee = 10000; uint256 txid,hashBlock; CTransaction vintx; int32_t vout; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 4136b0bca..8cfc85028 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2941,10 +2941,10 @@ struct dilithium_handle *dilithium_handlenew(std::string handle) struct dilithium_handle *hashstr = 0; if ( handle.size() < sizeof(Dilithium_handles[0].handle)-1 ) { - HASH_FIND(hh,Dilithium_handles,handle,(int32_t)handle.size(),hashstr); + HASH_FIND(hh,Dilithium_handles,handle.c_str(),(int32_t)handle.size(),hashstr); if ( hashstr == 0 ) { - hashstr = calloc(1,sizeof(*hashstr)); + hashstr = (struct dilithium_handle *)calloc(1,sizeof(*hashstr)); strncpy(hashstr->handle,handle.c_str(),sizeof(hashstr->handle)); HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,(int32_t)handle.size(),hashstr); } From e8982c5f17af04b4a621628ba09e8d68184867ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 00:12:44 -1100 Subject: [PATCH 09/56] Allow overwrite by same pub33 --- src/cc/dilithium.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 8cfc85028..9bf337c2a 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3492,6 +3492,17 @@ bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co } else return eval->Invalid("unexpected zero signerpubtxid"); } +int32_t dilithium_registrationpub33(CPubKey &pub33,uint256 txid) +{ + std::string handle; std::vector bigpub; + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) + { + if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) + return(0); + } + return(-1); +} + bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static int32_t didinit; @@ -3545,8 +3556,16 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co hashstr->destpubtxid = txid; return(true); } - else if ( hashstr->destpubtxid == txid ) - return(true); + else + { + if ( hashstr->destpubtxid == txid ) + return(true); + else if ( dilithium_registrationpub33(oldpub33,hashstr->destpubtxid) == 0 ) + { + if ( oldpub33 == pub33 ) + return(true); + } else return eval->Invalid("duplicate dilithium handle rejected"); + } else return eval->Invalid("duplicate dilithium handle rejected"); } else return eval->Invalid("couldnt decode register opret"); } From d28fa50d9ba37dc30fcfe027431bf9cc78c52a1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 00:13:30 -1100 Subject: [PATCH 10/56] Tx --- src/cc/dilithium.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 9bf337c2a..7fab10faf 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3494,7 +3494,7 @@ bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co int32_t dilithium_registrationpub33(CPubKey &pub33,uint256 txid) { - std::string handle; std::vector bigpub; + std::string handle; std::vector bigpub; CTransaction tx; if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) From 905868c6c145109171ac26a6bb3b19f07b19f2f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 00:14:15 -1100 Subject: [PATCH 11/56] Declare variables --- src/cc/dilithium.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 7fab10faf..51f4c9510 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3494,7 +3494,7 @@ bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co int32_t dilithium_registrationpub33(CPubKey &pub33,uint256 txid) { - std::string handle; std::vector bigpub; CTransaction tx; + std::string handle; std::vector bigpub; CTransaction tx; uint256 hashBlock; int32_t numvouts; if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) @@ -3507,7 +3507,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co { static int32_t didinit; std::vector > txids; - uint256 txid,hashBlock; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CTransaction txi; CPubKey pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64]; + uint256 txid,hashBlock; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CTransaction txi; CPubKey oldpub33,pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64]; dilithiumpk = GetUnspendable(cp,0); if ( didinit == 0 ) { From 94b32af9645369c9f96f86b82466e207fb48e9db Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 00:15:04 -1100 Subject: [PATCH 12/56] Allow replacement handle --- src/cc/dilithium.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 51f4c9510..d7b59f54c 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3564,9 +3564,9 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co { if ( oldpub33 == pub33 ) return(true); - } else return eval->Invalid("duplicate dilithium handle rejected"); + } + return eval->Invalid("duplicate dilithium handle rejected"); } - else return eval->Invalid("duplicate dilithium handle rejected"); } else return eval->Invalid("couldnt decode register opret"); } From f53e6c02b3f18eacd2150c63da2995218c3342a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 00:18:28 -1100 Subject: [PATCH 13/56] Grandfather existing handles --- src/cc/dilithium.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index d7b59f54c..4a181e7c5 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3508,6 +3508,8 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co static int32_t didinit; std::vector > txids; uint256 txid,hashBlock; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CTransaction txi; CPubKey oldpub33,pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64]; + if ( height < 14500 ) + return(true); dilithiumpk = GetUnspendable(cp,0); if ( didinit == 0 ) { From c5032f46df0e7c6a8d8a1200c4b7ab7245f6e31e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 00:59:44 -1100 Subject: [PATCH 14/56] Test --- src/cc/dilithium.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 4a181e7c5..a82113ebc 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3527,8 +3527,8 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co if ( hashstr->destpubtxid != txid ) { if ( hashstr->destpubtxid != zeroid ) - fprintf(stderr,"overwriting %s %s with %s\n",handle.c_str(),hashstr->destpubtxid.GetHex().c_str(),txid.GetHex().c_str()); - fprintf(stderr,"%s <- %s\n",handle.c_str(),txid.GetHex().c_str()); + fprintf(stderr,"ht.%d overwriting %s %s with %s\n",height,handle.c_str(),hashstr->destpubtxid.GetHex().c_str(),txid.GetHex().c_str()); + fprintf(stderr,"ht.%d %s <- %s\n",height,handle.c_str(),txid.GetHex().c_str()); hashstr->destpubtxid = txid; } } @@ -3565,7 +3565,11 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co else if ( dilithium_registrationpub33(oldpub33,hashstr->destpubtxid) == 0 ) { if ( oldpub33 == pub33 ) + { + hashstr->destpubtxid = txid; + fprintf(stderr,"ht.%d %s <- %s\n",height,handle.c_str(),txid.GetHex().c_str()); return(true); + } } return eval->Invalid("duplicate dilithium handle rejected"); } From 08318626f353c2b0985ef87975de0348ff3ec21d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 01:17:04 -1100 Subject: [PATCH 15/56] Handleinfo --- src/cc/cclib.cpp | 4 ++++ src/cc/dilithium.c | 51 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 3a6fba108..651723e44 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -83,6 +83,7 @@ CClib_methods[] = { (char *)"musig", (char *)"spend", (char *)"sendtxid sig scriptPubKey", 3, 3, 'y', EVAL_MUSIG }, { (char *)"dilithium", (char *)"keypair", (char *)"[hexseed]", 0, 1, 'K', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"register", (char *)"handle, [hexseed]", 1, 2, 'R', EVAL_DILITHIUM }, + { (char *)"dilithium", (char *)"handleinfo", (char *)"handle", 1, 1, 'I', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"sign", (char *)"msg [hexseed]", 1, 2, 'S', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"verify", (char *)"pubtxid msg sig", 3, 3, 'V', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"send", (char *)"handle pubtxid amount", 3, 3, 'x', EVAL_DILITHIUM }, @@ -130,6 +131,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); bool dilithium_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue dilithium_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue dilithium_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); @@ -273,6 +275,8 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) return(dilithium_keypair(txfee,cp,params)); else if ( strcmp(method,"register") == 0 ) return(dilithium_register(txfee,cp,params)); + else if ( strcmp(method,"handleinfo") == 0 ) + return(dilithium_handleinfo(txfee,cp,params)); else if ( strcmp(method,"sign") == 0 ) return(dilithium_sign(txfee,cp,params)); else if ( strcmp(method,"verify") == 0 ) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index a82113ebc..5f79e2e50 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2936,22 +2936,30 @@ struct dilithium_handle char handle[32]; } *Dilithium_handles; -struct dilithium_handle *dilithium_handlenew(std::string handle) +struct dilithium_handle *dilithium_handlenew(char *handle) { - struct dilithium_handle *hashstr = 0; - if ( handle.size() < sizeof(Dilithium_handles[0].handle)-1 ) + struct dilithium_handle *hashstr = 0; int32_t len = (int32_t)strlen(handle); + if ( len < sizeof(Dilithium_handles[0].handle)-1 ) { - HASH_FIND(hh,Dilithium_handles,handle.c_str(),(int32_t)handle.size(),hashstr); + HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); if ( hashstr == 0 ) { hashstr = (struct dilithium_handle *)calloc(1,sizeof(*hashstr)); - strncpy(hashstr->handle,handle.c_str(),sizeof(hashstr->handle)); - HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,(int32_t)handle.size(),hashstr); + strncpy(hashstr->handle,handle,sizeof(hashstr->handle)); + HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,len,hashstr); } } return(hashstr); } +struct dilithium_handle *dilithium_handlefind(char *handle) +{ + struct dilithium_handle *hashstr = 0; int32_t len = (int32_t)strlen(handle); + if ( len < sizeof(Dilithium_handles[0].handle)-1 ) + HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); + return(hashstr); +} + int32_t dilithium_Qmsghash(uint8_t *msg,CTransaction tx,int32_t numvouts,std::vector voutpubtxids) { CScript data; uint256 hash; int32_t i,numvins,len = 0; std::vector vintxids; std::vector vinprevns; std::vector vouts; @@ -3503,6 +3511,33 @@ int32_t dilithium_registrationpub33(CPubKey &pub33,uint256 txid) return(-1); } +UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); CPubKey pub33; int32_t i,n; char *handlestr,str[67]; struct dilithium_handle *hashstr; + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) + { + if ( (handlestr= jstr(jitem(params,0),0)) != 0 ) + { + result.push_back(Pair("result","success")); + result.push_back(Pair("handle",handlestr)); + if ( (hashstr= dilithium_handlefind(handlestr)) != 0 ) + { + result.push_back(Pair("destpubtxid",hashstr->destpubtxid.GetHex().c_str())); + if ( dilithium_registrationpub33(pub33,hashstr->destpubtxid) == 0 ) + { + for (i=0; i<33; i++) + sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.data())[i]); + str[i<<1] = 0; + } + result.push_back(Pair("pubkey",str)); + } else result.push_back(Pair("status","available")); + return(result); + } + } + result.push_back(Pair("result","error")); + return(result); +} + bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static int32_t didinit; @@ -3522,7 +3557,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co { if ( dilithium_registeropretdecode(handle,pub33,bigpub,txi.vout[numvouts-1].scriptPubKey) == 'R' ) { - if ( (hashstr= dilithium_handlenew(handle)) != 0 ) + if ( (hashstr= dilithium_handlenew(handle.c_str())) != 0 ) { if ( hashstr->destpubtxid != txid ) { @@ -3551,7 +3586,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co return eval->Invalid("vout1 for register not txfee"); else if ( tx.vout[2] != vout ) return eval->Invalid("register not sending to faucet"); - else if ( (hashstr= dilithium_handlenew(handle)) == 0 ) + else if ( (hashstr= dilithium_handlenew(handle.c_str())) == 0 ) return eval->Invalid("error creating dilithium handle"); else if ( hashstr->destpubtxid == zeroid ) { From be402b768464dcd9792de625eb2d00d7da46b0e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 01:18:19 -1100 Subject: [PATCH 16/56] Char * --- src/cc/dilithium.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 5f79e2e50..80502687d 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3526,7 +3526,7 @@ UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *p if ( dilithium_registrationpub33(pub33,hashstr->destpubtxid) == 0 ) { for (i=0; i<33; i++) - sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.data())[i]); + sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.ptr())[i]); str[i<<1] = 0; } result.push_back(Pair("pubkey",str)); @@ -3557,7 +3557,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co { if ( dilithium_registeropretdecode(handle,pub33,bigpub,txi.vout[numvouts-1].scriptPubKey) == 'R' ) { - if ( (hashstr= dilithium_handlenew(handle.c_str())) != 0 ) + if ( (hashstr= dilithium_handlenew((char *)handle.c_str())) != 0 ) { if ( hashstr->destpubtxid != txid ) { @@ -3586,7 +3586,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co return eval->Invalid("vout1 for register not txfee"); else if ( tx.vout[2] != vout ) return eval->Invalid("register not sending to faucet"); - else if ( (hashstr= dilithium_handlenew(handle.c_str())) == 0 ) + else if ( (hashstr= dilithium_handlenew((char *)handle.c_str())) == 0 ) return eval->Invalid("error creating dilithium handle"); else if ( hashstr->destpubtxid == zeroid ) { From 3e22ce7bc77848e1d5d9b650ab4621d76c6f60d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 01:19:08 -1100 Subject: [PATCH 17/56] Begin --- src/cc/dilithium.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 80502687d..a35de9a2c 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3526,7 +3526,7 @@ UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *p if ( dilithium_registrationpub33(pub33,hashstr->destpubtxid) == 0 ) { for (i=0; i<33; i++) - sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.ptr())[i]); + sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.begin())[i]); str[i<<1] = 0; } result.push_back(Pair("pubkey",str)); From 6773dfcbb29c50dc17a426e408dcf7f27e7bf6ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 02:19:21 -1100 Subject: [PATCH 18/56] Add mutex --- src/cc/dilithium.c | 85 +++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index a35de9a2c..6ca4a64eb 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2936,11 +2936,14 @@ struct dilithium_handle char handle[32]; } *Dilithium_handles; +pthread_mutex_t DILITHIUM_MUTEX; + struct dilithium_handle *dilithium_handlenew(char *handle) { struct dilithium_handle *hashstr = 0; int32_t len = (int32_t)strlen(handle); if ( len < sizeof(Dilithium_handles[0].handle)-1 ) { + pthread_mutex_lock(&DILITHIUM_MUTEX); HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); if ( hashstr == 0 ) { @@ -2948,6 +2951,7 @@ struct dilithium_handle *dilithium_handlenew(char *handle) strncpy(hashstr->handle,handle,sizeof(hashstr->handle)); HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,len,hashstr); } + pthread_mutex_unlock(&DILITHIUM_MUTEX); } return(hashstr); } @@ -2956,7 +2960,11 @@ struct dilithium_handle *dilithium_handlefind(char *handle) { struct dilithium_handle *hashstr = 0; int32_t len = (int32_t)strlen(handle); if ( len < sizeof(Dilithium_handles[0].handle)-1 ) + { + pthread_mutex_lock(&DILITHIUM_MUTEX); HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); + pthread_mutex_unlock(&DILITHIUM_MUTEX); + } return(hashstr); } @@ -3500,22 +3508,60 @@ bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co } else return eval->Invalid("unexpected zero signerpubtxid"); } -int32_t dilithium_registrationpub33(CPubKey &pub33,uint256 txid) +int32_t dilithium_registrationpub33(char *pkaddr,CPubKey &pub33,uint256 txid) { std::string handle; std::vector bigpub; CTransaction tx; uint256 hashBlock; int32_t numvouts; + pkaddr[0] = 0; if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) { if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) + { + dilithium_addr(pkaddr,&bigpub[0],CRYPTO_PUBLICKEYBYTES); return(0); + } } return(-1); } +void dilithium_handleinit(struct CCcontract_info *cp) +{ + static int32_t didinit; + std::vector > txids; struct dilithium_handle *hashstr; CPubKey dilithiumpk,pub33; uint256 txid,hashBlock; CTransaction txi; int32_t numvouts; std::vector bigpub; std::string handle; + if ( didinit != 0 ) + return; + pthread_mutex_init(&DILITHIUM_MUTEX,NULL); + dilithiumpk = GetUnspendable(cp,0); + GetCCaddress(cp,CCaddr,dilithiumpk); + SetCCtxids(txids,CCaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + txid = it->first.txhash; + if ( myGetTransaction(txid,txi,hashBlock) != 0 && (numvouts= txi.vout.size()) > 1 ) + { + if ( dilithium_registeropretdecode(handle,pub33,bigpub,txi.vout[numvouts-1].scriptPubKey) == 'R' ) + { + if ( (hashstr= dilithium_handlenew((char *)handle.c_str())) != 0 ) + { + if ( hashstr->destpubtxid != txid ) + { + if ( hashstr->destpubtxid != zeroid ) + fprintf(stderr,"overwriting %s %s with %s\n",handle.c_str(),hashstr->destpubtxid.GetHex().c_str(),txid.GetHex().c_str()); + fprintf(stderr,"%s <- %s\n",handle.c_str(),txid.GetHex().c_str()); + hashstr->destpubtxid = txid; + } + } + } + } + } + didinit = 1; +} + UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - UniValue result(UniValue::VOBJ); CPubKey pub33; int32_t i,n; char *handlestr,str[67]; struct dilithium_handle *hashstr; + UniValue result(UniValue::VOBJ); CPubKey pub33; int32_t i,n; char *handlestr,pkaddr[64],str[67]; struct dilithium_handle *hashstr; if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) { + dilithium_handleinit(cp); if ( (handlestr= jstr(jitem(params,0),0)) != 0 ) { result.push_back(Pair("result","success")); @@ -3523,11 +3569,12 @@ UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *p if ( (hashstr= dilithium_handlefind(handlestr)) != 0 ) { result.push_back(Pair("destpubtxid",hashstr->destpubtxid.GetHex().c_str())); - if ( dilithium_registrationpub33(pub33,hashstr->destpubtxid) == 0 ) + if ( dilithium_registrationpub33(pkaddr,pub33,hashstr->destpubtxid) == 0 ) { for (i=0; i<33; i++) sprintf(&str[i<<1],"%02x",((uint8_t *)pub33.begin())[i]); str[i<<1] = 0; + result.push_back(Pair("pkaddr",pkaddr)); } result.push_back(Pair("pubkey",str)); } else result.push_back(Pair("status","available")); @@ -3541,37 +3588,11 @@ UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *p bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static int32_t didinit; - std::vector > txids; - uint256 txid,hashBlock; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CTransaction txi; CPubKey oldpub33,pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64]; + uint256 txid; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CPubKey oldpub33,pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64],pkaddr[64]; if ( height < 14500 ) return(true); + dilithium_handleinit(cp); dilithiumpk = GetUnspendable(cp,0); - if ( didinit == 0 ) - { - GetCCaddress(cp,CCaddr,dilithiumpk); - SetCCtxids(txids,CCaddr); - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) - { - txid = it->first.txhash; - if ( myGetTransaction(txid,txi,hashBlock) != 0 && (numvouts= txi.vout.size()) > 1 ) - { - if ( dilithium_registeropretdecode(handle,pub33,bigpub,txi.vout[numvouts-1].scriptPubKey) == 'R' ) - { - if ( (hashstr= dilithium_handlenew((char *)handle.c_str())) != 0 ) - { - if ( hashstr->destpubtxid != txid ) - { - if ( hashstr->destpubtxid != zeroid ) - fprintf(stderr,"ht.%d overwriting %s %s with %s\n",height,handle.c_str(),hashstr->destpubtxid.GetHex().c_str(),txid.GetHex().c_str()); - fprintf(stderr,"ht.%d %s <- %s\n",height,handle.c_str(),txid.GetHex().c_str()); - hashstr->destpubtxid = txid; - } - } - } - } - } - didinit = 1; - } if ( (numvouts= tx.vout.size()) <= 1 ) return eval->Invalid("not enough vouts for registration tx"); else if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) @@ -3597,7 +3618,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co { if ( hashstr->destpubtxid == txid ) return(true); - else if ( dilithium_registrationpub33(oldpub33,hashstr->destpubtxid) == 0 ) + else if ( dilithium_registrationpub33(pkaddr,oldpub33,hashstr->destpubtxid) == 0 ) { if ( oldpub33 == pub33 ) { From 3af9fd9af46b9c9bcc85ce1c054f9e50b845accc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 02:20:17 -1100 Subject: [PATCH 19/56] CCaddr --- src/cc/dilithium.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 6ca4a64eb..b92102f22 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3526,7 +3526,7 @@ int32_t dilithium_registrationpub33(char *pkaddr,CPubKey &pub33,uint256 txid) void dilithium_handleinit(struct CCcontract_info *cp) { static int32_t didinit; - std::vector > txids; struct dilithium_handle *hashstr; CPubKey dilithiumpk,pub33; uint256 txid,hashBlock; CTransaction txi; int32_t numvouts; std::vector bigpub; std::string handle; + std::vector > txids; struct dilithium_handle *hashstr; CPubKey dilithiumpk,pub33; uint256 txid,hashBlock; CTransaction txi; int32_t numvouts; std::vector bigpub; std::string handle; char CCaddr[64]; if ( didinit != 0 ) return; pthread_mutex_init(&DILITHIUM_MUTEX,NULL); @@ -3588,7 +3588,7 @@ UniValue dilithium_handleinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *p bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static int32_t didinit; - uint256 txid; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CPubKey oldpub33,pub33,dilithiumpk; CTxOut vout,vout0; char CCaddr[64],pkaddr[64]; + uint256 txid; int32_t numvouts; struct dilithium_handle *hashstr; std::string handle; std::vector bigpub; CPubKey oldpub33,pub33,dilithiumpk; CTxOut vout,vout0; char pkaddr[64]; if ( height < 14500 ) return(true); dilithium_handleinit(cp); From 8e89c783d4ce66cf419ddd8f3eefef50ab2c4a28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Mar 2019 03:22:51 -1100 Subject: [PATCH 20/56] Casts for windows --- src/wallet/wallet.cpp | 4 ++-- src/wallet/walletdb.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 9cf2a86cb..1208a77f2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1825,12 +1825,12 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl fprintf(stderr, "Received transaction to address other than notary address, ignored! \n"); return false; } - fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,numvoutIsOurs); + fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,(int32_t)numvoutIsOurs); // here we add calculation for number if vouts received, average size and determine if we accept them to wallet or not. int64_t avgVoutSize = totalvoutvalue / numvoutIsOurs; if ( avgVoutSize < MIN_RECV_SATS ) { // average vout size is less than set minimum, default is 1 coin, we will ignore it - fprintf(stderr, "ignored: %d vouts average size of %ld sats.\n",numvoutIsOurs, avgVoutSize); + fprintf(stderr, "ignored: %d vouts average size of %ld sats.\n",numvoutIsOurs, (long)avgVoutSize); return false; } } diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 972b2cdf4..83a79821f 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -965,7 +965,7 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) reAdded++; } } - fprintf(stderr, "Cleared %lu corrupted transactions from wallet. Readded %i known transactions.\n",deadTxns.size(),reAdded); + fprintf(stderr, "Cleared %lu corrupted transactions from wallet. Readded %i known transactions.\n",(long)deadTxns.size(),reAdded); deadTxns.clear(); } From dbb33e694984e1284d6fae65d47cba233a2ffc51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:16:30 -1100 Subject: [PATCH 21/56] +debugs --- src/cc/rogue/list.c | 96 ++++++++++++++++++++++++-------------------- src/cc/rogue/main.c | 21 +++++++++- src/cc/rogue/rogue.c | 2 +- src/cc/rogue/rogue.h | 1 + src/cc/rogue/state.c | 6 +++ 5 files changed, 81 insertions(+), 45 deletions(-) diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 622af60cd..59abef98c 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -19,6 +19,58 @@ int total = 0; /* total dynamic memory bytes */ #endif +/* + * discard: + * Free up an item + */ + +int32_t itemcounter; +THING *thingptrs[100000]; +int32_t numptrs; + +int32_t thing_find(THING *ptr) +{ + for (i=0; i_t._t_type,thingptrs[i]->o_type,thingptrs[i]->o_type); + free(thingptrs[i]); + } + memset(thingptrs,0,sizeof(thingptrs)); + numptrs = 0; +} + /* * detach: * takes an item out of whatever linked list it might be in @@ -77,49 +129,7 @@ _free_list(THING **ptr) } } -/* - * discard: - * Free up an item - */ -int32_t itemcounter; -THING *thingptrs[100000]; -int32_t numptrs; - -void -discard(THING *item) -{ -#ifdef MASTER - total--; -#endif - if ( 0 ) - { - int32_t i; - for (i=0; i_t._t_type,thingptrs[i]->o_type,thingptrs[i]->o_type); - free(thingptrs[i]); - } - memset(thingptrs,0,sizeof(thingptrs)); - numptrs = 0; -} /* * new_item @@ -139,7 +149,7 @@ new_item(void) #else item = (THING *)calloc(1, sizeof *item); #endif - if ( 0 ) + if ( 1 ) { thingptrs[numptrs++] = item; if ( (++itemcounter % 100) == 0 ) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 6b466e9a0..d58e45e47 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -742,7 +742,7 @@ int32_t rogue_sendrawtransaction(char *rawtx) void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) { - char cmd[16384],hexstr[16384],params[32768],*retstr,*rawtx,*pastkeys; int32_t i,numpastkeys; cJSON *retjson; + char cmd[16384],hexstr[16384],params[32768],*retstr,*rawtx,*pastkeys,*pastcmp,*keys; int32_t i,len,numpastkeys; cJSON *retjson; //fprintf(stderr,"rogue_progress num.%d\n",num); if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) { @@ -767,6 +767,25 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * // if not matching... panic? if ( 0 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) { + sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); + if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (keys= jstr(retjson,"keystrokes")) != 0 ) + { + len = strlen(keys) / 2; + pastcmp = (char *)malloc(len + 1) + decode_hex(pastcmp,len,keys); + if ( len != numpastkeys || memcmp(pastcmp,pastkeys,len) != 0 ) + { + fprintf(stderr,"pastcmp[%d] != pastkeys[%d]?\n",len,numpastkeys); + } + free(pastcmp); + } + free_json(retjson); + } + } free(pastkeys); } diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 478e3d2ed..5e5a66e06 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -286,7 +286,7 @@ char *rogue_keystrokesload(int32_t *numkeysp,uint64_t seed,int32_t counter) fclose(fp); num += fsize; counter++; - fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); + //fprintf(stderr,"loaded %ld from (%s) total %d\n",fsize,fname,num); } *numkeysp = num; return(keystrokes); diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 8c1101fc6..ba57adbe6 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -824,6 +824,7 @@ void doctor(struct rogue_state *rs,int); void playit(struct rogue_state *rs); struct room *roomin(struct rogue_state *rs,coord *cp); +int32_t thing_find(THING *ptr); #define MAXDAEMONS 20 diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index b0176a042..b649e32ee 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1429,6 +1429,11 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) struct rogue_packitem *item; if (write_error) return(WRITESTAT); + if ( thing_find(o) < 0 ) + { + fprintf(stderr,"cant find thing.%p in list\n",o); + return(0); + } if ( o->_o._o_packch != 0 ) { item = &rs->P.roguepack[rs->P.packsize]; @@ -1478,6 +1483,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) rs_write_int(savef, o->_o._o_flags); rs_write_int(savef, o->_o._o_group); rs_write_string(savef, o->_o._o_label); + fprintf(stderr,"label.%p\n",o->_o._o_label); return(WRITESTAT); } From ead3aefd44cbdbb48f941bfb2d2534fd9262a844 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:19:12 -1100 Subject: [PATCH 22/56] Syntax --- src/cc/rogue/list.c | 1 + src/cc/rogue/main.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 59abef98c..2700d9948 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -30,6 +30,7 @@ int32_t numptrs; int32_t thing_find(THING *ptr) { + int32_t i; for (i=0; i Date: Wed, 6 Mar 2019 00:19:49 -1100 Subject: [PATCH 23/56] Item --- src/cc/rogue/list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 2700d9948..40f141861 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -28,7 +28,7 @@ int32_t itemcounter; THING *thingptrs[100000]; int32_t numptrs; -int32_t thing_find(THING *ptr) +int32_t thing_find(THING *item) { int32_t i; for (i=0; i Date: Wed, 6 Mar 2019 00:22:33 -1100 Subject: [PATCH 24/56] Skeet --- src/cc/rogue/state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index b649e32ee..54188cec0 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1431,7 +1431,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) return(WRITESTAT); if ( thing_find(o) < 0 ) { - fprintf(stderr,"cant find thing.%p in list\n",o); + fprintf(stderr,"cant find thing.%p in list\n",o); sleep(3); return(0); } if ( o->_o._o_packch != 0 ) From b92ff12efea38d6de9af76a79b30079079a60320 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:26:51 -1100 Subject: [PATCH 25/56] +print --- src/cc/rogue/state.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index 54188cec0..f0ce015cd 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1431,7 +1431,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) return(WRITESTAT); if ( thing_find(o) < 0 ) { - fprintf(stderr,"cant find thing.%p in list\n",o); sleep(3); + fprintf(stderr,"cant find thing.%p (%s) in list\n",o,inv_name(o,FALSE)); sleep(3); return(0); } if ( o->_o._o_packch != 0 ) @@ -1483,7 +1483,6 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) rs_write_int(savef, o->_o._o_flags); rs_write_int(savef, o->_o._o_group); rs_write_string(savef, o->_o._o_label); - fprintf(stderr,"label.%p\n",o->_o._o_label); return(WRITESTAT); } From 5c46f7488eb7cb89dea5044968e0360d6ed66789 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:36:43 -1100 Subject: [PATCH 26/56] Error check things --- src/cc/rogue/list.c | 16 +++++++++++++--- src/cc/rogue/pack.c | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 40f141861..68d889d8b 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -24,17 +24,24 @@ int total = 0; /* total dynamic memory bytes */ * Free up an item */ +#define ENABLE_DEBUG +#define MAX_DEBUGPTRS 100000 + int32_t itemcounter; -THING *thingptrs[100000]; +THING *thingptrs[MAX_DEBUGPTRS]; int32_t numptrs; int32_t thing_find(THING *item) { +#ifdef ENABLE_DEBUG int32_t i; for (i=0; il_next = NULL; item->l_prev = NULL; return item; diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index 362c65412..8ad899c7b 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -466,7 +466,14 @@ get_item(struct rogue_state *rs,char *purpose, int type) return NULL; } else + { + if ( thing_find(obj) < 0 ) + { + fprintf(stderr,"cant find thing.%p in list\n",obj); sleep(3); + return(NULL); + } return obj; + } } } return NULL; From 26078cf4abd3ce46603bb952c82e778ff8cd2a8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:41:27 -1100 Subject: [PATCH 27/56] +prints --- src/cc/rogue/pack.c | 2 +- src/cc/rogue/state.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index 8ad899c7b..a43a7dcb5 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -467,7 +467,7 @@ get_item(struct rogue_state *rs,char *purpose, int type) } else { - if ( thing_find(obj) < 0 ) + if ( 0 && thing_find(obj) < 0 ) { fprintf(stderr,"cant find thing.%p in list\n",obj); sleep(3); return(NULL); diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index f0ce015cd..25bb2e461 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1734,6 +1734,7 @@ rs_write_thing(struct rogue_state *rs,FILE *savef, THING *t) rs_write_short(savef, t->_t._t_flags); rs_write_stats(savef, &t->_t._t_stats); rs_write_room_reference(savef, t->_t._t_room); + fprintf(stderr,"pack\n"); rs_write_object_list(rs,savef, t->_t._t_pack); //fprintf(stderr,"%ld\n",ftell(savef)); @@ -2100,6 +2101,7 @@ rs_save_file(struct rogue_state *rs,FILE *savef) rs_write_coord(savef, oldpos); rs_write_coord(savef, stairs); rs_write_thing(rs,savef, &player); + fprintf(stderr,"references\n"); rs_write_object_reference(savef, player.t_pack, cur_armor); rs_write_object_reference(savef, player.t_pack, cur_ring[0]); rs_write_object_reference(savef, player.t_pack, cur_ring[1]); @@ -2107,7 +2109,9 @@ rs_save_file(struct rogue_state *rs,FILE *savef) rs_write_object_reference(savef, player.t_pack, l_last_pick); rs_write_object_reference(savef, player.t_pack, last_pick); + fprintf(stderr,"lvl_obj\n"); rs_write_object_list(rs,savef, lvl_obj); + fprintf(stderr,"mlist\n"); rs_write_thing_list(rs,savef, mlist); rs_write_places(savef,places,MAXLINES*MAXCOLS); From 0ee026a04727e8cb03bfa1c1c764de9282803bfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:47:15 -1100 Subject: [PATCH 28/56] -sleep --- src/cc/rogue/pack.c | 5 +++++ src/cc/rogue/state.c | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index a43a7dcb5..7de1fd7a5 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -280,6 +280,11 @@ inventory(struct rogue_state *rs,THING *list, int type) list->o_type != FOOD && list->o_type != AMULET) && !(type == R_OR_S && (list->o_type == RING || list->o_type == STICK))) continue; + if ( thing_find(list) < 0 ) + { + fprintf(stderr,"cant find thing.(%c) in pack\n",list->o_packch); + sleep(3); + } n_objs++; #ifdef MASTER if (!list->o_packch) diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index 25bb2e461..9963bbc9e 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1431,7 +1431,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) return(WRITESTAT); if ( thing_find(o) < 0 ) { - fprintf(stderr,"cant find thing.%p (%s) in list\n",o,inv_name(o,FALSE)); sleep(3); + fprintf(stderr,"cant find thing.%p (%s) in list\n",o,inv_name(o,FALSE)); //sleep(3); return(0); } if ( o->_o._o_packch != 0 ) @@ -1734,7 +1734,6 @@ rs_write_thing(struct rogue_state *rs,FILE *savef, THING *t) rs_write_short(savef, t->_t._t_flags); rs_write_stats(savef, &t->_t._t_stats); rs_write_room_reference(savef, t->_t._t_room); - fprintf(stderr,"pack\n"); rs_write_object_list(rs,savef, t->_t._t_pack); //fprintf(stderr,"%ld\n",ftell(savef)); @@ -2101,7 +2100,6 @@ rs_save_file(struct rogue_state *rs,FILE *savef) rs_write_coord(savef, oldpos); rs_write_coord(savef, stairs); rs_write_thing(rs,savef, &player); - fprintf(stderr,"references\n"); rs_write_object_reference(savef, player.t_pack, cur_armor); rs_write_object_reference(savef, player.t_pack, cur_ring[0]); rs_write_object_reference(savef, player.t_pack, cur_ring[1]); @@ -2109,9 +2107,7 @@ rs_save_file(struct rogue_state *rs,FILE *savef) rs_write_object_reference(savef, player.t_pack, l_last_pick); rs_write_object_reference(savef, player.t_pack, last_pick); - fprintf(stderr,"lvl_obj\n"); rs_write_object_list(rs,savef, lvl_obj); - fprintf(stderr,"mlist\n"); rs_write_thing_list(rs,savef, mlist); rs_write_places(savef,places,MAXLINES*MAXCOLS); From df13632747546607e46b6656032a1ff51d69491c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:51:52 -1100 Subject: [PATCH 29/56] Brute force inventory check --- src/cc/rogue/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index 54d7beb99..3bbb5fc53 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -25,7 +25,7 @@ command(struct rogue_state *rs) char *fp; THING *mp; static char countch, direction, newcount = FALSE; - +inventory(rs,pack, 0); if (on(player, ISHASTE)) ntimes++; /* From 8bb36334e4b39c687438a693694f0b2ece493603 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 00:53:04 -1100 Subject: [PATCH 30/56] Revert --- src/cc/rogue/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index 3bbb5fc53..5e3b56f02 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -25,7 +25,7 @@ command(struct rogue_state *rs) char *fp; THING *mp; static char countch, direction, newcount = FALSE; -inventory(rs,pack, 0); + if (on(player, ISHASTE)) ntimes++; /* From 8ce1f9dea1ec543663d5d511fe5907a0116783e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 01:10:45 -1100 Subject: [PATCH 31/56] num_packitems --- src/cc/rogue/command.c | 2 +- src/cc/rogue/pack.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index 5e3b56f02..affa08782 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -25,7 +25,7 @@ command(struct rogue_state *rs) char *fp; THING *mp; static char countch, direction, newcount = FALSE; - +num_packitems(rs); if (on(player, ISHASTE)) ntimes++; /* diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index 7de1fd7a5..e3b20a45d 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -163,6 +163,11 @@ int32_t num_packitems(struct rogue_state *rs) int32_t type = 0,n = 0,total = 0; for (; list != NULL; list = next(list)) { + if ( thing_find(list) < 0 ) + { + fprintf(stderr,"num_packitems cant find %p\n",list); + sleep(3); + } if ( list->o_packch != 0 ) { n++; From d3e077180d6982437c7616e9637938e8259dd801 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 01:18:07 -1100 Subject: [PATCH 32/56] Log file --- src/cc/rogue/command.c | 1 - src/cc/rogue/fight.c | 44 +++++++++++++++++++++++------------------- src/cc/rogue/io.c | 4 ++-- src/cc/rogue/pack.c | 33 ++++++++++++++++--------------- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index affa08782..84281c5a7 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -25,7 +25,6 @@ command(struct rogue_state *rs) char *fp; THING *mp; static char countch, direction, newcount = FALSE; -num_packitems(rs); if (on(player, ISHASTE)) ntimes++; /* diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 43474616e..95d7105b2 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -290,27 +290,31 @@ attack(struct rogue_state *rs,THING *mp) } when 'N': { - register THING *obj, *steal; - register int nobj; + register THING *obj, *steal; + register int nobj; + + /* + * Nymph's steal a magic item, look through the pack + * and pick out one we like. + */ + steal = NULL; + for (nobj = 0, obj = pack; obj != NULL; obj = next(obj)) + if (obj != cur_armor && obj != cur_weapon + && obj != cur_ring[LEFT] && obj != cur_ring[RIGHT] + && is_magic(obj) && rnd(++nobj) == 0) + steal = obj; + if (steal != NULL) + { + remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); + mp=NULL; + fprintf(stderr,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); - /* - * Nymph's steal a magic item, look through the pack - * and pick out one we like. - */ - steal = NULL; - for (nobj = 0, obj = pack; obj != NULL; obj = next(obj)) - if (obj != cur_armor && obj != cur_weapon - && obj != cur_ring[LEFT] && obj != cur_ring[RIGHT] - && is_magic(obj) && rnd(++nobj) == 0) - steal = obj; - if (steal != NULL) - { - remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); - mp=NULL; - leave_pack(rs,steal, FALSE, FALSE); - msg(rs,"she stole %s!", inv_name(steal, TRUE)); - discard(steal); - } + leave_pack(rs,steal, FALSE, FALSE); + msg(rs,"she stole %s!", inv_name(steal, TRUE)); + fprintf(stderr,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); + discard(steal); + fprintf(stderr,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); + } } otherwise: break; diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index 994f112e2..dbbdb2cc1 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -160,14 +160,14 @@ readchar(struct rogue_state *rs) if ( rs->ind < rs->numkeys ) { c = rs->keystrokes[rs->ind++]; - if ( 0 ) + if ( 1 ) { static FILE *fp; static int32_t counter; if ( fp == 0 ) fp = fopen("log","wb"); if ( fp != 0 ) { - fprintf(fp,"%d: (%c) hp.%d\n",counter,c,pstats.s_hpt); + fprintf(fp,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); fflush(fp); counter++; } diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index e3b20a45d..d49f6aa02 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -167,6 +167,7 @@ int32_t num_packitems(struct rogue_state *rs) { fprintf(stderr,"num_packitems cant find %p\n",list); sleep(3); + return(-1); } if ( list->o_packch != 0 ) { @@ -224,29 +225,29 @@ THING * leave_pack(struct rogue_state *rs,THING *obj, bool newobj, bool all) { THING *nobj; - + inpack--; nobj = obj; if (obj->o_count > 1 && !all) { - last_pick = obj; - obj->o_count--; - if (obj->o_group) - inpack++; - if (newobj) - { - nobj = new_item(); - *nobj = *obj; - next(nobj) = NULL; - prev(nobj) = NULL; - nobj->o_count = 1; - } + last_pick = obj; + obj->o_count--; + if (obj->o_group) + inpack++; + if (newobj) + { + nobj = new_item(); + *nobj = *obj; + next(nobj) = NULL; + prev(nobj) = NULL; + nobj->o_count = 1; + } } else { - last_pick = NULL; - pack_used[obj->o_packch - 'a'] = FALSE; - detach(pack, obj); + last_pick = NULL; + pack_used[obj->o_packch - 'a'] = FALSE; + detach(pack, obj); } return nobj; } From 435535f3a6c378496c059617ce1a8f61cea6ca15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 01:21:07 -1100 Subject: [PATCH 33/56] Test --- src/cc/rogue/fight.c | 6 +++--- src/cc/rogue/io.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 95d7105b2..371431cd0 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -307,13 +307,13 @@ attack(struct rogue_state *rs,THING *mp) { remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); mp=NULL; - fprintf(stderr,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); + fprintf(stderr,"hp.%d num.%d\n",pstats.s_hpt,num_packitems(rs)); leave_pack(rs,steal, FALSE, FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); - fprintf(stderr,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); + fprintf(stderr," hp.%d num.%d\n",pstats.s_hpt,num_packitems(rs)); discard(steal); - fprintf(stderr,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); + fprintf(stderr," hp.%d num.%d\n",pstats.s_hpt,num_packitems(rs)); } } otherwise: diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index dbbdb2cc1..32f19bdb2 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -167,7 +167,7 @@ readchar(struct rogue_state *rs) fp = fopen("log","wb"); if ( fp != 0 ) { - fprintf(fp,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs);); + fprintf(fp,"%d: (%c) hp.%d num.%d\n",counter,c,pstats.s_hpt,num_packitems(rs)); fflush(fp); counter++; } From 5c5fc9ca4868a6b63d4fc651d9471942a07bb35a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 01:23:46 -1100 Subject: [PATCH 34/56] ABC --- src/cc/rogue/fight.c | 6 +++--- src/cc/rogue/pack.c | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 371431cd0..ba140205e 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -307,13 +307,13 @@ attack(struct rogue_state *rs,THING *mp) { remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); mp=NULL; - fprintf(stderr,"hp.%d num.%d\n",pstats.s_hpt,num_packitems(rs)); + fprintf(stderr,"hp.%d num.%d A\n",pstats.s_hpt,num_packitems(rs)); sleep(3); leave_pack(rs,steal, FALSE, FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); - fprintf(stderr," hp.%d num.%d\n",pstats.s_hpt,num_packitems(rs)); + fprintf(stderr," hp.%d num.%d B\n",pstats.s_hpt,num_packitems(rs)); sleep(3); discard(steal); - fprintf(stderr," hp.%d num.%d\n",pstats.s_hpt,num_packitems(rs)); + fprintf(stderr," hp.%d num.%d C\n",pstats.s_hpt,num_packitems(rs)); sleep(3); } } otherwise: diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index d49f6aa02..e7aa8874a 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -166,8 +166,6 @@ int32_t num_packitems(struct rogue_state *rs) if ( thing_find(list) < 0 ) { fprintf(stderr,"num_packitems cant find %p\n",list); - sleep(3); - return(-1); } if ( list->o_packch != 0 ) { From 4626a8dae9d15519ee95ce80488755fb5f2afc33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 01:27:56 -1100 Subject: [PATCH 35/56] Test --- src/cc/rogue/fight.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index ba140205e..4c9b61da6 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -307,13 +307,14 @@ attack(struct rogue_state *rs,THING *mp) { remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); mp=NULL; - fprintf(stderr,"hp.%d num.%d A\n",pstats.s_hpt,num_packitems(rs)); sleep(3); - +if ( thing_find(steal) < 0 ) +{ + fprintf(stderr,"steal %p not foun\n",steal); + sleep(3); +} leave_pack(rs,steal, FALSE, FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); - fprintf(stderr," hp.%d num.%d B\n",pstats.s_hpt,num_packitems(rs)); sleep(3); discard(steal); - fprintf(stderr," hp.%d num.%d C\n",pstats.s_hpt,num_packitems(rs)); sleep(3); } } otherwise: From c4e7d1f436f570b93ffd3fb5a260d8eab8897db6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 6 Mar 2019 08:10:01 -0500 Subject: [PATCH 36/56] Add help docs for all -ac_* params of komodod (#1313) --- src/init.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 6049fb09f..2a612634e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -562,6 +562,36 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-metricsui", _("Set to 1 for a persistent metrics screen, 0 for sequential metrics output (default: 1 if running in a console, 0 otherwise)")); strUsage += HelpMessageOpt("-metricsrefreshtime", strprintf(_("Number of seconds between metrics refreshes (default: %u if running in a console, %u otherwise)"), 1, 600)); } + strUsage += HelpMessageGroup(_("Komodo Asset Chain options:")); + strUsage += HelpMessageOpt("-ac_algo", _("Choose PoW mining algorithm, default is Equihash")); + strUsage += HelpMessageOpt("-ac_blocktime", _("Block time in seconds, default is 60")); + strUsage += HelpMessageOpt("-ac_cc", _("Cryptoconditions, default 0")); + strUsage += HelpMessageOpt("-ac_beam", _("BEAM integration")); + strUsage += HelpMessageOpt("-ac_coda", _("CODA integration")); + strUsage += HelpMessageOpt("-ac_cclib", _("Cryptoconditions dynamicly loadable library")); + strUsage += HelpMessageOpt("-ac_ccenable", _("Cryptoconditions to enable")); + strUsage += HelpMessageOpt("-ac_ccactivate", _("Block height to enable Cryptoconditions")); + strUsage += HelpMessageOpt("-ac_decay", _("Percentage of block reward decrease at each halving")); + strUsage += HelpMessageOpt("-ac_end", _("Block height at which block rewards will end")); + strUsage += HelpMessageOpt("-ac_eras", _("Block reward eras")); + strUsage += HelpMessageOpt("-ac_founders", _("Number of blocks between founders reward payouts")); + strUsage += HelpMessageOpt("-ac_halving", _("Number of blocks between each block reward halving")); + strUsage += HelpMessageOpt("-ac_name", _("Name of asset chain")); + strUsage += HelpMessageOpt("-ac_notarypay", _("Pay notaries, default 0")); + strUsage += HelpMessageOpt("-ac_perc", _("Percentage of block rewards paid to the founder")); + strUsage += HelpMessageOpt("-ac_private", _("Shielded transactions only (except coinbase + notaries), default is 0")); + strUsage += HelpMessageOpt("-ac_pubkey", _("Public key for receiving payments on the network")); + strUsage += HelpMessageOpt("-ac_public", _("Transparent transactions only, default 0")); + strUsage += HelpMessageOpt("-ac_reward", _("Block reward in satoshis, default is 0")); + strUsage += HelpMessageOpt("-ac_sapling", _("Sapling activation block height")); + strUsage += HelpMessageOpt("-ac_script", _("P2SH/multisig address to receive founders rewards")); + strUsage += HelpMessageOpt("-ac_staked", _("Percentage of blocks that are Proof-Of-Stake, default 0")); + strUsage += HelpMessageOpt("-ac_supply", _("Starting supply, default is 0")); + strUsage += HelpMessageOpt("-ac_timelockfrom", _("Timelocked coinbase start height")); + strUsage += HelpMessageOpt("-ac_timelockgte", _("Timelocked coinbase minimum amount to be locked")); + strUsage += HelpMessageOpt("-ac_timelockto", _("Timelocked coinbase stop height")); + strUsage += HelpMessageOpt("-ac_txpow", _("Enforce transaction-rate limit, default 0")); + strUsage += HelpMessageOpt("-ac_veruspos", _("Use Verus Proof-Of-Stake (-ac_veruspos=50) default 0")); return strUsage; } From 23ca797f73945b7c85d940762c34f6979e00d248 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 02:13:05 -1100 Subject: [PATCH 37/56] Remove myAddress from roc --- 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 2397be883..289b97dfb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5393,8 +5393,8 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector Date: Wed, 6 Mar 2019 02:41:39 -1100 Subject: [PATCH 38/56] +print --- src/cc/rogue/fight.c | 5 ----- src/cc/rogue/pack.c | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 4c9b61da6..e65e96d76 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -307,11 +307,6 @@ attack(struct rogue_state *rs,THING *mp) { remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); mp=NULL; -if ( thing_find(steal) < 0 ) -{ - fprintf(stderr,"steal %p not foun\n",steal); - sleep(3); -} leave_pack(rs,steal, FALSE, FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); discard(steal); diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index e7aa8874a..d7622a5e7 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -226,6 +226,11 @@ leave_pack(struct rogue_state *rs,THING *obj, bool newobj, bool all) inpack--; nobj = obj; + if ( thing_find(obj) < 0 ) + { + fprintf(stderr,"leave_pack unknown obj %p\n",obj); + sleep(3); + } if (obj->o_count > 1 && !all) { last_pick = obj; From 891bfb4b9d4c582e94f6c2cc8fa33028a72afe85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 02:51:03 -1100 Subject: [PATCH 39/56] Test --- src/cc/rogue/pack.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index d7622a5e7..c49b87140 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -166,6 +166,7 @@ int32_t num_packitems(struct rogue_state *rs) if ( thing_find(list) < 0 ) { fprintf(stderr,"num_packitems cant find %p\n",list); + return(-1); } if ( list->o_packch != 0 ) { @@ -226,11 +227,6 @@ leave_pack(struct rogue_state *rs,THING *obj, bool newobj, bool all) inpack--; nobj = obj; - if ( thing_find(obj) < 0 ) - { - fprintf(stderr,"leave_pack unknown obj %p\n",obj); - sleep(3); - } if (obj->o_count > 1 && !all) { last_pick = obj; @@ -289,11 +285,11 @@ inventory(struct rogue_state *rs,THING *list, int type) list->o_type != FOOD && list->o_type != AMULET) && !(type == R_OR_S && (list->o_type == RING || list->o_type == STICK))) continue; - if ( thing_find(list) < 0 ) + /*if ( thing_find(list) < 0 ) { fprintf(stderr,"cant find thing.(%c) in pack\n",list->o_packch); sleep(3); - } + }*/ n_objs++; #ifdef MASTER if (!list->o_packch) From ab4fde8764b2748b1ecf4e4e2a2a4d03de7dd5e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:03:46 -1100 Subject: [PATCH 40/56] Test --- src/cc/rogue/fight.c | 26 ++++++++++++-------------- src/cc/rogue/list.c | 35 +++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index e65e96d76..ae2db635d 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -290,8 +290,7 @@ attack(struct rogue_state *rs,THING *mp) } when 'N': { - register THING *obj, *steal; - register int nobj; + THING *obj, *steal; int nobj; /* * Nymph's steal a magic item, look through the pack @@ -594,26 +593,25 @@ void remove_mon(struct rogue_state *rs,coord *mp, THING *tp, bool waskill) { register THING *obj, *nexti; - for (obj = tp->t_pack; obj != NULL; obj = nexti) { - nexti = next(obj); - obj->o_pos = tp->t_pos; - detach(tp->t_pack, obj); - if (waskill) - fall(rs,obj, FALSE); - else - discard(obj); + nexti = next(obj); + obj->o_pos = tp->t_pos; + detach(tp->t_pack, obj); + if (waskill) + fall(rs,obj, FALSE); + else + discard(obj); } moat(mp->y, mp->x) = NULL; mvaddch(mp->y, mp->x, tp->t_oldch); detach(mlist, tp); if (on(*tp, ISTARGET)) { - kamikaze = FALSE; - to_death = FALSE; - if (fight_flush) - flush_type(); + kamikaze = FALSE; + to_death = FALSE; + if (fight_flush) + flush_type(); } discard(tp); } diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 68d889d8b..60eac8b16 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -61,6 +61,16 @@ discard(THING *item) break; } } + THING *list = pack; + for (; list != NULL; list = next(list)) + { + if ( list == item ) + { + fprintf(stderr,"pack item discarded? (%s)\n",inv_name(list,FALSE)); + sleep(3); + break; + } + } #endif itemcounter--; free((char *) item); @@ -89,11 +99,11 @@ void _detach(THING **list, THING *item) { if (*list == item) - *list = next(item); + *list = next(item); if (prev(item) != NULL) - item->l_prev->l_next = next(item); + item->l_prev->l_next = next(item); if (next(item) != NULL) - item->l_next->l_prev = prev(item); + item->l_next->l_prev = prev(item); item->l_next = NULL; item->l_prev = NULL; } @@ -108,14 +118,14 @@ _attach(THING **list, THING *item) { if (*list != NULL) { - item->l_next = *list; - (*list)->l_prev = item; - item->l_prev = NULL; + item->l_next = *list; + (*list)->l_prev = item; + item->l_prev = NULL; } else { - item->l_next = NULL; - item->l_prev = NULL; + item->l_next = NULL; + item->l_prev = NULL; } *list = item; } @@ -129,17 +139,14 @@ void _free_list(THING **ptr) { THING *item; - while (*ptr != NULL) { - item = *ptr; - *ptr = next(item); - discard(item); + item = *ptr; + *ptr = next(item); + discard(item); } } - - /* * new_item * Get a new item with a specified size From 90b730090474e0308d46aa365b169c823a48a9a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:09:47 -1100 Subject: [PATCH 41/56] Leave pack all --- src/cc/rogue/fight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index ae2db635d..6d81a53fe 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -306,7 +306,7 @@ attack(struct rogue_state *rs,THING *mp) { remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); mp=NULL; - leave_pack(rs,steal, FALSE, FALSE); + leave_pack(rs,steal, FALSE, TRUE);//FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); discard(steal); } From 53b12740a38ddaed0b77526d4dbb63ade876159b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:14:43 -1100 Subject: [PATCH 42/56] Dont discard unless last o_count --- src/cc/rogue/fight.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 6d81a53fe..0e512d4b7 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -306,7 +306,7 @@ attack(struct rogue_state *rs,THING *mp) { remove_mon(rs,&mp->t_pos, moat(mp->t_pos.y, mp->t_pos.x), FALSE); mp=NULL; - leave_pack(rs,steal, FALSE, TRUE);//FALSE); + leave_pack(rs,steal, FALSE, FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); discard(steal); } @@ -600,7 +600,7 @@ remove_mon(struct rogue_state *rs,coord *mp, THING *tp, bool waskill) detach(tp->t_pack, obj); if (waskill) fall(rs,obj, FALSE); - else + else if ( obj->o_count <= 0 ) discard(obj); } moat(mp->y, mp->x) = NULL; From 25e1e4c703a75662e0abd0a393eb1834d6f033e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:17:32 -1100 Subject: [PATCH 43/56] Prevent pack corruption --- src/cc/rogue/fight.c | 6 +++--- src/cc/rogue/potions.c | 2 +- src/cc/rogue/scrolls.c | 2 +- src/cc/rogue/weapons.c | 38 +++++++++++++++++++------------------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 0e512d4b7..9cb4bf61e 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -308,7 +308,8 @@ attack(struct rogue_state *rs,THING *mp) mp=NULL; leave_pack(rs,steal, FALSE, FALSE); msg(rs,"she stole %s!", inv_name(steal, TRUE)); - discard(steal); + if ( steal->o_count <= 0 ) + discard(steal); } } otherwise: @@ -600,8 +601,7 @@ remove_mon(struct rogue_state *rs,coord *mp, THING *tp, bool waskill) detach(tp->t_pack, obj); if (waskill) fall(rs,obj, FALSE); - else if ( obj->o_count <= 0 ) - discard(obj); + else discard(obj); } moat(mp->y, mp->x) = NULL; mvaddch(mp->y, mp->x, tp->t_oldch); diff --git a/src/cc/rogue/potions.c b/src/cc/rogue/potions.c index 00865b5dd..b10f83bd4 100644 --- a/src/cc/rogue/potions.c +++ b/src/cc/rogue/potions.c @@ -220,7 +220,7 @@ quaff(struct rogue_state *rs) call_it(rs,&pot_info[obj->o_which]); if (discardit) - discard(obj); + discard(obj); return; } diff --git a/src/cc/rogue/scrolls.c b/src/cc/rogue/scrolls.c index 5554a5701..8ed6d2648 100644 --- a/src/cc/rogue/scrolls.c +++ b/src/cc/rogue/scrolls.c @@ -313,7 +313,7 @@ def: call_it(rs,&scr_info[obj->o_which]); if (discardit) - discard(obj); + discard(obj); } /* diff --git a/src/cc/rogue/weapons.c b/src/cc/rogue/weapons.c index e313bf9d3..0a8b6016c 100644 --- a/src/cc/rogue/weapons.c +++ b/src/cc/rogue/weapons.c @@ -129,28 +129,28 @@ fall(struct rogue_state *rs,THING *obj, bool pr) if (fallpos(&obj->o_pos, &fpos)) { - pp = INDEX(fpos.y, fpos.x); - pp->p_ch = (char) obj->o_type; - obj->o_pos = fpos; - if (cansee(rs,fpos.y, fpos.x)) - { - if (pp->p_monst != NULL) - pp->p_monst->t_oldch = (char) obj->o_type; - else - mvaddch(fpos.y, fpos.x, obj->o_type); - } - attach(lvl_obj, obj); - return; + pp = INDEX(fpos.y, fpos.x); + pp->p_ch = (char) obj->o_type; + obj->o_pos = fpos; + if (cansee(rs,fpos.y, fpos.x)) + { + if (pp->p_monst != NULL) + pp->p_monst->t_oldch = (char) obj->o_type; + else + mvaddch(fpos.y, fpos.x, obj->o_type); + } + attach(lvl_obj, obj); + return; } if (pr) { - if (has_hit) - { - endmsg(rs); - has_hit = FALSE; - } - msg(rs,"the %s vanishes as it hits the ground", - weap_info[obj->o_which].oi_name); + if (has_hit) + { + endmsg(rs); + has_hit = FALSE; + } + msg(rs,"the %s vanishes as it hits the ground", + weap_info[obj->o_which].oi_name); } discard(obj); } From e670687db59468245b500ff817dd5dde1c1e78ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:20:41 -1100 Subject: [PATCH 44/56] -ddebugs --- src/cc/rogue/io.c | 2 +- src/cc/rogue/list.c | 2 +- src/cc/rogue/pack.c | 10 ---------- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index 32f19bdb2..4c289ad7d 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -160,7 +160,7 @@ readchar(struct rogue_state *rs) if ( rs->ind < rs->numkeys ) { c = rs->keystrokes[rs->ind++]; - if ( 1 ) + if ( 0 ) { static FILE *fp; static int32_t counter; if ( fp == 0 ) diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 60eac8b16..a021c6a8f 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -24,7 +24,7 @@ int total = 0; /* total dynamic memory bytes */ * Free up an item */ -#define ENABLE_DEBUG +//#define ENABLE_DEBUG #define MAX_DEBUGPTRS 100000 int32_t itemcounter; diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index c49b87140..1f2f3faaa 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -285,11 +285,6 @@ inventory(struct rogue_state *rs,THING *list, int type) list->o_type != FOOD && list->o_type != AMULET) && !(type == R_OR_S && (list->o_type == RING || list->o_type == STICK))) continue; - /*if ( thing_find(list) < 0 ) - { - fprintf(stderr,"cant find thing.(%c) in pack\n",list->o_packch); - sleep(3); - }*/ n_objs++; #ifdef MASTER if (!list->o_packch) @@ -477,11 +472,6 @@ get_item(struct rogue_state *rs,char *purpose, int type) } else { - if ( 0 && thing_find(obj) < 0 ) - { - fprintf(stderr,"cant find thing.%p in list\n",obj); sleep(3); - return(NULL); - } return obj; } } From fb89be82f12f567409a0652df530d9bc577729f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:36:36 -1100 Subject: [PATCH 45/56] Merge branch 'FSM' into jl777 # Conflicts: # src/cc/rogue/main.c --- qa/rpc-tests/cryptoconditions_channels.py | 3 ++- qa/rpc-tests/cryptoconditions_dice.py | 20 ++++++++++++-------- qa/rpc-tests/cryptoconditions_faucet.py | 14 +++++++++----- qa/rpc-tests/cryptoconditions_heir.py | 6 +++--- qa/rpc-tests/cryptoconditions_oracles.py | 4 ++-- qa/rpc-tests/cryptoconditions_rewards.py | 6 ++++-- qa/rpc-tests/cryptoconditions_token.py | 22 +++++++++++----------- src/cc/assets.cpp | 3 ++- 8 files changed, 45 insertions(+), 33 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index 722cce66e..71f62f49d 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -31,7 +31,8 @@ class CryptoconditionsChannelsTest(CryptoconditionsTestFramework): result = rpc.channelsaddress(self.pubkey) assert_success(result) # test that additional CCaddress key is returned - for x in ['myCCaddress', 'ChannelsCCaddress', 'Channelsmarker', 'myaddress', 'CCaddress']: + for x in ['ChannelsCC1of2TokensAddress', 'myCCAddress(Channels)', 'ChannelsCC1of2Address', 'myAddress', \ + 'myCCaddress', 'ChannelsNormalAddress', 'PubkeyCCaddress(Channels)', 'ChannelsCCAddress']: assert_equal(result[x][0], 'R') # getting empty channels list diff --git a/qa/rpc-tests/cryptoconditions_dice.py b/qa/rpc-tests/cryptoconditions_dice.py index 51fd18908..7b960cb67 100755 --- a/qa/rpc-tests/cryptoconditions_dice.py +++ b/qa/rpc-tests/cryptoconditions_dice.py @@ -24,15 +24,19 @@ class CryptoconditionsDiceTest(CryptoconditionsTestFramework): result = rpc1.getbalance() assert_greater_than(result, 100000) - dice = rpc.diceaddress() - assert_equal(dice['result'], 'success') - for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: - assert_equal(dice[x][0], 'R') + result = rpc.diceaddress() + for x in result.keys(): + print(x+": "+str(result[x])) + assert_equal(result['result'], 'success') + for x in ['myCCaddress', 'DiceCCAddress', 'myaddress']: + assert_equal(result[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') + result = rpc.diceaddress(self.pubkey) + for x in result.keys(): + print(x+": "+str(result[x])) + assert_equal(result['result'], 'success') + for x in ['myCCaddress', 'DiceCCAddress', 'myaddress', 'DiceCCTokensAddress', 'DiceNormalAddress']: + assert_equal(result[x][0], 'R') # no dice created yet result = rpc.dicelist() diff --git a/qa/rpc-tests/cryptoconditions_faucet.py b/qa/rpc-tests/cryptoconditions_faucet.py index a3cbdeb15..c02522cc5 100755 --- a/qa/rpc-tests/cryptoconditions_faucet.py +++ b/qa/rpc-tests/cryptoconditions_faucet.py @@ -24,16 +24,20 @@ class CryptoconditionsFaucetTest(CryptoconditionsTestFramework): assert_greater_than(result['balance'], 0.0) balance = result['balance'] - faucet = rpc.faucetaddress() - assert_equal(faucet['result'], 'success') + result = rpc.faucetaddress() + assert_equal(result['result'], 'success') + for x in result.keys(): + print(x+": "+str(result[x])) # verify all keys look like valid AC addrs, could be better - for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: - assert_equal(faucet[x][0], 'R') + for x in ['myCCaddress', 'FaucetCCTokensAddress', 'FaucetNormalAddress', 'myaddress']: + assert_equal(result[x][0], 'R') result = rpc.faucetaddress(self.pubkey) assert_success(result) + for x in result.keys(): + print(x+": "+str(result[x])) # test that additional CCaddress key is returned - for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress', 'CCaddress']: + for x in ['myCCaddress', 'FaucetCCTokensAddress', 'FaucetNormalAddress', 'myaddress']: assert_equal(result[x][0], 'R') # no funds in the faucet yet diff --git a/qa/rpc-tests/cryptoconditions_heir.py b/qa/rpc-tests/cryptoconditions_heir.py index b79ae7bba..a2443f0b3 100755 --- a/qa/rpc-tests/cryptoconditions_heir.py +++ b/qa/rpc-tests/cryptoconditions_heir.py @@ -20,16 +20,16 @@ class CryptoconditionsHeirTest(CryptoconditionsTestFramework): rpc = self.nodes[0] rpc1 = self.nodes[1] - result = rpc.heiraddress() + result = rpc.heiraddress('') assert_success(result) # verify all keys look like valid AC addrs, could be better - for x in ['myCCaddress', 'HeirCCaddress', 'Heirmarker', 'myaddress']: + for x in ['HeirNormalAddress', 'HeirCCTokensAddress', 'myaddress', 'myCCaddress', 'HeirCCAddress']: assert_equal(result[x][0], 'R') result = rpc.heiraddress(self.pubkey) assert_success(result) # test that additional CCaddress key is returned - for x in ['myCCaddress', 'HeirCCaddress', 'Heirmarker', 'myaddress', 'CCaddress']: + for x in ['HeirNormalAddress', 'myCCaddress', 'myaddress', 'HeirCC1of2Address', 'HeirCCAddress', 'HeirCC1of2TokensAddress']: assert_equal(result[x][0], 'R') # getting empty heir list diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index 048b577d1..008ab6256 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -22,12 +22,12 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): result = rpc.oraclesaddress() assert_success(result) - for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + for x in ['myCCaddress', 'OraclesCCAddress', 'OraclesNormalAddress', 'myaddress', 'OraclesCCTokensAddress']: assert_equal(result[x][0], 'R') result = rpc.oraclesaddress(self.pubkey) assert_success(result) - for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + for x in ['myCCaddress', 'OraclesCCAddress', 'OraclesNormalAddress', 'myaddress', 'OraclesCCTokensAddress']: assert_equal(result[x][0], 'R') # there are no oracles created yet diff --git a/qa/rpc-tests/cryptoconditions_rewards.py b/qa/rpc-tests/cryptoconditions_rewards.py index 7bda54eaf..d70e40740 100755 --- a/qa/rpc-tests/cryptoconditions_rewards.py +++ b/qa/rpc-tests/cryptoconditions_rewards.py @@ -15,13 +15,15 @@ from cryptoconditions import assert_success, assert_error, generate_random_strin class CryptoconditionsRewardsTest(CryptoconditionsTestFramework): def run_rewards_tests(self): + rpc = self.nodes[0] + result = rpc.rewardsaddress() - for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: + for x in ['myCCaddress', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: assert_equal(result[x][0], 'R') result = rpc.rewardsaddress(self.pubkey) - for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: + for x in ['myCCaddress', 'myaddress', 'RewardsCCAddress', 'RewardsCCTokensAddress', 'RewardsNormalAddress']: assert_equal(result[x][0], 'R') # no rewards yet diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py index 97ed86f8d..faf2cbc8d 100755 --- a/qa/rpc-tests/cryptoconditions_token.py +++ b/qa/rpc-tests/cryptoconditions_token.py @@ -21,22 +21,22 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): result = rpc.tokenaddress() assert_success(result) - for x in ['TokensCCaddress', 'myCCaddress', 'Tokensmarker', 'myaddress']: + for x in ['TokensCCAddress', 'myCCaddress', 'myCCAddress(Tokens)', 'myaddress', 'TokensNormalAddress']: assert_equal(result[x][0], 'R') result = rpc.tokenaddress(self.pubkey) assert_success(result) - for x in ['TokensCCaddress', 'myCCaddress', 'Tokensmarker', 'myaddress', 'CCaddress']: + for x in ['TokensCCAddress', 'myCCaddress', 'myCCAddress(Tokens)', 'myaddress', 'TokensNormalAddress']: assert_equal(result[x][0], 'R') result = rpc.assetsaddress() assert_success(result) - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + for x in ['AssetsCCAddress', 'myCCaddress', 'myCCAddress(Assets)', 'myaddress', 'AssetsNormalAddress']: assert_equal(result[x][0], 'R') result = rpc.assetsaddress(self.pubkey) assert_success(result) - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: + for x in ['AssetsCCAddress', 'myCCaddress', 'myCCAddress(Assets)', 'myaddress', 'AssetsNormalAddress']: assert_equal(result[x][0], 'R') # there are no tokens created yet @@ -61,7 +61,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): assert_equal(result[0], tokenid) # there are no token orders yet - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # getting token balance for non existing tokenid @@ -117,7 +117,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): tokenask = rpc.tokenask("100", tokenid, "7.77") tokenaskhex = tokenask['hex'] tokenaskid = self.send_and_mine(tokenask['hex'], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) order = result[0] assert order, "found order" @@ -136,7 +136,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): assert txid, "found txid" # should be no token orders - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # checking ask cancellation @@ -157,7 +157,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): # from valid node cancel = rpc.tokencancelask(tokenid, testorderid) self.send_and_mine(cancel["hex"], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) @@ -184,7 +184,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): tokenbid = rpc.tokenbid("100", tokenid, "10") tokenbidhex = tokenbid['hex'] tokenbidid = self.send_and_mine(tokenbid['hex'], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) order = result[0] assert order, "found order" @@ -203,7 +203,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): assert txid, "found txid" # should be no token orders - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # checking bid cancellation @@ -220,7 +220,7 @@ class CryptoconditionsTokenTest(CryptoconditionsTestFramework): # from valid node cancel = rpc.tokencancelbid(tokenid, testorderid) self.send_and_mine(cancel["hex"], rpc) - result = rpc.tokenorders() + result = rpc.tokenorders(tokenid) assert_equal(result, []) # invalid token transfer amount (have to add status to CC code!) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 6e57e816b..9ae4cc1eb 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -297,6 +297,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti return eval->Invalid("vout2 doesnt go to origpubkey fillbuy"); else if ( inputs != tx.vout[2].nValue + tx.vout[4].nValue ) return eval->Invalid("asset inputs doesnt match vout2+3 fillbuy"); + preventCCvouts ++; } else if( ConstrainVout(tx.vout[2], 1, origTokensCCaddr, inputs) == 0 ) // tokens to originator cc addr (tokens+nonfungible evals) return eval->Invalid("vout2 doesnt match inputs fillbuy"); @@ -468,7 +469,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti } // what does this do? - bool bPrevent = PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts); + bool bPrevent = PreventCC(eval, tx, preventCCvins, numvins, preventCCvouts, numvouts); // seems we do not need this call as we already checked vouts well //std::cerr << "AssetsValidate() PreventCC returned=" << bPrevent << std::endl; return (bPrevent); } From 61de6564729f98204d388cb74fac5d7bce4b4ec7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 04:00:29 -1100 Subject: [PATCH 46/56] Enable keystrokes test --- src/cc/rogue/main.c | 13 +++++++++---- src/cc/rogue/rogue.c | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index e743a9672..ae5875d0e 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -765,7 +765,7 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * } // extract and get keystrokes field and compare it to pastkeys // if not matching... panic? - if ( 0 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) + if ( 1 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) { sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) @@ -777,15 +777,20 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * len = strlen(keys) / 2; pastcmp = (char *)malloc(len + 1); decode_hex(pastcmp,len,keys); + fprintf(stderr,"keystrokes.(%s) vs pastkeys\n",keys); + for (i=0; i Date: Wed, 6 Mar 2019 04:13:57 -1100 Subject: [PATCH 47/56] +debug --- src/cc/rogue/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index ae5875d0e..0dffa882b 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -763,8 +763,6 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * } free(rs->keystrokeshex), rs->keystrokeshex = 0; } - // extract and get keystrokes field and compare it to pastkeys - // if not matching... panic? if ( 1 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) { sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); @@ -789,10 +787,11 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * } else fprintf(stderr,"no keystrokes in (%s)\n",retstr); free_json(retjson); } else fprintf(stderr,"error parsing.(%s)\n",retstr); + fprintf(stderr,"extracted.(%s)\n",retstr); free(retstr); } else fprintf(stderr,"error extracting game\n"); free(pastkeys); - } + } else fprintf(stderr,"no pastkeys\n"); for (i=0; i Date: Wed, 6 Mar 2019 04:22:11 -1100 Subject: [PATCH 48/56] Fix rogue results processing --- src/cc/rogue/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 0dffa882b..87f0a0c31 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -770,7 +770,7 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (keys= jstr(retjson,"keystrokes")) != 0 ) + if ( (resobj= jobj(retjson,"result")) != 0 && (keys= jstr(resobj,"keystrokes")) != 0 ) { len = strlen(keys) / 2; pastcmp = (char *)malloc(len + 1); @@ -791,7 +791,7 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * free(retstr); } else fprintf(stderr,"error extracting game\n"); free(pastkeys); - } else fprintf(stderr,"no pastkeys\n"); + } // else fprintf(stderr,"no pastkeys\n"); for (i=0; ikeystrokeshex != 0 ) free(rs->keystrokeshex); rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); strcpy(rs->keystrokeshex,rawtx); - //fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); +fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); } free_json(retjson); } From 40d4907f8cbdf62024b20ca542933fa2057cf2c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 04:22:47 -1100 Subject: [PATCH 49/56] Resobj --- src/cc/rogue/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 87f0a0c31..1db9bb62c 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -742,7 +742,7 @@ int32_t rogue_sendrawtransaction(char *rawtx) void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) { - char cmd[16384],hexstr[16384],params[32768],*retstr,*rawtx,*pastkeys,*pastcmp,*keys; int32_t i,len,numpastkeys; cJSON *retjson; + char cmd[16384],hexstr[16384],params[32768],*retstr,*rawtx,*pastkeys,*pastcmp,*keys; int32_t i,len,numpastkeys; cJSON *retjson,*resobj; //fprintf(stderr,"rogue_progress num.%d\n",num); if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) { From e8d71bc8f16d39424d997d63cc0fd58bf28be9a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 04:35:14 -1100 Subject: [PATCH 50/56] Enable keystrokes sending --- src/cc/rogue/main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 1db9bb62c..6b1008363 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -716,11 +716,6 @@ int32_t rogue_sendrawtransaction(char *rawtx) if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) { //fprintf(stderr,"params.(%s) -> %s\n",params,retstr); - if ( is_hexstr(retstr,64) == 64 ) - { - free(retstr); - return(0); - } { static FILE *fp; if ( fp == 0 ) @@ -731,6 +726,11 @@ int32_t rogue_sendrawtransaction(char *rawtx) fflush(fp); } } + if ( is_hexstr(retstr,64) == 64 ) + { + free(retstr); + return(0); + } if ( (retjson= cJSON_Parse(retstr)) != 0 ) { free_json(retjson); @@ -763,7 +763,7 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * } free(rs->keystrokeshex), rs->keystrokeshex = 0; } - if ( 1 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) + if ( 0 && (pastkeys= rogue_keystrokesload(&numpastkeys,seed,1)) != 0 ) { sprintf(params,"[\"extract\",\"17\",\"[%%22%s%%22]\"]",Gametxidstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) @@ -824,7 +824,7 @@ void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char * free(rs->keystrokeshex); rs->keystrokeshex = (char *)malloc(strlen(rawtx)+1); strcpy(rs->keystrokeshex,rawtx); -fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); +//fprintf(stderr,"set keystrokestx <- %s\n",rs->keystrokeshex); } free_json(retjson); } From 3c5d1a7fea87e2deda2a32ce09e99a6d40f08c7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 04:55:14 -1100 Subject: [PATCH 51/56] Test --- src/cc/rogue/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 6b1008363..f38ee1976 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -711,10 +711,12 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t rogue_sendrawtransaction(char *rawtx) { - char params[512],*retstr; cJSON *retjson; int32_t numconfs = -1; + char *params,*retstr; cJSON *retjson; int32_t numconfs = -1; + params = (char *)malloc(strlen(rawtx) + 16); sprintf(params,"[\"%s\"]",rawtx); if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) { + free(params); //fprintf(stderr,"params.(%s) -> %s\n",params,retstr); { static FILE *fp; @@ -737,6 +739,7 @@ int32_t rogue_sendrawtransaction(char *rawtx) } free(retstr); } + free(params); return(-1); } From c5b6ed9894407f9f2d0f153732ee8405f4eb8d7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 05:04:04 -1100 Subject: [PATCH 52/56] Print --- src/cc/rogue/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index f38ee1976..f3d1b41d7 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -717,7 +717,7 @@ int32_t rogue_sendrawtransaction(char *rawtx) if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) { free(params); - //fprintf(stderr,"params.(%s) -> %s\n",params,retstr); + fprintf(stderr,"sendrawtransaction.(%s)\n",retstr); { static FILE *fp; if ( fp == 0 ) From 415bc355f351f34dcd49f443593f23006a635281 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 05:16:21 -1100 Subject: [PATCH 53/56] Sendrawtransaction result --- src/cc/rogue/main.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index f3d1b41d7..e5bf9383f 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -711,13 +711,12 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t rogue_sendrawtransaction(char *rawtx) { - char *params,*retstr; cJSON *retjson; int32_t numconfs = -1; + char *params,*retstr,*hexstr; cJSON *retjson; int32_t numconfs = -1; params = (char *)malloc(strlen(rawtx) + 16); sprintf(params,"[\"%s\"]",rawtx); if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) { free(params); - fprintf(stderr,"sendrawtransaction.(%s)\n",retstr); { static FILE *fp; if ( fp == 0 ) @@ -728,13 +727,16 @@ int32_t rogue_sendrawtransaction(char *rawtx) fflush(fp); } } - if ( is_hexstr(retstr,64) == 64 ) - { - free(retstr); - return(0); - } if ( (retjson= cJSON_Parse(retstr)) != 0 ) { + if ( (resobj= jobj(retjson,"result")) != 0 ) + { + if ( (hexstr= jstr(resobj,0)) != 0 && is_hexstr(hexstr,64) == 64 ) + { + free(retstr); + return(0); + } + } free_json(retjson); } free(retstr); From 1bf8f353866daab692b5ccf1aaa63b61aa65c724 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 05:17:21 -1100 Subject: [PATCH 54/56] Resobj --- src/cc/rogue/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index e5bf9383f..89c4eaae7 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -711,7 +711,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t rogue_sendrawtransaction(char *rawtx) { - char *params,*retstr,*hexstr; cJSON *retjson; int32_t numconfs = -1; + char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t numconfs = -1; params = (char *)malloc(strlen(rawtx) + 16); sprintf(params,"[\"%s\"]",rawtx); if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) From 6e26b4505dbe6efd634db19a60a0410f2dbf3911 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 05:34:58 -1100 Subject: [PATCH 55/56] Fix crash --- src/cc/rogue/main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 89c4eaae7..ea58767ba 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -711,12 +711,11 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) int32_t rogue_sendrawtransaction(char *rawtx) { - char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t numconfs = -1; + char *params,*retstr,*hexstr; cJSON *retjson,*resobj; int32_t retval = -1; params = (char *)malloc(strlen(rawtx) + 16); sprintf(params,"[\"%s\"]",rawtx); if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) { - free(params); { static FILE *fp; if ( fp == 0 ) @@ -732,17 +731,14 @@ int32_t rogue_sendrawtransaction(char *rawtx) if ( (resobj= jobj(retjson,"result")) != 0 ) { if ( (hexstr= jstr(resobj,0)) != 0 && is_hexstr(hexstr,64) == 64 ) - { - free(retstr); - return(0); - } + retval = 0; } free_json(retjson); } free(retstr); } free(params); - return(-1); + return(retval); } void rogue_progress(struct rogue_state *rs,int32_t waitflag,uint64_t seed,char *keystrokes,int32_t num) From b7326ab6cd5fb3a26cfd0d8d7170f8eecd452d74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 07:10:16 -1100 Subject: [PATCH 56/56] Dont long sends --- src/cc/rogue/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index ea58767ba..df7c6481a 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -716,6 +716,7 @@ int32_t rogue_sendrawtransaction(char *rawtx) sprintf(params,"[\"%s\"]",rawtx); if ( (retstr= komodo_issuemethod(USERPASS,"sendrawtransaction",params,ROGUE_PORT)) != 0 ) { + if ( 0 ) { static FILE *fp; if ( fp == 0 )