diff --git a/.gitignore b/.gitignore index 89d21bd7a..11b713d22 100755 --- a/.gitignore +++ b/.gitignore @@ -184,3 +184,15 @@ iguana/DB/SWAPS/667293271-3414303895.swap iguana/DB/SWAPS/548227681-1452262678.swap iguana/DB/SWAPS/548227681-1452262678 + +*.bobdeposit + +*.bobpayment + +*.bobreclaim + +*.bobrefund + +*.swap + +iguana/DB/SWAPS/1268007736-526212866 diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index de6ebd330..ba880e2e6 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -1857,4 +1857,11 @@ ZERO_ARGS(InstantDEX,init) return(clonestr("{\"result\":\"success\"}")); } +ZERO_ARGS(InstantDEX,getswaplist) +{ + return(basilisk_swaplist(myinfo)); +} + + + #include "../includes/iguana_apiundefs.h" diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index b0159dcdb..a267d5c61 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -1059,7 +1059,7 @@ FILE *basilisk_swap_save(struct supernet_info *myinfo,struct basilisk_swap *swap { FILE *fp=0; char fname[512]; sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,rp->requestid,rp->quoteid), OS_compatible_path(fname); - if ( 0 && (fp= fopen(fname,"rb+")) == 0 ) + if ( (fp= fopen(fname,"rb+")) == 0 ) { if ( (fp= fopen(fname,"wb+")) != 0 ) { @@ -1076,6 +1076,22 @@ FILE *basilisk_swap_save(struct supernet_info *myinfo,struct basilisk_swap *swap return(fp); } +int32_t basilisk_swap_load(uint32_t requestid,uint32_t quoteid,bits256 *privkeyp,struct basilisk_request *rp,uint32_t *statebitsp,int32_t *optiondurationp) +{ + FILE *fp=0; char fname[512]; int32_t retval = -1; + sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb+")) != 0 ) + { + if ( fread(privkeyp,1,sizeof(*privkeyp),fp) == sizeof(*privkeyp) && + fread(rp,1,sizeof(*rp),fp) == sizeof(*rp) && + fread(statebitsp,1,sizeof(*statebitsp),fp) == sizeof(*statebitsp) && + fread(optiondurationp,1,sizeof(*optiondurationp),fp) == sizeof(*optiondurationp) ) + retval = 0; + fclose(fp); + } + return(retval); +} + struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit); void basilisk_swaps_init(struct supernet_info *myinfo) @@ -1091,7 +1107,7 @@ void basilisk_swaps_init(struct supernet_info *myinfo) if ( (fp= fopen(fname,"rb+")) != 0 ) // check to see if completed { memset(&M,0,sizeof(M)); - swapcompleted = 0; + swapcompleted = 1; for (iter=0; iter<2; iter++) { if ( fread(privkey.bytes,1,sizeof(privkey),fp) == sizeof(privkey) && @@ -1099,7 +1115,7 @@ void basilisk_swaps_init(struct supernet_info *myinfo) fread(&statebits,1,sizeof(statebits),fp) == sizeof(statebits) && fread(&optionduration,1,sizeof(optionduration),fp) == sizeof(optionduration) ) { - while ( fread(&M,1,sizeof(M),fp) == sizeof(M) ) + while ( 0 && fread(&M,1,sizeof(M),fp) == sizeof(M) ) { M.data = 0; //printf("entry iter.%d crc32.%x datalen.%d\n",iter,M.crc32,M.datalen); @@ -1401,7 +1417,7 @@ void basilisk_swap_saveupdate(struct supernet_info *myinfo,struct basilisk_swap { FILE *fp; char fname[512]; sprintf(fname,"%s/SWAPS/%u-%u.swap",GLOBAL_DBDIR,swap->I.req.requestid,swap->I.req.quoteid), OS_compatible_path(fname); - if ( 0 && (fp= fopen(fname,"wb")) != 0 ) + if ( (fp= fopen(fname,"wb")) != 0 ) { fwrite(&swap->I,1,sizeof(swap->I),fp); /*fwrite(&swap->bobdeposit,1,sizeof(swap->bobdeposit),fp); @@ -2527,3 +2543,27 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256 portable_mutex_unlock(&myinfo->DEX_swapmutex); return(swap); } + +char *basilisk_swaplist(struct supernet_info *myinfo) +{ + char fname[512]; FILE *fp; struct basilisk_request R; int32_t optionduration; uint32_t quoteid,requestid,statebits; cJSON *retjson,*array; bits256 privkey; + retjson = cJSON_CreateObject(); + array = cJSON_CreateArray(); + sprintf(fname,"%s/SWAPS/list",GLOBAL_DBDIR), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb")) != 0 ) + { + while ( fread(&requestid,1,sizeof(requestid),fp) == sizeof(requestid) && fread("eid,1,sizeof(quoteid),fp) == sizeof(quoteid) ) + { + if ( basilisk_swap_load(requestid,quoteid,&privkey,&R,&statebits,&optionduration) == 0 ) + { + jaddi(array,basilisk_requestjson(&R)); + } + } + fclose(fp); + } + jaddstr(retjson,"result","success"); + jadd(retjson,"swaps",array); + return(jprint(retjson,1)); +} + + diff --git a/iguana/tests/dexgetT b/iguana/tests/dexgetT index 0cae93716..7483dbd01 100755 --- a/iguana/tests/dexgetT +++ b/iguana/tests/dexgetT @@ -1,2 +1,2 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettransaction\",\"txid\":\"790211d19afd88f00537c2b847772cebe01853617528990e1c1f59eb45d2f1d9\",\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettransaction\",\"txid\":\"3c00ee16d12c6aae81863d1da485cdd6cd2b73847f8ab93de3663adf6c285e3b\",\"symbol\":\"KMD\"}" diff --git a/iguana/tests/swaplist b/iguana/tests/swaplist new file mode 100755 index 000000000..2db29548e --- /dev/null +++ b/iguana/tests/swaplist @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"getswaplist\"}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 048165ccd..861e71444 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -224,6 +224,7 @@ ZERO_ARGS(InstantDEX,allexchanges); STRING_ARG(InstantDEX,allpairs,exchange); THREE_STRINGS(InstantDEX,supports,exchange,base,rel); ZERO_ARGS(InstantDEX,init); +ZERO_ARGS(InstantDEX,getswaplist); //THREE_STRINGS(atomic,approve,myorderid,otherid,txname); //THREE_STRINGS(atomic,claim,myorderid,otherid,txname); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 7496ccd4b..ac4487c49 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -526,6 +526,7 @@ int32_t iguana_unspentind2txid(struct supernet_info *myinfo,struct iguana_info * int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_outpoint outpt); char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj,struct vin_info *V); int32_t iguana_markedunspents_find(struct iguana_info *coin,int32_t *firstslotp,bits256 txid,int32_t vout); +void jumblr_opidsupdate(struct supernet_info *myinfo,struct iguana_info *coin); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey,struct vin_info *V); bits256 scrypt_blockhash(const void *input);