Browse Source

Merge pull request #632 from jl777/jl777

getendpoint tcp://
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
dbf8445a48
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      iguana/exchanges/LP_commands.c
  2. 4
      iguana/exchanges/LP_include.h
  3. 6
      iguana/exchanges/LP_nativeDEX.c
  4. 21
      iguana/exchanges/LP_network.c
  5. 2
      iguana/exchanges/coins
  6. 3
      iguana/exchanges/getendpoint
  7. 2
      iguana/exchanges/mshark
  8. 34
      iguana/exchanges/stats.c

22
iguana/exchanges/LP_commands.c

@ -166,6 +166,7 @@ instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\ instantdex_claim()\n\
timelock(coin, duration, destaddr=(tradeaddr), amount)\n\ timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
unlockedspend(coin, txid)\n\ unlockedspend(coin, txid)\n\
getendpoint()\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
\"}")); \"}"));
//sell(base, rel, price, basevolume, timeout=10, duration=3600)\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\"}")); 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,"tcp://*:7781") >= 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 ) else if ( strcmp(method,"instantdex_claim") == 0 )
{ {
if ( (ptr= LP_coinsearch("KMD")) != 0 ) if ( (ptr= LP_coinsearch("KMD")) != 0 )

4
iguana/exchanges/LP_include.h

@ -35,10 +35,12 @@ voind dontprintf(char *formatstr,...) {}
#define LP_MAJOR_VERSION "0" #define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1" #define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "27770" #define LP_BUILD_NUMBER "27771"
#define LP_BARTERDEX_VERSION 1 #define LP_BARTERDEX_VERSION 1
#define LP_MAGICBITS 1 #define LP_MAGICBITS 1
#define LP_IPC_ENDPOINT "tcp://127.0.0.1:7781"
#define LP_DONT_IMPORTPRIVKEY #define LP_DONT_IMPORTPRIVKEY
#ifdef FROM_JS #ifdef FROM_JS

6
iguana/exchanges/LP_nativeDEX.c

@ -101,7 +101,7 @@ struct LP_trade *LP_trades,*LP_tradesQ;
uint16_t LP_fixed_pairport;//,LP_publicport; uint16_t LP_fixed_pairport;//,LP_publicport;
uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; 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_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_cmdcount,LP_mypullsock = -1;
int32_t LP_numfinished,LP_showwif,IAMLP = 0; int32_t LP_numfinished,LP_showwif,IAMLP = 0;
double LP_profitratio = 1.; double LP_profitratio = 1.;
@ -334,7 +334,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
} }
else else
{ {
LP_queuecommand(0,jsonstr,pubsock,0); LP_queuecommand(0,jsonstr,pubsock,0,0);
//if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) //if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 )
//{ //{
//} //}
@ -417,7 +417,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
//printf("self broadcast.(%s)\n",Broadcaststr); //printf("self broadcast.(%s)\n",Broadcaststr);
str = Broadcaststr; str = Broadcaststr;
Broadcaststr = 0; Broadcaststr = 0;
LP_queuecommand(0,str,pubsock,0); LP_queuecommand(0,str,pubsock,0,0);
/*if ( (argjson= cJSON_Parse(str)) != 0 ) /*if ( (argjson= cJSON_Parse(str)) != 0 )
{ {
//portable_mutex_lock(&LP_commandmutex); //portable_mutex_lock(&LP_commandmutex);

21
iguana/exchanges/LP_network.c

@ -426,6 +426,7 @@ struct LP_queuedcommand
struct LP_queuedcommand *next,*prev; struct LP_queuedcommand *next,*prev;
char **retstrp; char **retstrp;
int32_t responsesock,msglen,stats_JSONonly; int32_t responsesock,msglen,stats_JSONonly;
uint32_t queueid;
char msg[]; char msg[];
} *LP_commandQ; } *LP_commandQ;
@ -446,8 +447,16 @@ void LP_commandQ_loop(void *ctx)
if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 ) if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 )
{ {
//printf("processed.(%s)\n",retstr); //printf("processed.(%s)\n",retstr);
if ( ptr->responsesock >= 0 && (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr)+1,0)) <= 0 ) if ( ptr->responsesock >= 0 )
printf("error sending result\n"); {
/*if ( ptr->queueid != 0 )
{
retjson = cJSON_CreateObject();
}*/
if ( (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr)+1,0)) <= 0 )
printf("error sending result\n");
}
if ( ptr->retstrp != 0 ) if ( ptr->retstrp != 0 )
(*ptr->retstrp) = retstr; (*ptr->retstrp) = retstr;
else free(retstr); else free(retstr);
@ -463,7 +472,7 @@ void LP_commandQ_loop(void *ctx)
} }
} }
void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly) void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly,uint32_t queueid)
{ {
struct LP_queuedcommand *ptr; int32_t msglen; struct LP_queuedcommand *ptr; int32_t msglen;
msglen = (int32_t)strlen(buf) + 1; msglen = (int32_t)strlen(buf) + 1;
@ -471,8 +480,10 @@ void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats
ptr = calloc(1,sizeof(*ptr) + msglen); ptr = calloc(1,sizeof(*ptr) + msglen);
if ( (ptr->retstrp= retstrp) != 0 ) if ( (ptr->retstrp= retstrp) != 0 )
*retstrp = 0; *retstrp = 0;
ptr->responsesock = responsesock;
ptr->msglen = msglen; ptr->msglen = msglen;
if ( (ptr->queueid= queueid) != 0 && responsesock < 0 )
ptr->responsesock = IPC_ENDPOINT;
else ptr->responsesock = responsesock;
ptr->stats_JSONonly = stats_JSONonly; ptr->stats_JSONonly = stats_JSONonly;
memcpy(ptr->msg,buf,msglen); memcpy(ptr->msg,buf,msglen);
DL_APPEND(LP_commandQ,ptr); DL_APPEND(LP_commandQ,ptr);
@ -562,7 +573,7 @@ void LP_psockloop(void *_ptr)
{ {
sendsock = ptr->sendsock; sendsock = ptr->sendsock;
break; break;
} else LP_queuecommand(0,(char *)buf,ptr->publicsock,0); } else LP_queuecommand(0,(char *)buf,ptr->publicsock,0,0);
} }
if ( buf != 0 ) if ( buf != 0 )
{ {

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

3
iguana/exchanges/getendpoint

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getendpoint\"}"

2
iguana/exchanges/mshark

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
source userpass source userpass
# this will only work for watchonly addresses that have been rescanned and with active coins # this will only work for watchonly addresses that have been rescanned and with active coins
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"fundvalue\",\"address\":\"RTu3JZZKLJTcfNwBa19dWRagEfQq49STqC\",\"holdings\":[{\"coin\":\"iota\",\"balance\":1500000}, {\"coin\":\"bitcoin-cash\",\"balance\":1200}, {\"coin\":\"bitcoin\",\"balance\":137}, {\"coin\":\"chips\",\"balance\":100000}],\"divisor\":1400000}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"fundvalue\",\"address\":\"RTu3JZZKLJTcfNwBa19dWRagEfQq49STqC\",\"holdings\":[{\"coin\":\"iota\",\"balance\":1500000}, {\"coin\":\"bitcoin-cash\",\"balance\":1200}, {\"coin\":\"bitcoin\",\"balance\":100}, {\"coin\":\"komodo\",\"balance\":100000}, {\"coin\":\"chips\",\"balance\":100000}],\"divisor\":1400000}"

34
iguana/exchanges/stats.c

@ -29,7 +29,7 @@
#define STATS_DEST "/var/www/html/DEXstats.json" #define STATS_DEST "/var/www/html/DEXstats.json"
#include "DEXstats.h" #include "DEXstats.h"
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port); char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly); void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly,uint32_t queueid);
extern uint32_t DOCKERFLAG; extern uint32_t DOCKERFLAG;
char *stats_validmethods[] = char *stats_validmethods[] =
@ -330,11 +330,12 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
} }
extern void *bitcoin_ctx(); 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) char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{ {
static void *ctx; static void *ctx;
cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; char symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr=0,*filestr,*token = 0; int32_t i,j,n,num=0; cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; char symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr=0,*filestr,*token = 0; int32_t i,j,n,num=0; uint32_t queueid;
if ( ctx == 0 ) if ( ctx == 0 )
ctx = bitcoin_ctx(); ctx = bitcoin_ctx();
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++) for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
@ -556,7 +557,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
} }
else else
{ {
cJSON *arg; //char *buf; cJSON *arg; char *buf;
if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 ) if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 )
{ {
arg = jobj(argjson,"params"); arg = jobj(argjson,"params");
@ -569,20 +570,23 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
#ifdef FROM_MARKETMAKER #ifdef FROM_MARKETMAKER
if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 ) if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 )
{ {
//buf = jprint(arg,0); if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
//LP_queuecommand(&retstr,buf,-1,1); {
//free(buf); buf = jprint(arg,0);
//while ( retstr == 0 ) LP_queuecommand(&retstr,buf,-1,1,queueid);
// usleep(10000); free(buf);
retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); 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 retstr = clonestr("{\"error\":\"invalid remote method\"}");
#else #else
//buf = jprint(arg,0); if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
//LP_queuecommand(&retstr,buf,-1,1); {
//free(buf); if ( jobj(arg,"id") == 0 )
//while ( retstr == 0 ) jaddnum(arg,"id",rand());
// usleep(10000); buf = jprint(arg,0);
retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); LP_queuecommand(&retstr,buf,-1,1,queueid);
free(buf);
} else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port);
#endif #endif
} }
free_json(argjson); free_json(argjson);

Loading…
Cancel
Save