Fund
This commit is contained in:
@@ -1443,5 +1443,42 @@ UniValue games_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue games_fund(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 amount,inputsum; CPubKey gamespk,mypk; std::vector<uint8_t> opret;
|
||||
if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 )
|
||||
{
|
||||
amount = jdouble(jitem(params,1),0) * COIN + 0.0000000049;
|
||||
gamespk = GetUnspendable(cp,0);
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( amount > GAMES_TXFEE )
|
||||
{
|
||||
if ( (inputsum= AddNormalinputs(mtx,mypk,amount+GAMES_TXFEE,64)) >= amount+GAMES_TXFEE )
|
||||
{
|
||||
mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,amount,gamespk));
|
||||
rawtx = FinalizeCCTx(0,cp,mtx,mypk,GAMES_TXFEE,opret);
|
||||
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);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ std::string Games_pname;
|
||||
#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 *)"fund", (char *)"amount", 1, 1, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"players", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"games", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"pending", (char *)"no params", 0, 0, ' ', EVAL_GAMES }, \
|
||||
@@ -49,6 +50,7 @@ std::string Games_pname;
|
||||
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_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
|
||||
@@ -811,7 +811,7 @@ int tetris(int argc, char **argv)
|
||||
#endif // _WIN32
|
||||
rs->seed = rs->origseed;
|
||||
strcpy(Gametxidstr,argv[2]);
|
||||
fprintf(stderr,"setplayerdata\n");
|
||||
fprintf(stderr,"setplayerdata %s\n",Gametxidstr);
|
||||
if ( games_setplayerdata(rs,Gametxidstr) < 0 )
|
||||
{
|
||||
fprintf(stderr,"invalid gametxid, or already started\n");
|
||||
|
||||
Reference in New Issue
Block a user