Browse Source

Merge pull request #421 from jl777/spvdex

Spvdex
etomic
jl777 7 years ago
committed by GitHub
parent
commit
ece180a00c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      iguana/exchanges/LP_coins.c
  2. 2
      iguana/exchanges/LP_commands.c
  3. 5
      iguana/exchanges/LP_include.h
  4. 36
      iguana/exchanges/LP_nativeDEX.c
  5. 30
      iguana/exchanges/LP_network.c
  6. 22
      iguana/exchanges/LP_peers.c
  7. 9
      iguana/exchanges/LP_portfolio.c
  8. 9
      iguana/exchanges/LP_signatures.c
  9. 25
      iguana/exchanges/LP_socket.c
  10. 2
      iguana/exchanges/LP_swap.c
  11. 41
      iguana/exchanges/LP_tradebots.c
  12. 39
      iguana/exchanges/LP_utxo.c
  13. 21
      iguana/exchanges/LP_utxos.c
  14. 1
      iguana/exchanges/mm.c

4
iguana/exchanges/LP_coins.c

@ -389,9 +389,9 @@ struct iguana_info *LP_coinfind(char *symbol)
if ( (coin= LP_coinadd(&cdata)) != 0 )
{
coin->inactive = isinactive * (uint32_t)time(NULL);
if ( strcmp(symbol,"KMD") == 0 )
/*if ( strcmp(symbol,"KMD") == 0 )
coin->inactive = 0;
else if ( strcmp(symbol,"BTC") == 0 )
else*/ if ( strcmp(symbol,"BTC") == 0 )
{
coin->inactive = (uint32_t)time(NULL) * !IAMLP;
printf("BTC inactive.%u\n",coin->inactive);

2
iguana/exchanges/LP_commands.c

@ -337,6 +337,8 @@ bot_resume(botid)\n\
{
ptr->inactive = 0;
cJSON *array = cJSON_CreateArray();
if ( ptr->smartaddr[0] != 0 )
LP_unspents_load(coin,ptr->smartaddr);
jaddi(array,LP_coinjson(ptr,0));
return(jprint(array,1));
} else return(clonestr("{\"error\":\"coin port conflicts with existing coin\"}"));

5
iguana/exchanges/LP_include.h

@ -247,7 +247,7 @@ struct iguana_info
portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
uint32_t lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint32_t importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio
@ -379,7 +379,8 @@ int64_t LP_komodo_interest(bits256 txid,int64_t value);
void LP_availableset(struct LP_utxoinfo *utxo);
int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2);
int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock);
uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int32_t ispaired);
void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);

36
iguana/exchanges/LP_nativeDEX.c

@ -19,6 +19,7 @@
// marketmaker
//
// electrum keepalive
// merge bots + portfoliot
// verify portfolio, interest to KMD withdraw
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
// bigendian architectures need to use little endian for sighash calcs
@ -675,21 +676,30 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
{
int32_t i,n; cJSON *item;
int32_t i,n; cJSON *item; char *symbol; struct iguana_info *coin;
for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++)
{
printf("%s ",activecoins[i]);
LP_coinfind(activecoins[i]);
LP_priceinfoadd(activecoins[i]);
if ( (coin= LP_coinfind(activecoins[i])) != 0 && LP_getheight(coin) <= 0 )
coin->inactive = (uint32_t)time(NULL);
LP_unspents_load(coin->symbol,coin->smartaddr);
}
if ( (n= cJSON_GetArraySize(coins)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(coins,i);
printf("%s ",jstr(item,"coin"));
LP_coincreate(item);
LP_priceinfoadd(jstr(item,"coin"));
if ( (symbol= jstr(item,"coin")) != 0 )
{
printf("%s ",jstr(item,"coin"));
LP_coincreate(item);
LP_priceinfoadd(jstr(item,"coin"));
if ( (coin= LP_coinfind(symbol)) != 0 && LP_getheight(coin) <= 0 )
coin->inactive = (uint32_t)time(NULL);
LP_unspents_load(coin->symbol,coin->smartaddr);
}
}
}
printf("privkey updates\n");
@ -825,7 +835,7 @@ int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg)
void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson)
{
char *myipaddr=0; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],bindaddr2[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx();
char *myipaddr=0; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx();
LP_showwif = juint(argjson,"wif");
if ( passphrase == 0 || passphrase[0] == 0 )
{
@ -910,15 +920,15 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
pubsock = -1;
nanomsg_transportname(0,subaddr,myipaddr,mypubport);
nanomsg_transportname(1,bindaddr,myipaddr,mypubport);
nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport);
//nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport);
valid = 0;
if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 )
{
valid = 0;
if ( nn_bind(pubsock,bindaddr) >= 0 )
valid++;
if ( nn_bind(pubsock,bindaddr2) >= 0 )
valid++;
//if ( nn_bind(pubsock,bindaddr2) >= 0 )
// valid++;
if ( valid > 0 )
{
timeout = 1;
@ -931,7 +941,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
nn_close(pubsock), pubsock = -1;
}
} else printf("error getting pubsock %d\n",pubsock);
printf(">>>>>>>>> myipaddr.(%s %s) (%s) pullsock.%d valid.%d\n",bindaddr,bindaddr2,subaddr,pubsock,valid);
printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d\n",bindaddr,subaddr,pubsock,valid);
LP_mypubsock = pubsock;
}
printf("got %s, initpeers\n",myipaddr);
@ -993,7 +1003,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching queue_loop for port.%u\n",myport);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)myipaddr) != 0 )
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 )
{
printf("error launching prices_loop for port.%u\n",myport);
exit(-1);
@ -1028,11 +1038,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_swapsloop for port.%u\n",myport);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_tradebot_timeslices,ctx) != 0 )
{
printf("error launching LP_tradebot_timeslices\n");
exit(-1);
}
int32_t nonz;
while ( 1 )
{
@ -1116,7 +1121,6 @@ void LP_fromjs_iter()
{
LP_notify_pubkeys(ctx,LP_mypubsock);
LP_privkey_updates(ctx,LP_mypubsock,0);
prices_loop(0);
if ( (retstr= basilisk_swapentry(0,0)) != 0 )
free(retstr);
}

30
iguana/exchanges/LP_network.c

@ -98,17 +98,17 @@ int32_t nn_poll(struct nn_pollfd *fds, int nfds, int timeout)
char *nanomsg_transportname(int32_t bindflag,char *str,char *ipaddr,uint16_t port)
{
sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port);
sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port);
return(str);
}
char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t port)
/*char *nanomsg_transportname2(int32_t bindflag,char *str,char *ipaddr,uint16_t port)
{
sprintf(str,"tcp://%s:%u",bindflag == 0 ? ipaddr : "*",port+10);
sprintf(str,"ws://%s:%u",bindflag == 0 ? ipaddr : "*",port+10);
return(str);
}
/*int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag)
int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag)
{
int32_t sentbytes;
if ( sock < 0 )
@ -735,7 +735,7 @@ char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired)
return(retstr);
}
uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int32_t ispaired)
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired)
{
uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
@ -750,8 +750,8 @@ uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int3
safecopy(publicaddr,addr,128);
if ( (addr= jstr(retjson,"connectaddr")) != 0 )
safecopy(connectaddr,addr,128);
if ( (addr= jstr(retjson,"connectaddr2")) != 0 )
safecopy(connectaddr2,addr,128);
//if ( (addr= jstr(retjson,"connectaddr2")) != 0 )
// safecopy(connectaddr2,addr,128);
if ( publicaddr[0] != 0 && connectaddr[0] != 0 )
publicport = juint(retjson,"publicport");
free_json(retjson);
@ -767,9 +767,9 @@ uint16_t LP_psock_get(char *connectaddr,char *connectaddr2,char *publicaddr,int3
int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired)
{
int32_t nntype,pullsock,timeout; char bindaddr[128],bindaddr2[128],connectaddr[128],connectaddr2[128];
int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128];
*mypullportp = mypullport;
connectaddr2[0] = 0;
//connectaddr2[0] = 0;
if ( ispaired == 0 )
{
if ( LP_canbind != 0 )
@ -780,7 +780,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
{
nanomsg_transportname(0,publicaddr,myipaddr,mypullport);
nanomsg_transportname(1,bindaddr,myipaddr,mypullport);
nanomsg_transportname2(1,bindaddr2,myipaddr,mypullport);
//nanomsg_transportname2(1,bindaddr2,myipaddr,mypullport);
}
else
{
@ -792,7 +792,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
}
while ( *mypullportp == 0 )
{
if ( (*mypullportp= LP_psock_get(connectaddr,connectaddr2,publicaddr,ispaired)) != 0 )
if ( (*mypullportp= LP_psock_get(connectaddr,publicaddr,ispaired)) != 0 )
break;
sleep(10);
printf("try to get publicaddr again\n");
@ -811,8 +811,8 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
}
else
{
if ( connectaddr2[0] != 0 && nn_connect(pullsock,connectaddr2) > 0 )
printf("%s ",connectaddr2);
//if ( connectaddr2[0] != 0 && nn_connect(pullsock,connectaddr2) > 0 )
// printf("%s ",connectaddr2);
printf("nntype.%d NN_PAIR.%d connect to %s connectsock.%d\n",nntype,NN_PAIR,connectaddr,pullsock);
}
}
@ -823,8 +823,8 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
printf("bind to %s error for %s: %s\n",bindaddr,publicaddr,nn_strerror(nn_errno()));
exit(-1);
}
if ( nn_bind(pullsock,bindaddr2) >= 0 )
printf("bound to %s\n",bindaddr2);
//if ( nn_bind(pullsock,bindaddr2) >= 0 )
// printf("bound to %s\n",bindaddr2);
}
timeout = 1;
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));

22
iguana/exchanges/LP_peers.c

@ -56,7 +56,7 @@ char *LP_peers()
struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t numpeers,int32_t numutxos,uint32_t sessionid)
{
uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],subaddr2[64],pushaddr[64],pushaddr2[64],subaddr[64]; struct LP_peerinfo *peer = 0;
uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0;
printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport);
#ifdef LP_STRICTPEERS
if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 )
@ -90,19 +90,19 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 )
{
nanomsg_transportname(0,pushaddr,peer->ipaddr,pushport);
nanomsg_transportname2(0,pushaddr2,peer->ipaddr,pushport);
//nanomsg_transportname2(0,pushaddr2,peer->ipaddr,pushport);
valid = 0;
if ( nn_connect(pushsock,pushaddr) >= 0 )
valid++;
if ( nn_connect(pushsock,pushaddr2) >= 0 )
valid++;
//if ( nn_connect(pushsock,pushaddr2) >= 0 )
// valid++;
if ( valid > 0 )
{
timeout = 1;
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
//maxsize = 2 * 1024 * 1024;
//nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDBUF,&maxsize,sizeof(maxsize));
printf("connected to push.(%s %s) pushsock.%d valid.%d\n",pushaddr,pushaddr2,pushsock,valid);
printf("connected to push.(%s) pushsock.%d valid.%d\n",pushaddr,pushsock,valid);
peer->connected = (uint32_t)time(NULL);
peer->pushsock = pushsock;
if ( (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 )
@ -111,20 +111,20 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0);
nanomsg_transportname(0,subaddr,peer->ipaddr,subport);
nanomsg_transportname2(0,subaddr2,peer->ipaddr,subport);
//nanomsg_transportname2(0,subaddr2,peer->ipaddr,subport);
valid = 0;
if ( nn_connect(subsock,subaddr) >= 0 )
valid++;
if ( nn_connect(subsock,subaddr2) >= 0 )
valid++;
//if ( nn_connect(subsock,subaddr2) >= 0 )
// valid++;
if ( valid > 0 )
{
peer->subsock = subsock;
printf("connected to sub.(%s %s) subsock.%d valid.%d\n",subaddr,subaddr2,peer->subsock,valid);
printf("connected to sub.(%s) subsock.%d valid.%d\n",subaddr,peer->subsock,valid);
}
else
{
printf("error connecting to subsock.%d (%s %s)\n",subsock,subaddr,subaddr2);
printf("error connecting to subsock.%d (%s)\n",subsock,subaddr);
nn_close(subsock);
subsock = -1;
}
@ -134,7 +134,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
{
nn_close(pushsock);
pushsock = -1;
printf("error connecting to push.(%s %s)\n",pushaddr,pushaddr2);
printf("error connecting to push.(%s)\n",pushaddr);
}
} else printf("%s pushport.%u subport.%u pushsock.%d\n",ipaddr,pushport,subport,pushsock);
if ( peer->pushsock >= 0 && peer->subsock >= 0 )

9
iguana/exchanges/LP_portfolio.c

@ -586,15 +586,14 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a
return(n);
}
void prices_loop(void *arg)
void prices_loop(void *ctx)
{
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_ctx();
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp;
while ( 1 )
{
LP_tradebots_timeslice(ctx);
if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
{
if ( arg == 0 )
return;
sleep(60);
continue;
}
@ -628,8 +627,6 @@ void prices_loop(void *arg)
}
free(retstr);
}
if ( arg == 0 )
return;
sleep(60);
}
}

9
iguana/exchanges/LP_signatures.c

@ -528,21 +528,20 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item)
{
if ( memcmp(rmd160,pubp->rmd160,20) != 0 )
{
for (i=0; i<20; i++)
printf("%02x",pubp->rmd160[i]);
//for (i=0; i<20; i++)
// printf("%02x",pubp->rmd160[i]);
memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160));
memcpy(pubp->pubsecp,pubsecp,sizeof(pubp->pubsecp));
memcpy(pubp->sig,sig,sizeof(pubp->sig));
pubp->siglen = siglen;
char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr);
//pubp->timestamp = (uint32_t)time(NULL);
//char str[65]; printf(" -> rmd160.(%s) for %s (%s) sig.%s\n",hexstr,bits256_str(str,pubp->pubkey),pubsecpstr,sigstr);
}
pubp->timestamp = juint(item,"timestamp");
retval = 0;
} else pubp->numerrors++;
}
}
else
else if ( 0 )
{
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);

25
iguana/exchanges/LP_socket.c

@ -410,8 +410,8 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
}
} else printf("couldnt find electrum server for (%s %s) or no retjsonp.%p\n",method,params,retjsonp);
ep = ep->prev;
if ( ep != 0 )
printf("using prev ep.%s\n",ep->symbol);
//if ( ep != 0 )
// printf("using prev ep.%s\n",ep->symbol);
}
return(0);
}
@ -543,7 +543,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON *
cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,int32_t electrumflag)
{
cJSON *retjson=0; struct LP_address *ap; struct iguana_info *coin; int32_t height,usecache=1;
cJSON *retjson=0; char *retstr; struct LP_address *ap; struct iguana_info *coin; int32_t updatedflag,height,usecache=1;
if ( (coin= LP_coinfind(symbol)) == 0 )
return(0);
if ( ep == 0 || ep->heightp == 0 )
@ -563,9 +563,16 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON
{
if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 )
{
printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0)));
//printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0)));
updatedflag = 0;
if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 )
LP_postutxos(coin->symbol,addr);
LP_postutxos(coin->symbol,addr), updatedflag = 1;
if ( strcmp(addr,coin->smartaddr) == 0 )
{
retstr = jprint(retjson,0);
LP_unspents_cache(coin->symbol,coin->smartaddr,retstr,updatedflag);
free(retstr);
}
if ( ap != 0 )
{
ap->unspenttime = (uint32_t)time(NULL);
@ -971,7 +978,13 @@ 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 = cJSON_CreateObject();
struct electrum_info *ep; int32_t already; cJSON *retjson;
if ( ipaddr == 0 || ipaddr[0] == 0 || port == 0 )
{
coin->electrum = 0;
return(cJSON_Parse("{\"result\":\"success\",\"status\":\"electrum mode disabled, now in native coin mode\"}"));
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"ipaddr",ipaddr);
jaddnum(retjson,"port",port);
if ( (ep= LP_electrum_info(&already,coin->symbol,ipaddr,port,IGUANA_MAXPACKETSIZE * 10)) == 0 )

2
iguana/exchanges/LP_swap.c

@ -262,7 +262,7 @@ int32_t LP_choosei_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
int32_t LP_choosei_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
int32_t otherchoosei=-1,i,len = 0; uint8_t pubkey33[33]; char str[65],str2[65];
int32_t otherchoosei=-1,i,len = 0; uint8_t pubkey33[33];
if ( datalen == sizeof(otherchoosei)+sizeof(bits256)*2 )
{
len += iguana_rwnum(0,data,sizeof(otherchoosei),&otherchoosei);

41
iguana/exchanges/LP_tradebots.c

@ -320,39 +320,36 @@ void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid)
}
}
void LP_tradebot_timeslices(void *ctx)
void LP_tradebots_timeslice(void *ctx)
{
struct LP_tradebot_trade *tp; struct iguana_info *relcoin; struct LP_tradebot *bot,*tmp; int32_t i,lastnumfinished = 0;
while ( 1 )
static uint32_t lastnumfinished = 0;
struct LP_tradebot_trade *tp; struct iguana_info *relcoin; struct LP_tradebot *bot,*tmp; int32_t i;
DL_FOREACH_SAFE(LP_tradebots,bot,tmp)
{
DL_FOREACH_SAFE(LP_tradebots,bot,tmp)
if ( (relcoin= LP_coinfind(bot->rel)) != 0 )
LP_listunspent_issue(bot->rel,relcoin->smartaddr,1);
if ( bot->numpending > 0 && LP_numfinished > lastnumfinished )
{
if ( (relcoin= LP_coinfind(bot->rel)) != 0 )
LP_listunspent_issue(bot->rel,relcoin->smartaddr,1);
if ( bot->numpending > 0 && LP_numfinished > lastnumfinished )
// expire pending trades and see if any still need their requestid/quoteid
for (i=0; i<bot->numtrades; i++)
{
// expire pending trades and see if any still need their requestid/quoteid
for (i=0; i<bot->numtrades; i++)
if ( (tp= bot->trades[i]) != 0 && tp->finished == 0 )
{
if ( (tp= bot->trades[i]) != 0 && tp->finished == 0 )
if ( time(NULL) > tp->started+INSTANTDEX_LOCKTIME*2 )
{
if ( time(NULL) > tp->started+INSTANTDEX_LOCKTIME*2 )
{
bot->pendbasesum -= tp->basevol;
bot->pendrelsum -= tp->relvol;
bot->numpending--;
tp->finished = (uint32_t)time(NULL);
printf("%s trade.%d of %d expired\n",bot->name,i,bot->numtrades);
}
bot->pendbasesum -= tp->basevol;
bot->pendrelsum -= tp->relvol;
bot->numpending--;
tp->finished = (uint32_t)time(NULL);
printf("%s trade.%d of %d expired\n",bot->name,i,bot->numtrades);
}
}
}
else if ( bot->numpending == 0 )
LP_tradebot_timeslice(ctx,bot);
}
lastnumfinished = LP_numfinished;
sleep(60);
else if ( bot->numpending == 0 )
LP_tradebot_timeslice(ctx,bot);
}
lastnumfinished = LP_numfinished;
}
char *LP_tradebot_list(void *ctx,int32_t pubsock,cJSON *argjson)

39
iguana/exchanges/LP_utxo.c

@ -981,3 +981,42 @@ int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight)
}
return(num);
}
void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag)
{
char fname[1024]; FILE *fp=0;
sprintf(fname,"%s/UNSPENTS/%s_%s",GLOBAL_DBDIR,symbol,addr), OS_portable_path(fname);
if ( updatedflag == 0 && (fp= fopen(fname,"rb")) == 0 )
updatedflag = 1;
else if ( fp != 0 )
fclose(fp);
if ( updatedflag != 0 && (fp= fopen(fname,"wb")) != 0 )
{
fwrite(arraystr,1,strlen(arraystr),fp);
fclose(fp);
}
}
void LP_unspents_load(char *symbol,char *addr)
{
char fname[1024],*arraystr; long fsize; struct iguana_info *coin; cJSON *retjson;
if ( (coin= LP_coinfind(symbol)) != 0 )
{
sprintf(fname,"%s/UNSPENTS/%s_%s",GLOBAL_DBDIR,symbol,addr), OS_portable_path(fname);
if ( (arraystr= OS_filestr(&fsize,fname)) != 0 )
{
if ( (retjson= cJSON_Parse(arraystr)) != 0 )
{
printf("PROCESS UNSPENTS %s\n",arraystr);
if ( electrum_process_array(coin,coin->electrum,coin->smartaddr,retjson,1) == 0 )
printf("error electrum_process_array\n");
else printf("processed %s\n",arraystr);
free_json(retjson);
}
free(arraystr);
}
}
}

21
iguana/exchanges/LP_utxos.c

@ -733,18 +733,19 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
userpub = curve25519(userpass,curve25519_basepoint9());
printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub));
}
if ( coin->electrum == 0 && coin->userpass[0] != 0 )
}
if ( coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(coin) > 0 )
{
LP_listunspent_issue(coin->symbol,coin->smartaddr,0);
if ( (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 )
{
LP_listunspent_issue(coin->symbol,coin->smartaddr,0);
if ( (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 )
if ( jobj(retjson,"error") != 0 )
{
if ( jobj(retjson,"error") != 0 )
{
printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1));
exit(-1);
}
} else free_json(retjson);
}
printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1));
exit(-1);
}
} else free_json(retjson);
coin->importedprivkey = (uint32_t)time(NULL);
}
vcalc_sha256(0,checkkey.bytes,privkey.bytes,sizeof(privkey));
checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64;

1
iguana/exchanges/mm.c

@ -882,6 +882,7 @@ int main(int argc, const char * argv[])
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/UNSPENTS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
#ifdef FROM_JS
argc = 2;
retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}");

Loading…
Cancel
Save