diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 89efcc6d2..7aa7c46da 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; 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(HexStr(pk)) << OP_CHECKSIG; + txNew.vout[0].nValue = payload.size(); + txNew.nLockTime = 0; + CTransaction txNewConst(txNew); + signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, payload.size(), 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 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 ) { @@ -680,7 +680,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) txidoprets.push_back(payments_juint256(jitem(params,2+i))); 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 ) { 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