Events
This commit is contained in:
@@ -195,6 +195,8 @@ int64_t AddTokenCCInputs(struct CCcontract_info *cp, CMutableTransaction &mtx, C
|
||||
int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, const CTransaction& tx, int32_t v, uint256 reftokenid);
|
||||
|
||||
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx);
|
||||
void komodo_sendmessage(int32_t minpeers,int32_t maxpeers,const char *message,std::vector<uint8_t> payload);
|
||||
int32_t payments_parsehexdata(std::vector<uint8_t> &hexdata,cJSON *item,int32_t len);
|
||||
|
||||
CScript EncodeTokenCreateOpRet(uint8_t funcid, std::vector<uint8_t> origpubkey, std::string name, std::string description, vscript_t vopretNonfungible);
|
||||
CScript EncodeTokenCreateOpRet(uint8_t funcid, std::vector<uint8_t> origpubkey, std::string name, std::string description, std::vector<std::pair<uint8_t, vscript_t>> oprets);
|
||||
|
||||
@@ -136,35 +136,51 @@ UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
return(result);
|
||||
}
|
||||
|
||||
// send yourself 1 coin to your CC address using normal utxo from your -pubkey
|
||||
|
||||
UniValue games_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
{
|
||||
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); std::string rawtx;
|
||||
UniValue result(UniValue::VOBJ); CPubKey mypk; int64_t amount = COIN; int32_t broadcastflag=0;
|
||||
if ( txfee == 0 )
|
||||
txfee = GAMES_TXFEE;
|
||||
mypk = pubkey2pk(Mypubkey());
|
||||
if ( AddNormalinputs(mtx,mypk,COIN+txfee,64) >= COIN+txfee ) // add utxo to mtx
|
||||
UniValue result(UniValue::VOBJ); std::vector<uint8_t> payload; int32_t n;
|
||||
if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 )
|
||||
{
|
||||
mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,mypk)); // make vout0
|
||||
rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,games_opret('1',mypk));
|
||||
return(games_rawtxresult(result,rawtx,broadcastflag));
|
||||
if ( payments_parsehexdata(payload,jitem(params,0),0) == 0 )
|
||||
{
|
||||
komodo_sendmessage(4,8,"events",payload);
|
||||
result.push_back(Pair("result","success"));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result","error"));
|
||||
result.push_back(Pair("error","couldnt parsehexdata"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.push_back(Pair("result","error"));
|
||||
result.push_back(Pair("error","not enough params"));
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue games_create(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue games_info(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
return(result);
|
||||
}
|
||||
|
||||
UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||
{
|
||||
UniValue result(UniValue::VOBJ);
|
||||
return(result);
|
||||
}
|
||||
|
||||
bool games_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx)
|
||||
{
|
||||
char expectedaddress[64]; CPubKey pk;
|
||||
if ( tx.vout.size() != 2 ) // make sure the tx only has 2 outputs
|
||||
return eval->Invalid("invalid number of vouts");
|
||||
else if ( games_opretdecode(pk,tx.vout[1].scriptPubKey) != '1' ) // verify has opreturn
|
||||
return eval->Invalid("invalid opreturn");
|
||||
GetCCaddress(cp,expectedaddress,pk);
|
||||
if ( IsCClibvout(cp,tx,0,expectedaddress) == COIN ) // make sure amount and destination matches
|
||||
return(true);
|
||||
else return eval->Invalid("invalid vout0 amount");
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,11 +12,19 @@ std::string MYCCLIBNAME = (char *)"gamescc";
|
||||
|
||||
#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 *)"rngnext", (char *)"seed", 1, 1, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"create", (char *)"game,minplayers,maxplayers,buyin,numblocks", 5, 5, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"info", (char *)"txid", 1, 1, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"events", (char *)"hex", 1, 1, ' ', EVAL_GAMES }, \
|
||||
{ (char *)MYCCNAME, (char *)"register", (char *)"txid", 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_rngnext(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_create(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_info(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
UniValue games_events(uint64_t txfee,struct CCcontract_info *cp,cJSON *params);
|
||||
|
||||
#define CUSTOM_DISPATCH \
|
||||
if ( cp->evalcode == EVAL_GAMES ) \
|
||||
@@ -25,6 +33,14 @@ if ( cp->evalcode == EVAL_GAMES ) \
|
||||
return(games_rng(txfee,cp,params)); \
|
||||
else if ( strcmp(method,"rngnext") == 0 ) \
|
||||
return(games_rngnext(txfee,cp,params)); \
|
||||
else if ( strcmp(method,"create") == 0 ) \
|
||||
return(games_create(txfee,cp,params)); \
|
||||
else if ( strcmp(method,"info") == 0 ) \
|
||||
return(games_info(txfee,cp,params)); \
|
||||
else if ( strcmp(method,"register") == 0 ) \
|
||||
return(games_register(txfee,cp,params)); \
|
||||
else if ( strcmp(method,"events") == 0 ) \
|
||||
return(games_events(txfee,cp,params)); \
|
||||
else \
|
||||
{ \
|
||||
result.push_back(Pair("result","error")); \
|
||||
|
||||
Reference in New Issue
Block a user