Browse Source

swaplist API

etomic
jl777 8 years ago
parent
commit
be1309d7f3
  1. 12
      .gitignore
  2. 7
      basilisk/basilisk.c
  3. 48
      basilisk/basilisk_swap.c
  4. 2
      iguana/tests/dexgetT
  5. 2
      iguana/tests/swaplist
  6. 1
      includes/iguana_apideclares.h
  7. 1
      includes/iguana_funcs.h

12
.gitignore

@ -184,3 +184,15 @@ iguana/DB/SWAPS/667293271-3414303895.swap
iguana/DB/SWAPS/548227681-1452262678.swap iguana/DB/SWAPS/548227681-1452262678.swap
iguana/DB/SWAPS/548227681-1452262678 iguana/DB/SWAPS/548227681-1452262678
*.bobdeposit
*.bobpayment
*.bobreclaim
*.bobrefund
*.swap
iguana/DB/SWAPS/1268007736-526212866

7
basilisk/basilisk.c

@ -1857,4 +1857,11 @@ ZERO_ARGS(InstantDEX,init)
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
ZERO_ARGS(InstantDEX,getswaplist)
{
return(basilisk_swaplist(myinfo));
}
#include "../includes/iguana_apiundefs.h" #include "../includes/iguana_apiundefs.h"

48
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]; FILE *fp=0; char fname[512];
sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,rp->requestid,rp->quoteid), OS_compatible_path(fname); 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 ) if ( (fp= fopen(fname,"wb+")) != 0 )
{ {
@ -1076,6 +1076,22 @@ FILE *basilisk_swap_save(struct supernet_info *myinfo,struct basilisk_swap *swap
return(fp); 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); 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) 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 if ( (fp= fopen(fname,"rb+")) != 0 ) // check to see if completed
{ {
memset(&M,0,sizeof(M)); memset(&M,0,sizeof(M));
swapcompleted = 0; swapcompleted = 1;
for (iter=0; iter<2; iter++) for (iter=0; iter<2; iter++)
{ {
if ( fread(privkey.bytes,1,sizeof(privkey),fp) == sizeof(privkey) && 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(&statebits,1,sizeof(statebits),fp) == sizeof(statebits) &&
fread(&optionduration,1,sizeof(optionduration),fp) == sizeof(optionduration) ) 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; M.data = 0;
//printf("entry iter.%d crc32.%x datalen.%d\n",iter,M.crc32,M.datalen); //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]; 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); 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->I,1,sizeof(swap->I),fp);
/*fwrite(&swap->bobdeposit,1,sizeof(swap->bobdeposit),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); portable_mutex_unlock(&myinfo->DEX_swapmutex);
return(swap); 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(&quoteid,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));
}

2
iguana/tests/dexgetT

@ -1,2 +1,2 @@
#!/bin/bash #!/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\"}"

2
iguana/tests/swaplist

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"getswaplist\"}"

1
includes/iguana_apideclares.h

@ -224,6 +224,7 @@ ZERO_ARGS(InstantDEX,allexchanges);
STRING_ARG(InstantDEX,allpairs,exchange); STRING_ARG(InstantDEX,allpairs,exchange);
THREE_STRINGS(InstantDEX,supports,exchange,base,rel); THREE_STRINGS(InstantDEX,supports,exchange,base,rel);
ZERO_ARGS(InstantDEX,init); ZERO_ARGS(InstantDEX,init);
ZERO_ARGS(InstantDEX,getswaplist);
//THREE_STRINGS(atomic,approve,myorderid,otherid,txname); //THREE_STRINGS(atomic,approve,myorderid,otherid,txname);
//THREE_STRINGS(atomic,claim,myorderid,otherid,txname); //THREE_STRINGS(atomic,claim,myorderid,otherid,txname);

1
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); 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); 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); 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); 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); bits256 scrypt_blockhash(const void *input);

Loading…
Cancel
Save