From 112df09f652ca26d1874776efec3c12c8196b63c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Mar 2019 04:25:09 -1100 Subject: [PATCH] Events --- src/cc/CCinclude.h | 2 ++ src/cc/gamescc.cpp | 58 +++++++++++++++++++++++++++++----------------- src/cc/gamescc.h | 18 +++++++++++++- src/main.cpp | 18 ++++++++++++-- src/miner.cpp | 17 ++++++++++++++ 5 files changed, 89 insertions(+), 24 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index f5877c711..13d7236d4 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -195,6 +195,8 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid); bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx); +void komodo_sendmessage(int32_t minpeers,int32_t maxpeers,const char *message,std::vector payload); +int32_t payments_parsehexdata(std::vector &hexdata,cJSON *item,int32_t len); CScript EncodeTokenCreateOpRet(uint8_t funcid, std::vector origpubkey, std::string name, std::string description, vscript_t vopretNonfungible); CScript EncodeTokenCreateOpRet(uint8_t funcid, std::vector origpubkey, std::string name, std::string description, std::vector> oprets); diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index d9ea74871..68de4bb8a 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -136,35 +136,51 @@ UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } -// send yourself 1 coin to your CC address using normal utxo from your -pubkey - -UniValue games_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string rawtx; - UniValue result(UniValue::VOBJ); CPubKey mypk; int64_t amount = COIN; int32_t broadcastflag=0; - if ( txfee == 0 ) - txfee = GAMES_TXFEE; - mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs(mtx,mypk,COIN+txfee,64) >= COIN+txfee ) // add utxo to mtx + UniValue result(UniValue::VOBJ); std::vector payload; int32_t n; + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,mypk)); // make vout0 - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,games_opret('1',mypk)); - return(games_rawtxresult(result,rawtx,broadcastflag)); + if ( payments_parsehexdata(payload,jitem(params,0),0) == 0 ) + { + komodo_sendmessage(4,8,"events",payload); + result.push_back(Pair("result","success")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt parsehexdata")); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough params")); } return(result); } +UniValue games_create(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + return(result); +} + +UniValue games_info(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + return(result); +} + +UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); + return(result); +} + bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - char expectedaddress[64]; CPubKey pk; - if ( tx.vout.size() != 2 ) // make sure the tx only has 2 outputs - return eval->Invalid("invalid number of vouts"); - else if ( games_opretdecode(pk,tx.vout[1].scriptPubKey) != '1' ) // verify has opreturn - return eval->Invalid("invalid opreturn"); - GetCCaddress(cp,expectedaddress,pk); - if ( IsCClibvout(cp,tx,0,expectedaddress) == COIN ) // make sure amount and destination matches - return(true); - else return eval->Invalid("invalid vout0 amount"); + return(true); } diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index a8e472622..02f589056 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -12,11 +12,19 @@ std::string MYCCLIBNAME = (char *)"gamescc"; #define RPC_FUNCS \ { (char *)MYCCNAME, (char *)"rng", (char *)"hash,playerid", 1, 2, ' ', EVAL_GAMES }, \ - { (char *)MYCCNAME, (char *)"rngnext", (char *)"seed", 1, 1, ' ', EVAL_GAMES }, + { (char *)MYCCNAME, (char *)"rngnext", (char *)"seed", 1, 1, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"create", (char *)"game,minplayers,maxplayers,buyin,numblocks", 5, 5, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"info", (char *)"txid", 1, 1, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"events", (char *)"hex", 1, 1, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"register", (char *)"txid", 1, 1, ' ', EVAL_GAMES }, bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_create(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_info(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #define CUSTOM_DISPATCH \ if ( cp->evalcode == EVAL_GAMES ) \ @@ -25,6 +33,14 @@ if ( cp->evalcode == EVAL_GAMES ) \ return(games_rng(txfee,cp,params)); \ else if ( strcmp(method,"rngnext") == 0 ) \ return(games_rngnext(txfee,cp,params)); \ + else if ( strcmp(method,"create") == 0 ) \ + return(games_create(txfee,cp,params)); \ + else if ( strcmp(method,"info") == 0 ) \ + return(games_info(txfee,cp,params)); \ + else if ( strcmp(method,"register") == 0 ) \ + return(games_register(txfee,cp,params)); \ + else if ( strcmp(method,"events") == 0 ) \ + return(games_events(txfee,cp,params)); \ else \ { \ result.push_back(Pair("result","error")); \ diff --git a/src/main.cpp b/src/main.cpp index ce0760cf5..996fe2e3c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7035,8 +7035,22 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 1); return false; } - - + else if ( strCommand == "events" ) + { + int32_t i; + if ( ASSETCHAINS_CCLIB != MYCCLIBNAME || ASSETCHAINS_CCLIB != "gamescc" ) + { + Misbehaving(pfrom->GetId(), 1); + return false; + } + CNodeState *state = State(pfrom->GetId()); + if (state == NULL) + return; + for (i=0; iname ); + return(true); + } else if (strCommand == "verack") { pfrom->SetRecvVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); diff --git a/src/miner.cpp b/src/miner.cpp index 2069e5a8c..eaba96ee1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -931,6 +931,23 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake); } +void komodo_sendmessage(int32_t minpeers,int32_t maxpeers,const char *message,std::vector payload) +{ + int32_t numsent = 0; + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + if ( pnode->hSocket == INVALID_SOCKET ) + continue; + if ( numsent < minpeers || (rand() % 10) == 0 ) + { + pnode->PushMessage(message,payload); + if ( numsent++ > maxpeers ) + break; + } + } +} + void komodo_broadcast(CBlock *pblock,int32_t limit) { if (IsInitialBlockDownload())