From 89913fa6ae498be1d9bbe96dcf86694182a0e579 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Mar 2019 03:46:03 -1100 Subject: [PATCH] pricedata --- src/cc/games/prices.c | 6 ------ src/cc/games/prices.cpp | 40 +++++++++++++++++++++++++++++++++++++++- src/cc/games/tetris.cpp | 6 ++++++ src/cc/gamescc.cpp | 2 +- src/cc/gamescc.h | 6 +++++- 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/cc/games/prices.c b/src/cc/games/prices.c index 97c617be7..3d4a65e14 100644 --- a/src/cc/games/prices.c +++ b/src/cc/games/prices.c @@ -12,12 +12,6 @@ #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"prices",cmdstr,0,0,0) extern int64_t Net_change; -/* - In order to port a game into gamesCC, the RNG needs to be seeded with the gametxid seed, also events needs to be broadcast using issue_games_events. Also the game engine needs to be daemonized, preferably by putting all globals into a single data structure. - - also, the standalone game needs to support argv of seed gametxid, along with replay args - */ - int random_tetromino(struct games_state *rs) { rs->seed = _games_rngnext(rs->seed); diff --git a/src/cc/games/prices.cpp b/src/cc/games/prices.cpp index 9db720907..a903355e4 100644 --- a/src/cc/games/prices.cpp +++ b/src/cc/games/prices.cpp @@ -14,10 +14,48 @@ * * ******************************************************************************/ +UniValue games_pricedata(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); std::string rawtx; int64_t inputsum,price; CPubKey mypk; + if ( params != 0 && cJSON_GetArraySize(params) == 1 ) + { + if ( cclib_parsehash(&price,jitem(params,0),8) < 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt parsehash")); + } + mypk = pubkey2pk(Mypubkey()); + if ( amount > GAMES_TXFEE ) + { + if ( (inputsum= AddNormalinputs(mtx,mypk,GAMES_TXFEE,64)) >= GAMES_TXFEE ) + { + rawtx = FinalizeCCTx(0,cp,mtx,mypk,GAMES_TXFEE,CScript() << OP_RETURN << price); + return(games_rawtxresult(result,rawtx,1)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough funds")); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","amount too small")); + } + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt parse")); + } + return(result); +} void prices_update(uint32_t timestamp,uint32_t uprice,int32_t ismine) { - //fprintf(stderr,"%s t%u %.4f\n",ismine!=0?"mine":"ext ",timestamp,(double)uprice/10000); + fprintf(stderr,"%s t%u %.4f %16llx\n",ismine!=0?"mine":"ext ",timestamp,(double)uprice/10000,(long long)(timestamp<<32) | uprice); } // game specific code for daemon diff --git a/src/cc/games/tetris.cpp b/src/cc/games/tetris.cpp index f1b6416ba..12c443e1e 100644 --- a/src/cc/games/tetris.cpp +++ b/src/cc/games/tetris.cpp @@ -66,6 +66,12 @@ int32_t games_payloadrecv(CPubKey pk,uint32_t timestamp,std::vector pay } else return(-1); } +UniValue games_oracledata(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result; + return(result); +} + bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { return(true); diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 17b0d371b..77b463822 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1731,7 +1731,7 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,gamespk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,GAMES_TXFEE,opret); - return(games_rawtxresult(result,rawtx,1)); + return(games_rawtxresult(resulft,rawtx,1)); } else { diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 63d029b0a..19f3f66cf 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -46,6 +46,7 @@ std::string Games_pname; { (char *)MYCCNAME, (char *)"highlander", (char *)"gametxid", 1, 1, 'H', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"events", (char *)"eventshex [gametxid [eventid]]", 1, 3, ' ', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"extract", (char *)"gametxid [pubkey]", 1, 2, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"pricedata", (char *)"hexstr", 1, 1, ' ', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"register", (char *)"gametxid [playertxid]", 1, 2, 'R', EVAL_GAMES }, bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); @@ -65,6 +66,7 @@ UniValue games_highlander(uint64_t txfee,struct CCcontract_info *cp,cJSON *param UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_pricedata(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #define CUSTOM_DISPATCH \ if ( cp->evalcode == EVAL_GAMES ) \ @@ -100,7 +102,9 @@ if ( cp->evalcode == EVAL_GAMES ) \ else if ( strcmp(method,"highlander") == 0 ) \ return(games_highlander(txfee,cp,params)); \ else if ( strcmp(method,"fund") == 0 ) \ - return(games_fund(txfee,cp,params)); \ + return(games_fund(txfee,cp,params)); \ + else if ( strcmp(method,"pricedata") == 0 ) \ + return(games_pricedata(txfee,cp,params)); \ else \ { \ result.push_back(Pair("result","error")); \