From 619c92a1ac2a08cd4dae195bb706f7d89abcce2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Feb 2019 16:57:07 -1100 Subject: [PATCH 01/69] Remove OS specific --- src/cc/rogue/rogue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 786718039..80a4e7da2 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -548,13 +548,13 @@ tstp(int ignored) getyx(curscr, y, x); mvcur(y, x, oy, ox); fflush(stdout); - //wmove(curscr,oy,ox); -#ifndef __APPLE__ + wmove(curscr,oy,ox); +/*#ifndef __APPLE__ #ifndef BUILD_ROGUE curscr->_cury = oy; curscr->_curx = ox; #endif -#endif +#endif*/x } /* From 61966f52f8b9c337c011d76db1e81f31ade20c7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Feb 2019 16:57:56 -1100 Subject: [PATCH 02/69] -x --- src/cc/rogue/rogue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 80a4e7da2..92d3ad378 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -554,7 +554,7 @@ tstp(int ignored) curscr->_cury = oy; curscr->_curx = ox; #endif -#endif*/x +#endif*/ } /* From f1d392b72c168edf4c6216c29f8a5b4f9381b7b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 07:10:36 -1100 Subject: [PATCH 03/69] Initial musig CC commit --- src/cc/cclib.cpp | 81 ++++++++++--- src/cc/musig.cpp | 265 +++++++++++++++++++++++++++++++++++++++++++ src/cc/rogue_rpc.cpp | 5 +- src/cc/sudoku.cpp | 4 - 4 files changed, 332 insertions(+), 23 deletions(-) create mode 100755 src/cc/musig.cpp diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index f2f13837c..ae3d88573 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -36,6 +36,7 @@ std::string MYCCLIBNAME = (char *)"rogue"; #else #define EVAL_SUDOKU 17 +#define EVAL_MUSIG 18 std::string MYCCLIBNAME = (char *)"sudoku"; #endif @@ -70,6 +71,16 @@ CClib_methods[] = { (char *)"sudoku", (char *)"txidinfo", (char *)"txid", 1, 1, 'T', EVAL_SUDOKU }, { (char *)"sudoku", (char *)"pending", (char *)"", 0, 0, 'U', EVAL_SUDOKU }, { (char *)"sudoku", (char *)"solution", (char *)"txid solution timestamps[81]", 83, 83, 'S', EVAL_SUDOKU }, + { (char *)"musig", (char *)"calcmsg", (char *)"sendtxid scriptPubKey", 2, 2, 'C', EVAL_MUSIG }, + { (char *)"musig", (char *)"combine", (char *)"pubkeys ...", 2, 256, 'P', EVAL_MUSIG }, + { (char *)"musig", (char *)"session", (char *)"msg pkhash", 2, 2, 'R', EVAL_MUSIG }, + { (char *)"musig", (char *)"commit", (char *)"pubkeys ...", 2, 256, 'H', EVAL_MUSIG }, + { (char *)"musig", (char *)"nonce", (char *)"pubkeys ...", 2, 256, 'N', EVAL_MUSIG }, + { (char *)"musig", (char *)"partialsign", (char *)"pubkeys ...", 2, 256, 'S', EVAL_MUSIG }, + { (char *)"musig", (char *)"sigcombine", (char *)"pubkeys ...", 2, 256, 'M', EVAL_MUSIG }, + { (char *)"musig", (char *)"verify", (char *)"msg sig pubkey", 3, 3, 'V', EVAL_MUSIG }, + { (char *)"musig", (char *)"send", (char *)"combined_pk amount", 2, 2, 'x', EVAL_MUSIG }, + { (char *)"musig", (char *)"spend", (char *)"sendtxid sig destpubkey", 3, 3, 'y', EVAL_MUSIG }, #endif }; @@ -98,6 +109,18 @@ UniValue sudoku_txidinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params UniValue sudoku_generate(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue sudoku_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); + +bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); +UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_combine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_partialsign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_sigcombine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #endif UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params) @@ -158,6 +181,37 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params) return(result); } } + else if ( cp->evalcode == EVAL_MUSIG ) + { + //printf("CClib_method params.%p\n",params); + if ( strcmp(method,"combine") == 0 ) + return(musig_combine(txfee,cp,params)); + else if ( strcmp(method,"calcmsg") == 0 ) + return(musig_calcmsg(txfee,cp,params)); + else if ( strcmp(method,"session") == 0 ) + return(musig_session(txfee,cp,params)); + else if ( strcmp(method,"commit") == 0 ) + return(musig_commit(txfee,cp,params)); + else if ( strcmp(method,"nonce") == 0 ) // returns combined nonce if ready + return(musig_nonce(txfee,cp,params)); + else if ( strcmp(method,"partialsign") == 0 ) + return(musig_partialsign(txfee,cp,params)); + else if ( strcmp(method,"sigcombine") == 0 ) + return(musig_sigcombine(txfee,cp,params)); + else if ( strcmp(method,"verify") == 0 ) + return(musig_verify(txfee,cp,params)); + else if ( strcmp(method,"send") == 0 ) + return(musig_send(txfee,cp,params)); + else if ( strcmp(method,"spend") == 0 ) + return(musig_spend(txfee,cp,params)); + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid musig method")); + result.push_back(Pair("method",method)); + return(result); + } + } #endif else { @@ -278,7 +332,11 @@ bool CClib_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C #ifdef BUILD_ROGUE return(rogue_validate(cp,height,eval,tx)); #else - return(sudoku_validate(cp,height,eval,tx)); + if ( cp->evalcode == EVAL_SUDOKU ) + return(sudoku_validate(cp,height,eval,tx)); + else if ( cp->evalcode == EVAL_MUSIG ) + return(musig_validate(cp,height,eval,tx)); + else return eval->Invalid("invalid evalcode"); #endif } numvins = tx.vin.size(); @@ -385,21 +443,6 @@ std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) return(""); } -/*UniValue FaucetInfo() -{ - UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; - result.push_back(Pair("result","success")); - result.push_back(Pair("name","Faucet")); - cp = CCinit(&C,EVAL_FAUCET); - faucetpk = GetUnspendable(cp,0); - funding = AddFaucetInputs(cp,mtx,faucetpk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); - return(result); -}*/ - std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *params) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); @@ -481,7 +524,10 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will { newstr[j++] = '"'; i += 2; - } else newstr[j++] = jsonstr[i]; + } + else if ( jsonstr[i] == ''' ) + newstr[j++] = '"'; + else newstr[j++] = jsonstr[i]; } newstr[j] = 0; params = cJSON_Parse(newstr); @@ -533,5 +579,6 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #else #include "sudoku.cpp" +#include "musig.cpp" #endif diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp new file mode 100755 index 000000000..1a9d860cf --- /dev/null +++ b/src/cc/musig.cpp @@ -0,0 +1,265 @@ +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + + +#include +#include +#include + +#define MUSIG_PREVN 0 // for now, just use vout0 for the musig output + +uint256 musig_msghash(uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) +{ + std::vector data; uint256 hash; int32_t len = 0; + data << E_MARSHAL(ss << prevhash << prevn << vout << combined_pk); +fprintf(stderr,"data size %d\n",(int32_t)data.size()); + vcalc_sha256(0,(uint8_t *)&hash,data.ptr(),data.size()); + return(hash); +} + +uint256 musig_prevoutmsg(uint256 sendtxid,CScript scriptPubKey) +{ + CTransaction vintx; uint256 hashBlock; int32_t numvouts; CTxOut vout; secp256k1_pubkey combined_pk; + if ( myGetTransaction(prevhash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) + { + if ( musig_sendopretdecode(combined_pk,vintx.vouts[numvouts-1].scriptPubKey) == 'x' ) + { + vout.nValue = vintx.vout[MUSIG_PREVN].nValue - txfee; + vout.scriptPubKey = scriptPubKey; + return(musig_msghash(prevhash,MUSIG_PREVN,vout,combined_pk)); + } + } + return(zeroid); +} + +UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); uint256 sendtxid,msg; char *scriptstr; int32_t n; + if ( (params= cclib_reparse(&n,params)) != 0 ) + { + if ( n == 2 ) + { + sendtxid = juint256(jitem(params,0)); + scriptstr = jstr(jitem(params,1),0); + if ( is_hexstr(scriptstr,0) != 0 ) + { + CScript scriptPubKey(ParseHex(scriptstr)); + msg = musig_prevoutmsg(sendtxid,scriptPubKey); + result.push_back("result","success"); + result.push_back("msg",msg.GetHex()); + return(result); + } else return(cclib_error(result,"script is not hex")); + } else return(cclib_error(result,"need exactly 2 parameters: sendtxid, scriptPubKey")); + } else return(cclib_error(result,"couldnt parse params")); +} + +UniValue musig_combine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +UniValue musig_partialsign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +UniValue musig_sigcombine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back("result","success"); + return(result); +} + +// helpers for rpc calls that generate/validate onchain tx + +UniValue musig_rawtxresult(UniValue &result,std::string rawtx) +{ + CTransaction tx; + if ( rawtx.size() > 0 ) + { + result.push_back(Pair("hex",rawtx)); + if ( DecodeHexTx(tx,rawtx) != 0 ) + { + //if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) + // RelayTransaction(tx); + result.push_back(Pair("txid",tx.GetHash().ToString())); + result.push_back(Pair("result","success")); + } else result.push_back(Pair("error","decode hex")); + } else result.push_back(Pair("error","couldnt finalize CCtx")); + return(result); +} + +CScript musig_sendopret(uint8_t funcid,secp256k1_pubkey combined_pk) +{ + CScript opret; uint8_t evalcode = EVAL_MUSIG; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << combined_pk); + return(opret); +} + +uint8_t musig_sendopretdecode(secp256k1_pubkey &combined_pk,CScript scriptPubKey) +{ + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> combined_pk) != 0 && e == EVAL_MUSIG && f == 'x' ) + { + return(f); + } + return(0); +} + +CScript musig_spendopret(uint8_t funcid,secp256k1_pubkey combined_pk,secp256k1_schnorrsig musig) +{ + CScript opret; uint8_t evalcode = EVAL_MUSIG; + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << combined_pk << musig); + return(opret); +} + +uint8_t musig_spendopretdecode(secp256k1_pubkey &combined_pk,secp256k1_schnorrsig &musig,CScript scriptPubKey) +{ + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> combined_pk; ss >> musig) != 0 && e == EVAL_MUSIG && f == 'y' ) + { + return(f); + } + return(0); +} + +UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); int32_t n; char *hexstr; std::string rawtx; int64_t amount; CPubKey musigpk,mypk; + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + musigpk = GetUnspendable(cp,0); + if ( (params= cclib_reparse(&n,params)) != 0 ) + { + if ( n == 2 && (hexstr= jstr(jitem(params,0),0)) != 0 && is_hexstr(hexstr,0) == 66 ) + { + secp256k1_pubkey combined_pk(ParseHex(hexstr)); + amount = jdouble(jitem(params,1),0) * COIN + 0.0000000049; + if ( amount >= 3*txfee && AddNormalinputs(mtx,mypk,amount+2*txfee,64) >= amount+2*txfee ) + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount+txfee,musigpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_sendopret('x',combined_pk)); + return(musig_rawtxresult(result,rawtx)); + } else return(cclib_error(result,"couldnt find funds or less than 0.0003")); + } else return(cclib_error(result,"must have 2 params: combined_pk, amount")); + } else return(cclib_error(result,"not enough parameters")); +} + +UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + static secp256k1_context *ctx; + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint256 msg,prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; + if ( ctx == 0 ) + ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + if ( (params= cclib_reparse(&n,params)) != 0 ) + { + if ( n == 3 ) + { + prevhash = juint256(jitem(params,0)); + scriptstr = jstr(jitem(params,1),0); + musigstr = jstr(jitem(params,2),0); + if ( is_hexstr(scriptstr,0) != 0 && is_hexstr(musigstr,0) != 0 ) + { + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + secp256k1_schnorrsig musig(ParseHex(musigstr)); + CScript scriptPubKey(ParseHex(scriptstr)); + if ( myGetTransaction(prevhash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) + { + vout.nValue = vintx.vout[0].nValue - txfee; + vout.scriptPubKey = scriptPubKey; + if ( musig_sendopretdecode(combined_pk,vintx.vouts[numvouts-1].scriptPubKey) == 'x' ) + { + msg = musig_prevoutmsg(prevhash,vout.scriptPubKey); + if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) + return(cclib_error(result,"musig didnt validate")); + mtx.vin.push_back(CTxIn(prevhash,MUSIG_PREVN)); + mtx.vout.push_back(vout); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_spendopret('y',combined_pk,musig)); + return(musig_rawtxresult(result,rawtx)); + } else return(cclib_error(result,"couldnt decode send opret")); + } else return(cclib_error(result,"couldnt find vin0")); + } else return(cclib_error(result,"script or musig is not hex")); + } else return(cclib_error(result,"need to have exactly 3 params prevhash, scriptPubKey, musig")); + } else return(cclib_error(result,"params parse error")); +} + +bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) +{ + static secp256k1_context *ctx; + secp256k1_pubkey combined_pk,checkpk; secp256k1_schnorrsig musig; uint256 msg,hashBlock; CTransaction vintx; int32_t numvouts; + if ( ctx == 0 ) + ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); + if ( tx.vout.size() != 2 ) + return eval->Invalid("numvouts != 2"); + else if ( tx.vin.size() != 1 ) + return eval->Invalid("numvins != 1"); + else if ( IsCCInput(tx.vin[0].scriptSig) == 0 ) + return eval->Invalid("illegal normal vin0"); + else if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) + { + if ( musig_sendopretdecode(combined_pk,vintx.vouts[numvouts-1].scriptPubKey) == 'x' ) + { + if ( musig_spendopretdecode(check_pk,musig,tx.vout[tx.vout.size()-1].scriptPubKey) == 'y' ) + { + if ( combined_pk == check_pk ) + { + msg = musig_prevoutmsg(tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); + if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) + return eval->Invalid("failed schnorrsig_verify"); + else return(true); + } else return eval->Invalid("combined_pk didnt match send opret"); + } else return eval->Invalid("failed decode musig spendopret"); + } else return eval->Invalid("couldnt decode send opret"); + } else return eval->Invalid("couldnt find vin0 tx"); +} diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 3d89e0568..8ca239c7b 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1078,7 +1078,7 @@ UniValue rogue_highlander(uint64_t txfee,struct CCcontract_info *cp,cJSON *param UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,gameheight,maxplayers,numvouts; uint256 txid; CTransaction tx; int64_t buyin; bits256 t; char myrogueaddr[64]; CPubKey mypk,roguepk; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,gameheight,maxplayers,numvouts; uint256 txid; CTransaction tx; int64_t buyin; uint64_t seed; bits256 t; char myrogueaddr[64]; CPubKey mypk,roguepk; result.push_back(Pair("name","rogue")); result.push_back(Pair("method","gameinfo")); if ( (params= cclib_reparse(&n,params)) != 0 ) @@ -1095,7 +1095,8 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) roguepk = GetUnspendable(cp,0); GetCCaddress1of2(cp,myrogueaddr,roguepk,mypk); //fprintf(stderr,"myrogueaddr.%s\n",myrogueaddr); - rogue_gamefields(result,maxplayers,buyin,txid,myrogueaddr); + seed = rogue_gamefields(result,maxplayers,buyin,txid,myrogueaddr); + result.push_back(Pair("seed",(int64_t)seed)); for (i=0; iInvalid("not enough vouts"); } -#include -#include -#include - From 998a2cf173f5b199d95c2b7ba71e032dee411ce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 07:17:05 -1100 Subject: [PATCH 04/69] CScript opret; uint8_t evalcode = EVAL_MUSIG; opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << combined_pk); --- src/cc/cclib.cpp | 2 +- src/cc/musig.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index ae3d88573..0d907d4ca 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -525,7 +525,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will newstr[j++] = '"'; i += 2; } - else if ( jsonstr[i] == ''' ) + else if ( jsonstr[i] == '\'' ) newstr[j++] = '"'; else newstr[j++] = jsonstr[i]; } diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 1a9d860cf..4696f7949 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -22,6 +22,7 @@ uint256 musig_msghash(uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) { + CScript data; std::vector data; uint256 hash; int32_t len = 0; data << E_MARSHAL(ss << prevhash << prevn << vout << combined_pk); fprintf(stderr,"data size %d\n",(int32_t)data.size()); From fdaf1fb297d1535d2016cbe15d171c3701e10b8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 07:21:15 -1100 Subject: [PATCH 05/69] syntax --- src/cc/musig.cpp | 232 +++++++++++++++++++++++------------------------ 1 file changed, 116 insertions(+), 116 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 4696f7949..12da40f1d 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -19,120 +19,7 @@ #include #define MUSIG_PREVN 0 // for now, just use vout0 for the musig output - -uint256 musig_msghash(uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) -{ - CScript data; - std::vector data; uint256 hash; int32_t len = 0; - data << E_MARSHAL(ss << prevhash << prevn << vout << combined_pk); -fprintf(stderr,"data size %d\n",(int32_t)data.size()); - vcalc_sha256(0,(uint8_t *)&hash,data.ptr(),data.size()); - return(hash); -} - -uint256 musig_prevoutmsg(uint256 sendtxid,CScript scriptPubKey) -{ - CTransaction vintx; uint256 hashBlock; int32_t numvouts; CTxOut vout; secp256k1_pubkey combined_pk; - if ( myGetTransaction(prevhash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) - { - if ( musig_sendopretdecode(combined_pk,vintx.vouts[numvouts-1].scriptPubKey) == 'x' ) - { - vout.nValue = vintx.vout[MUSIG_PREVN].nValue - txfee; - vout.scriptPubKey = scriptPubKey; - return(musig_msghash(prevhash,MUSIG_PREVN,vout,combined_pk)); - } - } - return(zeroid); -} - -UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); uint256 sendtxid,msg; char *scriptstr; int32_t n; - if ( (params= cclib_reparse(&n,params)) != 0 ) - { - if ( n == 2 ) - { - sendtxid = juint256(jitem(params,0)); - scriptstr = jstr(jitem(params,1),0); - if ( is_hexstr(scriptstr,0) != 0 ) - { - CScript scriptPubKey(ParseHex(scriptstr)); - msg = musig_prevoutmsg(sendtxid,scriptPubKey); - result.push_back("result","success"); - result.push_back("msg",msg.GetHex()); - return(result); - } else return(cclib_error(result,"script is not hex")); - } else return(cclib_error(result,"need exactly 2 parameters: sendtxid, scriptPubKey")); - } else return(cclib_error(result,"couldnt parse params")); -} - -UniValue musig_combine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -UniValue musig_partialsign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -UniValue musig_sigcombine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) -{ - UniValue result(UniValue::VOBJ); - result.push_back("result","success"); - return(result); -} - -// helpers for rpc calls that generate/validate onchain tx - -UniValue musig_rawtxresult(UniValue &result,std::string rawtx) -{ - CTransaction tx; - if ( rawtx.size() > 0 ) - { - result.push_back(Pair("hex",rawtx)); - if ( DecodeHexTx(tx,rawtx) != 0 ) - { - //if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) - // RelayTransaction(tx); - result.push_back(Pair("txid",tx.GetHash().ToString())); - result.push_back(Pair("result","success")); - } else result.push_back(Pair("error","decode hex")); - } else result.push_back(Pair("error","couldnt finalize CCtx")); - return(result); -} +#define MUSIG_TXFEE 10000 CScript musig_sendopret(uint8_t funcid,secp256k1_pubkey combined_pk) { @@ -170,12 +57,125 @@ uint8_t musig_spendopretdecode(secp256k1_pubkey &combined_pk,secp256k1_schnorrsi return(0); } +uint256 musig_msghash(uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) +{ + CScript data; uint256 hash; int32_t len = 0; + data << E_MARSHAL(ss << prevhash << prevn << vout << combined_pk); +fprintf(stderr,"data size %d\n",(int32_t)data.size()); + vcalc_sha256(0,(uint8_t *)&hash,data.data(),data.size()); + return(hash); +} + +uint256 musig_prevoutmsg(uint256 sendtxid,CScript scriptPubKey) +{ + CTransaction vintx; uint256 hashBlock; int32_t numvouts; CTxOut vout; secp256k1_pubkey combined_pk; + if ( myGetTransaction(sendtxid,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) + { + if ( musig_sendopretdecode(combined_pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) + { + vout.nValue = vintx.vout[MUSIG_PREVN].nValue - MUSIG_TXFEE; + vout.scriptPubKey = scriptPubKey; + return(musig_msghash(sendtxid,MUSIG_PREVN,vout,combined_pk)); + } + } + return(zeroid); +} + +UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); uint256 sendtxid,msg; char *scriptstr; int32_t n; + if ( (params= cclib_reparse(&n,params)) != 0 ) + { + if ( n == 2 ) + { + sendtxid = juint256(jitem(params,0)); + scriptstr = jstr(jitem(params,1),0); + if ( is_hexstr(scriptstr,0) != 0 ) + { + CScript scriptPubKey(ParseHex(scriptstr)); + msg = musig_prevoutmsg(sendtxid,scriptPubKey); + result.push_back(Pair("result","success")); + result.push_back(Pair("msg",msg.GetHex())); + return(result); + } else return(cclib_error(result,"script is not hex")); + } else return(cclib_error(result,"need exactly 2 parameters: sendtxid, scriptPubKey")); + } else return(cclib_error(result,"couldnt parse params")); +} + +UniValue musig_combine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +UniValue musig_partialsign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +UniValue musig_sigcombine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + result.push_back(Pair("result","success")); + return(result); +} + +// helpers for rpc calls that generate/validate onchain tx + +UniValue musig_rawtxresult(UniValue &result,std::string rawtx) +{ + CTransaction tx; + if ( rawtx.size() > 0 ) + { + result.push_back(Pair("hex",rawtx)); + if ( DecodeHexTx(tx,rawtx) != 0 ) + { + //if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) + // RelayTransaction(tx); + result.push_back(Pair("txid",tx.GetHash().ToString())); + result.push_back(Pair("result","success")); + } else result.push_back(Pair("error","decode hex")); + } else result.push_back(Pair("error","couldnt finalize CCtx")); + return(result); +} + UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); int32_t n; char *hexstr; std::string rawtx; int64_t amount; CPubKey musigpk,mypk; if ( txfee == 0 ) - txfee = 10000; + txfee = MUSIG_TXFEE; mypk = pubkey2pk(Mypubkey()); musigpk = GetUnspendable(cp,0); if ( (params= cclib_reparse(&n,params)) != 0 ) @@ -211,7 +211,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( is_hexstr(scriptstr,0) != 0 && is_hexstr(musigstr,0) != 0 ) { if ( txfee == 0 ) - txfee = 10000; + txfee = MUSIG_TXFEE; mypk = pubkey2pk(Mypubkey()); secp256k1_schnorrsig musig(ParseHex(musigstr)); CScript scriptPubKey(ParseHex(scriptstr)); From a2d6ae5e145cff32f35981f71229022785b272a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 07:28:27 -1100 Subject: [PATCH 06/69] Msg -> msg[32] --- src/cc/musig.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 12da40f1d..6d2a1f583 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -57,16 +57,15 @@ uint8_t musig_spendopretdecode(secp256k1_pubkey &combined_pk,secp256k1_schnorrsi return(0); } -uint256 musig_msghash(uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) +void musig_msghash(uint8_t *msg,uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) { CScript data; uint256 hash; int32_t len = 0; data << E_MARSHAL(ss << prevhash << prevn << vout << combined_pk); fprintf(stderr,"data size %d\n",(int32_t)data.size()); - vcalc_sha256(0,(uint8_t *)&hash,data.data(),data.size()); - return(hash); + vcalc_sha256(0,msg,data.data(),data.size()); } -uint256 musig_prevoutmsg(uint256 sendtxid,CScript scriptPubKey) +int32_t musig_prevoutmsg(uint8_t *msg,uint256 sendtxid,CScript scriptPubKey) { CTransaction vintx; uint256 hashBlock; int32_t numvouts; CTxOut vout; secp256k1_pubkey combined_pk; if ( myGetTransaction(sendtxid,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) @@ -75,7 +74,7 @@ uint256 musig_prevoutmsg(uint256 sendtxid,CScript scriptPubKey) { vout.nValue = vintx.vout[MUSIG_PREVN].nValue - MUSIG_TXFEE; vout.scriptPubKey = scriptPubKey; - return(musig_msghash(sendtxid,MUSIG_PREVN,vout,combined_pk)); + return(musig_msghash(msg,sendtxid,MUSIG_PREVN,vout,combined_pk)); } } return(zeroid); @@ -83,7 +82,7 @@ uint256 musig_prevoutmsg(uint256 sendtxid,CScript scriptPubKey) UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - UniValue result(UniValue::VOBJ); uint256 sendtxid,msg; char *scriptstr; int32_t n; + UniValue result(UniValue::VOBJ); uint256 sendtxid; int32_t i; uint8_t msg[32]; char *scriptstr,str[65]; int32_t n; if ( (params= cclib_reparse(&n,params)) != 0 ) { if ( n == 2 ) @@ -93,9 +92,12 @@ UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( is_hexstr(scriptstr,0) != 0 ) { CScript scriptPubKey(ParseHex(scriptstr)); - msg = musig_prevoutmsg(sendtxid,scriptPubKey); + musig_prevoutmsg(msg,sendtxid,scriptPubKey); result.push_back(Pair("result","success")); - result.push_back(Pair("msg",msg.GetHex())); + for (i=0; i<32; i++) + sprintf(&str[i<<1],"%02x",msg[i]); + str[64] = 0; + result.push_back(Pair("msg",str)); return(result); } else return(cclib_error(result,"script is not hex")); } else return(cclib_error(result,"need exactly 2 parameters: sendtxid, scriptPubKey")); @@ -198,7 +200,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { static secp256k1_context *ctx; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint256 msg,prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( (params= cclib_reparse(&n,params)) != 0 ) @@ -219,9 +221,9 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { vout.nValue = vintx.vout[0].nValue - txfee; vout.scriptPubKey = scriptPubKey; - if ( musig_sendopretdecode(combined_pk,vintx.vouts[numvouts-1].scriptPubKey) == 'x' ) + if ( musig_sendopretdecode(combined_pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { - msg = musig_prevoutmsg(prevhash,vout.scriptPubKey); + musig_prevoutmsg(msg,prevhash,vout.scriptPubKey); if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) return(cclib_error(result,"musig didnt validate")); mtx.vin.push_back(CTxIn(prevhash,MUSIG_PREVN)); @@ -238,7 +240,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static secp256k1_context *ctx; - secp256k1_pubkey combined_pk,checkpk; secp256k1_schnorrsig musig; uint256 msg,hashBlock; CTransaction vintx; int32_t numvouts; + secp256k1_pubkey combined_pk,checkpk; secp256k1_schnorrsig musig; uint256 hashBlock; CTransaction vintx; int32_t numvouts; uint8_t msg[32]; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( tx.vout.size() != 2 ) @@ -249,13 +251,13 @@ bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C return eval->Invalid("illegal normal vin0"); else if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) { - if ( musig_sendopretdecode(combined_pk,vintx.vouts[numvouts-1].scriptPubKey) == 'x' ) + if ( musig_sendopretdecode(combined_pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { - if ( musig_spendopretdecode(check_pk,musig,tx.vout[tx.vout.size()-1].scriptPubKey) == 'y' ) + if ( musig_spendopretdecode(checkpk,musig,tx.vout[tx.vout.size()-1].scriptPubKey) == 'y' ) { - if ( combined_pk == check_pk ) + if ( combined_pk == checkpk ) { - msg = musig_prevoutmsg(tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); + musig_prevoutmsg(msg,tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) return eval->Invalid("failed schnorrsig_verify"); else return(true); From 30edb30e4aca089bbe7fe59246ae1b0aeff35485 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 07:47:39 -1100 Subject: [PATCH 07/69] Serialize pk -> combined_pk --- src/cc/musig.cpp | 76 ++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 6d2a1f583..561851640 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -21,63 +21,65 @@ #define MUSIG_PREVN 0 // for now, just use vout0 for the musig output #define MUSIG_TXFEE 10000 -CScript musig_sendopret(uint8_t funcid,secp256k1_pubkey combined_pk) +CScript musig_sendopret(uint8_t funcid,CPubKey pk) { CScript opret; uint8_t evalcode = EVAL_MUSIG; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << combined_pk); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk); return(opret); } -uint8_t musig_sendopretdecode(secp256k1_pubkey &combined_pk,CScript scriptPubKey) +uint8_t musig_sendopretdecode(CPubKey &pk,CScript scriptPubKey) { std::vector vopret; uint8_t e,f; GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> combined_pk) != 0 && e == EVAL_MUSIG && f == 'x' ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk) != 0 && e == EVAL_MUSIG && f == 'x' ) { return(f); } return(0); } -CScript musig_spendopret(uint8_t funcid,secp256k1_pubkey combined_pk,secp256k1_schnorrsig musig) +CScript musig_spendopret(uint8_t funcid,CPubKey pk,secp256k1_schnorrsig musig) { CScript opret; uint8_t evalcode = EVAL_MUSIG; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << combined_pk << musig); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << musig); return(opret); } -uint8_t musig_spendopretdecode(secp256k1_pubkey &combined_pk,secp256k1_schnorrsig &musig,CScript scriptPubKey) +uint8_t musig_spendopretdecode(CPubKey &pk,secp256k1_schnorrsig &musig,CScript scriptPubKey) { std::vector vopret; uint8_t e,f; GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> combined_pk; ss >> musig) != 0 && e == EVAL_MUSIG && f == 'y' ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> musig) != 0 && e == EVAL_MUSIG && f == 'y' ) { return(f); } return(0); } -void musig_msghash(uint8_t *msg,uint256 prevhash,int32_t prevn,CTxOut vout,secp256k1_pubkey combined_pk) +int32_t musig_msghash(uint8_t *msg,uint256 prevhash,int32_t prevn,CTxOut vout,CPubKey pk) { CScript data; uint256 hash; int32_t len = 0; - data << E_MARSHAL(ss << prevhash << prevn << vout << combined_pk); + data << E_MARSHAL(ss << prevhash << prevn << vout << pk); fprintf(stderr,"data size %d\n",(int32_t)data.size()); - vcalc_sha256(0,msg,data.data(),data.size()); + vcalc_sha256(0,msg,data.begin(),data.size()); + return(0); } int32_t musig_prevoutmsg(uint8_t *msg,uint256 sendtxid,CScript scriptPubKey) { - CTransaction vintx; uint256 hashBlock; int32_t numvouts; CTxOut vout; secp256k1_pubkey combined_pk; + CTransaction vintx; uint256 hashBlock; int32_t numvouts; CTxOut vout; CPubKey pk; + memset(msg,0,32); if ( myGetTransaction(sendtxid,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) { - if ( musig_sendopretdecode(combined_pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) + if ( musig_sendopretdecode(pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { vout.nValue = vintx.vout[MUSIG_PREVN].nValue - MUSIG_TXFEE; vout.scriptPubKey = scriptPubKey; - return(musig_msghash(msg,sendtxid,MUSIG_PREVN,vout,combined_pk)); + return(musig_msghash(msg,sendtxid,MUSIG_PREVN,vout,pk)); } } - return(zeroid); + return(-1); } UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) @@ -184,15 +186,15 @@ UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { if ( n == 2 && (hexstr= jstr(jitem(params,0),0)) != 0 && is_hexstr(hexstr,0) == 66 ) { - secp256k1_pubkey combined_pk(ParseHex(hexstr)); + CPubKey pk(ParseHex(hexstr)); amount = jdouble(jitem(params,1),0) * COIN + 0.0000000049; if ( amount >= 3*txfee && AddNormalinputs(mtx,mypk,amount+2*txfee,64) >= amount+2*txfee ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount+txfee,musigpk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_sendopret('x',combined_pk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_sendopret('x',pk)); return(musig_rawtxresult(result,rawtx)); } else return(cclib_error(result,"couldnt find funds or less than 0.0003")); - } else return(cclib_error(result,"must have 2 params: combined_pk, amount")); + } else return(cclib_error(result,"must have 2 params: pk, amount")); } else return(cclib_error(result,"not enough parameters")); } @@ -200,7 +202,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { static secp256k1_context *ctx; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,pk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( (params= cclib_reparse(&n,params)) != 0 ) @@ -221,15 +223,18 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { vout.nValue = vintx.vout[0].nValue - txfee; vout.scriptPubKey = scriptPubKey; - if ( musig_sendopretdecode(combined_pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) + if ( musig_sendopretdecode(pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { - musig_prevoutmsg(msg,prevhash,vout.scriptPubKey); - if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) - return(cclib_error(result,"musig didnt validate")); - mtx.vin.push_back(CTxIn(prevhash,MUSIG_PREVN)); - mtx.vout.push_back(vout); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_spendopret('y',combined_pk,musig)); - return(musig_rawtxresult(result,rawtx)); + if ( secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) + { + musig_prevoutmsg(msg,prevhash,vout.scriptPubKey); + if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) + return(cclib_error(result,"musig didnt validate")); + mtx.vin.push_back(CTxIn(prevhash,MUSIG_PREVN)); + mtx.vout.push_back(vout); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_spendopret('y',pk,musig)); + return(musig_rawtxresult(result,rawtx)); + } else return(cclib_error(result,"couldnt parse pk")); } else return(cclib_error(result,"couldnt decode send opret")); } else return(cclib_error(result,"couldnt find vin0")); } else return(cclib_error(result,"script or musig is not hex")); @@ -240,7 +245,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static secp256k1_context *ctx; - secp256k1_pubkey combined_pk,checkpk; secp256k1_schnorrsig musig; uint256 hashBlock; CTransaction vintx; int32_t numvouts; uint8_t msg[32]; + secp256k1_pubkey combined_pk; CPubKey pk,checkpk; secp256k1_schnorrsig musig; uint256 hashBlock; CTransaction vintx; int32_t numvouts; uint8_t msg[32]; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( tx.vout.size() != 2 ) @@ -251,16 +256,19 @@ bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C return eval->Invalid("illegal normal vin0"); else if ( myGetTransaction(tx.vin[0].prevout.hash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) { - if ( musig_sendopretdecode(combined_pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) + if ( musig_sendopretdecode(pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { if ( musig_spendopretdecode(checkpk,musig,tx.vout[tx.vout.size()-1].scriptPubKey) == 'y' ) { - if ( combined_pk == checkpk ) + if ( pk == checkpk ) { - musig_prevoutmsg(msg,tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); - if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) - return eval->Invalid("failed schnorrsig_verify"); - else return(true); + if ( secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) + { + musig_prevoutmsg(msg,tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); + if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) + return eval->Invalid("failed schnorrsig_verify"); + else return(true); + } else return eval->Invalid("couldnt parse pk"); } else return eval->Invalid("combined_pk didnt match send opret"); } else return eval->Invalid("failed decode musig spendopret"); } else return eval->Invalid("couldnt decode send opret"); From 8de3c71baa8ab11903439d50f8e0191a326ce112 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 07:56:45 -1100 Subject: [PATCH 08/69] musig64 --- src/cc/musig.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 561851640..64d7528b6 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -39,18 +39,18 @@ uint8_t musig_sendopretdecode(CPubKey &pk,CScript scriptPubKey) return(0); } -CScript musig_spendopret(uint8_t funcid,CPubKey pk,secp256k1_schnorrsig musig) +CScript musig_spendopret(uint8_t funcid,CPubKey pk,std::vector musig64) { CScript opret; uint8_t evalcode = EVAL_MUSIG; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << musig); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << musig64); return(opret); } -uint8_t musig_spendopretdecode(CPubKey &pk,secp256k1_schnorrsig &musig,CScript scriptPubKey) +uint8_t musig_spendopretdecode(CPubKey &pk,std::vector &musig64,CScript scriptPubKey) { std::vector vopret; uint8_t e,f; GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> musig) != 0 && e == EVAL_MUSIG && f == 'y' ) + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> musig64) != 0 && e == EVAL_MUSIG && f == 'y' ) { return(f); } @@ -62,7 +62,7 @@ int32_t musig_msghash(uint8_t *msg,uint256 prevhash,int32_t prevn,CTxOut vout,CP CScript data; uint256 hash; int32_t len = 0; data << E_MARSHAL(ss << prevhash << prevn << vout << pk); fprintf(stderr,"data size %d\n",(int32_t)data.size()); - vcalc_sha256(0,msg,data.begin(),data.size()); + vcalc_sha256(0,msg,data.begin(),(int32_t)data.size()); return(0); } @@ -212,12 +212,12 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) prevhash = juint256(jitem(params,0)); scriptstr = jstr(jitem(params,1),0); musigstr = jstr(jitem(params,2),0); - if ( is_hexstr(scriptstr,0) != 0 && is_hexstr(musigstr,0) != 0 ) + if ( is_hexstr(scriptstr,0) != 0 && is_hexstr(musigstr,0) != 128 ) { if ( txfee == 0 ) txfee = MUSIG_TXFEE; mypk = pubkey2pk(Mypubkey()); - secp256k1_schnorrsig musig(ParseHex(musigstr)); + std::vector musig64(ParseHex(musigstr)); CScript scriptPubKey(ParseHex(scriptstr)); if ( myGetTransaction(prevhash,vintx,hashBlock) != 0 && (numvouts= vintx.vout.size()) > 1 ) { @@ -225,16 +225,17 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) vout.scriptPubKey = scriptPubKey; if ( musig_sendopretdecode(pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { - if ( secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) + if ( secp256k1_schnorrsig_parse(ctx,&musig,&musig64[0]) > 0 && + secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) { musig_prevoutmsg(msg,prevhash,vout.scriptPubKey); if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) return(cclib_error(result,"musig didnt validate")); mtx.vin.push_back(CTxIn(prevhash,MUSIG_PREVN)); mtx.vout.push_back(vout); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_spendopret('y',pk,musig)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,musig_spendopret('y',pk,musig64)); return(musig_rawtxresult(result,rawtx)); - } else return(cclib_error(result,"couldnt parse pk")); + } else return(cclib_error(result,"couldnt parse pk or musig")); } else return(cclib_error(result,"couldnt decode send opret")); } else return(cclib_error(result,"couldnt find vin0")); } else return(cclib_error(result,"script or musig is not hex")); @@ -245,7 +246,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { static secp256k1_context *ctx; - secp256k1_pubkey combined_pk; CPubKey pk,checkpk; secp256k1_schnorrsig musig; uint256 hashBlock; CTransaction vintx; int32_t numvouts; uint8_t msg[32]; + secp256k1_pubkey combined_pk; CPubKey pk,checkpk; secp256k1_schnorrsig musig; uint256 hashBlock; CTransaction vintx; int32_t numvouts; std::vector musig64; uint8_t msg[32]; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( tx.vout.size() != 2 ) @@ -258,17 +259,18 @@ bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C { if ( musig_sendopretdecode(pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { - if ( musig_spendopretdecode(checkpk,musig,tx.vout[tx.vout.size()-1].scriptPubKey) == 'y' ) + if ( musig_spendopretdecode(checkpk,musig64,tx.vout[tx.vout.size()-1].scriptPubKey) == 'y' ) { if ( pk == checkpk ) { - if ( secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) + if ( secp256k1_schnorrsig_parse(ctx,&musig,&musig64[0]) > 0 && + secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) { musig_prevoutmsg(msg,tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) return eval->Invalid("failed schnorrsig_verify"); else return(true); - } else return eval->Invalid("couldnt parse pk"); + } else return eval->Invalid("couldnt parse pk or musig"); } else return eval->Invalid("combined_pk didnt match send opret"); } else return eval->Invalid("failed decode musig spendopret"); } else return eval->Invalid("couldnt decode send opret"); From 6ed384ff471be6653e0084f7b8fcf0e524e6611e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:07:05 -1100 Subject: [PATCH 09/69] Fixes --- src/cc/musig.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 64d7528b6..c12866865 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -62,7 +62,8 @@ int32_t musig_msghash(uint8_t *msg,uint256 prevhash,int32_t prevn,CTxOut vout,CP CScript data; uint256 hash; int32_t len = 0; data << E_MARSHAL(ss << prevhash << prevn << vout << pk); fprintf(stderr,"data size %d\n",(int32_t)data.size()); - vcalc_sha256(0,msg,data.begin(),(int32_t)data.size()); + hash = Hash(data.begin(),data.end()); + memcpy(msg,&hash,sizeof(hash)); return(0); } @@ -202,7 +203,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { static secp256k1_context *ctx; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,pk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,pk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; secp256k1_schnorrsig musig; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( (params= cclib_reparse(&n,params)) != 0 ) From fb69ddb0c66c37f949b3e007720162344c7e4b8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:12:36 -1100 Subject: [PATCH 10/69] Add modules --- src/secp256k1/Makefile.am | 5 ----- src/secp256k1/src/secp256k1.c | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/secp256k1/Makefile.am b/src/secp256k1/Makefile.am index 676415834..089d3ee8e 100644 --- a/src/secp256k1/Makefile.am +++ b/src/secp256k1/Makefile.am @@ -174,11 +174,6 @@ if ENABLE_MODULE_ECDH include src/modules/ecdh/Makefile.am.include endif -#if ENABLE_MODULE_MUSIG -include src/modules/schnorrsig/Makefile.am.include -include src/modules/musig/Makefile.am.include -#endif - if ENABLE_MODULE_RECOVERY include src/modules/recovery/Makefile.am.include endif diff --git a/src/secp256k1/src/secp256k1.c b/src/secp256k1/src/secp256k1.c index b89a7c04a..2cf57856b 100644 --- a/src/secp256k1/src/secp256k1.c +++ b/src/secp256k1/src/secp256k1.c @@ -580,6 +580,12 @@ int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey * # include "modules/ecdh/main_impl.h" #endif +#ifdef ENABLE_MODULE_MUSIG +#include "modules/schnorrsig/main_impl.h" +#include "modules/musig/main_impl.h" +#endif + + #ifdef ENABLE_MODULE_RECOVERY # include "modules/recovery/main_impl.h" #endif From 88d08c07fa1ebce2f59216f2719014e198a41d2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:17:34 -1100 Subject: [PATCH 11/69] secp256k1_nonce_function_bipschnorr --- src/secp256k1/src/secp256k1.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/secp256k1/src/secp256k1.c b/src/secp256k1/src/secp256k1.c index 2cf57856b..fbff4b3aa 100644 --- a/src/secp256k1/src/secp256k1.c +++ b/src/secp256k1/src/secp256k1.c @@ -340,6 +340,27 @@ static int nonce_function_rfc6979(unsigned char *nonce32, const unsigned char *m return 1; } +/* This nonce function is described in BIP-schnorr + * (https://github.com/sipa/bips/blob/bip-schnorr/bip-schnorr.mediawiki) */ +static int secp256k1_nonce_function_bipschnorr(unsigned char *nonce32, const unsigned char *msg32, const unsigned char *key32, const unsigned char *algo16, void *data, unsigned int counter) { + secp256k1_sha256 sha; + (void) data; + (void) counter; + VERIFY_CHECK(counter == 0); + + /* Hash x||msg as per the spec */ + secp256k1_sha256_initialize(&sha); + secp256k1_sha256_write(&sha, key32, 32); + secp256k1_sha256_write(&sha, msg32, 32); + /* Hash in algorithm, which is not in the spec, but may be critical to + * users depending on it to avoid nonce reuse across algorithms. */ + if (algo16 != NULL) { + secp256k1_sha256_write(&sha, algo16, 16); + } + secp256k1_sha256_finalize(&sha, nonce32); + return 1; +} + const secp256k1_nonce_function secp256k1_nonce_function_rfc6979 = nonce_function_rfc6979; const secp256k1_nonce_function secp256k1_nonce_function_default = nonce_function_rfc6979; From 6adebc5e7bf3a82cfbaf8b0b35e06df8a4cbaf6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:19:37 -1100 Subject: [PATCH 12/69] Test --- src/secp256k1/src/modules/schnorrsig/main_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index b366236d8..6ccec1523 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -10,7 +10,7 @@ #include "include/secp256k1.h" #include "include/secp256k1_schnorrsig.h" #include "hash.h" - +hello int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; VERIFY_CHECK(ctx != NULL); From 0a433f453bd4098de592b12219f545655aa04c06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:20:59 -1100 Subject: [PATCH 13/69] ENABLE_MODULE_MUSIG --- src/secp256k1/src/modules/schnorrsig/main_impl.h | 2 +- src/secp256k1/src/secp256k1.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index 6ccec1523..b366236d8 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -10,7 +10,7 @@ #include "include/secp256k1.h" #include "include/secp256k1_schnorrsig.h" #include "hash.h" -hello + int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; VERIFY_CHECK(ctx != NULL); diff --git a/src/secp256k1/src/secp256k1.c b/src/secp256k1/src/secp256k1.c index fbff4b3aa..1f04af395 100644 --- a/src/secp256k1/src/secp256k1.c +++ b/src/secp256k1/src/secp256k1.c @@ -4,6 +4,7 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ +#define ENABLE_MODULE_MUSIG #include "include/secp256k1.h" #include "util.h" From 965abd3d526caa3f87188cb62836b29a9f798115 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:23:06 -1100 Subject: [PATCH 14/69] Force include --- src/secp256k1/src/secp256k1.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/secp256k1/src/secp256k1.c b/src/secp256k1/src/secp256k1.c index 1f04af395..4c24c1084 100644 --- a/src/secp256k1/src/secp256k1.c +++ b/src/secp256k1/src/secp256k1.c @@ -4,7 +4,6 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#define ENABLE_MODULE_MUSIG #include "include/secp256k1.h" #include "util.h" @@ -602,10 +601,10 @@ int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey * # include "modules/ecdh/main_impl.h" #endif -#ifdef ENABLE_MODULE_MUSIG +//#ifdef ENABLE_MODULE_MUSIG #include "modules/schnorrsig/main_impl.h" #include "modules/musig/main_impl.h" -#endif +//#endif #ifdef ENABLE_MODULE_RECOVERY From 5944b3e64fce54a06a5dbbe971fac12c617645cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:25:10 -1100 Subject: [PATCH 15/69] Test --- src/secp256k1/src/secp256k1.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/secp256k1/src/secp256k1.c b/src/secp256k1/src/secp256k1.c index 4c24c1084..1c7b75bc5 100644 --- a/src/secp256k1/src/secp256k1.c +++ b/src/secp256k1/src/secp256k1.c @@ -601,10 +601,8 @@ int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey * # include "modules/ecdh/main_impl.h" #endif -//#ifdef ENABLE_MODULE_MUSIG #include "modules/schnorrsig/main_impl.h" #include "modules/musig/main_impl.h" -//#endif #ifdef ENABLE_MODULE_RECOVERY From 8de28666e0e18373444888d390be2ded4ea2795e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:34:19 -1100 Subject: [PATCH 16/69] $(LIBSECP256K1) --- src/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 395ff0352..22668c91f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -574,9 +574,9 @@ komodod_LDADD += \ $(LIBZCASH_LIBS) if TARGET_DARWIN -komodod_LDADD += libcc.dylib +komodod_LDADD += libcc.dylib $(LIBSECP256K1) else -komodod_LDADD += libcc.so +komodod_LDADD += libcc.so $(LIBSECP256K1) endif From 9ca5858eebdca923517dd5e786c6d63034dd2bcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:41:10 -1100 Subject: [PATCH 17/69] Include secp --- src/cc/cclib.cpp | 1 + src/cc/makecclib | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 0d907d4ca..f02d63dbd 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -579,6 +579,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #else #include "sudoku.cpp" +#include "../secp256k1/src/secp256k1.c" #include "musig.cpp" #endif diff --git a/src/cc/makecclib b/src/cc/makecclib index 832cf1e96..871569325 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1,2 +1,2 @@ #!/bin/sh -gcc -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../libcc.so cclib.cpp +gcc -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../libcc.so cclib.cpp ../secp256k1/libsecp256k1.la From 38e67bca763fed2b6d2b618d5089019ac1b145fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:45:05 -1100 Subject: [PATCH 18/69] ../include --- src/cc/makecclib | 2 +- src/secp256k1/src/secp256k1.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/makecclib b/src/cc/makecclib index 871569325..f4d2bd01b 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1,2 +1,2 @@ #!/bin/sh -gcc -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../libcc.so cclib.cpp ../secp256k1/libsecp256k1.la +gcc -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o ../libcc.so cclib.cpp diff --git a/src/secp256k1/src/secp256k1.c b/src/secp256k1/src/secp256k1.c index 1c7b75bc5..657893d0d 100644 --- a/src/secp256k1/src/secp256k1.c +++ b/src/secp256k1/src/secp256k1.c @@ -4,7 +4,7 @@ * file COPYING or http://www.opensource.org/licenses/mit-license.php.* **********************************************************************/ -#include "include/secp256k1.h" +#include "../include/secp256k1.h" #include "util.h" #include "num_impl.h" From b82b61d772c9b321ff662b49a888d8464051a8fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:50:03 -1100 Subject: [PATCH 19/69] -DSECP256K1_BUILD --- src/cc/cclib.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index f02d63dbd..3cfb1a185 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -579,6 +579,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #else #include "sudoku.cpp" +#define SECP256K1_BUILD #include "../secp256k1/src/secp256k1.c" #include "musig.cpp" #endif From 8ce89adfe711d8972d72c48b4cd8442cd65ca349 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:55:49 -1100 Subject: [PATCH 20/69] Basic-config --- src/cc/cclib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 3cfb1a185..88fa9b554 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -579,7 +579,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #else #include "sudoku.cpp" -#define SECP256K1_BUILD +#include "../secp256k1/src/basic-config.h" #include "../secp256k1/src/secp256k1.c" #include "musig.cpp" #endif From d745071b2abc938668eaea61517a00fcb35c332a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 08:59:00 -1100 Subject: [PATCH 21/69] USE_BASIC_CONFIG --- src/cc/cclib.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 88fa9b554..1fc8c45a7 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -579,6 +579,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #else #include "sudoku.cpp" +#define USE_BASIC_CONFIG #include "../secp256k1/src/basic-config.h" #include "../secp256k1/src/secp256k1.c" #include "musig.cpp" From 5d7ffa476033156a598430775e57e6992e839e66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:01:29 -1100 Subject: [PATCH 22/69] ../../.. --- src/secp256k1/src/modules/musig/main_impl.h | 4 ++-- src/secp256k1/src/modules/schnorrsig/main_impl.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/secp256k1/src/modules/musig/main_impl.h b/src/secp256k1/src/modules/musig/main_impl.h index dece823d6..8bd2f1831 100644 --- a/src/secp256k1/src/modules/musig/main_impl.h +++ b/src/secp256k1/src/modules/musig/main_impl.h @@ -8,8 +8,8 @@ #ifndef _SECP256K1_MODULE_MUSIG_MAIN_ #define _SECP256K1_MODULE_MUSIG_MAIN_ -#include "include/secp256k1.h" -#include "include/secp256k1_musig.h" +#include "../../../include/secp256k1.h" +#include "../../../include/secp256k1_musig.h" #include "hash.h" /* Computes ell = SHA256(pk[0], ..., pk[np-1]) */ diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index b366236d8..f2b418159 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -7,8 +7,8 @@ #ifndef _SECP256K1_MODULE_SCHNORRSIG_MAIN_ #define _SECP256K1_MODULE_SCHNORRSIG_MAIN_ -#include "include/secp256k1.h" -#include "include/secp256k1_schnorrsig.h" +#include "../../../include/secp256k1.h" +#include "../../../include/secp256k1_schnorrsig.h" #include "hash.h" int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { From 96c6f295339ddb1f9f5f92b55e41fa4b33ec4ea4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:06:09 -1100 Subject: [PATCH 23/69] Define funds --- src/secp256k1/src/modules/schnorrsig/main_impl.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index f2b418159..9a08e81d8 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -11,6 +11,9 @@ #include "../../../include/secp256k1_schnorrsig.h" #include "hash.h" +static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx); +static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n); + int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; VERIFY_CHECK(ctx != NULL); From 23a530ae4ebb7dc2f23c06aeecce591a9fc2c117 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:09:43 -1100 Subject: [PATCH 24/69] static int secp256k1_musig_pubkey_combine_callback(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data) --- src/secp256k1/src/modules/schnorrsig/main_impl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index 9a08e81d8..00f241020 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -13,6 +13,7 @@ static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx); static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n); +typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data); int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; From c1264e8ddb42fae26bb3c128ae204391416706e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:12:08 -1100 Subject: [PATCH 25/69] Reorder --- src/secp256k1/src/modules/schnorrsig/main_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index 00f241020..2eb939f55 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -11,9 +11,9 @@ #include "../../../include/secp256k1_schnorrsig.h" #include "hash.h" +typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data); static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx); static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n); -typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data); int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; From dfb71e518242d8ea2bef87a9cb2647e5915c1542 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:14:59 -1100 Subject: [PATCH 26/69] e tes --- src/cc/cclib.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 1fc8c45a7..33b76ff91 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -579,9 +579,9 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will #else #include "sudoku.cpp" -#define USE_BASIC_CONFIG -#include "../secp256k1/src/basic-config.h" -#include "../secp256k1/src/secp256k1.c" +//#define USE_BASIC_CONFIG +//#include "../secp256k1/src/basic-config.h" +//#include "../secp256k1/src/secp256k1.c" #include "musig.cpp" #endif From e4494dc1207d38a16a26166c760c417b8bab1197 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:16:35 -1100 Subject: [PATCH 27/69] Test --- src/cc/musig.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index c12866865..34561d820 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -14,9 +14,9 @@ ******************************************************************************/ -#include -#include -#include +#include "../secp256k1/include/secp256k1.h" +#include "../secp256k1/include/secp256k1_schnorrsig.h" +#include "../secp256k1/include/secp256k1_musig.h" #define MUSIG_PREVN 0 // for now, just use vout0 for the musig output #define MUSIG_TXFEE 10000 From 60122c9eeca2a91331eae3ed8dd50c8369552fbe Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:23:32 -1100 Subject: [PATCH 28/69] (const uint8_t *) --- src/cc/musig.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 34561d820..800102e13 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -226,11 +226,11 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) vout.scriptPubKey = scriptPubKey; if ( musig_sendopretdecode(pk,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { - if ( secp256k1_schnorrsig_parse(ctx,&musig,&musig64[0]) > 0 && + if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) { musig_prevoutmsg(msg,prevhash,vout.scriptPubKey); - if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) + if ( !secp256k1_schnorrsig_verify((const secp256k1_context *)ctx,&musig,(const uint8_t *)msg,(const secp256k1_pubkey *)&combined_pk) ) return(cclib_error(result,"musig didnt validate")); mtx.vin.push_back(CTxIn(prevhash,MUSIG_PREVN)); mtx.vout.push_back(vout); @@ -264,11 +264,11 @@ bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C { if ( pk == checkpk ) { - if ( secp256k1_schnorrsig_parse(ctx,&musig,&musig64[0]) > 0 && + if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) { musig_prevoutmsg(msg,tx.vin[0].prevout.hash,tx.vout[0].scriptPubKey); - if ( !secp256k1_schnorrsig_verify(ctx,&musig,msg,&combined_pk) ) + if ( !secp256k1_schnorrsig_verify((const secp256k1_context *)ctx,&musig,(const uint8_t *)msg,(const secp256k1_pubkey *)&combined_pk) ) return eval->Invalid("failed schnorrsig_verify"); else return(true); } else return eval->Invalid("couldnt parse pk or musig"); From 6cdecbe7f78ddf29eeab4368f150dbeb7a302e7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:30:27 -1100 Subject: [PATCH 29/69] Pull in schnorr --- src/komodo_gateway.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 02ab67407..35952bebf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,6 +16,17 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" +#include "secp256k1/include/secp256k1.h" +#include "secp256k1/include/secp256k1_schnorrsig.h" +#include "secp256k1/include/secp256k1_musig.h" + +void dummy_linker_tricker() +{ + secp256k1_context *ctx = 0; std::vector musig64; CPubKey pk; secp256k1_schnorrsig musig; secp256k1_pubkey combined_pk; + if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) + return(1); +} + int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) From bb07e87c4a993b12b0fc43c91b0bf677f15e185b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:31:44 -1100 Subject: [PATCH 30/69] Int32 --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 35952bebf..5dd9907c9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,7 +20,7 @@ #include "secp256k1/include/secp256k1_schnorrsig.h" #include "secp256k1/include/secp256k1_musig.h" -void dummy_linker_tricker() +int32_t dummy_linker_tricker() { secp256k1_context *ctx = 0; std::vector musig64; CPubKey pk; secp256k1_schnorrsig musig; secp256k1_pubkey combined_pk; if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) From befefc81c9e22b9f1a191ee3d5012dcf26113254 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:34:07 -1100 Subject: [PATCH 31/69] Test --- src/komodo_gateway.h | 4 ++-- src/secp256k1/src/modules/schnorrsig/main_impl.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5dd9907c9..68e648b14 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,7 +16,7 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" -#include "secp256k1/include/secp256k1.h" +/*#include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_schnorrsig.h" #include "secp256k1/include/secp256k1_musig.h" @@ -25,7 +25,7 @@ int32_t dummy_linker_tricker() secp256k1_context *ctx = 0; std::vector musig64; CPubKey pk; secp256k1_schnorrsig musig; secp256k1_pubkey combined_pk; if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) return(1); -} +}*/ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index 2eb939f55..925c49d2a 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -25,6 +25,7 @@ int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char * } int secp256k1_schnorrsig_parse(const secp256k1_context* ctx, secp256k1_schnorrsig* sig, const unsigned char *in64) { + parse is here (void) ctx; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); From 0fe4fdd07cbac8b174db05227f398315be1690ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:43:00 -1100 Subject: [PATCH 32/69] Disable for now --- src/cc/cclib.cpp | 2 +- src/secp256k1/src/modules/schnorrsig/main_impl.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 33b76ff91..75dd13fa2 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -582,6 +582,6 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will //#define USE_BASIC_CONFIG //#include "../secp256k1/src/basic-config.h" //#include "../secp256k1/src/secp256k1.c" -#include "musig.cpp" +//#include "musig.cpp" #endif diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index 925c49d2a..2eb939f55 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -25,7 +25,6 @@ int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char * } int secp256k1_schnorrsig_parse(const secp256k1_context* ctx, secp256k1_schnorrsig* sig, const unsigned char *in64) { - parse is here (void) ctx; VERIFY_CHECK(ctx != NULL); ARG_CHECK(sig != NULL); From 33c9f37abe0da91e990047e3204c0f989cb713af Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:45:12 -1100 Subject: [PATCH 33/69] Enable --- src/cc/cclib.cpp | 2 +- src/secp256k1/src/modules/schnorrsig/main_impl.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 75dd13fa2..33b76ff91 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -582,6 +582,6 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will //#define USE_BASIC_CONFIG //#include "../secp256k1/src/basic-config.h" //#include "../secp256k1/src/secp256k1.c" -//#include "musig.cpp" +#include "musig.cpp" #endif diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index 2eb939f55..a99897d2c 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -11,9 +11,9 @@ #include "../../../include/secp256k1_schnorrsig.h" #include "hash.h" -typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data); -static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx); -static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n); +//typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data); +//static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx); +//static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n); int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; From 3c802c4a0219207903151d7ca483665a749d37a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 09:53:09 -1100 Subject: [PATCH 34/69] -// --- src/secp256k1/src/modules/schnorrsig/main_impl.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/secp256k1/src/modules/schnorrsig/main_impl.h b/src/secp256k1/src/modules/schnorrsig/main_impl.h index a99897d2c..f2b418159 100644 --- a/src/secp256k1/src/modules/schnorrsig/main_impl.h +++ b/src/secp256k1/src/modules/schnorrsig/main_impl.h @@ -11,10 +11,6 @@ #include "../../../include/secp256k1_schnorrsig.h" #include "hash.h" -//typedef int (secp256k1_ecmult_multi_callback)(secp256k1_scalar *sc, secp256k1_ge *pt, size_t idx, void *data); -//static void secp256k1_scalar_chacha20(secp256k1_scalar *r1, secp256k1_scalar *r2, const unsigned char *seed, uint64_t idx); -//static int secp256k1_ecmult_multi_var(const secp256k1_ecmult_context *ctx, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n); - int secp256k1_schnorrsig_serialize(const secp256k1_context* ctx, unsigned char *out64, const secp256k1_schnorrsig* sig) { (void) ctx; VERIFY_CHECK(ctx != NULL); From ea3e9ee36a7fb89f48aecc824ce18050de53848c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 10:01:21 -1100 Subject: [PATCH 35/69] Parse --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 68e648b14..5dd9907c9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,7 +16,7 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" -/*#include "secp256k1/include/secp256k1.h" +#include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_schnorrsig.h" #include "secp256k1/include/secp256k1_musig.h" @@ -25,7 +25,7 @@ int32_t dummy_linker_tricker() secp256k1_context *ctx = 0; std::vector musig64; CPubKey pk; secp256k1_schnorrsig musig; secp256k1_pubkey combined_pk; if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) return(1); -}*/ +} int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); From 5280af8c12010d7cc7929651fc7d92337d4a2368 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 10:13:16 -1100 Subject: [PATCH 36/69] Revert --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5dd9907c9..68e648b14 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,7 +16,7 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" -#include "secp256k1/include/secp256k1.h" +/*#include "secp256k1/include/secp256k1.h" #include "secp256k1/include/secp256k1_schnorrsig.h" #include "secp256k1/include/secp256k1_musig.h" @@ -25,7 +25,7 @@ int32_t dummy_linker_tricker() secp256k1_context *ctx = 0; std::vector musig64; CPubKey pk; secp256k1_schnorrsig musig; secp256k1_pubkey combined_pk; if ( secp256k1_schnorrsig_parse((const secp256k1_context *)ctx,&musig,(const uint8_t *)&musig64[0]) > 0 && secp256k1_ec_pubkey_parse(ctx,&combined_pk,pk.begin(),33) > 0 ) return(1); -} +}*/ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); From 0594b52df25a3b8096ac18e99ed02f283c8d320a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 20:33:13 -1100 Subject: [PATCH 37/69] Big buffer --- .gitignore | 10 ++++++++++ src/cc/rogue/init.c | 1 + src/cc/rogue/io.c | 12 ++++++++++++ src/cc/rogue/rip.c | 2 +- src/cc/rogue/rogue.c | 2 +- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ebaa71f4d..2f97780ab 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,13 @@ src/cc/rogue/rogue src/cc/rogue/rogue.so src/cc/rogue/test.zip + +src/rogue.530623577502174316.0 + +src/rogue.530623577502174316.pack + +src/rogue.530623577502174316.player + +src/checkfile + +src/log diff --git a/src/cc/rogue/init.c b/src/cc/rogue/init.c index ffc0b3707..b11cfa80c 100644 --- a/src/cc/rogue/init.c +++ b/src/cc/rogue/init.c @@ -34,6 +34,7 @@ void restore_player(struct rogue_state *rs) int32_t i,total = 0; THING *obj; //rs->P.gold = purse; max_hp = rs->P.hitpoints; + //pstats.s_hpt = max_hp; pstats.s_str = rs->P.strength & 0xffff; if ( (max_stats.s_str= (rs->P.strength >> 16) & 0xffff) == 0 ) max_stats.s_str = 16; diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index 9842ba353..994f112e2 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -160,6 +160,18 @@ readchar(struct rogue_state *rs) if ( rs->ind < rs->numkeys ) { c = rs->keystrokes[rs->ind++]; + if ( 0 ) + { + 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); + fflush(fp); + counter++; + } + } while ( c == 'Q' && rs->ind < rs->numkeys ) { //fprintf(stderr,"Got 'Q' next (%c)\n",rs->keystrokes[rs->ind]); sleep(2); diff --git a/src/cc/rogue/rip.c b/src/cc/rogue/rip.c index 65be2e8fa..1866f0b48 100644 --- a/src/cc/rogue/rip.c +++ b/src/cc/rogue/rip.c @@ -238,7 +238,7 @@ death(struct rogue_state *rs,char monst) //struct tm *localtime(const time_t *); if ( rs->guiflag == 0 ) { - fprintf(stderr,"death during replay\n"); + fprintf(stderr,"death during replay by (%c)\n",monst); //sleep(3); rs->replaydone = (uint32_t)time(NULL); return; } diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 92d3ad378..2f4545585 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -607,7 +607,7 @@ playit(struct rogue_state *rs) } else { - if ( rs->needflush != 0 && rs->num > 1024 ) + if ( rs->needflush != 0 && rs->num > 8000 ) { if ( flushkeystrokes(rs) == 0 ) rs->needflush = 0; From 23caa3477367a08556128a329ffd1ba602591fef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 21:33:25 -1100 Subject: [PATCH 38/69] Allow zombies --- .gitignore | 2 + src/cc/rogue/main.c | 514 +++++++++++++++++++++++++++++++++++++++++++ src/cc/rogue/rogue.c | 71 +----- src/cc/rogue/rogue.h | 4 +- src/cc/rogue/state.c | 2 +- src/cc/rogue_rpc.cpp | 2 +- 6 files changed, 526 insertions(+), 69 deletions(-) diff --git a/.gitignore b/.gitignore index 2f97780ab..0d0846e31 100644 --- a/.gitignore +++ b/.gitignore @@ -142,3 +142,5 @@ src/rogue.530623577502174316.player src/checkfile src/log + +src/foo.zip diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index c0fa36752..1131e3429 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -20,10 +20,17 @@ #include #include #include +#include +#include + +char USERPASS[8192]; +char Gametxidstr[67]; #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +#define KOMODO_ASSETCHAIN_MAXLEN 65 +#define ASSETCHAINS_SYMBOL "ROGUE" #ifndef _BITS256 #define _BITS256 @@ -31,6 +38,15 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin typedef union _bits256 bits256; #endif +double OS_milliseconds() +{ + struct timeval tv; double millis; + gettimeofday(&tv,NULL); + millis = ((double)tv.tv_sec * 1000. + (double)tv.tv_usec / 1000.); + //printf("tv_sec.%ld usec.%d %f\n",tv.tv_sec,tv.tv_usec,millis); + return(millis); +} + int32_t _unhex(char c) { if ( c >= '0' && c <= '9' ) @@ -167,6 +183,23 @@ char *clonestr(char *str) strcpy(clone,str); return(clone); } + +char *parse_conf_line(char *line,char *field) +{ + line += strlen(field); + for (; *line!='='&&*line!=0; line++) + break; + if ( *line == 0 ) + return(0); + if ( *line == '=' ) + line++; + while ( line[strlen(line)-1] == '\r' || line[strlen(line)-1] == '\n' || line[strlen(line)-1] == ' ' ) + line[strlen(line)-1] = 0; + //printf("LINE.(%s)\n",line); + _stripwhite(line,0); + return(clonestr(line)); +} + int32_t safecopy(char *dest,char *src,long len) { int32_t i = -1; @@ -246,6 +279,487 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } +struct MemoryStruct { char *memory; size_t size; }; +struct return_string { char *ptr; size_t len; }; + +// return data from the server +#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32) +#define CURL_GLOBAL_SSL (1<<0) +#define CURL_GLOBAL_WIN32 (1<<1) + + +/************************************************************************ + * + * Initialize the string handler so that it is thread safe + * + ************************************************************************/ + +void init_string(struct return_string *s) +{ + s->len = 0; + s->ptr = (char *)calloc(1,s->len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr,"init_string malloc() failed\n"); + exit(-1); + } + s->ptr[0] = '\0'; +} + +/************************************************************************ + * + * Use the "writer" to accumulate text until done + * + ************************************************************************/ + +size_t accumulatebytes(void *ptr,size_t size,size_t nmemb,struct return_string *s) +{ + size_t new_len = s->len + size*nmemb; + s->ptr = (char *)realloc(s->ptr,new_len+1); + if ( s->ptr == NULL ) + { + fprintf(stderr, "accumulate realloc() failed\n"); + exit(-1); + } + memcpy(s->ptr+s->len,ptr,size*nmemb); + s->ptr[new_len] = '\0'; + s->len = new_len; + return(size * nmemb); +} + +/************************************************************************ + * + * return the current system time in milliseconds + * + ************************************************************************/ + +#define EXTRACT_BITCOIND_RESULT // if defined, ensures error is null and returns the "result" field +#ifdef EXTRACT_BITCOIND_RESULT + +/************************************************************************ + * + * perform post processing of the results + * + ************************************************************************/ + +char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *params) +{ + long i,j,len; char *retstr = 0; cJSON *json,*result,*error; + //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); + return(rpcstr); + } + json = cJSON_Parse(rpcstr); + if ( json == 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s can't parse.(%s) params.(%s)\n",debugstr,command,rpcstr,params); + free(rpcstr); + return(0); + } + result = cJSON_GetObjectItem(json,"result"); + error = cJSON_GetObjectItem(json,"error"); + if ( error != 0 && result != 0 ) + { + if ( (error->type&0xff) == cJSON_NULL && (result->type&0xff) != cJSON_NULL ) + { + retstr = cJSON_Print(result); + len = strlen(retstr); + if ( retstr[0] == '"' && retstr[len-1] == '"' ) + { + for (i=1,j=0; itype&0xff) != cJSON_NULL || (result->type&0xff) != cJSON_NULL ) + { + if ( strcmp(command,"signrawtransaction") != 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC (%s) error.%s\n",debugstr,command,rpcstr); + } + free(rpcstr); + } else retstr = rpcstr; + free_json(json); + //fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: postprocess returns.(%s)\n",retstr); + return(retstr); +} +#endif + +/************************************************************************ + * + * perform the query + * + ************************************************************************/ + +char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params) +{ + static int didinit,count,count2; static double elapsedsum,elapsedsum2; + struct curl_slist *headers = NULL; struct return_string s; CURLcode res; CURL *curl_handle; + char *bracket0,*bracket1,*databuf = 0; long len; int32_t specialcase,numretries; double starttime; + if ( didinit == 0 ) + { + didinit = 1; + curl_global_init(CURL_GLOBAL_ALL); //init the curl session + } + numretries = 0; + if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) + specialcase = 1; + else specialcase = 0; + if ( url[0] == 0 ) + strcpy(url,"http://127.0.0.1:7876/nxt"); + if ( specialcase != 0 && 0 ) + printf("<<<<<<<<<<< bitcoind_RPC: debug.(%s) url.(%s) command.(%s) params.(%s)\n",debugstr,url,command,params); +try_again: + if ( retstrp != 0 ) + *retstrp = 0; + starttime = OS_milliseconds(); + curl_handle = curl_easy_init(); + init_string(&s); + headers = curl_slist_append(0,"Expect:"); + + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl_handle,CURLOPT_URL, url); + curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function + curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback + curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash + curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback + if ( strncmp(url,"https",5) == 0 ) + { + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYPEER,0); + curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYHOST,0); + } + if ( userpass != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_USERPWD, userpass); + databuf = 0; + if ( params != 0 ) + { + if ( command != 0 && specialcase == 0 ) + { + len = strlen(params); + if ( len > 0 && params[0] == '[' && params[len-1] == ']' ) { + bracket0 = bracket1 = (char *)""; + } + else + { + bracket0 = (char *)"["; + bracket1 = (char *)"]"; + } + + databuf = (char *)malloc(256 + strlen(command) + strlen(params)); + sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + // + } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); + curl_easy_setopt(curl_handle,CURLOPT_POST,1L); + if ( databuf != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,databuf); + else curl_easy_setopt(curl_handle,CURLOPT_POSTFIELDS,params); + } + //laststart = milliseconds(); + res = curl_easy_perform(curl_handle); + curl_slist_free_all(headers); + curl_easy_cleanup(curl_handle); + if ( databuf != 0 ) // clean up temporary buffer + { + free(databuf); + databuf = 0; + } + if ( res != CURLE_OK ) + { + numretries++; + if ( specialcase != 0 ) + { + printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); + free(s.ptr); + return(0); + } + else if ( numretries >= 1 ) + { + //printf("Maximum number of retries exceeded!\n"); + free(s.ptr); + return(0); + } + if ( (rand() % 1000) == 0 ) + printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); + free(s.ptr); + sleep((1< (%s)\n",params,s.ptr); + count2++; + elapsedsum2 += (OS_milliseconds() - starttime); + if ( (count2 % 10000) == 0) + printf("%d: ave %9.6f | elapsed %.3f millis | NXT calls.(%s) cmd.(%s)\n",count2,elapsedsum2/count2,(double)(OS_milliseconds() - starttime),url,command); + return(s.ptr); + } + } + printf("bitcoind_RPC: impossible case\n"); + free(s.ptr); + return(0); +} + +static size_t WriteMemoryCallback(void *ptr,size_t size,size_t nmemb,void *data) +{ + size_t realsize = (size * nmemb); + struct MemoryStruct *mem = (struct MemoryStruct *)data; + mem->memory = (char *)((ptr != 0) ? realloc(mem->memory,mem->size + realsize + 1) : malloc(mem->size + realsize + 1)); + if ( mem->memory != 0 ) + { + if ( ptr != 0 ) + memcpy(&(mem->memory[mem->size]),ptr,realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + //printf("got %d bytes\n",(int32_t)(size*nmemb)); + return(realsize); +} + +char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3) +{ + struct MemoryStruct chunk; CURL *cHandle; long code; struct curl_slist *headers = 0; + if ( (cHandle= *cHandlep) == NULL ) + *cHandlep = cHandle = curl_easy_init(); + else curl_easy_reset(cHandle); + //#ifdef DEBUG + //curl_easy_setopt(cHandle,CURLOPT_VERBOSE, 1); + //#endif + curl_easy_setopt(cHandle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(cHandle,CURLOPT_SSL_VERIFYPEER,0); + //curl_easy_setopt(cHandle,CURLOPT_SSLVERSION,1); + curl_easy_setopt(cHandle,CURLOPT_URL,url); + curl_easy_setopt(cHandle,CURLOPT_CONNECTTIMEOUT,10); + if ( userpass != 0 && userpass[0] != 0 ) + curl_easy_setopt(cHandle,CURLOPT_USERPWD,userpass); + if ( postfields != 0 && postfields[0] != 0 ) + { + curl_easy_setopt(cHandle,CURLOPT_POST,1); + curl_easy_setopt(cHandle,CURLOPT_POSTFIELDS,postfields); + } + if ( hdr0 != NULL && hdr0[0] != 0 ) + { + //printf("HDR0.(%s) HDR1.(%s) HDR2.(%s) HDR3.(%s)\n",hdr0!=0?hdr0:"",hdr1!=0?hdr1:"",hdr2!=0?hdr2:"",hdr3!=0?hdr3:""); + headers = curl_slist_append(headers,hdr0); + if ( hdr1 != 0 && hdr1[0] != 0 ) + headers = curl_slist_append(headers,hdr1); + if ( hdr2 != 0 && hdr2[0] != 0 ) + headers = curl_slist_append(headers,hdr2); + if ( hdr3 != 0 && hdr3[0] != 0 ) + headers = curl_slist_append(headers,hdr3); + } //headers = curl_slist_append(0,"Expect:"); + if ( headers != 0 ) + curl_easy_setopt(cHandle,CURLOPT_HTTPHEADER,headers); + //res = curl_easy_perform(cHandle); + memset(&chunk,0,sizeof(chunk)); + curl_easy_setopt(cHandle,CURLOPT_WRITEFUNCTION,WriteMemoryCallback); + curl_easy_setopt(cHandle,CURLOPT_WRITEDATA,(void *)&chunk); + curl_easy_perform(cHandle); + curl_easy_getinfo(cHandle,CURLINFO_RESPONSE_CODE,&code); + if ( headers != 0 ) + curl_slist_free_all(headers); + if ( code != 200 ) + printf("(%s) server responded with code %ld (%s)\n",url,code,chunk.memory); + return(chunk.memory); +} + +#ifdef autoextract +uint16_t _komodo_userpass(char *username,char *password,FILE *fp) +{ + char *rpcuser,*rpcpassword,*str,line[8192]; uint16_t port = 0; + rpcuser = rpcpassword = 0; + username[0] = password[0] = 0; + while ( fgets(line,sizeof(line),fp) != 0 ) + { + if ( line[0] == '#' ) + continue; + //printf("line.(%s) %p %p\n",line,strstr(line,(char *)"rpcuser"),strstr(line,(char *)"rpcpassword")); + if ( (str= strstr(line,(char *)"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,(char *)"rpcuser"); + else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); + else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) + { + port = atoi(parse_conf_line(str,(char *)"rpcport")); + //fprintf(stderr,"rpcport.%u in file\n",port); + } + } + if ( rpcuser != 0 && rpcpassword != 0 ) + { + strcpy(username,rpcuser); + strcpy(password,rpcpassword); + } + //printf("rpcuser.(%s) rpcpassword.(%s) KMDUSERPASS.(%s) %u\n",rpcuser,rpcpassword,KMDUSERPASS,port); + if ( rpcuser != 0 ) + free(rpcuser); + if ( rpcpassword != 0 ) + free(rpcpassword); + return(port); +} + +void komodo_statefname(char *fname,char *symbol,char *str) +{ + int32_t n,len; + sprintf(fname,"%s",getDataDir()); + if ( (n= (int32_t)strlen(ASSETCHAINS_SYMBOL)) != 0 ) + { + len = (int32_t)strlen(fname); + if ( strcmp(ASSETCHAINS_SYMBOL,&fname[len - n]) == 0 ) + 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]); + return; + } + } + else + { +#ifdef _WIN32 + strcat(fname,"\\"); +#else + strcat(fname,"/"); +#endif + } + if ( symbol != 0 && symbol[0] != 0 && strcmp("KMD",symbol) != 0 ) + { + strcat(fname,symbol); + //printf("statefname.(%s) -> (%s)\n",symbol,fname); +#ifdef _WIN32 + strcat(fname,"\\"); +#else + strcat(fname,"/"); +#endif + } + strcat(fname,str); + //printf("test.(%s) -> [%s] statename.(%s) %s\n",test,ASSETCHAINS_SYMBOL,symbol,fname); +} + +uint16_t komodo_userpass(char *userpass,char *symbol) +{ + FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[KOMODO_ASSETCHAIN_MAXLEN]; + userpass[0] = 0; + if ( strcmp("KMD",symbol) == 0 ) + { +#ifdef __APPLE__ + sprintf(confname,"Komodo.conf"); +#else + sprintf(confname,"komodo.conf"); +#endif + } + else sprintf(confname,"%s.conf",symbol); + komodo_statefname(fname,symbol,confname); + if ( (fp= fopen(fname,"rb")) != 0 ) + { + port = _komodo_userpass(username,password,fp); + sprintf(userpass,"%s:%s",username,password); + if ( strcmp(symbol,ASSETCHAINS_SYMBOL) == 0 ) + strcpy(USERPASS,userpass); + fclose(fp); + } + return(port); +} +#endif + +#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) + +char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) +{ + //static void *cHandle; + char url[512],*retstr=0,*retstr2=0,postdata[8192]; + if ( params == 0 || params[0] == 0 ) + params = (char *)"[]"; + if ( strlen(params) < sizeof(postdata)-128 ) + { + sprintf(url,(char *)"http://127.0.0.1:%u",port); + sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); + retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); + //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); + } + return(retstr2); +} + +#include "rogue.h" + +void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) +{ + char cmd[16384],hexstr[16384]; int32_t i; + if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) + { + for (i=0; i> keystrokes.log",Gametxidstr,hexstr); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + } +} + +int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) +{ + char cmd[32768]; int32_t i,n,retval=-1; char *filestr,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item; + if ( rs->guiflag == 0 ) + return(-1); + if ( gametxidstr == 0 || *gametxidstr == 0 ) + return(retval); + sprintf(fname,"%s.gameinfo",gametxidstr); + sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + else + { + filestr = (char *)OS_fileptr(&allocsize,fname); + if ( (retjson= cJSON_Parse(filestr)) != 0 ) + { + if ( (array= jarray(&n,retjson,"players")) != 0 ) + { + for (i=0; iP,(int32_t)strlen(datastr)/2,datastr); + fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0)); + rs->restoring = 1; + } + } + } + } + } + free_json(retjson); + } + free(filestr); + } + return(retval); +} + int main(int argc, char **argv, char **envp) { uint64_t seed; FILE *fp = 0; diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 2f4545585..7e5a53fe5 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -26,7 +26,6 @@ */ struct rogue_state globalR; void garbage_collect(); -char Gametxidstr[67]; void purge_obj_guess(struct obj_info *array,int32_t n) { @@ -152,71 +151,11 @@ int32_t flushkeystrokes(struct rogue_state *rs) } #else -uint8_t *OS_fileptr(long *allocsizep,char *fname); -#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) - -int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) -{ - char cmd[32768]; int32_t i,n,retval=-1; char *filestr,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item; - if ( gametxidstr == 0 || *gametxidstr == 0 ) - return(retval); - sprintf(fname,"%s.gameinfo",gametxidstr); - sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); - else - { - filestr = (char *)OS_fileptr(&allocsize,fname); - if ( (retjson= cJSON_Parse(filestr)) != 0 ) - { - if ( (array= jarray(&n,retjson,"players")) != 0 ) - { - for (i=0; iP,(int32_t)strlen(datastr)/2,datastr); - fprintf(stderr,"set pname[%s] %s\n",pname==0?"":pname,jprint(item,0)); - rs->restoring = 1; - } - } - } - } - } - free_json(retjson); - } - free(filestr); - } - return(retval); -} - -void rogue_progress(uint64_t seed,char *keystrokes,int32_t num) -{ - char cmd[16384],hexstr[16384]; int32_t i; - if ( Gametxidstr[0] != 0 ) - { - for (i=0; i> keystrokes.log",Gametxidstr,hexstr); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); - } -} - int32_t flushkeystrokes(struct rogue_state *rs) { if ( rs->num > 0 ) { - rogue_progress(rs->seed,rs->buffered,rs->num); + rogue_progress(rs,rs->seed,rs->buffered,rs->num); memset(rs->buffered,0,sizeof(rs->buffered)); rs->counter++; rs->num = 0; @@ -230,10 +169,10 @@ void rogue_bailout(struct rogue_state *rs) flushkeystrokes(rs); //sleep(5); return; - fprintf(stderr,"bailing out\n"); + /*fprintf(stderr,"bailing out\n"); sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib bailout 17 \\\"[%%22%s%%22]\\\" >> bailout.log",Gametxidstr); if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); + fprintf(stderr,"error issuing (%s)\n",cmd);*/ } int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis) @@ -356,6 +295,8 @@ int rogue(int argc, char **argv, char **envp) { char *env; int lowtime; struct rogue_state *rs = &globalR; memset(rs,0,sizeof(*rs)); + rs->guiflag = 1; + rs->sleeptime = 1; // non-zero to allow refresh() if ( argc == 3 && strlen(argv[2]) == 64 ) { rs->seed = atol(argv[1]); @@ -366,8 +307,6 @@ int rogue(int argc, char **argv, char **envp) return(-1); } } else rs->seed = 777; - rs->guiflag = 1; - rs->sleeptime = 1; // non-zero to allow refresh() md_init(); #ifdef MASTER diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index f687b170c..802dd5f64 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -370,7 +370,7 @@ struct rogue_state uint8_t playerdata[10000]; }; extern struct rogue_state globalR; - +extern char Gametxidstr[67]; int rogue(int argc, char **argv, char **envp); void rogueiterate(struct rogue_state *rs); @@ -380,6 +380,8 @@ int32_t rogue_restorepack(struct rogue_state *rs); void restore_player(struct rogue_state *rs); int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis); void rogue_bailout(struct rogue_state *rs); +void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num); +int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr); #define ROGUE_MAXTOTAL (pstats.s_str*2) diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index 589f77422..7a0e2e4c6 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1432,7 +1432,7 @@ rs_write_object(struct rogue_state *rs,FILE *savef, THING *o) if ( o->_o._o_packch != 0 ) { item = &rs->P.roguepack[rs->P.packsize]; - if ( pstats.s_hpt <= 0 ) + if ( 0 && pstats.s_hpt <= 0 ) { //fprintf(stderr,"KILLED\n"); rs->P.gold = -1; diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 8ca239c7b..2d34d27c8 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1005,7 +1005,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param newdata[i] = player[i]; ((uint8_t *)&P)[i] = player[i]; } - if ( P.gold <= 0 || P.hitpoints <= 0 || (P.strength&0xffff) <= 0 || P.level <= 0 || P.experience <= 0 || P.dungeonlevel <= 0 ) + if ( 0 && (P.gold <= 0 || P.hitpoints <= 0 || (P.strength&0xffff) <= 0 || P.level <= 0 || P.experience <= 0 || P.dungeonlevel <= 0) ) { fprintf(stderr,"zero value character was killed -> no playerdata\n"); newdata.resize(0); From a08a6f3be4a9dce2379a8a1b0057e4ed05a8fa21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 21:35:14 -1100 Subject: [PATCH 39/69] -lcurl --- src/cc/rogue/Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/Makefile.in b/src/cc/rogue/Makefile.in index c53ece6ac..2669a2025 100644 --- a/src/cc/rogue/Makefile.in +++ b/src/cc/rogue/Makefile.in @@ -28,8 +28,8 @@ CC = @CC@ #CFLAGS=-O2 CFLAGS= @CFLAGS@ -fPIC -#LIBS=-lcurses -LIBS = @LIBS@ +LIBS=-lcurses -lcurl +#LIBS = @LIBS@ #RM=rm -f RM = rm -f From 0514250ce31de0ebe26e23e09c39b2af036baa6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:07:25 -1100 Subject: [PATCH 40/69] Attempt curl. Will be broken until debugged --- .gitignore | 8 ++ src/cc/rogue/config.h | 270 ------------------------------------------ src/cc/rogue/main.c | 77 ++++++++---- 3 files changed, 65 insertions(+), 290 deletions(-) delete mode 100644 src/cc/rogue/config.h diff --git a/.gitignore b/.gitignore index 0d0846e31..030c9dc5a 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,11 @@ src/checkfile src/log src/foo.zip + +src/cc/rogue/config.h + +src/cc/rogue/config.h + +src/ROGUE.conf + +src/rogue.scr diff --git a/src/cc/rogue/config.h b/src/cc/rogue/config.h deleted file mode 100644 index 558ae3ba1..000000000 --- a/src/cc/rogue/config.h +++ /dev/null @@ -1,270 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if scorefile is top scores, not top players */ -#define ALLSCORES 1 - -/* Define if checktime feature should be enabled */ -/* #undef CHECKTIME */ - -/* Define to group owner of setgid executable */ -/* #undef GROUPOWNER */ - -/* Define to 1 if you have the `alarm' function. */ -#define HAVE_ALARM 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_ARPA_INET_H 1 - -/* Define to 1 if libcurses is requested */ -#define HAVE_CURSES_H 1 - -/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ -/* #undef HAVE_DOPRNT */ - -/* Define to 1 if you have the `erasechar' function. */ -#define HAVE_ERASECHAR 1 - -/* Define if ncurses has ESCDELAY variable */ -#define HAVE_ESCDELAY 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the `fork' function. */ -#define HAVE_FORK 1 - -/* Define to 1 if you have the `getgid' function. */ -#define HAVE_GETGID 1 - -/* Define to 1 if you have the `getloadavg' function. */ -#define HAVE_GETLOADAVG 1 - -/* Define to 1 if you have the `getpass' function. */ -#define HAVE_GETPASS 1 - -/* Define to 1 if you have the `getpwuid' function. */ -#define HAVE_GETPWUID 1 - -/* Define to 1 if you have the `getuid' function. */ -#define HAVE_GETUID 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `killchar' function. */ -#define HAVE_KILLCHAR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the `loadav' function. */ -/* #undef HAVE_LOADAV */ - -/* Define to 1 if `lstat' has the bug that it succeeds when given the - zero-length file name argument. */ -/* #undef HAVE_LSTAT_EMPTY_STRING_BUG */ - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Define to 1 if libncurses is requested */ -/* #undef HAVE_NCURSES_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NCURSES_TERM_H */ - -/* Define to 1 if you have the `nlist' function. */ -/* #undef HAVE_NLIST */ - -/* Define to 1 if you have the header file. */ -#define HAVE_NLIST_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_PROCESS_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_PWD_H 1 - -/* Define to 1 if you have the `setenv' function. */ -#define HAVE_SETENV 1 - -/* Define to 1 if you have the `setgid' function. */ -#define HAVE_SETGID 1 - -/* Define to 1 if you have the `setregid' function. */ -#define HAVE_SETREGID 1 - -/* Define to 1 if you have the `setresgid' function. */ -/* #undef HAVE_SETRESGID */ - -/* Define to 1 if you have the `setresuid' function. */ -/* #undef HAVE_SETRESUID */ - -/* Define to 1 if you have the `setreuid' function. */ -#define HAVE_SETREUID 1 - -/* Define to 1 if you have the `setuid' function. */ -#define HAVE_SETUID 1 - -/* Define to 1 if you have the `spawnl' function. */ -/* #undef HAVE_SPAWNL */ - -/* Define to 1 if `stat' has the bug that it succeeds when given the - zero-length file name argument. */ -/* #undef HAVE_STAT_EMPTY_STRING_BUG */ - -/* Define to 1 if stdbool.h conforms to C99. */ -#define HAVE_STDBOOL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strchr' function. */ -#define HAVE_STRCHR 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_UTSNAME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_TERMIOS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_TERM_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UTMP_H 1 - -/* Define to 1 if you have the `vfork' function. */ -#define HAVE_VFORK 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_VFORK_H */ - -/* Define to 1 if you have the `vprintf' function. */ -#define HAVE_VPRINTF 1 - -/* Define to 1 if `fork' works. */ -#define HAVE_WORKING_FORK 1 - -/* Define to 1 if `vfork' works. */ -#define HAVE_WORKING_VFORK 1 - -/* Define to 1 if the system has the type `_Bool'. */ -#define HAVE__BOOL 1 - -/* Define to 1 if you have the `_spawnl' function. */ -/* #undef HAVE__SPAWNL */ - -/* define if we should use program's load average function instead of system - */ -/* #undef LOADAV */ - -/* Define to file to use for scoreboard lockfile */ -#define LOCKFILE "rogue.lck" - -/* Define to 1 if `lstat' dereferences a symlink specified with a trailing - slash. */ -/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */ - -/* Define to include wizard mode */ -/* #undef MASTER */ - -/* Define if maxusers feature should be enabled */ -/* #undef MAXLOAD */ - -/* Define if maxusers feature should be enabled */ -/* #undef MAXUSERS */ - -/* kernel file to pass to nlist() when reading load average (unlikely to work) - */ -/* #undef NAMELIST */ - -/* word for the number of scores to store in scoreboard */ -#define NUMNAME "Ten" - -/* number of scores to store in scoreboard */ -#define NUMSCORES 10 - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "yendor@rogueforge.net" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "Rogue" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "Rogue 5.4.4" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "rogue" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "5.4.4" - -/* Define crypt(3) wizard mode password */ -/* #undef PASSWD */ - -/* Define as the return type of signal handlers (`int' or `void'). */ -#define RETSIGTYPE void - -/* Define to file to use for scoreboard */ -#define SCOREFILE "rogue.scr" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to 1 if your declares `struct tm'. */ -/* #undef TM_IN_SYS_TIME */ - -/* define if we should use program's user counting function instead of - system's */ -/* #undef UCOUNT */ - -/* utmp like file to pass to ucount() when counting online users (unlikely to - work) */ -/* #undef UTMP */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define to `int' if does not define. */ -/* #undef pid_t */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - -/* Define as `fork' if `vfork' does not work. */ -/* #undef vfork */ diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 1131e3429..01ae794eb 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -23,14 +23,14 @@ #include #include -char USERPASS[8192]; +char USERPASS[8192]; uint16_t ROGUE_PORT; char Gametxidstr[67]; #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) #define KOMODO_ASSETCHAIN_MAXLEN 65 -#define ASSETCHAINS_SYMBOL "ROGUE" +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; #ifndef _BITS256 #define _BITS256 @@ -583,7 +583,6 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * return(chunk.memory); } -#ifdef autoextract uint16_t _komodo_userpass(char *username,char *password,FILE *fp) { char *rpcuser,*rpcpassword,*str,line[8192]; uint16_t port = 0; @@ -617,7 +616,7 @@ uint16_t _komodo_userpass(char *username,char *password,FILE *fp) return(port); } -void komodo_statefname(char *fname,char *symbol,char *str) +/*void komodo_statefname(char *fname,char *symbol,char *str) { int32_t n,len; sprintf(fname,"%s",getDataDir()); @@ -652,7 +651,7 @@ void komodo_statefname(char *fname,char *symbol,char *str) } strcat(fname,str); //printf("test.(%s) -> [%s] statename.(%s) %s\n",test,ASSETCHAINS_SYMBOL,symbol,fname); -} +}*/ uint16_t komodo_userpass(char *userpass,char *symbol) { @@ -667,8 +666,8 @@ uint16_t komodo_userpass(char *userpass,char *symbol) #endif } else sprintf(confname,"%s.conf",symbol); - komodo_statefname(fname,symbol,confname); - if ( (fp= fopen(fname,"rb")) != 0 ) + //komodo_statefname(fname,symbol,confname); + if ( (fp= fopen(confname,"rb")) != 0 ) { port = _komodo_userpass(username,password,fp); sprintf(userpass,"%s:%s",username,password); @@ -678,7 +677,6 @@ uint16_t komodo_userpass(char *userpass,char *symbol) } return(port); } -#endif #define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) @@ -703,32 +701,53 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) { - char cmd[16384],hexstr[16384]; int32_t i; + char cmd[16384],hexstr[16384],params[32768]; int32_t i; if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) { for (i=0; i> keystrokes.log",Gametxidstr,hexstr); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); + if ( 0 ) + { + sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib keystrokes 17 \\\"[%%22%s%%22,%%22%s%%22]\\\" >> keystrokes.log",Gametxidstr,hexstr); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + } + else + { + sprintf(params,"[\"keystrokes\",17,[\"%s\",\"%s\"]]",Gametxidstr,hexstr); + if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) + { + fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); + free(retstr); + } + } } } int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) { - char cmd[32768]; int32_t i,n,retval=-1; char *filestr,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item; + char cmd[32768]; int32_t i,n,retval=-1; char *filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item; if ( rs->guiflag == 0 ) return(-1); if ( gametxidstr == 0 || *gametxidstr == 0 ) return(retval); - sprintf(fname,"%s.gameinfo",gametxidstr); - sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname); - if ( system(cmd) != 0 ) - fprintf(stderr,"error issuing (%s)\n",cmd); + if ( 0 ) + { + sprintf(fname,"%s.gameinfo",gametxidstr); + sprintf(cmd,"./komodo-cli -ac_name=ROGUE cclib gameinfo 17 \\\"[%%22%s%%22]\\\" > %s",gametxidstr,fname); + if ( system(cmd) != 0 ) + fprintf(stderr,"error issuing (%s)\n",cmd); + else filestr = (char *)OS_fileptr(&allocsize,fname); + } else { - filestr = (char *)OS_fileptr(&allocsize,fname); + sprintf(params,"[\"gameinfo\",17,[\"%s\"]]",gametxidstr); + filestr = komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT); + } + if ( filestr != 0 ) + { + fprintf(stderr,"gameinfo.(%s)\n",filestr); if ( (retjson= cJSON_Parse(filestr)) != 0 ) { if ( (array= jarray(&n,retjson,"players")) != 0 ) @@ -762,7 +781,20 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) int main(int argc, char **argv, char **envp) { - uint64_t seed; FILE *fp = 0; + uint64_t seed; FILE *fp = 0; int32_t i,j,c; char userpass[8192]; + for (i=j=0; argv[0][i]!=0&&j Date: Wed, 20 Feb 2019 22:09:20 -1100 Subject: [PATCH 41/69] syntax --- .gitignore | 2 ++ src/cc/rogue/main.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 030c9dc5a..2ab07ee0f 100644 --- a/.gitignore +++ b/.gitignore @@ -152,3 +152,5 @@ src/cc/rogue/config.h src/ROGUE.conf src/rogue.scr + +src/cc/rogue/confdefs.h diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 01ae794eb..84e7ae91f 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -701,7 +701,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) { - char cmd[16384],hexstr[16384],params[32768]; int32_t i; + char cmd[16384],hexstr[16384],params[32768],*retstr; int32_t i; if ( rs->guiflag != 0 && Gametxidstr[0] != 0 ) { for (i=0; iguiflag == 0 ) return(-1); if ( gametxidstr == 0 || *gametxidstr == 0 ) From 513a9cc3fc5b6a8b9144cc697da31973a44ed59c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:20:36 -1100 Subject: [PATCH 42/69] +prints --- src/cc/cclib.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 33b76ff91..578ce84d8 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -253,7 +253,7 @@ UniValue CClib_info(struct CCcontract_info *cp) UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) { UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; - //printf("CClib params.%p\n",params); + printf("CClib params.%p (%s)\n",params,params!=0?jprint(params,0):""); for (i=0; ievalcode == CClib_methods[i].evalcode && strcmp(method,CClib_methods[i].method) == 0 ) @@ -531,7 +531,7 @@ cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will } newstr[j] = 0; params = cJSON_Parse(newstr); - if ( 0 && params != 0 ) + if ( 1 && params != 0 ) printf("new.(%s) -> %s\n",newstr,jprint(params,0)); free(newstr); *nump = cJSON_GetArraySize(params); From b60b2118c54d2031df82f95d046b3e399728f1e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:28:44 -1100 Subject: [PATCH 43/69] Stubs --- src/cc/rogue/main.c | 2 +- src/cc/rogue/rogue.c | 13 +++++++++++++ src/cc/rogue/rogue.h | 1 - 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 84e7ae91f..f0e7df58a 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -24,7 +24,7 @@ #include char USERPASS[8192]; uint16_t ROGUE_PORT; -char Gametxidstr[67]; +extern char Gametxidstr[67]; #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 7e5a53fe5..b4cb6244f 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -25,6 +25,7 @@ * The main program, of course */ struct rogue_state globalR; +char Gametxidstr[67]; void garbage_collect(); void purge_obj_guess(struct obj_info *array,int32_t n) @@ -151,6 +152,18 @@ int32_t flushkeystrokes(struct rogue_state *rs) } #else +#ifdef BUILD_ROGUE +// stubs for inside daemon +void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) +{ +} + +int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) +{ + return(-1); +} +#endif + int32_t flushkeystrokes(struct rogue_state *rs) { if ( rs->num > 0 ) diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 802dd5f64..b64af8f1a 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -370,7 +370,6 @@ struct rogue_state uint8_t playerdata[10000]; }; extern struct rogue_state globalR; -extern char Gametxidstr[67]; int rogue(int argc, char **argv, char **envp); void rogueiterate(struct rogue_state *rs); From 3db424cdf87bd91c3855292bc77f887bb90d3254 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:30:21 -1100 Subject: [PATCH 44/69] Test --- src/cc/rogue/rogue.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index b4cb6244f..6d0af34b2 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -154,6 +154,7 @@ int32_t flushkeystrokes(struct rogue_state *rs) #ifdef BUILD_ROGUE // stubs for inside daemon +xxx void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) { } From 8d39e0119b11d8084bbb724e9dd277dfc34a9a29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:32:17 -1100 Subject: [PATCH 45/69] Fix --- src/cc/rogue/rogue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 6d0af34b2..0a6d83cff 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -154,7 +154,8 @@ int32_t flushkeystrokes(struct rogue_state *rs) #ifdef BUILD_ROGUE // stubs for inside daemon -xxx +char Gametxidstr[67]; + void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) { } From d835211676faa3bcbdd26690ed38f0a6a7e57b21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:32:57 -1100 Subject: [PATCH 46/69] -Gameidstr --- src/cc/rogue/rogue.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 0a6d83cff..e8de063de 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -154,7 +154,6 @@ int32_t flushkeystrokes(struct rogue_state *rs) #ifdef BUILD_ROGUE // stubs for inside daemon -char Gametxidstr[67]; void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_t num) { From f6d2b31ab65be445a56fe70fdd5ad7e9344512ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:39:20 -1100 Subject: [PATCH 47/69] tst --- 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 f0e7df58a..5056ff14d 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -742,7 +742,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } else { - sprintf(params,"[\"gameinfo\",17,[\"%s\"]]",gametxidstr); + sprintf(params,"[\"gameinfo\",\"17\",\"[\'%s\']\"]",gametxidstr); filestr = komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT); } if ( filestr != 0 ) From c5dce15a91ea65c7629b3e85c9e8666d1b6dc49b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:40:23 -1100 Subject: [PATCH 48/69] %22 --- 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 5056ff14d..8ec480a0a 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -742,7 +742,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } else { - sprintf(params,"[\"gameinfo\",\"17\",\"[\'%s\']\"]",gametxidstr); + sprintf(params,"[\"gameinfo\",\"17\",\"[%22%s%22]\"]",gametxidstr); filestr = komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT); } if ( filestr != 0 ) From acd6f878168806bc48ac761e14215066efbd2665 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:41:08 -1100 Subject: [PATCH 49/69] %22 --- 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 8ec480a0a..c338cf397 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -715,7 +715,7 @@ void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_ } else { - sprintf(params,"[\"keystrokes\",17,[\"%s\",\"%s\"]]",Gametxidstr,hexstr); + sprintf(params,"[\"keystrokes\",\"17\",\"[%22%s%22,%22%s%22]\"]",Gametxidstr,hexstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) { fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); From f394bf75acb1022d8ea37550cd23b1f87f427714 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:42:05 -1100 Subject: [PATCH 50/69] %% --- src/cc/rogue/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index c338cf397..8f674ba40 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -715,7 +715,7 @@ void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_ } else { - sprintf(params,"[\"keystrokes\",\"17\",\"[%22%s%22,%22%s%22]\"]",Gametxidstr,hexstr); + sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) { fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); @@ -742,7 +742,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } else { - sprintf(params,"[\"gameinfo\",\"17\",\"[%22%s%22]\"]",gametxidstr); + sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); filestr = komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT); } if ( filestr != 0 ) From f98831dafdc41acf0ea694296a148dac2a3f1b9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:43:28 -1100 Subject: [PATCH 51/69] Test --- 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 8f674ba40..a7c1d1d3f 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -690,7 +690,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); + printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } From 652d9880a7ffce3a756995a05dc0a45439fb8757 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:43:56 -1100 Subject: [PATCH 52/69] USERPASS --- 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 a7c1d1d3f..969314166 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -690,7 +690,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); + printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,USERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } From 957178495bbeee8f426621ee1733903a25c2c04f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:46:12 -1100 Subject: [PATCH 53/69] Test --- src/cc/rogue/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 969314166..49a09a5cf 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -450,7 +450,7 @@ try_again: databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); // } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); curl_easy_setopt(curl_handle,CURLOPT_POST,1L); @@ -690,7 +690,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,USERPASS); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,USERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } From 3881f9cea47df07f7ad7ce02f06cdd88e0b28e95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:50:57 -1100 Subject: [PATCH 54/69] Prints --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 47f7d3004..99d9b87f1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5416,6 +5416,7 @@ UniValue cclib(const UniValue& params, bool fHelp) } if ( params.size() == 3 ) { + fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); jsonparams = cJSON_Parse(params[2].get_str().c_str()); } } From a65a83bdb8d4619bc45c14883d77d9ffddd81eee Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:55:40 -1100 Subject: [PATCH 55/69] Test --- src/cc/rogue/main.c | 6 +++--- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 49a09a5cf..fab4875b1 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -450,7 +450,7 @@ try_again: databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); // } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); curl_easy_setopt(curl_handle,CURLOPT_POST,1L); @@ -715,7 +715,7 @@ void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_ } else { - sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); + sprintf(params,"[\"keystrokes\",\"17\",\\\"[%%22%s%%22,%%22%s%%22]\\\"]",Gametxidstr,hexstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) { fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); @@ -742,7 +742,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } else { - sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); + sprintf(params,"[\"gameinfo\",\"17\",\\\"[%%22%s%%22]\\\"]",gametxidstr); filestr = komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT); } if ( filestr != 0 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 99d9b87f1..decb6fb96 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5416,7 +5416,7 @@ UniValue cclib(const UniValue& params, bool fHelp) } if ( params.size() == 3 ) { - fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); + //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); jsonparams = cJSON_Parse(params[2].get_str().c_str()); } } From c2def52cb232f7faf28829aa4624e1a36d9c4929 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 22:56:53 -1100 Subject: [PATCH 56/69] Test --- 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 fab4875b1..6ac9efe3b 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -715,7 +715,7 @@ void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_ } else { - sprintf(params,"[\"keystrokes\",\"17\",\\\"[%%22%s%%22,%%22%s%%22]\\\"]",Gametxidstr,hexstr); + sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) { fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); From 2496f79e41c478c780b6142cb1036490361c9949 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:05:58 -1100 Subject: [PATCH 57/69] Jsonstr --- src/cc/CCinclude.h | 2 +- src/cc/cclib.cpp | 76 +++++++++++++++++++++------------------- src/wallet/rpcwallet.cpp | 6 ++-- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index eb9297a36..ca51506e8 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -139,7 +139,7 @@ int32_t komodo_nextheight(); int32_t CCgetspenttxid(uint256 &spenttxid,int32_t &vini,int32_t &height,uint256 txid,int32_t vout); void CCclearvars(struct CCcontract_info *cp); -UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params); +UniValue CClib(struct CCcontract_info *cp,char *method,char *jsonstr); UniValue CClib_info(struct CCcontract_info *cp); CBlockIndex *komodo_blockindex(uint256 hash); CBlockIndex *komodo_chainactive(int32_t height); diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 578ce84d8..88db00732 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -123,9 +123,43 @@ UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #endif -UniValue CClib_method(struct CCcontract_info *cp,char *method,cJSON *params) +cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be freed by caller { - UniValue result(UniValue::VOBJ); uint64_t txfee = 10000; + cJSON *params; char *jsonstr,*newstr; int32_t i,j; + *nump = 0; + if ( jsonstr != 0 ) + { + if ( jsonstr[0] == '"' && jsonstr[strlen(jsonstr)-1] == '"' ) + { + jsonstr[strlen(jsonstr)-1] = 0; + jsonstr++; + } + newstr = (char *)malloc(strlen(jsonstr)+1); + for (i=j=0; jsonstr[i]!=0; i++) + { + if ( jsonstr[i] == '%' && jsonstr[i+1] == '2' && jsonstr[i+2] == '2' ) + { + newstr[j++] = '"'; + i += 2; + } + else if ( jsonstr[i] == '\'' ) + newstr[j++] = '"'; + else newstr[j++] = jsonstr[i]; + } + newstr[j] = 0; + params = cJSON_Parse(newstr); + if ( 1 && params != 0 ) + printf("new.(%s) -> %s\n",newstr,jprint(params,0)); + free(newstr); + *nump = cJSON_GetArraySize(params); + //free(origparams); + } else params = 0; + return(params); +} + +UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) +{ + UniValue result(UniValue::VOBJ); uint64_t txfee = 10000; int32_t m; cJSON *params = cclib_reparse(&m,jsonstr); #ifdef BUILD_ROGUE if ( cp->evalcode == EVAL_ROGUE ) { @@ -250,10 +284,10 @@ UniValue CClib_info(struct CCcontract_info *cp) return(result); } -UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) +UniValue CClib(struct CCcontract_info *cp,char *method,char *jsonstr) { UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; - printf("CClib params.%p (%s)\n",params,params!=0?jprint(params,0):""); + printf("CClib params.(%s)\n",jsonstr!=0?jsonstr:""); for (i=0; ievalcode == CClib_methods[i].evalcode && strcmp(method,CClib_methods[i].method) == 0 ) @@ -265,7 +299,7 @@ UniValue CClib(struct CCcontract_info *cp,char *method,cJSON *params) rawtx = CClib_rawtxgen(cp,CClib_methods[i].funcid,params); result.push_back(Pair("rawtx",rawtx)); return(result); - } else return(CClib_method(cp,method,params)); + } else return(CClib_method(cp,method,jsonstr)); } } result.push_back(Pair("result","error")); @@ -507,38 +541,6 @@ uint256 juint256(cJSON *obj) return(revuint256(tmp)); } -cJSON *cclib_reparse(int32_t *nump,cJSON *origparams) // assumes origparams will be freed by caller -{ - cJSON *params; char *jsonstr,*newstr; int32_t i,j; - if ( (jsonstr= jprint(origparams,0)) != 0 ) - { - if ( jsonstr[0] == '"' && jsonstr[strlen(jsonstr)-1] == '"' ) - { - jsonstr[strlen(jsonstr)-1] = 0; - jsonstr++; - } - newstr = (char *)malloc(strlen(jsonstr)+1); - for (i=j=0; jsonstr[i]!=0; i++) - { - if ( jsonstr[i] == '%' && jsonstr[i+1] == '2' && jsonstr[i+2] == '2' ) - { - newstr[j++] = '"'; - i += 2; - } - else if ( jsonstr[i] == '\'' ) - newstr[j++] = '"'; - else newstr[j++] = jsonstr[i]; - } - newstr[j] = 0; - params = cJSON_Parse(newstr); - if ( 1 && params != 0 ) - printf("new.(%s) -> %s\n",newstr,jprint(params,0)); - free(newstr); - *nump = cJSON_GetArraySize(params); - //free(origparams); - } else params = 0; - return(params); -} #ifdef BUILD_ROGUE #include "rogue_rpc.cpp" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index decb6fb96..3965416c4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5396,7 +5396,7 @@ UniValue cclibinfo(const UniValue& params, bool fHelp) UniValue cclib(const UniValue& params, bool fHelp) { - struct CCcontract_info *cp,C; char *method; cJSON *jsonparams=0; uint8_t evalcode = EVAL_FIRSTUSER; + struct CCcontract_info *cp,C; char *method,*jsonstr=0; uint8_t evalcode = EVAL_FIRSTUSER; if ( fHelp || params.size() > 3 ) throw runtime_error("cclib method [evalcode] [JSON params]\n"); if ( ASSETCHAINS_CCLIB.size() == 0 ) @@ -5417,11 +5417,11 @@ UniValue cclib(const UniValue& params, bool fHelp) if ( params.size() == 3 ) { //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); - jsonparams = cJSON_Parse(params[2].get_str().c_str()); + jsonparams = params[2].get_str().c_str(); } } cp = CCinit(&C,evalcode); - return(CClib(cp,method,jsonparams)); + return(CClib(cp,method,jsonstr)); } UniValue oraclesaddress(const UniValue& params, bool fHelp) From d9a52ff53cd8099f5dac9a768a68df26eb1f83c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:08:13 -1100 Subject: [PATCH 58/69] if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) --- src/cc/musig.cpp | 6 +++--- src/cc/rogue_rpc.cpp | 16 ++++++++-------- src/cc/sudoku.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 800102e13..04f3fe35d 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -86,7 +86,7 @@ int32_t musig_prevoutmsg(uint8_t *msg,uint256 sendtxid,CScript scriptPubKey) UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); uint256 sendtxid; int32_t i; uint8_t msg[32]; char *scriptstr,str[65]; int32_t n; - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n == 2 ) { @@ -183,7 +183,7 @@ UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) txfee = MUSIG_TXFEE; mypk = pubkey2pk(Mypubkey()); musigpk = GetUnspendable(cp,0); - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n == 2 && (hexstr= jstr(jitem(params,0),0)) != 0 && is_hexstr(hexstr,0) == 66 ) { @@ -206,7 +206,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,pk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; secp256k1_schnorrsig musig; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n == 3 ) { diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 2d34d27c8..60d9a5cfd 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -657,7 +657,7 @@ UniValue rogue_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey roguepk,mypk; char *jsonstr; uint64_t inputsum,change,required,buyin=0; int32_t i,n,maxplayers = 1; if ( txfee == 0 ) txfee = 10000; - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { @@ -693,7 +693,7 @@ UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *param UniValue result(UniValue::VOBJ); std::vector playerdata; uint256 playertxid,tokenid,origplayergame;int32_t n; CPubKey pk; bits256 t; std::string symbol,pname; result.push_back(Pair("result","success")); rogue_univalue(result,"playerinfo",-1,-1); - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { @@ -723,7 +723,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) roguepk = GetUnspendable(cp,0); rogue_univalue(result,"register",-1,-1); playertxid = tokenid = zeroid; - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { @@ -803,7 +803,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param if ( txfee == 0 ) txfee = 10000; rogue_univalue(result,"keystrokes",-1,-1); - if ( (params= cclib_reparse(&n,params)) != 0 && n == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 ) { gametxid = juint256(jitem(params,0)); result.push_back(Pair("gametxid",gametxid.GetHex())); @@ -896,7 +896,7 @@ UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) roguepk = GetUnspendable(cp,0); result.push_back(Pair("name","rogue")); result.push_back(Pair("method","extract")); - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { @@ -968,7 +968,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param funcid = 'H'; mult = 200000; } - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { @@ -1081,7 +1081,7 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,gameheight,maxplayers,numvouts; uint256 txid; CTransaction tx; int64_t buyin; uint64_t seed; bits256 t; char myrogueaddr[64]; CPubKey mypk,roguepk; result.push_back(Pair("name","rogue")); result.push_back(Pair("method","gameinfo")); - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { @@ -1212,7 +1212,7 @@ UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); int32_t n; char *namestr = 0; rogue_univalue(result,"setname",-1,-1); - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 0 ) { diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index d48a1bc2c..a8e7c651b 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2817,7 +2817,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params good = 0; if ( params != 0 ) { - if ( (params= cclib_reparse(&n,params)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) { if ( n > 2 && n <= (sizeof(timestamps)/sizeof(*timestamps))+2 ) { From 2dff5b98f025b4dda5b391d93e447956211c4934 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:10:26 -1100 Subject: [PATCH 59/69] Jsonstr --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3965416c4..36172a612 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5417,7 +5417,7 @@ UniValue cclib(const UniValue& params, bool fHelp) if ( params.size() == 3 ) { //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); - jsonparams = params[2].get_str().c_str(); + jsonstr = params[2].get_str().c_str(); } } cp = CCinit(&C,evalcode); From 695278546955eeab749f3f3b2b5a8f7a0f8eff5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:12:58 -1100 Subject: [PATCH 60/69] params --- src/cc/musig.cpp | 6 +++--- src/cc/rogue_rpc.cpp | 16 ++++++++-------- src/cc/sudoku.cpp | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 04f3fe35d..5d56635aa 100755 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -86,7 +86,7 @@ int32_t musig_prevoutmsg(uint8_t *msg,uint256 sendtxid,CScript scriptPubKey) UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); uint256 sendtxid; int32_t i; uint8_t msg[32]; char *scriptstr,str[65]; int32_t n; - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n == 2 ) { @@ -183,7 +183,7 @@ UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) txfee = MUSIG_TXFEE; mypk = pubkey2pk(Mypubkey()); musigpk = GetUnspendable(cp,0); - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n == 2 && (hexstr= jstr(jitem(params,0),0)) != 0 && is_hexstr(hexstr,0) == 66 ) { @@ -206,7 +206,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,pk; secp256k1_pubkey combined_pk; char *scriptstr,*musigstr; uint8_t msg[32]; CTransaction vintx; uint256 prevhash,hashBlock; int32_t n,numvouts; CTxOut vout; secp256k1_schnorrsig musig; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n == 3 ) { diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 60d9a5cfd..57ce1e14b 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -657,7 +657,7 @@ UniValue rogue_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey roguepk,mypk; char *jsonstr; uint64_t inputsum,change,required,buyin=0; int32_t i,n,maxplayers = 1; if ( txfee == 0 ) txfee = 10000; - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { @@ -693,7 +693,7 @@ UniValue rogue_playerinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *param UniValue result(UniValue::VOBJ); std::vector playerdata; uint256 playertxid,tokenid,origplayergame;int32_t n; CPubKey pk; bits256 t; std::string symbol,pname; result.push_back(Pair("result","success")); rogue_univalue(result,"playerinfo",-1,-1); - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { @@ -723,7 +723,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) roguepk = GetUnspendable(cp,0); rogue_univalue(result,"register",-1,-1); playertxid = tokenid = zeroid; - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { @@ -803,7 +803,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param if ( txfee == 0 ) txfee = 10000; rogue_univalue(result,"keystrokes",-1,-1); - if ( params != 0 && (n= cJSON_GetArraySize()) == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 2 && (keystrokestr= jstr(jitem(params,1),0)) != 0 ) { gametxid = juint256(jitem(params,0)); result.push_back(Pair("gametxid",gametxid.GetHex())); @@ -896,7 +896,7 @@ UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) roguepk = GetUnspendable(cp,0); result.push_back(Pair("name","rogue")); result.push_back(Pair("method","extract")); - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { @@ -968,7 +968,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param funcid = 'H'; mult = 200000; } - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { @@ -1081,7 +1081,7 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ),a(UniValue::VARR); int32_t i,n,gameheight,maxplayers,numvouts; uint256 txid; CTransaction tx; int64_t buyin; uint64_t seed; bits256 t; char myrogueaddr[64]; CPubKey mypk,roguepk; result.push_back(Pair("name","rogue")); result.push_back(Pair("method","gameinfo")); - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { @@ -1212,7 +1212,7 @@ UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); int32_t n; char *namestr = 0; rogue_univalue(result,"setname",-1,-1); - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 0 ) { diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index a8e7c651b..49bcf79d9 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2817,7 +2817,7 @@ UniValue sudoku_solution(uint64_t txfee,struct CCcontract_info *cp,cJSON *params good = 0; if ( params != 0 ) { - if ( params != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n > 2 && n <= (sizeof(timestamps)/sizeof(*timestamps))+2 ) { From 0dd112c6d85de51692730161a31ff06646e29ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:16:37 -1100 Subject: [PATCH 61/69] Syntax --- src/cc/cclib.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 88db00732..f17f04273 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -125,7 +125,7 @@ UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be freed by caller { - cJSON *params; char *jsonstr,*newstr; int32_t i,j; + cJSON *params; char *newstr; int32_t i,j; *nump = 0; if ( jsonstr != 0 ) { @@ -286,7 +286,7 @@ UniValue CClib_info(struct CCcontract_info *cp) UniValue CClib(struct CCcontract_info *cp,char *method,char *jsonstr) { - UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; + UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; cJSON *params; printf("CClib params.(%s)\n",jsonstr!=0?jsonstr:""); for (i=0; i Date: Wed, 20 Feb 2019 23:17:40 -1100 Subject: [PATCH 62/69] Char * --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 36172a612..ab8992c0d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5417,7 +5417,7 @@ UniValue cclib(const UniValue& params, bool fHelp) if ( params.size() == 3 ) { //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); - jsonstr = params[2].get_str().c_str(); + jsonstr = (char *)params[2].get_str().c_str(); } } cp = CCinit(&C,evalcode); From d58bfc8a7fbda8a03f009f2242dd5df7e3c9a106 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:20:37 -1100 Subject: [PATCH 63/69] Prints --- src/cc/cclib.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index f17f04273..3f4a5d6a8 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -160,6 +160,7 @@ cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) { UniValue result(UniValue::VOBJ); uint64_t txfee = 10000; int32_t m; cJSON *params = cclib_reparse(&m,jsonstr); + fprintf(stderr,"method.(%s) -> (%s)\n",jsonstr!=0?jsonstr:"",params!=0?jprint(params,0):""); #ifdef BUILD_ROGUE if ( cp->evalcode == EVAL_ROGUE ) { From e392999374bfb4cded273a333aeac44c52739a99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:24:27 -1100 Subject: [PATCH 64/69] Jsonstr --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ab8992c0d..de4b22b7e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5416,8 +5416,8 @@ UniValue cclib(const UniValue& params, bool fHelp) } if ( params.size() == 3 ) { - //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),params[2].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); + fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),jsonstr); } } cp = CCinit(&C,evalcode); From 0cc4ef9d9008f73e3f0ff855a80bb048372de4d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:26:36 -1100 Subject: [PATCH 65/69] Test --- src/cc/rogue/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 6ac9efe3b..49a09a5cf 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -450,7 +450,7 @@ try_again: databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); // } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); curl_easy_setopt(curl_handle,CURLOPT_POST,1L); @@ -742,7 +742,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } else { - sprintf(params,"[\"gameinfo\",\"17\",\\\"[%%22%s%%22]\\\"]",gametxidstr); + sprintf(params,"[\"gameinfo\",\"17\",\"[%%22%s%%22]\"]",gametxidstr); filestr = komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT); } if ( filestr != 0 ) From 13ba8a70ca9a86f8964d1c0b478b984b4921cadd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:28:57 -1100 Subject: [PATCH 66/69] -prints --- src/cc/cclib.cpp | 4 ++-- src/cc/rogue/main.c | 2 +- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 3f4a5d6a8..a595f5559 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -160,7 +160,7 @@ cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) { UniValue result(UniValue::VOBJ); uint64_t txfee = 10000; int32_t m; cJSON *params = cclib_reparse(&m,jsonstr); - fprintf(stderr,"method.(%s) -> (%s)\n",jsonstr!=0?jsonstr:"",params!=0?jprint(params,0):""); + //fprintf(stderr,"method.(%s) -> (%s)\n",jsonstr!=0?jsonstr:"",params!=0?jprint(params,0):""); #ifdef BUILD_ROGUE if ( cp->evalcode == EVAL_ROGUE ) { @@ -288,7 +288,7 @@ UniValue CClib_info(struct CCcontract_info *cp) UniValue CClib(struct CCcontract_info *cp,char *method,char *jsonstr) { UniValue result(UniValue::VOBJ); int32_t i; std::string rawtx; cJSON *params; - printf("CClib params.(%s)\n",jsonstr!=0?jsonstr:""); + //printf("CClib params.(%s)\n",jsonstr!=0?jsonstr:""); for (i=0; ievalcode == CClib_methods[i].evalcode && strcmp(method,CClib_methods[i].method) == 0 ) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 49a09a5cf..af357feb8 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -450,7 +450,7 @@ try_again: databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); // } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); curl_easy_setopt(curl_handle,CURLOPT_POST,1L); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index de4b22b7e..0ed2f866c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5417,7 +5417,7 @@ UniValue cclib(const UniValue& params, bool fHelp) if ( params.size() == 3 ) { jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),jsonstr); + //fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),jsonstr); } } cp = CCinit(&C,evalcode); From 89e375e95dbccb5877f55a94c298134e6f5f8fe6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:32:23 -1100 Subject: [PATCH 67/69] Resultjson --- src/cc/cclib.cpp | 2 +- src/cc/rogue/main.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index a595f5559..625872483 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -148,7 +148,7 @@ cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be } newstr[j] = 0; params = cJSON_Parse(newstr); - if ( 1 && params != 0 ) + if ( 0 && params != 0 ) printf("new.(%s) -> %s\n",newstr,jprint(params,0)); free(newstr); *nump = cJSON_GetArraySize(params); diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index af357feb8..32967614c 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -727,7 +727,7 @@ void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) { - char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item; + char cmd[32768]; int32_t i,n,retval=-1; char params[1024],*filestr=0,*pname,*statusstr,*datastr,fname[128]; long allocsize; cJSON *retjson,*array,*item,*resultjson; if ( rs->guiflag == 0 ) return(-1); if ( gametxidstr == 0 || *gametxidstr == 0 ) @@ -747,10 +747,10 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } if ( filestr != 0 ) { - fprintf(stderr,"gameinfo.(%s)\n",filestr); - if ( (retjson= cJSON_Parse(filestr)) != 0 ) + if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jitem(retjson,"result")) != 0 ) { - if ( (array= jarray(&n,retjson,"players")) != 0 ) + fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); + if ( (array= jarray(&n,resultjson,"players")) != 0 ) { for (i=0; i Date: Wed, 20 Feb 2019 23:32:59 -1100 Subject: [PATCH 68/69] jobj --- 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 32967614c..7971a9b3d 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -747,7 +747,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) } if ( filestr != 0 ) { - if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jitem(retjson,"result")) != 0 ) + if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,"result")) != 0 ) { fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); if ( (array= jarray(&n,resultjson,"players")) != 0 ) From 2fdc745c0b75bf03ede1bb02be566eaff6b5b026 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Feb 2019 23:35:42 -1100 Subject: [PATCH 69/69] -print --- src/cc/rogue/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 7971a9b3d..ca05226d3 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -718,7 +718,7 @@ void rogue_progress(struct rogue_state *rs,uint64_t seed,char *keystrokes,int32_ sprintf(params,"[\"keystrokes\",\"17\",\"[%%22%s%%22,%%22%s%%22]\"]",Gametxidstr,hexstr); if ( (retstr= komodo_issuemethod(USERPASS,"cclib",params,ROGUE_PORT)) != 0 ) { - fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); + //fprintf(stderr,"KEYSTROKES.(%s)\n",retstr); free(retstr); } } @@ -749,7 +749,7 @@ int32_t rogue_setplayerdata(struct rogue_state *rs,char *gametxidstr) { if ( (retjson= cJSON_Parse(filestr)) != 0 && (resultjson= jobj(retjson,"result")) != 0 ) { - fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); + //fprintf(stderr,"gameinfo.(%s)\n",jprint(resultjson,0)); if ( (array= jarray(&n,resultjson,"players")) != 0 ) { for (i=0; i