Browse Source

Test

etomic
jl777 8 years ago
parent
commit
eac7e9ea81
  1. 16
      iguana/exchanges/LP_forwarding.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 27
      iguana/exchanges/LP_nativeDEX.c

16
iguana/exchanges/LP_forwarding.c

@ -113,10 +113,22 @@ void LP_forwarding_register(bits256 pubkey,char *pushaddr,int32_t max)
char *LP_forwardhex(bits256 pubkey,char *hexstr)
{
struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; cJSON *retjson;
struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *retstr=0; cJSON *retjson,*argjson;
if ( hexstr == 0 || hexstr[0] == 0 )
return(clonestr("{\"error\":\"nohex\"}"));
if ( (ptr= LP_forwardfind(pubkey)) != 0 )
if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,LP_mypubkey) == 0 )
{
datalen = (int32_t)strlen(hexstr) >> 1;
data = malloc(datalen);
decode_hex(data,datalen,hexstr);
if ( (argjson= cJSON_Parse((char *)data)) != 0 )
{
retstr = LP_command_process(LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,argjson,0,0,LP_profitratio - 1.);
free_json(argjson);
}
return(retstr);
}
else if ( (ptr= LP_forwardfind(pubkey)) != 0 )
{
if ( ptr->pushsock >= 0 )
{

1
iguana/exchanges/LP_include.h

@ -225,6 +225,7 @@ int32_t LP_forward(bits256 pubkey,char *jsonstr,int32_t freeflag);
int32_t LP_ismine(struct LP_utxoinfo *utxo);
int32_t LP_isavailable(struct LP_utxoinfo *utxo);
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port);
char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin);
#endif

27
iguana/exchanges/LP_nativeDEX.c

@ -79,6 +79,21 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_forwarding.c"
#include "LP_commands.c"
char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin)
{
char *retstr=0;
if ( LP_tradecommand(myipaddr,pubsock,argjson,data,datalen,profitmargin) <= 0 )
{
if ( (retstr= stats_JSON(argjson,"127.0.0.1",0)) != 0 )
{
printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr);
if ( pubsock >= 0 )
LP_send(pubsock,retstr,1);
}
}
return(retstr);
}
int32_t LP_pullsock_check(char *myipaddr,int32_t pubsock,int32_t pullsock,double profitmargin)
{
int32_t recvsize,len,datalen=0,nonz = 0; void *ptr; char *retstr,*jsonstr=0; cJSON *argjson,*reqjson;
@ -110,16 +125,8 @@ int32_t LP_pullsock_check(char *myipaddr,int32_t pubsock,int32_t pullsock,double
if ( pubsock >= 0 && (reqjson= LP_dereference(argjson,"publish")) != 0 )
LP_send(pubsock,jprint(reqjson,1),1);
}
else if ( LP_tradecommand(myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvsize - len,profitmargin) <= 0 )
{
if ( (retstr= stats_JSON(argjson,"127.0.0.1",0)) != 0 )
{
printf("%s PULL.[%d] %s -> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",recvsize,jsonstr,retstr);
if ( pubsock >= 0 )
LP_send(pubsock,retstr,1);
else free(retstr);
}
}
else if ( (retstr= LP_command_process(myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvsize - len,profitmargin)) != 0 )
free(retstr);
portable_mutex_unlock(&LP_commandmutex);
free_json(argjson);
} else printf("error parsing(%s)\n",jsonstr);

Loading…
Cancel
Save