Browse Source

Merge pull request #159 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
af4249aabe
  1. 6
      basilisk/basilisk.c
  2. 6
      basilisk/basilisk_MSG.c
  3. 39
      basilisk/basilisk_bitcoin.c
  4. 5
      basilisk/basilisk_swap.c
  5. 5
      iguana/dPoW.h
  6. 37
      iguana/dpow/dpow_network.c
  7. 2
      iguana/dpow/dpow_rpc.c
  8. 50
      iguana/iguana_exchanges.c
  9. 20
      iguana/iguana_payments.c
  10. 2
      iguana/main.c

6
basilisk/basilisk.c

@ -213,6 +213,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
return(-1);
}
//portable_mutex_lock(&myinfo->allcoins_mutex);
//dex_reqsend(myinfo,&data[-(int32_t)sizeof(struct iguana_msghdr)],datalen);
alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent));
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
@ -876,7 +877,7 @@ void basilisks_loop(void *arg)
startmilli = OS_milliseconds();
basilisk_issued_purge(myinfo,600000);
basilisk_p2pQ_process(myinfo,777);
if ( myinfo->NOTARY.RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 )
{
if ( relay != 0 )
basilisk_ping_send(myinfo,relay);
@ -894,8 +895,7 @@ void basilisks_loop(void *arg)
}
else
{
if ( myinfo->IAMNOTARY == 0 )
dex_updateclient(myinfo);
dex_updateclient(myinfo);
if ( myinfo->IAMLP != 0 )
endmilli = startmilli + 1000;
else endmilli = startmilli + 2000;

6
basilisk/basilisk_MSG.c

@ -291,10 +291,12 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
{
int32_t keylen,datalen; uint8_t key[BASILISK_KEYSIZE],space[16384],*data,*ptr = 0; char *retstr=0;
data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,&space[BASILISK_KEYSIZE],sizeof(space)-BASILISK_KEYSIZE,hexstr);
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 )
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash"));
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 )
memcpy(space,key,BASILISK_KEYSIZE);
if ( data != 0 )
{
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"));
} else printf("no get_dataptr\n");
@ -305,6 +307,8 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
} else printf("not notary.%d relayid.%d\n",myinfo->IAMNOTARY,myinfo->NOTARY.RELAYID);
if ( vals != 0 && juint(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
if ( 0 && data != 0 && datalen != 0 )
dex_reqsend(myinfo,space,datalen+BASILISK_KEYSIZE);
return(basilisk_standardservice("OUT",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,0));
}
#include "../includes/iguana_apiundefs.h"

39
basilisk/basilisk_bitcoin.c

@ -584,8 +584,8 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
if ( valsobj == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
vins = 0;
changeaddr = jstr(valsobj,"changeaddr");
if ( (amount= j64bits(valsobj,"satoshis")) == 0 )
@ -882,11 +882,11 @@ cJSON *BTC_makeclaimfunc(struct supernet_info *myinfo,struct exchange_info *exch
HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis;
char *retstr=0,*symbol,*coinaddr; cJSON *retjson,*txoutjson; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height;
if ( vals == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
@ -896,6 +896,35 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( coin != 0 )
{
if ( coin->FULLNODE < 0 )
{
txid = jbits256(vals,"txid");
vout = jint(vals,"vout");
if ( (txoutjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 )
{
if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= SATOSHIDEN*jdouble(txoutjson,"value")) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"address",coinaddr);
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin);
jaddnum(retjson,"height",height);
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",coin->symbol);
}
else
{
free_json(txoutjson);
return(clonestr("{\"error\":\"return from gettxout missing fields\"}"));
}
free_json(txoutjson);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"null return from gettxout\"}"));
}
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )

5
basilisk/basilisk_swap.c

@ -17,6 +17,11 @@
// mode to autocreate required outputs
// more better LP commands
// depends on just three external functions:
// - iguana_sendrawtransaction(myinfo,coin,signedtx);
// - basilisk_value(myinfo,rawtx->coin,0,0,myinfo->myaddr.persistent,argjson,0)
// basilisk_bitcoinrawtx(myinfo,rawtx->coin,"",basilisktag,jint(valsobj,"timeout"),valsobj,V)
// included from basilisk.c
/* https://bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271

5
iguana/dPoW.h

@ -141,5 +141,10 @@ struct dpow_info
uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp);
int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp);
void dex_updateclient(struct supernet_info *myinfo);
int32_t dex_reqsend(struct supernet_info *myinfo,uint8_t *data,int32_t datalen);
char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration);
char *dpow_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx);
cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout);
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin);
#endif

37
iguana/dpow/dpow_network.c

@ -56,7 +56,10 @@ static int _increasing_ipbits(const void *a,const void *b)
void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size)
{
printf("DEX_PACKET.[%d] crc.%x lag.%d\n",size,calc_crc32(0,(void *)((long)dexp+sizeof(dexp->crc32)),(int32_t)(size-sizeof(dexp->crc32))),(int32_t)(time(NULL)-dexp->timestamp));
char *retstr;
printf("uniq DEX_PACKET.[%d] crc.%x lag.%d\n",size,calc_crc32(0,(void *)((long)dexp+sizeof(dexp->crc32)),(int32_t)(size-sizeof(dexp->crc32))),(int32_t)(time(NULL)-dexp->timestamp));
if ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 )
free(retstr);
}
int32_t dex_reqsend(struct supernet_info *myinfo,uint8_t *data,int32_t datalen)
@ -442,7 +445,7 @@ void dpow_bestconsensus(struct dpow_block *bp)
bp->notaries[bp->myind].bestk = bp->bestk = bestks[besti];
//printf("set best.%d to (%d %llx) recv.%llx\n",best,bp->bestk,(long long)bp->bestmask,(long long)recvmask);
}
bp->recvmask = recvmask;
bp->recvmask |= recvmask;
if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch )
{
bp->bestmask = dpow_notarybestk(bp->recvmask,bp,&bp->bestk);
@ -480,7 +483,7 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr
}
else
{
//dpow_bestconsensus(bp);
dpow_bestconsensus(bp);
np->srcutxo = bp->notaries[bp->myind].src.prev_hash;
np->srcvout = bp->notaries[bp->myind].src.prev_vout;
np->destutxo = bp->notaries[bp->myind].dest.prev_hash;
@ -688,10 +691,16 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
return;
if ( bp->isratify == 0 && bp->state != 0xffffffff && senderind >= 0 && senderind < bp->numnotaries && bits256_nonz(srcutxo) != 0 && bits256_nonz(destutxo) != 0 )
{
bp->notaries[senderind].src.prev_hash = srcutxo;
bp->notaries[senderind].src.prev_vout = srcvout;
bp->notaries[senderind].dest.prev_hash = destutxo;
bp->notaries[senderind].dest.prev_vout = destvout;
if ( bits256_nonz(srcutxo) != 0 )
{
bp->notaries[senderind].src.prev_hash = srcutxo;
bp->notaries[senderind].src.prev_vout = srcvout;
}
if ( bits256_nonz(destutxo) != 0 )
{
bp->notaries[senderind].dest.prev_hash = destutxo;
bp->notaries[senderind].dest.prev_vout = destvout;
}
if ( bestmask != 0 )
bp->notaries[senderind].bestmask = bestmask;
if ( recvmask != 0 )
@ -700,7 +709,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
{
//fprintf(stderr,"{%d %x} ",senderind,paxwdcrc);
}
if ( bestk >= 0 && (bp->notaries[senderind].bestk= bestk) >= 0 )
if ( (bp->notaries[senderind].bestk= bestk) >= 0 )
{
if ( (bp->notaries[senderind].src.siglens[bestk]= siglens[0]) != 0 )
{
@ -717,11 +726,13 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
else bp->destsigsmasks[bestk] &= ~(1LL << senderind);
}
}
dpow_bestconsensus(bp);
//bp->recvmask |= (1LL << senderind) | (1LL << bp->myind);
//bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
//if ( bp->paxwdcrc != 0 )
bp->notaries[bp->myind].paxwdcrc = bp->paxwdcrc;
bp->notaries[bp->myind].paxwdcrc = bp->paxwdcrc;
if ( bp->bestmask == 0 )
{
bp->recvmask |= (1LL << senderind) | (1LL << bp->myind);
bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk);
//dpow_bestconsensus(bp);
}
if ( bp->bestk >= 0 )
bp->notaries[bp->myind].bestk = bp->bestk;
if ( bp->bestmask != 0 )

2
iguana/dpow/dpow_rpc.c

@ -405,7 +405,7 @@ int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32
coin->lastbestheight = height;
if ( height > coin->longestchain )
coin->longestchain = height;
if ( (array= jarray(&n,json,"tx")) != 0 )
if ( txs != 0 && numtxp != 0 && (array= jarray(&n,json,"tx")) != 0 )
{
for (i=0; i<n&&i<maxtx; i++)
txs[i] = jbits256i(array,i);

50
iguana/iguana_exchanges.c

@ -22,16 +22,18 @@
//char *Exchange_names[] = { "poloniex", "bittrex", "btc38", "huobi", "bitstamp", "bitfinex", "btce", "coinbase", "okcoin", "lakebtc", "quadriga", "truefx", "ecb", "instaforex", "fxcm", "yahoo" };
int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_quote *sortbuf,int32_t n,int32_t max,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes)
int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_quote *sortbuf,int32_t n,int32_t max,int32_t ind,int32_t dir,struct exchange_quote *quotes,int32_t numquotes,double offset)
{
int32_t i; struct exchange_quote *quote;
printf("instantdex_updatesources.%s update dir.%d numquotes.%d\n",exchange->name,dir,numquotes);
//printf("instantdex_updatesources.%s update dir.%d numquotes.%d offset %.6f\n",exchange->name,dir,numquotes,offset);
for (i=0; i<numquotes; i++)
{
quote = &quotes[i << 1];
//printf("n.%d ind.%d i.%d dir.%d price %.8f vol %.8f\n",n,ind,i,dir,quote->price,quote->volume);
if ( quote->price > SMALLVAL )
{
//printf("%s n.%d ind.%d i.%d dir.%d price %.8f vol %.8f offset %.6f\n",exchange->name,n,ind,i,dir,quote->price+offset,quote->volume,offset);
quote->price += offset;
quote->satoshis = quote->price * SATOSHIDEN;
sortbuf[n] = *quote;
sortbuf[n].val = ind;
sortbuf[n].exchangebits = exchange->exchangebits;
@ -45,7 +47,7 @@ int32_t instantdex_updatesources(struct exchange_info *exchange,struct exchange_
double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *sortbuf,int32_t max,double *totalvolp,char *base,char *rel,double basevolume,cJSON *argjson)
{
char *str; double totalvol,pricesum; uint32_t timestamp;
char *str; double totalvol,pricesum,hblas[64][2],refbid,refask; uint32_t timestamp;
struct exchange_quote quote; int32_t i,n,dir,num,depth = 100;
struct exchange_info *exchange; struct exchange_request *req,*active[64];
if ( myinfo == 0 )
@ -86,33 +88,55 @@ double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *s
}
}
}
for (i=0; i<num; i++)
memset(hblas,0,sizeof(hblas));
refbid = refask = 0.;
if ( strcmp(rel,"USD") == 0 )
{
if ( active[i]->numbids > 0 && active[i]->numasks > 0 )
for (i=0; i<num; i++)
{
if ( active[i]->numbids > 0 && active[i]->numasks > 0 )
{
hblas[i][0] = active[i]->bidasks[0].price;
hblas[i][1] = active[i]->bidasks[1].price;
if ( active[i]->exchange != 0 && strcmp("poloniex",active[i]->exchange->name) == 0 )
refbid = active[i]->bidasks[0].price, refask = active[i]->bidasks[1].price;
//printf("(%6f %.6f) ",hblas[i][0],hblas[i][1]);
}
}
//printf(" refbid %.6f refask %.7f\n",refbid,refask);
if ( refbid != 0. && refask != 0. )
{
for (i=0; i<num; i++)
{
if ( hblas[i][0] != 0. && hblas[i][1] != 0. )
hblas[i][0] = (refbid - hblas[i][0]), hblas[i][1] = (refask - hblas[i][1]);
else memset(hblas[i],0,sizeof(hblas[i]));
}
} else memset(hblas,0,sizeof(hblas));
}
for (i=n=0; i<num; i++)
{
if ( dir < 0 && active[i]->numbids > 0 )
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,1,active[i]->bidasks,active[i]->numbids);
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,1,active[i]->bidasks,active[i]->numbids,hblas[i][0]);
else if ( dir > 0 && active[i]->numasks > 0 )
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks);
n = instantdex_updatesources(active[i]->exchange,sortbuf,n,max,i,-1,&active[i]->bidasks[1],active[i]->numasks,hblas[i][1]);
}
printf("numexchanges.%d dir.%d %s/%s numX.%d n.%d\n",myinfo->numexchanges,dir,base,rel,num,n);
//printf("numexchanges.%d dir.%d %s/%s numX.%d n.%d\n",myinfo->numexchanges,dir,base,rel,num,n);
if ( dir < 0 )
revsort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
else sort64s(&sortbuf[0].satoshis,n,sizeof(*sortbuf));
for (totalvol=pricesum=i=0; i<n; i++)// && totalvol < basevolume; i++)
//for (i=0; i<n; i++)
// printf("%.6f ",sortbuf[i].price);
//printf("%d prices\n",n);
for (totalvol=pricesum=i=0; i<n && totalvol < basevolume; i++)
{
quote = sortbuf[i];
printf("dir.%d n.%d i.%d price %.8f %.8f %.8f\n",dir,n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume);
//printf("dir.%d n.%d i.%d price %.8f %.8f %.8f\n",dir,n,i,dstr(sortbuf[i].satoshis),sortbuf[i].price,quote.volume);
if ( quote.satoshis != 0 )
{
pricesum += (quote.price * quote.volume);
totalvol += quote.volume;
printf("dir.%d i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",dir,i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol);
//printf("dir.%d i.%d of %d %12.8f vol %.8f %s | aveprice %.8f total vol %.8f\n",dir,i,n,sortbuf[i].price,quote.volume,active[quote.val]->exchange->name,pricesum/totalvol,totalvol);
}
}
if ( totalvol > 0. )

20
iguana/iguana_payments.c

@ -288,11 +288,29 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx)
{
bits256 txid; uint8_t *serialized; int32_t i,len,n; struct iguana_peer *addr; cJSON *vals; char *str;
bits256 txid,checktxid; uint8_t *serialized; int32_t i,len,n; struct iguana_peer *addr; cJSON *vals; char *str;
len = (int32_t)strlen(signedtx) >> 1;
serialized = calloc(1,sizeof(struct iguana_msghdr) + len);
decode_hex(&serialized[sizeof(struct iguana_msghdr)],len,signedtx);
txid = bits256_doublesha256(0,&serialized[sizeof(struct iguana_msghdr)],len);
if ( coin->FULLNODE < 0 )
{
if ( (str= dpow_sendrawtransaction(myinfo,coin,signedtx)) != 0 )
{
if ( is_hexstr(str,0) == sizeof(checktxid)*2 )
{
decode_hex(checktxid.bytes,sizeof(checktxid),str);
if ( bits256_cmp(txid,checktxid) == 0 )
{
free(str);
return(txid);
}
}
free(str);
memset(txid.bytes,0,sizeof(txid));
return(txid);
}
}
if ( coin->peers != 0 && (n= coin->peers->numranked) > 0 )
{
for (i=0; i<8 && i<n; i++)

2
iguana/main.c

@ -1627,7 +1627,7 @@ void iguana_main(void *arg)
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("coinbase"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("lakebtc"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("quadriga"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("okcoin"),0);
// prices reversed? myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("okcoin"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("btce"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitstamp"),0);
#endif

Loading…
Cancel
Save