Browse Source

Merge branch 'dev' of https://github.com/jl777/SuperNET into dev-decker-dev

etomic
DeckerSU 7 years ago
parent
commit
83712ae52a
  1. 4
      iguana/exchanges/LP_coins.c
  2. 2
      iguana/exchanges/LP_commands.c
  3. 9
      iguana/exchanges/LP_nativeDEX.c
  4. 2
      iguana/exchanges/LP_rpc.c
  5. 42
      iguana/exchanges/LP_socket.c
  6. 8
      iguana/exchanges/LP_tradebots.c

4
iguana/exchanges/LP_coins.c

@ -201,7 +201,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
if ( coin->userpass[0] != 0 )
{
jaddnum(item,"height",LP_getheight(coin));
balance = LP_RTsmartbalance(coin);
if ( coin->electrum != 0 )
balance = LP_unspents_load(coin->symbol,coin->smartaddr);
else balance = LP_RTsmartbalance(coin);
jaddnum(item,"balance",dstr(balance));
jaddnum(item,"KMDvalue",dstr(LP_KMDvalue(coin,balance)));
}

2
iguana/exchanges/LP_commands.c

@ -99,7 +99,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r
available localhost RPC commands: \n \
pricearray(base, rel, starttime=0, endtime=-1, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\
setprice(base, rel, price)\n\
autoprice(base, rel, minprice, margin, refbase, refrel, factor, offset)*\n\
autoprice(base, rel, fixed, minprice, margin, refbase, refrel, factor, offset)*\n\
goal(coin=*, val=<autocalc>)\n\
myprice(base, rel)\n\
enable(coin)\n\

9
iguana/exchanges/LP_nativeDEX.c

@ -18,6 +18,7 @@
// LP_nativeDEX.c
// marketmaker
//
// bot status 1600% ?
// BCH signing
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
// bigendian architectures need to use little endian for sighash calcs
@ -1201,6 +1202,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("RPC port got stuck, close bindsocket\n");
LP_bindsock = -1;
closesocket(sock);
LP_bindsock_reset++;
sleep(10);
printf("launch new rpcloop\n");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
}
}
}

2
iguana/exchanges/LP_rpc.c

@ -1040,7 +1040,7 @@ bits256 LP_getbestblockhash(struct iguana_info *coin)
decode_hex(blockhash.bytes,sizeof(blockhash),retstr);
free(retstr);
}
}
} else printf("electrum mode doesnt support block level scanning\n");
return(blockhash);
}

42
iguana/exchanges/LP_socket.c

@ -124,9 +124,9 @@ int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port)
#endif
if ( bindflag == 0 )
{
printf("call connect sock.%d\n",sock);
//printf("call connect sock.%d\n",sock);
result = connect(sock,(struct sockaddr *)&saddr,addrlen);
printf("called connect result.%d\n",result);
//printf("called connect result.%d\n",result);
timeout.tv_sec = 2;
timeout.tv_usec = 0;
setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(void *)&timeout,sizeof(timeout));
@ -389,6 +389,25 @@ void electrum_initial_requests(struct electrum_info *ep)
electrum_sitem(ep,stratumreq,3,&retjson);
}
int32_t electrum_kickstart(struct electrum_info *ep)
{
closesocket(ep->sock), ep->sock = -1;
sleep(1);
if ( (ep->sock= LP_socket(0,ep->ipaddr,ep->port)) < 0 )
{
printf("error RE-connecting to %s:%u\n",ep->ipaddr,ep->port);
return(-1);
}
else
{
ep->stratumid = 0;
electrum_initial_requests(ep);
printf("RECONNECT ep.%p %s numerrors.%d too big -> new %s:%u sock.%d\n",ep,ep->symbol,ep->numerrors,ep->ipaddr,ep->port,ep->sock);
ep->numerrors = 0;
}
return(0);
}
cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout)
{
// queue id and string and callback
@ -417,20 +436,9 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
if ( *retjsonp == 0 || jobj(*retjsonp,"error") != 0 )
{
if ( ++ep->numerrors >= LP_ELECTRUM_MAXERRORS )
{
closesocket(ep->sock), ep->sock = -1;
if ( (ep->sock= LP_socket(0,ep->ipaddr,ep->port)) < 0 )
printf("error RE-connecting to %s:%u\n",ep->ipaddr,ep->port);
else
{
ep->stratumid = 0;
electrum_initial_requests(ep);
printf("ep.%p %s numerrors.%d too big -> new %s:%u sock.%d\n",ep,ep->symbol,ep->numerrors,ep->ipaddr,ep->port,ep->sock);
ep->numerrors = 0;
}
}
electrum_kickstart(ep);
} else if ( ep->numerrors > 0 )
ep->numerrors++;
ep->numerrors--;
if ( ep->prev == 0 )
{
if ( *retjsonp == 0 )
@ -1038,7 +1046,7 @@ void LP_dedicatedloop(void *arg)
cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port)
{
struct electrum_info *ep; int32_t already; cJSON *retjson;
struct electrum_info *ep; int32_t kickval,already; cJSON *retjson;
if ( ipaddr == 0 || ipaddr[0] == 0 || port == 0 )
{
//coin->electrum = 0;
@ -1070,8 +1078,10 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port)
}
else
{
kickval = electrum_kickstart(ep);
jaddstr(retjson,"result","success");
jaddstr(retjson,"status","already there");
jaddstr(retjson,"restart",kickval);
}
//printf("(%s)\n",jprint(retjson,0));
return(retjson);

8
iguana/exchanges/LP_tradebots.c

@ -438,14 +438,18 @@ char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,doubl
if ( dstr(abalance) < relvolume + dstr(txfees) )
{
retjson = cJSON_CreateObject();
if ( relcoin->electrum != 0 )
balance = LP_unspents_load(relcoin->symbol,relcoin->smartaddr);
else balance = LP_RTsmartbalance(relcoin);
jaddstr(retjson,"error","not enough funds");
jaddstr(retjson,"coin",rel);
jaddnum(retjson,"balance",dstr(abalance));
jaddnum(retjson,"abalance",dstr(abalance));
jaddnum(retjson,"balance",dstr(balance));
jaddnum(retjson,"relvolume",relvolume);
jaddnum(retjson,"txfees",dstr(txfees));
shortfall = (relvolume + dstr(txfees)) - dstr(balance);
jaddnum(retjson,"shortfall",shortfall);
if ( (balance= LP_RTsmartbalance(relcoin)) > abalance+SATOSHIDEN*(shortfall+relvolume/77.) )
if ( balance > (relvolume + 10*relvolume/777.) )
{
char *withdrawstr; cJSON *outputjson,*withdrawjson,*outputs,*item;
outputjson = cJSON_CreateObject();

Loading…
Cancel
Save