Browse Source

Test

etomic
jl777 7 years ago
parent
commit
89efa12c76
  1. 50
      iguana/exchanges/LP_socket.c

50
iguana/exchanges/LP_socket.c

@ -363,6 +363,16 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep
cJSON *electrum_version(char *symbol,struct electrum_info *ep,cJSON **retjsonp);
cJSON *electrum_headers_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp);
struct stritem *electrum_sitem(struct electrum_info *ep,char *stratumreq,int32_t timeout,cJSON **retjsonp)
{
struct stritem *sitem = (struct stritem *)queueitem(stratumreq);
sitem->expiration = timeout;
sitem->DL.type = ep->stratumid++;
sitem->retptrp = (void **)retjsonp;
queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
return(sitem);
}
cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout)
{
// queue id and string and callback
@ -377,12 +387,13 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params);
//printf("%s %s",symbol,stratumreq);
memset(ep->buf,0,ep->bufsize);
sitem = (struct stritem *)queueitem(stratumreq);
sitem = electrum_sitem(ep,stratumreq,timeout,retjsonp);
/*sitem = (struct stritem *)queueitem(stratumreq);
sitem->expiration = timeout;
sitem->DL.type = ep->stratumid++;
sitem->retptrp = (void **)retjsonp;
sitem->retptrp = (void **)retjsonp;*/
portable_mutex_lock(&ep->mutex);
queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
//queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
expiration = (uint32_t)time(NULL) + timeout + 1;
while ( *retjsonp == 0 && time(NULL) <= expiration )
usleep(5000);
@ -928,23 +939,26 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len)
void LP_dedicatedloop(void *arg)
{
struct pollfd fds; int32_t i,len,flag,timeout = 10; struct iguana_info *coin; cJSON *retjson; struct stritem *sitem; struct electrum_info *ep = arg;
char stratumreq[1024]; struct pollfd fds; int32_t i,len,flag,timeout = 10; struct iguana_info *coin; cJSON *retjson=0; struct stritem *sitem; struct electrum_info *ep = arg;
if ( (coin= LP_coinfind(ep->symbol)) != 0 )
ep->heightp = &coin->height, ep->heighttimep = &coin->heighttime;
if ( (retjson= electrum_headers_subscribe(ep->symbol,ep,&retjson)) != 0 )
free_json(retjson);
sleep(2);
for (i=0; i<3; i++)
{
printf("call estimatefee\n");
if ( (retjson= electrum_estimatefee(coin->symbol,coin->electrum,&retjson,2)) != 0 )
{
printf("estimate fee (%s)\n",jprint(retjson,0));
free_json(retjson);
} else printf("null value from electrum_estimatefee\n");
}
if ( (retjson= electrum_version(ep->symbol,ep,&retjson)) != 0 )
printf("electrum_version %s\n",jprint(retjson,1));
retjson = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,"blockchain.headers.subscribe","[]");
electrum_sitem(ep,stratumreq,3,&retjson);
retjson = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,"server.version","[\"barterDEX\", [\"1.1\", \"1.1\"]]");
electrum_sitem(ep,stratumreq,3,&retjson);
retjson = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,"blockchain.estimatefee","[2]");
electrum_sitem(ep,stratumreq,3,&retjson);
//if ( (retjson= electrum_headers_subscribe(ep->symbol,ep,&retjson)) != 0 )
// free_json(retjson);
//if ( (retjson= electrum_version(ep->symbol,ep,&retjson)) != 0 )
// printf("electrum_version %s\n",jprint(retjson,1));
printf("LP_dedicatedloop ep.%p sock.%d for %s:%u num.%d %p %s ht.%d\n",ep,ep->sock,ep->ipaddr,ep->port,Num_electrums,&Num_electrums,ep->symbol,*ep->heightp);
while ( ep->sock >= 0 )
{

Loading…
Cancel
Save