diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ed06c1a4d..2713dd9ed 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -601,7 +601,6 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 return(0); } - int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index cd2022231..edc4904fb 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -34,9 +34,49 @@ UniValue games_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastf return(result); } -UniValue games_func0(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) +UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - UniValue result(UniValue::VOBJ); + UniValue result(UniValue::VOBJ); int32_t i,n,playerid=0; uint16_t seeds[4]; uint64_t seed; bits256 hash; + if ( params != 0 && ((n= cJSON_GetArraySize(params)) == 2 || n == 3) ) + { + hash = jbits256(jitem(params,0),0); + seed = jdouble(jitem(params,1),0); + if ( n == 3 ) + { + playerid = juint(jitem(params,2),0); + if ( playerid >= 0x100 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","playerid too big")); + return(result); + } + } + if ( seed == 0 ) + { + playerid++; + if ( playerid == 0x100 ) + { + for (i=0; i<8; i++) + hash.uints[i] ^= 0xffffffff; + playerid--; + } + for (i=0; i<8; i++) + { + if ( ((1 << i) & playerid) != 0 ) + seed ^= hash.uints[i]; + } + } + else + { + for (i=0; i<4; i++) + { + seeds[i] = (seed >> (i*16)); + seeds[i] = (seeds[i]*11109 + 13849); + } + seed = ((uint64_t)seeds[3] << 48) | ((uint64_t)seeds[2] << 24) | ((uint64_t)seeds[1] << 16) | seeds[0]; + } + result.push_back(Pair("seed",seed)); + } result.push_back(Pair("result","success")); result.push_back(Pair("message","just an example of an information returning rpc")); return(result); diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 5eceb2d35..ebdb92a93 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -7,18 +7,18 @@ std::string MYCCLIBNAME = (char *)"gamescc"; #define MYCCNAME "games" #define RPC_FUNCS \ - { (char *)MYCCNAME, (char *)"func0", (char *)"", 1, 1, '0', EVAL_GAMES }, \ + { (char *)MYCCNAME, (char *)"rng", (char *)"hash,seed,playerid", 2, 3, '0', EVAL_GAMES }, \ { (char *)MYCCNAME, (char *)"func1", (char *)"", 0, 0, '1', EVAL_GAMES }, bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); -UniValue games_func0(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue games_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); #define CUSTOM_DISPATCH \ if ( cp->evalcode == EVAL_GAMES ) \ { \ - if ( strcmp(method,"func0") == 0 ) \ - return(games_func0(txfee,cp,params)); \ + if ( strcmp(method,"rng") == 0 ) \ + return(games_rng(txfee,cp,params)); \ else if ( strcmp(method,"func1") == 0 ) \ return(games_func1(txfee,cp,params)); \ else \