From 21684cfa77a1965ad038d4d242193fa68c2968a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Mar 2019 01:53:15 -1100 Subject: [PATCH] rngnext --- src/cc/gamescc.cpp | 31 +++++++++++++++++++++++++------ src/cc/gamescc.h | 10 +++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 02ead4d8f..a9801d03e 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -34,7 +34,7 @@ UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastf return(result); } -uint64_t games_rngnext(uint64_t initseed) +uint64_t _games_rngnext(uint64_t initseed) { uint16_t seeds[4]; int32_t i; seeds[0] = initseed; @@ -48,6 +48,25 @@ uint64_t games_rngnext(uint64_t initseed) return(((uint64_t)seeds[3] << 48) | ((uint64_t)seeds[2] << 24) | ((uint64_t)seeds[1] << 16) | seeds[0]); } +UniValue games_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +{ + UniValue result(UniValue::VOBJ); int32_t n; uint64_t seed; + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) + { + seed = jdouble(jitem(params,0),0); + result.push_back(Pair("seed",seed)); + seed = games_rngnext(seed); + result.push_back(Pair("rng",seed)); + result.push_back(Pair("result","success")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough params")); + } + return(result); +} + UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); int32_t i,n,playerid=0; uint64_t seed,initseed; bits256 hash; @@ -75,13 +94,13 @@ UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) } } initseed = seed; - seed = games_rngnext(initseed); + seed = _games_rngnext(initseed); result.push_back(Pair("playerid",(int64_t)(playerid - 1))); - result.push_back(Pair("initseed",initseed)); - result.push_back(Pair("seed",seed)); + result.push_back(Pair("seed",initseed)); + result.push_back(Pair("rng",seed)); for (i=0; i", 0, 0, '1', EVAL_GAMES }, + { (char *)MYCCNAME, (char *)"rng", (char *)"hash,seed,playerid", 2, 3, ' ', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"rngnext", (char *)"seed", 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_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #define CUSTOM_DISPATCH \ if ( cp->evalcode == EVAL_GAMES ) \ { \ if ( strcmp(method,"rng") == 0 ) \ return(games_rng(txfee,cp,params)); \ - else if ( strcmp(method,"func1") == 0 ) \ - return(games_func1(txfee,cp,params)); \ + else if ( strcmp(method,"rngnext") == 0 ) \ + return(games_rngnext(txfee,cp,params)); \ else \ { \ result.push_back(Pair("result","error")); \