From 5a1c07c477ecbc2fe54a2ee64e3a1f0895a80e34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 24 Mar 2019 23:31:14 -1100 Subject: [PATCH 1/5] +print --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 079ce1eea..c1f488c5c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2079,7 +2079,7 @@ void komodo_args(char *argv0) while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { - fprintf(stderr,"waiting for datadir\n"); + fprintf(stderr,"waiting for datadir (%s)\n",dirname); #ifndef _WIN32 sleep(3); #else From 55a5f398aaac8319453122dbe2b63e10607afaf6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 00:38:27 -1100 Subject: [PATCH 2/5] Sign event payload --- src/cc/gamescc.cpp | 69 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 89efcc6d2..7628db500 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -45,6 +45,16 @@ uint8_t games_opretdecode(CPubKey &pk,CScript scriptPubKey) return(0); } +uint8_t games_eventdecode(CPubKey &pk,std::vector &sig,std::vector &payload,std::vector message) +{ + uint8_t e,f; + if ( message.size() > 2 && E_UNMARSHAL(message,ss >> e; ss >> f; ss >> pk; ss >> sig; ss >> payload) != 0 && e == EVAL_GAMES ) + { + return(f); + } + return(0); +} + UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag) { CTransaction tx; @@ -154,15 +164,49 @@ UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } +int32_t games_eventsign(std::vector &sig,std::vector payload,CPubKey pk) +{ + bool signSuccess; SignatureData sigdata; uint256 hash; uint8_t *ptr; auto consensusBranchId = 0; + const CKeyStore& keystore = *pwalletMain; + txNew.vin.resize(1); + txNew.vout.resize(1); + txNew.vin[0].prevout.hash = payload.GetHash(); + txNew.vin[0].prevout.n = 0; + txNew.vout[0].scriptPubKey = CScript() << payload << OP_DROP << ParseHex(HexString(pk)) << OP_CHECKSIG; + txNew.vout[0].nValue = (int32_t)payload.size(); + txNew.nLockTime = 0; + CTransaction txNewConst(txNew); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), txNew.vout[0].scriptPubKey, sigdata, consensusBranchId); + if ( signSuccess > 0 ) + { + UpdateTransaction(txNew,0,sigdata); + ptr = (uint8_t *)&sigdata.scriptSig[0]; + siglen = sigdata.scriptSig.size(); + sig.resize(siglen); + for (i=0; i payload; int32_t n; + UniValue result(UniValue::VOBJ); std::vector sig,payload; int32_t n; CPubKey mypk; uint256 hash; if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) { if ( payments_parsehexdata(payload,jitem(params,0),0) == 0 ) { - komodo_sendmessage(4,8,"events",payload); - result.push_back(Pair("result","success")); + mypk = pubkey2pk(Mypubkey()); + if ( games_eventsign(sig,payload,mypk) == 0 ) + { + komodo_sendmessage(4,8,"events",E_MARSHAL(ss << EVAL_GAMES << 'E' << mypk << sig << payload)); + result.push_back(Pair("result","success")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","signing ereror")); + } } else { @@ -178,12 +222,21 @@ UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -void komodo_netevent(std::vector payload) +void komodo_netevent(std::vector message) { - int32_t i; - for (i=0; i sig,payload; char str[67]; + if ( games_eventdecode(pk,sig,payload,message) == 'E' ) + { + for (i=0; i Date: Mon, 25 Mar 2019 00:45:04 -1100 Subject: [PATCH 3/5] Syntax --- src/cc/gamescc.cpp | 8 ++++---- src/cc/gamescc.h | 1 + src/cc/payments.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 7628db500..1a7ce0257 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -166,17 +166,17 @@ UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) int32_t games_eventsign(std::vector &sig,std::vector payload,CPubKey pk) { - bool signSuccess; SignatureData sigdata; uint256 hash; uint8_t *ptr; auto consensusBranchId = 0; + bool signSuccess; SignatureData sigdata; int32_t i,siglen; uint256 hash; uint8_t *ptr; auto consensusBranchId = 0; CMutableTransaction txNew; const CKeyStore& keystore = *pwalletMain; txNew.vin.resize(1); txNew.vout.resize(1); txNew.vin[0].prevout.hash = payload.GetHash(); txNew.vin[0].prevout.n = 0; - txNew.vout[0].scriptPubKey = CScript() << payload << OP_DROP << ParseHex(HexString(pk)) << OP_CHECKSIG; - txNew.vout[0].nValue = (int32_t)payload.size(); + txNew.vout[0].scriptPubKey = CScript() << payload << OP_DROP << ParseHex(HexStr(pk)) << OP_CHECKSIG; + txNew.vout[0].nValue = payload.size(); txNew.nLockTime = 0; CTransaction txNewConst(txNew); - signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, *utxovaluep, SIGHASH_ALL), txNew.vout[0].scriptPubKey, sigdata, consensusBranchId); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, payload.size(), SIGHASH_ALL), txNew.vout[0].scriptPubKey, sigdata, consensusBranchId); if ( signSuccess > 0 ) { UpdateTransaction(txNew,0,sigdata); diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 02f589056..6e88b9e32 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -1,3 +1,4 @@ +#include "CCinclud.h" std::string MYCCLIBNAME = (char *)"gamescc"; diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 0190bf198..75c1431f0 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -569,7 +569,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); - CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease,totalallocations; std::vector txidoprets; + CPubKey Paymentspk,mypk,txidpk; uint256 txid,hashBlock; int64_t amount,totalallocations; CScript opret; CTransaction tx; char txidaddr[64]; std::string rawtx; int32_t n,useopret = 0,lockedblocks,minrelease; std::vector txidoprets; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); Paymentspk = GetUnspendable(cp,0); @@ -662,7 +662,7 @@ UniValue PaymentsTxidopret(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::vector txidoprets; uint256 hashBlock; int32_t i,n,numoprets=0,lockedblocks,minrelease,totalallocations=0; std::string rawtx; + UniValue result(UniValue::VOBJ); CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::vector txidoprets; uint256 hashBlock; int32_t i,n,numoprets=0,lockedblocks,minrelease; std::string rawtx; int64_t totalallocations = 0; cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n >= 4 ) { From 5a6c3fa7e71c922407ff77d7e35fbcd01915a3bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 00:45:37 -1100 Subject: [PATCH 4/5] E --- src/cc/gamescc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 6e88b9e32..143ecc50a 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -1,4 +1,4 @@ -#include "CCinclud.h" +#include "CCinclude.h" std::string MYCCLIBNAME = (char *)"gamescc"; From aa1c34fbf488d065593c2703ea065ff6c07d79fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 25 Mar 2019 00:49:17 -1100 Subject: [PATCH 5/5] Syntax --- src/cc/gamescc.cpp | 2 +- src/cc/gamescc.h | 1 + src/cc/payments.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 1a7ce0257..7aa7c46da 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -229,7 +229,7 @@ void komodo_netevent(std::vector message) { for (i=0; i scriptPubKey,opret; int32_t allocation; + std::vector scriptPubKey,opret; int64_t allocation; if ( myGetTransaction(txidoprets[i],tx,hashBlock) != 0 && tx.vout.size() > 1 && DecodePaymentsTxidOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) { totalallocations += allocation; @@ -732,7 +732,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,allocation,numoprets=0,lockedblocks,minrelease,totalallocations; std::vector txidoprets; int64_t funds,fundsopret; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease; std::vector txidoprets; int64_t funds,fundsopret,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n == 1 ) {