Browse Source

Merge pull request #260 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
5aa44aa57b
  1. 6
      .gitignore
  2. 6
      basilisk/basilisk_tradebot.c
  3. 4
      basilisk/tradebots_liquidity.c
  4. 8
      iguana/dPoW.h
  5. 6
      iguana/dpow/dpow_network.c
  6. 5
      iguana/dpow/dpow_rpc.c
  7. 8
      iguana/iguana_notary.c
  8. 2
      iguana/iguana_payments.c
  9. 49
      iguana/kmd_lookup.h

6
.gitignore

@ -141,3 +141,9 @@ iguana/confs/c6faccf6b625bbb826f47b77c3274e985db7b0a47d435f32bea2f7f3724cdd17.ol
iguana/marketmaker
iguana/secp256k1.o-501dfbfe
iguana/confs/cc577d22ca76351d495f147b470103392b5f2ab0948e45608623a7d9728e2c6f
iguana/confs/cc577d22ca76351d495f147b470103392b5f2ab0948e45608623a7d9728e2c6f.old
iguana/DB/DEX.log

6
basilisk/basilisk_tradebot.c

@ -330,9 +330,9 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
aveprice = refprice;
if ( fabs(aveprice) < SMALLVAL )
return(0);
printf("avebid %f bidvol %f, aveask %f askvol %f\n",retvals[0],retvals[1],retvals[2],retvals[3]);
//retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol;
destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount;
printf("aveprice %f dest %.8f avebid %f bidvol %f, aveask %f askvol %f\n",aveprice,dstr(destamount),retvals[0],retvals[1],retvals[2],retvals[3]);
if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
@ -343,8 +343,8 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
free(retstr);
}
// BTC balance 0.00500000 destamount 0.00041951 aveprice 0.00421619 minamount 0.00020000
printf("%s balance %.8f destamount %.8f aveprice %.8f minamount %.8f\n",list[0].dest,dstr(balance),dstr(destamount),aveprice,dstr(minamount));
if ( balance > destamount && (int64_t)destamount > 0 && destamount >= maxamount && destamount >= minamount )
printf("%s balance %.8f destamount %.8f aveprice %.8f maxamount %.8f minamount %.8f\n",list[0].dest,dstr(balance),dstr(destamount),aveprice,dstr(maxamount),dstr(minamount));
if ( balance > destamount && (int64_t)destamount > 0 && destamount >= minamount ) // max?
{
metric = 1.;
*issueR = list[0];

4
basilisk/tradebots_liquidity.c

@ -1010,7 +1010,7 @@ double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,
dir = 1;
else if ( strcmp(rel,refli.base) == 0 && strcmp(base,refli.rel) == 0 )
dir = -1;
else dir = 0;
else continue;
if ( exchange[0] != 0 && refli.exchange[0] != 0 && strcmp(exchange,refli.exchange) != 0 )
{
printf("continue %s %s/%s [%d] dir.%d vs %s %s/%s\n",exchange,base,rel,i,dir,refli.exchange,refli.base,refli.rel);
@ -1164,7 +1164,7 @@ void tradebots_processprices(struct supernet_info *myinfo,struct exchange_info *
//printf("reject %s %s/%s\n",exchange,base,rel);
return;
}
//printf("%s %s/%s bids.%d asks.%d\n",exchange->name,base,rel,numbids,numasks);
printf("%s %s/%s bids.%d asks.%d\n",exchange->name,base,rel,numbids,numasks);
if ( numbids > 0 && (volume= bidasks[0].volume) > 0. && (profitmargin=
tradebot_liquidity_active(myinfo,&price,exchange->name,base,rel,volume)) > 0. )
{

8
iguana/dPoW.h

@ -195,11 +195,11 @@ cJSON *dpow_checkaddress(struct supernet_info *myinfo,struct iguana_info *coin,c
void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen);
void kmd_bitcoinscan();
cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr);
cJSON *kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
struct iguana_info *iguana_coinfind(char *symbol);
cJSON *kmd_listtransactions(struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip);
cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr);
cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr);
cJSON *kmd_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip);
cJSON *kmd_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *kmd_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout);
cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);

6
iguana/dpow/dpow_network.c

@ -408,12 +408,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str);
}
}
#ifndef __APPLE__
if ( (rand() % 100) < 40 )
{
nanomsg_tcpname(0,str,ipaddr,REP_SOCK);
nn_connect(myinfo->reqsock,str);
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str);
}
#endif
}
}
if ( freeptr != 0 )
@ -550,7 +552,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
}
else if ( dexreq.func == 'u' )
{
if ( (retjson= kmd_listunspent(coin,(char *)&dexp->packet[datalen])) != 0 )
if ( (retjson= kmd_listunspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
@ -590,7 +592,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
else if ( dexreq.func == '2' )
{
//printf("call list.(%s %d %d)\n",(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg);
if ( (retjson= kmd_listtransactions(coin,(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg)) != 0 )
if ( (retjson= kmd_listtransactions(myinfo,coin,(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg)) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);

5
iguana/dpow/dpow_rpc.c

@ -324,6 +324,7 @@ cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits2
json = cJSON_Parse(retstr);
free(retstr);
}
//printf("dpow_gettxout.(%s)\n",retstr);
return(json);
}
@ -408,7 +409,7 @@ cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,ch
cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
if ( myinfo->DEXEXPLORER != 0 )
return(kmd_listspent(coin,coinaddr));
return(kmd_listspent(myinfo,coin,coinaddr));
else
{
return(0);
@ -418,7 +419,7 @@ cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char
cJSON *dpow_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
if ( myinfo->DEXEXPLORER != 0 )
return(kmd_getbalance(coin,coinaddr));
return(kmd_getbalance(myinfo,coin,coinaddr));
else
{
return(0);

8
iguana/iguana_notary.c

@ -791,7 +791,7 @@ TWO_STRINGS(dex,listunspent2,symbol,address)
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
if ( strcmp(coin->symbol,"BTC") == 0 || coin->DEXEXPLORER == 0 )
return(clonestr("[]"));
if ( (retjson= kmd_listunspent(coin,address)) != 0 )
if ( (retjson= kmd_listunspent(myinfo,coin,address)) != 0 )
return(jprint(retjson,1));
}
}
@ -811,7 +811,7 @@ TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip)
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
if ( strcmp(coin->symbol,"BTC") == 0 || coin->DEXEXPLORER == 0 )
return(clonestr("[]"));
if ( (retjson= kmd_listtransactions(coin,address,count,skip)) != 0 )
if ( (retjson= kmd_listtransactions(myinfo,coin,address,count,skip)) != 0 )
return(jprint(retjson,1));
}
}
@ -839,7 +839,7 @@ TWO_STRINGS(dex,listspent,symbol,address)
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 && coin->DEXEXPLORER != 0 )
return(jprint(kmd_listspent(coin,address),1));
return(jprint(kmd_listspent(myinfo,coin,address),1));
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
}
@ -854,7 +854,7 @@ TWO_STRINGS(dex,getbalance,symbol,address)
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 && coin->DEXEXPLORER != 0 )
return(jprint(kmd_getbalance(coin,address),1));
return(jprint(kmd_getbalance(myinfo,coin,address),1));
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
}

2
iguana/iguana_payments.c

@ -359,7 +359,7 @@ uint64_t _iguana_interest(uint32_t now,int32_t chainheight,uint32_t txlocktime,u
numerator = (value * KOMODO_INTEREST);
interest = (numerator / denominator) / SATOSHIDEN;
}
fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",chainheight,(long long)value,(double)value/SATOSHIDEN,txlocktime,now,minutes,(long long)interest,(double)interest/SATOSHIDEN,(long long)numerator,(long long)denominator);
//fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",chainheight,(long long)value,(double)value/SATOSHIDEN,txlocktime,now,minutes,(long long)interest,(double)interest/SATOSHIDEN,(long long)numerator,(long long)denominator);
}
return(interest);
}

49
iguana/kmd_lookup.h

@ -124,6 +124,7 @@ int32_t kmd_transactionvin(struct iguana_info *coin,bits256 spendtxid,int32_t vi
void kmd_transactionvout(struct iguana_info *coin,struct kmd_transactionhh *ptr,int32_t vout,uint64_t amount,uint8_t type_rmd160[21],bits256 spendtxid,int32_t spendvini)
{
struct kmd_addresshh *addr; struct kmd_transaction *tx = 0;
if ( 0 )
{
char coinaddr[64],str[65];
bitcoin_address(coinaddr,type_rmd160[0],&type_rmd160[1],20);
@ -304,9 +305,9 @@ cJSON *kmd_transactionjson(int32_t height,struct kmd_transactionhh *ptr,char *ty
return(obj);
}
cJSON *kmd_unspentjson(struct iguana_info *coin,int32_t height,struct kmd_transaction *tx,int32_t vout)
cJSON *kmd_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct kmd_transaction *tx,int32_t vout,int32_t is_listunspent)
{
cJSON *item = cJSON_CreateObject();
char *script; cJSON *sobj,*txout,*item = cJSON_CreateObject();
jaddstr(item,"type","received");
jaddnum(item,"height",tx->height);
jaddnum(item,"timestamp",tx->timestamp);
@ -315,6 +316,17 @@ cJSON *kmd_unspentjson(struct iguana_info *coin,int32_t height,struct kmd_transa
jaddnum(item,"amount",dstr(tx->vouts[vout].amount));
if ( strcmp(coin->symbol,"KMD") == 0 )
jaddnum(item,"interest",dstr(_iguana_interest((uint32_t)time(NULL),coin->longestchain,tx->timestamp,tx->vouts[vout].amount)));
if ( is_listunspent != 0 )
{
//char str[65]; printf("get spendscriptstr for %s/v%d\n",bits256_str(str,tx->txid),vout);
if ( (txout= dpow_gettxout(myinfo,coin,tx->txid,vout)) != 0 )
{
//printf("got.(%s)\n",jprint(txout,0));
if ( (sobj= jobj(txout,"scriptPubKey")) != 0 && (script= jstr(sobj,"hex")) != 0 )
jaddstr(item,"scriptPubKey",script);
free_json(txout);
}
}
return(item);
}
@ -378,7 +390,7 @@ cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout)
return(cJSON_Parse("{\"error\":\"txid not found\"}"));
}
cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode,cJSON *array)
cJSON *kmd_listaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t mode,cJSON *array)
{
struct kmd_addresshh *addr; struct kmd_transactionhh *ptr=0,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i;
if ( array == 0 )
@ -412,14 +424,14 @@ cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode,cJSO
//if ( fulltx == 0 )
{
if ( mode == 0 )
jaddi(array,kmd_unspentjson(coin,coin->kmd_height,ptr->tx,i));
jaddi(array,kmd_unspentjson(myinfo,coin,coin->kmd_height,ptr->tx,i,1));
else if ( mode == 1 )
jaddi(array,kmd_spentjson(coin->kmd_height,ptr->tx,i,spent));
else if ( mode == 2 )
{
if ( spent != 0 )
jaddi(array,kmd_spentjson(coin->kmd_height,ptr->tx,i,spent));
else jaddi(array,kmd_unspentjson(coin,coin->kmd_height,ptr->tx,i));
else jaddi(array,kmd_unspentjson(myinfo,coin,coin->kmd_height,ptr->tx,i,0));
}
}
/*else if ( flag == 0 )
@ -455,34 +467,37 @@ cJSON *kmd_listaddress(struct iguana_info *coin,char *coinaddr,int32_t mode,cJSO
return(array);
}
cJSON *kmd_listunspent(struct iguana_info *coin,char *coinaddr)
cJSON *kmd_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
return(kmd_listaddress(coin,coinaddr,0,0));
cJSON *retjson;
retjson = kmd_listaddress(myinfo,coin,coinaddr,0,0);
//printf("KMD utxos.(%s)\n",jprint(retjson,0));
return(retjson);
}
cJSON *kmd_listspent(struct iguana_info *coin,char *coinaddr)
cJSON *kmd_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
return(kmd_listaddress(coin,coinaddr,1,0));
return(kmd_listaddress(myinfo,coin,coinaddr,1,0));
}
cJSON *kmd_listtransactions(struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip)
cJSON *kmd_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip)
{
cJSON *array = cJSON_CreateArray();
//if ( (height= kmd_height(coin)) > coin->kmd_height+KMD_EXPLORER_LAG )
// return(cJSON_Parse("[]"));
if ( count == 0 )
count = 100;
array = kmd_listaddress(coin,coinaddr,0,0);
array = kmd_listaddress(coin,coinaddr,1,array);
array = kmd_listaddress(myinfo,coin,coinaddr,0,0);
array = kmd_listaddress(myinfo,coin,coinaddr,1,array);
return(array);
}
int64_t _kmd_getbalance(struct iguana_info *coin,char *coinaddr,uint64_t *receivedp,uint64_t *sentp,uint64_t *interestp)
int64_t _kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint64_t *receivedp,uint64_t *sentp,uint64_t *interestp)
{
int32_t iter,i,n; cJSON *array,*item; uint64_t value;
for (iter=1; iter<=2; iter++)
{
if ( (array= kmd_listaddress(coin,coinaddr,iter,0)) != 0 )
if ( (array= kmd_listaddress(myinfo,coin,coinaddr,iter,0)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
@ -505,7 +520,7 @@ int64_t _kmd_getbalance(struct iguana_info *coin,char *coinaddr,uint64_t *receiv
return(*receivedp - *sentp);
}
cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr)
cJSON *kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
cJSON *retjson; double netbalance=0.,fbalance; uint64_t interest,i,s,r,sent=0,received=0; int64_t balance=0; struct kmd_addresshh *addr,*tmp; char address[64]; int32_t height = coin->kmd_height+1;
retjson = cJSON_CreateObject();
@ -517,7 +532,7 @@ cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr)
{
bitcoin_address(address,addr->type_rmd160[0],&addr->type_rmd160[1],20);
s = r = i = 0;
balance += _kmd_getbalance(coin,address,&r,&s,&i);
balance += _kmd_getbalance(myinfo,coin,address,&r,&s,&i);
netbalance += dstr(r);
netbalance -= dstr(s);
if ( (r - s) > 100000*SATOSHIDEN )
@ -531,7 +546,7 @@ cJSON *kmd_getbalance(struct iguana_info *coin,char *coinaddr)
}
else
{
balance = _kmd_getbalance(coin,coinaddr,&received,&sent,&interest);
balance = _kmd_getbalance(myinfo,coin,coinaddr,&received,&sent,&interest);
netbalance = dstr(balance);
}
jaddstr(retjson,"result","success");

Loading…
Cancel
Save