Browse Source

Merge pull request #479 from jl777/spvdex

sync with spvdex, added crc32 to version at start
etomic
jl777 7 years ago
committed by GitHub
parent
commit
1ccf79721b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 93
      crypto777/cJSON.c
  2. 2
      iguana/exchanges/LP_RTmetrics.c
  3. 1
      iguana/exchanges/LP_commands.c
  4. 73
      iguana/exchanges/LP_nativeDEX.c
  5. 10
      iguana/exchanges/LP_network.c
  6. 19
      iguana/exchanges/LP_ordermatch.c
  7. 2
      iguana/exchanges/LP_peers.c
  8. 2
      iguana/exchanges/LP_prices.c
  9. 23
      iguana/exchanges/LP_remember.c
  10. 65
      iguana/exchanges/LP_rpc.c
  11. 2
      iguana/exchanges/LP_scan.c
  12. 11
      iguana/exchanges/LP_signatures.c
  13. 9
      iguana/exchanges/LP_socket.c
  14. 122
      iguana/exchanges/LP_statemachine.c
  15. 8
      iguana/exchanges/LP_swap.c
  16. 2
      iguana/exchanges/LP_tradebots.c
  17. 11
      iguana/exchanges/LP_transaction.c
  18. 66
      iguana/exchanges/LP_utxo.c
  19. 8
      iguana/exchanges/LP_utxos.c

93
crypto777/cJSON.c

@ -59,13 +59,46 @@ void LP_free(void *ptr);
static void *(*cJSON_malloc)(size_t sz) = (void *)LP_alloc;
static void (*cJSON_free)(void *ptr) = LP_free;
static void *cJSON_mallocstr(int32_t len)
{
return(cJSON_malloc(len));
}
static char **cJSON_mallocptrs(int32_t num,char **space,int32_t max)
{
if ( num < max )
return(space);
else return(cJSON_malloc(num * sizeof(char *)));
}
static void *cJSON_mallocnode()
{
return(cJSON_malloc(sizeof(cJSON)));
}
static void cJSON_freeptrs(char **ptrs,int32_t num,char **space)
{
if ( ptrs != space )
cJSON_free(ptrs);
}
static void cJSON_freestr(char *str)
{
cJSON_free(str);
}
static void cJSON_freenode(cJSON *item)
{
cJSON_free(item);
}
static char* cJSON_strdup(const char* str)
{
size_t len;
char* copy;
len = strlen(str) + 1;
if (!(copy = (char*)cJSON_malloc(len+1))) return 0;
if (!(copy = (char*)cJSON_mallocstr((int32_t)len+1))) return 0;
memcpy(copy,str,len);
return copy;
}
@ -78,14 +111,14 @@ void cJSON_InitHooks(cJSON_Hooks* hooks)
return;
}
cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
}
/* Internal constructor. */
static cJSON *cJSON_New_Item(void)
{
cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
cJSON* node = (cJSON*)cJSON_mallocnode();
if (node) memset(node,0,sizeof(cJSON));
return node;
}
@ -98,9 +131,9 @@ void cJSON_Delete(cJSON *c)
{
next=c->next;
if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
if (c->string) cJSON_free(c->string);
cJSON_free(c);
if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_freestr(c->valuestring);
if (c->string) cJSON_freestr(c->string);
cJSON_freenode(c);
c=next;
}
}
@ -134,13 +167,13 @@ static char *print_number(cJSON *item)
double d = item->valuedouble;
if ( fabs(((double)item->valueint) - d) <= DBL_EPSILON && d >= (1. - DBL_EPSILON) && d < (1LL << 62) )//d <= INT_MAX && d >= INT_MIN )
{
str = (char *)cJSON_malloc(24); /* 2^64+1 can be represented in 21 chars + sign. */
str = (char *)cJSON_mallocstr(24); /* 2^64+1 can be represented in 21 chars + sign. */
if ( str != 0 )
sprintf(str,"%lld",(long long)item->valueint);
}
else
{
str = (char *)cJSON_malloc(66); /* This is a nice tradeoff. */
str = (char *)cJSON_mallocstr(66); /* This is a nice tradeoff. */
if ( str != 0 )
{
if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 )
@ -175,7 +208,7 @@ static const char *parse_string(cJSON *item,const char *str)
while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes
out=(char*)cJSON_malloc(len+2); /* This is how long we need for the string, roughly. */
out=(char*)cJSON_mallocstr(len+2); /* This is how long we need for the string, roughly. */
if (!out) return 0;
ptr=str+1;ptr2=out;
@ -240,7 +273,7 @@ static char *print_string_ptr(const char *str)
if (!str) return cJSON_strdup("");
ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
out=(char*)cJSON_malloc(len+3+1);
out=(char*)cJSON_mallocstr(len+3+1);
if (!out) return 0;
ptr2=out;ptr=str;
@ -374,7 +407,7 @@ static const char *parse_array(cJSON *item,const char *value)
/* Render an array to text */
static char *print_array(cJSON *item,int32_t depth,int32_t fmt)
{
char **entries;
char **entries,*space_entries[512];
char *out=0,*ptr,*ret;int32_t len=5;
cJSON *child=item->child;
int32_t numentries=0,i=0,fail=0;
@ -384,12 +417,12 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt)
/* Explicitly handle numentries==0 */
if (!numentries)
{
out=(char*)cJSON_malloc(3+1);
out=(char*)cJSON_mallocstr(3+1);
if (out) strcpy(out,"[]");
return out;
}
/* Allocate an array to hold the values for each */
entries=(char**)cJSON_malloc((1+numentries)*sizeof(char*));
entries=cJSON_mallocptrs(1+numentries,space_entries,sizeof(space_entries)/sizeof(*space_entries));
if (!entries) return 0;
memset(entries,0,numentries*sizeof(char*));
/* Retrieve all the results: */
@ -403,15 +436,15 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt)
}
/* If we didn't fail, try to malloc the output string */
if (!fail) out=(char*)cJSON_malloc(len+1);
if (!fail) out=(char*)cJSON_mallocstr(len+1);
/* If that fails, we fail. */
if (!out) fail=1;
/* Handle failure. */
if (fail)
{
for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
cJSON_free(entries);
for (i=0;i<numentries;i++) if (entries[i]) cJSON_freestr(entries[i]);
cJSON_freeptrs(entries,numentries,space_entries);
return 0;
}
@ -422,9 +455,9 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt)
{
strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
cJSON_free(entries[i]);
cJSON_freestr(entries[i]);
}
cJSON_free(entries);
cJSON_freeptrs(entries,numentries,space_entries);
*ptr++=']';*ptr++=0;
return out;
}
@ -468,7 +501,7 @@ static const char *parse_object(cJSON *item,const char *value)
/* Render an object to text. */
static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
{
char **entries=0,**names=0;
char **entries=0,**names=0,*space_entries[512],*space_names[512];
char *out=0,*ptr,*ret,*str;int32_t len=7,i=0,j;
cJSON *child=item->child,*firstchild;
int32_t numentries=0,fail=0;
@ -487,7 +520,7 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
/* Explicitly handle empty object case */
if (!numentries)
{
out=(char*)cJSON_malloc(fmt?depth+4+1:3+1);
out=(char*)cJSON_mallocstr(fmt?depth+4+1:3+1);
if (!out) return 0;
ptr=out;*ptr++='{';
if (fmt) {*ptr++='\n';for (i=0;i<depth-1;i++) *ptr++='\t';}
@ -495,10 +528,10 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
return out;
}
/* Allocate space for the names and the objects */
entries=(char**)cJSON_malloc(numentries*sizeof(char*));
entries=(char**)cJSON_mallocptrs(numentries,space_entries,sizeof(space_entries)/sizeof(*space_entries));
if (!entries) return 0;
names=(char**)cJSON_malloc(numentries*sizeof(char*));
if (!names) {cJSON_free(entries);return 0;}
names=(char**)cJSON_mallocptrs(numentries,space_names,sizeof(space_names)/sizeof(*space_names));
if (!names) {cJSON_freeptrs(entries,numentries,space_entries);return 0;}
memset(entries,0,sizeof(char*)*numentries);
memset(names,0,sizeof(char*)*numentries);
@ -515,14 +548,15 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
}
/* Try to allocate the output string */
if (!fail) out=(char*)cJSON_malloc(len+1);
if (!fail) out=(char*)cJSON_mallocstr(len+1);
if (!out) fail=1;
/* Handle failure */
if (fail)
{
for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
cJSON_free(names);cJSON_free(entries);
for (i=0;i<numentries;i++) {if (names[i]) cJSON_freestr(names[i]);if (entries[i]) cJSON_freestr(entries[i]);}
cJSON_freeptrs(names,numentries,space_names);
cJSON_freeptrs(entries,numentries,space_entries);
return 0;
}
@ -536,10 +570,11 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
if (i!=numentries-1) *ptr++=',';
if (fmt) *ptr++='\n';*ptr=0;
cJSON_free(names[i]);cJSON_free(entries[i]);
cJSON_freestr(names[i]);cJSON_freestr(entries[i]);
}
cJSON_free(names);cJSON_free(entries);
cJSON_freeptrs(names,numentries,space_names);
cJSON_freeptrs(entries,numentries,space_entries);
if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
*ptr++='}';*ptr++=0;
return out;

2
iguana/exchanges/LP_RTmetrics.c

@ -161,7 +161,7 @@ void LP_RTmetrics_update(char *base,char *rel)
{
if ( (swaps= jarray(&numswaps,statsjson,"swaps")) != 0 )
{
printf("LP_RTmetrics_update for (%s)\n",jprint(swaps,0));
//printf("LP_RTmetrics_update for (%s)\n",jprint(swaps,0));
if ( numswaps > 0 )
LP_RTmetrics_swapsinfo(base,rel,swaps,numswaps);
}

1
iguana/exchanges/LP_commands.c

@ -36,6 +36,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r
{
char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr;
method = jstr(argjson,"method");
//printf("stats_JSON %s\n",method);
/*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) )
{
if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 )

73
iguana/exchanges/LP_nativeDEX.c

@ -19,10 +19,11 @@
//
// if ( G.LP_pendingswaps != 0 ) return(-1);
// bot safe to exit?
//
// 324744 and 50mb
// BCH signing
// single utxo allocations alice
// alice waiting for bestprice
//
// previously, it used to show amount, kmd equiv, perc
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
// bigendian architectures need to use little endian for sighash calcs
@ -117,6 +118,16 @@ struct LP_globals
struct LP_privkey LP_privkeys[100];
} G;
uint32_t LP_rand()
{
uint32_t retval;
retval = rand();
retval = (retval << 7) ^ (retval >> 17) ^ rand();
retval = (retval << 13) ^ (retval >> 13) ^ rand();
retval = (retval << 17) ^ (retval >> 7) ^ rand();
return(retval);
}
#include "LP_network.c"
char *activecoins[] = { "BTC", "KMD" };
@ -129,7 +140,6 @@ char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.25
"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" }; //
// stubs
void tradebot_swap_balancingtrade(struct basilisk_swap *swap,int32_t iambob)
@ -229,7 +239,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
dup++;
else uniq++;
portable_mutex_lock(&LP_commandmutex);
if ( (rand() % 10000) == 0 )
if ( (LP_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 )
{
@ -326,7 +336,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth)
{
int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr,*buf; char methodstr[64],*retstr,*str; struct nn_pollfd pfd;
int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd;
if ( sock >= 0 )
{
while ( nonz < maxdepth && recvlen > 0 )
@ -338,11 +348,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
if ( nn_poll(&pfd,1,1) != 1 )
break;
ptr = 0;
buf = malloc(1000000);
if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 )
//if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
//buf = malloc(1000000);
//if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 )
if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
{
ptr = buf;
//ptr = buf;
methodstr[0] = 0;
//printf("%s.(%s)\n",typestr,(char *)ptr);
if ( 0 )
@ -393,8 +403,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
}
if ( ptr != 0 )
{
//nn_freemsg(ptr), ptr = 0;
free(buf);
nn_freemsg(ptr), ptr = 0;
//free(buf);
}
}
}
@ -411,7 +421,7 @@ int32_t LP_nanomsg_recvs(void *ctx)
{
if ( peer->errors >= LP_MAXPEER_ERRORS )
{
if ( (rand() % 10000) == 0 )
if ( (LP_rand() % 10000) == 0 )
peer->errors--;
else
{
@ -767,7 +777,7 @@ void LP_pubkeysloop(void *ctx)
}
if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 )
{
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
LP_notify_pubkeys(ctx,LP_mypubsock);
lasttime = (uint32_t)time(NULL);
}
@ -784,7 +794,7 @@ void LP_privkeysloop(void *ctx)
{
LP_millistats_update(&LP_privkeysloop_stats);
LP_counter += 1000;
//printf("LP_privkeysloop %u\n",LP_counter);
//printf("LP_privkeysloop %u\n",LP_counter);
LP_privkey_updates(ctx,LP_mypubsock,0);
sleep(LP_ORDERBOOK_DURATION * .777);
}
@ -800,10 +810,9 @@ void LP_swapsloop(void *ignore)
{
LP_millistats_update(&LP_swapsloop_stats);
LP_counter += 10000;
//printf("LP_swapsloop %u\n",LP_counter);
//printf("LP_swapsloop %u\n",LP_counter);
if ( (retstr= basilisk_swapentry(0,0)) != 0 )
free(retstr);
//LP_millistats_update(0);
sleep(600);
}
}
@ -836,14 +845,14 @@ void LP_reserved_msgs(void *ignore)
if ( num_Reserved_msgs[1] > 0 )
{
num_Reserved_msgs[1]--;
//printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]);
//printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[1][num_Reserved_msgs[1]]);
Reserved_msgs[1][num_Reserved_msgs[1]] = 0;
}
else if ( num_Reserved_msgs[0] > 0 )
{
num_Reserved_msgs[0]--;
//printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]);
//printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]);
Reserved_msgs[0][num_Reserved_msgs[0]] = 0;
}
@ -879,8 +888,9 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha
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],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx();
printf("Marketmaker %s.%s %s\n",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER);
char *myipaddr=0,version[64]; 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();
sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request));
printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version)));
LP_showwif = juint(argjson,"wif");
if ( passphrase == 0 || passphrase[0] == 0 )
{
@ -896,6 +906,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
}
#endif
OS_randombytes((void *)&n,sizeof(n));
srand((uint32_t)n);
if ( jobj(argjson,"gui") != 0 )
safecopy(LP_gui,jstr(argjson,"gui"),sizeof(LP_gui));
if ( jobj(argjson,"canbind") == 0 )
@ -1205,14 +1216,14 @@ int32_t zeroval() { return(0); }
void *LP_alloc(uint64_t len)
{
return(calloc(1,len));
return(calloc(1,len));
LP_cjson_allocated += len;
LP_cjson_total += len;
LP_cjson_count++;
struct LP_memory_list *mp;
mp = calloc(1,sizeof(*mp) + len);
mp->ptr = calloc(1,len);
printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated);
//printf(">>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu %llu\n",mp,mp->ptr,(long long)len,(long long)LP_cjson_allocated);
mp->timestamp = (uint32_t)time(NULL);
mp->len = (uint32_t)len;
portable_mutex_lock(&LP_cJSONmutex);
@ -1223,21 +1234,20 @@ void *LP_alloc(uint64_t len)
void LP_free(void *ptr)
{
static uint32_t lasttime,unknown;
free(ptr);
return;
static uint32_t lasttime,unknown; static int64_t lasttotal;
free(ptr); return;
uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp;
if ( (now= (uint32_t)time(NULL)) > lasttime+60 )
if ( (now= (uint32_t)time(NULL)) > lasttime+6 )
{
n = lagging = 0;
DL_FOREACH_SAFE(LP_memory_list,mp,tmp)
{
total += mp->len;
n++;
if ( 0 && now > mp->timestamp+60 )
if ( 0 && now > mp->timestamp+120 )
{
lagging++;
if ( now > mp->timestamp+60 )
if ( now > mp->timestamp+240 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_memory_list,mp);
@ -1247,8 +1257,9 @@ void LP_free(void *ptr)
}
}
}
printf("total %d allocated total %llu/%llu [%llu %llu] %.1f ave %s unknown.%u lagging.%d\n",n,(long long)total,(long long)LP_cjson_allocated,(long long)LP_cjson_total,(long long)LP_cjson_count,(double)LP_cjson_total/LP_cjson_count,mbstr(str,total),unknown,lagging);
printf("[%lld] total %d allocated total %llu/%llu [%llu %llu] %.1f ave %s unknown.%u lagging.%d\n",(long long)(total-lasttotal),n,(long long)total,(long long)LP_cjson_allocated,(long long)LP_cjson_total,(long long)LP_cjson_count,(double)LP_cjson_total/LP_cjson_count,mbstr(str,total),unknown,lagging);
lasttime = (uint32_t)time(NULL);
lasttotal = total;
}
DL_FOREACH_SAFE(LP_memory_list,mp,tmp)
{
@ -1262,13 +1273,13 @@ void LP_free(void *ptr)
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_memory_list,mp);
portable_mutex_unlock(&LP_cJSONmutex);
printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated);
//printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u %llu\n",ptr,mp,mp->len,(long long)LP_cjson_allocated);
free(mp->ptr);
free(mp);
} else unknown++; // free from source file with #define redirect for alloc that wasnt
}
char *LP_clonestr(char *str)
/*char *LP_clonestr(char *str)
{
char *retstr = LP_alloc(strlen(str)+1);
strcpy(retstr,str);
@ -1278,6 +1289,6 @@ char *LP_clonestr(char *str)
void *LP_realloc(void *ptr,uint64_t len)
{
return(realloc(ptr,len));
}
}*/

10
iguana/exchanges/LP_network.c

@ -183,7 +183,7 @@ bits256 LP_calc_magic(uint8_t *msg,int32_t len)
sum += (OS_milliseconds() - millis);
nsum += n;
counter++;
if ( n > maxn || (rand() % 10000) == 0 )
if ( n > maxn || (LP_rand() % 10000) == 0 )
{
if ( n > maxn )
{
@ -237,7 +237,7 @@ int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32)
break;
}
if ( i >= sizeof(crcs)/sizeof(*crcs) )
i = (rand() % (sizeof(crcs)/sizeof(*crcs)));
i = (LP_rand() % (sizeof(crcs)/sizeof(*crcs)));
return(i);
}
else
@ -316,7 +316,7 @@ void queue_loop(void *arg)
flag = 0;
if ( ptr->sock >= 0 )
{
if ( ptr->notready == 0 || (rand() % ptr->notready) == 0 )
if ( ptr->notready == 0 || (LP_rand() % ptr->notready) == 0 )
{
if ( LP_sockcheck(ptr->sock) > 0 )
{
@ -387,11 +387,11 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32
if ( sock0 < 0 && sock1 < 0 )
{
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind) + 1;
peerind = (LP_rand() % maxind) + 1;
else peerind = 1;
sock0 = LP_peerindsock(&peerind);
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind) + 1;
peerind = (LP_rand() % maxind) + 1;
else peerind = 1;
sock1 = LP_peerindsock(&peerind);
}

19
iguana/exchanges/LP_ordermatch.c

@ -52,7 +52,7 @@ double LP_bob_competition(int32_t *counterp,uint64_t aliceid,double price,int32_
firsti = i;
}
if ( firsti < 0 )
firsti = (rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition)));
firsti = (LP_rand() % (sizeof(Bob_competition)/sizeof(*Bob_competition)));
Bob_competition[firsti].starttime = (uint32_t)time(NULL);
Bob_competition[firsti].counter = counter;
Bob_competition[firsti].aliceid = aliceid;
@ -252,7 +252,7 @@ int32_t LP_nanobind(void *ctx,char *pairstr)
{
for (i=0; i<10; i++)
{
r = (10000 + (rand() % 50000)) & 0xffff;
r = (10000 + (LP_rand() % 50000)) & 0xffff;
if ( LP_fixed_pairport != 0 )
r = LP_fixed_pairport;
nanomsg_transportname(0,pairstr,LP_myipaddr,r);
@ -572,6 +572,8 @@ char *LP_connectedalice(cJSON *argjson) // alice
return(clonestr("{\"result\",\"update stats\"}"));
}
printf("CONNECTED.(%s) numpending.%d tradeid.%u requestid.%u quoteid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid,Q.R.requestid,Q.R.quoteid);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
printf("calculated requestid.%u quoteid.%u\n",Q.R.requestid,Q.R.quoteid);
if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid);
@ -585,12 +587,6 @@ char *LP_connectedalice(cJSON *argjson) // alice
LP_aliceid(Q.tradeid,Q.aliceid,"error2",0,0);
return(clonestr("{\"error\":\"cant find autxo\"}"));
}
/*if ( autxo->S.swap != 0 )
{
printf("ignore duplicate swap\n");
LP_aliceid(Q.tradeid,Q.aliceid,"error3",0,0);
return(clonestr("{\"error\":\"ignore duplicate swap\"}"));
}*/
LP_aliceid(Q.tradeid,Q.aliceid,"connected",Q.R.requestid,Q.R.quoteid);
butxo = &B;
memset(butxo,0,sizeof(*butxo));
@ -622,7 +618,6 @@ char *LP_connectedalice(cJSON *argjson) // alice
if ( bits256_nonz(Q.privkey) != 0 )//&& Q.quotetime >= Q.timestamp-3 )
{
retjson = cJSON_CreateObject();
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 )
{
jaddstr(retjson,"error","couldnt swapinit");
@ -771,7 +766,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
LP_quoteparse(&Q,argjson);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
LP_tradecommand_log(argjson);
printf("LP_tradecommand: received %12s aliceid.%22llu %5s/%-5s %12.8f -> %12.8f price %12.8f\n",method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis);
printf("(%-10u %10u) %12s aliceid.%22llu %5s/%-5s %12.8f -> %12.8f price %12.8f\n",Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis);
retval = 1;
autxo = &A;
butxo = &B;
@ -884,12 +879,12 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
} else return(retval);
if ( qprice > price )
{
r = (rand() % 100);
r = (LP_rand() % 100);
range = (qprice - price);
price += (r * range) / 100.;
bestprice = LP_bob_competition(&counter,aliceid,price,0);
printf(">>>>>>>>>>>>> price %.8f qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",ask,qprice,r,range,price,bestprice,counter);
if ( counter > 5 || price > bestprice*1.1 ) // skip if late or bad price
if ( counter > 3 || price > bestprice ) // skip if late or bad price
return(retval);
} else return(retval);
LP_RTmetrics_update(Q.srccoin,Q.destcoin);

2
iguana/exchanges/LP_peers.c

@ -235,7 +235,7 @@ uint16_t LP_randpeer(char *destip)
numpeers = LP_numpeers();
if ( numpeers > 0 )
{
r = rand() % numpeers;
r = LP_rand() % numpeers;
n = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{

2
iguana/exchanges/LP_prices.c

@ -1070,7 +1070,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price)
}
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
if ( (rand() % 1000) == 0 )
if ( (LP_rand() % 1000) == 0 )
printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price);
pubp->timestamp = (uint32_t)time(NULL);
if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL )

23
iguana/exchanges/LP_remember.c

@ -1247,29 +1247,6 @@ char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid)
if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid)) != 0 )
return(jprint(item,1));
else return(clonestr("{\"error\":\"cant find requestid-quoteid\"}"));
/*if ( (liststr= basilisk_swaplist(requestid,quoteid)) != 0 )
{
//printf("swapentry.(%s)\n",liststr);
if ( (retjson= cJSON_Parse(liststr)) != 0 )
{
if ( (array= jarray(&n,retjson,"swaps")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
//printf("(%s) check r%u/q%u\n",jprint(item,0),juint(item,"requestid"),juint(item,"quoteid"));
if ( juint(item,"requestid") == requestid && juint(item,"quoteid") == quoteid )
{
retstr = jprint(item,0);
break;
}
}
}
free_json(retjson);
}
free(liststr);
}
return(retstr);*/
}
extern struct LP_quoteinfo LP_Alicequery;

65
iguana/exchanges/LP_rpc.c

@ -115,7 +115,7 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
void LP_unspents_mark(char *symbol,cJSON *vins)
{
printf("LOCK (%s)\n",jprint(vins,0));
//printf("LOCK (%s)\n",jprint(vins,0));
}
char *NXTnodes[] = { "62.75.159.113", "91.44.203.238", "82.114.88.225", "78.63.207.76", "188.174.110.224", "91.235.72.49", "213.144.130.91", "209.222.98.250", "216.155.128.10", "178.33.203.157", "162.243.122.251", "69.163.47.173", "193.151.106.129", "78.94.2.74", "192.3.196.10", "173.33.112.87", "104.198.173.28", "35.184.154.126", "174.140.167.239", "23.88.113.131", "198.71.84.173", "178.150.207.53", "23.88.61.53", "192.157.233.106", "192.157.241.212", "23.89.192.88", "23.89.200.27", "192.157.241.139", "23.89.200.63", "23.89.192.98", "163.172.214.102", "176.9.85.5", "80.150.243.88", "80.150.243.92", "80.150.243.98", "109.70.186.198", "146.148.84.237", "104.155.56.82", "104.197.157.140", "37.48.73.249", "146.148.77.226", "84.57.170.200", "107.161.145.131", "80.150.243.97", "80.150.243.93", "80.150.243.100", "80.150.243.95", "80.150.243.91", "80.150.243.99", "80.150.243.96", "93.231.187.177", "212.237.23.85", "35.158.179.254", "46.36.66.41", "185.170.113.79", "163.172.68.112", "78.47.35.210", "77.90.90.75", "94.177.196.134", "212.237.22.215", "94.177.234.11", "167.160.180.199", "54.68.189.9", "94.159.62.14", "195.181.221.89", "185.33.145.94", "195.181.209.245", "195.181.221.38", "195.181.221.162", "185.33.145.12", "185.33.145.176", "178.79.128.235", "94.177.214.120", "94.177.199.41", "94.177.214.200", "94.177.213.201", "212.237.13.162", "195.181.221.236", "195.181.221.185", "185.28.103.187", "185.33.146.244", "217.61.123.71", "195.181.214.45", "195.181.212.99", "195.181.214.46", "195.181.214.215", "195.181.214.68", "217.61.123.118", "195.181.214.79", "217.61.123.14", "217.61.124.100", "195.181.214.111", "85.255.0.176", "81.2.254.116", "217.61.123.184", "195.181.212.231", "94.177.214.110", "195.181.209.164", "104.129.56.238", "85.255.13.64", "167.160.180.206", "217.61.123.226", "167.160.180.208", "93.186.253.127", "212.237.6.208", "94.177.207.190", "217.61.123.119", "85.255.1.245", "217.61.124.157", "37.59.57.141", "167.160.180.58", "104.223.53.14", "217.61.124.69", "195.181.212.103", "85.255.13.141", "104.207.133.204", "71.90.7.107", "107.150.18.108", "23.94.134.161", "80.150.243.13", "80.150.243.11", "185.81.165.52", "80.150.243.8" };
@ -314,13 +314,13 @@ char *account = "NXT-MRBN-8DFH-PFMK-A4DBM";
cJSON *LP_assethbla(char *assetid)
{
char url[1024],*retstr; int32_t n; cJSON *array,*bid=0,*ask=0,*retjson;
sprintf(url,"http://%s:7876/nxt?requestType=getBidOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid);
sprintf(url,"http://%s:7876/nxt?requestType=getBidOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[LP_rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid);
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 )
{
bid = cJSON_Parse(retstr);
free(retstr);
}
sprintf(url,"http://%s:7876/nxt?requestType=getAskOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid);
sprintf(url,"http://%s:7876/nxt?requestType=getAskOrders&asset=%s&firstIndex=0&lastIndex=0",NXTnodes[LP_rand() % (sizeof(NXTnodes)/sizeof(*NXTnodes))],assetid);
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 )
{
ask = cJSON_Parse(retstr);
@ -866,6 +866,7 @@ char *LP_sendrawtransaction(char *symbol,char *signedtx)
errobj = cJSON_CreateObject();
jaddstr(errobj,"error","rejected");
jaddnum(errobj,"code",-27);
free(retstr);
retstr = jprint(errobj,1);
}
else
@ -922,36 +923,38 @@ char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON *
return(jprint(retjson,1));
}
return(signedtx);
array = cJSON_CreateArray();
jaddistr(array,rawtx);
jaddi(array,jduplicate(vins));
jaddi(array,jduplicate(privkeys));
paramstr = jprint(array,1);
//printf("signrawtransaction\n");
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"signrawtransaction",paramstr)) != 0 )
if ( (0) )
{
if ( (json= cJSON_Parse(retstr)) != 0 )
array = cJSON_CreateArray();
jaddistr(array,rawtx);
jaddi(array,jduplicate(vins));
jaddi(array,jduplicate(privkeys));
paramstr = jprint(array,1);
//printf("signrawtransaction\n");
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"signrawtransaction",paramstr)) != 0 )
{
if ( (hexstr= jstr(json,"hex")) != 0 )
if ( (json= cJSON_Parse(retstr)) != 0 )
{
len = (int32_t)strlen(hexstr);
signedtx = calloc(1,len+1);
strcpy(signedtx,hexstr);
*completedp = is_cJSON_True(jobj(json,"complete"));
len >>= 1;
data = malloc(len);
decode_hex(data,len,hexstr);
*signedtxidp = bits256_doublesha256(0,data,len);
if ( (hexstr= jstr(json,"hex")) != 0 )
{
len = (int32_t)strlen(hexstr);
signedtx = calloc(1,len+1);
strcpy(signedtx,hexstr);
*completedp = is_cJSON_True(jobj(json,"complete"));
len >>= 1;
data = malloc(len);
decode_hex(data,len,hexstr);
*signedtxidp = bits256_doublesha256(0,data,len);
}
//else
printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr);
free_json(json);
}
//else
printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr);
free_json(json);
free(retstr);
}
free(retstr);
free(paramstr);
return(signedtx);
}
free(paramstr);
return(signedtx);
}
cJSON *LP_getblock(char *symbol,bits256 txid)
@ -1032,7 +1035,7 @@ uint32_t LP_heighttime(char *symbol,int32_t height)
{
if ( (retjson= cJSON_Parse(blockhashstr)) != 0 )
{
printf("height.(%s)\n",jprint(retjson,0));
//printf("height.(%s)\n",jprint(retjson,0));
timestamp = juint(retjson,"time");
free_json(retjson);
}
@ -1043,7 +1046,7 @@ uint32_t LP_heighttime(char *symbol,int32_t height)
{
if ( (retjson= electrum_getheader(coin->symbol,ep,&retjson,height)) != 0 )
{
printf("%s\n",jprint(retjson,0));
//printf("%s\n",jprint(retjson,0));
timestamp = juint(retjson,"timestamp");
free_json(retjson);
}
@ -1074,7 +1077,7 @@ cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t hei
*heightp = juint(json,"height");
if ( height >= 0 && *heightp != height )
{
printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0));
//printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0));
*heightp = -1;
free_json(json);
json = 0;
@ -1255,7 +1258,7 @@ int32_t LP_notarization_latest(int32_t *bestheightp,struct iguana_info *coin)
blockhash = jbits256(blockjson,"previousblockhash");
if ( bits256_nonz(blockhash) == 0 )
{
printf("null prev.(%s)\n",jprint(blockjson,0));
//printf("null prev.(%s)\n",jprint(blockjson,0));
free_json(blockjson);
break;
}

2
iguana/exchanges/LP_scan.c

@ -466,7 +466,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
{
if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 )
{
char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0));
//char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)

11
iguana/exchanges/LP_signatures.c

@ -132,14 +132,16 @@ int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson)
qp->R.quoteid = juint(argjson,"quoteid");
if ( qp->R.requestid == 0 )
{
rid= basilisk_requestid(&qp->R);
//printf("requestid.%u -> %u\n",qp->R.requestid,rid);
rid = basilisk_requestid(&qp->R);
if ( qp->R.requestid != 0 && qp->R.requestid != rid )
printf("requestid.%u -> %u\n",qp->R.requestid,rid);
qp->R.requestid = rid;
}
if ( qp->R.quoteid == 0 )
{
qid= basilisk_quoteid(&qp->R);
//printf("quoteid.%u -> %u\n",qp->R.quoteid,qid);
qid = basilisk_quoteid(&qp->R);
if ( qp->R.quoteid != 0 && qp->R.quoteid != qid )
printf("quoteid.%u -> %u\n",qp->R.quoteid,qid);
qp->R.quoteid = qid;
}
return(0);
@ -614,6 +616,7 @@ char *LP_notify_recv(cJSON *argjson)
void LP_smartutxos_push(struct iguana_info *coin)
{
uint64_t value; bits256 zero,txid; int32_t i,vout,height,n; cJSON *array,*item,*req;
return;
if ( coin->smartaddr[0] == 0 )
return;
//LP_notify_pubkeys(coin->ctx,LP_mypubsock);

9
iguana/exchanges/LP_socket.c

@ -272,7 +272,7 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep)
ep = recent_ep;
if ( n > 0 )
{
i = (rand() % n);
i = (LP_rand() % n);
ep = rbuf[i];
}
}
@ -513,7 +513,7 @@ cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON **
cJSON *retjson;
if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.subscribe",addr,ELECTRUM_TIMEOUT)) != 0 )
{
printf("subscribe.(%s)\n",jprint(retjson,0));
//printf("subscribe.(%s)\n",jprint(retjson,0));
}
return(retjson);
}
@ -602,7 +602,10 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON
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), updatedflag = 1;
{
//LP_postutxos(coin->symbol,addr);
updatedflag = 1;
}
if ( strcmp(addr,coin->smartaddr) == 0 )
{
retstr = jprint(retjson,0);

122
iguana/exchanges/LP_statemachine.c

@ -132,6 +132,18 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil
}*/
return(fp);
}
//printf("VOUT.(%s)\n",jprint(vout,0));
/*if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 )
{
item = jitem(addresses,0);
//printf("item.(%s)\n",jprint(item,0));
if ( (addr= jstr(item,0)) != 0 )
{
safecopy(coinaddr,addr,64);
//printf("extracted.(%s)\n",coinaddr);
}
}*/
/*if ( IAMLP != 0 && time(NULL) > lasthello+600 )
{
char *hellostr,*retstr; cJSON *retjson; int32_t allgood,sock = LP_bindsock;
@ -174,7 +186,7 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil
{
if ( peer->errors >= LP_MAXPEER_ERRORS )
{
if ( (rand() % 10000) == 0 )
if ( (LP_rand() % 10000) == 0 )
{
peer->errors--;
if ( peer->errors < LP_MAXPEER_ERRORS )
@ -183,7 +195,7 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil
if ( IAMLP == 0 )
continue;
}
if ( now > peer->lastpeers+LP_ORDERBOOK_DURATION*.777 || (rand() % 100000) == 0 )
if ( now > peer->lastpeers+LP_ORDERBOOK_DURATION*.777 || (LP_rand() % 100000) == 0 )
{
if ( strcmp(peer->ipaddr,myipaddr) != 0 )
{
@ -229,7 +241,7 @@ int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipa
if ( (peer= LP_peerfind(argipbits,argport)) == 0 )
{
numpeers = LP_numpeers();
if ( IAMLP != 0 || numpeers < LP_MIN_PEERS || (IAMLP == 0 && (rand() % LP_MAX_PEERS) > numpeers) )
if ( IAMLP != 0 || numpeers < LP_MIN_PEERS || (IAMLP == 0 && (LP_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 )
@ -347,6 +359,94 @@ void issue_LP_uitem(char *destip,uint16_t destport,char *symbol,char *coinaddr,b
return(retstr);*/
}
/*if ( (liststr= basilisk_swaplist(requestid,quoteid)) != 0 )
{
//printf("swapentry.(%s)\n",liststr);
if ( (retjson= cJSON_Parse(liststr)) != 0 )
{
if ( (array= jarray(&n,retjson,"swaps")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
//printf("(%s) check r%u/q%u\n",jprint(item,0),juint(item,"requestid"),juint(item,"quoteid"));
if ( juint(item,"requestid") == requestid && juint(item,"quoteid") == quoteid )
{
retstr = jprint(item,0);
break;
}
}
}
free_json(retjson);
}
free(liststr);
}
return(retstr);*/
/*struct cJSON_list
{
struct cJSON_list *next,*prev;
cJSON *item;
uint32_t timestamp,cjsonid;
} *LP_cJSONlist;
void cJSON_register(cJSON *item)
{
struct cJSON_list *ptr;
ptr = calloc(1,sizeof(*ptr));
ptr->timestamp = (uint32_t)time(NULL);
ptr->item = item;
item->cjsonid = LP_rand();
ptr->cjsonid = item->cjsonid;
portable_mutex_lock(&LP_cJSONmutex);
DL_APPEND(LP_cJSONlist,ptr);
portable_mutex_unlock(&LP_cJSONmutex);
}
void cJSON_unregister(cJSON *item)
{
static uint32_t lasttime;
int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now;
if ( (now= (uint32_t)time(NULL)) > lasttime+6 )
{
n = 0;
DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp)
{
if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 )
{
if ( (tmpstr= jprint(ptr->item,0)) != 0 )
{
total += strlen(tmpstr);
free(tmpstr);
}
}
n++;
}
printf("total %d cJSON pending\n",n);
lasttime = (uint32_t)time(NULL);
}
DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp)
{
if ( ptr->cjsonid == item->cjsonid )
break;
else if ( now > ptr->timestamp+60 && item->cjsonid != 0 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_cJSONlist,ptr);
portable_mutex_unlock(&LP_cJSONmutex);
printf("free expired\n");
cJSON_Delete(ptr->item);
free(ptr);
}
ptr = 0;
}
if ( ptr != 0 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_cJSONlist,ptr);
free(ptr);
portable_mutex_unlock(&LP_cJSONmutex);
} //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid);
}*/
char *issue_LP_getprices(char *destip,uint16_t destport)
{
char url[512];
@ -855,7 +955,7 @@ int32_t _basilisk_rawtx_gen(char *str,uint32_t swapstarted,uint8_t *pubkey33,int
{
char scriptstr[1024],wifstr[256],coinaddr[64],*signedtx,*rawtxbytes; uint32_t basilisktag; int32_t retval = -1; cJSON *vins,*privkeys,*addresses,*valsobj; struct vin_info *V;
init_hexbytes_noT(scriptstr,script,scriptlen);
basilisktag = (uint32_t)rand();
basilisktag = (uint32_t)LP_rand();
valsobj = cJSON_CreateObject();
jaddstr(valsobj,"coin",rawtx->coin->symbol);
jaddstr(valsobj,"spendscript",scriptstr);
@ -1095,7 +1195,7 @@ int32_t basilisk_swapiteration(struct basilisk_swap *swap,uint8_t *data,int32_t
basilisk_swap_saveupdate(swap);
if ( swap->connected == 0 )
basilisk_psockinit(swap,swap->I.iambob != 0);
//if ( (rand() % 30) == 0 )
//if ( (LP_rand() % 30) == 0 )
printf("E r%u/q%u swapstate.%x otherstate.%x remaining %d\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,swap->I.otherstatebits,(int32_t)(swap->I.expiration-time(NULL)));
if ( swap->I.iambob != 0 )
{
@ -1269,7 +1369,7 @@ int32_t basilisk_swapiteration(struct basilisk_swap *swap,uint8_t *data,int32_t
}
}
}
if ( (rand() % 30) == 0 )
if ( (LP_rand() % 30) == 0 )
printf("finished swapstate.%x other.%x\n",swap->I.statebits,swap->I.otherstatebits);
if ( swap->I.statebits == savestatebits && swap->I.otherstatebits == saveotherbits )
sleep(DEX_SLEEP + (swap->I.iambob == 0)*1);
@ -1665,7 +1765,7 @@ void basilisk_swaploop(void *_utxo)
else tradebot_pendingadd(swapjson(swap),swap->I.req.dest,dstr(swap->I.req.destamount),swap->I.req.src,dstr(swap->I.req.srcamount));
}
printf("%s swap finished statebits %x\n",swap->I.iambob!=0?"BOB":"ALICE",swap->I.statebits);
//basilisk_swap_purge(swap);
basilisk_swap_purge(swap);
free(data);
}
#endif
@ -2692,7 +2792,7 @@ void LP_price_broadcastloop(void *ctx)
minprice = LP_pricevol_invert(&basevol,bot->maxprice,bot->totalrelvolume - bot->relsum);
printf("simulated trade sell %s/%s minprice %.8f volume %.8f, %.8f %s -> %s price %.8f relvol %.8f\n",bot->rel,bot->base,minprice,basevol,v,bot->base,bot->rel,p,relvol);
}
if ( (rand() % 2) == 0 )
if ( (LP_rand() % 2) == 0 )
{
bot->relsum += relvol;
bot->basesum += v;
@ -2709,7 +2809,7 @@ void LP_price_broadcastloop(void *ctx)
#ifdef FROM_JS
int32_t sentbytes,sock,peerind,maxind;
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind) + 1;
peerind = (LP_rand() % maxind) + 1;
else peerind = 1;
sock = LP_peerindsock(&peerind);
if ( sock >= 0 )
@ -2751,11 +2851,11 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32
else
{
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind) + 1;
peerind = (LP_rand() % maxind) + 1;
else peerind = 1;
sock0 = LP_peerindsock(&peerind);
if ( (maxind= LP_numpeers()) > 0 )
peerind = (rand() % maxind) + 1;
peerind = (LP_rand() % maxind) + 1;
else peerind = 1;
sock1 = LP_peerindsock(&peerind);
}

8
iguana/exchanges/LP_swap.c

@ -112,7 +112,7 @@
void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx)
{
if ( rawtx->vins != 0 )
free_json(rawtx->vins);
free_json(rawtx->vins), rawtx->vins = 0;
//if ( rawtx->txbytes != 0 )
// free(rawtx->txbytes), rawtx->txbytes = 0;
}
@ -831,7 +831,7 @@ void LP_bobloop(void *_swap)
}
}
basilisk_swap_finished(swap);
//free(swap);
free(swap);
} else printf("swap timed out\n");
G.LP_pendingswaps--;
}
@ -1127,7 +1127,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->I.aliceconfirms = swap->I.alicemaxconfirms;
swap->I.bobconfirms *= !swap->I.bobistrusted;
swap->I.aliceconfirms *= !swap->I.aliceistrusted;
printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr);
printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< r.%u q.%u, %.8f bobconfs.%d, %.8f aliceconfs.%d taddr.%d %d\n",jumblrflag,swap->I.req.requestid,swap->I.req.quoteid,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms,bobcoin->taddr,alicecoin->taddr);
if ( swap->I.iambob != 0 )
{
basilisk_rawtx_setparms("myfee",swap->I.req.quoteid,&swap->myfee,bobcoin,0,0,LP_DEXFEE(swap->I.bobsatoshis) + 0*bobcoin->txfee,0,0,jumblrflag);
@ -1189,7 +1189,7 @@ struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256
G.LP_skipstatus[G.LP_numskips] = ((uint64_t)rp->requestid << 32) | rp->quoteid;
if ( G.LP_numskips < sizeof(G.LP_skipstatus)/sizeof(*G.LP_skipstatus) )
G.LP_numskips++;
printf("basilisk_thread_start request.%u iambob.%d (%s/%s) quoteid.%u\n",rp->requestid,iambob,rp->src,rp->dest,rp->quoteid);
printf("LP_swapinit request.%u iambob.%d (%s/%s) quoteid.%u\n",rp->requestid,iambob,rp->src,rp->dest,rp->quoteid);
bitcoin_pubkey33(swap->ctx,pubkey33,privkey);
pubkey25519 = curve25519(privkey,curve25519_basepoint9());
swap->persistent_pubkey = pubkey25519;

2
iguana/exchanges/LP_tradebots.c

@ -324,7 +324,7 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot)
printf("try autobuy %s/%s remaining %.8f maxprice %.8f maxrel %.8f\n",bot->base,bot->rel,remaining,bot->maxprice,maxrel);
if ( maxrel < remaining )
remaining = maxrel;
tradeid = rand();
tradeid = LP_rand();
for (i=1; i<=maxiters; i++)
{
if ( remaining < 0.001 )

11
iguana/exchanges/LP_transaction.c

@ -1651,17 +1651,6 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u
vout = jitem(vouts,v);
if ( valuep != 0 )
*valuep = LP_value_extract(vout,1);
//printf("VOUT.(%s)\n",jprint(vout,0));
/*if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 )
{
item = jitem(addresses,0);
//printf("item.(%s)\n",jprint(item,0));
if ( (addr= jstr(item,0)) != 0 )
{
safecopy(coinaddr,addr,64);
//printf("extracted.(%s)\n",coinaddr);
}
}*/
LP_destaddr(coinaddr,vout);
}
free_json(txobj);

66
iguana/exchanges/LP_utxo.c

@ -27,72 +27,6 @@ struct LP_inuse_info
} LP_inuse[1024];
int32_t LP_numinuse;
/*struct cJSON_list
{
struct cJSON_list *next,*prev;
cJSON *item;
uint32_t timestamp,cjsonid;
} *LP_cJSONlist;
void cJSON_register(cJSON *item)
{
struct cJSON_list *ptr;
ptr = calloc(1,sizeof(*ptr));
ptr->timestamp = (uint32_t)time(NULL);
ptr->item = item;
item->cjsonid = rand();
ptr->cjsonid = item->cjsonid;
portable_mutex_lock(&LP_cJSONmutex);
DL_APPEND(LP_cJSONlist,ptr);
portable_mutex_unlock(&LP_cJSONmutex);
}
void cJSON_unregister(cJSON *item)
{
static uint32_t lasttime;
int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now;
if ( (now= (uint32_t)time(NULL)) > lasttime+6 )
{
n = 0;
DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp)
{
if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 )
{
if ( (tmpstr= jprint(ptr->item,0)) != 0 )
{
total += strlen(tmpstr);
free(tmpstr);
}
}
n++;
}
printf("total %d cJSON pending\n",n);
lasttime = (uint32_t)time(NULL);
}
DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp)
{
if ( ptr->cjsonid == item->cjsonid )
break;
else if ( now > ptr->timestamp+60 && item->cjsonid != 0 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_cJSONlist,ptr);
portable_mutex_unlock(&LP_cJSONmutex);
printf("free expired\n");
cJSON_Delete(ptr->item);
free(ptr);
}
ptr = 0;
}
if ( ptr != 0 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_cJSONlist,ptr);
free(ptr);
portable_mutex_unlock(&LP_cJSONmutex);
} //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid);
}*/
struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout)
{
int32_t i;

8
iguana/exchanges/LP_utxos.c

@ -700,7 +700,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri
}
}
free_json(array);
if ( flag != 0 )
if ( 0 && flag != 0 )
LP_postutxos(coin->symbol,coin->smartaddr);
}
if ( values != 0 )
@ -848,8 +848,10 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase)
else if ( IAMLP == 0 || coin->inactive == 0 )
{
//printf("from updates %s\n",coin->symbol);
if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (rand() % 10) == 0 )
LP_postutxos(coin->symbol,coin->smartaddr);
if ( LP_privkey_init(pubsock,coin,G.LP_privkey,G.LP_mypub25519) == 0 && (LP_rand() % 10) == 0 )
{
//LP_postutxos(coin->symbol,coin->smartaddr);
}
}
}
}

Loading…
Cancel
Save