This commit is contained in:
jl777
2019-03-22 00:48:24 -11:00
parent e66ec82ea2
commit b0009ecca2
3 changed files with 46 additions and 7 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -7,18 +7,18 @@ std::string MYCCLIBNAME = (char *)"gamescc";
#define MYCCNAME "games"
#define RPC_FUNCS \
{ (char *)MYCCNAME, (char *)"func0", (char *)"<parameter help>", 1, 1, '0', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"rng", (char *)"hash,seed,playerid", 2, 3, '0', EVAL_GAMES }, \
{ (char *)MYCCNAME, (char *)"func1", (char *)"<no args>", 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 \