|
|
@ -325,18 +325,26 @@ uint64_t rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 |
|
|
|
return(seed); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid) |
|
|
|
int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransaction &tx,int64_t &buyin,int32_t &maxplayers,uint256 txid,int32_t unspentv0) |
|
|
|
{ |
|
|
|
uint256 hashBlock; int32_t i,numvouts; char coinaddr[64]; CPubKey roguepk; uint64_t txfee = 10000; |
|
|
|
buyin = maxplayers = 0; |
|
|
|
if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 ) |
|
|
|
if ( (txid == zeroid || myGetTransaction(txid,tx,hashBlock) != 0) && (numvouts= tx.vout.size()) > 1 ) |
|
|
|
{ |
|
|
|
gameheight = komodo_blockheight(hashBlock); |
|
|
|
if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) >= txfee && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,0) == 0 ) |
|
|
|
if ( txid != zeroid ) |
|
|
|
gameheight = komodo_blockheight(hashBlock); |
|
|
|
else |
|
|
|
{ |
|
|
|
txid = tx.GetHash(); |
|
|
|
//fprintf(stderr,"set txid %s %llu\n",txid.GetHex().c_str(),(long long)CCgettxout(txid,0,1));
|
|
|
|
} |
|
|
|
if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) == txfee && (unspentv0 == 0 || CCgettxout(txid,0,1) == txfee) ) |
|
|
|
{ |
|
|
|
if ( rogue_newgameopreturndecode(buyin,maxplayers,tx.vout[numvouts-1].scriptPubKey) == 'G' ) |
|
|
|
{ |
|
|
|
if ( numvouts > maxplayers+1 ) |
|
|
|
if ( maxplayers < 1 || maxplayers > ROGUE_MAXPLAYERS || buyin < 0 ) |
|
|
|
return(-6); |
|
|
|
if ( numvouts > 2*maxplayers+1 ) |
|
|
|
{ |
|
|
|
for (i=0; i<maxplayers; i++) |
|
|
|
{ |
|
|
@ -346,10 +354,11 @@ int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa |
|
|
|
break; |
|
|
|
} |
|
|
|
if ( i == maxplayers ) |
|
|
|
{ |
|
|
|
// dimxy: make sure no vouts to any address other than main CC and 0.0001 faucet
|
|
|
|
return(0); |
|
|
|
else return(-5); |
|
|
|
} |
|
|
|
else return(-4); |
|
|
|
} else return(-5); |
|
|
|
} else return(-4); |
|
|
|
} else return(-3); |
|
|
|
} else return(-2); |
|
|
|
} else return(-1); |
|
|
@ -447,7 +456,7 @@ int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint |
|
|
|
return(-2); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid) == 0 ) |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0) == 0 ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"playertxid.%s got vin.%s/v%d gametxid.%s iterate.%d\n",playertxid.ToString().c_str(),playertx.vin[1].prevout.hash.ToString().c_str(),(int32_t)playertx.vin[1].prevout.n-maxplayers,gametxid.ToString().c_str(),rogue_iterateplayer(registertxid,gametxid,playertx.vin[1].prevout.n-maxplayers,playertxid));
|
|
|
|
if ( (tokenid != zeroid || playertx.vin[1].prevout.hash == gametxid) && rogue_iterateplayer(registertxid,gametxid,playertx.vin[1].prevout.n-maxplayers,playertxid) == 0 ) |
|
|
@ -719,7 +728,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|
|
|
if ( n > 0 ) |
|
|
|
{ |
|
|
|
gametxid = juint256(jitem(params,0)); |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid)) == 0 ) |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1)) == 0 ) |
|
|
|
{ |
|
|
|
if ( n > 1 ) |
|
|
|
{ |
|
|
@ -803,7 +812,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param |
|
|
|
mypk = pubkey2pk(Mypubkey()); |
|
|
|
roguepk = GetUnspendable(cp,0); |
|
|
|
GetCCaddress1of2(cp,destaddr,roguepk,mypk); |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid) == 0 ) |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1) == 0 ) |
|
|
|
{ |
|
|
|
if ( rogue_findbaton(cp,playertxid,0,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,tx,maxplayers,destaddr,numplayers,symbol,pname) == 0 ) |
|
|
|
{ |
|
|
@ -811,7 +820,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param |
|
|
|
result.push_back(Pair("playertxid",playertxid.GetHex())); |
|
|
|
if ( maxplayers == 1 || nextheight <= batonht+ROGUE_MAXKEYSTROKESGAP ) |
|
|
|
{ |
|
|
|
mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); |
|
|
|
mtx.vin.push_back(CTxIn(batontxid,batonvout,CScript())); //this validates user if pk
|
|
|
|
mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,batonvalue-txfee,roguepk,mypk)); |
|
|
|
Myprivkey(mypriv); |
|
|
|
CCaddr1of2set(cp,roguepk,mypk,mypriv,destaddr); |
|
|
@ -830,7 +839,7 @@ char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector<uint8_t> &newdat |
|
|
|
roguepk = GetUnspendable(cp,0); |
|
|
|
*numkeysp = 0; |
|
|
|
seed = 0; |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0)) == 0 ) |
|
|
|
{ |
|
|
|
if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,rogueaddr,numplayers,symbol,pname) == 0 ) |
|
|
|
{ |
|
|
@ -957,7 +966,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param |
|
|
|
else |
|
|
|
{ |
|
|
|
funcid = 'H'; |
|
|
|
mult = 1000000; |
|
|
|
mult = 200000; |
|
|
|
} |
|
|
|
if ( (params= cclib_reparse(&n,params)) != 0 ) |
|
|
|
{ |
|
|
@ -965,7 +974,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param |
|
|
|
{ |
|
|
|
gametxid = juint256(jitem(params,0)); |
|
|
|
result.push_back(Pair("gametxid",gametxid.GetHex())); |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,1)) == 0 ) |
|
|
|
{ |
|
|
|
if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,myrogueaddr,numplayers,symbol,pname) == 0 ) |
|
|
|
{ |
|
|
@ -1008,11 +1017,13 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param |
|
|
|
cpTokens = CCinit(&tokensC, EVAL_TOKENS); |
|
|
|
mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cpTokens,NULL))); // marker to token cc addr, burnable and validated
|
|
|
|
mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); |
|
|
|
fprintf(stderr,"\nextracted $$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d size.%d\n",P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,(int32_t)sizeof(P)); |
|
|
|
fprintf(stderr,"\nextracted $$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d amulet.%d\n",P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,P.amulet); |
|
|
|
if ( P.amulet != 0 ) |
|
|
|
mult *= 5; |
|
|
|
cashout = (uint64_t)P.gold * mult; |
|
|
|
if ( funcid == 'H' && maxplayers > 1 ) |
|
|
|
{ |
|
|
|
if ( numplayers != maxplayers || (numplayers - rogue_playersalive(tmp,gametxid,maxplayers)) > 1 && (P.dungeonlevel > 1 || P.gold < 10000 || P.level < 20) ) |
|
|
|
if ( (numplayers != maxplayers || (numplayers - rogue_playersalive(tmp,gametxid,maxplayers)) > 1) && P.amulet == 0 ) |
|
|
|
return(cclib_error(result,"highlander must be a winner or last one standing")); |
|
|
|
cashout += numplayers * buyin; |
|
|
|
} |
|
|
@ -1076,7 +1087,7 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|
|
|
{ |
|
|
|
txid = juint256(jitem(params,0)); |
|
|
|
result.push_back(Pair("gametxid",txid.GetHex())); |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid) == 0 ) |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid,0) == 0 ) |
|
|
|
{ |
|
|
|
result.push_back(Pair("result","success")); |
|
|
|
result.push_back(Pair("gameheight",(int64_t)gameheight)); |
|
|
@ -1116,7 +1127,7 @@ UniValue rogue_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|
|
|
//char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN);
|
|
|
|
if ( it->second.satoshis != txfee || vout != 0 ) // reject any that are not highlander markers
|
|
|
|
continue; |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid) == 0 && nextheight <= gameheight+ROGUE_MAXKEYSTROKESGAP ) |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,txid,1) == 0 && nextheight <= gameheight+ROGUE_MAXKEYSTROKESGAP ) |
|
|
|
{ |
|
|
|
rogue_playersalive(numplayers,txid,maxplayers); |
|
|
|
if ( numplayers < maxplayers ) |
|
|
@ -1180,7 +1191,7 @@ UniValue rogue_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|
|
|
{ |
|
|
|
if ( rogue_registeropretdecode(gametxid,tokenid,playertxid,tx.vout[numvouts-1].scriptPubKey) == 'R' ) |
|
|
|
{ |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid) == 0 ) |
|
|
|
if ( rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid,0) == 0 ) |
|
|
|
{ |
|
|
|
if ( CCgettxout(txid,vout,1) < 0 ) |
|
|
|
b.push_back(gametxid.GetHex()); |
|
|
@ -1260,7 +1271,7 @@ int32_t rogue_playerdata_validate(uint256 &playertxid,struct CCcontract_info *cp |
|
|
|
|
|
|
|
bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) |
|
|
|
{ |
|
|
|
CScript scriptPubKey; std::vector<uint8_t> vopret; uint8_t *script,e,f,funcid; int32_t i,maxplayers,decoded=0,regslot,ind,errflag,dispflag,score,numvouts; CTransaction vintx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid,ptxid; int64_t buyin; std::vector<uint8_t> playerdata,keystrokes; std::string symbol,pname; |
|
|
|
CScript scriptPubKey; std::vector<uint8_t> vopret; uint8_t *script,e,f,funcid; int32_t i,maxplayers,decoded=0,regslot,ind,err,dispflag,gameheight,score,numvouts; CTransaction vintx,gametx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid,ptxid; int64_t buyin; std::vector<uint8_t> playerdata,keystrokes; std::string symbol,pname; |
|
|
|
if ( strcmp(ASSETCHAINS_SYMBOL,"ROGUE") == 0 && height < 21274 ) |
|
|
|
return(true); |
|
|
|
if ( (numvouts= tx.vout.size()) > 1 ) |
|
|
@ -1283,19 +1294,21 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C |
|
|
|
} |
|
|
|
if ( e == EVAL_ROGUE ) |
|
|
|
{ |
|
|
|
fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]); |
|
|
|
//fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
|
|
|
|
if ( decoded == 0 ) |
|
|
|
{ |
|
|
|
switch ( funcid ) |
|
|
|
{ |
|
|
|
case 'G': |
|
|
|
if ( (funcid= rogue_newgameopreturndecode(buyin,maxplayers,scriptPubKey)) != 'G' ) |
|
|
|
case 'G': // seems just need to make sure no vout abuse is left to do
|
|
|
|
gametx = tx; |
|
|
|
gametxid = tx.GetHash(); |
|
|
|
gameheight = height; |
|
|
|
if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,zeroid,0)) != 0 ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"height.%d couldnt decode newgame opret\n",height);
|
|
|
|
//if ( height > 20000 )
|
|
|
|
return eval->Invalid("couldnt decode newgame opret"); |
|
|
|
fprintf(stderr,"height.%d %s rogue_isvalidgame error.%d\n",height,gametxid.GetHex().c_str(),err); |
|
|
|
return eval->Invalid("invalid gametxid"); |
|
|
|
} |
|
|
|
// validate newgame tx
|
|
|
|
//fprintf(stderr,"height.%d %s rogue_isvalidgame\n",height,gametxid.GetHex().c_str());
|
|
|
|
return(true); |
|
|
|
break; |
|
|
|
case 'R': |
|
|
@ -1305,6 +1318,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C |
|
|
|
//if ( height > 20000 )
|
|
|
|
return eval->Invalid("couldnt decode register opret"); |
|
|
|
} |
|
|
|
// baton is created
|
|
|
|
// validation is done below
|
|
|
|
break; |
|
|
|
case 'K': |
|
|
@ -1314,7 +1328,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C |
|
|
|
//if ( height > 20000 )
|
|
|
|
return eval->Invalid("couldnt decode keystrokes opret"); |
|
|
|
} |
|
|
|
// validate keystrokes are from the correct pk. might need to add vin
|
|
|
|
// spending the baton proves it is the user if the pk is the signer
|
|
|
|
return(true); |
|
|
|
break; |
|
|
|
case 'H': case 'Q': |
|
|
@ -1324,7 +1338,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C |
|
|
|
//if ( height > 20000 )
|
|
|
|
return eval->Invalid("couldnt decode H/Q opret"); |
|
|
|
} |
|
|
|
// validation is done below
|
|
|
|
// spending the baton proves it is the user if the pk is the signer
|
|
|
|
// rest of validation is done below
|
|
|
|
break; |
|
|
|
default: |
|
|
|
return eval->Invalid("illegal rogue non-decoded funcid"); |
|
|
@ -1334,6 +1349,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C |
|
|
|
switch ( funcid ) |
|
|
|
{ |
|
|
|
case 'R': // register
|
|
|
|
// verify vout amounts are as they should be and no vins that shouldnt be
|
|
|
|
return(true); |
|
|
|
case 'H': // win
|
|
|
|
case 'Q': // bailout
|
|
|
@ -1351,7 +1367,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C |
|
|
|
} |
|
|
|
else // 'H'
|
|
|
|
{ |
|
|
|
// verify vin/vout
|
|
|
|
// verify vin/vout and proper payouts
|
|
|
|
} |
|
|
|
return(true); |
|
|
|
break; |
|
|
|