From d2182b54eebf9ea3457aadc07a45837e0609fce8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Sep 2016 12:43:38 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 74 ++++++++++++++++++++++++++++++++++++ basilisk/basilisk_DEX.c | 7 +++- basilisk/basilisk_tradebot.c | 74 ------------------------------------ crypto777/OS_portable.h | 3 ++ crypto777/bitcoind_RPC.c | 4 -- iguana/iguana_wallet.c | 1 + includes/iguana_funcs.h | 1 + 7 files changed, 84 insertions(+), 80 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index dba265ba6..1013a53c4 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -800,6 +800,80 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t free(ptr); } +double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n) +{ + int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; uint64_t destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.; + memset(issueR,0,sizeof(*issueR)); + minamount = list[0].minamount; + //printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid); + if ( (active= basilisk_request_started(myinfo,list[0].requestid)) != 0 ) + pendingid = active->req.quoteid; + if ( bits256_cmp(myinfo->myaddr.persistent,list[0].srchash) == 0 ) // my request + myrequest = 1; + for (i=0; imyaddr.persistent,list[i].desthash) == 0 ) // my quoteid + myrequest |= 2; + havequoteflag++; + if ( pendingid == 0 ) + { + if ( list[i].destamount > maxamount ) + { + maxamount = list[i].destamount; + maxi = i; + } + } + else if ( active != 0 && pendingid == list[i].quoteid ) + { + } + } else noquoteflag++; + } + printf("myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount)); + double retvals[4],refprice,profitmargin,aveprice,balance=0.; cJSON *retjson; char *retstr; + if ( myinfo->IAMLP != 0 && myrequest == 0 && pendingid == 0 && noquoteflag != 0 && (profitmargin= tradebot_liquidity_active(myinfo,&refprice,list[0].src,list[0].dest)) > 0. ) + { + if ( (aveprice= instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount))) == 0. || refprice > aveprice ) + aveprice = refprice; + if ( fabs(aveprice) < SMALLVAL ) + return(0); + destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount; + if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + balance = jdouble(retjson,"result"); + free_json(retjson); + } + free(retstr); + } + printf("balance %.8f destamount %.8f aveprice %.8f minamount %.8f\n",balance,dstr(destamount),aveprice,dstr(minamount)); + if ( balance > destamount && destamount > 0 && destamount >= maxamount && destamount >= minamount ) + { + metric = 1.; + *issueR = list[0]; + issueR->desthash = myinfo->myaddr.persistent; + issueR->destamount = destamount; + issueR->quotetime = (uint32_t)time(NULL); + } + } + else if ( myrequest != 0 && pendingid == 0 && maxi >= 0 ) // automatch best quote + { + if ( minamount != 0 && maxamount > minamount && time(NULL) > BASILISK_DEXDURATION/2 ) + { + printf("automatch quoteid.%u triggered %.8f > %.8f\n",list[maxi].quoteid,dstr(maxamount),dstr(minamount)); + *issueR = list[maxi]; + if ( minamount > 0 ) + metric = (dstr(maxamount) / dstr(minamount)) - 1.; + else metric = 1.; + } + } + return(metric); +} + void basilisk_requests_poll(struct supernet_info *myinfo) { char *retstr; cJSON *outerarray,*retjson; int32_t i,n; struct basilisk_request issueR; double hwm = 0.; diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 1e0e546af..657f6baa4 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -417,8 +417,11 @@ STRING_ARG(InstantDEX,available,source) { if ( myinfo->expiration != 0 ) return(bitcoinrpc_getbalance(myinfo,coin,json,remoteaddr,"*",coin->chain->minconfirms,1,1<<30)); - else return(clonestr("{\"error\":\"need to unlock wallet\"}")); - } else return(clonestr("{\"error\":\"specified coin is not active\"}")); + printf("InstantDEX_available: need to unlock wallet\n"); + return(clonestr("{\"error\":\"need to unlock wallet\"}")); + } + printf("InstantDEX_available: %s is not active\n",source!=0?source:""); + return(clonestr("{\"error\":\"specified coin is not active\"}")); } HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index e60696db8..ee975cb6e 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -158,80 +158,6 @@ double tradebot_liquidity_active(struct supernet_info *myinfo,double *refpricep, return(0.); } -double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n) -{ - int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; uint64_t destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.; - memset(issueR,0,sizeof(*issueR)); - minamount = list[0].minamount; - //printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid); - if ( (active= basilisk_request_started(myinfo,list[0].requestid)) != 0 ) - pendingid = active->req.quoteid; - if ( bits256_cmp(myinfo->myaddr.persistent,list[0].srchash) == 0 ) // my request - myrequest = 1; - for (i=0; imyaddr.persistent,list[i].desthash) == 0 ) // my quoteid - myrequest |= 2; - havequoteflag++; - if ( pendingid == 0 ) - { - if ( list[i].destamount > maxamount ) - { - maxamount = list[i].destamount; - maxi = i; - } - } - else if ( active != 0 && pendingid == list[i].quoteid ) - { - } - } else noquoteflag++; - } - printf("myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount)); - double retvals[4],refprice,profitmargin,aveprice,balance=0.; cJSON *retjson; char *retstr; - if ( myinfo->IAMLP != 0 && myrequest == 0 && pendingid == 0 && noquoteflag != 0 && (profitmargin= tradebot_liquidity_active(myinfo,&refprice,list[0].src,list[0].dest)) > 0. ) - { - if ( (aveprice= instantdex_avehbla(myinfo,retvals,list[0].src,list[0].dest,1.3 * dstr(list[0].srcamount))) == 0. || refprice > aveprice ) - aveprice = refprice; - if ( fabs(aveprice) < SMALLVAL ) - return(0); - destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount; - if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - balance = jdouble(retjson,"result"); - free_json(retjson); - } - free(retstr); - } - printf("balance %.8f destamount %.8f aveprice %.8f minamount %.8f\n",balance,dstr(destamount),aveprice,dstr(minamount)); - if ( balance > destamount && destamount > 0 && destamount >= maxamount && destamount >= minamount ) - { - metric = 1.; - *issueR = list[0]; - issueR->desthash = myinfo->myaddr.persistent; - issueR->destamount = destamount; - issueR->quotetime = (uint32_t)time(NULL); - } - } - else if ( myrequest != 0 && pendingid == 0 && maxi >= 0 ) // automatch best quote - { - if ( minamount != 0 && maxamount > minamount && time(NULL) > BASILISK_DEXDURATION/2 ) - { - printf("automatch quoteid.%u triggered %.8f > %.8f\n",list[maxi].quoteid,dstr(maxamount),dstr(minamount)); - *issueR = list[maxi]; - if ( minamount > 0 ) - metric = (dstr(maxamount) / dstr(minamount)) - 1.; - else metric = 1.; - } - } - return(metric); -} - double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_request *issueR,cJSON *retjson,double hwm) { cJSON *array,*item; uint8_t *hexdata,*allocptr,hexspace[8192]; char *hexstr; int32_t i,hexlen,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.; diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 9d4423615..eb5237c0f 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -17,6 +17,9 @@ // iguana_OS has functions that invoke system calls. Whenever possible stdio and similar functions are use and most functions are fully portable and in this file. For things that require OS specific, the call is routed to iguana_OS_portable_* Usually, all but one OS can be handled with the same code, so iguana_OS_portable.c has most of this shared logic and an #ifdef iguana_OS_nonportable.c +#ifdef __APPLE__ +#define LIQUIDITY_PROVIDER 1 +#endif #ifdef NATIVE_WINDOWS //#define uint64_t unsigned __int64 diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index f292f68db..5154c8c98 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -15,10 +15,6 @@ #include "OS_portable.h" -#ifdef __APPLE__ -#define LIQUIDITY_PROVIDER 1 -#endif - #if LIQUIDITY_PROVIDER #ifdef _WIN32 #include diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 1d40058bb..3fa792ad4 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -1658,6 +1658,7 @@ STRING_AND_THREEINTS(bitcoinrpc,getbalance,account,minconf,includeempty,lastheig if ( rmdarray != 0 ) free(rmdarray); retjson = cJSON_CreateObject(); + printf("%s balance %.8f\n",coin->symbol,dstr(balance)); jaddnum(retjson,"result",dstr(balance)); return(jprint(retjson,1)); } diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index c25af93a0..a3ab668b0 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -451,6 +451,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc void iguana_utxoaddrs_purge(struct iguana_info *coin); int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight,uint8_t *rmd160); int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr); +double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n); void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins); int32_t iguana_immediate(struct iguana_info *coin,int32_t immedmillis); int32_t iguana_fastfindreset(struct iguana_info *coin);