diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 915014299..fe63fb3c0 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -221,7 +221,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 ) cmd[0] = 's'; else cmd[0] = 'S'; - r = rand() % (coin->peers->numranked+1); + r = rand() % IGUANA_MAXPEERS; for (l=0; lipaddr,destipaddr) == 0) ) { //fprintf(stderr,">>> (%s).%u ",addr->ipaddr,coin->chain->portp2p); - //printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); + //printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 ) { void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey; @@ -320,7 +320,8 @@ void basilisk_sendback(struct supernet_info *myinfo,char *origCMD,char *symbol,c if ( (virt= iguana_coinfind(symbol)) != 0 ) { jaddnum(valsobj,"hwm",virt->blocks.hwmchain.height); - jaddbits256(valsobj,"chaintip",virt->blocks.hwmchain.RO.hash2); + if ( bits256_nonz(virt->blocks.hwmchain.RO.hash2) != 0 ) + jaddbits256(valsobj,"chaintip",virt->blocks.hwmchain.RO.hash2); } data = basilisk_jsondata(sizeof(struct iguana_msghdr),&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag); //printf("sendback.%d -> %s\n",datalen,remoteaddr); @@ -408,7 +409,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc if ( fanout < minfanout ) fanout = minfanout; if ( (numrequired= jint(valsobj,"numrequired")) <= 0 ) - numrequired = MAX(fanout,sqrt(myinfo->NOTARY.NUMRELAYS)+1); + numrequired = MIN(fanout,sqrt(myinfo->NOTARY.NUMRELAYS)+1); if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 ) { if ( (virt= iguana_coinfind(symbol)) != 0 ) @@ -822,6 +823,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) } else printf("null incoming\n"); if ( hwm > 0. ) { + printf("hwm %f\n",hwm); if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request { printf("my req hwm %f\n",hwm); @@ -832,11 +834,11 @@ void basilisk_requests_poll(struct supernet_info *myinfo) } else //if ( issueR.quoteid == 0 ) { - printf("other req hwm %f >>>>>>>>>>> send response\n",hwm); + printf("other req hwm %f >>>>>>>>>>> send response (%llx -> %llx)\n",hwm,(long long)issueR.desthash.txid,(long long)issueR.srchash.txid); issueR.quoteid = basilisk_quoteid(&issueR); issueR.desthash = myinfo->myaddr.persistent; datalen = basilisk_rwDEXquote(1,data,&issueR); - basilisk_channelsend(myinfo,issueR.desthash,'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16),(uint32_t)time(NULL),data,datalen,0); + basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16),(uint32_t)time(NULL),data,datalen,0); if ( (retstr= basilisk_start(myinfo,&issueR,0)) != 0 ) free(retstr); } //else printf("basilisk_requests_poll unexpected hwm issueR\n"); diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 34b0ec787..6bdf8dc44 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -413,44 +413,31 @@ ZERO_ARGS(InstantDEX,allcoins) STRING_ARG(InstantDEX,available,source) { - char *retstr; uint64_t total = 0; int32_t i,n; cJSON *item,*vals,*unspents,*balancejson,*retjson = 0; + uint64_t total = 0; int32_t i,n=0; cJSON *item,*unspents,*retjson = 0; if ( source != 0 && source[0] != 0 && (coin= iguana_coinfind(source)) != 0 ) { if ( myinfo->expiration != 0 ) { - //return(bitcoinrpc_getbalance(myinfo,coin,json,remoteaddr,"*",coin->chain->minconfirms,1,1<<30)); - if ( (vals= basilisk_balance_valsobj(myinfo,coin)) != 0 ) + if ( (unspents= iguana_listunspents(myinfo,coin,0,0,0,remoteaddr)) != 0 ) { - if ( (retstr= basilisk_balances(myinfo,coin,0,0,GENESIS_PUBKEY,vals,"")) != 0 ) + if ( (n= cJSON_GetArraySize(unspents)) > 0 ) { - printf("available.(%s)\n",retstr); - if ( (balancejson= cJSON_Parse(retstr)) != 0 ) + for (i=0; i %.8f\n",jprint(item,0),dstr(total)); - } - } + total += jdouble(item,"amount") * SATOSHIDEN; } -if ( total == 0 ) -total = 500000; - retjson = cJSON_CreateObject(); - jaddnum(retjson,"result",dstr(total)); - free_json(balancejson); - printf("n.%d total %.8f (%s)\n",n,dstr(total),jprint(retjson,0)); + //printf("(%s) -> %.8f\n",jprint(item,0),dstr(total)); } - free(retstr); } - free_json(vals); - if ( retjson != 0 ) - return(jprint(retjson,1)); + free_json(unspents); } + retjson = cJSON_CreateObject(); + jaddnum(retjson,"result",dstr(total)); + printf("(%s) n.%d total %.8f (%s)\n",jprint(unspents,0),n,dstr(total),jprint(retjson,0)); + return(jprint(retjson,1)); } printf("InstantDEX_available: need to unlock wallet\n"); return(clonestr("{\"error\":\"need to unlock wallet\"}")); @@ -473,27 +460,25 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) jaddnum(vals,"timestamp",time(NULL)); hash = myinfo->myaddr.persistent; printf("service.(%s)\n",jprint(vals,0)); + memset(&R,0,sizeof(R)); + if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 ) { - memset(&R,0,sizeof(R)); - if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 ) - { - printf("R.requestid.%u vs calc %u, q.%u\n",R.requestid,basilisk_requestid(&R),R.quoteid); - //if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) - // R.relaybits = myinfo->myaddr.myipbits; - if ( (reqjson= basilisk_requestjson(&R)) != 0 ) - free_json(reqjson); - datalen = basilisk_rwDEXquote(1,serialized,&R); - int32_t i; for (i=0; iIAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) + // R.relaybits = myinfo->myaddr.myipbits; + if ( (reqjson= basilisk_requestjson(&R)) != 0 ) + free_json(reqjson); + datalen = basilisk_rwDEXquote(1,serialized,&R); + int32_t i; for (i=0; i 0 ) { memset(hash.bytes,0,sizeof(hash)); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); - if ( basilisk_channelsend(myinfo,hash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 ) + if ( basilisk_channelsend(myinfo,R.srchash,R.desthash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 ) return(clonestr("{\"result\":\"DEX message sent\"}")); else return(clonestr("{\"error\":\"DEX message couldnt be sent\"}")); } @@ -523,8 +508,9 @@ int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int INT_ARG(InstantDEX,incoming,requestid) { - cJSON *retjson,*retarray; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192]; + cJSON *retjson,*retarray; bits256 zero; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[8192]; now = (uint32_t)time(NULL); + memset(&zero,0,sizeof(zero)); width = (now - myinfo->DEXpoll) + 2*drift; if ( width < (drift+1) ) width = 2*drift+1; @@ -534,7 +520,7 @@ INT_ARG(InstantDEX,incoming,requestid) retjson = cJSON_CreateObject(); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); msgid = (uint32_t)time(NULL) + drift; - if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 ) + if ( (retarray= basilisk_channelget(myinfo,zero,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 ) { //printf("GOT.(%s)\n",jprint(retarray,0)); if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index d634715b2..3e3907c26 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -27,8 +27,6 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3 else if ( duration > INSTANTDEX_LOCKTIME*2 ) duration = INSTANTDEX_LOCKTIME*2; memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash)); - if ( bits256_nonz(desthash) == 0 ) - msg->broadcast = 1; if ( bits256_nonz(desthash) == 0 ) msg->broadcast = 1; msg->duration = duration; @@ -108,7 +106,7 @@ int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256 char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; char *retstr; - senderhash = jbits256(valsobj,"sender"); + senderhash = jbits256(valsobj,"srchash"); duration = juint(valsobj,"duration"); keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash); retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration); @@ -118,7 +116,7 @@ char *basilisk_respond_OUT(struct supernet_info *myinfo,char *CMD,void *addr,cha duration = BASILISK_MSGDURATION; } // printf("OUT keylen.%d datalen.%d\n",keylen,datalen); - // char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); + char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(retstr); } @@ -203,7 +201,7 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha msgid = juint(valsobj,"msgid"); channel = juint(valsobj,"channel"); //char str[65],str2[65]; printf("%s -> %s channel.%u msgid.%x width.%d\n",bits256_str(str,jbits256(valsobj,"sender")),bits256_str(str2,hash),juint(valsobj,"channel"),msgid,width); - return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"sender"),hash,width)); + return(basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(valsobj,"srchash"),hash,width)); } #include "../includes/iguana_apidefs.h" @@ -212,7 +210,8 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { uint32_t msgid,width,channel; - jaddbits256(vals,"sender",myinfo->myaddr.persistent); + jaddbits256(vals,"srchash",hash); + jaddbits256(vals,"desthash",myinfo->myaddr.persistent); if ( (msgid= juint(vals,"msgid")) == 0 ) { msgid = (uint32_t)time(NULL); @@ -223,8 +222,8 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr) { channel = juint(vals,"channel"); width = juint(vals,"width"); - return(basilisk_iterate_MSG(myinfo,channel,msgid,hash,myinfo->myaddr.persistent,width)); - } else return(basilisk_standardservice("MSG",myinfo,0,hash,vals,hexstr,1)); + return(basilisk_iterate_MSG(myinfo,channel,msgid,myinfo->myaddr.persistent,myinfo->myaddr.persistent,width)); + } else return(basilisk_standardservice("MSG",myinfo,0,myinfo->myaddr.persistent,vals,hexstr,1)); } HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) @@ -232,7 +231,7 @@ 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; if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 ) { - keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash); + keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),hash); if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); @@ -248,7 +247,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) } #include "../includes/iguana_apiundefs.h" -int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t duration) +int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t duration) { char *retstr,*hexstr,strbuf[4096],*ptr = 0; int32_t retval = -1; cJSON *valsobj; if ( (hexstr= basilisk_addhexstr(&ptr,0,strbuf,sizeof(strbuf),data,datalen)) != 0 ) @@ -260,9 +259,10 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2)); jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"duration",duration); - jaddbits256(valsobj,"sender",myinfo->myaddr.persistent); - char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,hash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout")); - if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,hash,valsobj,hexstr)) != 0 ) + jaddbits256(valsobj,"srchash",srchash); + jaddbits256(valsobj,"desthash",desthash); + char str[65]; printf("sendmessage.[%d] channel.%u msgid.%x -> %s numrelays.%d:%d\n",datalen,channel,msgid,bits256_str(str,desthash),myinfo->NOTARY.NUMRELAYS,juint(valsobj,"fanout")); + if ( (retstr= basilisk_sendmessage(myinfo,0,0,0,desthash,valsobj,hexstr)) != 0 ) free(retstr); free_json(valsobj); if ( ptr != 0 ) @@ -296,7 +296,7 @@ int32_t basilisk_message_returned(uint8_t *key,uint8_t *data,int32_t maxlen,cJSO return(retval); } -cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t channel,uint32_t msgid,int32_t width) +cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,int32_t width) { char *retstr; cJSON *valsobj,*retarray=0,*item; valsobj = cJSON_CreateObject(); @@ -308,9 +308,11 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch jaddnum(valsobj,"timeout",2500); jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); jaddnum(valsobj,"numrequired",1); - if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 ) + jaddbits256(valsobj,"srchash",srchash); + jaddbits256(valsobj,"desthash",desthash); + if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 ) { - //printf("channel.%u msgid.%u gotmessage.(%s)\n",channel,msgid,retstr); + printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr)); if ( (retarray= cJSON_Parse(retstr)) != 0 ) { if ( is_cJSON_Array(retarray) == 0 ) diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 2fab0e662..dea04fc92 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -437,12 +437,12 @@ void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,s Lptr->retstr = jprint(infojson,1); return(Lptr); } - if ( (fanout= juint(valsobj,"fanout")) < 5 ) - fanout = 5; + if ( (fanout= juint(valsobj,"fanout")) < 8 ) + fanout = 8; if ( (numrequired= juint(valsobj,"numrequired")) < fanout ) { jaddnum(valsobj,"numrequired",fanout); - numrequired = fanout; + numrequired = 1; } ptr = basilisk_issueremote(myinfo,0,&numsent,"INF",coin->symbol,1,valsobj,fanout,numrequired,basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF); return(ptr); @@ -860,9 +860,9 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) coin = iguana_coinfind(symbol); } if ( jobj(vals,"numrequired") == 0 ) - jaddnum(vals,"numrequired",myinfo->NOTARY.NUMRELAYS); + jaddnum(vals,"numrequired",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); + jaddnum(vals,"fanout",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1)); if ( coin != 0 ) { //if ( juint(vals,"burn") == 0 ) diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index b2bb9c482..0a2cc9060 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -468,8 +468,9 @@ int32_t basilisk_process_swapget(struct supernet_info *myinfo,void *ptr,int32_t int32_t basilisk_swapget(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t maxlen,int32_t (*basilisk_verify_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)) { int32_t retval; cJSON *retarray; - if ( (retarray= basilisk_channelget(myinfo,myinfo->myaddr.persistent,swap->req.quoteid,msgbits,0)) != 0 ) + if ( (retarray= basilisk_channelget(myinfo,swap->otherhash,swap->myhash,swap->req.quoteid,msgbits,0)) != 0 ) { + printf("got.(%s) msgbits.%08x\n",jprint(retarray,0),msgbits); retval = basilisk_process_retarray(myinfo,swap,basilisk_process_swapget,data,maxlen,swap->req.quoteid,msgbits,retarray,basilisk_verify_func); if ( retval > 0 ) return(0); @@ -955,7 +956,7 @@ int32_t basilisk_verify_privkeys(struct supernet_info *myinfo,void *ptr,uint8_t uint32_t basilisk_swapsend(struct supernet_info *myinfo,struct basilisk_swap *swap,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t nextbits) { - if ( basilisk_channelsend(myinfo,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2) == 0 ) + if ( basilisk_channelsend(myinfo,swap->myhash,swap->otherhash,swap->req.quoteid,msgbits,data,datalen,INSTANTDEX_LOCKTIME*2) == 0 ) return(nextbits); printf("ERROR basilisk_channelsend\n"); return(0); diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index 0885f4498..bc62e5858 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -160,7 +160,7 @@ double tradebot_liquidity_active(struct supernet_info *myinfo,double *refpricep, 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.; + int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; uint64_t balance=0,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); @@ -191,7 +191,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk } else noquoteflag++; } printf("%s -> %s myrequest.%d pendingid.%u noquoteflag.%d havequoteflag.%d maxi.%d %.8f\n",list[0].src,list[0].dest,myrequest,pendingid,noquoteflag,havequoteflag,maxi,dstr(maxamount)); - double retvals[4],refprice,profitmargin,aveprice,balance=0.; cJSON *retjson; char *retstr; + double retvals[4],refprice,profitmargin,aveprice; 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 ) @@ -203,12 +203,13 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - balance = jdouble(retjson,"result"); + balance = jdouble(retjson,"result") * SATOSHIDEN; free_json(retjson); } free(retstr); } - printf("%s balance %.8f destamount %.8f aveprice %.8f minamount %.8f\n",list[0].dest,balance,dstr(destamount),aveprice,dstr(minamount)); + // 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 && destamount > 0 && destamount >= maxamount && destamount >= minamount ) { metric = 1.; @@ -216,6 +217,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk issueR->desthash = myinfo->myaddr.persistent; issueR->destamount = destamount; issueR->quotetime = (uint32_t)time(NULL); + printf("issueR set!\n"); } } else if ( myrequest != 0 && pendingid == 0 && maxi >= 0 ) // automatch best quote diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 52e152492..28aa3e38f 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -377,7 +377,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 { if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 ) lastbundle = hash2, lastheight = height; - else if ( 0 && missing++ > coin->MAXBUNDLES && strcmp("BTCD",coin->symbol) != 0 ) + else if ( missing++ > coin->MAXBUNDLES && strcmp("BTCD",coin->symbol) != 0 ) { printf("missing.%d\n",missing); break; diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index 084142d4f..566f67176 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -651,7 +651,7 @@ TWO_STRINGS(iguana,addnode,activecoin,ipaddr) struct iguana_peer *addr; int32_t i,n; if ( coin == 0 ) coin = iguana_coinfind(activecoin); - if ( strcmp(coin->symbol,"NOTARY") == 0 ) + if ( coin != 0 && strcmp(coin->symbol,"NOTARY") == 0 ) basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY); printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr); if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 ) diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 8a1c6e1ca..032ce2e87 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -1286,19 +1286,24 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime) return(jprint(retjson,1)); } +cJSON *iguana_listunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,char *remoteaddr) +{ + if ( minconf == 0 ) + minconf = 1; + if ( maxconf == 0 ) + maxconf = (1 << 30); + return(iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,0)); +} + TWOINTS_AND_ARRAY(bitcoinrpc,listunspent,minconf,maxconf,array) { //int32_t numrmds,numunspents=0; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray(); cJSON *argarray,*retjson; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - if ( minconf == 0 ) - minconf = 1; - if ( maxconf == 0 ) - maxconf = (1 << 30); if ( (argarray= array) == 0 || cJSON_GetArraySize(array) == 0 ) argarray = iguana_getaddressesbyaccount(myinfo,coin,"*"); - retjson = iguana_RTlistunspent(myinfo,coin,argarray,minconf,maxconf,remoteaddr,0); + retjson = iguana_listunspents(myinfo,coin,argarray,minconf,maxconf,remoteaddr); if ( argarray != array ) free_json(argarray); return(jprint(retjson,1)); diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 513cff2bf..ee161b72c 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -781,9 +781,12 @@ void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,str } if ( block != 0 && coin->RTheight > 0 && coin->utxoaddrtable != 0 )//&& coin->RTheight <= coin->blocks.hwmchain.height ) { - if ( block->height < (coin->RTheight - coin->minconfirms + 1) ) + /*if ( block->height < (coin->RTheight - coin->minconfirms) ) + { + printf("ht.%d > RT.%d - %d\n",block->height,coin->RTheight,coin->minconfirms); return; - if ( (block= iguana_blockfind("RTnew",coin,iguana_blockhash(coin,block->height-coin->minconfirms))) == 0 ) + }*/ + if ( (block= iguana_blockfind("RTnew",coin,iguana_blockhash(coin,block->height-coin->minconfirms+1))) == 0 ) return; // error check to bundle boundary portable_mutex_lock(&coin->RTmutex); diff --git a/iguana/iguana_volatiles.c b/iguana/iguana_volatiles.c index a284c68b2..371b07600 100755 --- a/iguana/iguana_volatiles.c +++ b/iguana/iguana_volatiles.c @@ -426,7 +426,7 @@ int32_t iguana_volatilesmap(struct supernet_info *myinfo,struct iguana_info *coi iguana_bundleload(myinfo,coin,ramchain,coin->bundles[ramchain->height/coin->chain->bundlesize],1); if ( (rdata= ramchain->H.data) == 0 ) { - printf("volatilesmap.[%d] no rdata\n",ramchain->height/coin->chain->bundlesize); + //printf("volatilesmap.[%d] no rdata\n",ramchain->height/coin->chain->bundlesize); return(-1); } } diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 30174cfa3..18884b54f 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -1146,7 +1146,7 @@ ZERO_ARGS(bitcoinrpc,getinfo) else { valsobj = cJSON_CreateObject(); - ptr = basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,0,1000,valsobj); + ptr = basilisk_getinfo(&Lptr,myinfo,coin,remoteaddr,0,3000,valsobj); free_json(valsobj); if ( ptr != 0 && ptr->retstr != 0 ) { diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 5c6dfd770..1369ea1d6 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -569,6 +569,7 @@ int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *c void iguana_RTreset(struct iguana_info *coin); void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight); void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block); +cJSON *iguana_listunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,char *remoteaddr); void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t checkonly); int32_t iguana_bundlehash2_check(struct iguana_info *coin,bits256 hash2); void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp);