Browse Source

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

pass-iguana-arg
Artem Pikulin 7 years ago
parent
commit
2b6d30ee99
  1. 2
      iguana/exchanges/LP_cache.c
  2. 6
      iguana/exchanges/LP_commands.c
  3. 12
      iguana/exchanges/LP_include.h
  4. 50
      iguana/exchanges/LP_instantdex.c
  5. 4
      iguana/exchanges/LP_mmjson.c
  6. 6
      iguana/exchanges/LP_nativeDEX.c
  7. 86
      iguana/exchanges/LP_ordermatch.c
  8. 4
      iguana/exchanges/LP_portfolio.c
  9. 4
      iguana/exchanges/LP_prices.c
  10. 20
      iguana/exchanges/LP_remember.c
  11. 7
      iguana/exchanges/LP_rpc.c
  12. 2
      iguana/exchanges/LP_signatures.c
  13. 2
      iguana/exchanges/LP_socket.c
  14. 5
      iguana/exchanges/LP_swap.c
  15. 4
      iguana/exchanges/LP_tradebots.c
  16. 4
      iguana/exchanges/LP_transaction.c
  17. 32
      iguana/exchanges/LP_utxo.c
  18. 2
      iguana/exchanges/coins
  19. 2
      iguana/exchanges/install
  20. 14
      iguana/exchanges/mm.c
  21. 27
      iguana/exchanges/stats.c

2
iguana/exchanges/LP_cache.c

@ -53,7 +53,7 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx
for (i=0; i<numvouts; i++)
{
vout = jitem(vouts,i);
tx->outpoints[i].value = LP_value_extract(vout,0);
tx->outpoints[i].value = LP_value_extract(vout,0,txid);
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest");
LP_destaddr(tx->outpoints[i].coinaddr,vout);
//printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value));

6
iguana/exchanges/LP_commands.c

@ -306,7 +306,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}*/
else if ( strcmp(method,"recentswaps") == 0 )
{
return(LP_recent_swaps(jint(argjson,"limit")));
return(LP_recent_swaps(jint(argjson,"limit"),0));
}
else if ( strcmp(method,"stop") == 0 )
{
@ -500,7 +500,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
} else vol = jdouble(argjson,"relvolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,base,rel,price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,base,rel,price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0,jstr(argjson,"uuid")));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"sell") == 0 )
@ -514,7 +514,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
} else vol = jdouble(argjson,"basevolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,rel,base,1./price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0));
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,rel,base,1./price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0,jstr(argjson,"uuid")));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
}

12
iguana/exchanges/LP_include.h

@ -35,7 +35,7 @@ voind dontprintf(char *formatstr,...) {}
#define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "27772"
#define LP_BUILD_NUMBER "27774"
#define LP_BARTERDEX_VERSION 1
#define LP_MAGICBITS 1
@ -276,7 +276,7 @@ struct LP_swap_remember
uint32_t finishtime,tradeid,requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate;
int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)];
uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],Predeemscript[1024],Dredeemscript[1024],pubkey33[33],other33[33];
char Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75],alicePaymentEthTx[75];
char uuidstr[65],Agui[65],Bgui[65],gui[65],src[65],dest[65],bobtomic[128],alicetomic[128],etomicsrc[65],etomicdest[65],destaddr[64],Adestaddr[64],Sdestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[65],bobcoin[65],*txbytes[sizeof(txnames)/sizeof(*txnames)],bobDepositEthTx[75],bobPaymentEthTx[75],alicePaymentEthTx[75];
};
struct LP_outpoint
@ -379,7 +379,7 @@ struct LP_quoteinfo
uint64_t satoshis,txfee,destsatoshis,desttxfee,aliceid;
uint32_t timestamp,quotetime,tradeid;
int32_t vout,vout2,destvout,feevout,pair;
char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65];
char srccoin[65],coinaddr[64],destcoin[65],destaddr[64],gui[64],etomicsrc[65],etomicdest[65],uuidstr[65];
};
struct LP_endpoint { int32_t pair; char ipaddr[64]; uint16_t port; };
@ -397,7 +397,7 @@ struct basilisk_swap
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
bits256 privkeys[INSTANTDEX_DECKSIZE];
//struct basilisk_swapmessage *messages; int32_t nummessages,sentflag;
char Bdeposit[64],Bpayment[64];
char Bdeposit[64],Bpayment[64],uuidstr[65];
uint64_t aliceid,otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint8_t persistent_pubkey33[33],persistent_other33[33],changermd160[20],pad[15],verifybuf[100000];
};
@ -479,7 +479,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
void LP_quotesinit(char *base,char *rel);
int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,bits256 pubkey,char *jsonstr,int32_t freeflag);
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port);
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest);
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest,bits256 txid);
int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vout);
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,int32_t stats_JSONonly);
int64_t LP_kmdvalue(char *symbol,int64_t satoshis);
@ -490,7 +490,7 @@ int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsoc
int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t *voutp,int32_t *heightp,cJSON *item);
void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_t cmdchannel,char *ipaddr);
void LP_failedmsg(uint32_t requestid,uint32_t quoteid,double val);
void LP_failedmsg(uint32_t requestid,uint32_t quoteid,double val,char *uuidstr);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
//int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);

50
iguana/exchanges/LP_instantdex.c

@ -82,8 +82,34 @@ void LP_instantdex_deposituniq(FILE *fp,bits256 txid)
void LP_instantdex_filescreate(char *coinaddr)
{
char fname[512]; FILE *fp; bits256 txid; int32_t i,n; cJSON *array,*newarray,*txobj;
char fname[512]; FILE *fp; bits256 txid; int32_t i,j,n; cJSON *array,*newarray,*txobj;
sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname);
if ( (fp= fopen(fname,"rb")) == 0 )
{
if ( (fp= fopen(fname,"wb+")) != 0 )
{
//printf("created %s\n",fname);
for (i=0; i<2; i++)
{
if ( (array= LP_instantdex_txids(i,coinaddr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (j=0; j<n; j++)
{
txid = jbits256i(array,j);
//char str[65]; printf("j.%d of %d: %s\n",j,n,bits256_str(str,txid));
LP_instantdex_deposituniq(fp,txid);
fflush(fp);
}
}
//printf("i.%d n.%d\n",i,n);
free_json(array);
}
}
fclose(fp);
} else printf("couldnt create %s\n",fname);
} else fclose(fp);
if ( (fp= fopen(fname,"rb")) != 0 )
{
array = cJSON_CreateArray();
@ -94,7 +120,7 @@ void LP_instantdex_filescreate(char *coinaddr)
{
fseek(fp,sizeof(txid) * i,SEEK_SET);
if ( fread(&txid,1,sizeof(txid),fp) != sizeof(txid) )
printf("error reating %s\n",fname);
printf("error creating %s\n",fname);
jaddibits256(array,txid);
if ( (txobj= LP_gettxout("KMD",coinaddr,txid,0)) != 0 )
free_json(txobj);
@ -312,7 +338,7 @@ char *LP_unlockedspend(void *ctx,char *symbol,bits256 utxotxid)
{
vout0 = jitem(vouts,0);
LP_destaddr(vinaddr,vout0);
satoshis = LP_value_extract(vout0,0);
satoshis = LP_value_extract(vout0,0,utxotxid);
opret = jitem(vouts,numvouts - 1);
jaddstr(retjson,"result","success");
jaddbits256(retjson,"lockedtxid",utxotxid);
@ -396,20 +422,20 @@ char *LP_timelock(char *symbol,uint32_t duration,char *destaddr,uint64_t satoshi
int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *coin,bits256 utxotxid)
{
uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis; uint32_t expiration,claimtime;
uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki,iter; int64_t weeksatoshis,satoshis,interest; uint32_t expiration,claimtime;
if ( (txjson= LP_gettx("LP_claim_submit",coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 3 )
{
vout0 = jitem(vouts,0);
LP_destaddr(vinaddr,vout0);
satoshis = LP_value_extract(vout0,1);
satoshis = LP_value_extract(vout0,1,utxotxid);
vout2 = jitem(vouts,2);
LP_destaddr(destaddr,vout2);
if ( strcmp(destaddr,coin->smartaddr) == 0 )
{
vout1 = jitem(vouts,1);
weeksatoshis = LP_value_extract(vout1,0);
weeksatoshis = LP_value_extract(vout1,0,utxotxid);
weeki = (int32_t)(weeksatoshis % 10000);
for (iter=0; iter<2; iter++)
for (j=-168; j<=168; j++)
@ -425,10 +451,12 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info
//claimtime = LP_claimtime(coin,expiration);
item = cJSON_CreateObject();
jaddbits256(item,"txid",utxotxid);
jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0)));
jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0,utxotxid)));
if ( coin->electrum == 0 )
jaddnum(item,"interest",dstr(satoshis)-dstr(LP_value_extract(vout0,0)));
else jaddnum(item,"interest",dstr(LP_komodo_interest(utxotxid,satoshis)));
interest = dstr(satoshis) - dstr(LP_value_extract(vout0,0,utxotxid));
else interest = dstr(LP_komodo_interest(utxotxid,satoshis));
jaddnum(item,"interest",interest);
//printf("%.8f %.8f %.8f\n",dstr(satoshis),dstr(LP_value_extract(vout0,0,utxotxid)),dstr(LP_komodo_interest(utxotxid,satoshis)));
if ( claimtime <= expiration )
{
printf("iter.%d j.%d claimtime.%u vs %u, wait %d seconds to %s claim %.8f\n",iter,j,claimtime,expiration,(int32_t)expiration-claimtime,bits256_str(str,utxotxid),dstr(satoshis));
@ -526,10 +554,10 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2
}
else
{
amount64 = LP_value_extract(jitem(vouts,1),0);
amount64 = LP_value_extract(jitem(vouts,1),0,txid);
weeki = (amount64 % 10000);
item = jitem(vouts,0);
satoshis = LP_value_extract(item,0);
satoshis = LP_value_extract(item,0,txid);
//char str[65]; printf("%s %s funded %.8f weeki.%d (%s)\n",bits256_str(str,txid),destaddr,dstr(satoshis),weeki,jprint(item,0));
if ( LP_destaddr(p2shaddr,item) == 0 )
{

4
iguana/exchanges/LP_mmjson.c

@ -50,7 +50,7 @@
int32_t MM_numfields;
char *MM_fields[] =
{
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "cli", "etomic", "bobtomic", "alicetomic", "etomicsrc", "etomicdest"
"timestamp", "getdPoW", "dPoW", "aliceid", "src", "base", "basevol", "dest", "rel", "relvol", "price", "requestid", "quoteid", "finished", "expired", "bobdeposit", "alicepayment", "bobpayment", "paymentspent", "Apaymentspent", "depositspent", "ind", "method", "swapstatus", "method2", "gettradestatus", "coin", "rmd160", "pub", "pubsecp", "sig", "session", "notify", "pubkey", "price64", "credits", "utxocoin", "n", "bal", "min", "max", "postprice", "notarized", "notarizedhash", "notarizationtxid", "wantnotify", "isLP", "gui", "nogui", "tradeid", "address", "txid", "vout", "srchash", "txfee", "quotetime", "satoshis", "desthash", "txid2", "vout2", "destaddr", "desttxid", "destvout", "feetxid", "feevout", "desttxfee", "destsatoshis", "pending", "reserved", "broadcast", "ismine", "simplegui", "request", "proof", "connect", "expiration", "iambob", "Bgui", "", "Agui", "bob", "srcamount", "bobtxfee", "alice", "destamount", "alicetxfee", "sentflags", "values", "result", "success", "status", "finishtime", "tradestatus", "pair", "connected", "warning", "critical", "endcritical", "cli", "etomic", "bobtomic", "alicetomic", "etomicsrc", "etomicdest", "hyperdex", "uuid"
};
#define MMJSON_BOUNDARY ((int32_t)(sizeof(MM_fields)/sizeof(*MM_fields)))
@ -581,6 +581,8 @@ int32_t MMJSON_encode(uint8_t *linebuf,char *line)
s = jfieldname(ptr);
if ( (ind= mmfind(s)) < 0 )
{
static uint32_t counter;
if ( counter++ < 3 )
printf("missing field.(%s) add to MM_fields[]\n",s);
linebuf[k++] = MMJSON_STRING;
memcpy(&linebuf[k],s,strlen(s)+1);

6
iguana/exchanges/LP_nativeDEX.c

@ -515,6 +515,7 @@ void command_rpcloop(void *ctx)
void LP_coinsloop(void *_coins)
{
static int32_t didfilescreate;
struct LP_address *ap=0; struct LP_transaction *tx; 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 notarized,oldht,j,nonz; char *coins = _coins;
if ( strcmp("BTC",coins) == 0 )
{
@ -564,6 +565,11 @@ void LP_coinsloop(void *_coins)
//printf("%s has no smartaddress??\n",coin->symbol);
continue;
}
if ( didfilescreate == 0 && strcmp("KMD",coin->symbol) == 0 )
{
LP_instantdex_filescreate(coin->smartaddr);
didfilescreate = 1;
}
memset(&zero,0,sizeof(zero));
if ( coin->inactive != 0 )
continue;

86
iguana/exchanges/LP_ordermatch.c

@ -25,13 +25,14 @@ uint32_t Alice_expiration,Bob_expiration;
struct { uint64_t aliceid; double bestprice; uint32_t starttime,counter; } Bob_competition[512];
void LP_failedmsg(uint32_t requestid,uint32_t quoteid,double val)
void LP_failedmsg(uint32_t requestid,uint32_t quoteid,double val,char *uuidstr)
{
char *msg; cJSON *retjson;
if ( IPC_ENDPOINT >= 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"method","failed");
jaddstr(retjson,"uuid",uuidstr);
jaddnum(retjson,"error",val);
jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid);
@ -482,7 +483,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
if ( (coin= LP_coinfind(qp->srccoin)) == 0 )
{
printf("cant find coin.%s\n",qp->srccoin);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3000);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3000,qp->uuidstr);
return(-1);
}
privkey = LP_privkey(coin->symbol,coin->smartaddr,coin->taddr);
@ -498,7 +499,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp,dtrust > 0)) == 0 )
{
printf("cant initialize swap\n");
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3001);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3001,qp->uuidstr);
return(-1);
}
if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 )
@ -541,19 +542,19 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
}
else
{
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3002);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3002,qp->uuidstr);
printf("error launching swaploop\n");
}
}
else
{
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3003);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3003,qp->uuidstr);
printf("couldnt bind to any port %s\n",pairstr);
}
}
else
{
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3004);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-3004,qp->uuidstr);
printf("cant find privkey for %s\n",coin->smartaddr);
}
if ( retval < 0 )
@ -566,7 +567,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
return(retval);
}
char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid,bits256 destpubkey)
char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration,uint32_t tradeid,bits256 destpubkey,char *uuidstr)
{
double price;
price = 0.;
@ -576,10 +577,11 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q
if ( (qp->tradeid= tradeid) == 0 )
qp->tradeid = LP_rand();
qp->srchash = destpubkey;
strncpy(qp->uuidstr,uuidstr,sizeof(qp->uuidstr)-1);
LP_query(ctx,myipaddr,mypubsock,"request",qp);
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey;
char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s)\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest);
return(LP_recent_swaps(0));
char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f etomicdest.(%s) uuid.%s\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice,qp->etomicdest,qp->uuidstr);
return(LP_recent_swaps(0,uuidstr));
}
int32_t LP_quotecmp(int32_t strictflag,struct LP_quoteinfo *qp,struct LP_quoteinfo *qp2)
@ -625,7 +627,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
if ( bits256_cmp(qp->desthash,G.LP_mypub25519) != 0 )
{
LP_aliceid(qp->tradeid,qp->aliceid,"error1",0,0);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4000);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4000,qp->uuidstr);
return(clonestr("{\"result\",\"update stats\"}"));
}
printf("CONNECTED numpending.%d tradeid.%u requestid.%u quoteid.%u pairstr.%s\n",G.LP_pendingswaps,qp->tradeid,qp->R.requestid,qp->R.quoteid,pairstr!=0?pairstr:"");
@ -643,7 +645,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
LP_availableset(qp->desttxid,qp->vout);
LP_availableset(qp->feetxid,qp->feevout);
LP_aliceid(qp->tradeid,qp->aliceid,"error4",0,0);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,qprice);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,qprice,qp->uuidstr);
printf("quote %s/%s validate error %.0f\n",qp->srccoin,qp->destcoin,qprice);
return(clonestr("{\"error\":\"quote validation error\"}"));
}
@ -653,7 +655,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
LP_availableset(qp->desttxid,qp->vout);
LP_availableset(qp->feetxid,qp->feevout);
LP_aliceid(qp->tradeid,qp->aliceid,"error5",0,0);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4002);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4002,qp->uuidstr);
return(clonestr("{\"error\":\"no price set\"}"));
}
//LP_RTmetrics_update(qp->srccoin,qp->destcoin);
@ -662,7 +664,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
if ( (coin= LP_coinfind(qp->destcoin)) == 0 )
{
LP_aliceid(qp->tradeid,qp->aliceid,"error6",0,0);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4003);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4003,qp->uuidstr);
return(clonestr("{\"error\":\"cant get alicecoin\"}"));
}
qp->privkey = LP_privkey(coin->symbol,qp->destaddr,coin->taddr);
@ -675,13 +677,13 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
LP_availableset(qp->desttxid,qp->vout);
LP_availableset(qp->feetxid,qp->feevout);
LP_aliceid(qp->tradeid,qp->aliceid,"error7",qp->R.requestid,qp->R.quoteid);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4004);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4004,qp->uuidstr);
return(jprint(retjson,1));
}
if ( pairstr == 0 || pairstr[0] == 0 || (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 )
{
LP_aliceid(qp->tradeid,qp->aliceid,"error8",qp->R.requestid,qp->R.quoteid);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4005);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4005,qp->uuidstr);
jaddstr(retjson,"error","couldnt create pairsock");
}
else if ( nn_connect(pairsock,pairstr) >= 0 )
@ -716,14 +718,14 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
{
LP_aliceid(qp->tradeid,qp->aliceid,"error9",qp->R.requestid,qp->R.quoteid);
jaddstr(retjson,"error","couldnt aliceloop");
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4006);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4006,qp->uuidstr);
}
}
else
{
LP_aliceid(qp->tradeid,qp->aliceid,"error10",qp->R.requestid,qp->R.quoteid);
printf("connect error %s\n",nn_strerror(nn_errno()));
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4007);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4007,qp->uuidstr);
}
//printf("connected result.(%s)\n",jprint(retjson,0));
if ( jobj(retjson,"error") != 0 )
@ -739,7 +741,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
LP_availableset(qp->feetxid,qp->feevout);
LP_aliceid(qp->tradeid,qp->aliceid,"error11",0,0);
printf("no privkey found coin.%s %s taddr.%u\n",qp->destcoin,qp->destaddr,coin->taddr);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4008);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-4008,qp->uuidstr);
return(clonestr("{\"error\",\"no privkey\"}"));
}
}
@ -897,7 +899,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[4096]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos));
*newqp = *qp;
qp = newqp;
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
//printf("bob %s received REQUEST.(%s)\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32);
if ( (coin= LP_coinfind(qp->srccoin)) == 0 || (othercoin= LP_coinfind(qp->destcoin)) == 0 )
return(0);
if ( (myprice= LP_trades_bobprice(&bid,&ask,qp)) == 0. )
@ -1013,7 +1015,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
}
i++;
}
printf("i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",i,qprice,myprice,price,p);
printf("%s/%s i.%d qprice %.8f myprice %.8f price %.8f [%.8f]\n",qp->srccoin,qp->destcoin,i,qprice,myprice,price,p);
if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 )
{
//printf("found unallocated txids\n");
@ -1039,7 +1041,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp)
{
char *retstr; double qprice;
char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1));
//char str[65]; printf("alice %s received RESERVED.(%s) %.8f\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32,(double)qp->destsatoshis/(qp->satoshis+1));
*newqp = *qp;
qp = newqp;
if ( (qprice= LP_trades_alicevalidate(ctx,qp)) > 0. )
@ -1049,7 +1051,7 @@ struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,str
if ( (retstr= LP_quotereceived(qp)) != 0 )
free(retstr);
return(qp);
} else LP_failedmsg(qp->R.requestid,qp->R.quoteid,qprice);
} else LP_failedmsg(qp->R.requestid,qp->R.quoteid,qprice,qp->uuidstr);
return(0);
}
@ -1066,13 +1068,13 @@ struct LP_quoteinfo *LP_trades_gotconnect(void *ctx,struct LP_quoteinfo *qp,stru
return(0);
if ( LP_reservation_check(qp->txid,qp->vout,qp->desthash) == 0 && LP_reservation_check(qp->txid2,qp->vout2,qp->desthash) == 0 )
{
char str[65]; printf("bob %s received CONNECT.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
char str[65]; printf("bob %s received CONNECT.(%s)\n",bits256_str(str,G.LP_mypub25519),qp->uuidstr+32);
LP_connectstartbob(ctx,LP_mypubsock,qp->srccoin,qp->destcoin,qprice,qp);
return(qp);
}
else
{
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-1);
LP_failedmsg(qp->R.requestid,qp->R.quoteid,-1,qp->uuidstr);
printf("connect message from non-reserved (%llu)\n",(long long)qp->aliceid);
}
return(0);
@ -1086,14 +1088,14 @@ struct LP_quoteinfo *LP_trades_gotconnected(void *ctx,struct LP_quoteinfo *qp,st
qp = newqp;
if ( (val= LP_trades_alicevalidate(ctx,qp)) > 0. )
{
printf("CONNECTED ALICE\n");
//printf("CONNECTED ALICE uuid.%s\n",qp->uuidstr);
LP_aliceid(qp->tradeid,qp->aliceid,"connected",0,0);
if ( (retstr= LP_connectedalice(qp,pairstr)) != 0 )
free(retstr);
LP_mypriceset(&changed,qp->destcoin,qp->srccoin,0.);
LP_alicequery_clear();
return(qp);
} else LP_failedmsg(qp->R.requestid,qp->R.quoteid,val);
} else LP_failedmsg(qp->R.requestid,qp->R.quoteid,val,qp->uuidstr);
//printf("LP_trades_alicevalidate error\n");
return(0);
}
@ -1147,6 +1149,7 @@ void LP_tradesloop(void *ctx)
{
if ( tp->negotiationdone != 0 )
continue;
//printf("check %s\n",tp->Q.uuidstr+32);
timeout = LP_AUTOTRADE_TIMEOUT;
if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
@ -1309,7 +1312,7 @@ void LP_tradecommandQ(struct LP_quoteinfo *qp,char *pairstr,int32_t funcid)
safecopy(qtp->pairstr,pairstr,sizeof(qtp->pairstr));
DL_APPEND(LP_tradesQ,qtp);
portable_mutex_unlock(&LP_tradesmutex);
//printf("queue.%d %p\n",funcid,qtp);
//printf("queue.%d uuid.(%s)\n",funcid,qtp->Q.uuidstr);
}
int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen)
@ -1329,13 +1332,13 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
rq = ((uint64_t)Q.R.requestid << 32) | Q.R.quoteid;
if ( Q.timestamp > 0 && time(NULL) > Q.timestamp + LP_AUTOTRADE_TIMEOUT*20 ) // eat expired packets, some old timestamps floating about?
{
printf("aliceid.%llu is expired by %d\n",(long long)Q.aliceid,(uint32_t)time(NULL) - (Q.timestamp + LP_AUTOTRADE_TIMEOUT*20));
printf("uuid.%s aliceid.%llu is expired by %d\n",Q.uuidstr+32,(long long)Q.aliceid,(uint32_t)time(NULL) - (Q.timestamp + LP_AUTOTRADE_TIMEOUT*20));
return(1);
}
LP_tradecommand_log(argjson);
qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee); //jdouble(argjson,"price");
//printf("%s\n",jprint(argjson,0));
printf("%-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),qprice,LP_RTcount,LP_swapscount,G.netid);
printf("%-4d uuid.%32s %12s %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.uuidstr+32,method,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),qprice,LP_RTcount,LP_swapscount,G.netid);
retval = 1;
aliceid = j64bits(argjson,"aliceid");
if ( strcmp(method,"reserved") == 0 )
@ -1383,7 +1386,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
if ( i == sizeof(rqs)/sizeof(*rqs) )
i = (rand() % (sizeof(rqs)/sizeof(*rqs)));
rqs[i] = rq;
//printf("CONNECTED.(%s)\n",jprint(argjson,0));
//printf("CONNECTED.(%s)\n",jprint(argjson,0));
if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 )
Q.othercredits = LP_instantdex_proofcheck(Q.srccoin,Q.coinaddr,proof,num);
if ( Qtrades == 0 )
@ -1444,9 +1447,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
return(retval);
}
char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce,bits256 destpubkey,uint32_t tradeid)
char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce,bits256 destpubkey,uint32_t tradeid,char *uuidstr)
{
uint64_t desttxfee,txfee,balance; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[4096]; int32_t num=0,maxiters=100,i,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
uint64_t desttxfee,txfee,balance; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[4096]; int32_t num=0,maxiters=100,i,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); char _uuidstr[65];
basecoin = LP_coinfind(base);
relcoin = LP_coinfind(rel);
if ( gui == 0 )
@ -1514,6 +1517,8 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha
printf("maxutxo %.8f relvolume %.8f desttxfee %.8f\n",dstr(maxutxo),relvolume,dstr(desttxfee));
maxprice = LP_fomoprice(base,rel,&relvolume);
printf("fomoprice %.8f relvolume %.8f\n",maxprice,relvolume);
if ( maxprice == 0. )
return(clonestr("{\"error\":\"no orderbook entry found to handle request\"}"));
} else printf("no utxo available\n");
}
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
@ -1570,7 +1575,7 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha
else if (basecoin->etomic[0] != 0 )
{
strcpy(Q.etomicdest,basecoin->smartaddr);
printf("Q.etomicdest (%s)\n",Q.etomicdest);
//printf("Q.etomicdest (%s)\n",Q.etomicdest);
}
if ( relcoin->etomic[0] != 0 )
{
@ -1582,7 +1587,20 @@ char *LP_autobuy(void *ctx,int32_t fomoflag,char *myipaddr,int32_t mypubsock,cha
int32_t changed;
LP_mypriceset(&changed,rel,base,1. / maxprice);
LP_mypriceset(&changed,base,rel,0.);
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey));
if ( uuidstr == 0 || uuidstr[0] == 0 )
{
uint8_t uuidhash[256]; bits256 hash; uint64_t millis; int32_t len = 0;
memcpy(uuidhash,&G.LP_mypub25519,sizeof(bits256)), len += sizeof(bits256);
millis = OS_milliseconds();
memcpy(&uuidhash[len],&millis,sizeof(millis)), len += sizeof(millis);
memcpy(&uuidhash[len],base,(int32_t)strlen(base)), len += (int32_t)strlen(base);
memcpy(&uuidhash[len],rel,(int32_t)strlen(rel)), len += (int32_t)strlen(rel);
vcalc_sha256(0,hash.bytes,uuidhash,len);
uuidstr = _uuidstr;
bits256_str(uuidstr,hash);
//char str[65]; printf("%s %llu %s %s -> uuid.%s\n",bits256_str(str,G.LP_mypub25519),(long long)millis,base,rel,uuidstr);
}
return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration,tradeid,destpubkey,uuidstr));
}

4
iguana/exchanges/LP_portfolio.c

@ -110,7 +110,7 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr)
for (i=0; i<n; i++)
{
item = jitem(array,i);
value = LP_value_extract(item,1);
value = LP_value_extract(item,0,zero);
valuesum += value;
}
}
@ -799,7 +799,7 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str
//if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( (retstr2= LP_autobuy(ctx,0,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui,LP_lastnonce+1,zero,1)) != 0 )
if ( (retstr2= LP_autobuy(ctx,0,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui,LP_lastnonce+1,zero,1,0)) != 0 )
{
if ( (retjson2= cJSON_Parse(retstr2)) != 0 )
{

4
iguana/exchanges/LP_prices.c

@ -114,7 +114,7 @@ void LP_pubkey_update(struct LP_pubkey_info *pubp,uint32_t baseind,uint32_t reli
DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON()
//printf("create pubp quotes %d/%d\n",baseind,relind);
}
//printf("%d/%d price %.8f balance %.8f %s num.%d %.8f %.8f\n",baseind,relind,price,dstr(balance),utxocoin,numutxos,dstr(minutxo),dstr(maxutxo));
//printf("%d/%d price %.8f balance %.8f %s num.%d min %.8f max %.8f\n",baseind,relind,price,dstr(balance),utxocoin,numutxos,dstr(minutxo),dstr(maxutxo));
pq->price = price;
if ( utxocoin != 0 && utxocoin[0] != 0 )
{
@ -1169,7 +1169,7 @@ cJSON *LP_pricearray(char *base,char *rel,uint32_t firsttime,uint32_t lasttime,i
void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,char *utxocoin,int32_t numrelutxos,int64_t balance,int64_t minutxo,int64_t maxutxo,int64_t unconfcredits)
{
struct LP_priceinfo *basepp,*relpp; uint32_t now; int64_t price64; struct LP_pubkey_info *pubp; char str[65],fname[512]; FILE *fp;
//printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey));
//printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s balance %.8f min %.8f max %.8f\n",base,rel,price,bits256_str(str,pubkey),dstr(balance),dstr(minutxo),dstr(maxutxo));
if ( LP_pricevalid(price) > 0 && (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
//if ( (fp= basepp->fps[relpp->ind]) == 0 )

20
iguana/exchanges/LP_remember.c

@ -63,6 +63,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
if ( swap->Bpayment[0] != 0 )
fprintf(fp,",\"%s\":\"%s\"","Bpayment",swap->Bpayment);
fprintf(fp,",\"expiration\":%u",swap->I.expiration);
fprintf(fp,",\"uuid\":\"%s\"",swap->uuidstr);
fprintf(fp,",\"iambob\":%d",swap->I.iambob);
fprintf(fp,",\"bobcoin\":\"%s\"",swap->I.bobstr);
if ( swap->I.bobtomic[0] != 0 )
@ -117,6 +118,7 @@ void basilisk_dontforget(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx
fprintf(fp,",\"Agui\":\"%s\"",G.gui);
else fprintf(fp,",\"Bgui\":\"%s\"",G.gui);
fprintf(fp,",\"gui\":\"%s\"",G.gui);
fprintf(fp,",\"uuid\":\"%s\"",swap->uuidstr);
if ( memcmp(zeroes,swap->I.secretAm,20) != 0 )
{
init_hexbytes_noT(secretAmstr,swap->I.secretAm,20);
@ -629,6 +631,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap)
jaddnum(item,"critical",LP_swap_critical);
jaddnum(item,"endcritical",LP_swap_endcritical);
}
jaddstr(item,"uuid",rswap->uuidstr);
jaddnum(item,"expiration",rswap->expiration);// - INSTANTDEX_LOCKTIME*2);
jaddnum(item,"tradeid",rswap->tradeid);
jaddnum(item,"requestid",rswap->requestid);
@ -693,6 +696,7 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
if ( (item= cJSON_Parse(fstr)) != 0 )
{
rswap->iambob = jint(item,"iambob");
safecopy(rswap->uuidstr,jstr(item,"uuid"),sizeof(rswap->uuidstr));
safecopy(rswap->Bgui,jstr(item,"Bgui"),sizeof(rswap->Bgui));
safecopy(rswap->Agui,jstr(item,"Agui"),sizeof(rswap->Agui));
safecopy(rswap->gui,jstr(item,"gui"),sizeof(rswap->gui));
@ -940,7 +944,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
rswap->Dredeemlen >>= 1;
decode_hex(rswap->Dredeemscript,rswap->Dredeemlen,rstr);
}
rswap->values[i] = value = LP_value_extract(txobj,1);
rswap->values[i] = value = LP_value_extract(txobj,1,txid);
if ( (symbol= jstr(txobj,"src")) != 0 )
{
safecopy(rswap->src,symbol,sizeof(rswap->src));
@ -1103,6 +1107,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
//printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap never started");
jaddstr(retjson,"uuid",rswap.uuidstr);
jaddstr(retjson,"status","finished");
jaddstr(retjson,"bob",rswap.bobcoin);
jaddstr(retjson,"src",rswap.src);
@ -1127,6 +1132,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
printf("this isnt my swap! alice.(%s vs %s)\n",alice->smartaddr,rswap.Adestaddr);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap for different account");
jaddstr(retjson,"uuid",rswap.uuidstr);
jaddstr(retjson,"alice",alice->symbol);
jaddstr(retjson,"aliceaddr",alice->smartaddr);
jaddstr(retjson,"dest",rswap.dest);
@ -1139,6 +1145,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
printf("need to scan %s first\n",alice->symbol);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","need to scan coin first");
jaddstr(retjson,"uuid",rswap.uuidstr);
jaddstr(retjson,"coin",alice->symbol);
jaddnum(retjson,"scanned",alice->lastscanht);
jaddnum(retjson,"longest",alice->longestchain);
@ -1166,6 +1173,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
printf("this isnt my swap! bob.(%s vs %s)\n",bob->smartaddr,rswap.destaddr);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap for different account");
jaddstr(retjson,"uuid",rswap.uuidstr);
jaddstr(retjson,"bob",bob->symbol);
jaddstr(retjson,"bobaddr",bob->smartaddr);
jaddstr(retjson,"src",rswap.src);
@ -1178,6 +1186,7 @@ cJSON *basilisk_remember(int32_t fastflag,int64_t *KMDtotals,int64_t *BTCtotals,
printf("need to scan %s first\n",bob->symbol);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","need to scan coin first");
jaddstr(retjson,"uuid",rswap.uuidstr);
jaddstr(retjson,"coin",bob->symbol);
jaddnum(retjson,"scanned",bob->lastscanht);
jaddnum(retjson,"longest",bob->longestchain);
@ -1681,7 +1690,7 @@ char *basilisk_swapentry(int32_t fastflag,uint32_t requestid,uint32_t quoteid,in
extern struct LP_quoteinfo LP_Alicequery;
extern uint32_t Alice_expiration;
char *LP_recent_swaps(int32_t limit)
char *LP_recent_swaps(int32_t limit,char *uuidstr)
{
char fname[512],*retstr,*base,*rel,*statusstr; long fsize,offset; FILE *fp; int32_t baseind,relind,i=0; uint32_t requestid,quoteid; cJSON *array,*item,*retjson,*subitem,*swapjson; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS]; double srcamount,destamount,netamounts[LP_MAXPRICEINFOS];
memset(KMDtotals,0,sizeof(KMDtotals));
@ -1772,9 +1781,12 @@ char *LP_recent_swaps(int32_t limit)
jaddstr(item,"alice",LP_Alicequery.destcoin);
jaddstr(item,"rel",LP_Alicequery.destcoin);
jaddnum(item,"relvalue",dstr(LP_Alicequery.destsatoshis));
jaddbits256(item,"desthash",G.LP_mypub25519);
jadd64bits(item,"aliceid",LP_aliceid_calc(LP_Alicequery.desttxid,LP_Alicequery.destvout,LP_Alicequery.feetxid,LP_Alicequery.feevout));
jadd(retjson,"pending",item);
} else Alice_expiration = 0;
if ( uuidstr != 0 )
jaddstr(retjson,"uuid",uuidstr);
return(jprint(retjson,1));
}
@ -1833,7 +1845,7 @@ char *basilisk_swapentries(int32_t fastflag,char *refbase,char *refrel,int32_t l
}
free(liststr);
}
if ( (liststr= LP_recent_swaps(limit)) != 0 )
if ( (liststr= LP_recent_swaps(limit,0)) != 0 )
{
if ( (retjson= cJSON_Parse(liststr)) != 0 )
{
@ -1894,7 +1906,7 @@ char *basilisk_swapentries(int32_t fastflag,char *refbase,char *refrel,int32_t l
int32_t LP_pendingswap(uint32_t requestid,uint32_t quoteid)
{
cJSON *retjson,*array,*pending,*item; uint32_t r,q; char *retstr; int32_t i,n,retval = 0;
if ( (retstr= LP_recent_swaps(1000)) != 0 )
if ( (retstr= LP_recent_swaps(1000,0)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{

7
iguana/exchanges/LP_rpc.c

@ -136,8 +136,9 @@ int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin)
uint64_t LP_RTsmartbalance(struct iguana_info *coin)
{
cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value;
cJSON *array,*item; char buf[512],*retstr; int32_t i,n; uint64_t valuesum,value; bits256 zero;
valuesum = 0;
memset(zero.bytes,0,sizeof(zero));
sprintf(buf,"[0, 99999999, [\"%s\"]]",coin->smartaddr);
retstr = bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,"listunspent",buf);
if ( retstr != 0 && retstr[0] != 0 )
@ -148,7 +149,7 @@ uint64_t LP_RTsmartbalance(struct iguana_info *coin)
for (i=0; i<n; i++)
{
item = jitem(array,i);
value = LP_value_extract(item,1);
value = LP_value_extract(item,0,zero);
valuesum += value;
//printf("%s -> %.8f\n",jprint(item,0),dstr(value));
}
@ -535,7 +536,7 @@ int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t
{
*txidp = jbits256(item,"txid");
*voutp = juint(item,"vout");
satoshis = LP_value_extract(item,0);
satoshis = LP_value_extract(item,0,*txidp);
*heightp = LP_txheight(coin,*txidp);
}
else

2
iguana/exchanges/LP_signatures.c

@ -44,6 +44,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp)
double price; char etomic[64],activesymbol[65]; cJSON *retjson = cJSON_CreateObject();
if ( jobj(retjson,"gui") == 0 )
jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui);
jaddstr(retjson,"uuid",qp->uuidstr);
jadd64bits(retjson,"aliceid",qp->aliceid);
jaddnum(retjson,"tradeid",qp->tradeid);
jaddstr(retjson,"base",qp->srccoin);
@ -114,6 +115,7 @@ int32_t LP_quoteparse(struct LP_quoteinfo *qp,cJSON *argjson)
memset(qp,0,sizeof(*qp));
safecopy(qp->gui,LP_gui,sizeof(qp->gui));
safecopy(qp->srccoin,jstr(argjson,"base"),sizeof(qp->srccoin));
safecopy(qp->uuidstr,jstr(argjson,"uuid"),sizeof(qp->uuidstr));
if ( LP_etomicsymbol(activesymbol,etomic,qp->srccoin) != 0 )
{
if ( (etomicstr= jstr(argjson,"bobtomic")) == 0 || strcmp(etomicstr,etomic) != 0 )

2
iguana/exchanges/LP_socket.c

@ -296,7 +296,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep
{
txid = jbits256(item,"txid");
v = jint(item,"vout");
value = LP_value_extract(item,0);
value = LP_value_extract(item,0,txid);
ht = LP_txheight(coin,txid);
if ( (retjson= LP_gettxout(coin->symbol,coinaddr,txid,v)) != 0 )
free_json(retjson);

5
iguana/exchanges/LP_swap.c

@ -914,7 +914,7 @@ void LP_bobloop(void *_swap)
} else printf("swap timed out\n");
LP_swap_endcritical = (uint32_t)time(NULL);
if ( err < 0 )
LP_failedmsg(swap->I.req.requestid,swap->I.req.quoteid,err);
LP_failedmsg(swap->I.req.requestid,swap->I.req.quoteid,err,swap->uuidstr);
sleep(13);
LP_pendswap_add(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid);
//swap->I.finished = LP_swapwait(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*3,swap->I.aliceconfirms == 0 ? 3 : 30);
@ -994,7 +994,7 @@ void LP_aliceloop(void *_swap)
}
LP_swap_endcritical = (uint32_t)time(NULL);
if ( err < 0 )
LP_failedmsg(swap->I.req.requestid,swap->I.req.quoteid,err);
LP_failedmsg(swap->I.req.requestid,swap->I.req.quoteid,err,swap->uuidstr);
sleep(13);
LP_pendswap_add(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid);
//swap->I.finished = LP_swapwait(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*3,swap->I.aliceconfirms == 0 ? 3 : 30);
@ -1305,6 +1305,7 @@ struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256
if ( ctx == 0 )
ctx = bitcoin_ctx();
swap = calloc(1,sizeof(*swap));
memcpy(swap->uuidstr,qp->uuidstr,sizeof(swap->uuidstr));
swap->aliceid = LP_aliceid_calc(qp->desttxid,qp->destvout,qp->feetxid,qp->feevout);
swap->I.req.quoteid = rp->quoteid;
swap->ctx = ctx;

4
iguana/exchanges/LP_tradebots.c

@ -322,7 +322,7 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot)
LP_tradebot_calcstats(bot);
if ( bot->dead == 0 && bot->pause == 0 && bot->userpause == 0 && bot->numtrades < sizeof(bot->trades)/sizeof(*bot->trades) )
{
if ( (liststr= LP_recent_swaps(0)) != 0 )
if ( (liststr= LP_recent_swaps(0,0)) != 0 )
{
if ( (retjson= cJSON_Parse(liststr)) != 0 )
{
@ -338,7 +338,7 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot)
{
if ( remaining < 0.001 )
break;
if ( (retstr= LP_autobuy(ctx,0,LP_myipaddr,LP_mypubsock,bot->base,bot->rel,bot->maxprice,remaining/i,0,0,G.gui,0,destpubkey,tradeid)) != 0 )
if ( (retstr= LP_autobuy(ctx,0,LP_myipaddr,LP_mypubsock,bot->base,bot->rel,bot->maxprice,remaining/i,0,0,G.gui,0,destpubkey,tradeid,0)) != 0 )
{
if ( (retjson2= cJSON_Parse(retstr)) != 0 )
{

4
iguana/exchanges/LP_transaction.c

@ -795,7 +795,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && utxovout < n )
{
obj = jitem(vouts,utxovout);
value = LP_value_extract(obj,1);
value = LP_value_extract(obj,1,utxotxid);
//printf("value in vout.%d %.8f (%s)\n",vout,dstr(value),jprint(txobj,0));
}
free_json(txobj);
@ -2155,7 +2155,7 @@ 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);
*valuep = LP_value_extract(vout,1,signedtxid);
LP_destaddr(coinaddr,vout);
}
free_json(txobj);

32
iguana/exchanges/LP_utxo.c

@ -206,9 +206,9 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe
return(mini);
}
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest)
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest,bits256 utxotxid)
{
double val = 0.; uint64_t value = 0; int32_t electrumflag;
double val = 0.; uint64_t interest,value = 0; int32_t electrumflag;
electrumflag = (jobj(obj,"tx_hash") != 0);
if ( electrumflag == 0 )
{
@ -218,8 +218,17 @@ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest)
} else value = j64bits(obj,"value");
if ( value != 0 )
{
if ( addinterest != 0 && jobj(obj,"interest") != 0 )
if ( addinterest != 0 )
{
if ( jobj(obj,"interest") != 0 )
value += (jdouble(obj,"interest") * SATOSHIDEN);
else
{
interest = LP_komodo_interest(utxotxid,value);
//char str[65]; printf("(%s) txid.%s %.8f + %.8f\n",jprint(obj,0),bits256_str(str,utxotxid),dstr(value),dstr(interest));
value += interest;
}
}
}
return(value);
}
@ -320,14 +329,17 @@ int32_t LP_address_minmax(int32_t iambob,uint64_t *medianp,uint64_t *minp,uint64
{
for (i=1; i<m; i++)
{
//printf("%.8f ",dstr(LP_DEPOSITSATOSHIS(buf[i])));
if ( max >= LP_DEPOSITSATOSHIS(buf[i]) )
{
*maxp = buf[i];
*medianp = buf[m/2];
//printf("buf[%d] %.8f -> maxp, m.%d/2 %.8f -> median\n",i,dstr(*maxp),m,dstr(*medianp));
break;
}
}
} else printf("sort error? max %.8f != %.8f\n",dstr(max),dstr(buf[0]));
//printf("vs. max %.8f %s maxp %.8f median %.8f\n",dstr(max),coin->symbol,dstr(*maxp),dstr(*medianp));
}
else
{
@ -358,7 +370,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a
{
if ( (txout= LP_gettxout(coin->symbol,coinaddr,up->U.txid,up->U.vout)) != 0 )
{
if ( LP_value_extract(txout,0) == 0 )
if ( LP_value_extract(txout,0,up->U.txid) == 0 )
{
//char str[65]; printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout);
free_json(txout);
@ -693,7 +705,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr
for (i=0; i<n; i++)
{
item = jitem(array,i);
balance += LP_value_extract(item,1);
balance += LP_value_extract(item,1,zero);
//printf("i.%d (%s) balance %.8f\n",i,jprint(item,0),dstr(balance));
}
}
@ -813,7 +825,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array)
val = j64bits(item,"value");
if ( coin->electrum == 0 && (txobj= LP_gettxout(coin->symbol,coinaddr,txid,v)) != 0 )
{
value = LP_value_extract(txobj,0);
value = LP_value_extract(txobj,0,txid);
if ( value != 0 && value != val )
{
char str[65]; printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",coin->symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(txobj,0));
@ -893,7 +905,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS
for (i=0; i<numvouts; i++)
{
vout = jitem(vouts,i);
tx->outpoints[i].value = LP_value_extract(vout,0);
tx->outpoints[i].value = LP_value_extract(vout,0,txid);
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest");
LP_destaddr(tx->outpoints[i].coinaddr,vout);
//printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value));
@ -1046,7 +1058,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf
destaddr[0] = 0;
if ( (txobj= LP_gettxout(coin->symbol,destaddr,txid,vout)) != 0 )
{
if ( (value= LP_value_extract(txobj,0)) == 0 )
if ( (value= LP_value_extract(txobj,0,txid)) == 0 )
{
char str[65]; printf("%s LP_txvalue.%s strange utxo.(%s) vout.%d\n",coin->symbol,bits256_str(str,txid),jprint(txobj,0),vout);
}
@ -1123,7 +1135,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout)
uint64_t value; char str[65];
if ( (txobj= LP_gettxout(coin->symbol,coinaddr,txid,vout)) != 0 )
{
value = LP_value_extract(txobj,0);//SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest"));
value = LP_value_extract(txobj,0,txid);//SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest"));
if ( coinaddr != 0 )
LP_destaddr(coinaddr,txobj);
//printf("LP_txvalue %s tx %s/v%d value %.8f\n",coin->symbol,bits256_str(str,txid),vout,dstr(value));
@ -1150,7 +1162,7 @@ int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout)
if ( (txjson= LP_gettx("LP_outpoint_amount",symbol,txid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && vout < numvouts )
amount = LP_value_extract(jitem(vouts,vout),0);
amount = LP_value_extract(jitem(vouts,vout),0,txid);
free_json(txjson);
}
}

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

2
iguana/exchanges/install

@ -1,5 +1,5 @@
#!/bin/bash
cp install updateprices get_supernet trackbtc auto_chipskmd auto_chipsbtc pendingswaps fundvalue balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction 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 client_static run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts
cp install updateprices get_supernet trackbtc auto_chipskmd auto_chipsbtc pendingswaps fundvalue balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction 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 client_osx client_static 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 .

14
iguana/exchanges/mm.c

@ -337,16 +337,28 @@ int main(int argc, const char * argv[])
}
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
{
printf("couldnt write to (%s)\n",dirname);
exit(0);
}
sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
{
printf("couldnt write to (%s)\n",dirname);
exit(0);
}
sprintf(dirname,"%s/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
{
printf("couldnt write to (%s)\n",dirname);
exit(0);
}
sprintf(dirname,"%s/UNSPENTS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
{
printf("couldnt write to (%s)\n",dirname);
exit(0);
}
#ifdef FROM_JS
argc = 2;
retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}");
@ -379,7 +391,7 @@ int main(int argc, const char * argv[])
incr = 100.;
while ( LP_STOP_RECEIVED == 0 )
sleep(100000);
}
} else printf("couldnt parse.(%s)\n",argv[1]);
#endif
return 0;
}

27
iguana/exchanges/stats.c

@ -24,6 +24,8 @@
#include <stdio.h>
#include <stdint.h>
#include "../../crypto777/OS_portable.h"
#define IGUANA_MAXRPCTHREADS 1
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define STATS_DESTDIR "/var/www/html"
#define STATS_DEST "/var/www/html/DEXstats.json"
@ -833,7 +835,6 @@ void stats_rpcloop(void *args)
//printf("after sock.%d\n",sock);
clilen = sizeof(cli_addr);
sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen);
//#ifdef _WIN32
if ( sock < 0 )
{
printf("iguana_rpcloop ERROR on accept port.%u usock.%d errno %d %s\n",port,sock,errno,strerror(errno));
@ -841,16 +842,6 @@ void stats_rpcloop(void *args)
bindsock = -1;
continue;
}
/*#else
if ( sock < 0 )
{
//fprintf(stderr,".");
if ( IAMLP == 0 )
usleep(50000);
else usleep(2500);
continue;
}
#endif*/
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
//printf("port.%u got incoming from %x\n",port,ipbits);
if ( DOCKERFLAG != 0 && (DOCKERFLAG == 1 || ipbits == DOCKERFLAG) )
@ -866,25 +857,13 @@ void stats_rpcloop(void *args)
req->sock = sock;
req->ipbits = ipbits;
req->port = port;
if ( spawned > 0 )
if ( spawned >= (IGUANA_MAXRPCTHREADS-1) )
LP_rpc_processreq(req);
// this might lead to "cant open file errors"
else if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
{
printf("error launching rpc handler on port %d, retval.%d\n",port,retval);
LP_rpc_processreq(req);
/*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);
}*/
}
}
printf("i got killed\n");

Loading…
Cancel
Save