From 5325bf6507ff34928a83193b128e26e4a33223e5 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 00:05:24 +0100 Subject: [PATCH 01/13] add Makefile for rogue multiOS supported Makefile --- src/cc/Makefile_rogue | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/cc/Makefile_rogue diff --git a/src/cc/Makefile_rogue b/src/cc/Makefile_rogue new file mode 100644 index 000000000..7fb3f799f --- /dev/null +++ b/src/cc/Makefile_rogue @@ -0,0 +1,37 @@ +SHELL = /bin/sh +CC = gcc +CC_DARWIN = g++-6 +CC_WIN = x86_64-w64-mingw32-gcc-posix +CFLAGS_DARWIN = -DBUILD_ROGUE -std=c++11 -arch x86_64 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib +CFLAGS = -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared +CFLAGS_WIN = -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared +DEBUGFLAGS = -O0 -D _DEBUG +RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program +$(info $(OS)) +OS := $(shell uname -s) +$(info $(OS)) +TARGET = librogue.so +TARGET_DARWIN = librogue.dylib +TARGET_WIN = librogue.dll +SOURCES = cclib.cpp +#HEADERS = $(shell echo ../cryptoconditions/include/*.h) -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ + +all: $(TARGET) + +$(TARGET): $(SOURCES) + $(info Building cclib to src/) +ifeq ($(OS),Darwin) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET_DARWIN) -c $(SOURCES) -lncurses + cp $(TARGET_DARWIN) ../libcc.dylib +else ifeq ($(OS),Linux) + $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) -c $(SOURCES) -lncurses + cp $(TARGET) ../libcc.so +#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host +else + $(info WINDOWS) + $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) -c $(SOURCES) -lncurses + cp $(TARGET_WIN) ../libcc.dll +endif + +clean: + rm -rf $(TARGET) From 9eb16504de6a35e5a31792954cb266bf96d37912 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 00:08:03 +0100 Subject: [PATCH 02/13] update makerogue --- src/cc/makerogue | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/cc/makerogue b/src/cc/makerogue index 249e646f5..3b47638e9 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -1,8 +1,5 @@ #!/bin/sh cd rogue; -./configure # only need this first time +./configure make; cd .. -gcc -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -o librogue.so -c cclib.cpp -#gcc -std=c++11 -fPIC -shared -o librogue.so cclib.o rogue/rogue.so -cp librogue.so ../libcc.so - +make -f Makefile_rogue From c5b8640d9dde49a4b5b7706c545c1afb4eebb7ce Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 00:15:35 +0100 Subject: [PATCH 03/13] update OSX makefile --- zcutil/build-mac.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index a3619111f..df4efd05f 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -47,14 +47,7 @@ make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 WD=$PWD cd src/cc echo $PWD - -if make "$@"; then - echo CCLIB BUILD SUCCESSFUL -else - echo CCLIB BUILD FAILED - exit 1 -fi - +./makerogue cd $WD ./autogen.sh From cfa13caa4c1fe9cddc3c1b267d19e69da37257c1 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 00:16:20 +0100 Subject: [PATCH 04/13] update makerogue --- src/cc/makerogue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cc/makerogue b/src/cc/makerogue index 3b47638e9..a38eab6a4 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -2,4 +2,10 @@ cd rogue; ./configure make; cd .. -make -f Makefile_rogue + +if make -f Makefile_rogue "$@"; then + echo ROGUE BUILD SUCCESSFUL +else + echo ROGUE BUILD FAILED + exit 1 +fi From 553b54b61cb32f41a86281dd26fabe2ecce1363f Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 12:13:11 +0100 Subject: [PATCH 05/13] roguefy makefile 'roguefy' for komodo linux makefile --- zcutil/build.sh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/zcutil/build.sh b/zcutil/build.sh index dc312c8e8..7b452a1fc 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -103,20 +103,12 @@ ld -v HOST="$HOST" BUILD="$BUILD" NO_PROTON="$PROTON_ARG" "$MAKE" "$@" -C ./depends/ V=1 - #BUILD CCLIB WD=$PWD cd src/cc echo $PWD - -if make "$@"; then - echo CCLIB BUILD SUCCESSFUL -else - echo CCLIB BUILD FAILED - exit 1 -fi - +./makerogue cd $WD ./autogen.sh From 8b35141984d4a25ed761bdf23fb40a1772145b5e Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 15:29:59 +0100 Subject: [PATCH 06/13] roguefy WIN makefile --- zcutil/build-win.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zcutil/build-win.sh b/zcutil/build-win.sh index 5c12893fa..ef0c09549 100755 --- a/zcutil/build-win.sh +++ b/zcutil/build-win.sh @@ -11,6 +11,12 @@ cd "$(dirname "$(readlink -f "$0")")/.." cd depends/ && make HOST=$HOST V=1 NO_QT=1 cd ../ +WD=$PWD +cd src/cc +echo $PWD +./makerogue +cd $WD + ./autogen.sh CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site CXXFLAGS="-DPTW32_STATIC_LIB -DCURL_STATICLIB -DCURVE_ALT_BN128 -fopenmp -pthread" ./configure --prefix="${PREFIX}" --host=x86_64-w64-mingw32 --enable-static --disable-shared sed -i 's/-lboost_system-mt /-lboost_system-mt-s /' configure From a9d9c7599dacc9fa962b33700cd84b47861a3537 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 18:14:32 +0100 Subject: [PATCH 07/13] Update Makefile_rogue --- src/cc/Makefile_rogue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/Makefile_rogue b/src/cc/Makefile_rogue index 7fb3f799f..543ab2895 100644 --- a/src/cc/Makefile_rogue +++ b/src/cc/Makefile_rogue @@ -4,7 +4,7 @@ CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix CFLAGS_DARWIN = -DBUILD_ROGUE -std=c++11 -arch x86_64 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -Wl,-undefined -Wl,dynamic_lookup -Wno-write-strings -shared -dynamiclib CFLAGS = -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -CFLAGS_WIN = -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared +CFLAGS_WIN = -Wno-write-strings -DBUILD_ROGUE -std=c++11 -I../../depends/x86_64-w64-mingw32/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared DEBUGFLAGS = -O0 -D _DEBUG RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program $(info $(OS)) From e1621fb8f8b66d4ca61b48fd51b6f20f33ff1efe Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 18:47:07 +0100 Subject: [PATCH 08/13] update win makefile --- zcutil/build-win.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcutil/build-win.sh b/zcutil/build-win.sh index ef0c09549..8cf1751af 100755 --- a/zcutil/build-win.sh +++ b/zcutil/build-win.sh @@ -1,5 +1,5 @@ #!/bin/bash -HOST=x86_64-w64-mingw32 +export HOST=x86_64-w64-mingw32 CXX=x86_64-w64-mingw32-g++-posix CC=x86_64-w64-mingw32-gcc-posix PREFIX="$(pwd)/depends/$HOST" From 84dacb5ff8c0c8fdd6db19ae7da1cd54ab65b3b7 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 19:31:49 +0100 Subject: [PATCH 09/13] update Makefile_rogue --- src/cc/Makefile_rogue | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cc/Makefile_rogue b/src/cc/Makefile_rogue index 543ab2895..45efdc803 100644 --- a/src/cc/Makefile_rogue +++ b/src/cc/Makefile_rogue @@ -23,14 +23,15 @@ $(TARGET): $(SOURCES) ifeq ($(OS),Darwin) $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET_DARWIN) -c $(SOURCES) -lncurses cp $(TARGET_DARWIN) ../libcc.dylib -else ifeq ($(OS),Linux) - $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) -c $(SOURCES) -lncurses - cp $(TARGET) ../libcc.so -#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host -else +else ifeq ($(HOST),x86_64-w64-mingw32) $(info WINDOWS) $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) -c $(SOURCES) -lncurses - cp $(TARGET_WIN) ../libcc.dll + cp $(TARGET_WIN) ../libcc.dll +#else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host +else + $(info LINUX) + $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) -c $(SOURCES) -lncurses + cp $(TARGET) ../libcc.so endif clean: From 8ac6e7458b2a3ffd982c2d3dd4151e63b9a17f9d Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 20:55:08 +0100 Subject: [PATCH 10/13] test --- src/cc/rogue/mdport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/mdport.c b/src/cc/rogue/mdport.c index 9d6c7d2c6..f87650f38 100644 --- a/src/cc/rogue/mdport.c +++ b/src/cc/rogue/mdport.c @@ -33,7 +33,7 @@ #include #if defined(_WIN32) -#include +#include #include #include #include From 846e102e7b9b4774552ab05dabe4b319974b4772 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 22:13:28 +0100 Subject: [PATCH 11/13] fix --- src/cc/rogue/mdport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/mdport.c b/src/cc/rogue/mdport.c index f87650f38..d9c4e9c21 100644 --- a/src/cc/rogue/mdport.c +++ b/src/cc/rogue/mdport.c @@ -34,7 +34,7 @@ #if defined(_WIN32) #include -#include +#include #include #include #pragma warning( disable: 4201 ) From 10dfaedb062d1c7a8520d41a3ae9c5d72f8695d2 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 18 Feb 2019 23:23:26 +0100 Subject: [PATCH 12/13] fix --- src/cc/rogue/mdport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/mdport.c b/src/cc/rogue/mdport.c index d9c4e9c21..988e1c7b7 100644 --- a/src/cc/rogue/mdport.c +++ b/src/cc/rogue/mdport.c @@ -40,7 +40,7 @@ #pragma warning( disable: 4201 ) #include #pragma warning( default: 4201 ) -#include +#include #undef MOUSE_MOVED #endif From 640f3e0699cfd2d93c6ceb7a2c6977a0d7bb5bbe Mon Sep 17 00:00:00 2001 From: ca333 Date: Tue, 19 Feb 2019 00:15:41 +0100 Subject: [PATCH 13/13] resolve conflict --- src/cc/rogue_rpc.cpp | 121 +++++++++++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 33 deletions(-) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index ef24489ba..d74bc9619 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -265,7 +265,7 @@ int32_t rogue_iamregistered(int32_t maxplayers,uint256 gametxid,CTransaction tx, vout = i+1; 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); 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) { 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(); 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; 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); if ( IsCClibvout(cp,tx,0,cp->unspendableCCaddr) >= txfee && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,0) == 0 ) @@ -434,14 +434,14 @@ int32_t rogue_iterateplayer(uint256 ®istertxid,uint256 firsttxid,int32_t firs int32_t rogue_playerdata(struct CCcontract_info *cp,uint256 &origplayergame,uint256 &tokenid,CPubKey &pk,std::vector &playerdata,std::string &symbol,std::string &pname,uint256 playertxid) { uint256 origplayertxid,hashBlock,gametxid,registertxid; CTransaction gametx,playertx,highlandertx; std::vector 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 ( tokenid != zeroid ) { 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()); return(-2); @@ -478,9 +478,10 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke playertxid = zeroid; for (i=0; i= 0 ) { - if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 0 ) + if ( myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 0 ) { numplayers++; Getscriptaddress(ccaddr,spenttx.vout[0].scriptPubKey); @@ -524,7 +525,7 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke txid = spenttxid; if ( spentvini != 0 ) 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 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); return(-5); } + //fprintf(stderr,"n.%d txid.%s\n",n,txid.GetHex().c_str()); } //fprintf(stderr,"set baton %s\n",txid.GetHex().c_str()); batontxid = txid; batonvout = 0; // not vini // how to detect timeout, bailedout, highlander 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 ) batonht = komodo_nextheight(); @@ -555,10 +557,10 @@ int32_t rogue_findbaton(struct CCcontract_info *cp,uint256 &playertxid,char **ke return(-4); else batonht = pindex->GetHeight(); batonvalue = batontx.vout[0].nValue; - //printf("keystrokes[%d]\n",numkeys); + //printf("batonht.%d keystrokes[%d]\n",batonht,numkeys); return(0); - } - } + } else fprintf(stderr,"couldnt find baton\n"); + } else fprintf(stderr,"error with playerdata\n"); } else fprintf(stderr,"findbaton opret error\n"); } else @@ -577,7 +579,7 @@ void rogue_gameplayerinfo(struct CCcontract_info *cp,UniValue &obj,uint256 gamet destaddr[0] = 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); } 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 ( 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 ) 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 ) { 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 token in the opret @@ -834,7 +836,7 @@ char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector &newdat { UniValue obj; 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 playertxid.%s\n",pname.size()!=0?pname.c_str():Rogue_pname.c_str(),batontxid.ToString().c_str(),numkeys,(long long)seed,(int32_t)playerdata.size(),playertxid.GetHex().c_str()); memset(&P,0,sizeof(P)); if ( playerdata.size() > 0 ) { @@ -872,8 +874,8 @@ char *rogue_extractgame(char *str,int32_t *numkeysp,std::vector &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); fprintf(stderr,"%s\n",str); } else num = 0; - } - } + } else fprintf(stderr,"extractgame: couldnt find baton\n"); + } else fprintf(stderr,"extractgame: invalid game\n"); *numkeysp = numkeys; return(keystrokes); } @@ -1174,7 +1176,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); 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' ) { @@ -1216,9 +1218,51 @@ UniValue rogue_setname(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } +int32_t rogue_playerdata_validate(uint256 &playertxid,struct CCcontract_info *cp,std::vector playerdata,uint256 gametxid,CPubKey pk) +{ + static uint32_t good,bad; static uint256 prevgame; + char str[512],*keystrokes,rogueaddr[64],str2[67]; int32_t i,numkeys; std::vector newdata; uint64_t seed; CPubKey roguepk; struct rogue_player P; + if ( gametxid == prevgame ) + return(0); + prevgame = gametxid; + 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 ) + { + good++; + fprintf(stderr,"%s good.%d bad.%d\n",gametxid.GetHex().c_str(),good,bad); + return(0); + } + newdata[10] = newdata[11] = playerdata[10] = playerdata[11] = 0; + if ( newdata == playerdata ) + { + good++; + fprintf(stderr,"%s matched after clearing maxstrength good.%d bad.%d\n",gametxid.GetHex().c_str(),good,bad); + return(0); + } + bad++; + for (i=0; i no playerdata\n"); + } + fprintf(stderr,"%s playerdata: gold.%d hp.%d strength.%d/%d level.%d exp.%d dl.%d\n",gametxid.GetHex().c_str(),P.gold,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel); + fprintf(stderr,"newdata[%d] != playerdata[%d], numkeys.%d %s pub.%s playertxid.%s good.%d bad.%d\n",(int32_t)newdata.size(),(int32_t)playerdata.size(),numkeys,rogueaddr,pubkey33_str(str2,(uint8_t *)&pk),playertxid.GetHex().c_str(),good,bad); + } + return(-1); +} + bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) { - CScript scriptPubKey; std::vector 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 playerdata,keystrokes; std::string symbol,pname; + CScript scriptPubKey; std::vector 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 playerdata,keystrokes; std::string symbol,pname; + if ( strcmp(ASSETCHAINS_SYMBOL,"ROGUE") == 0 && height < 21274 ) + return(true); if ( (numvouts= tx.vout.size()) > 1 ) { scriptPubKey = tx.vout[numvouts-1].scriptPubKey; @@ -1233,10 +1277,7 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C { if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) == 0 ) { - funcid = 'Q'; fprintf(stderr,"ht.%d couldnt decode tokens opret (%c)\n",height,script[1]); - if ( height < 20000 ) - e = EVAL_ROGUE; } else e = EVAL_ROGUE, decoded = 1; } else e = EVAL_ROGUE, decoded = 1; } @@ -1250,8 +1291,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C case 'G': if ( (funcid= rogue_newgameopreturndecode(buyin,maxplayers,scriptPubKey)) != 'G' ) { - fprintf(stderr,"height.%d couldnt decode newgame opret\n",height); - if ( height > 20000 ) + //fprintf(stderr,"height.%d couldnt decode newgame opret\n",height); + //if ( height > 20000 ) return eval->Invalid("couldnt decode newgame opret"); } // validate newgame tx @@ -1260,8 +1301,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C case 'R': if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) != 'R' ) { - fprintf(stderr,"height.%d couldnt decode register opret\n",height); - if ( height > 20000 ) + //fprintf(stderr,"height.%d couldnt decode register opret\n",height); + //if ( height > 20000 ) return eval->Invalid("couldnt decode register opret"); } // validation is done below @@ -1269,8 +1310,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C case 'K': if ( (funcid= rogue_keystrokesopretdecode(gametxid,batontxid,pk,keystrokes,scriptPubKey)) != 'K' ) { - fprintf(stderr,"height.%d couldnt decode keystrokes opret\n",height); - if ( height > 20000 ) + //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 @@ -1279,8 +1320,8 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C case 'H': case 'Q': if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) != funcid ) { - fprintf(stderr,"height.%d couldnt decode H/Q opret\n",height); - if ( height > 20000 ) + //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 @@ -1292,12 +1333,26 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C } switch ( funcid ) { - case 'G': // newgame case 'R': // register - case 'K': // keystrokes + return(true); case 'H': // win 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(ptxid,cp,playerdata,gametxid,pk) < 0 ) + { + //fprintf(stderr,"ht.%d gametxid.%s player.%s invalid playerdata[%d]\n",height,gametxid.GetHex().c_str(),ptxid.GetHex().c_str(),(int32_t)playerdata.size()); + } //else fprintf(stderr,"ht.%d playertxid.%s validated\n",height,ptxid.GetHex().c_str()); + } + if ( funcid == 'Q' ) + { + // verify vin/vout + } + else // 'H' + { + // verify vin/vout + } return(true); break; default: