From 100eac16540646e98fb02cd36a935ee57da6741e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Mar 2019 03:38:14 -1100 Subject: [PATCH] Jl777 (#1315) * Remove voutsum check * 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 * Cleanup .pack file * Remove * Remove .pack * Disable passkeys * Rvalidate * Syntax * Allow overwrite by same pub33 * Tx * Declare variables * Allow replacement handle * Grandfather existing handles * Test * Handleinfo * Char * * Begin * Add mutex * CCaddr * Casts for windows * +debugs * Syntax * Item * Skeet * +print * Error check things * +prints * -sleep * Brute force inventory check * Revert * num_packitems * Log file * Test * ABC * Test * Add help docs for all -ac_* params of komodod (#1313) * Remove myAddress from roc * +print * Test * Test * Leave pack all * Dont discard unless last o_count * Prevent pack corruption * -ddebugs * Merge branch 'FSM' into jl777 # Conflicts: # src/cc/rogue/main.c --- src/cc/CCinclude.h | 1 + src/cc/cclib.cpp | 29 ++++++ src/cc/dilithium.c | 200 +++++++++++++++++++++++++++++++++++++-- src/cc/rogue/command.c | 1 - src/cc/rogue/fight.c | 64 ++++++------- src/cc/rogue/io.c | 2 +- src/cc/rogue/list.c | 150 +++++++++++++++++------------ src/cc/rogue/main.c | 23 ++++- src/cc/rogue/pack.c | 39 ++++---- src/cc/rogue/potions.c | 2 +- src/cc/rogue/rogue.c | 2 +- src/cc/rogue/rogue.h | 1 + src/cc/rogue/scrolls.c | 2 +- src/cc/rogue/state.c | 5 + src/cc/rogue/weapons.c | 38 ++++---- src/init.cpp | 30 ++++++ src/wallet/rpcwallet.cpp | 4 +- src/wallet/wallet.cpp | 4 +- src/wallet/walletdb.cpp | 2 +- 19 files changed, 449 insertions(+), 150 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..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 ) @@ -504,6 +508,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 nValue,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..b92102f22 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2929,6 +2929,45 @@ 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; + +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 ) + { + hashstr = (struct dilithium_handle *)calloc(1,sizeof(*hashstr)); + strncpy(hashstr->handle,handle,sizeof(hashstr->handle)); + HASH_ADD_KEYPTR(hh,Dilithium_handles,hashstr->handle,len,hashstr); + } + pthread_mutex_unlock(&DILITHIUM_MUTEX); + } + 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 ) + { + pthread_mutex_lock(&DILITHIUM_MUTEX); + HASH_FIND(hh,Dilithium_handles,handle,len,hashstr); + pthread_mutex_unlock(&DILITHIUM_MUTEX); + } + 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 +3149,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 +3179,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 +3508,130 @@ bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co } else return eval->Invalid("unexpected zero signerpubtxid"); } +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; char CCaddr[64]; + 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,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")); + 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(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")); + 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; + 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); + dilithiumpk = GetUnspendable(cp,0); + 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((char *)handle.c_str())) == 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 if ( dilithium_registrationpub33(pkaddr,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"); + } + } 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 +3639,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"); diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index 54d7beb99..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; - if (on(player, ISHASTE)) ntimes++; /* diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 43474616e..9cb4bf61e 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -290,27 +290,27 @@ attack(struct rogue_state *rs,THING *mp) } when 'N': { - 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; - leave_pack(rs,steal, FALSE, FALSE); - msg(rs,"she stole %s!", inv_name(steal, TRUE)); - discard(steal); - } + THING *obj, *steal; 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; + leave_pack(rs,steal, FALSE, FALSE); + msg(rs,"she stole %s!", inv_name(steal, TRUE)); + if ( steal->o_count <= 0 ) + discard(steal); + } } otherwise: break; @@ -594,26 +594,24 @@ 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/io.c b/src/cc/rogue/io.c index 994f112e2..4c289ad7d 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\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/list.c b/src/cc/rogue/list.c index 622af60cd..a021c6a8f 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -19,80 +19,38 @@ int total = 0; /* total dynamic memory bytes */ #endif -/* - * detach: - * takes an item out of whatever linked list it might be in - */ - -void -_detach(THING **list, THING *item) -{ - if (*list == item) - *list = next(item); - if (prev(item) != NULL) - item->l_prev->l_next = next(item); - if (next(item) != NULL) - item->l_next->l_prev = prev(item); - item->l_next = NULL; - item->l_prev = NULL; -} - -/* - * _attach: - * add an item to the head of a list - */ - -void -_attach(THING **list, THING *item) -{ - if (*list != NULL) - { - item->l_next = *list; - (*list)->l_prev = item; - item->l_prev = NULL; - } - else - { - item->l_next = NULL; - item->l_prev = NULL; - } - *list = item; -} - -/* - * _free_list: - * Throw the whole blamed thing away - */ - -void -_free_list(THING **ptr) -{ - THING *item; - - while (*ptr != NULL) - { - item = *ptr; - *ptr = next(item); - discard(item); - } -} - /* * discard: * 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_prev->l_next = next(item); + if (next(item) != NULL) + item->l_next->l_prev = prev(item); + item->l_next = NULL; + item->l_prev = NULL; +} + +/* + * _attach: + * add an item to the head of a list + */ + +void +_attach(THING **list, THING *item) +{ + if (*list != NULL) + { + item->l_next = *list; + (*list)->l_prev = item; + item->l_prev = NULL; + } + else + { + item->l_next = NULL; + item->l_prev = NULL; + } + *list = item; +} + +/* + * _free_list: + * Throw the whole blamed thing away + */ + +void +_free_list(THING **ptr) +{ + THING *item; + while (*ptr != NULL) + { + item = *ptr; + *ptr = next(item); + discard(item); + } +} + /* * new_item * Get a new item with a specified size @@ -139,12 +165,14 @@ new_item(void) #else item = (THING *)calloc(1, sizeof *item); #endif - if ( 0 ) +#ifdef ENABLE_DEBUG + if ( numptrs < MAX_DEBUGPTRS ) { thingptrs[numptrs++] = item; if ( (++itemcounter % 100) == 0 ) fprintf(stderr,"itemcounter.%d\n",itemcounter); } +#endif item->l_next = NULL; item->l_prev = NULL; return item; diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 5e79e399e..e743a9672 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 ) { @@ -765,8 +765,27 @@ 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 ) { + 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/pack.c b/src/cc/rogue/pack.c index 362c65412..1f2f3faaa 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); + return(-1); + } if ( list->o_packch != 0 ) { n++; @@ -219,29 +224,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; } @@ -466,7 +471,9 @@ get_item(struct rogue_state *rs,char *purpose, int type) return NULL; } else + { return obj; + } } } return NULL; 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/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/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/state.c b/src/cc/rogue/state.c index b0176a042..9963bbc9e 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 (%s) in list\n",o,inv_name(o,FALSE)); //sleep(3); + return(0); + } if ( o->_o._o_packch != 0 ) { item = &rs->P.roguepack[rs->P.packsize]; 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); } 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; } 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