jl777 8 years ago
parent
commit
9dda18a3cc
  1. 2
      basilisk/basilisk.c
  2. 16
      basilisk/basilisk_DEX.c
  3. 4
      basilisk/basilisk_swap.c
  4. 8
      basilisk/basilisk_tradebot.c
  5. 2
      includes/iguana_structs.h

2
basilisk/basilisk.c

@ -820,7 +820,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
} else printf("null incoming\n"); } else printf("null incoming\n");
if ( hwm > 0. ) if ( hwm > 0. )
{ {
if ( bits256_cmp(myinfo->myaddr.persistent,issueR.hash) == 0 ) // my request if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request
{ {
printf("my req hwm %f\n",hwm); printf("my req hwm %f\n",hwm);
if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 ) if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )

16
basilisk/basilisk_DEX.c

@ -103,7 +103,7 @@ int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_r
len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->relaybits),&rp->relaybits); len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->relaybits),&rp->relaybits);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->srcamount),&rp->srcamount); len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->srcamount),&rp->srcamount);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->minamount),&rp->minamount); len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->minamount),&rp->minamount);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(rp->hash),rp->hash.bytes); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(rp->srchash),rp->srchash.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(rp->desthash),rp->desthash.bytes); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(rp->desthash),rp->desthash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->destamount),&rp->destamount); len += iguana_rwnum(rwflag,&serialized[len],sizeof(rp->destamount),&rp->destamount);
if ( rwflag != 0 ) if ( rwflag != 0 )
@ -148,7 +148,7 @@ cJSON *basilisk_requestjson(struct basilisk_request *rp)
expand_ipbits(ipaddr,rp->relaybits); expand_ipbits(ipaddr,rp->relaybits);
jaddstr(item,"relay",ipaddr); jaddstr(item,"relay",ipaddr);
} }
jaddbits256(item,"hash",rp->hash); jaddbits256(item,"srchash",rp->srchash);
if ( bits256_nonz(rp->desthash) != 0 ) if ( bits256_nonz(rp->desthash) != 0 )
jaddbits256(item,"desthash",rp->desthash); jaddbits256(item,"desthash",rp->desthash);
jaddstr(item,"src",rp->src); jaddstr(item,"src",rp->src);
@ -189,7 +189,7 @@ cJSON *basilisk_requestjson(struct basilisk_request *rp)
return(item); return(item);
} }
int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits256 hash,uint32_t timestamp) int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits256 desthash,uint32_t timestamp)
{ {
char *dest,*src; uint32_t i; char *dest,*src; uint32_t i;
memset(rp,0,sizeof(*rp)); memset(rp,0,sizeof(*rp));
@ -197,7 +197,7 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2
{ {
if ( (rp->destamount= j64bits(valsobj,"destsatoshis")) != 0 ) if ( (rp->destamount= j64bits(valsobj,"destsatoshis")) != 0 )
{ {
rp->desthash = jbits256(valsobj,"desthash"); rp->desthash = desthash;
for (i=0; i<4; i++) for (i=0; i<4; i++)
if ( rp->desthash.ulongs[i] != 0 ) if ( rp->desthash.ulongs[i] != 0 )
break; break;
@ -206,7 +206,7 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2
} }
rp->minamount = j64bits(valsobj,"minamount"); rp->minamount = j64bits(valsobj,"minamount");
rp->timestamp = timestamp; rp->timestamp = timestamp;
rp->hash = hash; rp->srchash = jbits256(valsobj,"srchash");
strncpy(rp->src,src,sizeof(rp->src)-1); strncpy(rp->src,src,sizeof(rp->src)-1);
strncpy(rp->dest,dest,sizeof(rp->dest)-1); strncpy(rp->dest,dest,sizeof(rp->dest)-1);
rp->requestid = basilisk_requestid(rp); rp->requestid = basilisk_requestid(rp);
@ -224,7 +224,7 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2
char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits) char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits)
{ {
cJSON *retjson; cJSON *retjson;
if ( (bits256_cmp(rp->hash,myinfo->myaddr.persistent) == 0 || bits256_cmp(rp->desthash,myinfo->myaddr.persistent) == 0) ) if ( (bits256_cmp(rp->srchash,myinfo->myaddr.persistent) == 0 || bits256_cmp(rp->desthash,myinfo->myaddr.persistent) == 0) )
{ {
printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid);
if ( basilisk_thread_start(myinfo,rp) != 0 ) if ( basilisk_thread_start(myinfo,rp) != 0 )
@ -333,7 +333,7 @@ char *basilisk_respond_requests(struct supernet_info *myinfo,bits256 hash,uint32
for (i=0; i<num; i++) for (i=0; i<num; i++)
{ {
rp = &requests[i]; rp = &requests[i];
if ( quoteid == 0 || (quoteid == rp->quoteid && (bits256_cmp(hash,rp->hash) == 0 || bits256_cmp(hash,rp->desthash) == 0)) ) if ( quoteid == 0 || (quoteid == rp->quoteid && (bits256_cmp(hash,rp->srchash) == 0 || bits256_cmp(hash,rp->desthash) == 0)) )
qflag = 1; qflag = 1;
else qflag = 0; else qflag = 0;
if ( requestid == 0 || (rp->requestid == requestid && qflag != 0) ) if ( requestid == 0 || (rp->requestid == requestid && qflag != 0) )
@ -424,6 +424,8 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
uint8_t serialized[512]; struct basilisk_request R; cJSON *reqjson; uint32_t datalen=0,DEX_channel; uint8_t serialized[512]; struct basilisk_request R; cJSON *reqjson; uint32_t datalen=0,DEX_channel;
myinfo->DEXactive = (uint32_t)time(NULL) + BASILISK_TIMEOUT; myinfo->DEXactive = (uint32_t)time(NULL) + BASILISK_TIMEOUT;
jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN); jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN);
if ( jobj(vals,"srchash") == 0 )
jaddbits256(vals,"srchash",myinfo->myaddr.pubkey);
if ( jobj(vals,"desthash") == 0 ) if ( jobj(vals,"desthash") == 0 )
jaddbits256(vals,"desthash",hash); jaddbits256(vals,"desthash",hash);
jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN); jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN);

4
basilisk/basilisk_swap.c

@ -751,7 +751,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
swap->choosei %= INSTANTDEX_DECKSIZE; swap->choosei %= INSTANTDEX_DECKSIZE;
swap->otherchoosei = -1; swap->otherchoosei = -1;
swap->myhash = myinfo->myaddr.persistent; swap->myhash = myinfo->myaddr.persistent;
if ( bits256_cmp(swap->myhash,swap->req.hash) == 0 ) if ( bits256_cmp(swap->myhash,swap->req.srchash) == 0 )
{ {
swap->otherhash = swap->req.desthash; swap->otherhash = swap->req.desthash;
if ( strcmp(swap->req.src,swap->bobstr) == 0 ) if ( strcmp(swap->req.src,swap->bobstr) == 0 )
@ -764,7 +764,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
} }
else if ( bits256_cmp(swap->myhash,swap->req.desthash) == 0 ) else if ( bits256_cmp(swap->myhash,swap->req.desthash) == 0 )
{ {
swap->otherhash = swap->req.hash; swap->otherhash = swap->req.srchash;
if ( strcmp(swap->req.dest,swap->bobstr) == 0 ) if ( strcmp(swap->req.dest,swap->bobstr) == 0 )
swap->iambob = 1; swap->iambob = 1;
else if ( strcmp(swap->req.src,swap->alicestr) != 0 ) else if ( strcmp(swap->req.src,swap->alicestr) != 0 )

8
basilisk/basilisk_tradebot.c

@ -29,7 +29,7 @@ uint32_t basilisk_requestid(struct basilisk_request *rp)
for (i=0; i<sizeof(R); i++) for (i=0; i<sizeof(R); i++)
printf("%02x",((uint8_t *)&R)[i]); printf("%02x",((uint8_t *)&R)[i]);
printf(" <- crc.%u\n",calc_crc32(0,(void *)&R,sizeof(R))); printf(" <- crc.%u\n",calc_crc32(0,(void *)&R,sizeof(R)));
char str[65],str2[65]; printf("B REQUESTID: t.%u r.%u q.%u %s %.8f %s -> %s %.8f %s crc.%u\n",R.timestamp,R.requestid,R.quoteid,R.src,dstr(R.srcamount),bits256_str(str,R.hash),R.dest,dstr(R.destamount),bits256_str(str2,R.desthash),calc_crc32(0,(void *)&R,sizeof(R))); char str[65],str2[65]; printf("B REQUESTID: t.%u r.%u q.%u %s %.8f %s -> %s %.8f %s crc.%u\n",R.timestamp,R.requestid,R.quoteid,R.src,dstr(R.srcamount),bits256_str(str,R.srchash),R.dest,dstr(R.destamount),bits256_str(str2,R.desthash),calc_crc32(0,(void *)&R,sizeof(R)));
} }
return(calc_crc32(0,(void *)&R,sizeof(R))); return(calc_crc32(0,(void *)&R,sizeof(R)));
} }
@ -46,7 +46,7 @@ struct basilisk_request *basilisk_parsejson(struct basilisk_request *rp,cJSON *r
{ {
uint32_t requestid,quoteid; uint32_t requestid,quoteid;
memset(rp,0,sizeof(*rp)); memset(rp,0,sizeof(*rp));
rp->hash = jbits256(reqjson,"hash"); rp->srchash = jbits256(reqjson,"srchash");
rp->desthash = jbits256(reqjson,"desthash"); rp->desthash = jbits256(reqjson,"desthash");
rp->srcamount = j64bits(reqjson,"srcamount"); rp->srcamount = j64bits(reqjson,"srcamount");
rp->minamount = j64bits(reqjson,"minamount"); rp->minamount = j64bits(reqjson,"minamount");
@ -102,7 +102,7 @@ struct basilisk_swap *basilisk_request_started(struct supernet_info *myinfo,uint
int32_t basilisk_request_cmpref(struct basilisk_request *ref,struct basilisk_request *rp) int32_t basilisk_request_cmpref(struct basilisk_request *ref,struct basilisk_request *rp)
{ {
if ( bits256_cmp(rp->hash,ref->hash) != 0 || memcmp(rp->src,ref->src,sizeof(ref->src)) != 0 || memcmp(rp->dest,ref->dest,sizeof(ref->dest)) != 0 || rp->srcamount != ref->srcamount || rp->timestamp != ref->timestamp ) if ( bits256_cmp(rp->srchash,ref->srchash) != 0 || memcmp(rp->src,ref->src,sizeof(ref->src)) != 0 || memcmp(rp->dest,ref->dest,sizeof(ref->dest)) != 0 || rp->srcamount != ref->srcamount || rp->timestamp != ref->timestamp )
{ {
printf("basilisk_request_listprocess mismatched hash\n"); printf("basilisk_request_listprocess mismatched hash\n");
return(-1); return(-1);
@ -162,7 +162,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid); printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid);
if ( (active= basilisk_request_started(myinfo,list[0].requestid)) != 0 ) if ( (active= basilisk_request_started(myinfo,list[0].requestid)) != 0 )
pendingid = active->req.quoteid; pendingid = active->req.quoteid;
if ( bits256_cmp(myinfo->myaddr.persistent,list[0].hash) == 0 ) // my request if ( bits256_cmp(myinfo->myaddr.persistent,list[0].srchash) == 0 ) // my request
myrequest = 1; myrequest = 1;
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {

2
includes/iguana_structs.h

@ -548,7 +548,7 @@ struct basilisk_request
{ {
uint32_t requestid,timestamp,quoteid,quotetime; // 0 to 15 uint32_t requestid,timestamp,quoteid,quotetime; // 0 to 15
uint64_t srcamount,minamount; // 16 to 31 uint64_t srcamount,minamount; // 16 to 31
bits256 hash; // 32 to 63 bits256 srchash; // 32 to 63
bits256 desthash; bits256 desthash;
char src[8],dest[8]; char src[8],dest[8];
//char volatile_start,message[43]; //char volatile_start,message[43];

Loading…
Cancel
Save