Browse Source

Merge pull request #747 from jl777/jl777

uuid
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
6673ac0143
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      iguana/exchanges/LP_commands.c
  2. 10
      iguana/exchanges/LP_include.h
  3. 4
      iguana/exchanges/LP_mmjson.c
  4. 80
      iguana/exchanges/LP_ordermatch.c
  5. 2
      iguana/exchanges/LP_portfolio.c
  6. 4
      iguana/exchanges/LP_prices.c
  7. 18
      iguana/exchanges/LP_remember.c
  8. 2
      iguana/exchanges/LP_signatures.c
  9. 5
      iguana/exchanges/LP_swap.c
  10. 2
      iguana/exchanges/LP_tradebots.c
  11. 3
      iguana/exchanges/LP_utxo.c
  12. 2
      iguana/exchanges/coins
  13. 4
      iguana/exchanges/stats.c

4
iguana/exchanges/LP_commands.c

@ -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\"}"));
}
}

10
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 "27773"
#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];
};
@ -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);

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);

80
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,qp->R.requestid));
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)
@ -1335,7 +1338,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
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 )
@ -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 )
@ -1572,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 )
{
@ -1584,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));
}

2
iguana/exchanges/LP_portfolio.c

@ -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 )

18
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));
@ -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,uint32_t origrequestid)
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));
@ -1776,11 +1785,8 @@ char *LP_recent_swaps(int32_t limit,uint32_t origrequestid)
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 ( origrequestid != 0 )
{
jaddnum(retjson,"requestid",origrequestid);
jaddbits256(retjson,"desthash",G.LP_mypub25519);
}
if ( uuidstr != 0 )
jaddstr(retjson,"uuid",uuidstr);
return(jprint(retjson,1));
}

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 )

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;

2
iguana/exchanges/LP_tradebots.c

@ -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 )
{

3
iguana/exchanges/LP_utxo.c

@ -329,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
{

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

4
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"
@ -855,7 +857,7 @@ 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 )

Loading…
Cancel
Save