jl777 8 years ago
parent
commit
c0ee44dc54
  1. 6
      basilisk/basilisk.c
  2. 15
      basilisk/basilisk_DEX.c
  3. 11
      basilisk/basilisk_MSG.c
  4. 28
      basilisk/basilisk_bitcoin.c
  5. 3
      basilisk/basilisk_swap.c
  6. 2
      basilisk/basilisk_tradebot.c

6
basilisk/basilisk.c

@ -29,6 +29,7 @@ uint32_t basilisk_majority32(int32_t *datalenp,uint32_t rawcrcs[64],int32_t data
{
for (i=0; i<numcrcs; i++)
{
printf("%08x ",rawcrcs[i]);
for (j=0; j<numcandidates; j++)
{
if ( rawcrcs[i] == candidates[j] && datalens[i] == candlens[j] )
@ -45,13 +46,14 @@ uint32_t basilisk_majority32(int32_t *datalenp,uint32_t rawcrcs[64],int32_t data
numcandidates++;
}
}
printf("n.%d -> numcandidates.%d\n",i,numcandidates);
if ( numcandidates > 0 )
{
for (j=0; j<numcandidates; j++)
if ( tally[j] >= mintally )
{
*datalenp = candlens[j];
printf("tally[%d] >= mintally.%d numcrcs.%d crc %08x datalen.%d\n",j,mintally,numcrcs,candidates[j],*datalenp);
printf("tally[%d] %d >= mintally.%d numcrcs.%d crc %08x datalen.%d\n",j,tally[j],mintally,numcrcs,candidates[j],*datalenp);
return(candidates[j]);
}
}
@ -645,7 +647,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
jaddstr(item,"myip",remoteaddr);
if ( pending->numresults < sizeof(pending->results)/sizeof(*pending->results) )
{
//printf("%p.(RESULT).%d\n",pending,pending->numresults);
//printf("%p.(%s).%d\n",pending,jprint(item,0),pending->numresults);
pending->results[pending->numresults++] = item;
}
} else printf("couldnt parse.(%s)\n",retstr);

15
basilisk/basilisk_DEX.c

@ -288,10 +288,12 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
crcs[0] = crcs[1] = 0;
numiters = 0;
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
while ( numiters < 10 && (crc= basilisk_swapcrcsend(myinfo,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 )
{
printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
numiters++;
}
if ( crc != 0 )
@ -537,9 +539,20 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
} else printf("error creating request\n");
if ( datalen > 0 )
{
uint32_t msgid,crc,crcs[2],numiters = 0; uint8_t buf[4096];
memset(hash.bytes,0,sizeof(hash));
msgid = (uint32_t)time(NULL);
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
if ( basilisk_channelsend(myinfo,R.srchash,R.desthash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 )
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
sleep(3);
while ( numiters < 10 && (crc= basilisk_swapcrcsend(myinfo,buf,sizeof(buf),myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,crcs)) == 0 )
{
printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
numiters++;
}
if ( crc != 0 )//basilisk_channelsend(myinfo,R.srchash,R.desthash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 )
return(clonestr("{\"result\":\"DEX message sent\"}"));
else return(clonestr("{\"error\":\"DEX message couldnt be sent\"}"));
}

11
basilisk/basilisk_MSG.c

@ -196,10 +196,13 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
}
else
{
printf("overwrite update of msg.[%d]\n",msg->datalen);
memcpy(msg->data,data,datalen);
if ( sendping != 0 )
queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0);
if ( memcmp(msg->data,data,datalen) != 0 )
{
printf("overwrite update of msg.[%d] <- datalen.%d\n",msg->datalen,datalen);
memcpy(msg->data,data,datalen);
if ( sendping != 0 )
queue_enqueue("basilisk_message",&myinfo->msgQ,&msg->DL,0);
}
portable_mutex_unlock(&myinfo->messagemutex);
return(clonestr("{\"result\":\"message updated\"}"));
}

28
basilisk/basilisk_bitcoin.c

@ -383,7 +383,7 @@ double basilisk_bitcoin_valuemetric(struct supernet_info *myinfo,struct basilisk
void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64],str[65]; struct basilisk_value *v; uint64_t value = 0; bits256 txid; struct iguana_outpoint outpt;
int32_t i,j,height,vout,numsent; cJSON *retjson; struct basilisk_item *ptr; char coinaddr[64],str[65]; struct basilisk_value *v; uint64_t value = 0; bits256 txid; struct iguana_outpoint outpt;
if ( valsobj == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 )
@ -414,19 +414,35 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
printf("bitcoinvalue local ht.%d %s %.8f\n",v->height,v->coinaddr,dstr(v->value));
ptr = basilisk_issueremote(myinfo,0,&numsent,"VAL",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"numrequired"),basilisktag,timeoutmillis,0,basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout),0,0,BASILISK_DEFAULTDIFF); // this completes immediate
//queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
if ( ptr->numresults > 0 )
{
retjson = cJSON_CreateArray();
for (j=0; j<ptr->numresults; j++)
jaddi(retjson,ptr->results[j]), ptr->results[j] = 0;
ptr->retstr = jprint(retjson,1);
//printf("numresults.%d (%p)\n",ptr->numresults,ptr);
}
return(ptr);
}
}
}
printf("bitcoinvalue issue remote tag.%u\n",basilisktag);
ptr = basilisk_issueremote(myinfo,0,&numsent,"VAL",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"numrequired"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF);
if ( ptr->numresults > 0 )
{
retjson = cJSON_CreateArray();
for (j=0; j<ptr->numresults; j++)
jaddi(retjson,ptr->results[j]), ptr->results[j] = 0;
ptr->retstr = jprint(retjson,1);
//printf("numresults.%d (%p)\n",ptr->numresults,ptr);
}
//queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
return(ptr);
}
void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
struct basilisk_item *ptr; cJSON *infojson; int32_t numsent,fanout,numrequired;
struct basilisk_item *ptr; cJSON *infojson,*retjson; int32_t j,numsent,fanout,numrequired;
if ( valsobj == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
if ( (myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0) && strcmp(coin->symbol,"NOTARY") != 0 )
@ -445,6 +461,14 @@ void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,s
numrequired = 1;
}
ptr = basilisk_issueremote(myinfo,0,&numsent,"INF",coin->symbol,1,valsobj,fanout,numrequired,basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF);
if ( ptr->numresults > 0 )
{
retjson = cJSON_CreateArray();
for (j=0; j<ptr->numresults; j++)
jaddi(retjson,ptr->results[j]), ptr->results[j] = 0;
ptr->retstr = jprint(retjson,1);
//printf("numresults.%d (%p)\n",ptr->numresults,ptr);
}
return(ptr);
}

3
basilisk/basilisk_swap.c

@ -465,8 +465,9 @@ uint32_t basilisk_swaprecv(struct supernet_info *myinfo,uint8_t *verifybuf,int32
*datalenp = 0;
memset(rawcrcs,0,sizeof(rawcrcs));
memset(datalens,0,sizeof(datalens));
if ( (retarray= basilisk_channelget(myinfo,srchash,desthash,channel,msgbits,0)) != 0 )
if ( (retarray= basilisk_channelget(myinfo,desthash,srchash,channel,msgbits,0)) != 0 )
{
//printf("retarray.(%s)\n",jprint(retarray,0));
if ( (n= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<n; i++)

2
basilisk/basilisk_tradebot.c

@ -190,7 +190,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
}
} else noquoteflag++;
}
printf("%s -> %s myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",list[0].src,list[0].dest,myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount));
//printf("%s -> %s myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",list[0].src,list[0].dest,myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount));
double retvals[4],refprice,profitmargin,aveprice; cJSON *retjson; char *retstr;
if ( myinfo->IAMLP != 0 && myrequest == 0 && pendingid == 0 && noquoteflag != 0 && (profitmargin= tradebot_liquidity_active(myinfo,&refprice,list[0].src,list[0].dest)) > 0. )
{

Loading…
Cancel
Save