Merge pull request #1261 from jl777/jl777

Jl777
This commit is contained in:
jl777
2019-02-18 06:14:52 -11:00
committed by GitHub
8 changed files with 177 additions and 104 deletions

View File

@@ -305,7 +305,7 @@ bool AssetsValidate(struct CCcontract_info *cpAssets,Eval* eval,const CTransacti
return eval->Invalid("mismatched vout0 AssetsCCaddr for fillbuy"); return eval->Invalid("mismatched vout0 AssetsCCaddr for fillbuy");
} }
} }
fprintf(stderr,"fillbuy validated\n"); //fprintf(stderr,"fillbuy validated\n");
break; break;
//case 'e': // selloffer //case 'e': // selloffer
// break; // disable swaps // break; // disable swaps

View File

@@ -162,7 +162,7 @@ int32_t mvaddch(int32_t y, int32_t x, chtype ch)
int32_t waddstr(WINDOW *win, const char *str) int32_t waddstr(WINDOW *win, const char *str)
{ {
int32_t i; int32_t i;
//fprintf(stderr,"%s\n",str); fprintf(stderr,"%s\n",str);
for (i=0; str[i]!=0; i++) for (i=0; str[i]!=0; i++)
waddch(win,str[i]); waddch(win,str[i]);
return(0); return(0);
@@ -422,3 +422,9 @@ int32_t md_readchar(void)
return(0); return(0);
} }
char *unctrl(char c)
{
static char ctrlstr[5];
sprintf(ctrlstr,"^%%%02x",c);
return(ctrlstr);
}

View File

@@ -123,9 +123,10 @@ int32_t wprintw(WINDOW *win,char *fmt,...);
int32_t mvprintw(int32_t y,int32_t x,char *fmt,...); int32_t mvprintw(int32_t y,int32_t x,char *fmt,...);
int32_t mvwprintw(WINDOW *win,int32_t y,int32_t x,char *fmt,...); int32_t mvwprintw(WINDOW *win,int32_t y,int32_t x,char *fmt,...);
char *unctrl(char c);
#define A_CHARTEXT 0xff #define A_CHARTEXT 0xff
#define baudrate() 9600 #define baudrate() 9600
#define unctrl(a) "^x"
#define getmaxx(a) COLS #define getmaxx(a) COLS
#define getmaxy(a) LINES #define getmaxy(a) LINES
#define getyx(win,_argfory,_argforx) _argfory = win->y, _argforx = win->x #define getyx(win,_argfory,_argforx) _argfory = win->y, _argforx = win->x

View File

@@ -169,7 +169,7 @@ int32_t num_packitems(struct rogue_state *rs)
total += list->o_count; total += list->o_count;
} }
} }
if ( 0 ) if ( rs->guiflag != 0 )
{ {
char str[MAXSTR]; char str[MAXSTR];
sprintf(str,"strength*3 %d vs total.%d vs %d inventory letters\n",pstats.s_str*3,total,n); sprintf(str,"strength*3 %d vs total.%d vs %d inventory letters\n",pstats.s_str*3,total,n);
@@ -410,59 +410,63 @@ get_item(struct rogue_state *rs,char *purpose, int type)
{ {
THING *obj; THING *obj;
char ch; char ch;
if (pack == NULL) if (pack == NULL)
msg(rs,"you aren't carrying anything"); msg(rs,"you aren't carrying anything");
else if (again) else if (again)
if (last_pick) if (last_pick)
return last_pick; return last_pick;
else else
msg(rs,"you ran out"); msg(rs,"you ran out");
else else
{ {
for (;;) for (;;)
{ {
if (!terse) if (!terse)
addmsg(rs,"which object do you want to "); addmsg(rs,"which object do you want to ");
addmsg(rs,purpose); addmsg(rs,purpose);
if (terse) if (terse)
addmsg(rs," what"); addmsg(rs," what");
msg(rs,"? (* for list): "); msg(rs,"? (* for list): ");
ch = readchar(rs); ch = readchar(rs);
mpos = 0; mpos = 0;
/* /*
* Give the poor player a chance to abort the command * Give the poor player a chance to abort the command
*/ */
if (ch == ESCAPE) if (ch == ESCAPE)
{ {
reset_last(); reset_last();
after = FALSE; after = FALSE;
msg(rs,""); msg(rs,"");
return NULL; return NULL;
} }
n_objs = 1; /* normal case: person types one char */ n_objs = 1; /* normal case: person types one char */
if (ch == '*') if (ch == '*')
{ {
mpos = 0; mpos = 0;
if (inventory(rs,pack, type) == 0) if (inventory(rs,pack, type) == 0)
{ {
after = FALSE; after = FALSE;
return NULL; return NULL;
} }
continue; continue;
} }
for (obj = pack; obj != NULL; obj = next(obj)) for (obj = pack; obj != NULL; obj = next(obj))
if (obj->o_packch == ch) if (obj->o_packch == ch)
break; break;
if (obj == NULL) if (obj == NULL)
{ {
msg(rs,"'%s' is not a valid item",unctrl(ch)); //msg(rs,"'%s' is not a valid item",unctrl(ch));
continue; //continue;
} reset_last();
else after = FALSE;
return obj; msg(rs,"'%s' is not a valid item",unctrl(ch));
} return NULL;
} }
else
return obj;
}
}
return NULL; return NULL;
} }

View File

@@ -238,7 +238,7 @@ void rogue_bailout(struct rogue_state *rs)
int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis) int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis)
{ {
struct rogue_state *rs; FILE *fp; int32_t i; struct rogue_state *rs; FILE *fp; int32_t i,n;
rs = (struct rogue_state *)calloc(1,sizeof(*rs)); rs = (struct rogue_state *)calloc(1,sizeof(*rs));
rs->seed = seed; rs->seed = seed;
rs->keystrokes = keystrokes; rs->keystrokes = keystrokes;
@@ -248,7 +248,9 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
{ {
rs->P = *player; rs->P = *player;
rs->restoring = 1; rs->restoring = 1;
//fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints); fprintf(stderr,"restore player packsize.%d HP.%d\n",rs->P.packsize,rs->P.hitpoints);
if ( rs->P.packsize > MAXPACK )
rs->P.packsize = MAXPACK;
} }
globalR = *rs; globalR = *rs;
uint32_t starttime = (uint32_t)time(NULL); uint32_t starttime = (uint32_t)time(NULL);
@@ -278,8 +280,9 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu
if ( newdata != 0 && rs->playersize > 0 ) if ( newdata != 0 && rs->playersize > 0 )
memcpy(newdata,rs->playerdata,rs->playersize); memcpy(newdata,rs->playerdata,rs->playersize);
} }
n = rs->playersize;
free(rs); free(rs);
return(rs->playersize); return(n);
} }
#endif #endif

View File

@@ -265,7 +265,7 @@ int32_t rogue_iamregistered(int32_t maxplayers,uint256 gametxid,CTransaction tx,
vout = i+1; vout = i+1;
if ( myIsutxo_spent(spenttxid,gametxid,vout) >= 0 ) if ( myIsutxo_spent(spenttxid,gametxid,vout) >= 0 )
{ {
if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 0 ) if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 )
{ {
Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey); Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey);
if ( strcmp(myrogueaddr,destaddr) == 0 ) if ( strcmp(myrogueaddr,destaddr) == 0 )
@@ -296,7 +296,7 @@ int32_t rogue_playersalive(int32_t &numplayers,uint256 gametxid,int32_t maxplaye
uint64_t rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *myrogueaddr) uint64_t rogue_gamefields(UniValue &obj,int64_t maxplayers,int64_t buyin,uint256 gametxid,char *myrogueaddr)
{ {
CBlockIndex *pindex; int32_t ht,delay,numplayers; uint256 hashBlock; uint64_t seed=0; char cmd[512]; CTransaction tx; CBlockIndex *pindex; int32_t ht,delay,numplayers; uint256 hashBlock; uint64_t seed=0; char cmd[512]; CTransaction tx;
if ( GetTransaction(gametxid,tx,hashBlock,false) != 0 && (pindex= komodo_blockindex(hashBlock)) != 0 ) if ( myGetTransaction(gametxid,tx,hashBlock) != 0 && (pindex= komodo_blockindex(hashBlock)) != 0 )
{ {
ht = pindex->GetHeight(); ht = pindex->GetHeight();
delay = ROGUE_REGISTRATION * (maxplayers > 1); delay = ROGUE_REGISTRATION * (maxplayers > 1);
@@ -329,7 +329,7 @@ int32_t rogue_isvalidgame(struct CCcontract_info *cp,int32_t &gameheight,CTransa
{ {
uint256 hashBlock; int32_t i,numvouts; char coinaddr[64]; CPubKey roguepk; uint64_t txfee = 10000; uint256 hashBlock; int32_t i,numvouts; char coinaddr[64]; CPubKey roguepk; uint64_t txfee = 10000;
buyin = maxplayers = 0; buyin = maxplayers = 0;
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 )
{ {
gameheight = komodo_blockheight(hashBlock); gameheight = komodo_blockheight(hashBlock);
if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) >= txfee && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,0) == 0 ) if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) >= txfee && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,0) == 0 )
@@ -434,14 +434,14 @@ int32_t rogue_iterateplayer(uint256 &registertxid,uint256 firsttxid,int32_t firs
int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint256 &tokenid,CPubKey &pk,std::vector<uint8_t> &playerdata,std::string &symbol,std::string &pname,uint256 playertxid) int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint256 &tokenid,CPubKey &pk,std::vector<uint8_t> &playerdata,std::string &symbol,std::string &pname,uint256 playertxid)
{ {
uint256 origplayertxid,hashBlock,gametxid,registertxid; CTransaction gametx,playertx,highlandertx; std::vector<uint8_t> vopret; uint8_t *script,e,f; int32_t i,regslot,gameheight,numvouts,maxplayers; int64_t buyin; uint256 origplayertxid,hashBlock,gametxid,registertxid; CTransaction gametx,playertx,highlandertx; std::vector<uint8_t> vopret; uint8_t *script,e,f; int32_t i,regslot,gameheight,numvouts,maxplayers; int64_t buyin;
if ( GetTransaction(playertxid,playertx,hashBlock,false) != 0 && (numvouts= playertx.vout.size()) > 0 ) if ( myGetTransaction(playertxid,playertx,hashBlock) != 0 && (numvouts= playertx.vout.size()) > 0 )
{ {
if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,playertx.vout[numvouts-1].scriptPubKey)) == 'H' || f == 'Q' ) if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,playertx.vout[numvouts-1].scriptPubKey)) == 'H' || f == 'Q' )
{ {
if ( tokenid != zeroid ) if ( tokenid != zeroid )
{ {
playertxid = tokenid; playertxid = tokenid;
if ( GetTransaction(playertxid,playertx,hashBlock,false) == 0 || (numvouts= playertx.vout.size()) <= 0 ) if ( myGetTransaction(playertxid,playertx,hashBlock) == 0 || (numvouts= playertx.vout.size()) <= 0 )
{ {
fprintf(stderr,"couldnt get tokenid.%s\n",playertxid.GetHex().c_str()); fprintf(stderr,"couldnt get tokenid.%s\n",playertxid.GetHex().c_str());
return(-2); return(-2);
@@ -478,9 +478,10 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
playertxid = zeroid; playertxid = zeroid;
for (i=0; i<maxplayers; i++) for (i=0; i<maxplayers; i++)
{ {
fprintf(stderr,"findbaton.%d of %d\n",i,maxplayers);
if ( myIsutxo_spent(spenttxid,gametxid,i+1) >= 0 ) if ( myIsutxo_spent(spenttxid,gametxid,i+1) >= 0 )
{ {
if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 0 ) if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 )
{ {
numplayers++; numplayers++;
Getscriptaddress(ccaddr,spenttx.vout[0].scriptPubKey); Getscriptaddress(ccaddr,spenttx.vout[0].scriptPubKey);
@@ -489,26 +490,26 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
matches++; matches++;
regslot = i; regslot = i;
matchtx = spenttx; matchtx = spenttx;
} //else fprintf(stderr,"%d+1 doesnt match %s vs %s\n",i,ccaddr,destaddr); } else fprintf(stderr,"%d+1 doesnt match %s vs %s\n",i,ccaddr,destaddr);
} //else fprintf(stderr,"%d+1 couldnt find spenttx.%s\n",i,spenttxid.GetHex().c_str()); } else fprintf(stderr,"%d+1 couldnt find spenttx.%s\n",i,spenttxid.GetHex().c_str());
} //else fprintf(stderr,"%d+1 unspent\n",i); } else fprintf(stderr,"%d+1 unspent\n",i);
} }
if ( matches == 1 ) if ( matches == 1 )
{ {
if ( myIsutxo_spent(spenttxid,gametxid,maxplayers+i+1) < 0 ) if ( myIsutxo_spent(spenttxid,gametxid,maxplayers+i+1) < 0 )
{ {
numvouts = matchtx.vout.size(); numvouts = matchtx.vout.size();
//fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts); fprintf(stderr,"matchtxid.%s matches.%d numvouts.%d\n",matchtx.GetHash().GetHex().c_str(),matches,numvouts);
if ( rogue_registeropretdecode(txid,tokenid,playertxid,matchtx.vout[numvouts-1].scriptPubKey) == 'R' )//&& txid == gametxid ) if ( rogue_registeropretdecode(txid,tokenid,playertxid,matchtx.vout[numvouts-1].scriptPubKey) == 'R' )//&& txid == gametxid )
{ {
//fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str()); fprintf(stderr,"tokenid.%s txid.%s vs gametxid.%s player.%s\n",tokenid.GetHex().c_str(),txid.GetHex().c_str(),gametxid.GetHex().c_str(),playertxid.GetHex().c_str());
if ( tokenid != zeroid ) if ( tokenid != zeroid )
active = tokenid; active = tokenid;
else active = playertxid; else active = playertxid;
if ( active == zeroid || rogue_playerdata(cp,origplayergame,tid,pk,playerdata,symbol,pname,active) == 0 ) if ( active == zeroid || rogue_playerdata(cp,origplayergame,tid,pk,playerdata,symbol,pname,active) == 0 )
{ {
txid = matchtx.GetHash(); txid = matchtx.GetHash();
//fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str()); fprintf(stderr,"scan forward active.%s spenttxid.%s\n",active.GetHex().c_str(),txid.GetHex().c_str());
n = 0; n = 0;
while ( CCgettxout(txid,0,1) < 0 ) while ( CCgettxout(txid,0,1) < 0 )
{ {
@@ -524,7 +525,7 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
txid = spenttxid; txid = spenttxid;
if ( spentvini != 0 ) if ( spentvini != 0 )
return(-3); return(-3);
if ( keystrokesp != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) if ( keystrokesp != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() >= 2 )
{ {
uint256 g,b; CPubKey p; std::vector<uint8_t> k; uint256 g,b; CPubKey p; std::vector<uint8_t> k;
if ( rogue_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' ) if ( rogue_keystrokesopretdecode(g,b,p,k,spenttx.vout[spenttx.vout.size()-1].scriptPubKey) == 'K' )
@@ -541,13 +542,14 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
fprintf(stderr,"rogue_findbaton n.%d, seems something is wrong\n",n); fprintf(stderr,"rogue_findbaton n.%d, seems something is wrong\n",n);
return(-5); return(-5);
} }
fprintf(stderr,"n.%d txid.%s\n",n,txid.GetHex().c_str());
} }
//fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); fprintf(stderr,"set baton %s\n",txid.GetHex().c_str());
batontxid = txid; batontxid = txid;
batonvout = 0; // not vini batonvout = 0; // not vini
// how to detect timeout, bailedout, highlander // how to detect timeout, bailedout, highlander
hashBlock = zeroid; hashBlock = zeroid;
if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && batontx.vout.size() > 0 ) if ( myGetTransaction(batontxid,batontx,hashBlock) != 0 && batontx.vout.size() > 0 )
{ {
if ( hashBlock == zeroid ) if ( hashBlock == zeroid )
batonht = komodo_nextheight(); batonht = komodo_nextheight();
@@ -555,9 +557,9 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke
return(-4); return(-4);
else batonht = pindex->GetHeight(); else batonht = pindex->GetHeight();
batonvalue = batontx.vout[0].nValue; batonvalue = batontx.vout[0].nValue;
//printf("keystrokes[%d]\n",numkeys); printf("batonht.%d keystrokes[%d]\n",batonht,numkeys);
return(0); return(0);
} } else fprintf(stderr,"couldnt find baton\n");
} }
} else fprintf(stderr,"findbaton opret error\n"); } else fprintf(stderr,"findbaton opret error\n");
} }
@@ -577,7 +579,7 @@ void rogue_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gamet
destaddr[0] = 0; destaddr[0] = 0;
if ( myIsutxo_spent(spenttxid,gametxid,vout) >= 0 ) if ( myIsutxo_spent(spenttxid,gametxid,vout) >= 0 )
{ {
if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 0 ) if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 )
Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey); Getscriptaddress(destaddr,spenttx.vout[0].scriptPubKey);
} }
obj.push_back(Pair("slot",(int64_t)vout-1)); obj.push_back(Pair("slot",(int64_t)vout-1));
@@ -585,7 +587,7 @@ void rogue_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gamet
{ {
if ( CCgettxout(gametxid,maxplayers+vout,1) == 10000 ) if ( CCgettxout(gametxid,maxplayers+vout,1) == 10000 )
{ {
if ( GetTransaction(batontxid,batontx,hashBlock,false) != 0 && batontx.vout.size() > 1 ) if ( myGetTransaction(batontxid,batontx,hashBlock) != 0 && batontx.vout.size() > 1 )
{ {
if ( rogue_registeropretdecode(gtxid,tokenid,ptxid,batontx.vout[batontx.vout.size()-1].scriptPubKey) == 'R' && ptxid == playertxid && gtxid == gametxid ) if ( rogue_registeropretdecode(gtxid,tokenid,ptxid,batontx.vout[batontx.vout.size()-1].scriptPubKey) == 'R' && ptxid == playertxid && gtxid == gametxid )
obj.push_back(Pair("status","registered")); obj.push_back(Pair("status","registered"));
@@ -758,7 +760,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
if ( playertxid != zeroid ) if ( playertxid != zeroid )
{ {
voutPubkeysEmpty.push_back(burnpk); voutPubkeysEmpty.push_back(burnpk);
if ( GetTransaction(playertxid,playertx,hashBlock,false) != 0 ) if ( myGetTransaction(playertxid,playertx,hashBlock) != 0 )
{ {
if ( (funcid= DecodeTokenOpRet(playertx.vout.back().scriptPubKey, e, tid, voutPubkeys, vopretExtra)) != 0) if ( (funcid= DecodeTokenOpRet(playertx.vout.back().scriptPubKey, e, tid, voutPubkeys, vopretExtra)) != 0)
{ // if token in the opret { // if token in the opret
@@ -828,13 +830,16 @@ char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector<uint8_t> &newdat
roguepk = GetUnspendable(cp,0); roguepk = GetUnspendable(cp,0);
*numkeysp = 0; *numkeysp = 0;
seed = 0; seed = 0;
fprintf(stderr,"calling validgame\n");
if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 ) if ( (err= rogue_isvalidgame(cp,gameheight,gametx,buyin,maxplayers,gametxid)) == 0 )
{ {
fprintf(stderr,"calling baton\n");
if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,rogueaddr,numplayers,symbol,pname) == 0 ) if ( rogue_findbaton(cp,playertxid,&keystrokes,numkeys,regslot,playerdata,batontxid,batonvout,batonvalue,batonht,gametxid,gametx,maxplayers,rogueaddr,numplayers,symbol,pname) == 0 )
{ {
UniValue obj; UniValue obj;
fprintf(stderr,"calling gamefields\n");
seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,rogueaddr); seed = rogue_gamefields(obj,maxplayers,buyin,gametxid,rogueaddr);
//fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d\n",pname.size()!=0?pname.c_str():Rogue_pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size()); fprintf(stderr,"(%s) found baton %s numkeys.%d seed.%llu playerdata.%d\n",pname.size()!=0?pname.c_str():Rogue_pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size());
memset(&P,0,sizeof(P)); memset(&P,0,sizeof(P));
if ( playerdata.size() > 0 ) if ( playerdata.size() > 0 )
{ {
@@ -872,8 +877,8 @@ char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector<uint8_t> &newdat
sprintf(str,"extracted $$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",endP.gold,endP.hitpoints,endP.strength&0xffff,endP.strength>>16,endP.level,endP.experience,endP.dungeonlevel); sprintf(str,"extracted $$$gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",endP.gold,endP.hitpoints,endP.strength&0xffff,endP.strength>>16,endP.level,endP.experience,endP.dungeonlevel);
fprintf(stderr,"%s\n",str); fprintf(stderr,"%s\n",str);
} else num = 0; } else num = 0;
} } else fprintf(stderr,"extractgame: couldnt find baton\n");
} } else fprintf(stderr,"extractgame: invalid game\n");
*numkeysp = numkeys; *numkeysp = numkeys;
return(keystrokes); return(keystrokes);
} }
@@ -1174,7 +1179,7 @@ UniValue rogue_games(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); //char str[65]; fprintf(stderr,"%s check %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN);
if ( vout == 0 ) if ( vout == 0 )
{ {
if ( GetTransaction(txid,tx,hashBlock,false) != 0 && (numvouts= tx.vout.size()) > 1 ) if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 1 )
{ {
if ( rogue_registeropretdecode(gametxid,tokenid,playertxid,tx.vout[numvouts-1].scriptPubKey) == 'R' ) if ( rogue_registeropretdecode(gametxid,tokenid,playertxid,tx.vout[numvouts-1].scriptPubKey) == 'R' )
{ {
@@ -1216,10 +1221,28 @@ UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
return(result); return(result);
} }
int32_t rogue_playerdata_validate(struct CCcontract_info *cp,std::vector<uint8_t> playerdata,uint256 gametxid,CPubKey pk)
{
char str[512],*keystrokes,rogueaddr[64]; int32_t numkeys; std::vector<uint8_t> newdata; uint64_t seed; uint256 playertxid; CPubKey roguepk;
roguepk = GetUnspendable(cp,0);
GetCCaddress1of2(cp,rogueaddr,roguepk,pk);
fprintf(stderr,"call extractgame\n");
if ( (keystrokes= rogue_extractgame(str,&numkeys,newdata,seed,playertxid,cp,gametxid,rogueaddr)) != 0 )
{
free(keystrokes);
fprintf(stderr,"extracted.(%s)\n",str);
if ( newdata == playerdata )
return(0);
else fprintf(stderr,"newdata[%d] != playerdata[%d]\n",(int32_t)newdata.size(),(int32_t)playerdata.size());
}
return(-1);
}
bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) 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; 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,errflag,dispflag,score,numvouts; CTransaction vintx; CPubKey pk; uint256 hashBlock,gametxid,tokenid,batontxid,playertxid; int64_t buyin; std::vector<uint8_t> playerdata,keystrokes; std::string symbol,pname;
return(true); if ( strcmp(ASSETCHAINS_SYMBOL,"ROGUE") == 0 && height < 30000 )
return(true);
if ( (numvouts= tx.vout.size()) > 1 ) if ( (numvouts= tx.vout.size()) > 1 )
{ {
scriptPubKey = tx.vout[numvouts-1].scriptPubKey; scriptPubKey = tx.vout[numvouts-1].scriptPubKey;
@@ -1234,36 +1257,54 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C
{ {
if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) == 0 ) if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) == 0 )
{ {
funcid = 'Q'; fprintf(stderr,"ht.%d couldnt decode tokens opret (%c)\n",height,script[1]);
fprintf(stderr,"ht.%d couldnt decode tokens opret\n",height);
} else e = EVAL_ROGUE, decoded = 1; } else e = EVAL_ROGUE, decoded = 1;
} else e = EVAL_ROGUE, decoded = 1; } else e = EVAL_ROGUE, decoded = 1;
} }
if ( e == EVAL_ROGUE ) if ( e == EVAL_ROGUE )
{ {
fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
if ( decoded == 0 ) if ( decoded == 0 )
{ {
switch ( funcid ) switch ( funcid )
{ {
case 'G': case 'G':
if ( (funcid= rogue_newgameopreturndecode(buyin,maxplayers,scriptPubKey)) != 'G' ) if ( (funcid= rogue_newgameopreturndecode(buyin,maxplayers,scriptPubKey)) != 'G' )
return eval->Invalid("couldnt decode newgame opret"); {
//fprintf(stderr,"height.%d couldnt decode newgame opret\n",height);
//if ( height > 20000 )
return eval->Invalid("couldnt decode newgame opret");
}
// validate newgame tx // validate newgame tx
return(true); return(true);
break; break;
case 'R': case 'R':
if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) != 'R' ) if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) != 'R' )
return eval->Invalid("couldnt decode register opret"); {
//fprintf(stderr,"height.%d couldnt decode register opret\n",height);
//if ( height > 20000 )
return eval->Invalid("couldnt decode register opret");
}
// validation is done below
break; break;
case 'K': case 'K':
if ( (funcid= rogue_keystrokesopretdecode(gametxid,batontxid,pk,keystrokes,scriptPubKey)) != 'K' ) if ( (funcid= rogue_keystrokesopretdecode(gametxid,batontxid,pk,keystrokes,scriptPubKey)) != 'K' )
return eval->Invalid("couldnt decode keystrokes opret"); {
//fprintf(stderr,"height.%d couldnt decode keystrokes opret\n",height);
//if ( height > 20000 )
return eval->Invalid("couldnt decode keystrokes opret");
}
// validate keystrokes are from the correct pk. might need to add vin // validate keystrokes are from the correct pk. might need to add vin
return(true); return(true);
break; break;
case 'H': case 'Q': case 'H': case 'Q':
if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) != funcid ) if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) != funcid )
return eval->Invalid("couldnt decode H/Q opret"); {
//fprintf(stderr,"height.%d couldnt decode H/Q opret\n",height);
//if ( height > 20000 )
return eval->Invalid("couldnt decode H/Q opret");
}
// validation is done below
break; break;
default: default:
return eval->Invalid("illegal rogue non-decoded funcid"); return eval->Invalid("illegal rogue non-decoded funcid");
@@ -1272,16 +1313,29 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C
} }
switch ( funcid ) switch ( funcid )
{ {
case 'G': // newgame
case 'R': // register case 'R': // register
case 'K': // keystrokes return(true);
case 'H': // win case 'H': // win
case 'Q': // bailout case 'Q': // bailout
//fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]); // verify pk belongs to this tx
if ( playerdata.size() > 0 )
{
if ( rogue_playerdata_validate(cp,playerdata,gametxid,pk) < 0 )
{
fprintf(stderr,"ht.%d gametxid.%s player.%s invalid playerdata[%d]\n",height,gametxid.GetHex().c_str(),playertxid.GetHex().c_str(),(int32_t)playerdata.size());
} else fprintf(stderr,"ht.%d playertxid.%s validated\n",height,playertxid.GetHex().c_str());
}
if ( funcid == 'Q' )
{
// verify vin/vout
}
else // 'H'
{
// verify vin/vout
}
return(true); return(true);
break; break;
default: default:
//fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
return eval->Invalid("illegal rogue funcid"); return eval->Invalid("illegal rogue funcid");
break; break;
} }

View File

@@ -1127,10 +1127,10 @@ uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256
int32_t komodo_nextheight() int32_t komodo_nextheight()
{ {
CBlockIndex *pindex; int32_t ht,longest = komodo_longestchain(); CBlockIndex *pindex; int32_t ht;
if ( (pindex= chainActive.LastTip()) != 0 && (ht= pindex->GetHeight()) >= longest ) if ( (pindex= chainActive.LastTip()) != 0 && (ht= pindex->GetHeight()) > 0 )
return(ht+1); return(ht+1);
else return(longest + 1); else return(komodo_longestchain() + 1);
} }
int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_isrealtime(int32_t *kmdheightp)

View File

@@ -5308,13 +5308,18 @@ UniValue setpubkey(const UniValue& params, bool fHelp)
char Raddress[64]; char Raddress[64];
uint8_t pubkey33[33]; uint8_t pubkey33[33];
if ( NOTARY_PUBKEY33[0] == 0 ) { if ( NOTARY_PUBKEY33[0] == 0 )
if (strlen(params[0].get_str().c_str()) == 66) { {
if (strlen(params[0].get_str().c_str()) == 66)
{
decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); decode_hex(pubkey33,33,(char *)params[0].get_str().c_str());
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
if (strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) { if ( 0 && strcmp("RRmWExvapDM9YbLT9X9xAyzDgxomYf63ng",Raddress) == 0) // no idea what this addr is
{
result.push_back(Pair("error", "pubkey entered is invalid.")); result.push_back(Pair("error", "pubkey entered is invalid."));
} else { }
else
{
CBitcoinAddress address(Raddress); CBitcoinAddress address(Raddress);
bool isValid = address.IsValid(); bool isValid = address.IsValid();
if (isValid) if (isValid)
@@ -5331,10 +5336,10 @@ UniValue setpubkey(const UniValue& params, bool fHelp)
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
USE_EXTERNAL_PUBKEY = 1; USE_EXTERNAL_PUBKEY = 1;
} }
} else { } else result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string."));
result.push_back(Pair("error", "pubkey is wrong length, must be 66 char hex string.")); }
} else
} else { {
result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon, pubkey in use is below.")); result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon, pubkey in use is below."));
pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33); pubkey2addr((char *)Raddress,(uint8_t *)NOTARY_PUBKEY33);
std::string address_ret; address_ret.assign(Raddress); std::string address_ret; address_ret.assign(Raddress);