Browse Source

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

etomic
DeckerSU 7 years ago
parent
commit
1c5a2cc286
  1. 8
      crypto777/OS_portable.h
  2. 4
      crypto777/bitcoind_RPC.c
  3. 2
      crypto777/iguana_utils.c
  4. 12
      iguana/exchanges/LP_bitcoin.c
  5. 62
      iguana/exchanges/LP_coins.c
  6. 56
      iguana/exchanges/LP_commands.c
  7. 12
      iguana/exchanges/LP_include.h
  8. 168
      iguana/exchanges/LP_nativeDEX.c
  9. 80
      iguana/exchanges/LP_network.c
  10. 6
      iguana/exchanges/LP_peers.c
  11. 11
      iguana/exchanges/LP_portfolio.c
  12. 22
      iguana/exchanges/LP_prices.c
  13. 10
      iguana/exchanges/LP_remember.c
  14. 54
      iguana/exchanges/LP_rpc.c
  15. 11
      iguana/exchanges/LP_signatures.c
  16. 66
      iguana/exchanges/LP_socket.c
  17. 12
      iguana/exchanges/LP_tradebots.c
  18. 46
      iguana/exchanges/LP_transaction.c
  19. 53
      iguana/exchanges/LP_utxo.c
  20. 1
      iguana/exchanges/LP_utxos.c
  21. 3
      iguana/exchanges/bot_statuslist
  22. 2
      iguana/exchanges/coins
  23. 6
      iguana/exchanges/coins.json
  24. 2
      iguana/exchanges/install
  25. 3
      iguana/exchanges/millis
  26. 2
      iguana/exchanges/mm.c
  27. 12
      iguana/exchanges/mnzservers
  28. 3
      iguana/exchanges/processfiles
  29. 89
      iguana/exchanges/stats.c

8
crypto777/OS_portable.h

@ -143,6 +143,14 @@ typedef struct queue
char name[64],initflag;
} queue_t;
struct rpcrequest_info
{
struct rpcrequest_info *next,*prev;
pthread_t T;
int32_t sock;
uint32_t ipbits;
};
struct OS_mappedptr
{
char fname[512];

4
crypto777/bitcoind_RPC.c

@ -55,7 +55,9 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *
long i,j,len;
char *retstr = 0;
cJSON *json,*result,*error;
usleep(2500);
#ifdef FROM_MARKETMAKER
usleep(5000);
#endif
//printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr);
if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 )
{

2
crypto777/iguana_utils.c

@ -303,7 +303,7 @@ struct iguana_thread *iguana_launch(struct iguana_info *coin,char *name,iguana_f
coin->Launched[t->type]++;
retval = OS_thread_create(&t->handle,NULL,(void *)iguana_launcher,(void *)t);
if ( retval != 0 )
printf("error launching %s\n",t->name);
printf("error launching %s retval.%d errno.%d\n",t->name,retval,errno);
while ( (t= queue_dequeue(&TerminateQ)) != 0 )
{
if ( (rand() % 100000) == 0 && coin != 0 )

12
iguana/exchanges/LP_bitcoin.c

@ -1959,6 +1959,18 @@ int32_t bitcoin_timelockspend(uint8_t *script,int32_t n,uint8_t rmd160[20],uint3
return(n);
}
int32_t bitcoin_performancebond(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,uint32_t unlocktimestamp,uint8_t cltv_rmd160[20],uint8_t anytime_rmd160[20])
{
script[n++] = SCRIPT_OP_IF;
n = bitcoin_checklocktimeverify(script,n,unlocktimestamp);
n = bitcoin_standardspend(script,n,cltv_rmd160);
script[n++] = SCRIPT_OP_ELSE;
n = bitcoin_standardspend(script,n,anytime_rmd160);
script[n++] = SCRIPT_OP_ENDIF;
calc_rmd160_sha256(p2sh_rmd160,script,n);
return(n);
}
int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp)
{
int32_t i,plen;

62
iguana/exchanges/LP_coins.c

@ -23,9 +23,12 @@ char *portstrs[][3] = { { "BTC", "8332" }, { "KMD", "7771" } };
uint16_t LP_rpcport(char *symbol)
{
int32_t i;
for (i=0; i<sizeof(portstrs)/sizeof(*portstrs); i++)
if ( strcmp(portstrs[i][0],symbol) == 0 )
return(atoi(portstrs[i][1]));
if ( symbol != 0 && symbol[0] != 0 )
{
for (i=0; i<sizeof(portstrs)/sizeof(*portstrs); i++)
if ( strcmp(portstrs[i][0],symbol) == 0 )
return(atoi(portstrs[i][1]));
}
return(0);
}
@ -231,12 +234,15 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
struct iguana_info *LP_conflicts_find(struct iguana_info *refcoin)
{
struct iguana_info *coin=0,*tmp;
HASH_ITER(hh,LP_coins,coin,tmp)
if ( refcoin != 0 )
{
if ( coin->inactive != 0 || coin->electrum != 0 || coin == refcoin )
continue;
if ( strcmp(coin->serverport,refcoin->serverport) == 0 )
break;
HASH_ITER(hh,LP_coins,coin,tmp)
{
if ( coin->inactive != 0 || coin->electrum != 0 || coin == refcoin )
continue;
if ( strcmp(coin->serverport,refcoin->serverport) == 0 )
break;
}
}
return(coin);
}
@ -254,31 +260,37 @@ cJSON *LP_coinsjson(int32_t showwif)
char *LP_getcoin(char *symbol)
{
int32_t numenabled,numdisabled; struct iguana_info *coin,*tmp; cJSON *item=0,*retjson;
numenabled = numdisabled = 0;
retjson = cJSON_CreateObject();
HASH_ITER(hh,LP_coins,coin,tmp)
if ( symbol != 0 && symbol[0] != 0 )
{
if ( strcmp(symbol,coin->symbol) == 0 )
item = LP_coinjson(coin,0);
if ( coin->inactive == 0 )
numenabled++;
else numdisabled++;
numenabled = numdisabled = 0;
HASH_ITER(hh,LP_coins,coin,tmp)
{
if ( strcmp(symbol,coin->symbol) == 0 )
item = LP_coinjson(coin,0);
if ( coin->inactive == 0 )
numenabled++;
else numdisabled++;
}
jaddstr(retjson,"result","success");
jaddnum(retjson,"enabled",numenabled);
jaddnum(retjson,"disabled",numdisabled);
if ( item == 0 )
item = cJSON_CreateObject();
jadd(retjson,"coin",item);
}
jaddstr(retjson,"result","success");
jaddnum(retjson,"enabled",numenabled);
jaddnum(retjson,"disabled",numdisabled);
if ( item == 0 )
item = cJSON_CreateObject();
jadd(retjson,"coin",item);
return(jprint(retjson,1));
}
struct iguana_info *LP_coinsearch(char *symbol)
{
struct iguana_info *coin;
portable_mutex_lock(&LP_coinmutex);
HASH_FIND(hh,LP_coins,symbol,strlen(symbol),coin);
portable_mutex_unlock(&LP_coinmutex);
struct iguana_info *coin = 0;
if ( symbol != 0 && symbol[0] != 0 )
{
portable_mutex_lock(&LP_coinmutex);
HASH_FIND(hh,LP_coins,symbol,strlen(symbol),coin);
portable_mutex_unlock(&LP_coinmutex);
}
return(coin);
}

56
iguana/exchanges/LP_commands.c

@ -111,8 +111,8 @@ getrawtransaction(coin, txid)\n\
inventory(coin)\n\
bestfit(rel, relvolume)\n\
lastnonce()\n\
buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, pubkey="")\n\
sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce, pubkey="")\n\
buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, destpubkey="")\n\
sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce, destpubkey="")\n\
withdraw(coin, outputs[])\n\
sendrawtransaction(coin, signedtx)\n\
swapstatus()\n\
@ -142,6 +142,7 @@ snapshot_balance(coin, height, addresses[])\n\
dividends(coin, height, <args>)\n\
stop()\n\
bot_list()\n\
bot_statuslist()\n\
bot_buy(base, rel, maxprice, relvolume) -> botid\n\
bot_sell(base, rel, minprice, basevolume) -> botid\n\
bot_settings(botid, newprice, newvolume)\n\
@ -152,9 +153,12 @@ bot_resume(botid)\n\
\"}"));
//sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\
base = jstr(argjson,"base");
rel = jstr(argjson,"rel");
coin = jstr(argjson,"coin");
if ( (base= jstr(argjson,"base")) == 0 )
base = "";
if ((rel= jstr(argjson,"rel")) == 0 )
rel = "";
if ( (coin= jstr(argjson,"coin")) == 0 )
coin = "";
if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) // protected localhost
{
if ( G.USERPASS_COUNTER == 0 )
@ -186,7 +190,7 @@ bot_resume(botid)\n\
{
if ( jobj(argjson,"method2") == 0 )
{
LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,jbits256(argjson,"pubkey"),jprint(argjson,0));
LP_broadcast_message(LP_mypubsock,base!=0?base:coin,rel,jbits256(argjson,"pubkey"),jprint(argjson,0));
}
return(clonestr("{\"result\":\"success\"}"));
}
@ -199,6 +203,11 @@ bot_resume(botid)\n\
printf("DEBUG stop\n");
exit(0);
}
else if ( strcmp(method,"millis") == 0 )
{
LP_millistats_update(0);
return(clonestr("{\"result\":\"success\"}"));
}
else if ( strcmp(method,"getmessages") == 0 )
{
if ( (retjson= LP_getmessages(jint(argjson,"firsti"),jint(argjson,"num"))) != 0 )
@ -251,15 +260,15 @@ bot_resume(botid)\n\
uint32_t requestid,quoteid;
if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 )
return(basilisk_swapentry(requestid,quoteid));
else if ( coin != 0 && coin[0] != 0 )
else if ( coin[0] != 0 )
return(basilisk_swapentries(coin,0,jint(argjson,"limit")));
else if ( base != 0 && base[0] != 0 && rel != 0 && rel[0] != 0 )
else if ( base[0] != 0 && rel[0] != 0 )
return(basilisk_swapentries(base,rel,jint(argjson,"limit")));
else return(basilisk_swaplist(0,0));
}
else if ( (retstr= LP_istradebots_command(ctx,pubsock,method,argjson)) != 0 )
return(retstr);
if ( base != 0 && rel != 0 )
if ( base[0] != 0 && rel[0] != 0 )
{
double price,bid,ask;
if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 )
@ -300,7 +309,7 @@ bot_resume(botid)\n\
//*
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"pubkey"),0));
return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"sell") == 0 )
@ -308,18 +317,18 @@ bot_resume(botid)\n\
//*
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"pubkey"),0));
return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
}
else if ( rel != 0 && strcmp(method,"bestfit") == 0 )
else if ( rel[0] != 0 && strcmp(method,"bestfit") == 0 )
{
double relvolume;
if ( (relvolume= jdouble(argjson,"relvolume")) > SMALLVAL )
return(LP_bestfit(rel,relvolume));
else return(clonestr("{\"error\":\"no relvolume set\"}"));
}
else if ( (coin= jstr(argjson,"coin")) != 0 )
else if ( coin[0] != 0 )
{
if ( strcmp(method,"enable") == 0 )
{
@ -336,9 +345,15 @@ bot_resume(botid)\n\
if ( LP_conflicts_find(ptr) == 0 )
{
ptr->inactive = 0;
cJSON *array = cJSON_CreateArray();
cJSON *array;
if ( ptr->smartaddr[0] != 0 )
LP_unspents_load(coin,ptr->smartaddr);
if ( LP_getheight(ptr) <= 0 )
{
ptr->inactive = (uint32_t)time(NULL);
return(clonestr("{\"error\":\"coin cant be activated till synced\"}"));
} else LP_unspents_load(coin,ptr->smartaddr);
array = cJSON_CreateArray();
jaddi(array,LP_coinjson(ptr,0));
return(jprint(array,1));
} else return(clonestr("{\"error\":\"coin port conflicts with existing coin\"}"));
@ -491,14 +506,14 @@ bot_resume(botid)\n\
}
else if ( strcmp(method,"balance") == 0 )
{
if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 )
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(jprint(LP_address_balance(ptr,jstr(argjson,"address"),1),1));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"pricearray") == 0 )
{
uint32_t firsttime;
if ( base != 0 && rel != 0 )
if ( base[0] != 0 && rel[0] != 0 )
{
if ( (firsttime= juint(argjson,"firsttime")) < time(NULL)-30*24*3600 )
firsttime = (uint32_t)(time(NULL)-30*24*3600);
@ -518,7 +533,7 @@ bot_resume(botid)\n\
bits256 pub; static uint32_t lastnotify;
pub = jbits256(argjson,"pub");
//char str[65]; printf("got wantnotify.(%s) vs %s\n",jprint(argjson,0),bits256_str(str,G.LP_mypub25519));
if ( bits256_cmp(pub,G.LP_mypub25519) == 0 && time(NULL) > lastnotify+30 )
if ( bits256_cmp(pub,G.LP_mypub25519) == 0 && time(NULL) > lastnotify+60 )
{
lastnotify = (uint32_t)time(NULL);
//printf("wantnotify for me!\n");
@ -528,7 +543,7 @@ bot_resume(botid)\n\
}
else if ( strcmp(method,"listunspent") == 0 )
{
if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 )
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
char *coinaddr;
if ( (coinaddr= jstr(argjson,"address")) != 0 )
@ -542,10 +557,11 @@ bot_resume(botid)\n\
//printf("network invoked\n");
LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519);
//LP_smartutxos_push(ptr);
return(jprint(LP_address_utxos(ptr,coinaddr,1),1));
}
else
{
return(clonestr("{\"error\":\"not my address\"}"));
}
}
return(jprint(LP_address_utxos(ptr,coinaddr,1),1));
@ -555,7 +571,7 @@ bot_resume(botid)\n\
else if ( strcmp(method,"addr_unspents") == 0 )
{
//printf("GOT ADDR_UNSPENTS %s %s\n",jstr(argjson,"coin"),jstr(argjson,"address"));
if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 )
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
char *coinaddr;
if ( (coinaddr= jstr(argjson,"address")) != 0 )

12
iguana/exchanges/LP_include.h

@ -44,6 +44,12 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#define LP_ELECTRUM_MAXERRORS 777
#define LP_MEMPOOL_TIMEINCR 10
#define LP_MIN_PEERS 8
#define LP_MAX_PEERS 32
#define LP_MAXDESIRED_UTXOS 128
#define LP_MINDESIRED_UTXOS 64
// RTmetrics
#define LP_RTMETRICS_TOPGROUP 1.01
#define LP_MAXPENDING_SWAPS 13
@ -54,7 +60,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#define DPOW_MIN_ASSETCHAIN_SIGS 11
#define LP_ENCRYPTED_MAXSIZE (4096 + 2 + crypto_box_NONCEBYTES + crypto_box_ZEROBYTES)
#define LP_MAXPUBKEY_ERRORS 3
#define LP_MAXPUBKEY_ERRORS 10
#define PSOCK_KEEPALIVE 3600
#define MAINLOOP_PERSEC 100
#define MAX_PSOCK_PORT 60000
@ -247,7 +253,7 @@ struct iguana_info
UT_hash_handle hh;
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;
int32_t numutxos,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
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];
@ -350,7 +356,7 @@ struct LP_pubkeyinfo
bits256 pubkey;
float matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
//uint32_t timestamps[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
uint32_t timestamp,numerrors;
uint32_t timestamp,numerrors,lasttime;
int32_t istrusted;
uint8_t rmd160[20],sig[65],pubsecp[33],siglen;
};

168
iguana/exchanges/LP_nativeDEX.c

@ -18,14 +18,65 @@
// LP_nativeDEX.c
// marketmaker
//
// autoadd dust utxo to vin for initial atomic tx
// 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
// BCH signing
#include <stdio.h>
struct LP_millistats
{
double lastmilli,millisum,threshold;
uint32_t count;
char name[64];
} LP_psockloop_stats,LP_reserved_msgs_stats,utxosQ_loop_stats,command_rpcloop_stats,queue_loop_stats,prices_loop_stats,LP_coinsloop_stats,LP_coinsloopBTC_stats,LP_coinsloopKMD_stats,LP_pubkeysloop_stats,LP_privkeysloop_stats,LP_swapsloop_stats,LP_gcloop_stats;
extern int32_t IAMLP;
void LP_millistats_update(struct LP_millistats *mp)
{
double elapsed,millis;
if ( mp == 0 )
{
if ( IAMLP != 0 )
{
mp = &LP_psockloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
}
mp = &LP_reserved_msgs_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &utxosQ_loop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &command_rpcloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &queue_loop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &prices_loop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_coinsloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_coinsloopBTC_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_coinsloopKMD_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_pubkeysloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_privkeysloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_swapsloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
mp = &LP_gcloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count);
}
else
{
if ( mp->lastmilli == 0. )
mp->lastmilli = OS_milliseconds();
else
{
mp->count++;
millis = OS_milliseconds();
elapsed = (millis - mp->lastmilli);
mp->millisum += elapsed;
if ( mp->threshold != 0. && elapsed > mp->threshold )
{
//if ( IAMLP == 0 )
printf("%32s elapsed %10.2f millis > threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,elapsed,mp->threshold,mp->millisum/mp->count,mp->count);
}
mp->lastmilli = millis;
}
}
}
#include "LP_include.h"
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex;
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex;
int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
@ -33,6 +84,8 @@ struct LP_peerinfo *LP_peerinfos,*LP_mypeer;
struct LP_forwardinfo *LP_forwardinfos;
struct iguana_info *LP_coins;
struct LP_pubkeyinfo *LP_pubkeyinfos;
struct rpcrequest_info *LP_garbage_collector;
#include "LP_network.c"
char *activecoins[] = { "BTC", "KMD" };
@ -40,7 +93,11 @@ char GLOBAL_DBDIR[] = { "DB" };
char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" };
char LP_gui[16] = { "cli" };
char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", };//"5.9.253.204" }; //
char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203",
"24.54.206.138", "173.212.225.176", "136.243.45.140", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88",
//"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155",
};//"5.9.253.204" }; //
//uint32_t LP_deadman_switch;
uint16_t LP_fixed_pairport,LP_publicport;
@ -165,6 +222,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
if ( duplicate != 0 )
dup++;
else uniq++;
portable_mutex_lock(&LP_commandmutex);
if ( (rand() % 10000) == 0 )
printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff);
if ( duplicate == 0 )
@ -245,21 +303,18 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
}
else
{
portable_mutex_lock(&LP_commandmutex);
if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 )
{
}
portable_mutex_unlock(&LP_commandmutex);
//printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method"));
}
free_json(argjson);
}
}
} //else printf("DUPLICATE.(%s)\n",(char *)ptr);
portable_mutex_unlock(&LP_commandmutex);
if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 )
free(jsonstr);
if ( ptr != 0 )
nn_freemsg(ptr), ptr = 0;
return(retstr);
}
@ -271,21 +326,16 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
while ( nonz < maxdepth && recvlen > 0 )
{
nonz++;
#ifndef FROM_JS
memset(&pfd,0,sizeof(pfd));
pfd.fd = sock;
pfd.events = NN_POLLIN;
if ( nn_poll(&pfd,1,1) != 1 )
break;
#endif
if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
{
methodstr[0] = 0;
if ( 1 )
if ( 0 )
{
#ifdef FROM_JS
printf("%s RECV.(%s)\n",typestr,(char *)ptr);
#endif
cJSON *recvjson; char *mstr;//,*cstr;
if ( (recvjson= cJSON_Parse((char *)ptr)) != 0 )
{
@ -297,10 +347,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
free_json(recvjson);
}
}
#ifdef FROM_JS
else printf("%s got recv.%d\n",typestr,recvlen);
#endif
int32_t validreq = 0; double millis = OS_milliseconds();
int32_t validreq = 0;
if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen )
{
if ( LP_magic_check(ptr,recvlen,remoteaddr) <= 0 )
@ -320,22 +367,20 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
Broadcaststr = 0;
if ( (argjson= cJSON_Parse(str)) != 0 )
{
if ( jobj(argjson,"method") != 0 && strcmp("connect",jstr(argjson,"method")) == 0 )
printf("self.(%s)\n",str);
portable_mutex_lock(&LP_commandmutex);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 )
{
portable_mutex_lock(&LP_commandmutex);
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 )
free(retstr);
portable_mutex_unlock(&LP_commandmutex);
}
portable_mutex_unlock(&LP_commandmutex);
free_json(argjson);
}
free(str);
}
if ( OS_milliseconds()-millis > 1000 )
printf("%.3f LP_process_message (%s)\n",OS_milliseconds()-millis,methodstr);
}
if ( ptr != 0 )
nn_freemsg(ptr), ptr = 0;
}
}
}
@ -382,28 +427,34 @@ void command_rpcloop(void *myipaddr)
{
int32_t nonz = 0; void *ctx;
ctx = bitcoin_ctx();
strcpy(command_rpcloop_stats.name,"command_rpcloop");
command_rpcloop_stats.threshold = 1000.;
while ( 1 )
{
LP_millistats_update(&command_rpcloop_stats);
nonz = LP_nanomsg_recvs(ctx);
//if ( LP_mybussock >= 0 )
// nonz += LP_sock_check("BUS",ctx,origipaddr,-1,LP_mybussock);
if ( nonz == 0 )
{
if ( IAMLP != 0 )
usleep(1000);
else usleep(10000);
usleep(10000);
else usleep(50000);
}
else if ( IAMLP == 0 )
usleep(100);
usleep(1000);
}
}
void utxosQ_loop(void *myipaddr)
{
strcpy(utxosQ_loop_stats.name,"utxosQ_loop");
utxosQ_loop_stats.threshold = 150.;
while ( 1 )
{
LP_millistats_update(&utxosQ_loop_stats);
if ( LP_utxosQ_process() == 0 )
usleep(10000);
usleep(50000);
}
}
@ -493,8 +544,28 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer)
void LP_coinsloop(void *_coins)
{
struct LP_address *ap=0,*atmp; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t oldht,j,nonz; char *coins = _coins;
if ( strcmp("BTC",coins) == 0 )
{
strcpy(LP_coinsloopBTC_stats.name,"BTC coin loop");
LP_coinsloopBTC_stats.threshold = 2000.;
}
else if ( strcmp("KMD",coins) == 0 )
{
strcpy(LP_coinsloopKMD_stats.name,"KMD coin loop");
LP_coinsloopKMD_stats.threshold = 1000.;
}
else
{
strcpy(LP_coinsloop_stats.name,"other coins loop");
LP_coinsloop_stats.threshold = 500.;
}
while ( 1 )
{
if ( strcmp("BTC",coins) == 0 )
LP_millistats_update(&LP_coinsloopBTC_stats);
else if ( strcmp("KMD",coins) == 0 )
LP_millistats_update(&LP_coinsloopKMD_stats);
else LP_millistats_update(&LP_coinsloop_stats);
nonz = 0;
HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
{
@ -602,7 +673,7 @@ void LP_coinsloop(void *_coins)
if ( coins == 0 )
return;
if ( nonz == 0 )
usleep(1000);
usleep(100000);
}
}
@ -630,14 +701,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
if ( IAMLP == 0 )
continue;
}
if ( now > peer->lastpeers+60 || (rand() % 10000) == 0 )
if ( now > peer->lastpeers+LP_ORDERBOOK_DURATION*.777 || (rand() % 100000) == 0 )
{
if ( strcmp(peer->ipaddr,myipaddr) != 0 )
{
nonz++;
#ifdef FROM_JS
if ( (rand() % 100) == 0 )
#endif
LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport);
peer->diduquery = 0;
LP_peer_pricesquery(peer);
@ -650,9 +718,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
{
peer->diduquery = now;
nonz++;
#ifdef FROM_JS
if ( (rand() % 100) == 0 )
#endif
if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 )
free(retstr);
peer->needping = 0;
@ -661,7 +726,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
}
HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
{
if ( coin->addr_listunspent_requested != 0 && time(NULL) > coin->lastpushtime+60 )
if ( coin->addr_listunspent_requested != 0 && time(NULL) > coin->lastpushtime+LP_ORDERBOOK_DURATION )
{
//printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested);
coin->lastpushtime = (uint32_t)time(NULL);
@ -696,7 +761,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
{
if ( LP_getheight(coin) <= 0 )
coin->inactive = (uint32_t)time(NULL);
LP_unspents_load(coin->symbol,coin->smartaddr);
else LP_unspents_load(coin->symbol,coin->smartaddr);
}
}
if ( (n= cJSON_GetArraySize(coins)) > 0 )
@ -713,7 +778,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
{
if ( LP_getheight(coin) <= 0 )
coin->inactive = (uint32_t)time(NULL);
LP_unspents_load(coin->symbol,coin->smartaddr);
else LP_unspents_load(coin->symbol,coin->smartaddr);
}
}
}
@ -764,9 +829,12 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
void LP_pubkeysloop(void *ctx)
{
static uint32_t lasttime;
strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop");
LP_pubkeysloop_stats.threshold = 5000.;
sleep(10);
while ( 1 )
{
LP_millistats_update(&LP_pubkeysloop_stats);
if ( time(NULL) > lasttime+60 )
{
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
@ -779,9 +847,12 @@ void LP_pubkeysloop(void *ctx)
void LP_privkeysloop(void *ctx)
{
strcpy(LP_privkeysloop_stats.name,"LP_privkeysloop");
LP_privkeysloop_stats.threshold = (LP_ORDERBOOK_DURATION * .8 * 1000) + 10000;
sleep(20);
while ( 1 )
{
LP_millistats_update(&LP_privkeysloop_stats);
LP_counter += 1000;
//printf("LP_privkeysloop %u\n",LP_counter);
LP_privkey_updates(ctx,LP_mypubsock,0);
@ -792,25 +863,34 @@ void LP_privkeysloop(void *ctx)
void LP_swapsloop(void *ignore)
{
char *retstr;
strcpy(LP_swapsloop_stats.name,"LP_swapsloop");
LP_swapsloop_stats.threshold = 605000.;
sleep(50);
while ( 1 )
{
LP_millistats_update(&LP_swapsloop_stats);
LP_counter += 10000;
//printf("LP_swapsloop %u\n",LP_counter);
if ( (retstr= basilisk_swapentry(0,0)) != 0 )
free(retstr);
LP_millistats_update(0);
sleep(600);
}
}
void LP_reserved_msgs(void *ignore)
{
bits256 zero; int32_t flag; struct nn_pollfd pfd;
bits256 zero; int32_t flag,nonz; struct nn_pollfd pfd;
memset(zero.bytes,0,sizeof(zero));
strcpy(LP_reserved_msgs_stats.name,"LP_reserved_msgs");
LP_reserved_msgs_stats.threshold = 150.;
while ( 1 )
{
nonz = 0;
LP_millistats_update(&LP_reserved_msgs_stats);
if ( num_Reserved_msgs[0] > 0 || num_Reserved_msgs[1] > 0 )
{
nonz++;
flag = 0;
if ( LP_mypubsock >= 0 )
{
@ -840,7 +920,9 @@ void LP_reserved_msgs(void *ignore)
}
if ( ignore == 0 )
break;
usleep(3000);
if ( nonz != 0 )
usleep(3000);
else usleep(25000);
}
}
@ -853,12 +935,12 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha
Reserved_msgs[priority][num_Reserved_msgs[priority]++] = msg;
n = num_Reserved_msgs[priority];
} else LP_broadcast_message(LP_mypubsock,base,rel,pubkey,msg);
portable_mutex_unlock(&LP_reservedmutex);
if ( num_Reserved_msgs[priority] > max_Reserved_msgs[priority] )
{
max_Reserved_msgs[priority] = num_Reserved_msgs[priority];
printf("New priority.%d max_Reserved_msgs.%d\n",priority,max_Reserved_msgs[priority]);
}
portable_mutex_unlock(&LP_reservedmutex);
return(n);
}
@ -914,6 +996,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_swaplistmutex);
portable_mutex_init(&LP_cachemutex);
portable_mutex_init(&LP_networkmutex);
portable_mutex_init(&LP_gcmutex);
portable_mutex_init(&LP_forwardmutex);
portable_mutex_init(&LP_psockmutex);
portable_mutex_init(&LP_coinmutex);
@ -1032,6 +1115,11 @@ 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 *)gc_loop,(void *)myipaddr) != 0 )
{
printf("error launching gc_loop for port.%u\n",myport);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 )
{
printf("error launching prices_loop for port.%u\n",myport);

80
iguana/exchanges/LP_network.c

@ -140,7 +140,7 @@ struct LP_queue
{
struct LP_queue *next,*prev;
int32_t sock,peerind,msglen;
uint32_t starttime,crc32;
uint32_t starttime,crc32,notready;
uint8_t msg[];
} *LP_Q;
int32_t LP_Qenqueued,LP_Qerrors,LP_Qfound;
@ -265,32 +265,66 @@ int32_t LP_peerindsock(int32_t *peerindp)
return(-1);
}
void gc_loop(void *arg)
{
struct rpcrequest_info *req,*rtmp; int32_t flag = 0;
strcpy(LP_gcloop_stats.name,"gc_loop");
LP_gcloop_stats.threshold = 1100.;
while ( 1 )
{
flag = 0;
LP_millistats_update(&LP_gcloop_stats);
portable_mutex_lock(&LP_gcmutex);
DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp)
{
DL_DELETE(LP_garbage_collector,req);
//printf("garbage collect ipbits.%x\n",req->ipbits);
free(req);
flag++;
}
portable_mutex_unlock(&LP_gcmutex);
if ( 0 && flag != 0 )
printf("gc_loop.%d\n",flag);
sleep(1);
}
}
void queue_loop(void *arg)
{
struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0;
strcpy(queue_loop_stats.name,"queue_loop");
queue_loop_stats.threshold = 1000.;
while ( 1 )
{
nonz = 0;
LP_millistats_update(&queue_loop_stats);
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
n = 0;
n = nonz = flag = 0;
DL_FOREACH_SAFE(LP_Q,ptr,tmp)
{
n++;
flag = 0;
if ( ptr->sock >= 0 )
{
if ( LP_sockcheck(ptr->sock) > 0 )
if ( ptr->notready == 0 || (rand() % ptr->notready) == 0 )
{
bits256 magic;
magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256)));
memcpy(&ptr->msg[ptr->msglen - sizeof(bits256)],&magic,sizeof(magic));
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen )
printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen);
ptr->sock = -1;
if ( ptr->peerind > 0 )
ptr->starttime = (uint32_t)time(NULL);
else flag = 1;
} //else printf("sock not ready to send.%d\n",ptr->msglen);
if ( LP_sockcheck(ptr->sock) > 0 )
{
bits256 magic;
magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256)));
memcpy(&ptr->msg[ptr->msglen - sizeof(bits256)],&magic,sizeof(magic));
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen )
printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen);
else flag++;
ptr->sock = -1;
if ( ptr->peerind > 0 )
ptr->starttime = (uint32_t)time(NULL);
}
else
{
if ( ptr->notready++ > 1000 )
flag = 1;
}
}
}
else if ( 0 && time(NULL) > ptr->starttime+13 )
{
@ -300,7 +334,7 @@ void queue_loop(void *arg)
LP_Qfound++;
if ( (LP_Qfound % 100) == 0 )
printf("found.%u Q.%d err.%d match.%d\n",ptr->crc32,LP_Qenqueued,LP_Qerrors,LP_Qfound);
flag = 1;
flag++;
}
else if ( 0 ) // too much beyond duplicate filter when network is busy
{
@ -309,7 +343,7 @@ void queue_loop(void *arg)
if ( (ptr->sock= LP_peerindsock(&ptr->peerind)) < 0 )
{
printf("%d no more peers to try at peerind.%d %p Q_LP.%p\n",n,ptr->peerind,ptr,LP_Q);
flag = 1;
flag++;
LP_Qerrors++;
}
}
@ -326,12 +360,12 @@ void queue_loop(void *arg)
}
if ( arg == 0 )
break;
//if ( n != 0 )
// printf("LP_Q.[%d]\n",n);
if ( nonz == 0 )
usleep(5000);
else if ( IAMLP == 0 )
usleep(1000);
{
if ( IAMLP == 0 )
usleep(50000);
else usleep(10000);
}
}
}
@ -377,6 +411,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON
if ( IAMLP == 0 )
{
free(msg);
//printf("broadcast %s\n",jstr(argjson,"method"));
jdelete(argjson,"method");
jaddstr(argjson,"method","broadcast");
if ( jobj(argjson,"timestamp") == 0 )
@ -474,8 +509,11 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w
{
static struct nn_pollfd *pfds;
int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512];
strcpy(LP_psockloop_stats.name,"LP_psockloop");
LP_psockloop_stats.threshold = 200.;
while ( 1 )
{
LP_millistats_update(&LP_psockloop_stats);
now = (uint32_t)time(NULL);
if ( buf != 0 && ptr != 0 && sendsock >= 0 )
{

6
iguana/exchanges/LP_peers.c

@ -204,7 +204,7 @@ int32_t LP_coinbus(uint16_t coin_busport)
int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *retstr,uint32_t now)
{
struct LP_peerinfo *peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0;
struct LP_peerinfo *peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t numpeers,i,n=0;
if ( (array= cJSON_Parse(retstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
@ -221,7 +221,9 @@ int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipa
argipbits = (uint32_t)calc_ipbits(argipaddr);
if ( (peer= LP_peerfind(argipbits,argport)) == 0 )
{
peer = LP_addpeer(mypeer,mypubsock,argipaddr,argport,pushport,subport,jint(item,"numpeers"),jint(item,"numutxos"),juint(item,"session"));
numpeers = LP_numpeers();
if ( IAMLP != 0 || numpeers < LP_MIN_PEERS || (IAMLP == 0 && (rand() % LP_MAX_PEERS) > numpeers) )
peer = LP_addpeer(mypeer,mypubsock,argipaddr,argport,pushport,subport,jint(item,"numpeers"),jint(item,"numutxos"),juint(item,"session"));
}
if ( peer != 0 )
{

11
iguana/exchanges/LP_portfolio.c

@ -293,8 +293,6 @@ void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP
if ( dir > 0 )
newprice = (1. / price) * (1. + margin);
else newprice = (price * (1. + margin));
//newprice = 1. / (price * (1. - margin));
if ( (minprice= basepp->minprices[relpp->ind]) == 0. || price >= minprice )
{
LP_mypriceset(&changed,relpp->symbol,basepp->symbol,newprice);
@ -468,7 +466,10 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
basepp = LP_priceinfofind(LP_autorefs[i].base);
relpp = LP_priceinfofind(LP_autorefs[i].rel);
if ( basepp != 0 && relpp != 0 )
LP_autopriceset(ctx,1,basepp,relpp,0,LP_autorefs[i].refbase,LP_autorefs[i].refrel);
{
//printf("check ref-autoprice %s/%s\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel);
LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel);
}
}
}
@ -589,11 +590,15 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a
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;
strcpy(prices_loop_stats.name,"prices_loop");
prices_loop_stats.threshold = 91000.;
while ( 1 )
{
LP_millistats_update(&prices_loop_stats);
LP_tradebots_timeslice(ctx);
if ( (btcpp= LP_priceinfofind("BTC")) == 0 )
{
printf("prices_loop BTC not in LP_priceinfofind\n");
sleep(60);
continue;
}

22
iguana/exchanges/LP_prices.c

@ -34,7 +34,7 @@ struct LP_priceinfo
double factors[LP_MAXPRICEINFOS];
//double maxprices[LP_MAXPRICEINFOS]; // autofill of base/rel
//double relvols[LP_MAXPRICEINFOS];
FILE *fps[LP_MAXPRICEINFOS];
//FILE *fps[LP_MAXPRICEINFOS];
} LP_priceinfos[LP_MAXPRICEINFOS];
int32_t LP_numpriceinfos;
@ -366,9 +366,6 @@ void LP_peer_pricesquery(struct LP_peerinfo *peer)
peer->needping = (uint32_t)time(NULL);
if ( (retstr= issue_LP_getprices(peer->ipaddr,peer->port)) != 0 )
{
#ifdef FROM_JS
printf("%s\n",retstr);
#endif
if ( (array= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(array) && (n= cJSON_GetArraySize(array)) > 0 )
@ -700,15 +697,14 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d
void LP_pubkeys_query()
{
static uint32_t lasttime;
uint8_t zeroes[20]; bits256 zero; cJSON *reqjson; struct LP_pubkeyinfo *pubp=0,*tmp;
memset(zero.bytes,0,sizeof(zero));
memset(zeroes,0,sizeof(zeroes));
HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp)
{
if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 && time(NULL) > lasttime+30 )
if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 && time(NULL) > pubp->lasttime+60 )
{
lasttime = (uint32_t)time(NULL);
pubp->lasttime = (uint32_t)time(NULL);
reqjson = cJSON_CreateObject();
jaddstr(reqjson,"method","wantnotify");
jaddbits256(reqjson,"pub",pubp->pubkey);
@ -1036,10 +1032,10 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
//printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey));
if ( LP_pricevalid(price) > 0 && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
if ( (fp= basepp->fps[relpp->ind]) == 0 )
//if ( (fp= basepp->fps[relpp->ind]) == 0 )
{
LP_pricefname(fname,base,rel);
fp = basepp->fps[relpp->ind] = OS_appendfile(fname);
fp = OS_appendfile(fname); //basepp->fps[relpp->ind] =
}
if ( fp != 0 )
{
@ -1047,12 +1043,12 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
price64 = price * SATOSHIDEN;
fwrite(&now,1,sizeof(now),fp);
fwrite(&price64,1,sizeof(price64),fp);
fflush(fp);
fclose(fp);
}
if ( (fp= relpp->fps[basepp->ind]) == 0 )
//if ( (fp= relpp->fps[basepp->ind]) == 0 )
{
sprintf(fname,"%s/PRICES/%s_%s",GLOBAL_DBDIR,rel,base);
fp = relpp->fps[basepp->ind] = OS_appendfile(fname);
fp = OS_appendfile(fname); //relpp->fps[basepp->ind] =
}
if ( fp != 0 )
{
@ -1060,7 +1056,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
price64 = (1. / price) * SATOSHIDEN;
fwrite(&now,1,sizeof(now),fp);
fwrite(&price64,1,sizeof(price64),fp);
fflush(fp);
fclose(fp);
}
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{

10
iguana/exchanges/LP_remember.c

@ -839,7 +839,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
srcAdest = srcBdest = destAdest = destBdest = 0;
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 )
{
printf("legacy DB SWAPS files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
printf("legacy DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}"));
}
alice = LP_coinfind(rswap.alicecoin);
@ -937,7 +937,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
}
for (j=0; j<32; j++)
rev.bytes[j] = rswap.myprivs[0].bytes[31 - j];
if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(0,&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]);
}
LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]);
@ -967,7 +967,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( bits256_nonz(rswap.privBn) != 0 )
{
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(0,&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]);
}
}
@ -1042,7 +1042,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( redeemlen > 0 )
{
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(0,&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{
int32_t z;
for (z=0; z<20; z++)
@ -1073,7 +1073,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
vcalc_sha256(0,rswap.secretBn256,rswap.privBn.bytes,sizeof(rswap.privBn));
redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256);
len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(0,&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]);
}
LP_txbytes_update("bobrefund",rswap.bobcoin,rswap.txbytes[BASILISK_BOBREFUND],&rswap.txids[BASILISK_BOBREFUND],&rswap.depositspent,&rswap.sentflags[BASILISK_BOBREFUND]);

54
iguana/exchanges/LP_rpc.c

@ -25,6 +25,7 @@ char *LP_issue_curl(char *debugstr,char *destip,uint16_t port,char *url)
maxerrs = LP_MAXPEER_ERRORS;
if ( peer == 0 || (peer->errors < maxerrs || peer->good >= LP_MINPEER_GOOD) )
{
//printf("issue.(%s)\n",url);
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) == 0 )
{
if ( peer != 0 )
@ -110,7 +111,7 @@ char *LP_apicall(struct iguana_info *coin,char *method,char *params)
{
if ( (retjson= electrum_submit(coin->symbol,coin->electrum,&retjson,method,params,ELECTRUM_TIMEOUT)) != 0 )
{
retstr = jprint(retjson,0);
retstr = jprint(retjson,1);
//printf("got.%p (%s)\n",retjson,retstr);
return(retstr);
} return(clonestr("{\"error\":\"electrum no response\"}"));
@ -186,6 +187,24 @@ static char *assetids[][4] =
{ "10524562908394749924", "MGW", "1", "100000000" },
};
void LP_sendtoaddress_line(char *validaddress,char *assetname,uint64_t satoshis,uint64_t txnum)
{
char line[1024],lowerstr[64];
if ( strcmp(assetname,"SUPERNETx2") == 0 )
{
sprintf(line,"fiat/supernet sendtoaddress %s %.8f # txnum.%llu",validaddress,dstr(satoshis),(long long)txnum);
printf("%s\n",line);
sprintf(line,"fiat/revs sendtoaddress %s %.8f # txnum.%llu",validaddress,dstr(satoshis),(long long)txnum);
}
else
{
strcpy(lowerstr,assetname);
tolowercase(lowerstr);
sprintf(line,"fiat/%s sendtoaddress %s %.8f # txnum.%llu",lowerstr,validaddress,dstr(satoshis),(long long)txnum);
}
printf("%s\n",line);
}
uint64_t LP_assetid_mult(int32_t *assetindp,char *name,uint64_t assetid)
{
int32_t i; uint64_t mult = 0;
@ -291,9 +310,9 @@ char *account = "NXT-MRBN-8DFH-PFMK-A4DBM";
if ( (decjson= LP_NXT_decrypt(txnum,account,jstr(encjson,"data"),jstr(encjson,"nonce"),passphrase)) != 0 )
{
//printf("%s\n",jprint(decjson,0));
msgstr = jstr(decjson,"decryptedMessage");
if ( jstr(decjson,"decryptedMessage") != 0 )
msgstr = jstr(decjson,"decryptedMessage");
}
}
}
}
@ -314,12 +333,12 @@ char *account = "NXT-MRBN-8DFH-PFMK-A4DBM";
strncpy(validaddress,&msgstr[z],34);
if ( strlen(validaddress) == 34 || strlen(validaddress) == 33 )
{
printf("%-4d: (%34s) <- %13.5f %10s tx.%llu past_marker.%d\n",i,validaddress,dstr(qty * mult),assetname,(long long)txnum,past_marker);
//printf("%-4d: (%34s) <- %13.5f %10s tx.%llu past_marker.%d\n",i,validaddress,dstr(qty * mult),assetname,(long long)txnum,past_marker);
if ( past_marker == 0 )
{
LP_sendtoaddress_line(validaddress,assetname,(qty * mult),txnum);
}
} else printf("%-4d: (%34s) <- %13.5f %10s tx.%llu\n",i,msgstr!=0?msgstr:jprint(item,0),dstr(qty * mult),assetname,(long long)txnum);
if ( past_marker == 0 )
{
}
}
if ( msgjson != 0 )
free_json(msgjson);
@ -690,6 +709,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr,int32_t fullflag)
if ( strcmp(coin->smartaddr,coinaddr) == 0 )
{
retjson = LP_listunspent(symbol,coinaddr);
coin->numutxos = cJSON_GetArraySize(retjson);
//printf("SELF_LISTUNSPENT.(%s %s)\n",symbol,coinaddr);
}
else if ( IAMLP == 0 )
@ -801,11 +821,21 @@ int32_t LP_importaddress(char *symbol,char *address)
double _LP_getestimatedrate(struct iguana_info *coin)
{
char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020;
char buf[512],*retstr=0; int32_t numblocks; cJSON *errjson,*retjson; double rate = 0.00000020;
if ( coin->rate < 0. || time(NULL) > coin->ratetime+30 )
{
sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2);
if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 )
numblocks = strcmp(coin->symbol,"BTC") == 0 ? 6 : 2;
if ( coin->electrum == 0 )
{
sprintf(buf,"[%d]",numblocks);
retstr = LP_apicall(coin,"estimatefee",buf);
}
else
{
if ( (retjson= electrum_estimatefee(coin->symbol,coin->electrum,&retjson,numblocks)) != 0 )
retstr = jprint(retjson,1);
}
if ( retstr != 0 )
{
if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 )
{
@ -827,7 +857,7 @@ double _LP_getestimatedrate(struct iguana_info *coin)
coin->ratetime = (uint32_t)time(NULL);
}
free(retstr);
}
} else rate = coin->rate;
} else rate = coin->rate;
return(rate);
}

11
iguana/exchanges/LP_signatures.c

@ -286,11 +286,11 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2
if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 )
{
static uint32_t counter;
if ( counter++ < 10 )
if ( counter++ <= LP_MAXPUBKEY_ERRORS )
{
if ( pubp != 0 )
pubp->numerrors++;
if ( pubp != 0 && pubp->numerrors > 1 )
if ( pubp != 0 && pubp->numerrors > LP_MAXPUBKEY_ERRORS/2 )
printf("LP_utxos_sigcheck failure.%d, probably from %s with older version\n",pubp!=0?pubp->numerrors:-1,bits256_str(str,pubkey));
}
retval = -1;
@ -685,11 +685,10 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
memset(&zero,0,sizeof(zero));
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[1] < sizeof(Reserved_msgs[1])/sizeof(*Reserved_msgs[1])-2 )
{
Reserved_msgs[1][num_Reserved_msgs[1]++] = msg;
//Reserved_msgs[num_Reserved_msgs++] = msg2;
}
LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg2);
if ( num_Reserved_msgs[0] < sizeof(Reserved_msgs[0])/sizeof(*Reserved_msgs[0])-2 )
Reserved_msgs[0][num_Reserved_msgs[0]++] = msg2;
//LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg2);
portable_mutex_unlock(&LP_reservedmutex);
}

66
iguana/exchanges/LP_socket.c

@ -360,6 +360,35 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep
return(flag);
}
cJSON *electrum_version(char *symbol,struct electrum_info *ep,cJSON **retjsonp);
cJSON *electrum_headers_subscribe(char *symbol,struct electrum_info *ep,cJSON **retjsonp);
struct stritem *electrum_sitem(struct electrum_info *ep,char *stratumreq,int32_t timeout,cJSON **retjsonp)
{
struct stritem *sitem = (struct stritem *)queueitem(stratumreq);
sitem->expiration = timeout;
sitem->DL.type = ep->stratumid++;
sitem->retptrp = (void **)retjsonp;
queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
return(sitem);
}
void electrum_initial_requests(struct electrum_info *ep)
{
cJSON *retjson; char stratumreq[1024];
retjson = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,"blockchain.headers.subscribe","[]");
electrum_sitem(ep,stratumreq,3,&retjson);
retjson = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,"server.version","[\"barterDEX\", [\"1.1\", \"1.1\"]]");
electrum_sitem(ep,stratumreq,3,&retjson);
retjson = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,"blockchain.estimatefee","[2]");
electrum_sitem(ep,stratumreq,3,&retjson);
}
cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout)
{
// queue id and string and callback
@ -374,12 +403,13 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params);
//printf("%s %s",symbol,stratumreq);
memset(ep->buf,0,ep->bufsize);
sitem = (struct stritem *)queueitem(stratumreq);
sitem = electrum_sitem(ep,stratumreq,timeout,retjsonp);
/*sitem = (struct stritem *)queueitem(stratumreq);
sitem->expiration = timeout;
sitem->DL.type = ep->stratumid++;
sitem->retptrp = (void **)retjsonp;
sitem->retptrp = (void **)retjsonp;*/
portable_mutex_lock(&ep->mutex);
queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
//queue_enqueue("sendQ",&ep->sendQ,&sitem->DL);
expiration = (uint32_t)time(NULL) + timeout + 1;
while ( *retjsonp == 0 && time(NULL) <= expiration )
usleep(5000);
@ -393,6 +423,8 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
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;
}
@ -591,7 +623,11 @@ cJSON *electrum_address_getbalance(char *symbol,struct electrum_info *ep,cJSON *
cJSON *electrum_addpeer(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *endpoint) { return(electrum_strarg(symbol,ep,retjsonp,"server.add_peer",endpoint,ELECTRUM_TIMEOUT)); }
cJSON *electrum_sendrawtransaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *rawtx) { return(electrum_strarg(symbol,ep,retjsonp,"blockchain.transaction.broadcast",rawtx,ELECTRUM_TIMEOUT)); }
cJSON *electrum_estimatefee(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t numblocks) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.estimatefee",numblocks,ELECTRUM_TIMEOUT)); }
cJSON *electrum_estimatefee(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t numblocks)
{
return(electrum_intarg(symbol,ep,retjsonp,"blockchain.estimatefee",numblocks,ELECTRUM_TIMEOUT));
}
cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_chunk",n,ELECTRUM_TIMEOUT)); }
cJSON *electrum_getheader(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n)
@ -832,7 +868,17 @@ struct electrum_info *LP_electrum_info(int32_t *alreadyp,char *symbol,char *ipad
int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len)
{
cJSON *strjson,*errjson,*resultjson,*paramsjson; char *method; int32_t i,n,height; uint32_t idnum=0; struct stritem *stritem; struct iguana_info *coin; struct queueitem *tmp,*item = 0;
if ( str == 0 || len == 0 )
return(-1);
ep->lasttime = (uint32_t)time(NULL);
/*if ( (strjson= cJSON_Parse(str)) == 0 )
{
strjson = cJSON_CreateObject();
resitem = cJSON_CreateObject();
jaddstr(resitem,"string",str);
jadd(strjson,"result",resitem);
printf("mapped.(%s) -> %s\n",str,jprint(strjson,0));
}*/
if ( (strjson= cJSON_Parse(str)) != 0 )
{
resultjson = jobj(strjson,"result");
@ -875,9 +921,9 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len)
stritem = (struct stritem *)item;
if ( item->type == idnum )
{
//printf("matched idnum.%d result.%p\n",idnum,resultjson);
DL_DELETE(ep->pendingQ.list,item);
*((cJSON **)stritem->retptrp) = (resultjson != 0 ? jduplicate(resultjson) : strjson);
*((cJSON **)stritem->retptrp) = (resultjson != 0 ? jduplicate(resultjson) : jduplicate(strjson));
//printf("matched idnum.%d result.(%s)\n",idnum,jprint(*((cJSON **)stritem->retptrp),0));
resultjson = strjson = 0;
free(item);
break;
@ -906,14 +952,10 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len)
void LP_dedicatedloop(void *arg)
{
struct pollfd fds; int32_t i,len,flag,timeout = 10; struct iguana_info *coin; cJSON *retjson; struct stritem *sitem; struct electrum_info *ep = arg;
struct pollfd fds; int32_t i,len,flag,timeout = 10; struct iguana_info *coin; struct stritem *sitem; struct electrum_info *ep = arg;
if ( (coin= LP_coinfind(ep->symbol)) != 0 )
ep->heightp = &coin->height, ep->heighttimep = &coin->heighttime;
sleep(2);
if ( (retjson= electrum_version(ep->symbol,ep,&retjson)) != 0 )
printf("electrum_version %s\n",jprint(retjson,1));
if ( (retjson= electrum_headers_subscribe(ep->symbol,ep,&retjson)) != 0 )
free_json(retjson);
electrum_initial_requests(ep);
printf("LP_dedicatedloop ep.%p sock.%d for %s:%u num.%d %p %s ht.%d\n",ep,ep->sock,ep->ipaddr,ep->port,Num_electrums,&Num_electrums,ep->symbol,*ep->heightp);
while ( ep->sock >= 0 )
{

12
iguana/exchanges/LP_tradebots.c

@ -402,6 +402,16 @@ char *LP_tradebot_list(void *ctx,int32_t pubsock,cJSON *argjson)
return(jprint(array,1));
}
char *LP_tradebot_statuslist(void *ctx,int32_t pubsock,cJSON *argjson)
{
struct LP_tradebot *bot,*tmp; cJSON *array = cJSON_CreateArray();
DL_FOREACH_SAFE(LP_tradebots,bot,tmp)
{
jaddi(array,LP_tradebot_json(bot));
}
return(jprint(array,1));
}
char *LP_tradebot_buy(int32_t dispdir,char *base,char *rel,double maxprice,double relvolume)
{
struct LP_tradebot *bot; char *retstr; double shortfall; int32_t i,n; cJSON *array,*item,*retjson; uint64_t txfees,balance=0,abalance=0; struct iguana_info *basecoin,*relcoin;
@ -599,6 +609,8 @@ char *LP_istradebots_command(void *ctx,int32_t pubsock,char *method,cJSON *argjs
return(0);
if ( strcmp(method,"bot_list") == 0 )
return(LP_tradebot_list(ctx,pubsock,argjson));
else if ( strcmp(method,"bot_statuslist") == 0 )
return(LP_tradebot_statuslist(ctx,pubsock,argjson));
else if ( strcmp(method,"bot_buy") == 0 )
return(LP_tradebot_limitbuy(ctx,pubsock,argjson));
else if ( strcmp(method,"bot_sell") == 0 )

46
iguana/exchanges/LP_transaction.c

@ -603,9 +603,9 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_
return(complete);
}
char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t utxovout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys,int32_t zcash)
char *basilisk_swap_bobtxspend(int32_t dustcombine,bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t utxovout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys,int32_t zcash)
{
char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin;
char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *items[2],*txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t i,completed,spendlen,n,ignore_cltverr=1; struct vin_info V[8]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin;
LP_mark_spent(symbol,utxotxid,utxovout);
if ( txfee > 0 && txfee < 10000 )
txfee = 10000;
@ -617,9 +617,9 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
if ( redeemlen < 0 )
return(0);
value = 0;
#ifndef BASILISK_DISABLESENDTX
if ( (coin= LP_coinfind(symbol)) != 0 )
{
#ifndef BASILISK_DISABLESENDTX
if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 )
{
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && utxovout < n )
@ -629,16 +629,30 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
//printf("value in vout.%d %.8f (%s)\n",vout,dstr(value),jprint(txobj,0));
}
free_json(txobj);
//if ( value != 0 )
// gettxout
} else printf("cant gettx\n");
if ( value == 0 )
{
printf("basilisk_swap_bobtxspend.%s %s utxo.(%s).v%d already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid),utxovout);
return(0);
}
}
if ( coin->electrum != 0 || coin->numutxos < LP_MINDESIRED_UTXOS )
dustcombine = 0;
else if ( coin->numutxos >= LP_MINDESIRED_UTXOS )
dustcombine = 2;
if ( dustcombine != 0 )
{
uint64_t more;
if ( privkey2p != 0 )
dustcombine = 1;
memset(items,0,sizeof(items));
more = LP_dustcombine(items,dustcombine,coin);
if ( more != 0 )
printf("%s dustcombine.%d -> %.8f (%s) + (%s)\n",coin->symbol,dustcombine,dstr(more),items[0] != 0 ? jprint(items[0],0) : "",items[1] != 0 ? jprint(items[1],0) : "");
value += more;
dustcombine = (items[0] != 0) + (items[1] != 0);
}
#endif
}
if ( satoshis != 0 )
{
if ( value < satoshis+txfee )
@ -648,10 +662,10 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
satoshis = value - 3*txfee/4;
printf("reduce satoshis %.8f by txfee %.8f to value %.8f\n",dstr(satoshis),dstr(txfee),dstr(value));
}
else if ( value == satoshis && (double)txfee/value < 0.001 )
else if ( value == satoshis && (double)txfee/value < 0.1 )
{
satoshis = value - txfee;
printf("emergency txfee allocation from value %.8f identical to satoshis: %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(txfee));
printf("txfee allocation from value %.8f identical to satoshis: %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(txfee));
}
else
{
@ -696,6 +710,13 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
jaddistr(privkeys,wifstr);
V[0].suppress_pubkeys = suppress_pubkeys;
V[0].ignore_cltverr = ignore_cltverr;
for (i=0; i<dustcombine; i++) // must be simple standard vin
{
V[i+1].signers[0].privkey = privkey;
V[i+1].suppress_pubkeys = 0;
V[i+1].ignore_cltverr = 0;
V[i+1].N = V[i+1].M = 1;
}
if ( redeemlen != 0 )
memcpy(V[0].p2shscript,redeemscript,redeemlen), V[0].p2shlen = redeemlen;
txobj = bitcoin_txcreate(symbol,isPoS,locktime,1,timestamp);
@ -726,6 +747,9 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
jaddnum(item,"suppress",suppress_pubkeys);
jaddnum(item,"sequence",sequenceid);
jaddi(vins,item);
for (i=0; i<dustcombine; i++)
if ( items[i] != 0 )
jaddi(vins,items[i]);
jdelete(txobj,"vin");
jadd(txobj,"vin",vins);
if ( destaddr == 0 )
@ -1109,7 +1133,7 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub
txfee = LP_MIN_TXFEE;
for (iter=0; iter<2; iter++)
{
if ( (signedtx= basilisk_swap_bobtxspend(&rawtx->I.signedtxid,iter == 0 ? txfee : newtxfee,str,coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,privkey,0,0,0,0,0,rawtx->utxotxid,rawtx->utxovout,rawtx->I.destaddr,pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,rawtx->I.suppress_pubkeys,coin->zcash)) != 0 )
if ( (signedtx= basilisk_swap_bobtxspend(1,&rawtx->I.signedtxid,iter == 0 ? txfee : newtxfee,str,coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,privkey,0,0,0,0,0,rawtx->utxotxid,rawtx->utxovout,rawtx->I.destaddr,pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,rawtx->I.suppress_pubkeys,coin->zcash)) != 0 )
{
rawtx->I.datalen = (int32_t)strlen(signedtx) >> 1;
if ( rawtx->I.datalen <= sizeof(rawtx->txbytes) )
@ -1148,7 +1172,7 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t
}
for (iter=0; iter<2; iter++)
{
if ( (signedtx= basilisk_swap_bobtxspend(&dest->I.signedtxid,iter == 0 ? txfee : newtxfee,rawtx->name,symbol,wiftaddr,taddr,pubtype,p2shtype,isPoS,wiftype,swap->ctx,privkey,privkey2,rawtx->redeemscript,rawtx->I.redeemlen,userdata,userdatalen,dest->utxotxid,dest->utxovout,dest->I.destaddr,rawtx->I.pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,dest->I.suppress_pubkeys,zcash)) != 0 )
if ( (signedtx= basilisk_swap_bobtxspend(0,&dest->I.signedtxid,iter == 0 ? txfee : newtxfee,rawtx->name,symbol,wiftaddr,taddr,pubtype,p2shtype,isPoS,wiftype,swap->ctx,privkey,privkey2,rawtx->redeemscript,rawtx->I.redeemlen,userdata,userdatalen,dest->utxotxid,dest->utxovout,dest->I.destaddr,rawtx->I.pubkey33,1,0,&destamount,rawtx->I.amount,changeaddr,vinaddr,dest->I.suppress_pubkeys,zcash)) != 0 )
{
dest->I.datalen = (int32_t)strlen(signedtx) >> 1;
if ( dest->I.datalen <= sizeof(dest->txbytes) )
@ -1208,7 +1232,7 @@ char *basilisk_swap_Aspend(char *name,char *symbol,uint64_t Atxfee,uint8_t wifta
txfee = LP_MIN_TXFEE;
}
//txfee = LP_txfee(symbol);
signedtx = basilisk_swap_bobtxspend(&signedtxid,txfee,name,symbol,wiftaddr,taddr,pubtype,p2shtype,isPoS,wiftype,ctx,privAm,&privBn,redeemscript,redeemlen,0,0,utxotxid,utxovout,0,pubkey33,1,expiration,destamountp,0,0,vinaddr,1,zcash);
signedtx = basilisk_swap_bobtxspend(0,&signedtxid,txfee,name,symbol,wiftaddr,taddr,pubtype,p2shtype,isPoS,wiftype,ctx,privAm,&privBn,redeemscript,redeemlen,0,0,utxotxid,utxovout,0,pubkey33,1,expiration,destamountp,0,0,vinaddr,1,zcash);
LP_mark_spent(symbol,utxotxid,utxovout);
}
return(signedtx);

53
iguana/exchanges/LP_utxo.c

@ -957,6 +957,59 @@ int32_t LP_inventory_prevent(int32_t iambob,char *symbol,bits256 txid,int32_t vo
return(0);
}
cJSON *LP_dustcombine_item(struct LP_address_utxo *up)
{
cJSON *item = cJSON_CreateObject();
jaddbits256(item,"txid",up->U.txid);
jaddnum(item,"vout",up->U.vout);
return(item);
}
uint64_t LP_dustcombine(cJSON *items[2],int32_t dustcombine,struct iguana_info *coin)
{
struct LP_address *ap=0; struct LP_address_utxo *up,*tmp,*min0,*min1; cJSON *txobj;
if ( coin == 0 || coin->electrum != 0 || dustcombine <= 0 || dustcombine > 2 )
return(0);
return(0);
min1 = min0 = 0;
if ( (ap= _LP_addressfind(coin,coin->smartaddr)) != 0 )
{
DL_FOREACH_SAFE(ap->utxos,up,tmp)
{
if ( up->spendheight <= 0 && up->U.height > 0 && up->U.value != 0 )
{
if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,up->U.txid,up->U.vout)) == 0 )
up->spendheight = 1;
else
{
free_json(txobj);
if ( LP_inventory_prevent(0,coin->symbol,up->U.txid,up->U.vout) == 0 && LP_inventory_prevent(1,coin->symbol,up->U.txid,up->U.vout) == 0 )
{
if ( min1 == 0 || up->U.value < min1->U.value )
{
if ( min0 == 0 || up->U.value < min0->U.value )
{
min1 = min0;
min0 = up;
} else min1 = up;
}
}
}
}
}
}
if ( min0 != 0 )
{
items[0] = LP_dustcombine_item(min0);
if ( dustcombine == 2 && min1 != 0 )
{
items[1] = LP_dustcombine_item(min1);
return(min0->U.value + min1->U.value);
} else return(min0->U.value);
}
return(0);
}
int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight)
{
int32_t i,ht,num = 0; struct LP_transaction *tx,*tmp;

1
iguana/exchanges/LP_utxos.c

@ -512,6 +512,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri
txfee = LP_txfeecalc(coin,0,0);
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
coin->numutxos = n;
//printf("LP_privkey_init %s %s\n",coin->symbol,jprint(array,0));
for (iambob=0; iambob<=1; iambob++)
{

3
iguana/exchanges/bot_statuslist

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

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

6
iguana/exchanges/coins.json

File diff suppressed because one or more lines are too long

2
iguana/exchanges/install

@ -1,5 +1,5 @@
#!/bin/bash
cp bot_buy bot_list bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts
cp processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts
cp coins.json ..
cd ../dexscripts
#cp ../exchanges/passphrase ../exchanges/userpass .

3
iguana/exchanges/millis

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

2
iguana/exchanges/mm.c

@ -907,7 +907,7 @@ int main(int argc, const char * argv[])
} //else printf("(%s) launched.(%s)\n",argv[1],passphrase);
incr = 100.;
while ( (1) )
sleep(1);
sleep(100000);
profitmargin = jdouble(retjson,"profitmargin");
minask = jdouble(retjson,"minask");
maxbid = jdouble(retjson,"maxbid");

12
iguana/exchanges/mnzservers

@ -0,0 +1,12 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"b4a6361506d847817205a8e51374eb129fc33c3b5466235afdbc65f2291ffb4c\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"bd0c69da4ec3ed61613734f9f681f846fde5d8efc894c82dafbeeb7a01844872\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"8f7782b532808a30a1fe6ffc1fa3c55fea6d734f000763fa88d42ccfed60d213\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"d80a74847cd60899afdd673570f8b698e4089e5ad4d6e9e205b5e5891ec0c84f\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"322e236db07484b31aea9400a6f3f5ed972e29c6d4115c63aaedaa541d41e758\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"8579b74435093690d3d7680ecdac0dd1b892dc5ecd4fb603f0e22fd003176342\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"c4e3c95bd9612cce3fe1cfcc0a0e9c625bab7e4b83bc68f0ede73633e6a8c17f\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"43467b51e07fae3b19101fca7fe1bf250d34c8deecfd493c723f87d5eda1a64b\",\"method\":\"trust\",\"trust\":1}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"e900c42a0d883d098f382b59cf5655dd1d92b2c94f6580095a4f6382514f7a59\",\"method\":\"trust\",\"trust\":1}"

3
iguana/exchanges/processfiles

@ -0,0 +1,3 @@
ls -l /proc/$1/fd
echo sockstat
cat /proc/$1/net/sockstat

89
iguana/exchanges/stats.c

@ -589,24 +589,31 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen)
}
uint16_t RPC_port;
extern portable_mutex_t LP_commandmutex;
extern portable_mutex_t LP_commandmutex,LP_gcmutex;
extern struct rpcrequest_info *LP_garbage_collector;
void LP_rpc_processreq(void *_ptr)
{
uint64_t arg64 = *(uint64_t *)_ptr;
static uint32_t spawned,maxspawned;
char filetype[128],content_type[128];
int32_t recvlen,flag,postflag=0,contentlen,remains,sock,numsent,jsonflag=0,hdrsize,len;
char helpname[512],remoteaddr[64],*buf,*retstr,*space,*jsonbuf;
uint32_t ipbits,i,size = 32*IGUANA_MAXPACKETSIZE + 512;
ipbits = (arg64 >> 32);
char helpname[512],remoteaddr[64],*buf,*retstr,*space,*jsonbuf; struct rpcrequest_info *req = _ptr;
uint32_t ipbits,i,size = IGUANA_MAXPACKETSIZE + 512;
ipbits = req->ipbits;;
expand_ipbits(remoteaddr,ipbits);
sock = (arg64 & 0xffffffff);
sock = req->sock;
recvlen = flag = 0;
retstr = 0;
space = calloc(1,size);
jsonbuf = calloc(1,size);
remains = size-1;
buf = jsonbuf;
spawned++;
if ( spawned > maxspawned )
{
printf("max rpc threads spawned and alive %d <- %d\n",maxspawned,spawned);
maxspawned = spawned;
}
while ( remains > 0 )
{
//printf("flag.%d remains.%d recvlen.%d\n",flag,remains,recvlen);
@ -651,8 +658,7 @@ void LP_rpc_processreq(void *_ptr)
else
{
usleep(10000);
//printf("got.(%s) %d remains.%d of total.%d\n",jsonbuf,recvlen,remains,len);
//retstr = iguana_rpcparse(space,size,&postflag,jsonbuf);
printf("got.(%s) %d remains.%d of total.%d\n",jsonbuf,recvlen,remains,len);
if ( flag == 0 )
break;
}
@ -664,8 +670,6 @@ void LP_rpc_processreq(void *_ptr)
jsonflag = postflag = 0;
portable_mutex_lock(&LP_commandmutex);
retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,RPC_port);
//if ( strcmp("5.9.253.195",remoteaddr) == 0 )
// printf("RPC.(%s)%s\n",jsonbuf,retstr);
portable_mutex_unlock(&LP_commandmutex);
if ( filetype[0] != 0 )
{
@ -729,46 +733,63 @@ void LP_rpc_processreq(void *_ptr)
free(space);
free(jsonbuf);
closesocket(sock);
portable_mutex_lock(&LP_gcmutex);
DL_APPEND(LP_garbage_collector,req);
spawned--;
portable_mutex_unlock(&LP_gcmutex);
}
extern int32_t IAMLP;
void stats_rpcloop(void *args)
{
uint16_t port; int32_t sock,bindsock; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits; uint64_t arg64; void *arg64ptr;
static uint32_t counter;
uint16_t port; int32_t retval,sock,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req,*req2,*rtmp;
if ( (port= *(uint16_t *)args) == 0 )
port = 7779;
RPC_port = port;
while ( (bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 )
{
//if ( coin->MAXPEERS == 1 )
// break;
//exit(-1);
sleep(3);
}
printf(">>>>>>>>>> DEX stats 127.0.0.1:%d bind sock.%d DEX stats API enabled <<<<<<<<<\n",port,bindsock);
while ( bindsock >= 0 )
localhostbits = (uint32_t)calc_ipbits("127.0.0.1");
while ( 1 )
{
if ( bindsock < 0 )
{
while ( (bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 )
usleep(10000);
if ( counter++ < 1 )
printf(">>>>>>>>>> DEX stats 127.0.0.1:%d bind sock.%d DEX stats API enabled <<<<<<<<<\n",port,bindsock);
}
clilen = sizeof(cli_addr);
sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen);
if ( sock < 0 )
{
//printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno));
printf("iguana_rpcloop ERROR on accept usock.%d errno %d %s\n",sock,errno,strerror(errno));
close(bindsock);
bindsock = -1;
continue;
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
//printf("remote RPC request from (%s) %x\n",remoteaddr,ipbits);
arg64 = ((uint64_t)ipbits << 32) | (sock & 0xffffffff);
arg64ptr = malloc(sizeof(arg64));
memcpy(arg64ptr,&arg64,sizeof(arg64));
if ( 1 )
req = calloc(1,sizeof(*req));
req->sock = sock;
req->ipbits = ipbits;
LP_rpc_processreq(req);
continue;
if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
{
LP_rpc_processreq((void *)&arg64);
free(arg64ptr);
}
else if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_rpc_processreq,arg64ptr) != 0 )
{
printf("error launching rpc handler on port %d\n",port);
}
// yes, small leak per command
printf("error launching rpc handler on port %d, retval.%d\n",port,retval);
close(bindsock);
bindsock = -1;
portable_mutex_lock(&LP_gcmutex);
DL_FOREACH_SAFE(LP_garbage_collector,req2,rtmp)
{
DL_DELETE(LP_garbage_collector,req2);
free(req2);
}
portable_mutex_unlock(&LP_gcmutex);
if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
{
printf("error2 launching rpc handler on port %d, retval.%d\n",port,retval);
LP_rpc_processreq(req);
}
}
}
}

Loading…
Cancel
Save