From 00530e8afa66aa637d133ba2de86ad0a44bd4326 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Mar 2018 15:26:13 +0200 Subject: [PATCH] Price feed --- iguana/exchanges/LP_network.c | 21 +++++++++++++++++---- iguana/exchanges/LP_signatures.c | 7 ++++++- iguana/exchanges/stats.c | 4 ++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index acb4cfc54..dbbd8fb08 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -443,7 +443,22 @@ void LP_commandQ_loop(void *ctx) portable_mutex_lock(&LP_commandQmutex); DL_DELETE(LP_commandQ,ptr); portable_mutex_unlock(&LP_commandQmutex); - if ( (argjson= cJSON_Parse(ptr->msg)) != 0 ) + if ( ptr->stats_JSONonly < 0 ) + { + if ( ptr->responsesock >= 0 ) + { + if ( (result= cJSON_Parse(ptr->msg)) != 0 ) + { + retjson = cJSON_CreateObject(); + jaddnum(retjson,"queueid",0); + jadd(retjson,"result",result); + retstr = jprint(retjson,1); + if ( (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr)+1,0)) <= 0 ) + printf("error sending event\n"); + } + } + } + else if ( (argjson= cJSON_Parse(ptr->msg)) != 0 ) { if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 ) { @@ -489,9 +504,7 @@ void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats if ( (ptr->retstrp= retstrp) != 0 ) *retstrp = 0; ptr->msglen = msglen; - if ( (ptr->queueid= queueid) != 0 && responsesock < 0 ) - ptr->responsesock = IPC_ENDPOINT; - else ptr->responsesock = responsesock; + ptr->responsesock = responsesock; ptr->stats_JSONonly = stats_JSONonly; memcpy(ptr->msg,buf,msglen); DL_APPEND(LP_commandQ,ptr); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 693f31c3a..778c31161 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -458,7 +458,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re char *LP_postprice_recv(cJSON *argjson) { - bits256 pubkey; double price; char *base,*rel; + bits256 pubkey; double price; char *base,*rel,*argstr; //printf("PRICE POSTED.(%s)\n",jprint(argjson,0)); if ( (base= jstr(argjson,"base")) != 0 && (rel= jstr(argjson,"rel")) != 0 && (price= jdouble(argjson,"price")) > SMALLVAL ) { @@ -467,6 +467,11 @@ char *LP_postprice_recv(cJSON *argjson) { if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 ) { + if ( (argstr= jprint(argjson,0)) != 0 ) + { + LP_queuecommand(0,argstr,IPC_ENDPOINT,-1,0); + free(argstr); + } //printf("call pricefeed update\n"); LP_pricefeedupdate(pubkey,base,rel,price,jstr(argjson,"utxocoin"),jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN,jdouble(argjson,"credits")*SATOSHIDEN); return(clonestr("{\"result\":\"success\"}")); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 71da554a2..bec47d574 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -573,7 +573,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) { buf = jprint(arg,0); - LP_queuecommand(&retstr,buf,-1,1,queueid); + LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); free(buf); retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); } else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); @@ -584,7 +584,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( jobj(arg,"id") == 0 ) jaddnum(arg,"id",rand()); buf = jprint(arg,0); - LP_queuecommand(&retstr,buf,-1,1,queueid); + LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); free(buf); } else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); #endif