diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3dd161b7a..25f0d0631 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -166,6 +166,7 @@ instantdex_deposit(weeks, amount, broadcast=1)\n\ instantdex_claim()\n\ timelock(coin, duration, destaddr=(tradeaddr), amount)\n\ unlockedspend(coin, txid)\n\ +getendpoint()\n\ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ \"}")); //sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ @@ -230,6 +231,27 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ } return(clonestr("{\"error\":\"cant find KMD\"}")); } + else if ( strcmp(method,"getendpoint") == 0 ) + { + retjson = cJSON_CreateObject(); + if ( IPC_ENDPOINT >= 0 ) + { + jaddstr(retjson,"error","IPC endpoint already exists"); + jaddstr(retjson,"endpoint",LP_IPC_ENDPOINT); + } + else + { + if ( (IPC_ENDPOINT= nn_socket(AF_SP,NN_PUB)) >= 0 ) + { + if ( nn_bind(IPC_ENDPOINT,LP_IPC_ENDPOINT) >= 0 ) + { + jaddstr(retjson,"result","success"); + jaddstr(retjson,"endpoint",LP_IPC_ENDPOINT); + } else jaddstr(retjson,"error","couldnt connect to IPC_ENDPOINT"); + } else jaddstr(retjson,"error","couldnt get NN_PUB socket"); + } + return(jprint(retjson,1)); + } else if ( strcmp(method,"instantdex_claim") == 0 ) { if ( (ptr= LP_coinsearch("KMD")) != 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index bf3458156..ec9ec23e2 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -39,6 +39,8 @@ voind dontprintf(char *formatstr,...) {} #define LP_BARTERDEX_VERSION 1 #define LP_MAGICBITS 1 +#define LP_IPC_ENDPOINT "ws://127.0.0.1:7781" + #define LP_DONT_IMPORTPRIVKEY #ifdef FROM_JS diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9f2aca080..87b481dee 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -101,7 +101,7 @@ struct LP_trade *LP_trades,*LP_tradesQ; uint16_t LP_fixed_pairport;//,LP_publicport; uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; int32_t LP_STOP_RECEIVED,LP_numactive_LP;//,LP_mybussock = -1; -int32_t LP_mypubsock = -1; +int32_t LP_mypubsock = -1,IPC_ENDPOINT = -1; int32_t LP_cmdcount,LP_mypullsock = -1; int32_t LP_numfinished,LP_showwif,IAMLP = 0; double LP_profitratio = 1.; diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 53f2748f2..85094b68b 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -330,6 +330,7 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr) } extern void *bitcoin_ctx(); +extern int32_t IPC_ENDPOINT; char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port) { @@ -556,7 +557,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po } else { - cJSON *arg; //char *buf; + cJSON *arg; char *buf; if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 ) { arg = jobj(argjson,"params"); @@ -569,20 +570,25 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po #ifdef FROM_MARKETMAKER if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 ) { - //buf = jprint(arg,0); - //LP_queuecommand(&retstr,buf,-1,1); - //free(buf); - //while ( retstr == 0 ) - // usleep(10000); - retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); + if ( IPC_ENDPOINT >= 0 ) + { + if ( jobj(arg,"id") == 0 ) + jaddnum(arg,"id",rand()); + buf = jprint(arg,0); + LP_queuecommand(&retstr,buf,-1,1); + free(buf); + retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); + } else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); } else retstr = clonestr("{\"error\":\"invalid remote method\"}"); #else - //buf = jprint(arg,0); - //LP_queuecommand(&retstr,buf,-1,1); - //free(buf); - //while ( retstr == 0 ) - // usleep(10000); - retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); + if ( IPC_ENDPOINT >= 0 ) + { + if ( jobj(arg,"id") == 0 ) + jaddnum(arg,"id",rand()); + buf = jprint(arg,0); + LP_queuecommand(&retstr,buf,-1,1); + free(buf); + } else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); #endif } free_json(argjson);