Browse Source

IPC endpoint

jl777
jl777 7 years ago
parent
commit
461c8cd779
  1. 22
      iguana/exchanges/LP_commands.c
  2. 2
      iguana/exchanges/LP_include.h
  3. 2
      iguana/exchanges/LP_nativeDEX.c
  4. 32
      iguana/exchanges/stats.c

22
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 )

2
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

2
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.;

32
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);

Loading…
Cancel
Save