Browse Source

Merge pull request #531 from jl777/spvdex

bugfixes
etomic
jl777 7 years ago
committed by GitHub
parent
commit
d9458cd6a0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      iguana/exchanges/LP_coins.c
  2. 2
      iguana/exchanges/LP_commands.c
  3. 7
      iguana/exchanges/LP_include.h
  4. 94
      iguana/exchanges/LP_instantdex.c
  5. 17
      iguana/exchanges/LP_nativeDEX.c
  6. 5
      iguana/exchanges/LP_ordermatch.c
  7. 251
      iguana/exchanges/LP_portfolio.c
  8. 26
      iguana/exchanges/LP_prices.c
  9. 28
      iguana/exchanges/LP_privkey.c
  10. 44
      iguana/exchanges/LP_remember.c
  11. 7
      iguana/exchanges/LP_signatures.c
  12. 22
      iguana/exchanges/LP_statemachine.c
  13. 9
      iguana/exchanges/LP_tradebots.c
  14. 4
      iguana/exchanges/LP_transaction.c
  15. 2
      iguana/exchanges/auto_chipsbtc
  16. 2
      iguana/exchanges/auto_chipskmd
  17. 2
      iguana/exchanges/install

8
iguana/exchanges/LP_coins.c

@ -214,7 +214,7 @@ uint16_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot,
cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
{
struct electrum_info *ep; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject();
struct electrum_info *ep; bits256 zero; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject();
jaddstr(item,"coin",coin->symbol);
if ( showwif != 0 )
{
@ -261,6 +261,12 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
jaddnum(item,"txfee",strcmp(coin->symbol,"BTC") != 0 ? coin->txfee : LP_txfeecalc(coin,0,0));
if ( strcmp(coin->symbol,"KMD") == 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( strcmp(coin->smartaddr,coin->instantdex_address) != 0 )
{
LP_instantdex_depositadd(coin->smartaddr,zero);
strcpy(coin->instantdex_address,coin->smartaddr);
}
jaddnum(item,"zcredits",dstr(LP_myzcredits()));
jadd(item,"zdebits",LP_myzdebits());
}

2
iguana/exchanges/LP_commands.c

@ -321,7 +321,7 @@ instantdex_claim()\n\
double price,bid,ask;
if ( strcmp(method,"autoprice") == 0 )
{
if ( LP_autoprice(base,rel,argjson) < 0 )
if ( LP_autoprice(ctx,base,rel,argjson) < 0 )
return(clonestr("{\"error\":\"couldnt set autoprice\"}"));
else return(clonestr("{\"result\":\"success\"}"));
}

7
iguana/exchanges/LP_include.h

@ -294,7 +294,7 @@ struct iguana_info
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
uint32_t dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128];
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64];
// portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx;
@ -506,6 +506,8 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_
//void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo);
struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout);
int64_t LP_myzcredits();
void LP_instantdex_depositadd(char *coinaddr,bits256 txid);
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr);
int32_t LP_destaddr(char *destaddr,cJSON *item);
int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration);
cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel);
@ -517,6 +519,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS
int32_t LP_mempoolscan(char *symbol,bits256 searchtxid);
int32_t LP_txheight(struct iguana_info *coin,bits256 txid);
int32_t LP_numpeers();
double LP_CMCbtcprice(double *price_usdp,char *symbol);
char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag);
int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance);
int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight);
@ -527,6 +530,8 @@ cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout);
void LP_postutxos(char *symbol,char *coinaddr);
int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag);
uint16_t LP_randpeer(char *destip);
void LP_tradebot_pauseall();
void LP_portfolio_reset();
uint32_t LP_atomic_locktime(char *base,char *rel);
struct LP_pubkey_info *LP_pubkeyfind(bits256 pubkey);
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired);

94
iguana/exchanges/LP_instantdex.c

@ -19,16 +19,24 @@
// marketmaker
//
void LP_instantdex_txidaddfname(char *fname,char *afname)
void LP_instantdex_txidaddfname(char *fname,char *afname,char *coinaddr)
{
sprintf(fname,"%s/instantdex.json",GLOBAL_DBDIR);
sprintf(afname,"%s/instantdex_append.json",GLOBAL_DBDIR);
if ( coinaddr == 0 || coinaddr[0] == 0 )
{
sprintf(fname,"%s/instantdex.json",GLOBAL_DBDIR);
sprintf(afname,"%s/instantdex_append.json",GLOBAL_DBDIR);
}
else
{
sprintf(fname,"%s/instantdex_%s.json",GLOBAL_DBDIR,coinaddr);
sprintf(afname,"%s/instantdex_%s_append.json",GLOBAL_DBDIR,coinaddr);
}
}
cJSON *LP_instantdex_txids(int32_t appendonly)
cJSON *LP_instantdex_txids(int32_t appendonly,char *coinaddr)
{
char *filestr,fname[1024],afname[1024]; long fsize; cJSON *retjson=0;
LP_instantdex_txidaddfname(fname,afname);
LP_instantdex_txidaddfname(fname,afname,coinaddr);
if ( (filestr= OS_filestr(&fsize,appendonly != 0 ? afname : fname)) != 0 )
{
retjson = cJSON_Parse(filestr);
@ -37,10 +45,10 @@ cJSON *LP_instantdex_txids(int32_t appendonly)
return(retjson);
}
void LP_instantdex_filewrite(int32_t appendfile,cJSON *array)
void LP_instantdex_filewrite(int32_t appendfile,cJSON *array,char *coinaddr)
{
FILE *fp; char *filestr,fname[1024],afname[1024];
LP_instantdex_txidaddfname(fname,afname);
LP_instantdex_txidaddfname(fname,afname,coinaddr);
if ( (fp= fopen(appendfile == 0 ? fname : afname,"wb")) != 0 )
{
filestr = jprint(array,0);
@ -60,7 +68,7 @@ void LP_instantdex_deposituniq(FILE *fp,bits256 txid)
fread(&prevtxid,1,sizeof(prevtxid),fp);
if ( bits256_cmp(prevtxid,txid) == 0 )
{
printf("%s duplicate of deposits[%d]\n",bits256_str(str,prevtxid),i);
//printf("%s duplicate of deposits[%d]\n",bits256_str(str,prevtxid),i);
break;
}
}
@ -96,53 +104,51 @@ void LP_instantdex_filescreate(char *coinaddr)
jaddibits256(newarray,txid);
}
fclose(fp);
LP_instantdex_filewrite(0,newarray);
LP_instantdex_filewrite(0,newarray,coinaddr);
free_json(newarray);
LP_instantdex_filewrite(1,array);
LP_instantdex_filewrite(1,array,coinaddr);
free_json(array);
}
}
void LP_instantdex_depositadd(char *coinaddr,bits256 txid)
{
static FILE *depositsfp;
char fname[512],str[65]; bits256 prevtxid; cJSON *array,*txobj; int32_t i,n,iter;
if ( depositsfp == 0 )
FILE *fp; struct iguana_info *coin; char fname[512],*addr; bits256 prevtxid; cJSON *array; int32_t i,n,iter;
coin = LP_coinfind("KMD");
sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname);
if ( (fp= fopen(fname,"rb+")) == 0 )
{
sprintf(fname,"%s/deposits.%s",GLOBAL_DBDIR,coinaddr), OS_compatible_path(fname);
if ( (depositsfp= fopen(fname,"rb+")) == 0 )
if ( (fp= fopen(fname,"wb+")) != 0 )
{
depositsfp = fopen(fname,"wb+");
for (iter=0; iter<2; iter++)
for (iter=0; iter<4; iter++)
{
if ( (array= LP_instantdex_txids(iter)) != 0 )
if ( iter < 2 )
addr = coinaddr;
else addr = "";
if ( coin != 0 && (array= LP_instantdex_txids(iter&1,addr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
prevtxid = jbits256i(array,i);
printf("instantdex iter.%d i.%d check %s\n",iter,i,bits256_str(str,prevtxid));
if ( (txobj= LP_gettxout("KMD",coinaddr,prevtxid,0)) != 0 )
free_json(txobj);
else
//char str[65]; printf("instantdex iter.%d i.%d check %s\n",iter,i,bits256_str(str,prevtxid));
if ( LP_instantdex_creditcalc(coin,0,prevtxid,coinaddr) > 0 )
{
printf("null gettxout %s %s\n",coinaddr,bits256_str(str,prevtxid));
continue;
LP_instantdex_deposituniq(fp,prevtxid);
fflush(fp);
}
LP_instantdex_deposituniq(depositsfp,prevtxid);
fflush(depositsfp);
}
}
free_json(array);
}
}
} else fseek(depositsfp,0,SEEK_END);
}
if ( depositsfp != 0 && bits256_nonz(txid) != 0 )
}
} else fseek(fp,0,SEEK_END);
if ( fp != 0 && bits256_nonz(txid) != 0 )
{
LP_instantdex_deposituniq(depositsfp,txid);
fflush(depositsfp);
LP_instantdex_deposituniq(fp,txid);
fclose(fp);
}
LP_instantdex_filescreate(coinaddr);
}
@ -350,7 +356,7 @@ char *LP_instantdex_claim(struct iguana_info *coin)
sum = 0;
txids = cJSON_CreateArray();
newarray = cJSON_CreateArray();
if ( (array= LP_instantdex_txids(firsttime)) != 0 )
if ( (array= LP_instantdex_txids(firsttime,coin->smartaddr)) != 0 )
{
printf("claiming from.(%s)\n",jprint(array,0));
if ( (n= cJSON_GetArraySize(array)) > 0 )
@ -367,7 +373,7 @@ char *LP_instantdex_claim(struct iguana_info *coin)
}
firsttime = 0;
if ( cJSON_GetArraySize(newarray) > 0 )
LP_instantdex_filewrite(0,newarray);
LP_instantdex_filewrite(0,newarray,coin->smartaddr);
free_json(newarray);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
@ -480,15 +486,18 @@ int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue)
credits = ap->instantdex_credits;
if ( credits != 0 && (swaps_kmdvalue+kmdvalue) > credits )
{
DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp)
if ( 0 )
{
if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 )
printf("unfinished bob %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis)));
}
DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp)
{
if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 )
printf("unfinished alice %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis)));
DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp)
{
if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 )
printf("unfinished bob %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis)));
}
DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp)
{
if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 )
printf("unfinished alice %llu r%u-r%u src.%s %.8f dest.%s %.8f -> price %.8f value %.8f\n",(long long)sp->aliceid,sp->Q.R.requestid,sp->Q.R.quoteid,sp->Q.srccoin,dstr(sp->Q.satoshis),sp->Q.destcoin,dstr(sp->Q.destsatoshis),(double)sp->Q.destsatoshis/(sp->Q.satoshis+1),dstr(LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis)));
}
}
printf("REJECT: %s instantdex_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(credits),dstr(swaps_kmdvalue),dstr(kmdvalue));
}
@ -506,6 +515,7 @@ int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num)
{
bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr);
bitcoin_address(othersmartaddr,0,60,rmd160,20);
printf("proofcheck addrtype.%d (%s) -> %s\n",addrtype,coinaddr,othersmartaddr);
if ((ap= LP_address(coin,othersmartaddr)) != 0 )
{
ap->instantdex_credits = 0;
@ -535,7 +545,7 @@ int64_t LP_myzcredits()
cJSON *proof; struct iguana_info *coin; int64_t zcredits;
if ( (coin= LP_coinfind("KMD")) != 0 )
{
if ( (proof= LP_instantdex_txids(0)) != 0 )
if ( (proof= LP_instantdex_txids(0,coin->smartaddr)) != 0 )
{
zcredits = LP_instantdex_proofcheck(coin->smartaddr,proof,cJSON_GetArraySize(proof));
free_json(proof);

17
iguana/exchanges/LP_nativeDEX.c

@ -17,20 +17,20 @@
// LP_nativeDEX.c
// marketmaker
//
// fundvalue -> autoprice, cmc +margin -> autoprice, signals -> autoprice
// ordermatch pricing error
// https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG
// there is an issue about waiting for notarization for a swap that never starts
// use electrum in case of addr change in swap
//
// compress packets
// portfolio to set prices from historical
// portfolio value based on ask?
//
// else claim path
// swap memleak?
//
// WONTFIX:
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
// bigendian architectures need to use little endian for sighash calcs
// improve critical section detection when parallel trades
// use electrum in case of addr change in swap
// locktime claiming on sporadic assetchains
// there is an issue about waiting for notarization for a swap that never starts (expiration ok)
#include <stdio.h>
@ -1158,9 +1158,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
exit(-1);
}
LP_initcoins(ctx,pubsock,coinsjson);
G.waiting = 1;
LP_passphrase_init(passphrase,jstr(argjson,"gui"));
//char coinaddr[64]; bits256 zero;
//bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20);
//memset(zero.bytes,0,sizeof(zero));
//LP_instantdex_depositadd(coinaddr,zero);
#ifndef FROM_JS
if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 )
{

5
iguana/exchanges/LP_ordermatch.c

@ -444,7 +444,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double price,struct LP_quoteinfo *qp)
{
char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin;
char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin,*kmdcoin;
qp->quotetime = (uint32_t)time(NULL);
if ( (coin= LP_coinfind(qp->srccoin)) == 0 )
{
@ -475,7 +475,8 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
reqjson = LP_quotejson(qp);
jaddstr(reqjson,"method","connected");
jaddstr(reqjson,"pair",pairstr);
jadd(reqjson,"proof",LP_instantdex_txids(0));
if ( (kmdcoin= LP_coinfind("KMD")) != 0 )
jadd(reqjson,"proof",LP_instantdex_txids(0,kmdcoin->smartaddr));
char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash));
bits256 zero;
memset(zero.bytes,0,sizeof(zero));

251
iguana/exchanges/LP_portfolio.c

@ -18,9 +18,52 @@
// marketmaker
//
struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; };
struct LP_autoprice_ref
{
char refbase[65],refrel[65],base[65],rel[65],fundbid[16],fundask[16];
double margin,factor,offset;
cJSON *fundvalue;
} LP_autorefs[100];
int32_t LP_autoprices,num_LP_autorefs;
char LP_portfolio_base[128],LP_portfolio_rel[128];
double LP_portfolio_relvolume;
void LP_portfolio_reset()
{
struct iguana_info *coin,*tmp; cJSON *fundjson; int32_t i; struct LP_autoprice_ref *ptr;
for (i=0; i<num_LP_autorefs; i++)
{
ptr = &LP_autorefs[i];
if ( (fundjson= ptr->fundvalue) != 0 )
{
ptr->fundvalue = 0;
free_json(fundjson);
}
}
memset(LP_autorefs,0,sizeof(LP_autorefs));
LP_autoprices = 0;
num_LP_autorefs = 0;
strcpy(LP_portfolio_base,"");
strcpy(LP_portfolio_rel,"");
LP_portfolio_relvolume = 0.;
HASH_ITER(hh,LP_coins,coin,tmp)
{
coin->maxamount = 0;
coin->perc = 0;
coin->goal = 0;
coin->goalperc = 0;
coin->relvolume = 0;
coin->force = 0;
coin->balanceA = 0;
coin->valuesumA = 0;
coin->balanceB = 0;
coin->valuesumB = 0;
}
}
cJSON *LP_portfolio_entry(struct iguana_info *coin)
{
cJSON *item = cJSON_CreateObject();
@ -201,13 +244,6 @@ char *LP_portfolio_goal(char *symbol,double goal)
} else return(clonestr("{\"error\":\"cant set goal for inactive coin\"}"));
}
int32_t LP_autoprices,num_LP_autorefs;
struct LP_autoprice_ref
{
char refbase[65],refrel[65],base[65],rel[65];
} LP_autorefs[100];
/*int32_t LP_autofill(char *base,char *rel,double maxprice,double totalrelvolume)
{
struct LP_priceinfo *basepp,*relpp;
@ -221,58 +257,6 @@ struct LP_autoprice_ref
return(-1);
}*/
int32_t LP_autoprice(char *base,char *rel,cJSON *argjson)
{
//curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}"
struct LP_priceinfo *basepp,*relpp; int32_t i; char *refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice;
//printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0));
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
if ( jobj(argjson,"minprice") != 0 )
minprice = jdouble(argjson,"minprice");
else minprice = 0.;
margin = jdouble(argjson,"margin");
offset = jdouble(argjson,"offset");
factor = jdouble(argjson,"factor");
fixedprice = jdouble(argjson,"fixed");
basepp->fixedprices[relpp->ind] = fixedprice;
basepp->minprices[relpp->ind] = minprice;
basepp->margins[relpp->ind] = margin;
basepp->offsets[relpp->ind] = offset;
basepp->factors[relpp->ind] = factor;
if ( fixedprice > SMALLVAL || ((refbase= jstr(argjson,"refbase")) != 0 && (refrel= jstr(argjson,"refrel")) != 0) )
{
if ( fixedprice > SMALLVAL )
{
refbase = base;
refrel = rel;
}
for (i=0; i<num_LP_autorefs; i++)
{
if ( strcmp(base,LP_autorefs[i].base) == 0 && strcmp(rel,LP_autorefs[i].rel) == 0 )
{
safecopy(LP_autorefs[i].refbase,refbase,sizeof(LP_autorefs[i].refbase));
safecopy(LP_autorefs[i].refrel,refrel,sizeof(LP_autorefs[i].refrel));
printf("%d Update ref %s/%s for %s/%s factor %.8f offset %.8f\n",i,refbase,refrel,base,rel,factor,offset);
break;
}
}
if ( i == num_LP_autorefs && num_LP_autorefs < sizeof(LP_autorefs)/sizeof(*LP_autorefs) )
{
safecopy(LP_autorefs[num_LP_autorefs].refbase,refbase,sizeof(LP_autorefs[num_LP_autorefs].refbase));
safecopy(LP_autorefs[num_LP_autorefs].refrel,refrel,sizeof(LP_autorefs[num_LP_autorefs].refrel));
safecopy(LP_autorefs[num_LP_autorefs].base,base,sizeof(LP_autorefs[num_LP_autorefs].base));
safecopy(LP_autorefs[num_LP_autorefs].rel,rel,sizeof(LP_autorefs[num_LP_autorefs].rel));
printf("%d Using ref %s/%s for %s/%s factor %.8f, offset %.8f, margin %.8f fixed %.8f\n",num_LP_autorefs,refbase,refrel,base,rel,factor,offset,margin,fixedprice);
num_LP_autorefs++;
}
}
LP_autoprices++;
return(0);
}
return(-1);
}
void LP_autopriceset(void *ctx,int32_t dir,struct LP_priceinfo *basepp,struct LP_priceinfo *relpp,double price,char *refbase,char *refrel)
{
static uint32_t lasttime;
@ -418,7 +402,7 @@ double LP_pricesparse(void *ctx,int32_t trexflag,char *retstr,struct LP_priceinf
void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
{
char *retstr; cJSON *retjson,*bid,*ask; uint64_t bidsatoshis,asksatoshis; int32_t i; double nxtkmd,price; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp;
char *retstr,*base,*rel; cJSON *retjson,*bid,*ask,*fundjson,*argjson; uint64_t bidsatoshis,asksatoshis; int32_t i,changed; double nxtkmd,price,factor,offset,newprice,margin,price_btc,price_usd,kmd_btc,kmd_usd; struct LP_priceinfo *kmdpp,*fiatpp,*nxtpp,*basepp,*relpp;
if ( (retstr= issue_curlt("https://bittrex.com/api/v1.1/public/getmarketsummaries",LP_HTTP_TIMEOUT*10)) == 0 )
{
printf("trex error getting marketsummaries\n");
@ -477,18 +461,153 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
}
}
}
kmd_btc = LP_CMCbtcprice(&kmd_usd,"komodo");
for (i=0; i<num_LP_autorefs; i++)
{
basepp = LP_priceinfofind(LP_autorefs[i].base);
relpp = LP_priceinfofind(LP_autorefs[i].rel);
if ( basepp != 0 && relpp != 0 )
rel = LP_autorefs[i].rel;
base = LP_autorefs[i].base;
margin = LP_autorefs[i].margin;
offset = LP_autorefs[i].offset;
factor = LP_autorefs[i].factor;
if ( (argjson= LP_autorefs[i].fundvalue) != 0 )
{
if ( (fundjson= LP_fundvalue(argjson)) != 0 )
{
if ( jint(fundjson,"missing") == 0 )
{
if ( LP_autorefs[i].fundbid[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundbid)) > SMALLVAL )
{
newprice = (1. / price) * (1. + margin);
LP_mypriceset(&changed,rel,base,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice);
//printf("fundbid %.8f margin %.8f newprice %.8f\n",price,margin,newprice);
}
if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL )
{
newprice = (price * (1. + margin));
LP_mypriceset(&changed,base,rel,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice);
//printf("fundask %.8f margin %.8f newprice %.8f\n",price,margin,newprice);
}
}
free_json(fundjson);
}
}
else if ( strcmp(LP_autorefs[i].refrel,"coinmarketcap") == 0 )
{
//printf("check ref-autoprice %s/%s %f %f\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel,relpp->fixedprices[basepp->ind],basepp->fixedprices[relpp->ind]);
LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel);
//printf("%s/%s for %s/%s margin %.8f\n",base,rel,LP_autorefs[i].refbase,LP_autorefs[i].refrel,margin);
if ( (price_btc= LP_CMCbtcprice(&price_usd,LP_autorefs[i].refbase)) > SMALLVAL )
{
if ( strcmp(rel,"KMD") == 0 )
price = kmd_btc / price_btc;
else if ( strcmp(rel,"BTC") == 0 )
price = 1. / price_btc;
else continue;
if ( factor > 0. )
price = (price * factor) + offset;
newprice = (price * (1. + margin));
LP_mypriceset(&changed,rel,base,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice);
printf("price %.8f margin %.8f newprice %.8f %.8f\n",price,margin,newprice,(1. / price) * (1. + margin));
newprice = (1. / price) * (1. + margin);
LP_mypriceset(&changed,base,rel,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice);
}
}
else
{
basepp = LP_priceinfofind(base);
relpp = LP_priceinfofind(rel);
if ( basepp != 0 && relpp != 0 )
{
//printf("check ref-autoprice %s/%s %f %f\n",LP_autorefs[i].refbase,LP_autorefs[i].refrel,relpp->fixedprices[basepp->ind],basepp->fixedprices[relpp->ind]);
LP_autopriceset(ctx,1,basepp,relpp,0.,LP_autorefs[i].refbase,LP_autorefs[i].refrel);
}
}
}
}
int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson)
{
//curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"offset\":0.1,\"refbase\":\"KMD\",\refrel\":\"BTC\",\"factor\":15000,\"margin\":0.01}"
struct LP_priceinfo *basepp,*relpp; int32_t i,retval = -1; char *fundvalue_bid,*fundvalue_ask,*refbase="",*refrel=""; double minprice,margin,offset,factor,fixedprice; cJSON *fundvalue;
//printf("autoprice.(%s %s) %s\n",base,rel,jprint(argjson,0));
if ( (basepp= LP_priceinfofind(base)) != 0 && (relpp= LP_priceinfofind(rel)) != 0 )
{
if ( jobj(argjson,"minprice") != 0 )
minprice = jdouble(argjson,"minprice");
else minprice = 0.;
margin = jdouble(argjson,"margin");
offset = jdouble(argjson,"offset");
factor = jdouble(argjson,"factor");
fixedprice = jdouble(argjson,"fixed");
basepp->fixedprices[relpp->ind] = fixedprice;
basepp->minprices[relpp->ind] = minprice;
basepp->margins[relpp->ind] = margin;
basepp->offsets[relpp->ind] = offset;
basepp->factors[relpp->ind] = factor;
refbase = jstr(argjson,"refbase");
refrel = jstr(argjson,"refrel");
fundvalue_bid = jstr(argjson,"fundvalue_bid");
fundvalue_ask = jstr(argjson,"fundvalue_ask");
if ( fundvalue_bid != 0 || fundvalue_ask != 0 || fixedprice > SMALLVAL || (refbase != 0 && refrel != 0) )
{
if ( fixedprice > SMALLVAL )
{
refbase = base;
refrel = rel;
}
for (i=0; i<num_LP_autorefs; i++)
{
if ( strcmp(base,LP_autorefs[i].base) == 0 && strcmp(rel,LP_autorefs[i].rel) == 0 )
{
if ( fundvalue_bid != 0 || fundvalue_ask != 0 )
{
fundvalue = jduplicate(argjson);
jdelete(fundvalue,"method");
jaddstr(fundvalue,"method","fundvalue");
LP_autorefs[i].fundvalue = fundvalue;
safecopy(LP_autorefs[i].fundbid,fundvalue_bid,sizeof(LP_autorefs[i].fundbid));
safecopy(LP_autorefs[i].fundask,fundvalue_ask,sizeof(LP_autorefs[i].fundask));
}
LP_autorefs[i].margin = margin;
LP_autorefs[i].factor = factor;
LP_autorefs[i].offset = offset;
safecopy(LP_autorefs[i].refbase,refbase,sizeof(LP_autorefs[i].refbase));
safecopy(LP_autorefs[i].refrel,refrel,sizeof(LP_autorefs[i].refrel));
printf("%d Update ref %s/%s for %s/%s factor %.8f offset %.8f\n",i,refbase,refrel,base,rel,factor,offset);
break;
}
}
if ( i == num_LP_autorefs && num_LP_autorefs < sizeof(LP_autorefs)/sizeof(*LP_autorefs) )
{
if ( fundvalue_bid != 0 || fundvalue_ask != 0 )
{
fundvalue = jduplicate(argjson);
jdelete(fundvalue,"method");
jaddstr(fundvalue,"method","fundvalue");
LP_autorefs[num_LP_autorefs].fundvalue = fundvalue;
safecopy(LP_autorefs[num_LP_autorefs].fundbid,fundvalue_bid,sizeof(LP_autorefs[num_LP_autorefs].fundbid));
safecopy(LP_autorefs[num_LP_autorefs].fundask,fundvalue_ask,sizeof(LP_autorefs[num_LP_autorefs].fundask));
}
LP_autorefs[num_LP_autorefs].margin = margin;
LP_autorefs[num_LP_autorefs].factor = factor;
LP_autorefs[num_LP_autorefs].offset = offset;
safecopy(LP_autorefs[num_LP_autorefs].refbase,refbase,sizeof(LP_autorefs[num_LP_autorefs].refbase));
safecopy(LP_autorefs[num_LP_autorefs].refrel,refrel,sizeof(LP_autorefs[num_LP_autorefs].refrel));
safecopy(LP_autorefs[num_LP_autorefs].base,base,sizeof(LP_autorefs[num_LP_autorefs].base));
safecopy(LP_autorefs[num_LP_autorefs].rel,rel,sizeof(LP_autorefs[num_LP_autorefs].rel));
printf("%d Using ref %s/%s for %s/%s factor %.8f, offset %.8f, margin %.8f fixed %.8f\n",num_LP_autorefs,refbase,refrel,base,rel,factor,offset,margin,fixedprice);
num_LP_autorefs++;
}
}
LP_autoprices++;
retval = 0;
}
//LP_autoprice_iter(ctx,LP_priceinfofind("BTC"));
return(retval);
}
int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,struct iguana_info *buy,struct iguana_info *sell,double relvolume,int32_t setbaserel,char *gui)
{
char *retstr2; uint64_t txfee,desttxfee; double bid,ask,maxprice; bits256 zero; uint32_t requestid,quoteid,iter,i; cJSON *retjson2; struct LP_utxoinfo A; struct LP_address_utxo *utxos[1000]; int32_t max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
@ -558,8 +677,6 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str
else return(-1);
}
struct LP_portfoliotrade { double metric; char buycoin[65],sellcoin[65]; };
int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *array)
{
int32_t i,j,m,n = 0; cJSON *item; struct LP_portfoliotrade coins[256];

26
iguana/exchanges/LP_prices.c

@ -33,7 +33,7 @@ struct LP_priceinfo
char symbol[68];
uint64_t coinbits;
int32_t ind,pad;
double diagval,high[2],low[2],last[2],bid[2],ask[2]; //volume,btcvolume,prevday; // mostly bittrex info
double diagval,high[2],low[2],last[2],bid[2],ask[2];
double relvals[LP_MAXPRICEINFOS];
double myprices[LP_MAXPRICEINFOS];
double minprices[LP_MAXPRICEINFOS]; // autoprice
@ -53,6 +53,20 @@ struct LP_cacheinfo
uint32_t timestamp;
} *LP_cacheinfos;
void LP_priceinfos_clear()
{
int32_t i; struct LP_priceinfo *pp;
for (i=0; i<LP_numpriceinfos; i++)
{
pp = &LP_priceinfos[i];
memset(pp->myprices,0,sizeof(pp->myprices));
memset(pp->minprices,0,sizeof(pp->minprices));
memset(pp->fixedprices,0,sizeof(pp->fixedprices));
memset(pp->margins,0,sizeof(pp->margins));
memset(pp->offsets,0,sizeof(pp->offsets));
memset(pp->factors,0,sizeof(pp->factors));
}
}
float LP_pubkey_price(int32_t *numutxosp,int64_t *avesatoshisp,int64_t *maxsatoshisp,struct LP_pubkey_info *pubp,uint32_t baseind,uint32_t relind)
{
@ -915,8 +929,8 @@ int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance)
KMDvalue = balance;
else
{
price = LP_price(coin->symbol,"KMD");
KMDvalue = price * balance;
if ( (price= LP_price(coin->symbol,"KMD")) > SMALLVAL )
KMDvalue = price * balance;
}
}
return(KMDvalue);
@ -1140,7 +1154,7 @@ double LP_CMCbtcprice(double *price_usdp,char *symbol)
cJSON *LP_fundvalue(cJSON *argjson)
{
cJSON *holdings,*item,*newitem,*array,*retjson; int32_t i,iter,n; double usdprice,divisor,btcprice,balance,btcsum,KMDholdings,numKMD; struct iguana_info *coin; char *symbol,*coinaddr; int64_t fundvalue,KMDvalue = 0;
cJSON *holdings,*item,*newitem,*array,*retjson; int32_t i,iter,n,missing=0; double usdprice,divisor,btcprice,balance,btcsum,KMDholdings,numKMD; struct iguana_info *coin; char *symbol,*coinaddr; int64_t fundvalue,KMDvalue = 0;
fundvalue = 0;
KMDholdings = btcsum = 0.;
array = cJSON_CreateArray();
@ -1180,11 +1194,13 @@ cJSON *LP_fundvalue(cJSON *argjson)
}
else jaddstr(newitem,"error","no price source");
jaddi(array,newitem);
}
} else missing++;
}
}
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddnum(retjson,"missing",missing);
jadd(retjson,"holdings",array);
btcprice = LP_CMCbtcprice(&usdprice,"komodo");
divisor = jdouble(argjson,"divisor");

28
iguana/exchanges/LP_privkey.c

@ -307,7 +307,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase)
int32_t LP_passphrase_init(char *passphrase,char *gui)
{
static void *ctx; char coinaddr[64]; bits256 zero; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp;
static void *ctx; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp;
if ( ctx == 0 )
ctx = bitcoin_ctx();
if ( G.LP_pendingswaps != 0 )
@ -321,36 +321,16 @@ int32_t LP_passphrase_init(char *passphrase,char *gui)
printf("waiting for G.waiting\n");
sleep(5);
}
/*for (iambob=0; iambob<2; iambob++)
{
if ( G.LP_utxoinfos[iambob] != 0 )
{
HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp)
{
HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo);
//free(utxo);
}
}
if ( G.LP_utxoinfos2[iambob] != 0 )
{
G.LP_utxoinfos2[iambob] = 0;
//HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp)
//{
// HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo);
// free(utxo);
//}
}
}*/
memset(&G,0,sizeof(G));
LP_privkey_updates(ctx,LP_mypubsock,passphrase);
init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20);
G.LP_sessionid = (uint32_t)time(NULL);
safecopy(G.gui,gui,sizeof(G.gui));
LP_tradebot_pauseall();
LP_portfolio_reset();
LP_priceinfos_clear();
G.USERPASS_COUNTER = counter;
G.initializing = 0;
bitcoin_address(coinaddr,0,60,G.LP_myrmd160,20);
memset(zero.bytes,0,sizeof(zero));
LP_instantdex_depositadd(coinaddr,zero);
return(0);
}

44
iguana/exchanges/LP_remember.c

@ -375,11 +375,18 @@ int32_t basilisk_swap_isfinished(int32_t iambob,bits256 *txids,int32_t *sentflag
}
else if ( bits256_nonz(Apaymentspent) != 0 )
return(1);
else if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(depositspent) != 0 )
return(1);
}
else
{
if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 && sentflags[BASILISK_ALICEPAYMENT] == 0 )
return(1);
if ( sentflags[BASILISK_ALICEPAYMENT] == 0 )
{
if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 )
return(1);
else if ( sentflags[BASILISK_BOBPAYMENT] != 0 && sentflags[BASILISK_BOBREFUND] != 0 )
return(1);
}
else
{
if ( sentflags[BASILISK_ALICERECLAIM] != 0 || sentflags[BASILISK_ALICESPEND] != 0 )
@ -898,7 +905,12 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 )
{
//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);
return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}"));
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap never started");
jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid);
return(retjson);
//return(cJSON_Parse("{\"error\":\"mismatched bob/alice vs src/dest coins??\"}"));
}
alice = LP_coinfind(rswap.alicecoin);
bob = LP_coinfind(rswap.bobcoin);
@ -911,6 +923,15 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
bitcoin_address(otheraddr,alice->taddr,alice->pubtype,rswap.other33,33);
destBdest = otheraddr;
destAdest = rswap.Adestaddr;
if ( strcmp(alice->smartaddr,rswap.Adestaddr) != 0 )
{
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");
jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid);
return(retjson);
}
}
if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 )
{
@ -926,6 +947,15 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
bitcoin_address(otheraddr,bob->taddr,bob->pubtype,rswap.other33,33);
srcAdest = otheraddr;
srcBdest = rswap.destaddr;
if ( strcmp(bob->smartaddr,rswap.destaddr) != 0 )
{
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");
jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid);
return(retjson);
}
}
if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 )
{
@ -1004,7 +1034,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
}
if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 )
{
if ( time(NULL) > rswap.expiration )
if ( time(NULL) > rswap.expiration+777 )
{
flag = 0;
if ( bob->electrum == 0 )
@ -1093,7 +1123,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0;
else flag = -1, rswap.paymentspent = deadtxid;
}
if ( flag == 0 && time(NULL) > rswap.expiration )
if ( flag == 0 && time(NULL) > rswap.expiration+777 )
{
// bobreclaim
redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,zero,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256);
@ -1122,7 +1152,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0;
else flag = -1, rswap.depositspent = deadtxid;
}
if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration) )
if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777) )
{
printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration);
//if ( txbytes[BASILISK_BOBREFUND] == 0 )
@ -1350,7 +1380,7 @@ char *LP_recent_swaps(int32_t limit)
subitem = cJSON_CreateObject();
jaddnum(subitem,base,srcamount);
jaddnum(subitem,rel,destamount);
jaddnum(subitem,"price",destamount/srcamount);
jaddnum(subitem,"price",-destamount/srcamount);
jaddi(item,subitem);
}
} else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind);

7
iguana/exchanges/LP_signatures.c

@ -643,7 +643,7 @@ void LP_listunspent_query(char *symbol,char *coinaddr)
void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp)
{
cJSON *reqjson; bits256 zero; char *msg; int32_t flag = 0;
cJSON *reqjson; bits256 zero; char *msg; struct iguana_info *coin; int32_t flag = 0;
if ( strcmp(method,"request") == 0 )
{
if ( LP_allocated(qp->desttxid,qp->destvout) == 0 && LP_allocated(qp->feetxid,qp->feevout) == 0 )
@ -665,7 +665,10 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
if ( jobj(reqjson,"timestamp") == 0 )
jaddnum(reqjson,"timestamp",time(NULL));
if ( strcmp(method,"connect") == 0 )
jadd(reqjson,"proof",LP_instantdex_txids(0));
{
if ( (coin= LP_coinfind("KMD")) != 0 )
jadd(reqjson,"proof",LP_instantdex_txids(0,coin->smartaddr));
}
msg = jprint(reqjson,1);
printf("QUERY.(%s)\n",msg);
//if ( bits256_nonz(qp->srchash) == 0 || strcmp(method,"request") != 0 )

22
iguana/exchanges/LP_statemachine.c

@ -490,6 +490,28 @@ void LP_instantdex_txidadd(bits256 txid)
return((double)destsatoshis / satoshis);
else return(0.);
}*/
/*for (iambob=0; iambob<2; iambob++)
{
if ( G.LP_utxoinfos[iambob] != 0 )
{
HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp)
{
HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo);
//free(utxo);
}
}
if ( G.LP_utxoinfos2[iambob] != 0 )
{
G.LP_utxoinfos2[iambob] = 0;
//HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp)
//{
// HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo);
// free(utxo);
//}
}
}*/
char *issue_LP_getprices(char *destip,uint16_t destport)
{
char url[512];

9
iguana/exchanges/LP_tradebots.c

@ -40,6 +40,15 @@ struct LP_tradebot
struct LP_tradebot_trade *trades[LP_TRADEBOTS_MAXTRADES];
} *LP_tradebots;
void LP_tradebot_pauseall()
{
struct LP_tradebot *bot,*tmp;
DL_FOREACH_SAFE(LP_tradebots,bot,tmp)
{
bot->userpause = bot->pause = (uint32_t)time(NULL);
}
}
void LP_tradebot_updatestats(struct LP_tradebot *bot,struct LP_tradebot_trade *tp)
{
char *swapstr,*status; int32_t flag; cJSON *swapjson;

4
iguana/exchanges/LP_transaction.c

@ -1660,7 +1660,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u
memset(&spendtxid,0,sizeof(spendtxid));
if ( LP_spendsearch(destaddr,&spendtxid,&spendvin,symbol,utxotxid,utxovout) > 0 )
{
//printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),vout);
//char str[65]; printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),utxovout);
}
else if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 )
{
@ -1675,7 +1675,7 @@ bits256 LP_swap_spendtxid(char *symbol,char *destaddr,bits256 utxotxid,int32_t u
{
if ( (vins= jarray(&m,txobj,"vin")) != 0 )
{
//printf("vins.(%s)\n",jprint(vins,0));
//printf("vins.(%s)\n",jprint(vins,0));
if ( utxovout < m )
{
vin = jitem(vins,utxovout);

2
iguana/exchanges/auto_chipsbtc

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"BTC\",\"margin\":0.01,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"

2
iguana/exchanges/auto_chipskmd

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.01,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"

2
iguana/exchanges/install

@ -1,5 +1,5 @@
#!/bin/bash
cp 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 run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts
cp 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 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 .

Loading…
Cancel
Save