Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
15b0ab37bc
  1. 4
      basilisk/basilisk.h
  2. 109
      basilisk/basilisk_DEX.c
  3. 6
      iguana/iguana_exchanges.c
  4. 2
      iguana/iguana_msg.c
  5. 2
      iguana/tests/request

4
basilisk/basilisk.h

@ -41,12 +41,12 @@
struct basilisk_request struct basilisk_request
{ {
uint32_t requestid,timestamp,quoteid; uint32_t requestid,timestamp,quoteid;
uint64_t srcamount; uint64_t srcamount,minamount;
bits256 hash; bits256 hash;
char src[8],dest[8]; char src[8],dest[8];
char volatile_start,message[43]; char volatile_start,message[43];
uint64_t destamount;
uint32_t relaybits; uint32_t relaybits;
uint64_t destamount;
bits256 desthash; bits256 desthash;
} __attribute__((packed)); } __attribute__((packed));

109
basilisk/basilisk_DEX.c

@ -71,13 +71,14 @@ int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_r
return(len); return(len);
} }
uint32_t basilisk_request_enqueue(struct supernet_info *myinfo,int32_t queueflag,struct basilisk_request *finalR,bits256 hash,char *src,uint64_t srcamount,bits256 desthash,char *dest,uint64_t destamount,char *message,int32_t calcquoteid) uint32_t basilisk_request_enqueue(struct supernet_info *myinfo,int32_t queueflag,struct basilisk_request *finalR,bits256 hash,char *src,uint64_t srcamount,uint64_t minamount,bits256 desthash,char *dest,uint64_t destamount,char *message,int32_t calcquoteid)
{ {
uint8_t serialized[256]; int32_t len; struct queueitem *item; struct basilisk_request R; uint8_t serialized[256]; int32_t len; struct queueitem *item; struct basilisk_request R;
memset(&R,0,sizeof(R)); memset(&R,0,sizeof(R));
R.timestamp = (uint32_t)time(NULL); R.timestamp = (uint32_t)time(NULL);
R.hash = hash; R.hash = hash;
R.srcamount = srcamount; R.srcamount = srcamount;
R.minamount = minamount;
strncpy(R.src,src,sizeof(R.src)-1); strncpy(R.src,src,sizeof(R.src)-1);
strncpy(R.dest,dest,sizeof(R.dest)-1); strncpy(R.dest,dest,sizeof(R.dest)-1);
if ( message != 0 ) if ( message != 0 )
@ -105,15 +106,63 @@ uint32_t basilisk_request_enqueue(struct supernet_info *myinfo,int32_t queueflag
return(0); return(0);
} }
struct basilisk_request *basilisk_parsejson(struct basilisk_request *rp,cJSON *reqjson)
{
uint32_t requestid,quoteid; char *msgstr;
memset(rp,0,sizeof(*rp));
rp->hash = jbits256(reqjson,"hash");
rp->desthash = jbits256(reqjson,"desthash");
rp->srcamount = j64bits(reqjson,"srcamount");
rp->minamount = j64bits(reqjson,"minamount");
rp->destamount = j64bits(reqjson,"destamount");
requestid = juint(reqjson,"requestid");
quoteid = juint(reqjson,"quoteid");
if ( jstr(reqjson,"relay") != 0 )
rp->relaybits = (uint32_t)calc_ipbits(jstr(reqjson,"relay"));
rp->timestamp = juint(reqjson,"timestamp");
safecopy(rp->src,jstr(reqjson,"src"),sizeof(rp->src));
safecopy(rp->dest,jstr(reqjson,"dest"),sizeof(rp->dest));
if ( jobj(reqjson,"message") != 0 )
{
msgstr = jprint(jobj(reqjson,"message"),0);
if ( strlen(msgstr) > sizeof(rp->message)-1 )
printf("basilisk_parsejson msgstr.(%s) too long\n",msgstr);
safecopy(rp->message,msgstr,sizeof(rp->message));
free(msgstr);
}
if ( quoteid != 0 )
{
rp->quoteid = basilisk_quoteid(rp);
if ( quoteid != rp->quoteid )
printf("basilisk_parsejson quoteid.%u != %u error\n",quoteid,rp->quoteid);
}
rp->requestid = basilisk_requestid(rp);
if ( requestid != rp->requestid )
printf("basilisk_parsejson requestid.%u != %u error\n",requestid,rp->requestid);
return(rp);
}
cJSON *basilisk_requestjson(uint32_t relaybits,struct basilisk_request *rp) cJSON *basilisk_requestjson(uint32_t relaybits,struct basilisk_request *rp)
{ {
/*uint32_t requestid,timestamp,quoteid;
uint64_t srcamount,minamount;
bits256 hash;
char src[8],dest[8];
char volatile_start,message[43];
uint32_t relaybits;
uint64_t destamount;
bits256 desthash;*/
char ipaddr[64]; cJSON *msgobj,*item = cJSON_CreateObject(); char ipaddr[64]; cJSON *msgobj,*item = cJSON_CreateObject();
expand_ipbits(ipaddr,relaybits); expand_ipbits(ipaddr,relaybits);
jaddstr(item,"relay",ipaddr); jaddstr(item,"relay",ipaddr);
jaddbits256(item,"hash",rp->hash); jaddbits256(item,"hash",rp->hash);
if ( bits256_nonz(rp->desthash) != 0 )
jaddbits256(item,"desthash",rp->desthash);
jaddstr(item,"src",rp->src); jaddstr(item,"src",rp->src);
if ( rp->srcamount != 0 ) if ( rp->srcamount != 0 )
jadd64bits(item,"srcamount",rp->srcamount); jadd64bits(item,"srcamount",rp->srcamount);
if ( rp->minamount != 0 )
jadd64bits(item,"min",rp->minamount);
jaddstr(item,"dest",rp->dest); jaddstr(item,"dest",rp->dest);
if ( rp->destamount != 0 ) if ( rp->destamount != 0 )
jadd64bits(item,"destamount",rp->destamount); jadd64bits(item,"destamount",rp->destamount);
@ -122,6 +171,25 @@ cJSON *basilisk_requestjson(uint32_t relaybits,struct basilisk_request *rp)
jaddnum(item,"quoteid",rp->quoteid); jaddnum(item,"quoteid",rp->quoteid);
if ( rp->message[0] != 0 && (msgobj= cJSON_Parse(rp->message)) != 0 ) if ( rp->message[0] != 0 && (msgobj= cJSON_Parse(rp->message)) != 0 )
jadd(item,"message",msgobj); jadd(item,"message",msgobj);
if ( rp->quoteid != 0 && basilisk_quoteid(rp) != rp->quoteid )
printf("quoteid mismatch %u vs %u\n",basilisk_quoteid(rp),rp->quoteid);
if ( basilisk_requestid(rp) != rp->requestid )
printf("requestid mismatch %u vs %u\n",basilisk_requestid(rp),rp->requestid);
{
int32_t i; struct basilisk_request R;
if ( basilisk_parsejson(&R,item) != 0 )
{
if ( memcmp(&R,rp,sizeof(*rp)) != 0 )
{
for (i=0; i<sizeof(*rp); i++)
printf("%02x",((uint8_t *)rp)[i]);
printf(" <- rp\n");
for (i=0; i<sizeof(R); i++)
printf("%02x",((uint8_t *)&R)[i]);
printf(" <- R mismatch\n");
}
}
}
return(item); return(item);
} }
@ -129,14 +197,14 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,ui
{ {
cJSON *retjson; struct basilisk_request R; char msgjsonstr[64]; cJSON *retjson; struct basilisk_request R; char msgjsonstr[64];
sprintf(msgjsonstr,"{\"state\":%u\"}",statebits); sprintf(msgjsonstr,"{\"state\":%u\"}",statebits);
if ( basilisk_request_enqueue(myinfo,1,&R,rp->hash,rp->src,rp->srcamount,rp->desthash,rp->dest,rp->destamount,msgjsonstr,myinfo->RELAYID < 0) == rp->requestid ) if ( basilisk_request_enqueue(myinfo,1,&R,rp->hash,rp->src,rp->srcamount,rp->minamount,rp->desthash,rp->dest,rp->destamount,msgjsonstr,myinfo->RELAYID < 0) == rp->requestid )
{ {
if ( myinfo->RELAYID >= 0 && (bits256_cmp(rp->hash,myinfo->myaddr.persistent) == 0 || bits256_cmp(rp->desthash,myinfo->myaddr.persistent) == 0) ) if ( myinfo->RELAYID >= 0 && (bits256_cmp(rp->hash,myinfo->myaddr.persistent) == 0 || bits256_cmp(rp->desthash,myinfo->myaddr.persistent) == 0) )
{ {
printf("START thread to complete %u/%u for (%s %.8f) <- (%s %.8f)\n",rp->requestid,R.quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount)); printf("START thread to complete %u/%u for (%s %.8f) <- (%s %.8f)\n",rp->requestid,R.quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount));
if ( basilisk_thread_start(myinfo,&R) != 0 ) if ( basilisk_thread_start(myinfo,&R) != 0 )
{ {
basilisk_request_enqueue(myinfo,1,&R,rp->hash,rp->src,rp->srcamount,rp->desthash,rp->dest,rp->destamount,msgjsonstr,1); basilisk_request_enqueue(myinfo,1,&R,rp->hash,rp->src,rp->srcamount,rp->minamount,rp->desthash,rp->dest,rp->destamount,msgjsonstr,1);
return(clonestr("{\"result\":\"started atomic swap thread\"}")); return(clonestr("{\"result\":\"started atomic swap thread\"}"));
} }
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}"));
@ -152,38 +220,6 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,ui
} }
// end of swap code // end of swap code
struct basilisk_request *basilisk_parsejson(struct basilisk_request *rp,cJSON *reqjson)
{
uint32_t requestid,quoteid; char *msgstr;
memset(rp,0,sizeof(*rp));
rp->hash = jbits256(reqjson,"hash");
rp->srcamount = j64bits(reqjson,"srcamount");
rp->destamount = j64bits(reqjson,"destamount");
requestid = juint(reqjson,"requestid");
quoteid = juint(reqjson,"quoteid");
rp->timestamp = juint(reqjson,"timestamp");
safecopy(rp->src,jstr(reqjson,"src"),sizeof(rp->src));
safecopy(rp->dest,jstr(reqjson,"dest"),sizeof(rp->dest));
if ( jobj(reqjson,"message") != 0 )
{
msgstr = jprint(jobj(reqjson,"message"),0);
if ( strlen(msgstr) > sizeof(rp->message)-1 )
printf("basilisk_parsejson msgstr.(%s) too long\n",msgstr);
safecopy(rp->message,msgstr,sizeof(rp->message));
free(msgstr);
}
if ( quoteid != 0 )
{
rp->quoteid = basilisk_quoteid(rp);
if ( quoteid != rp->quoteid )
printf("basilisk_parsejson quoteid.%u != %u error\n",quoteid,rp->quoteid);
}
rp->requestid = basilisk_requestid(rp);
if ( requestid != rp->requestid )
printf("basilisk_parsejson requestid.%u != %u error\n",requestid,rp->requestid);
return(rp);
}
struct basilisk_relay *basilisk_request_ensure(struct supernet_info *myinfo,uint32_t senderipbits,int32_t numrequests) struct basilisk_relay *basilisk_request_ensure(struct supernet_info *myinfo,uint32_t senderipbits,int32_t numrequests)
{ {
int32_t j; struct basilisk_relay *relay = 0; int32_t j; struct basilisk_relay *relay = 0;
@ -431,7 +467,7 @@ char *basilisk_respond_DEX(struct supernet_info *myinfo,char *CMD,void *addr,cha
char str[65]; printf("DEX.(%s %.8f) -> %s %s\n",src,dstr(satoshis),dest,bits256_str(str,hash)); char str[65]; printf("DEX.(%s %.8f) -> %s %s\n",src,dstr(satoshis),dest,bits256_str(str,hash));
if ( jobj(valsobj,"message") != 0 ) if ( jobj(valsobj,"message") != 0 )
msgstr = jprint(jobj(valsobj,"message"),0); msgstr = jprint(jobj(valsobj,"message"),0);
if ( (requestid= basilisk_request_enqueue(myinfo,1,&R,hash,src,satoshis,desthash,dest,destamount,msgstr,destamount != 0)) != 0 ) if ( (requestid= basilisk_request_enqueue(myinfo,1,&R,hash,src,satoshis,j64bits(valsobj,"min"),desthash,dest,destamount,msgstr,destamount != 0)) != 0 )
{ {
sprintf(buf,"{\"result\":\"DEX request added\",\"requestid\":%u}",requestid); sprintf(buf,"{\"result\":\"DEX request added\",\"requestid\":%u}",requestid);
retstr = clonestr(buf); retstr = clonestr(buf);
@ -491,6 +527,7 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
jaddbits256(vals,"desthash",hash); jaddbits256(vals,"desthash",hash);
jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN); jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN);
jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN); jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN);
printf("service.(%s)\n",jprint(vals,0));
return(basilisk_standardservice("DEX",myinfo,0,myinfo->myaddr.persistent,vals,"",1)); return(basilisk_standardservice("DEX",myinfo,0,myinfo->myaddr.persistent,vals,"",1));
} }

6
iguana/iguana_exchanges.c

@ -84,19 +84,19 @@ double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *s
else if ( dir > 0 && active[i]->numasks > 0 ) else if ( dir > 0 && active[i]->numasks > 0 )
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks); n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks);
} }
printf("dir.%d %s/%s numX.%d n.%d\n",dir,base,rel,num,n); //printf("dir.%d %s/%s numX.%d n.%d\n",dir,base,rel,num,n);
if ( dir < 0 ) if ( dir < 0 )
revsort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf)); revsort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
else sort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf)); else sort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
for (totalvol=pricesum=i=0; i<n && totalvol < basevolume; i++) for (totalvol=pricesum=i=0; i<n && totalvol < basevolume; i++)
{ {
quote = sortbuf[i]; quote = sortbuf[i];
printf("n.%d i.%d price %.8f %.8f %.8f\n",n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume); //printf("n.%d i.%d price %.8f %.8f %.8f\n",n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume);
if ( quote.satoshis != 0 ) if ( quote.satoshis != 0 )
{ {
pricesum += (quote.price * quote.volume); pricesum += (quote.price * quote.volume);
totalvol += quote.volume; totalvol += quote.volume;
printf("i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol); //printf("i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol);
} }
} }
if ( totalvol > 0. ) if ( totalvol > 0. )

2
iguana/iguana_msg.c

@ -889,7 +889,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
{ {
struct iguana_msgblock msg; struct iguana_zblock *zblocks; uint32_t tmp,n=0; struct iguana_msgblock msg; struct iguana_zblock *zblocks; uint32_t tmp,n=0;
len = 0; len = 0;
if ( addr != 0 ) if ( addr != 0 && recvlen >= sizeof(bits256) )
{ {
if ( ishost == 0 ) if ( ishost == 0 )
{ {

2
iguana/tests/request

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":1,\"dest\":\"BTC\",\"minprice\":0.003,\"autoflag\":1}}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"BTCD\",\"amount\":1,\"dest\":\"BTC\",\"minprice\":0.0025,\"autoflag\":1}}"

Loading…
Cancel
Save