Browse Source

Test

etomic
jl777 8 years ago
parent
commit
47ec0d31a9
  1. 29
      iguana/exchanges/LP_bitcoin.c
  2. 12
      iguana/exchanges/LP_commands.c
  3. 8
      iguana/exchanges/LP_forwarding.c
  4. 6
      iguana/exchanges/LP_include.h
  5. 46
      iguana/exchanges/LP_nativeDEX.c
  6. 8
      iguana/exchanges/LP_network.c
  7. 30
      iguana/exchanges/LP_ordermatch.c
  8. 8
      iguana/exchanges/LP_utxos.c
  9. 24
      iguana/exchanges/mm.c
  10. 9
      iguana/exchanges/stats.c

29
iguana/exchanges/LP_bitcoin.c

@ -2055,7 +2055,7 @@ int32_t bitcoin_addr2rmd160(uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],
} }
for (i=0; i<len; i++) for (i=0; i<len; i++)
printf("%02x ",buf[i]); printf("%02x ",buf[i]);
char str[65]; printf("\nhex checkhash.(%s) len.%d mismatch %02x %02x %02x %02x vs %02x %02x %02x %02x (%s)\n",coinaddr,len,buf[len-1]&0xff,buf[len-2]&0xff,buf[len-3]&0xff,buf[len-4]&0xff,hash.bytes[31],hash.bytes[30],hash.bytes[29],hash.bytes[28],bits256_str(str,hash)); char str[65]; printf("\ntaddr.%02x checkhash.(%s) len.%d mismatch %02x %02x %02x %02x vs %02x %02x %02x %02x (%s)\n",taddr,coinaddr,len,buf[len-1]&0xff,buf[len-2]&0xff,buf[len-3]&0xff,buf[len-4]&0xff,hash.bytes[31],hash.bytes[30],hash.bytes[29],hash.bytes[28],bits256_str(str,hash));
} }
} }
return(0); return(0);
@ -2087,6 +2087,33 @@ char *bitcoin_address(char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pub
return(coinaddr); return(coinaddr);
} }
void iguana_priv2pub(void *ctx,uint8_t *pubkey33,char *coinaddr,bits256 privkey,uint8_t taddr,uint8_t addrtype)
{
bits256 pub; //char privstr[65],url[512],postdata[1024],*retstr,*pubstr,*addr; cJSON *retjson;
memset(pubkey33,0,33);
coinaddr[0] = 0;
crypto_box_priv2pub(pub.bytes,privkey.bytes);
//jaddbits256(retjson,"curve25519",pub);
bitcoin_pubkey33(ctx,pubkey33,privkey);
bitcoin_address(coinaddr,taddr,addrtype,pubkey33,33);
/*bits256_str(privstr,privkey);
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"SuperNET\",\"method\":\"priv2pub\",\"privkey\":\"%s\",\"addrtype\":%u,\"taddr\":%u}",privstr,addrtype,taddr);
if ( (retstr= bitcoind_RPC(0,"SuperNET",url,0,"priv2pub",postdata,0)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (pubstr= jstr(retjson,"secp256k1")) != 0 && strlen(pubstr) == 66 )
decode_hex(pubkey33,33,pubstr);
if ( (addr= jstr(retjson,"result")) != 0 && strlen(addr) < 64 )
strcpy(coinaddr,addr);
free_json(retjson);
}
free(retstr);
}*/
}
int32_t bitcoin_validaddress(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *coinaddr) int32_t bitcoin_validaddress(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *coinaddr)
{ {
uint8_t rmd160[20],addrtype; char checkaddr[128]; uint8_t rmd160[20],addrtype; char checkaddr[128];

12
iguana/exchanges/LP_commands.c

@ -19,7 +19,7 @@
// //
char *stats_JSON(char *myipaddr,int32_t pubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
{ {
char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson; struct iguana_info *ptr; char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson; struct iguana_info *ptr;
if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 )
@ -109,7 +109,7 @@ forwardhex(pubkey,hex)\n\
{ {
if ( LP_mypriceset(base,rel,price) < 0 ) if ( LP_mypriceset(base,rel,price) < 0 )
return(clonestr("{\"error\":\"couldnt set price\"}")); return(clonestr("{\"error\":\"couldnt set price\"}"));
else return(LP_pricepings(myipaddr,LP_mypubsock,profitmargin,base,rel,price * LP_profitratio)); else return(LP_pricepings(ctx,myipaddr,LP_mypubsock,profitmargin,base,rel,price * LP_profitratio));
} else return(clonestr("{\"error\":\"no price\"}")); } else return(clonestr("{\"error\":\"no price\"}"));
} }
else if ( strcmp(method,"myprice") == 0 ) else if ( strcmp(method,"myprice") == 0 )
@ -131,7 +131,7 @@ forwardhex(pubkey,hex)\n\
{ {
printf("price set (%s/%s) <- %.8f\n",rel,base,1./price); printf("price set (%s/%s) <- %.8f\n",rel,base,1./price);
LP_mypriceset(rel,base,1./price); LP_mypriceset(rel,base,1./price);
return(LP_autotrade(myipaddr,pubsock,profitmargin,base,rel,price,jdouble(argjson,"volume"),jint(argjson,"timeout"))); return(LP_autotrade(ctx,myipaddr,pubsock,profitmargin,base,rel,price,jdouble(argjson,"volume"),jint(argjson,"timeout")));
} else return(clonestr("{\"error\":\"no price set\"}")); } else return(clonestr("{\"error\":\"no price set\"}"));
} }
} }
@ -156,7 +156,7 @@ forwardhex(pubkey,hex)\n\
struct iguana_info *ptr; bits256 privkey,pubkey; uint8_t pubkey33[33]; struct iguana_info *ptr; bits256 privkey,pubkey; uint8_t pubkey33[33];
if ( (ptr= LP_coinfind(coin)) != 0 ) if ( (ptr= LP_coinfind(coin)) != 0 )
{ {
privkey = LP_privkeycalc(pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR); privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR);
//LP_utxopurge(0); //LP_utxopurge(0);
LP_privkey_init(-1,ptr,privkey,pubkey,pubkey33); LP_privkey_init(-1,ptr,privkey,pubkey,pubkey33);
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
@ -205,7 +205,7 @@ forwardhex(pubkey,hex)\n\
if ( (reqjson= LP_dereference(argjson,"forward")) != 0 ) if ( (reqjson= LP_dereference(argjson,"forward")) != 0 )
{ {
//printf("FORWARDED.(%s)\n",jprint(argjson,0)); //printf("FORWARDED.(%s)\n",jprint(argjson,0));
if ( LP_forward(myipaddr,pubsock,profitmargin,jbits256(argjson,"pubkey"),jprint(reqjson,1),1) > 0 ) if ( LP_forward(ctx,myipaddr,pubsock,profitmargin,jbits256(argjson,"pubkey"),jprint(reqjson,1),1) > 0 )
retstr = clonestr("{\"result\":\"success\"}"); retstr = clonestr("{\"result\":\"success\"}");
else retstr = clonestr("{\"error\":\"error forwarding\"}"); else retstr = clonestr("{\"error\":\"error forwarding\"}");
} else retstr = clonestr("{\"error\":\"cant recurse forwards\"}"); } else retstr = clonestr("{\"error\":\"cant recurse forwards\"}");
@ -237,7 +237,7 @@ forwardhex(pubkey,hex)\n\
else if ( strcmp(method,"lookup") == 0 ) else if ( strcmp(method,"lookup") == 0 )
return(LP_lookup(jbits256(argjson,"client"))); return(LP_lookup(jbits256(argjson,"client")));
else if ( strcmp(method,"forwardhex") == 0 ) else if ( strcmp(method,"forwardhex") == 0 )
retstr = LP_forwardhex(pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex")); retstr = LP_forwardhex(ctx,pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex"));
else if ( strcmp(method,"psock") == 0 ) else if ( strcmp(method,"psock") == 0 )
{ {
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 ) if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 )

8
iguana/exchanges/LP_forwarding.c

@ -190,7 +190,7 @@ cJSON *LP_dereference(cJSON *argjson,char *excludemethod)
return(reqjson); return(reqjson);
} }
char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr) char *LP_forwardhex(void *ctx,int32_t pubsock,bits256 pubkey,char *hexstr)
{ {
struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *retstr=0; cJSON *retjson=0,*argjson=0,*reqjson=0; struct LP_forwardinfo *ptr=0; uint8_t *data; int32_t datalen=0,sentbytes=0; char *retstr=0; cJSON *retjson=0,*argjson=0,*reqjson=0;
if ( hexstr == 0 || hexstr[0] == 0 ) if ( hexstr == 0 || hexstr[0] == 0 )
@ -204,7 +204,7 @@ char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr)
{ {
if ( reqjson != 0 ) if ( reqjson != 0 )
{ {
retstr = LP_command_process(LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.); retstr = LP_command_process(ctx,LP_mypeer != 0 ? LP_mypeer->ipaddr : "127.0.0.1",LP_mypubsock,reqjson,0,0,LP_profitratio - 1.);
//printf("LP_forwardhex.(%s) -> (%s)\n",jprint(reqjson,0),retstr!=0?retstr:""); //printf("LP_forwardhex.(%s) -> (%s)\n",jprint(reqjson,0),retstr!=0?retstr:"");
if ( pubsock >= 0 ) if ( pubsock >= 0 )
LP_send(pubsock,jprint(reqjson,0),0); LP_send(pubsock,jprint(reqjson,0),0);
@ -248,7 +248,7 @@ char *LP_forwardhex(int32_t pubsock,bits256 pubkey,char *hexstr)
return(retstr); return(retstr);
} }
int32_t LP_forward(char *myipaddr,int32_t pubsock,double profitmargin,bits256 pubkey,char *jsonstr,int32_t freeflag) int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,double profitmargin,bits256 pubkey,char *jsonstr,int32_t freeflag)
{ {
struct LP_forwardinfo *ptr; struct LP_peerinfo *peer,*tmp; char *hexstr,*retstr; int32_t len,retval = -1; cJSON *retjson,*reqjson,*argjson; struct LP_forwardinfo *ptr; struct LP_peerinfo *peer,*tmp; char *hexstr,*retstr; int32_t len,retval = -1; cJSON *retjson,*reqjson,*argjson;
if ( jsonstr == 0 || jsonstr[0] == 0 ) if ( jsonstr == 0 || jsonstr[0] == 0 )
@ -260,7 +260,7 @@ int32_t LP_forward(char *myipaddr,int32_t pubsock,double profitmargin,bits256 pu
printf("GOT FORWARDED.(%s)\n",myipaddr); printf("GOT FORWARDED.(%s)\n",myipaddr);
if ( (argjson= cJSON_Parse(jsonstr)) != 0 ) if ( (argjson= cJSON_Parse(jsonstr)) != 0 )
{ {
if ( (retstr= LP_command_process(myipaddr,pubsock,argjson,0,0,profitmargin)) != 0 ) if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,0,0,profitmargin)) != 0 )
free(retstr); free(retstr);
free_json(argjson); free_json(argjson);
} }

6
iguana/exchanges/LP_include.h

@ -228,14 +228,14 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
//double LP_query(char *method,struct LP_quoteinfo *qp,char *base,char *rel,bits256 mypub); //double LP_query(char *method,struct LP_quoteinfo *qp,char *base,char *rel,bits256 mypub);
int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys); int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct basilisk_rawtx *rawtx,int32_t v,uint8_t *recvbuf,int32_t recvlen,int32_t suppress_pubkeys);
void LP_quotesinit(char *base,char *rel); void LP_quotesinit(char *base,char *rel);
int32_t LP_forward(char *myipaddr,int32_t pubsock,double profitmargin,bits256 pubkey,char *jsonstr,int32_t freeflag); int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,double profitmargin,bits256 pubkey,char *jsonstr,int32_t freeflag);
int32_t LP_ismine(struct LP_utxoinfo *utxo); int32_t LP_ismine(struct LP_utxoinfo *utxo);
int32_t LP_isavailable(struct LP_utxoinfo *utxo); int32_t LP_isavailable(struct LP_utxoinfo *utxo);
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port); struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port);
char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin); char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin);
void LP_availableset(struct LP_utxoinfo *utxo); void LP_availableset(struct LP_utxoinfo *utxo);
int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2,bits256 pubkey); int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2,bits256 pubkey);
int32_t LP_pullsock_check(char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock,double profitmargin); int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock,double profitmargin);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);

46
iguana/exchanges/LP_nativeDEX.c

@ -76,14 +76,14 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_forwarding.c" #include "LP_forwarding.c"
#include "LP_commands.c" #include "LP_commands.c"
char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin) char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin)
{ {
char *retstr=0; char *retstr=0;
if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 ) if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 )
return(0); return(0);
if ( LP_tradecommand(myipaddr,pubsock,argjson,data,datalen,profitmargin) <= 0 ) if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen,profitmargin) <= 0 )
{ {
if ( (retstr= stats_JSON(myipaddr,pubsock,profitmargin,argjson,"127.0.0.1",0)) != 0 ) if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,profitmargin,argjson,"127.0.0.1",0)) != 0 )
{ {
//printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr);
if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 &&
@ -93,7 +93,7 @@ char *LP_command_process(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *
return(retstr); return(retstr);
} }
char *LP_process_message(char *typestr,char *myipaddr,int32_t pubsock,double profitmargin,void *ptr,int32_t recvlen,int32_t recvsock) char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,double profitmargin,void *ptr,int32_t recvlen,int32_t recvsock)
{ {
int32_t len,datalen=0; char *retstr=0,*jsonstr=0; cJSON *argjson,*reqjson; int32_t len,datalen=0; char *retstr=0,*jsonstr=0; cJSON *argjson,*reqjson;
if ( (datalen= is_hexstr((char *)ptr,0)) > 0 ) if ( (datalen= is_hexstr((char *)ptr,0)) > 0 )
@ -112,7 +112,7 @@ char *LP_process_message(char *typestr,char *myipaddr,int32_t pubsock,double pro
if ( jstr(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"forwardhex") == 0 ) if ( jstr(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"forwardhex") == 0 )
{ {
//printf("got forwardhex\n"); //printf("got forwardhex\n");
if ( (retstr= LP_forwardhex(pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex"))) != 0 ) if ( (retstr= LP_forwardhex(ctx,pubsock,jbits256(argjson,"pubkey"),jstr(argjson,"hex"))) != 0 )
{ {
} }
} }
@ -125,7 +125,7 @@ char *LP_process_message(char *typestr,char *myipaddr,int32_t pubsock,double pro
if ( pubsock >= 0 && (reqjson= LP_dereference(argjson,"publish")) != 0 ) if ( pubsock >= 0 && (reqjson= LP_dereference(argjson,"publish")) != 0 )
LP_send(pubsock,jprint(reqjson,1),1); LP_send(pubsock,jprint(reqjson,1),1);
} }
else if ( (retstr= LP_command_process(myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len,profitmargin)) != 0 ) else if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len,profitmargin)) != 0 )
{ {
} }
portable_mutex_unlock(&LP_commandmutex); portable_mutex_unlock(&LP_commandmutex);
@ -154,7 +154,7 @@ char *LP_process_message(char *typestr,char *myipaddr,int32_t pubsock,double pro
return(retstr); return(retstr);
} }
int32_t LP_pullsock_check(char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock,double profitmargin) int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock,double profitmargin)
{ {
void *ptr; int32_t recvlen=-1,nonz = 0; void *ptr; int32_t recvlen=-1,nonz = 0;
*retstrp = 0; *retstrp = 0;
@ -163,13 +163,13 @@ int32_t LP_pullsock_check(char **retstrp,char *myipaddr,int32_t pubsock,int32_t
while ( (recvlen= nn_recv(pullsock,&ptr,NN_MSG,0)) > 0 ) while ( (recvlen= nn_recv(pullsock,&ptr,NN_MSG,0)) > 0 )
{ {
nonz++; nonz++;
*retstrp = LP_process_message("PULL",myipaddr,pubsock,profitmargin,ptr,recvlen,pullsock); *retstrp = LP_process_message(ctx,"PULL",myipaddr,pubsock,profitmargin,ptr,recvlen,pullsock);
} }
} }
return(nonz); return(nonz);
} }
int32_t LP_subsock_check(char *myipaddr,int32_t pubsock,int32_t sock,double profitmargin) int32_t LP_subsock_check(void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,double profitmargin)
{ {
int32_t recvlen,nonz = 0; void *ptr; char *retstr; int32_t recvlen,nonz = 0; void *ptr; char *retstr;
if ( sock >= 0 ) if ( sock >= 0 )
@ -177,7 +177,7 @@ int32_t LP_subsock_check(char *myipaddr,int32_t pubsock,int32_t sock,double prof
while ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) while ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
{ {
nonz++; nonz++;
if ( (retstr= LP_process_message("SUB",myipaddr,pubsock,profitmargin,ptr,recvlen,sock)) != 0 ) if ( (retstr= LP_process_message(ctx,"SUB",myipaddr,pubsock,profitmargin,ptr,recvlen,sock)) != 0 )
free(retstr); free(retstr);
} }
} }
@ -205,10 +205,10 @@ void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo,double profitma
} }
} }
void LP_myutxo_updates(int32_t pubsock,char *passphrase,double profitmargin) void LP_myutxo_updates(void *ctx,int32_t pubsock,char *passphrase,double profitmargin)
{ {
//LP_utxopurge(0); not good to disrupt existing pointers //LP_utxopurge(0); not good to disrupt existing pointers
LP_privkey_updates(pubsock,passphrase,0); LP_privkey_updates(ctx,pubsock,passphrase,0);
} }
int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,double profitmargin,int32_t interval) int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,double profitmargin,int32_t interval)
@ -229,7 +229,7 @@ int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pu
return(n); return(n);
} }
int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t pushport,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin) int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t pushport,int32_t pullsock,uint16_t myport,char *passphrase,double profitmargin)
{ {
static uint32_t counter,lastforward,numpeers; static uint32_t counter,lastforward,numpeers;
struct LP_utxoinfo *utxo,*utmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0,n=0,lastn=-1; struct LP_utxoinfo *utxo,*utmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0,n=0,lastn=-1;
@ -265,12 +265,12 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso
LP_peer_pricesquery(peer->ipaddr,peer->port); LP_peer_pricesquery(peer->ipaddr,peer->port);
peer->diduquery = now; peer->diduquery = now;
} }
nonz += LP_subsock_check(origipaddr,pubsock,peer->subsock,profitmargin); nonz += LP_subsock_check(ctx,origipaddr,pubsock,peer->subsock,profitmargin);
} }
//if ( LP_canbind == 0 ) printf("counter.%d canbind.%d forwarding\n",counter,LP_canbind); //if ( LP_canbind == 0 ) printf("counter.%d canbind.%d forwarding\n",counter,LP_canbind);
if ( (counter % 600) == 60 ) if ( (counter % 600) == 60 )
{ {
LP_myutxo_updates(pubsock,passphrase,profitmargin); LP_myutxo_updates(ctx,pubsock,passphrase,profitmargin);
if ( lastforward < now-3600 ) if ( lastforward < now-3600 )
{ {
LP_forwarding_register(LP_mypubkey,pushaddr,pushport,10); LP_forwarding_register(LP_mypubkey,pushaddr,pushport,10);
@ -301,7 +301,7 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso
} }
} }
//if ( LP_canbind == 0 ) printf("counter.%d canbind.%d pullsock check\n",counter,LP_canbind); //if ( LP_canbind == 0 ) printf("counter.%d canbind.%d pullsock check\n",counter,LP_canbind);
nonz += LP_pullsock_check(&retstr,myipaddr,pubsock,pullsock,profitmargin); nonz += LP_pullsock_check(ctx,&retstr,myipaddr,pubsock,pullsock,profitmargin);
if ( retstr != 0 ) if ( retstr != 0 )
free(retstr); free(retstr);
//if ( LP_canbind == 0 ) printf("counter.%d canbind.%d hellos\n",counter,LP_canbind); //if ( LP_canbind == 0 ) printf("counter.%d canbind.%d hellos\n",counter,LP_canbind);
@ -320,7 +320,7 @@ int32_t LP_mainloop_iter(char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubso
return(nonz); return(nonz);
} }
void LP_initcoins(int32_t pubsock,cJSON *coins,char *passphrase) void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins,char *passphrase)
{ {
int32_t i,n; cJSON *item; int32_t i,n; cJSON *item;
for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++) for (i=0; i<sizeof(activecoins)/sizeof(*activecoins); i++)
@ -340,7 +340,7 @@ void LP_initcoins(int32_t pubsock,cJSON *coins,char *passphrase)
} }
} }
fprintf(stderr,"privkey updates\n"); fprintf(stderr,"privkey updates\n");
LP_privkey_updates(pubsock,passphrase,1); LP_privkey_updates(ctx,pubsock,passphrase,1);
} }
void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,char *seednode,double profitmargin) void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,char *seednode,double profitmargin)
@ -385,7 +385,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profitmargin,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profitmargin,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson)
{ {
char *myipaddr=0; long filesize,n; int32_t timeout,pullsock=-1,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128]; char *myipaddr=0; long filesize,n; int32_t timeout,pullsock=-1,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128]; void *ctx = bitcoin_ctx();
IAMLP = !amclient; IAMLP = !amclient;
#ifndef __linux__ #ifndef __linux__
if ( IAMLP != 0 ) if ( IAMLP != 0 )
@ -454,10 +454,10 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit
LP_mypubsock = pubsock; LP_mypubsock = pubsock;
} }
LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),profitmargin); LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),profitmargin);
pullsock = LP_initpublicaddr(&mypullport,pushaddr,myipaddr,mypullport,0); pullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
LP_deadman_switch = (uint32_t)time(NULL); LP_deadman_switch = (uint32_t)time(NULL);
printf("my command address is (%s) pullsock.%d pullport.%u\n",pushaddr,pullsock,mypullport); printf("my command address is (%s) pullsock.%d pullport.%u\n",pushaddr,pullsock,mypullport);
LP_initcoins(pubsock,jobj(argjson,"coins"),passphrase); LP_initcoins(ctx,pubsock,jobj(argjson,"coins"),passphrase);
if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 ) if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 )
{ {
printf("error launching LP_psockloop for (%s)\n",myipaddr); printf("error launching LP_psockloop for (%s)\n",myipaddr);
@ -470,7 +470,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit
} }
while ( 1 ) while ( 1 )
{ {
if ( LP_mainloop_iter(myipaddr,mypeer,pubsock,pushaddr,mypullport,pullsock,myport,passphrase,profitmargin) == 0 ) if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,mypullport,pullsock,myport,passphrase,profitmargin) == 0 )
usleep(100000); usleep(100000);
if ( LP_canbind == 0 ) if ( LP_canbind == 0 )
{ {
@ -480,7 +480,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit
printf("DEAD man's switch %u activated at %u lag.%d, register forwarding again\n",LP_deadman_switch,(uint32_t)time(NULL),(uint32_t)(time(NULL) - LP_deadman_switch)); printf("DEAD man's switch %u activated at %u lag.%d, register forwarding again\n",LP_deadman_switch,(uint32_t)time(NULL),(uint32_t)(time(NULL) - LP_deadman_switch));
if ( pullsock >= 0 ) if ( pullsock >= 0 )
nn_close(pullsock); nn_close(pullsock);
pullsock = LP_initpublicaddr(&mypullport,pushaddr,myipaddr,mypullport,0); pullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
LP_deadman_switch = (uint32_t)time(NULL); LP_deadman_switch = (uint32_t)time(NULL);
LP_forwarding_register(LP_mypubkey,pushaddr,mypullport,100000); LP_forwarding_register(LP_mypubkey,pushaddr,mypullport,100000);
} }

8
iguana/exchanges/LP_network.c

@ -359,7 +359,7 @@ char *LP_psock(char *myipaddr,int32_t ispaired)
*/ */
int32_t nn_tests(int32_t pullsock,char *pushaddr,int32_t nnother) int32_t nn_tests(void *ctx,int32_t pullsock,char *pushaddr,int32_t nnother)
{ {
int32_t sock,n,m,timeout,retval = -1; char msg[512],*retstr; int32_t sock,n,m,timeout,retval = -1; char msg[512],*retstr;
printf("nn_tests.(%s)\n",pushaddr); printf("nn_tests.(%s)\n",pushaddr);
@ -375,7 +375,7 @@ int32_t nn_tests(int32_t pullsock,char *pushaddr,int32_t nnother)
sprintf(msg,"{\"method\":\"nn_tests\",\"ipaddr\":\"%s\"}",pushaddr); sprintf(msg,"{\"method\":\"nn_tests\",\"ipaddr\":\"%s\"}",pushaddr);
n = LP_send(sock,msg,0); n = LP_send(sock,msg,0);
sleep(3); sleep(3);
LP_pullsock_check(&retstr,"127.0.0.1",-1,pullsock,0.); LP_pullsock_check(ctx,&retstr,"127.0.0.1",-1,pullsock,0.);
sprintf(msg,"{\"method\":\"nn_tests2\",\"ipaddr\":\"%s\"}",pushaddr); sprintf(msg,"{\"method\":\"nn_tests2\",\"ipaddr\":\"%s\"}",pushaddr);
m = LP_send(pullsock,msg,0); m = LP_send(pullsock,msg,0);
printf(">>>>>>>>>>>>>>>>>>>>>> sent %d+%d bytes -> pullsock.%d retstr.(%s)\n",n,m,pullsock,retstr!=0?retstr:""); printf(">>>>>>>>>>>>>>>>>>>>>> sent %d+%d bytes -> pullsock.%d retstr.(%s)\n",n,m,pullsock,retstr!=0?retstr:"");
@ -390,7 +390,7 @@ int32_t nn_tests(int32_t pullsock,char *pushaddr,int32_t nnother)
return(retval); return(retval);
} }
int32_t LP_initpublicaddr(uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired) int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired)
{ {
int32_t nntype,pullsock,timeout,maxsize; char bindaddr[128],connectaddr[128]; int32_t nntype,pullsock,timeout,maxsize; char bindaddr[128],connectaddr[128];
*mypullportp = mypullport; *mypullportp = mypullport;
@ -444,7 +444,7 @@ int32_t LP_initpublicaddr(uint16_t *mypullportp,char *publicaddr,char *myipaddr,
nn_setsockopt(pullsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); nn_setsockopt(pullsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0);
//LP_send(pullsock,"hello init",0); //LP_send(pullsock,"hello init",0);
} }
if ( LP_canbind == 0 && ispaired == 0 && nn_tests(pullsock,publicaddr,NN_PUSH) < 0 ) if ( LP_canbind == 0 && ispaired == 0 && nn_tests(ctx,pullsock,publicaddr,NN_PUSH) < 0 )
{ {
printf("command socket didnt work\n"); printf("command socket didnt work\n");
exit(-1); exit(-1);

30
iguana/exchanges/LP_ordermatch.c

@ -176,7 +176,7 @@ char *LP_quotereceived(cJSON *argjson)
} else return(clonestr("{\"error\":\"nullptr\"}")); } else return(clonestr("{\"error\":\"nullptr\"}"));
} }
char *LP_pricepings(char *myipaddr,int32_t pubsock,double profitmargin,char *base,char *rel,double price) char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,double profitmargin,char *base,char *rel,double price)
{ {
bits256 zero; cJSON *reqjson = cJSON_CreateObject(); bits256 zero; cJSON *reqjson = cJSON_CreateObject();
jaddbits256(reqjson,"pubkey",LP_mypubkey); jaddbits256(reqjson,"pubkey",LP_mypubkey);
@ -194,7 +194,7 @@ char *LP_pricepings(char *myipaddr,int32_t pubsock,double profitmargin,char *bas
jaddstr(reqjson,"method","forward"); jaddstr(reqjson,"method","forward");
jaddstr(reqjson,"method2","postprice"); jaddstr(reqjson,"method2","postprice");
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
LP_forward(myipaddr,pubsock,profitmargin,zero,jprint(reqjson,1),1); LP_forward(ctx,myipaddr,pubsock,profitmargin,zero,jprint(reqjson,1),1);
} }
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} }
@ -294,7 +294,7 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout)
return(-1); return(-1);
} }
double LP_query(char *myipaddr,int32_t mypubsock,double profitmargin,char *method,struct LP_quoteinfo *qp) double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,double profitmargin,char *method,struct LP_quoteinfo *qp)
{ {
cJSON *reqjson; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; cJSON *reqjson; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo;
if ( strcmp(method,"request") == 0 ) if ( strcmp(method,"request") == 0 )
@ -321,7 +321,7 @@ double LP_query(char *myipaddr,int32_t mypubsock,double profitmargin,char *metho
jaddstr(reqjson,"method2",method); jaddstr(reqjson,"method2",method);
jaddstr(reqjson,"method","forward"); jaddstr(reqjson,"method","forward");
jaddbits256(reqjson,"pubkey",qp->srchash); jaddbits256(reqjson,"pubkey",qp->srchash);
LP_forward(myipaddr,mypubsock,profitmargin,qp->srchash,jprint(reqjson,1),1); LP_forward(ctx,myipaddr,mypubsock,profitmargin,qp->srchash,jprint(reqjson,1),1);
} }
for (i=0; i<30; i++) for (i=0; i<30; i++)
{ {
@ -338,7 +338,7 @@ double LP_query(char *myipaddr,int32_t mypubsock,double profitmargin,char *metho
return(price); return(price);
} }
int32_t LP_nanobind(char *pairstr,char *myipaddr) int32_t LP_nanobind(void *ctx,char *pairstr,char *myipaddr)
{ {
int32_t i,timeout,r,pairsock = -1; uint16_t mypullport; char bindaddr[128]; int32_t i,timeout,r,pairsock = -1; uint16_t mypullport; char bindaddr[128];
if ( LP_canbind != 0 ) if ( LP_canbind != 0 )
@ -372,11 +372,11 @@ int32_t LP_nanobind(char *pairstr,char *myipaddr)
} else printf("error binding to %s for %s\n",bindaddr,pairstr); } else printf("error binding to %s for %s\n",bindaddr,pairstr);
} }
} }
} else pairsock = LP_initpublicaddr(&mypullport,pairstr,myipaddr,0,0); } else pairsock = LP_initpublicaddr(ctx,&mypullport,pairstr,myipaddr,0,0);
return(pairsock); return(pairsock);
} }
int32_t LP_connectstartbob(int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjson,char *myipaddr,char *base,char *rel,double profitmargin,double price,struct LP_quoteinfo *qp) int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjson,char *myipaddr,char *base,char *rel,double profitmargin,double price,struct LP_quoteinfo *qp)
{ {
char pairstr[512]; cJSON *retjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin; char pairstr[512]; cJSON *retjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin;
printf("LP_connectstartbob.(%s) with.(%s)\n",myipaddr,jprint(argjson,0)); printf("LP_connectstartbob.(%s) with.(%s)\n",myipaddr,jprint(argjson,0));
@ -389,7 +389,7 @@ int32_t LP_connectstartbob(int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjs
privkey = LP_privkey(utxo->coinaddr,coin->taddr); privkey = LP_privkey(utxo->coinaddr,coin->taddr);
if ( bits256_nonz(privkey) != 0 && qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && bits256_cmp(LP_mypubkey,qp->srchash) == 0 ) if ( bits256_nonz(privkey) != 0 && qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && bits256_cmp(LP_mypubkey,qp->srchash) == 0 )
{ {
if ( (pair= LP_nanobind(pairstr,myipaddr)) >= 0 ) if ( (pair= LP_nanobind(ctx,pairstr,myipaddr)) >= 0 )
{ {
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis,rel,qp->destsatoshis,qp->timestamp,qp->quotetime,DEXselector); LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis,rel,qp->destsatoshis,qp->timestamp,qp->quotetime,DEXselector);
swap = LP_swapinit(1,0,privkey,&qp->R,qp); swap = LP_swapinit(1,0,privkey,&qp->R,qp);
@ -409,7 +409,7 @@ int32_t LP_connectstartbob(int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjs
jdelete(retjson,"method"); jdelete(retjson,"method");
jaddstr(retjson,"method2","connected"); jaddstr(retjson,"method2","connected");
jaddstr(retjson,"method","forward"); jaddstr(retjson,"method","forward");
LP_forward(myipaddr,pubsock,profitmargin,utxo->S.otherpubkey,jprint(retjson,1),1); LP_forward(ctx,myipaddr,pubsock,profitmargin,utxo->S.otherpubkey,jprint(retjson,1),1);
retval = 0; retval = 0;
} else printf("error launching swaploop\n"); } else printf("error launching swaploop\n");
} else printf("couldnt bind to any port %s\n",pairstr); } else printf("couldnt bind to any port %s\n",pairstr);
@ -496,7 +496,7 @@ char *LP_connectedalice(cJSON *argjson) // alice
} }
} }
int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin)
{ {
char *method; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q; char *method; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q;
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) )
@ -541,7 +541,7 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
jdelete(retjson,"method"); jdelete(retjson,"method");
jaddstr(retjson,"method2","reserved"); jaddstr(retjson,"method2","reserved");
jaddstr(retjson,"method","forward"); jaddstr(retjson,"method","forward");
LP_forward(myipaddr,pubsock,profitmargin,butxo->S.otherpubkey,jprint(retjson,1),1); LP_forward(ctx,myipaddr,pubsock,profitmargin,butxo->S.otherpubkey,jprint(retjson,1),1);
butxo->T.lasttime = (uint32_t)time(NULL); butxo->T.lasttime = (uint32_t)time(NULL);
printf("set swappending.%u accept qprice %.8f, min %.8f\n",butxo->T.swappending,qprice,price); printf("set swappending.%u accept qprice %.8f, min %.8f\n",butxo->T.swappending,qprice,price);
} else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap);
@ -550,7 +550,7 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
{ {
retval = 4; retval = 4;
if ( butxo->T.swappending != 0 && butxo->S.swap == 0 ) if ( butxo->T.swappending != 0 && butxo->S.swap == 0 )
LP_connectstartbob(pubsock,butxo,argjson,myipaddr,Q.srccoin,Q.destcoin,profitmargin,qprice,&Q); LP_connectstartbob(ctx,pubsock,butxo,argjson,myipaddr,Q.srccoin,Q.destcoin,profitmargin,qprice,&Q);
else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0));
} }
} }
@ -558,7 +558,7 @@ int32_t LP_tradecommand(char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *d
return(retval); return(retval);
} }
char *LP_autotrade(char *myipaddr,int32_t mypubsock,double profitmargin,char *base,char *rel,double maxprice,double volume,int32_t timeout) char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,double profitmargin,char *base,char *rel,double maxprice,double volume,int32_t timeout)
{ {
int64_t satoshis,destsatoshis,desttxfee,txfee,bestdestsatoshis=0; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item,*bestitem=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; int32_t i,vout,numasks,DEXselector=0; uint32_t expiration; double ordermatchprice,bestmetric,metric,bestprice=0.,vol,price; struct LP_quoteinfo Q; int64_t satoshis,destsatoshis,desttxfee,txfee,bestdestsatoshis=0; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item,*bestitem=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; int32_t i,vout,numasks,DEXselector=0; uint32_t expiration; double ordermatchprice,bestmetric,metric,bestprice=0.,vol,price; struct LP_quoteinfo Q;
if ( maxprice <= 0. || volume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) if ( maxprice <= 0. || volume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
@ -636,13 +636,13 @@ char *LP_autotrade(char *myipaddr,int32_t mypubsock,double profitmargin,char *ba
return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); return(clonestr("{\"error\":\"cant set ordermatch quote\"}"));
if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypubkey,autxo->coinaddr) < 0 ) if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypubkey,autxo->coinaddr) < 0 )
return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); return(clonestr("{\"error\":\"cant set ordermatch quote info\"}"));
price = LP_query(myipaddr,mypubsock,profitmargin,"request",&Q); price = LP_query(ctx,myipaddr,mypubsock,profitmargin,"request",&Q);
bestitem = LP_quotejson(&Q); bestitem = LP_quotejson(&Q);
if ( price > SMALLVAL ) if ( price > SMALLVAL )
{ {
if ( price <= maxprice ) if ( price <= maxprice )
{ {
price = LP_query(myipaddr,mypubsock,profitmargin,"connect",&Q); price = LP_query(ctx,myipaddr,mypubsock,profitmargin,"connect",&Q);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,base,Q.satoshis,Q.destcoin,Q.destsatoshis,Q.timestamp,Q.quotetime,DEXselector); LP_requestinit(&Q.R,Q.srchash,Q.desthash,base,Q.satoshis,Q.destcoin,Q.destsatoshis,Q.timestamp,Q.quotetime,DEXselector);
expiration = (uint32_t)time(NULL) + timeout; expiration = (uint32_t)time(NULL) + timeout;
while ( time(NULL) < expiration ) while ( time(NULL) < expiration )

8
iguana/exchanges/LP_utxos.c

@ -722,7 +722,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr
return(total); return(total);
} }
bits256 LP_privkeycalc(uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr)
{ {
static uint32_t counter; static uint32_t counter;
bits256 privkey,userpub,userpass; char tmpstr[128]; cJSON *retjson; uint8_t tmptype,rmd160[20]; bits256 privkey,userpub,userpass; char tmpstr[128]; cJSON *retjson; uint8_t tmptype,rmd160[20];
@ -733,7 +733,7 @@ bits256 LP_privkeycalc(uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *co
privkey = iguana_wif2privkey(wifstr); privkey = iguana_wif2privkey(wifstr);
//printf("WIF.(%s) -> %s\n",wifstr,bits256_str(str,privkey)); //printf("WIF.(%s) -> %s\n",wifstr,bits256_str(str,privkey));
} }
iguana_priv2pub(pubkey33,coin->smartaddr,privkey,coin->pubtype); iguana_priv2pub(ctx,pubkey33,coin->smartaddr,privkey,coin->taddr,coin->pubtype);
if ( coin->counter == 0 ) if ( coin->counter == 0 )
{ {
coin->counter++; coin->counter++;
@ -757,7 +757,7 @@ bits256 LP_privkeycalc(uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *co
return(privkey); return(privkey);
} }
void LP_privkey_updates(int32_t pubsock,char *passphrase,int32_t initonly) void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t initonly)
{ {
int32_t i; struct iguana_info *coin; bits256 pubkey,privkey; uint8_t pubkey33[33]; int32_t i; struct iguana_info *coin; bits256 pubkey,privkey; uint8_t pubkey33[33];
memset(privkey.bytes,0,sizeof(privkey)); memset(privkey.bytes,0,sizeof(privkey));
@ -768,7 +768,7 @@ void LP_privkey_updates(int32_t pubsock,char *passphrase,int32_t initonly)
if ( (coin= LP_coinfind(LP_coins[i].symbol)) != 0 ) if ( (coin= LP_coinfind(LP_coins[i].symbol)) != 0 )
{ {
if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 )
privkey = LP_privkeycalc(pubkey33,&pubkey,coin,passphrase,""); privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,"");
if ( coin->inactive == 0 && initonly == 0 ) if ( coin->inactive == 0 && initonly == 0 )
LP_privkey_init(pubsock,coin,privkey,pubkey,pubkey33); LP_privkey_init(pubsock,coin,privkey,pubkey,pubkey33);
} }

24
iguana/exchanges/mm.c

@ -24,7 +24,7 @@
#include <stdint.h> #include <stdint.h>
#include "OS_portable.h" #include "OS_portable.h"
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MAX(a,b) ((a) > (b) ? (a) : (b))
char *stats_JSON(char *myipaddr,int32_t pubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port); char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,double profitmargin,cJSON *argjson,char *remoteaddr,uint16_t port);
#include "stats.c" #include "stats.c"
void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]); void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]);
@ -220,28 +220,6 @@ bits256 iguana_wif2privkey(char *wifstr)
return(privkey); return(privkey);
} }
void iguana_priv2pub(uint8_t *pubkey33,char *coinaddr,bits256 privkey,uint8_t addrtype)
{
char privstr[65],url[512],postdata[1024],*retstr,*pubstr,*addr; cJSON *retjson;
memset(pubkey33,0,33);
coinaddr[0] = 0;
bits256_str(privstr,privkey);
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"SuperNET\",\"method\":\"priv2pub\",\"privkey\":\"%s\",\"addrtype\":%u}",privstr,addrtype);
if ( (retstr= bitcoind_RPC(0,"SuperNET",url,0,"priv2pub",postdata,0)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (pubstr= jstr(retjson,"secp256k1")) != 0 && strlen(pubstr) == 66 )
decode_hex(pubkey33,33,pubstr);
if ( (addr= jstr(retjson,"result")) != 0 && strlen(addr) < 64 )
strcpy(coinaddr,addr);
free_json(retjson);
}
free(retstr);
}
}
double bittrex_balance(char *base,char *coinaddr) double bittrex_balance(char *base,char *coinaddr)
{ {
char *retstr; cJSON *retjson; double balance = 0.; char *retstr; cJSON *retjson; double balance = 0.;

9
iguana/exchanges/stats.c

@ -302,10 +302,15 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
return(json); return(json);
} }
extern void *bitcoin_ctx();
char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port) char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{ {
static void *ctx;
cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; double profitmargin = 0.; char *myipaddr="127.0.0.1",symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0; cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; double profitmargin = 0.; char *myipaddr="127.0.0.1",symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
//printf("rpcparse.(%s)\n",urlstr); //printf("rpcparse.(%s)\n",urlstr);
if ( ctx == 0 )
ctx = bitcoin_ctx();
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++) for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i]; urlmethod[i] = urlstr[i];
urlmethod[i++] = 0; urlmethod[i++] = 0;
@ -488,7 +493,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
if ( userpass != 0 && jstr(argjson,"userpass") == 0 ) if ( userpass != 0 && jstr(argjson,"userpass") == 0 )
jaddstr(argjson,"userpass",userpass); jaddstr(argjson,"userpass",userpass);
//printf("after urlconv.(%s) argjson.(%s)\n",jprint(json,0),jprint(argjson,0)); //printf("after urlconv.(%s) argjson.(%s)\n",jprint(json,0),jprint(argjson,0));
if ( (retstr= stats_JSON(myipaddr,-1,profitmargin,argjson,remoteaddr,port)) != 0 ) if ( (retstr= stats_JSON(ctx,myipaddr,-1,profitmargin,argjson,remoteaddr,port)) != 0 )
{ {
if ( (retitem= cJSON_Parse(retstr)) != 0 ) if ( (retitem= cJSON_Parse(retstr)) != 0 )
jaddi(retarray,retitem); jaddi(retarray,retitem);
@ -511,7 +516,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
//printf("ARGJSON.(%s)\n",jprint(arg,0)); //printf("ARGJSON.(%s)\n",jprint(arg,0));
if ( userpass != 0 && jstr(arg,"userpass") == 0 ) if ( userpass != 0 && jstr(arg,"userpass") == 0 )
jaddstr(arg,"userpass",userpass); jaddstr(arg,"userpass",userpass);
retstr = stats_JSON(myipaddr,-1,profitmargin,arg,remoteaddr,port); retstr = stats_JSON(ctx,myipaddr,-1,profitmargin,arg,remoteaddr,port);
} }
free_json(argjson); free_json(argjson);
free_json(json); free_json(json);

Loading…
Cancel
Save