Browse Source

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

patch-3
Artem Pikulin 7 years ago
parent
commit
2eea643646
  1. 4
      crypto777/bitcoind_RPC.c
  2. 2
      iguana/dpow/dpow_rpc.c
  3. 20
      iguana/exchanges/LP_commands.c
  4. 6
      iguana/exchanges/LP_instantdex.c
  5. 37
      iguana/exchanges/LP_ordermatch.c
  6. 2
      iguana/exchanges/LP_portfolio.c
  7. 37
      iguana/exchanges/LP_prices.c
  8. 2
      iguana/exchanges/LP_remember.c
  9. 2
      iguana/exchanges/LP_signatures.c
  10. 2
      iguana/exchanges/LP_tradebots.c
  11. 29
      iguana/exchanges/LP_utxo.c
  12. 2
      iguana/exchanges/coins
  13. 3
      iguana/exchanges/dump
  14. 3
      iguana/exchanges/fomo
  15. 1
      iguana/iguana777.c

4
crypto777/bitcoind_RPC.c

@ -164,7 +164,11 @@ char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *
if ( url[0] == 0 )
strcpy(url,"http://127.0.0.1:7776");
if ( specialcase != 0 && (0) )
{
//int32_t zeroval();
printf("<<<<<<<<<<< bitcoind_RPC: userpass.(%s) url.(%s) command.(%s) params.(%s)\n",userpass,url,command,params);
//printf("die.%d\n",1/zeroval());
}
try_again:
if ( retstrp != 0 )
*retstrp = 0;

2
iguana/dpow/dpow_rpc.c

@ -1277,6 +1277,8 @@ int32_t dpow_issuer_iteration(struct dpow_info *dp,struct iguana_info *coin,int3
if ( height <= 0 )
height = 1;
*isrealtimep = 0;
if ( coin->getinfostr[0] == 0 )
strcpy(coin->getinfostr,"getinfo");
if ( (retstr= dpow_issuemethod(coin->chain->userpass,(char *)coin->getinfostr,0,port)) != 0 )
{
if ( (infoobj= cJSON_Parse(retstr)) != 0 )

20
iguana/exchanges/LP_commands.c

@ -482,18 +482,30 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}
else if ( strcmp(method,"buy") == 0 )
{
//*
int32_t fomo = 0; double vol;
if ( jobj(argjson,"fomo") != 0 )
{
fomo = 1;
price = 1.;
vol = jdouble(argjson,"fomo");
} else vol = jdouble(argjson,"relvolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),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));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"sell") == 0 )
{
//*
int32_t fomo = 0; double vol;
if ( jobj(argjson,"dump") != 0 )
{
fomo = 1;
price = 1.;
vol = jdouble(argjson,"dump");
} else vol = jdouble(argjson,"basevolume");
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),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));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
}

6
iguana/exchanges/LP_instantdex.c

@ -678,13 +678,13 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob)
struct iguana_info *bob,*alice; int32_t flag = 0; char *retstr,*swapstr; bits256 zero; cJSON *item,*reqjson,*swapjson;
item = cJSON_CreateObject();
jaddnum(item,"iambob",iambob);
jaddnum(item,"aliceid",sp->aliceid);
jadd64bits(item,"aliceid",sp->aliceid);
jaddnum(item,"requestid",sp->Q.R.requestid);
jaddnum(item,"quoteid",sp->Q.R.quoteid);
jaddstr(item,"base",sp->Q.srccoin);
jaddnum(item,"satoshis",sp->Q.satoshis);
jadd64bits(item,"satoshis",sp->Q.satoshis);
jaddstr(item,"rel",sp->Q.destcoin);
jaddnum(item,"destsatoshis",sp->Q.destsatoshis);
jadd64bits(item,"destsatoshis",sp->Q.destsatoshis);
jaddnum(item,"price",sp->Q.destsatoshis/((double)sp->Q.satoshis+1));
if ( LP_swap_finished(sp,1) == 0 )
{

37
iguana/exchanges/LP_ordermatch.c

@ -1444,9 +1444,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
return(retval);
}
char *LP_autobuy(void *ctx,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)
{
uint64_t desttxfee,txfee; 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));
basecoin = LP_coinfind(base);
relcoin = LP_coinfind(rel);
if ( gui == 0 )
@ -1483,14 +1483,6 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
jaddnum(retjson,"wait",Alice_expiration-time(NULL));
return(jprint(retjson,1));
} else LP_alicequery_clear();
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( strcmp("BTC",rel) == 0 )
maxprice *= 1.01;
else maxprice *= 1.001;
memset(pubkeys,0,sizeof(pubkeys));
LP_txfees(&txfee,&desttxfee,base,rel);
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
LP_address_utxo_reset(&num,relcoin);
if ( num <= 1 )
{
@ -1501,6 +1493,31 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
}
return(clonestr("{\"error\":\"not enough utxo, please make more deposits\"}"));
}
LP_txfees(&txfee,&desttxfee,base,rel);
if ( txfee != 0 && txfee < 10000 )
txfee = 10000;
if ( desttxfee != 0 && desttxfee < 10000 )
desttxfee = 10000;
if ( fomoflag != 0 )
{
uint64_t median,minutxo,maxutxo;
maxprice = 0.; // fomo -> price is 1. and needs to be set
LP_address_minmax(0,&median,&minutxo,&maxutxo,relcoin,relcoin->smartaddr); // limit to largest utxo
if ( maxutxo > 0 )
{
relvolume = MIN(relvolume,dstr(maxutxo) - dstr(desttxfee)*3);
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);
} else printf("no utxo available\n");
}
if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 )
return(clonestr("{\"error\":\"invalid parameter\"}"));
if ( strcmp("BTC",rel) == 0 )
maxprice *= 1.01;
else maxprice *= 1.001;
memset(pubkeys,0,sizeof(pubkeys));
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
autxo = 0;
for (i=0; i<maxiters; i++)
{

2
iguana/exchanges/LP_portfolio.c

@ -763,7 +763,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,"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 )
{
if ( (retjson2= cJSON_Parse(retstr2)) != 0 )
{

37
iguana/exchanges/LP_prices.c

@ -969,6 +969,43 @@ char *LP_orderbook(char *base,char *rel,int32_t duration)
return(jprint(retjson,1));
}
double LP_fomoprice(char *base,char *rel,double *relvolumep)
{
char *retstr; cJSON *retjson,*asks,*item; int32_t i,numasks; double maxvol=0.,relvolume,biggest,price,fomoprice = 0.;
relvolume = *relvolumep;
if ( (retstr= LP_orderbook(base,rel,0)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (asks= jarray(&numasks,retjson,"asks")) != 0 && numasks > 0 )
{
for (i=0; i<numasks; i++)
{
item = jitem(asks,i);
biggest = jdouble(item,"maxvolume");
price = jdouble(item,"price");
if ( biggest > maxvol )
{
maxvol = biggest;
fomoprice = price;
}
printf("fomoprice (%.8f) i.%d %.8f vol %.8f [max %.8f @ %.8f]\n",relvolume,i,price,biggest,maxvol,fomoprice);
}
}
free_json(retjson);
}
free(retstr);
}
if ( maxvol > 0. && fomoprice > 0. )
{
if ( maxvol < relvolume )
relvolume = maxvol * 0.98;
fomoprice /= 0.95;
} else fomoprice = 0.;
*relvolumep = relvolume;
return(fomoprice);
}
int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance)
{
double price = 0.; int64_t KMDvalue=0;

2
iguana/exchanges/LP_remember.c

@ -1772,7 +1772,7 @@ 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));
jaddnum(item,"aliceid",LP_aliceid_calc(LP_Alicequery.desttxid,LP_Alicequery.destvout,LP_Alicequery.feetxid,LP_Alicequery.feevout));
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;
return(jprint(retjson,1));

2
iguana/exchanges/LP_signatures.c

@ -440,7 +440,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
jaddstr(reqjson,"pubsecp",pubsecpstr);
if ( (kmd= LP_coinfind("KMD")) != 0 && (ap= LP_address(kmd,kmd->smartaddr)) != 0 && ap->instantdex_credits != 0 )
jaddnum(reqjson,"credits",dstr(ap->instantdex_credits));
if ( (numutxos= LP_address_minmax(&median,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
if ( (numutxos= LP_address_minmax(1,&median,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
{
//printf("send %s numutxos.%d median %.8f min %.8f max %.8f\n",base,numutxos,dstr(median),dstr(minsize),dstr(maxsize));
jaddstr(reqjson,"utxocoin",base);

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,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 )
{
if ( (retjson2= cJSON_Parse(retstr)) != 0 )
{

29
iguana/exchanges/LP_utxo.c

@ -283,9 +283,9 @@ struct LP_address *LP_address(struct iguana_info *coin,char *coinaddr)
return(ap);
}
int32_t LP_address_minmax(uint64_t *medianp,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
int32_t LP_address_minmax(int32_t iambob,uint64_t *medianp,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
{
cJSON *array,*item; bits256 txid,zero; int64_t max,max2,value,*buf; int32_t i,m=0,vout,height,n = 0;
cJSON *array,*item; bits256 txid,zero; int64_t max,max2,value; uint64_t *buf; int32_t i,m=0,vout,height,n = 0;
*minp = *maxp = *medianp = max = max2 = 0;
memset(zero.bytes,0,sizeof(zero));
if ( (array= LP_listunspent(coin->symbol,coinaddr,zero,zero)) != 0 )
@ -314,25 +314,32 @@ int32_t LP_address_minmax(uint64_t *medianp,uint64_t *minp,uint64_t *maxp,struct
if ( m > 1 )
{
revsort64s(buf,m,sizeof(*buf));
if ( max == buf[0] && max2 == buf[1] )
if ( iambob != 0 )
{
for (i=1; i<m; i++)
if ( max == buf[0] && max2 == buf[1] )
{
if ( max >= LP_DEPOSITSATOSHIS(buf[i]) )
for (i=1; i<m; i++)
{
*maxp = buf[i];
*medianp = buf[m/2];
break;
if ( max >= LP_DEPOSITSATOSHIS(buf[i]) )
{
*maxp = buf[i];
*medianp = buf[m/2];
break;
}
}
}
} else printf("sort error? max %.8f != %.8f\n",dstr(max),dstr(buf[0]));
}
else
{
*maxp = buf[0];
*medianp = buf[m/2];
printf("alice addressmin max %s %.8f %.8f %.8f num.%d\n",coin->symbol,dstr(*minp),dstr(*maxp),dstr(*medianp),m);
}
else printf("sort error? max %.8f != %.8f\n",dstr(max),dstr(buf[0]));
} else *minp = *maxp = *medianp = 0;
free(buf);
}
free_json(array);
}
//printf("addressmin max %s %.8f %.8f %.8f num.%d\n",coin->symbol,dstr(*minp),dstr(*maxp),dstr(*medianp),m);
return(m/2);
}

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

3
iguana/exchanges/dump

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"HODL\",\"dump\":40.00038}"

3
iguana/exchanges/fomo

@ -0,0 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"buy\",\"base\":\"KMD\",\"rel\":\"HODL\",\"fomo\":40.00038}"

1
iguana/iguana777.c

@ -48,6 +48,7 @@ struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson,int32_
{
myinfo->allcoins_being_added = 1;
coin = mycalloc('C',1,sizeof(*coin));
strcpy(coin->getinfostr,"getinfo");
coin->blockspacesize = IGUANA_MAXPACKETSIZE + 8192;
coin->blockspace = calloc(1,coin->blockspacesize);
if ( virtcoin != 0 || ((privatechain= jstr(argjson,"geckochain")) != 0 && privatechain[0] != 0) )

Loading…
Cancel
Save