From 84bd4d730be065b9e39bf7ff3d188e05def37bef Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 13:49:58 +0200 Subject: [PATCH 001/520] Test --- crypto777/iguana_OS.c | 12 +-- iguana/exchanges/LP_include.h | 4 +- iguana/exchanges/LP_nativeDEX.c | 17 ++--- iguana/exchanges/LP_prices.c | 64 ---------------- iguana/exchanges/LP_socket.c | 25 +++---- iguana/exchanges/LP_transaction.c | 22 +----- iguana/exchanges/LP_utxo.c | 118 +++++++++++++++++++++++++++++- iguana/exchanges/LP_utxos.c | 49 +++++-------- 8 files changed, 163 insertions(+), 148 deletions(-) diff --git a/crypto777/iguana_OS.c b/crypto777/iguana_OS.c index 504905ee1..9b218f130 100755 --- a/crypto777/iguana_OS.c +++ b/crypto777/iguana_OS.c @@ -297,11 +297,11 @@ void *queue_dequeue(queue_t *queue)//,int32_t offsetflag) void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_t freeitem) { struct allocitem *ptr; - struct queueitem *item = 0; + struct queueitem *tmp,*item = 0; lock_queue(queue); if ( queue->list != 0 ) { - DL_FOREACH(queue->list,item) + DL_FOREACH_SAFE(queue->list,item,tmp) { ptr = (void *)((long)item - sizeof(struct allocitem)); if ( item == copy || (ptr->allocsize == copysize && memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)item + sizeof(struct queueitem)),copysize) == 0) ) @@ -321,11 +321,11 @@ void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_ void *queue_free(queue_t *queue) { - struct queueitem *item = 0; + struct queueitem *tmp,*item = 0; lock_queue(queue); if ( queue->list != 0 ) { - DL_FOREACH(queue->list,item) + DL_FOREACH_SAFE(queue->list,item,tmp) { DL_DELETE(queue->list,item); myfree(item,sizeof(struct queueitem)); @@ -338,11 +338,11 @@ void *queue_free(queue_t *queue) void *queue_clone(queue_t *clone,queue_t *queue,int32_t size) { - struct queueitem *ptr,*item = 0; + struct queueitem *ptr,*tmp,*item = 0; lock_queue(queue); if ( queue->list != 0 ) { - DL_FOREACH(queue->list,item) + DL_FOREACH_SAFE(queue->list,item,tmp) { ptr = mycalloc('c',1,sizeof(*ptr)); memcpy(ptr,item,size); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 2a113134d..0c8eb2411 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -192,7 +192,7 @@ struct iguana_info uint8_t pubkey33[33]; }; -struct _LP_utxoinfo { bits256 txid; uint64_t value; int32_t vout; }; +struct _LP_utxoinfo { bits256 txid; uint64_t value; int32_t vout,height; }; struct LP_utxostats { uint32_t sessionid,lasttime,errors,swappending,spentflag,lastspentcheck,bestflag; }; @@ -209,7 +209,6 @@ struct LP_utxoinfo struct _LP_utxoinfo payment,deposit,fee; struct LP_utxostats T; struct LP_utxoswap S; - //struct LP_utxonetwork N; int32_t iambob,iamlp; uint8_t key[sizeof(bits256) + sizeof(int32_t)]; uint8_t key2[sizeof(bits256) + sizeof(int32_t)]; @@ -303,6 +302,7 @@ struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid) int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); +void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 15296bcd6..cc43a25d3 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -420,30 +420,27 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height; bits256 zero; //struct LP_address *ap,*atmp; struct LP_address_utxo *up; + int32_t height; bits256 zero; struct LP_address *ap,*atmp; struct LP_address_utxo *up,*utmp; //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( coin->inactive != 0 || coin->electrum != 0 ) continue; - /*if ( time(NULL) > coin->lastmonitor+60 ) + if ( time(NULL) > coin->lastmonitor+60 ) { portable_mutex_lock(&coin->txmutex); HASH_ITER(hh,coin->addresses,ap,atmp) { - if ( ap->monitor != 0 ) + DL_FOREACH_SAFE(ap->utxos,up,utmp) { - DL_FOREACH(ap->utxos,up) + if ( up->spentflag == 0 ) { - if ( up->spentflag == 0 ) - { - if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) - up->spentflag = (uint32_t)time(NULL); - } + if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) + up->spentflag = (uint32_t)time(NULL); } } } portable_mutex_unlock(&coin->txmutex); coin->lastmonitor = (uint32_t)time(NULL); - }*/ + } memset(zero.bytes,0,sizeof(zero)); if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index c4e011a15..eb1df8867 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -55,70 +55,6 @@ struct LP_pubkeyinfo uint8_t rmd160[20]; } *LP_pubkeyinfos; - -struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) -{ - struct LP_address *ap; - HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap); - return(ap); -} - -struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) -{ - struct LP_address *ap; - ap = calloc(1,sizeof(*ap)); - safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr)); - HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); - return(ap); -} - -struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) -{ - struct LP_address *ap; - if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 ) - ap = _LP_addressadd(coin,coinaddr); - return(ap); -} - -/*void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value) -{ - struct LP_address *ap; struct LP_address_utxo *up; - portable_mutex_lock(&coin->txmutex); - if ( (ap= _LP_address(coin,coinaddr)) != 0 ) - { - up = calloc(1,sizeof(*up)); - up->U.txid = txid; - up->U.vout = vout; - up->U.value = value; - DL_APPEND(ap->utxos,up); - } - portable_mutex_unlock(&coin->txmutex); -} - -void LP_address_monitor(struct LP_pubkeyinfo *pubp) -{ - struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; - return; - HASH_ITER(hh,LP_coins,coin,tmp) - { - bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - portable_mutex_lock(&coin->txmutex); - if ( (ap= _LP_address(coin,coinaddr)) != 0 ) - { - ap->monitor = (uint32_t)time(NULL); - } - portable_mutex_unlock(&coin->txmutex); - if ( coin->electrum != 0 ) - { - if ( (retjson= electrum_address_subscribe(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 ) - { - printf("%s MONITOR.(%s) -> %s\n",coin->symbol,coinaddr,jprint(retjson,0)); - free_json(retjson); - } - } - } -}*/ - int32_t LP_pricevalid(double price) { if ( price > SMALLVAL && isnan(price) == 0 && price < SATOSHIDEN ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 2866205a8..688a7f870 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -304,7 +304,7 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) return(ep); } -void electrum_process_array(struct iguana_info *coin,cJSON *array) +void electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *array) { int32_t i,v,n; char str[65]; uint64_t value; bits256 txid; cJSON *item; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) @@ -333,6 +333,7 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) { printf(">>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); tx->outpoints[v].value = value; + LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height); } } printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); @@ -443,7 +444,7 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT); printf("history.(%s)\n",jprint(retjson,0)); - electrum_process_array(coin,retjson); + electrum_process_array(coin,addr,retjson); return(retjson); } @@ -452,7 +453,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON * cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT); printf("MEMPOOL.(%s)\n",jprint(retjson,0)); - electrum_process_array(coin,retjson); + electrum_process_array(coin,addr,retjson); return(retjson); } @@ -465,7 +466,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); - electrum_process_array(coin,retjson); + electrum_process_array(coin,addr,retjson); strcpy(coin->lastunspent,addr); coin->unspenttime = (uint32_t)time(NULL); } @@ -608,7 +609,7 @@ struct electrum_info *LP_electrum_info(int32_t *alreadyp,char *symbol,char *ipad int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) { - cJSON *strjson,*errjson,*resultjson,*paramsjson; char *method; int32_t i,n,height; uint32_t idnum=0; struct stritem *stritem; struct queueitem *item = 0; + cJSON *strjson,*errjson,*resultjson,*paramsjson; char *method; int32_t i,n,height; uint32_t idnum=0; struct stritem *stritem; struct queueitem *tmp,*item = 0; ep->lasttime = (uint32_t)time(NULL); if ( (strjson= cJSON_Parse(str)) != 0 ) { @@ -625,11 +626,11 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) resultjson = jitem(paramsjson,i); } } - else if ( strcmp(method,"blockchain.address.subscribe") == 0 ) + /*else if ( strcmp(method,"blockchain.address.subscribe") == 0 ) never is called { printf("recv addr subscribe.(%s)\n",jprint(resultjson,0)); electrum_process_array(ep->coin,resultjson); - } + }*/ } if ( resultjson != 0 ) { @@ -644,11 +645,9 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) portable_mutex_lock(&ep->pendingQ.mutex); if ( ep->pendingQ.list != 0 ) { - DL_FOREACH(ep->pendingQ.list,item) + DL_FOREACH_SAFE(ep->pendingQ.list,item,tmp) { stritem = (struct stritem *)item; - if ( *stritem->retptrp != 0 ) - continue; if ( item->type == idnum ) { //printf("matched idnum.%d result.%p\n",idnum,resultjson); @@ -660,13 +659,13 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) } if ( stritem->expiration < ep->lasttime ) { - //DL_DELETE(ep->pendingQ.list,item); + DL_DELETE(ep->pendingQ.list,item); printf("expired (%s)\n",stritem->str); errjson = cJSON_CreateObject(); jaddnum(errjson,"id",item->type); jaddstr(errjson,"error","timeout"); *((cJSON **)stritem->retptrp) = errjson; - //free(item); + free(item); } } } @@ -708,7 +707,7 @@ void LP_dedicatedloop(void *arg) if ( ep->pendingQ.list != 0 ) { printf("list %p\n",ep->pendingQ.list); - DL_FOREACH(ep->pendingQ.list,item) + DL_FOREACH_SAFE(ep->pendingQ.list,item,tmp) { printf("item.%p\n",item); if ( item->type == 0xffffffff ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 71bde88e4..86c06f84d 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -795,33 +795,13 @@ char *basilisk_swap_Aspend(char *name,char *symbol,uint64_t Atxfee,uint8_t wifta return(signedtx); } -int32_t LP_swap_txdestaddr(char *destaddr,bits256 txid,int32_t vout,cJSON *txobj) -{ - int32_t n,m,retval = -1; cJSON *vouts,*item,*addresses,*skey; char *addr; - if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n ) - { - item = jitem(vouts,vout); - if ( (skey= jobj(item,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) - { - item = jitem(addresses,0); - if ( (addr= jstr(item,0)) != 0 ) - { - safecopy(destaddr,addr,64); - retval = 0; - } - //printf("item.(%s) -> dest.(%s)\n",jprint(item,0),destaddr); - } - } - return(retval); -} - int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vout) { cJSON *retjson; coinaddr[0] = 0; if ( (retjson= LP_gettx(symbol,txid)) != 0 ) { - LP_swap_txdestaddr(coinaddr,txid,vout,retjson); + LP_txdestaddr(coinaddr,txid,vout,retjson); free_json(retjson); } return(coinaddr[0] != 0); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 5c327dc99..79ef1d862 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -18,6 +18,16 @@ // marketmaker // +// listunspent: valid for local node, mostly valid for electrum + +// full node + electrum for external listunspent, gettxout to validate +// pruned node + electrum for external listunspent, gettxout to validate +// full node, network for external listunspent, gettxout to validate +// pruned node, network for external listunspent, gettxout to validate +// electrum only, network for gettxout + +// locally track spends, height + uint64_t LP_value_extract(cJSON *obj) { double val = 0.; uint64_t value; @@ -29,6 +39,85 @@ uint64_t LP_value_extract(cJSON *obj) return(value); } +struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) +{ + struct LP_address *ap; + HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap); + return(ap); +} + +struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) +{ + struct LP_address *ap; + ap = calloc(1,sizeof(*ap)); + safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr)); + HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); + return(ap); +} + +struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) +{ + struct LP_address *ap; + if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 ) + ap = _LP_addressadd(coin,coinaddr); + return(ap); +} + +void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height) +{ + struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag; + portable_mutex_lock(&coin->txmutex); + if ( (ap= _LP_address(coin,coinaddr)) != 0 ) + { + flag = 0; + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 ) + { + if ( up->U.height <= 0 && height > 0 ) + up->U.height = height; + flag = 1; + break; + } + } + if ( flag == 0 ) + { + up = calloc(1,sizeof(*up)); + up->U.txid = txid; + up->U.vout = vout; + up->U.height = height; + up->U.value = value; + DL_APPEND(ap->utxos,up); + } + } + portable_mutex_unlock(&coin->txmutex); +} + +/*void LP_address_monitor(struct LP_pubkeyinfo *pubp) +{ + struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; + return; + HASH_ITER(hh,LP_coins,coin,tmp) + { + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + portable_mutex_lock(&coin->txmutex); + if ( (ap= _LP_address(coin,coinaddr)) != 0 ) + { + ap->monitor = (uint32_t)time(NULL); + } + portable_mutex_unlock(&coin->txmutex); + if ( coin->electrum != 0 ) + { + if ( (retjson= electrum_address_subscribe(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 ) + { + printf("%s MONITOR.(%s) -> %s\n",coin->symbol,coinaddr,jprint(retjson,0)); + free_json(retjson); + } + } + } +} +*/ + void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) { memcpy(key,txid.bytes,sizeof(txid)); @@ -270,9 +359,33 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) return(value + interest); } +int32_t LP_destaddr(char *destaddr,cJSON *item) +{ + int32_t m,retval = -1; cJSON *addresses,*skey; char *addr; + if ( (skey= jobj(item,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) + { + item = jitem(addresses,0); + if ( (addr= jstr(item,0)) != 0 ) + { + safecopy(destaddr,addr,64); + retval = 0; + } + //printf("item.(%s) -> dest.(%s)\n",jprint(item,0),destaddr); + } + return(retval); +} + +int32_t LP_txdestaddr(char *destaddr,bits256 txid,int32_t vout,cJSON *txobj) +{ + int32_t n,retval = -1; cJSON *vouts; + if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n ) + retval = LP_destaddr(destaddr,jitem(vouts,vout)); + return(retval); +} + uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { - struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65]; + struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65],_coinaddr[65]; if ( bits256_nonz(txid) == 0 ) return(0); if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) @@ -312,6 +425,9 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) { value = SATOSHIDEN * jdouble(txobj,"value"); + if ( coinaddr == 0 ) + coinaddr = _coinaddr; + LP_destaddr(coinaddr,txobj); free_json(txobj); printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); return(value); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index bf985cae1..955cdaff8 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -537,11 +537,6 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) HASH_ADD_KEYPTR(hh2,LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); portable_mutex_unlock(&LP_utxomutex); - /*if ( 0 && coin->electrum == 0 ) - { - LP_address_utxoadd(coin,coinaddr,txid,vout,value); - LP_address_utxoadd(coin,coinaddr,txid2,vout2,value2); - }*/ if ( iambob != 0 ) { if ( LP_mypeer != 0 ) @@ -715,7 +710,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { - char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; + char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; if ( coin == 0 ) { printf("coin not active\n"); @@ -732,41 +727,33 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr if ( iambob == 0 ) values = calloc(n,sizeof(*values)); else memset(values,0,n * sizeof(*values)); - //if ( iambob == 0 && IAMLP != 0 ) - // continue; used = 0; for (i=0; ielectrum == 0 ) { - //satoshis = SATOSHIDEN * jdouble(item,"amount"); - //if ( satoshis == 0 ) - // satoshis = SATOSHIDEN * jdouble(item,"value"); - satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"txid"),juint(item,"vout")); - if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) - { - //printf("%s\n",jprint(item,0)); - values[i] = satoshis; - } else used++; + txid = jbits256(item,"txid"); + vout = juint(item,"vout"); + value = LP_value_extract(item); + height = coin->height - jint(item,"confirmations"); } else { - //{"value":1000000,"tx_hash":"4e4f818c53486c0576693b4cd379849e5ff95538b38e4100f48884073a4e7636","tx_pos":0,"height":484877} - satoshis = j64bits(item,"value"); - satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")); - if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) - { - //printf("%s\n",jprint(item,0)); - values[i] = satoshis; - } - else - { - printf("skip.(%s) coinht.%d\n",jprint(item,0),coin->height); - used++; - } + txid = jbits256(item,"tx_hash"); + vout = juint(item,"tx_pos"); + value = j64bits(item,"value"); + height = jint(item,"height"); } - //printf("%.8f ",dstr(satoshis)); + satoshis = LP_txvalue(destaddr,coin->symbol,txid,vout); + if ( satoshis != value ) + printf("unexpected privkey_init value mismatch %.8f vs %.8f (%s)\n",dstr(satoshis),dstr(value),jprint(item,0)); + if ( LP_inventory_prevent(iambob,coin->symbol,txid,vout) == 0 && height > 0 ) + { + //printf("%s\n",jprint(item,0)); + values[i] = satoshis; + LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height); + } else used++; } //printf("array.%d\n",n); while ( used < n-1 ) From de569dec826d48f546647a72606f265fb5689a3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 14:19:43 +0200 Subject: [PATCH 002/520] Test --- iguana/exchanges/LP_include.h | 4 +- iguana/exchanges/LP_nativeDEX.c | 4 +- iguana/exchanges/LP_socket.c | 4 +- iguana/exchanges/LP_transaction.c | 7 +-- iguana/exchanges/LP_utxo.c | 77 +++++++++++++++---------------- iguana/exchanges/LP_utxos.c | 2 +- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0c8eb2411..1de4733c5 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -219,7 +219,7 @@ struct LP_address_utxo { struct LP_address_utxo *next,*prev; struct _LP_utxoinfo U; - uint32_t height,SPV,spentflag; + uint32_t height,SPV,spendheight; }; struct LP_address @@ -302,7 +302,7 @@ struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid) int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); -void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height); +void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cc43a25d3..9bc79a954 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -431,10 +431,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { DL_FOREACH_SAFE(ap->utxos,up,utmp) { - if ( up->spentflag == 0 ) + if ( up->spendheight <= 0 ) { if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) - up->spentflag = (uint32_t)time(NULL); + up->spendheight = 1; } } } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 688a7f870..78f83a387 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -333,7 +333,7 @@ void electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *array { printf(">>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); tx->outpoints[v].value = value; - LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height); + LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); } } printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); @@ -461,7 +461,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); - //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) + if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 86c06f84d..19169356d 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1053,7 +1053,7 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t v) { - cJSON *txobj,*vouts,*vout,*addresses,*item,*skey; uint8_t extraspace[32768]; bits256 signedtxid; struct iguana_msgtx msgtx; char *addr; int32_t n,m,suppress_pubkeys = 0; + cJSON *txobj,*vouts,*vout; uint8_t extraspace[32768]; bits256 signedtxid; struct iguana_msgtx msgtx; int32_t n,suppress_pubkeys = 0; if ( valuep != 0 ) *valuep = 0; if ( (txobj= bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->longestchain,&signedtxid,&msgtx,extraspace,sizeof(extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) @@ -1065,7 +1065,7 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u if ( valuep != 0 ) *valuep = LP_value_extract(vout); //printf("VOUT.(%s)\n",jprint(vout,0)); - if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) + /*if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) { item = jitem(addresses,0); //printf("item.(%s)\n",jprint(item,0)); @@ -1074,7 +1074,8 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u safecopy(coinaddr,addr,64); //printf("extracted.(%s)\n",coinaddr); } - } + }*/ + LP_destaddr(coinaddr,vout); } free_json(txobj); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 79ef1d862..6d0ffdc58 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -39,6 +39,30 @@ uint64_t LP_value_extract(cJSON *obj) return(value); } +int32_t LP_destaddr(char *destaddr,cJSON *item) +{ + int32_t m,retval = -1; cJSON *addresses,*skey; char *addr; + if ( (skey= jobj(item,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) + { + item = jitem(addresses,0); + if ( (addr= jstr(item,0)) != 0 ) + { + safecopy(destaddr,addr,64); + retval = 0; + } + //printf("item.(%s) -> dest.(%s)\n",jprint(item,0),destaddr); + } + return(retval); +} + +int32_t LP_txdestaddr(char *destaddr,bits256 txid,int32_t vout,cJSON *txobj) +{ + int32_t n,retval = -1; cJSON *vouts; + if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n ) + retval = LP_destaddr(destaddr,jitem(vouts,vout)); + return(retval); +} + struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) { struct LP_address *ap; @@ -63,7 +87,7 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) return(ap); } -void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height) +void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag; portable_mutex_lock(&coin->txmutex); @@ -76,6 +100,8 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int { if ( up->U.height <= 0 && height > 0 ) up->U.height = height; + if ( spendheight > 0 ) + up->spendheight = spendheight; flag = 1; break; } @@ -87,6 +113,7 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int up->U.vout = vout; up->U.height = height; up->U.value = value; + up->spendheight = spendheight; DL_APPEND(ap->utxos,up); } } @@ -192,7 +219,7 @@ struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,i uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_info *coin,bits256 txid,int32_t vout) { - uint64_t interest,value = 0; cJSON *txobj,*sobj,*array; int32_t n=0; + uint64_t interest,value = 0; cJSON *txobj; *interestp = 0; destaddr[0] = 0; if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) @@ -209,13 +236,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf *interestp = SATOSHIDEN * interest; } } - if ( (sobj= jobj(txobj,"scriptPubKey")) != 0 && (array= jarray(&n,sobj,"addresses")) != 0 ) - { - strcpy(destaddr,jstri(array,0)); - //printf("set destaddr.(%s)\n",destaddr); - if ( n > 1 ) - printf("LP_txinterestvalue warning: violation of 1 output assumption n.%d\n",n); - } else printf("LP_txinterestvalue no addresses found?\n"); + LP_destaddr(destaddr,txobj); //char str[65]; printf("dest.(%s) %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0)); free_json(txobj); } //else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); } @@ -224,7 +245,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) { - struct LP_transaction *tx; char *address; int32_t i,n,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin,*sobj,*addresses; bits256 spenttxid; char str[65]; + struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { //printf("TX.(%s)\n",jprint(txobj,0)); @@ -241,7 +262,8 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) vout = jitem(vouts,i); tx->outpoints[i].value = LP_value_extract(vout); tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); - if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) + LP_destaddr(tx->outpoints[i].coinaddr,vout); + /*if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) { if ( (addresses= jarray(&n,sobj,"addresses")) != 0 && n > 0 ) { @@ -256,7 +278,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) } //else if ( tx->outpoints[i].value != 0 ) // printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n); - } + }*/ } //printf("numvouts.%d\n",numvouts); } @@ -271,12 +293,13 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) continue; if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 ) { - if ( spentvout < tx->numvouts ) + if ( spentvout < tx->numvouts && tx->outpoints[spentvout].spendheight <= 0 ) { tx->outpoints[spentvout].spendtxid = txid; tx->outpoints[spentvout].spendvini = i; - tx->outpoints[spentvout].spendheight = height; - //printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); + tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; + LP_address_utxoadd(coin,tx->outpoints[i].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); + printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); if ( bits256_cmp(spenttxid,txid) == 0 ) @@ -359,30 +382,6 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) return(value + interest); } -int32_t LP_destaddr(char *destaddr,cJSON *item) -{ - int32_t m,retval = -1; cJSON *addresses,*skey; char *addr; - if ( (skey= jobj(item,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) - { - item = jitem(addresses,0); - if ( (addr= jstr(item,0)) != 0 ) - { - safecopy(destaddr,addr,64); - retval = 0; - } - //printf("item.(%s) -> dest.(%s)\n",jprint(item,0),destaddr); - } - return(retval); -} - -int32_t LP_txdestaddr(char *destaddr,bits256 txid,int32_t vout,cJSON *txobj) -{ - int32_t n,retval = -1; cJSON *vouts; - if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n ) - retval = LP_destaddr(destaddr,jitem(vouts,vout)); - return(retval); -} - uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65],_coinaddr[65]; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 955cdaff8..e98ef55e1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -752,7 +752,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height); + LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } //printf("array.%d\n",n); From 73832d71cd79872a8a4ee752a9f53b8532d6e504 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 14:24:41 +0200 Subject: [PATCH 003/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e98ef55e1..0cd46a170 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -752,7 +752,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); + //LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } //printf("array.%d\n",n); From 0e9a92ccc3e42a62363b990da8a29d76e9dfcd95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 14:26:24 +0200 Subject: [PATCH 004/520] Test --- iguana/exchanges/LP_utxo.c | 1 + iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6d0ffdc58..409a13f9a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -90,6 +90,7 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag; + return; portable_mutex_lock(&coin->txmutex); if ( (ap= _LP_address(coin,coinaddr)) != 0 ) { diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0cd46a170..e98ef55e1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -752,7 +752,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - //LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); + LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } //printf("array.%d\n",n); From 389d8fda803d87c25dcff6f875118f3e0a35a001 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 14:30:45 +0200 Subject: [PATCH 005/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 1de4733c5..201cb492d 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -167,7 +167,7 @@ struct basilisk_swapinfo uint8_t userdata_bobrefund[256],userdata_bobrefundlen; }; -struct LP_outpoint { bits256 spendtxid; uint64_t value,interest; int32_t spendvini,spendheight; char coinaddr[40]; }; +struct LP_outpoint { bits256 spendtxid; uint64_t value,interest; int32_t spendvini,spendheight; char coinaddr[64]; }; struct LP_transaction { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 409a13f9a..89ed0c8dc 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -249,7 +249,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { - //printf("TX.(%s)\n",jprint(txobj,0)); + printf("TX.(%s)\n",jprint(txobj,0)); if ( coin->electrum == 0 ) height = LP_txheight(coin,txid); else height = -1; @@ -257,7 +257,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) vouts = jarray(&numvouts,txobj,"vout"); if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { - //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); + printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); for (i=0; i Date: Fri, 15 Sep 2017 14:31:50 +0200 Subject: [PATCH 006/520] Test --- iguana/exchanges/LP_utxo.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 89ed0c8dc..6d0ffdc58 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -90,7 +90,6 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag; - return; portable_mutex_lock(&coin->txmutex); if ( (ap= _LP_address(coin,coinaddr)) != 0 ) { @@ -249,7 +248,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { - printf("TX.(%s)\n",jprint(txobj,0)); + //printf("TX.(%s)\n",jprint(txobj,0)); if ( coin->electrum == 0 ) height = LP_txheight(coin,txid); else height = -1; @@ -257,7 +256,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) vouts = jarray(&numvouts,txobj,"vout"); if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { - printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); + //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); for (i=0; i Date: Fri, 15 Sep 2017 14:44:48 +0200 Subject: [PATCH 007/520] Test --- iguana/exchanges/LP_rpc.c | 50 +++++++++++++++++++++++++++---------- iguana/exchanges/LP_utxos.c | 8 +++--- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 641d547ab..db062d6bc 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -351,19 +351,6 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) } } -cJSON *LP_listunspent(char *symbol,char *coinaddr) -{ - char buf[128]; cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); - //printf("LP_listunspent.(%s %s)\n",symbol,coinaddr); - if ( coin == 0 || coin->inactive != 0 ) - return(cJSON_Parse("{\"error\":\"no coin\"}")); - if ( coin->electrum == 0 ) - { - sprintf(buf,"[0, 99999999, [\"%s\"]]",coinaddr); - return(bitcoin_json(coin,"listunspent",buf)); - } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)); -} - /*cJSON *LP_listtransactions(char *symbol,char *coinaddr,int32_t count,int32_t skip) { char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); @@ -410,6 +397,43 @@ cJSON *LP_validateaddress(char *symbol,char *address) } } +int32_t LP_address_ismine(char *symbol,char *address) +{ + int32_t doneflag = 0; cJSON *retjson; + if ( (retjson= LP_validateaddress(symbol,address)) != 0 ) + { + if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) + { + doneflag = 1; + //printf("%s already ismine\n",address); + } + //printf("%s\n",jprint(retjson,0)); + free_json(retjson); + } + return(doneflag); +} + +cJSON *LP_listunspent(char *symbol,char *coinaddr) +{ + char buf[128]; cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); + //printf("LP_listunspent.(%s %s)\n",symbol,coinaddr); + if ( coin == 0 || coin->inactive != 0 ) + return(cJSON_Parse("{\"error\":\"no coin\"}")); + if ( coin->electrum == 0 ) + { + if ( LP_address_ismine(symbol,coinaddr) > 0 ) + { + sprintf(buf,"[0, 99999999, [\"%s\"]]",coinaddr); + return(bitcoin_json(coin,"listunspent",buf)); + } + else + { + printf("return local RAM listunspent\n"); + return(0); + } + } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)); +} + cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) { static void *ctx; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e98ef55e1..4b09a772b 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -758,9 +758,9 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr //printf("array.%d\n",n); while ( used < n-1 ) { - for (i=0; i= 0 ) { item = jitem(array,i); @@ -783,7 +783,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr else targetval = (depositval / 9) * 8 + 2*txfee; if ( targetval < txfee*2 ) targetval = txfee*2; - printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(depositval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval)); + //printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(depositval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval)); if ( depositval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) continue; i = -1; From 4a3172ee06b6970dd026b3b06808c8506552d574 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 15:13:49 +0200 Subject: [PATCH 008/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_rpc.c | 7 +----- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 42 +++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 201cb492d..b623c71a2 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -303,6 +303,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); +cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); #endif diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index db062d6bc..7d23f6f0a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -425,12 +425,7 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) { sprintf(buf,"[0, 99999999, [\"%s\"]]",coinaddr); return(bitcoin_json(coin,"listunspent",buf)); - } - else - { - printf("return local RAM listunspent\n"); - return(0); - } + } else return(LP_address_utxos(coin,coinaddr,0)); } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 78f83a387..f92fb7bb0 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -470,7 +470,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON strcpy(coin->lastunspent,addr); coin->unspenttime = (uint32_t)time(NULL); } - } + } else retjson = LP_address_utxos(coin,addr,1); return(retjson); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6d0ffdc58..0c013bfe6 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -34,7 +34,7 @@ uint64_t LP_value_extract(cJSON *obj) if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); if ( val > SMALLVAL ) - value = (val * SATOSHIDEN + 0.0000000049); + value = ((val + jdouble(obj,"interest")) * SATOSHIDEN + 0.0000000049); else value = 0; return(value); } @@ -120,6 +120,44 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int portable_mutex_unlock(&coin->txmutex); } +cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32_t electrumret) +{ + cJSON *item = cJSON_CreateObject(); + if ( electrumret == 0 ) + { + jaddbits256(item,"txid",up->U.txid); + jaddnum(item,"vout",up->U.vout); + jaddnum(item,"confirmations",coin->height - up->U.height); + jaddnum(item,"amount",dstr(up->U.value)); + jaddstr(item,"scriptPubKey",""); + } + else + { + jaddbits256(item,"tx_hash",up->U.txid); + jaddnum(item,"tx_pos",up->U.vout); + jaddnum(item,"height",up->U.height); + jadd64bits(item,"value",up->U.value); + } + return(item); +} + +cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret) +{ + cJSON *array; struct LP_address *ap; struct LP_address_utxo *up,*tmp; + array = cJSON_CreateArray(); + portable_mutex_lock(&coin->txmutex); + if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) + { + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( up->spendheight <= 0 ) + jaddi(array,LP_address_item(up,electrumret)); + } + } + portable_mutex_unlock(&coin->txmutex); + return(array); +} + /*void LP_address_monitor(struct LP_pubkeyinfo *pubp) { struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; @@ -423,7 +461,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) { - value = SATOSHIDEN * jdouble(txobj,"value"); + value = SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest")); if ( coinaddr == 0 ) coinaddr = _coinaddr; LP_destaddr(coinaddr,txobj); From 783399dd233395400d2e80f587c3fc0fb07b480f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 15:21:15 +0200 Subject: [PATCH 009/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 4b09a772b..442a21df8 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -747,7 +747,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr } satoshis = LP_txvalue(destaddr,coin->symbol,txid,vout); if ( satoshis != value ) - printf("unexpected privkey_init value mismatch %.8f vs %.8f (%s)\n",dstr(satoshis),dstr(value),jprint(item,0)); + printf("unexpected privkey_init value mismatch %.8f vs %.8f (%s) %.8f %.8f\n",dstr(satoshis),dstr(value),jprint(item,0),jdouble(item,"amount"),jdouble(item,"interest")); if ( LP_inventory_prevent(iambob,coin->symbol,txid,vout) == 0 && height > 0 ) { //printf("%s\n",jprint(item,0)); From a448036217be3ce83bb317daad13055129374dbc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 15:23:59 +0200 Subject: [PATCH 010/520] Test --- iguana/exchanges/LP_portfolio.c | 2 +- iguana/exchanges/LP_remember.c | 2 +- iguana/exchanges/LP_transaction.c | 2 +- iguana/exchanges/LP_utxo.c | 8 ++++---- iguana/exchanges/LP_utxos.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index a3e656e70..15263a593 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -57,7 +57,7 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr) for (i=0; i>= 1; decode_hex(Dredeemscript,Dredeemlen,rstr); } - values[i] = value = LP_value_extract(txobj); + values[i] = value = LP_value_extract(txobj,1); if ( (symbol= jstr(txobj,"coin")) != 0 ) { if ( i == BASILISK_ALICESPEND || i == BASILISK_BOBPAYMENT || i == BASILISK_BOBDEPOSIT || i == BASILISK_BOBREFUND || i == BASILISK_BOBRECLAIM || i == BASILISK_ALICECLAIM ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 19169356d..51b6b2ec7 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1063,7 +1063,7 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u { vout = jitem(vouts,v); if ( valuep != 0 ) - *valuep = LP_value_extract(vout); + *valuep = LP_value_extract(vout,1); //printf("VOUT.(%s)\n",jprint(vout,0)); /*if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 0c013bfe6..7a70268fe 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -28,13 +28,13 @@ // locally track spends, height -uint64_t LP_value_extract(cJSON *obj) +uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { double val = 0.; uint64_t value; if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); if ( val > SMALLVAL ) - value = ((val + jdouble(obj,"interest")) * SATOSHIDEN + 0.0000000049); + value = ((val + jdouble(obj,"interest")*addinterest) * SATOSHIDEN + 0.0000000049); else value = 0; return(value); } @@ -262,7 +262,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf destaddr[0] = 0; if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) { - if ( (value= LP_value_extract(txobj)) == 0 ) + if ( (value= LP_value_extract(txobj,0)) == 0 ) { char str[65]; printf("%s LP_txvalue.%s strange utxo.(%s) vout.%d\n",coin->symbol,bits256_str(str,txid),jprint(txobj,0),vout); } @@ -298,7 +298,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) for (i=0; ioutpoints[i].value = LP_value_extract(vout); + tx->outpoints[i].value = LP_value_extract(vout,0); tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); LP_destaddr(tx->outpoints[i].coinaddr,vout); /*if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 442a21df8..01843bd29 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -735,7 +735,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { txid = jbits256(item,"txid"); vout = juint(item,"vout"); - value = LP_value_extract(item); + value = LP_value_extract(item,0); height = coin->height - jint(item,"confirmations"); } else From d82840481572f875e1cd831581c69abb1d6ef979 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 15:26:55 +0200 Subject: [PATCH 011/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 7a70268fe..a83d64b8f 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -151,7 +151,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum DL_FOREACH_SAFE(ap->utxos,up,tmp) { if ( up->spendheight <= 0 ) - jaddi(array,LP_address_item(up,electrumret)); + jaddi(array,LP_address_item(coin,up,electrumret)); } } portable_mutex_unlock(&coin->txmutex); From 13fa5392f07d34395312d822c60fe5b84c3f5528 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 15:37:05 +0200 Subject: [PATCH 012/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a83d64b8f..3ede8623e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -453,7 +453,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) strcpy(coinaddr,tx->outpoints[vout].coinaddr); //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); } - return(tx->outpoints[vout].value + tx->outpoints[vout].interest); + return(tx->outpoints[vout].value + 0*tx->outpoints[vout].interest); } } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); } From 223f1b3306a38fb97d6390d5b7fecb2af129ee73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 11:30:18 +0200 Subject: [PATCH 013/520] Fix crash --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 3ede8623e..b8926cf4d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -336,7 +336,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) tx->outpoints[spentvout].spendtxid = txid; tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; - LP_address_utxoadd(coin,tx->outpoints[i].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); + LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); From 6d80af2598f28a01eaa74724b249887b198324c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 13:36:47 +0200 Subject: [PATCH 014/520] Test --- iguana/exchanges/LP_commands.c | 8 +++ iguana/exchanges/LP_nativeDEX.c | 40 +++++++-------- iguana/exchanges/LP_utxo.c | 90 ++++++++++++++++++++++++++++++--- iguana/exchanges/LP_utxos.c | 47 ++--------------- 4 files changed, 117 insertions(+), 68 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b76100e93..754dd6d3d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -351,6 +351,8 @@ dividends(coin, height, )\n\ return(LP_numutxos()); else if ( strcmp(method,"postprice") == 0 ) retstr = LP_postedprice(argjson); + else if ( strcmp(method,"postutxos") == 0 ) + retstr = LP_postedutxos(argjson); else if ( strcmp(method,"encrypted") == 0 ) retstr = clonestr("{\"result\":\"success\"}"); else if ( strcmp(method,"getprices") == 0 ) @@ -388,6 +390,12 @@ dividends(coin, height, )\n\ return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); else if ( strcmp(method,"lookup") == 0 ) return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); + else if ( strcmp(method,"listunspent") == 0 ) + { + if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) + return(jprint(LP_address_utxos(ptr,jstr(argjson,"address"),1),1)); + else return(clonestr("{\"error\":\"cant find coind\"}")); + } if ( strcmp(method,"broadcast") == 0 ) { bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9bc79a954..fb492573f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -325,6 +325,7 @@ void command_rpcloop(void *myipaddr) int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport,char *passphrase) { + int32_t enable_utxos = 0; static uint32_t counter,numpeers,lastresync; //lastforward struct LP_utxoinfo *utxo,*utmp; cJSON *retjson; struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp,*mostpeer; uint32_t id,now; int32_t mostutxos,nonz = 0,n=0,num,lastn=-1; now = (uint32_t)time(NULL); @@ -332,7 +333,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int origipaddr = "127.0.0.1"; if ( mypeer == 0 ) myipaddr = "127.0.0.1"; - //if ( LP_canbind == 0 ) printf("counter.%d canbind.%d peers\n",counter,LP_canbind); numpeers = LP_numpeers(); mostutxos = 0; mostpeer = 0; @@ -357,7 +357,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int // printf("%s num.%d vs %d\n",peer->ipaddr,peer->numpeers,numpeers); if ( strcmp(peer->ipaddr,myipaddr) != 0 ) LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); - if ( IAMLP != 0 && LP_mypeer != 0 && strcmp(peer->ipaddr,myipaddr) != 0 ) + if ( enable_utxos && IAMLP != 0 && LP_mypeer != 0 && strcmp(peer->ipaddr,myipaddr) != 0 ) { if ( (retstr= issue_LP_numutxos(peer->ipaddr,peer->port,LP_mypeer->ipaddr,LP_mypeer->port,LP_mypeer->numpeers,LP_mypeer->numutxos)) != 0 ) { @@ -379,7 +379,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( peer->diduquery == 0 ) { - if ( lastn != n || n < 20 ) + if ( enable_utxos && (lastn != n || n < 20) ) { lastn = n; n = LP_peer_utxosquery(mypeer,myport,pubsock,peer,now,60,100); @@ -394,14 +394,14 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } } //printf("numutxos vs mine.%d\n",LP_mypeer != 0 ? LP_mypeer->numutxos : -1); - if ( LP_mypeer != 0 && mostpeer != 0 && ((LP_mypeer->numutxos < mostutxos && time(NULL) > lastresync+10) || time(NULL) > lastresync+60) ) + if ( enable_utxos && LP_mypeer != 0 && mostpeer != 0 && ((LP_mypeer->numutxos < mostutxos && time(NULL) > lastresync+10) || time(NULL) > lastresync+60) ) { //printf("myutxos.%d most.%d %s\n",LP_mypeer->numutxos,mostutxos,mostpeer->ipaddr); LP_peer_utxosquery(LP_mypeer,myport,pubsock,mostpeer,now,60,(mostutxos-LP_mypeer->numutxos) * 2); lastresync = (uint32_t)time(NULL); //LP_peer_pricesquery(mostpeer->ipaddr,mostpeer->port); } - if ( (counter % 6000) == 10 ) + if ( enable_utxos && (counter % 6000) == 10 ) { LP_myutxo_updates(ctx,pubsock,passphrase); HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp) @@ -422,25 +422,35 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { int32_t height; bits256 zero; struct LP_address *ap,*atmp; struct LP_address_utxo *up,*utmp; //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); - if ( coin->inactive != 0 || coin->electrum != 0 ) + if ( coin->inactive != 0 ) continue; if ( time(NULL) > coin->lastmonitor+60 ) { portable_mutex_lock(&coin->txmutex); HASH_ITER(hh,coin->addresses,ap,atmp) { - DL_FOREACH_SAFE(ap->utxos,up,utmp) + if ( coin->electrum == 0 ) { - if ( up->spendheight <= 0 ) + DL_FOREACH_SAFE(ap->utxos,up,utmp) { - if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) - up->spendheight = 1; + if ( up->spendheight <= 0 ) + { + if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) + up->spendheight = 1; + } } } + else + { + if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,ap->coinaddr)) != 0 ) + free_json(retjson); + } } portable_mutex_unlock(&coin->txmutex); coin->lastmonitor = (uint32_t)time(NULL); } + if ( coin->electrum != 0 ) + continue; memset(zero.bytes,0,sizeof(zero)); if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { @@ -450,16 +460,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->firstrefht != 0 ) printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); } else LP_mempoolscan(coin->symbol,zero); - /*if ( (obj= LP_getinfo(coin->symbol)) != 0 ) - { - if ( (height= jint(obj,"blocks")) > coin->longestchain ) - { - coin->longestchain = height; - if ( coin->firstrefht != 0 ) - printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); - } else LP_mempoolscan(coin->symbol,zero); - free_json(obj); - } else printf("error getting info.%s\n",coin->symbol);*/ coin->lastgetinfo = (uint32_t)time(NULL); } if ( coin->firstrefht == 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index b8926cf4d..e47c2768e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -87,6 +87,15 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) return(ap); } +struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr) +{ + struct LP_address *ap; + portable_mutex_lock(&coin->txmutex); + ap = _LP_addressfind(coin,coinaddr); + portable_mutex_unlock(&coin->txmutex); + return(ap); +} + void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag; @@ -145,19 +154,88 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum { cJSON *array; struct LP_address *ap; struct LP_address_utxo *up,*tmp; array = cJSON_CreateArray(); - portable_mutex_lock(&coin->txmutex); - if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) + if ( coinaddr != 0 && coinaddr[0] != 0 ) { - DL_FOREACH_SAFE(ap->utxos,up,tmp) + portable_mutex_lock(&coin->txmutex); + if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) { - if ( up->spendheight <= 0 ) - jaddi(array,LP_address_item(coin,up,electrumret)); + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( up->spendheight <= 0 ) + jaddi(array,LP_address_item(coin,up,electrumret)); + } } + portable_mutex_unlock(&coin->txmutex); } - portable_mutex_unlock(&coin->txmutex); return(array); } +void LP_postutxos(int32_t pubsock,char *symbol) +{ + bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); + if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) + { + if ( cJSON_GetArraySize(array) == 0 ) + free_json(array); + else + { + memset(zero.bytes,0,sizeof(zero)); + jaddstr(reqjson,"method","postutxos"); + jaddstr(reqjson,"coin",symbol); + jaddstr(reqjson,"coinaddr",coin->smartaddr); + jadd(reqjson,"utxos",array); + msg = jprint(reqjson,1); + printf("post (%s)\n",msg); + LP_broadcast_message(pubsock,symbol,symbol,zero,msg); + } + } +} + +char *LP_postedutxos(cJSON *argjson) +{ + int32_t i,n,v,ht,errs,height; uint64_t value,val; cJSON *array,*item,*txobj; bits256 txid; char str[65],*symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; + if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig + { + printf("posted.(%s)\n",jprint(argjson,0)); + if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) + { + if ( (array= jarray(&n,argjson,"utxos")) != 0 ) + { + for (i=0; ielectrum == 0 && (txobj= LP_gettxout(symbol,txid,v)) != 0 ) + { + value = LP_value_extract(txobj,0); + if ( value != val ) + { + printf("%s %s/v%d value.%llu vs %llu\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val); + errs++; + } + ht = coin->height - jint(txobj,"confirmations"); + if ( ht != height ) + { + printf("%s %s/v%d ht.%d vs %d\n",symbol,bits256_str(str,txid),v,ht,height); + errs++; + } + free_json(txobj); + } + if ( errs == 0 ) + LP_address_utxoadd(coin,coinaddr,txid,v,val,height,-1); + } + } + } + else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr)) != 0 ) + free_json(array); + } + return(clonestr("{\"result\":\"success\"}")); +} + /*void LP_address_monitor(struct LP_pubkeyinfo *pubp) { struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 01843bd29..124e813d4 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -249,6 +249,7 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo) char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t lastn) { int32_t i,n,m; uint64_t val,val2; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo,*tmp; cJSON *utxosjson = cJSON_CreateArray(); + printf("deprecated! LP_utxos\n"); //n = mypeer != 0 ? mypeer->numutxos : 0; if ( lastn <= 0 ) lastn = LP_PROPAGATION_SLACK * 2; @@ -365,32 +366,12 @@ char *LP_spentcheck(cJSON *argjson) void LP_utxo_clientpublish(struct LP_utxoinfo *utxo) { bits256 zero; char *msg; - if ( LP_isunspent(utxo) > 0 ) + if ( 0 && LP_isunspent(utxo) > 0 ) { memset(zero.bytes,0,sizeof(zero)); msg = jprint(LP_utxojson(utxo),1); LP_broadcast_message(LP_mypubsock,utxo->coin,"",zero,msg); } - /*struct LP_peerinfo *peer,*tmp; cJSON *retjson; char *retstr; int32_t n = 0; - HASH_ITER(hh,LP_peerinfos,peer,tmp) - { - if ( (retstr= issue_LP_notifyutxo(peer->ipaddr,peer->port,utxo)) != 0 ) - { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( jobj(retjson,"error") == 0 ) - { - utxo->T.lasttime = (uint32_t)time(NULL); - n++; - } - free_json(retjson); - } - free(retstr); - } - //if ( utxo->T.lasttime != 0 ) - // return(0); - } - return(n);*/ } struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *spendscript,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) @@ -419,27 +400,6 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit printf("trying to add Alice utxo when not mine? %s/v%d\n",bits256_str(str,txid),vout); return(0); } - /*numconfirms = -1; - if ( (txobj= LP_gettx(symbol,txid)) != 0 ) - { - if ( coin->electrum == 0 ) - numconfirms = jint(txobj,"confirmations"); - else numconfirms = coin->height - jint(txobj,"height"); - free_json(txobj); - } - numconfirms = -1; - if ( (txobj= LP_gettx(symbol,txid2)) != 0 ) - { - if ( coin->electrum == 0 ) - numconfirms = jint(txobj,"confirmations"); - else numconfirms = coin->height - jint(txobj,"height"); - free_json(txobj); - } - if ( numconfirms <= 0 ) - { - printf("LP_utxoadd reject2 numconfirms.%d\n",numconfirms); - return(0); - }*/ if ( coin->inactive == 0 ) { if ( LP_iseligible(&val,&val2,iambob,symbol,txid,vout,tmpsatoshis,txid2,vout2) <= 0 ) @@ -612,6 +572,8 @@ int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t n int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,int32_t maxentries) { char *retstr; struct LP_peerinfo *peer; uint32_t now; int32_t retval = -1; + printf("deprecated LP_utxosquery\n"); + return(-1); peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); if ( coin == 0 ) coin = ""; @@ -841,6 +803,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr } } free_json(array); + LP_postutxos(mypubsock,coin->symbol); } //printf("privkey.%s %.8f\n",symbol,dstr(total)); return(total); From abab098a254e8538aa31d6eb880c9a61bbf81356 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 13:44:56 +0200 Subject: [PATCH 015/520] Test --- iguana/exchanges/LP_commands.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 754dd6d3d..1f907a3b7 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -371,9 +371,11 @@ dividends(coin, height, )\n\ return(LP_utxos(1,LP_mypeer,jstr(argjson,"coin"),jint(argjson,"lastn"))); else if ( strcmp(method,"utxo") == 0 ) { - if ( LP_utxoaddjson(1,LP_mypubsock,argjson) != 0 ) - retstr = clonestr("{\"result\":\"success\",\"utxo\":\"received\"}"); - else retstr = clonestr("{\"result\":\"couldnt add utxo\"}"); + printf("deprecated utxo received\n"); + //if ( LP_utxoaddjson(1,LP_mypubsock,argjson) != 0 ) + // retstr = clonestr("{\"result\":\"success\",\"utxo\":\"received\"}"); + //else + retstr = clonestr("{\"result\":\"couldnt add utxo\"}"); } else { From a829b2006b747939f59d61e7c61f447f0fde083f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 13:51:47 +0200 Subject: [PATCH 016/520] Test --- iguana/exchanges/LP_rpc.c | 6 ++++++ iguana/exchanges/LP_utxos.c | 18 ------------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 7d23f6f0a..3add08caf 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -60,6 +60,8 @@ char *issue_LP_getpeers(char *destip,uint16_t destport,char *ipaddr,uint16_t por char *issue_LP_numutxos(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) { char url[512],*retstr; + printf("deprecated issue_LP_numutxos\n"); + return(0); sprintf(url,"http://%s:%u/api/stats/numutxos?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,ipaddr,port,numpeers,numutxos); retstr = LP_issue_curl("numutxos",destip,port,url); //printf("%s -> getpeers.(%s)\n",destip,retstr); @@ -69,6 +71,8 @@ char *issue_LP_numutxos(char *destip,uint16_t destport,char *ipaddr,uint16_t por char *issue_LP_getutxos(char *destip,uint16_t destport,char *coin,int32_t lastn,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) { char url[512]; + printf("deprecated issue_LP_getutxos\n"); + return(0); sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,coin,lastn,ipaddr,port,numpeers,numutxos); return(LP_issue_curl("getutxos",destip,destport,url)); //return(issue_curlt(url,LP_HTTP_TIMEOUT)); @@ -77,6 +81,8 @@ char *issue_LP_getutxos(char *destip,uint16_t destport,char *coin,int32_t lastn, char *issue_LP_clientgetutxos(char *destip,uint16_t destport,char *coin,int32_t lastn) { char url[512];//,*retstr; + printf("deprecated issue_LP_clientgetutxos\n"); + return(0); sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=127.0.0.1&port=0",destip,destport,coin,lastn); return(LP_issue_curl("clientgetutxos",destip,destport,url)); //retstr = issue_curlt(url,LP_HTTP_TIMEOUT); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 124e813d4..b15793ce5 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -587,24 +587,6 @@ int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipa retval = LP_utxosparse(destipaddr,destport,retstr,now); //printf("got.(%s)\n",retstr); free(retstr); - /*i = 0; - if ( lastn >= mypeer->numutxos ) - firsti = -1; - else firsti = (mypeer->numutxos - lastn); - HASH_ITER(hh,LP_utxoinfos,utxo,tmp) - { - if ( i++ < firsti ) - continue; - if ( utxo->lasttime != now && strcmp(utxo->ipaddr,"127.0.0.1") != 0 ) - { - char str[65]; printf("{%s:%u %s} ",utxo->ipaddr,utxo->port,bits256_str(str,utxo->txid)); - flag++; - if ( (retstr= issue_LP_notifyutxo(destipaddr,destport,utxo)) != 0 ) - free(retstr); - } - } - if ( flag != 0 ) - printf(" <- missing utxos\n");*/ } return(retval); } From dbad241c598ca89f3b493832d9c6d87e3646b826 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 13:53:11 +0200 Subject: [PATCH 017/520] Test --- iguana/exchanges/LP_commands.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 1f907a3b7..f3155e3f9 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -348,7 +348,11 @@ dividends(coin, height, )\n\ else if ( strcmp(method,"getcoins") == 0 ) return(jprint(LP_coinsjson(0),1)); else if ( strcmp(method,"numutxos") == 0 ) - return(LP_numutxos()); + { + printf("deprecated numutxos received\n"); + retstr = clonestr("{\"result\":\"couldnt add utxo\"}"); + //return(LP_numutxos()); + } else if ( strcmp(method,"postprice") == 0 ) retstr = LP_postedprice(argjson); else if ( strcmp(method,"postutxos") == 0 ) @@ -368,7 +372,11 @@ dividends(coin, height, )\n\ else if ( strcmp(method,"getpeers") == 0 ) return(LP_peers()); else if ( strcmp(method,"getutxos") == 0 ) - return(LP_utxos(1,LP_mypeer,jstr(argjson,"coin"),jint(argjson,"lastn"))); + { + printf("deprecated getutxos received\n"); + retstr = clonestr("{\"result\":\"couldnt add utxo\"}"); + //return(LP_utxos(1,LP_mypeer,jstr(argjson,"coin"),jint(argjson,"lastn"))); + } else if ( strcmp(method,"utxo") == 0 ) { printf("deprecated utxo received\n"); From 5fc8d634770ee69bd0de4975368d9030aab95076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 13:54:41 +0200 Subject: [PATCH 018/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e47c2768e..50ea4303e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -539,12 +539,12 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) { - value = SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest")); + value = LP_value_extract(txobj,0);//SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest")); if ( coinaddr == 0 ) coinaddr = _coinaddr; LP_destaddr(coinaddr,txobj); free_json(txobj); - printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); + //printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); return(value); } printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); From 3955dcc17bb2f07dbcc892acf9730a123af311dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:04:03 +0200 Subject: [PATCH 019/520] Test --- iguana/exchanges/LP_swap.c | 8 ++++---- iguana/exchanges/LP_utxo.c | 8 +++----- iguana/exchanges/LP_utxos.c | 4 ++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 5c024221c..bcfe946cd 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -731,7 +731,7 @@ void LP_bobloop(void *_swap) if ( strcmp(swap->alicecoin.symbol,"BTC") == 0 ) m = 0; else m = 1; - while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,1)) < m ) // sync with alice + while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice { char str[65];printf("%d waiting for alicepayment to be confirmed.%d %s %s\n",n,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(3); @@ -784,7 +784,7 @@ void LP_aliceloop(void *_swap) if ( strcmp(swap->alicecoin.symbol,"BTC") == 0 ) m = 0; else m = 1; - while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,1)) < m ) + while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) { char str[65];printf("%d waiting for alicepayment to be confirmed.%d %s %s\n",n,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); @@ -794,14 +794,14 @@ void LP_aliceloop(void *_swap) printf("error waiting for bobpayment\n"); else { - while ( (n= LP_numconfirms(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,1)) < swap->I.bobconfirms ) + while ( (n= LP_numconfirms(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) { char str[65];printf("%d waiting for bobpayment to be confirmed.%d %s %s\n",n,swap->I.bobconfirms,swap->bobcoin.symbol,bits256_str(str,swap->bobpayment.I.signedtxid)); sleep(LP_SWAPSTEP_TIMEOUT); } if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 ) printf("error sending alicespend\n"); - while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,1)) < swap->I.aliceconfirms ) + while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms ) { char str[65];printf("%d waiting for alicespend to be confirmed.%d %s %s\n",n,swap->I.aliceconfirms,swap->bobcoin.symbol,bits256_str(str,swap->alicespend.I.signedtxid)); sleep(LP_SWAPSTEP_TIMEOUT); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 50ea4303e..c4f4a992c 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -457,7 +457,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid) return(height); } -int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t mempool) +int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool) { struct iguana_info *coin; int32_t ht,numconfirms = 100; //#ifndef BASILISK_DISABLEWAITTX @@ -467,11 +467,9 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t mempool) if ( coin->electrum == 0 ) { numconfirms = -1; - if ( (txobj= LP_gettx(symbol,txid)) != 0 ) + if ( (txobj= LP_gettxout(symbol,txid,vout)) != 0 ) { - if ( coin->electrum == 0 ) - numconfirms = jint(txobj,"confirmations"); - else numconfirms = coin->height - jint(txobj,"height"); + numconfirms = jint(txobj,"confirmations"); free_json(txobj); } else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b15793ce5..c123b7303 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -407,12 +407,12 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f:%.8f, value2 %.8f:%.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(val),dstr(value2),dstr(val2),dstr(tmpsatoshis)); return(0); } - if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,0)) <= 0 ) + if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,0)) <= 0 ) { printf("LP_utxoadd reject numconfirms.%d %s.%s\n",numconfirms,symbol,bits256_str(str,txid)); return(0); } - if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,0)) <= 0 ) + if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,vout2,0)) <= 0 ) { printf("LP_utxoadd reject2 numconfirms.%d\n",numconfirms); return(0); From 910506b89a9f946cbb9a3717eb5f52d4194c830c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:19:04 +0200 Subject: [PATCH 020/520] Test --- iguana/exchanges/LP_commands.c | 4 +++- iguana/exchanges/LP_utxo.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index f3155e3f9..9b016a4ef 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -379,7 +379,9 @@ dividends(coin, height, )\n\ } else if ( strcmp(method,"utxo") == 0 ) { - printf("deprecated utxo received\n"); + static uint32_t counter; + if ( counter++ < 3 ) + printf("deprecated utxo received\n"); //if ( LP_utxoaddjson(1,LP_mypubsock,argjson) != 0 ) // retstr = clonestr("{\"result\":\"success\",\"utxo\":\"received\"}"); //else diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c4f4a992c..54981e51f 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -173,6 +173,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum void LP_postutxos(int32_t pubsock,char *symbol) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); + printf("LP_postutxos\n"); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { if ( cJSON_GetArraySize(array) == 0 ) From 80a7bb1613727595d854c0423d5f1297b23ec4e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:22:12 +0200 Subject: [PATCH 021/520] Test --- iguana/exchanges/LP_utxo.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 54981e51f..abf1a9bca 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -371,6 +371,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) else height = -1; vins = jarray(&numvins,txobj,"vin"); vouts = jarray(&numvouts,txobj,"vout"); + // maybe filter so only addresses we care about are using RAM if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); @@ -380,22 +381,6 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) tx->outpoints[i].value = LP_value_extract(vout,0); tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); LP_destaddr(tx->outpoints[i].coinaddr,vout); - /*if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) - { - if ( (addresses= jarray(&n,sobj,"addresses")) != 0 && n > 0 ) - { - if ( n > 1 ) - printf("LP_transactioninit: txid.(%s) multiple addresses.[%s]\n",bits256_str(str,txid),jprint(addresses,0)); - if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) ) - { - strcpy(tx->outpoints[i].coinaddr,address); - //printf("(%s %.8f) ",address,dstr(tx->outpoints[i].value)); - } else if ( tx->outpoints[i].value != 0 ) - printf("LP_transactioninit: unexpected address.(%s)\n",jprint(addresses,0)); - } - //else if ( tx->outpoints[i].value != 0 ) - // printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n); - }*/ } //printf("numvouts.%d\n",numvouts); } @@ -416,7 +401,8 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); - printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); + if ( strcmp(coin->symbol,"BTC") != 0 ) + printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); if ( bits256_cmp(spenttxid,txid) == 0 ) From 8298fe598250ea2cd7d5da38660ee9d65fa75fb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:27:57 +0200 Subject: [PATCH 022/520] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index abf1a9bca..06f28f819 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -124,6 +124,7 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int up->U.value = value; up->spendheight = spendheight; DL_APPEND(ap->utxos,up); + char str[65]; printf(">>>>>>>>>> %s %s/v%d ht.%d %.8f\n",coin->symbol,bits256_str(str,txid),vout,height,dstr(value)); } } portable_mutex_unlock(&coin->txmutex); @@ -173,7 +174,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum void LP_postutxos(int32_t pubsock,char *symbol) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); - printf("LP_postutxos\n"); + printf("LP_postutxos pubsock.%d %s\n",pubsock,symbol); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { if ( cJSON_GetArraySize(array) == 0 ) From a7d39411e812712c599d26f4cdcee291f22f9629 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:31:32 +0200 Subject: [PATCH 023/520] Test --- iguana/exchanges/LP_utxo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 06f28f819..b79a851c4 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -124,7 +124,9 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int up->U.value = value; up->spendheight = spendheight; DL_APPEND(ap->utxos,up); - char str[65]; printf(">>>>>>>>>> %s %s/v%d ht.%d %.8f\n",coin->symbol,bits256_str(str,txid),vout,height,dstr(value)); + char str[65]; + if ( height > 0 ) + printf(">>>>>>>>>> %s %s/v%d ht.%d %.8f\n",coin->symbol,bits256_str(str,txid),vout,height,dstr(value)); } } portable_mutex_unlock(&coin->txmutex); From 71b9e3f3f3e4990c65e02f4dba0960321d6110d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:33:14 +0200 Subject: [PATCH 024/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index b79a851c4..3d3429703 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -126,7 +126,7 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int DL_APPEND(ap->utxos,up); char str[65]; if ( height > 0 ) - printf(">>>>>>>>>> %s %s/v%d ht.%d %.8f\n",coin->symbol,bits256_str(str,txid),vout,height,dstr(value)); + printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } portable_mutex_unlock(&coin->txmutex); @@ -176,9 +176,9 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum void LP_postutxos(int32_t pubsock,char *symbol) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); - printf("LP_postutxos pubsock.%d %s\n",pubsock,symbol); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { + printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr); if ( cJSON_GetArraySize(array) == 0 ) free_json(array); else From 588f0dd2a41a511e7fc110caa26ec3ce93a3cb52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:35:52 +0200 Subject: [PATCH 025/520] Test --- iguana/exchanges/LP_utxo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 3d3429703..71668b3d9 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -170,6 +170,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum } portable_mutex_unlock(&coin->txmutex); } + printf("%s %s utxos.(%s)\n",coin->symbol,coinaddr,jprint(array,0)); return(array); } From 05853e58228c3073a532b8eb581659853c499086 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:40:22 +0200 Subject: [PATCH 026/520] Test --- iguana/exchanges/LP_utxo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 71668b3d9..ddf85de98 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -155,7 +155,7 @@ cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32 cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret) { - cJSON *array; struct LP_address *ap; struct LP_address_utxo *up,*tmp; + cJSON *array; struct LP_address *ap=0; struct LP_address_utxo *up,*tmp; array = cJSON_CreateArray(); if ( coinaddr != 0 && coinaddr[0] != 0 ) { @@ -164,13 +164,14 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum { DL_FOREACH_SAFE(ap->utxos,up,tmp) { + char str[65]; printf("%s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->height,up->spendheight); if ( up->spendheight <= 0 ) jaddi(array,LP_address_item(coin,up,electrumret)); } } portable_mutex_unlock(&coin->txmutex); } - printf("%s %s utxos.(%s)\n",coin->symbol,coinaddr,jprint(array,0)); + printf("%s %s utxos.(%s) ap.%p\n",coin->symbol,coinaddr,jprint(array,0),ap); return(array); } From e0b2d43a2daf11379429043e460a5d60d6f7c5bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:49:38 +0200 Subject: [PATCH 027/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_utxo.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index b623c71a2..e80e60318 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -219,7 +219,7 @@ struct LP_address_utxo { struct LP_address_utxo *next,*prev; struct _LP_utxoinfo U; - uint32_t height,SPV,spendheight; + uint32_t SPV,spendheight; }; struct LP_address diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ddf85de98..1f0cfcfda 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -164,9 +164,12 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum { DL_FOREACH_SAFE(ap->utxos,up,tmp) { - char str[65]; printf("%s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->height,up->spendheight); + char str[65]; printf("LP_address_utxos %s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->U.height,up->spendheight); if ( up->spendheight <= 0 ) + { jaddi(array,LP_address_item(coin,up,electrumret)); + printf("new array %s\n",jprint(array,0)); + } } } portable_mutex_unlock(&coin->txmutex); From 44e914d4fcace954b6ad2f41167516b04722d9fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 14:53:04 +0200 Subject: [PATCH 028/520] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index e80e60318..4f150531a 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -219,7 +219,7 @@ struct LP_address_utxo { struct LP_address_utxo *next,*prev; struct _LP_utxoinfo U; - uint32_t SPV,spendheight; + int32_t SPV,spendheight; }; struct LP_address From 063c997045bcbedbae38b8d942e3a96d8e22167f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:01:02 +0200 Subject: [PATCH 029/520] Test --- iguana/exchanges/LP_utxo.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1f0cfcfda..2bace101c 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -124,9 +124,9 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int up->U.value = value; up->spendheight = spendheight; DL_APPEND(ap->utxos,up); - char str[65]; - if ( height > 0 ) - printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); + //char str[65]; + //if ( height > 0 ) + // printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } portable_mutex_unlock(&coin->txmutex); @@ -164,17 +164,17 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum { DL_FOREACH_SAFE(ap->utxos,up,tmp) { - char str[65]; printf("LP_address_utxos %s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->U.height,up->spendheight); + //char str[65]; printf("LP_address_utxos %s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->U.height,up->spendheight); if ( up->spendheight <= 0 ) { jaddi(array,LP_address_item(coin,up,electrumret)); - printf("new array %s\n",jprint(array,0)); + //printf("new array %s\n",jprint(array,0)); } } } portable_mutex_unlock(&coin->txmutex); } - printf("%s %s utxos.(%s) ap.%p\n",coin->symbol,coinaddr,jprint(array,0),ap); + //printf("%s %s utxos.(%s) ap.%p\n",coin->symbol,coinaddr,jprint(array,0),ap); return(array); } @@ -183,7 +183,7 @@ void LP_postutxos(int32_t pubsock,char *symbol) bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { - printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr); + //printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr); if ( cJSON_GetArraySize(array) == 0 ) free_json(array); else From e56abd45628e9903d949157ffd1f14adb0a80588 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:11:05 +0200 Subject: [PATCH 030/520] Test --- iguana/exchanges/LP_include.h | 3 ++- iguana/exchanges/LP_socket.c | 16 +++++++++------- iguana/exchanges/LP_utxo.c | 6 ++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 4f150531a..6e9dffa92 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -302,8 +302,9 @@ struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid) int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); -void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); +int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); +void LP_postutxos(int32_t pubsock,char *symbol); #endif diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index f92fb7bb0..9d825da63 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -304,9 +304,9 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) return(ep); } -void electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *array) +int32_t electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *array) { - int32_t i,v,n; char str[65]; uint64_t value; bits256 txid; cJSON *item; struct LP_transaction *tx; + int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; i>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); tx->outpoints[v].value = value; - LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); + flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); } } printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); } } } + return(flag); } cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *method,char *params,int32_t timeout) @@ -452,7 +453,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON * { cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT); - printf("MEMPOOL.(%s)\n",jprint(retjson,0)); + //printf("MEMPOOL.(%s)\n",jprint(retjson,0)); electrum_process_array(coin,addr,retjson); return(retjson); } @@ -465,8 +466,9 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); - electrum_process_array(coin,addr,retjson); + //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + if ( electrum_process_array(coin,addr,retjson) != 0 ) + LP_postutxos(LP_mypubsock,coin->symbol); strcpy(coin->lastunspent,addr); coin->unspenttime = (uint32_t)time(NULL); } @@ -614,7 +616,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - printf("strjson.(%s)\n",jprint(strjson,0)); + //printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 2bace101c..a9acf863e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -96,9 +96,9 @@ struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr) return(ap); } -void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) +int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { - struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag; + struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; portable_mutex_lock(&coin->txmutex); if ( (ap= _LP_address(coin,coinaddr)) != 0 ) { @@ -124,12 +124,14 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int up->U.value = value; up->spendheight = spendheight; DL_APPEND(ap->utxos,up); + retval = 1; //char str[65]; //if ( height > 0 ) // printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } portable_mutex_unlock(&coin->txmutex); + return(retval); } cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32_t electrumret) From f9f2252b141f62a052f2faa14755aec4e83179d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:18:20 +0200 Subject: [PATCH 031/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9b016a4ef..8e81a5a5e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -356,7 +356,7 @@ dividends(coin, height, )\n\ else if ( strcmp(method,"postprice") == 0 ) retstr = LP_postedprice(argjson); else if ( strcmp(method,"postutxos") == 0 ) - retstr = LP_postedutxos(argjson); + return(LP_postedutxos(argjson)); else if ( strcmp(method,"encrypted") == 0 ) retstr = clonestr("{\"result\":\"success\"}"); else if ( strcmp(method,"getprices") == 0 ) From 4f89f224f0c74d73bd5f3b72113b971c14bad0f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:31:26 +0200 Subject: [PATCH 032/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 6 +++--- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fb492573f..a81626a0b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -51,6 +51,7 @@ uint16_t LP_fixed_pairport,LP_publicport; int32_t LP_mybussock = -1; int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; +int32_t LP_mypushsock = -1; int32_t LP_pendingswaps,LP_showwif,USERPASS_COUNTER,IAMLP = 0; uint32_t LP_sessionid; double LP_profitratio = 1.; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index aadc2f485..7686d816d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -311,7 +311,7 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25 jdelete(argjson,"method2"); jaddstr(argjson,"method2",method); jaddstr(argjson,"method",method); - //printf("CRC32.%u (%s)\n",crc32,(char *)msg); + printf("CRC32.%u (%s)\n",crc32,(char *)msg); LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); } // else printf("no valid method in (%s)\n",msgstr); free_json(argjson); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 9d825da63..d92fc720a 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -468,7 +468,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) - LP_postutxos(LP_mypubsock,coin->symbol); + LP_postutxos(LP_mypushsock,coin->symbol); strcpy(coin->lastunspent,addr); coin->unspenttime = (uint32_t)time(NULL); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a9acf863e..543167a4b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -180,7 +180,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum return(array); } -void LP_postutxos(int32_t pubsock,char *symbol) +void LP_postutxos(int32_t sock,char *symbol) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) @@ -196,8 +196,8 @@ void LP_postutxos(int32_t pubsock,char *symbol) jaddstr(reqjson,"coinaddr",coin->smartaddr); jadd(reqjson,"utxos",array); msg = jprint(reqjson,1); - printf("post (%s)\n",msg); - LP_broadcast_message(pubsock,symbol,symbol,zero,msg); + printf("post (%s) -> %d\n",msg,LP_mypubsock); + LP_broadcast_message(LP_mypubsock,symbol,symbol,zero,msg); } } } From d2e4a8eb732dafb8b7d5e87813a86c15debbbd1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:40:52 +0200 Subject: [PATCH 033/520] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 543167a4b..864586544 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -191,7 +191,8 @@ void LP_postutxos(int32_t sock,char *symbol) else { memset(zero.bytes,0,sizeof(zero)); - jaddstr(reqjson,"method","postutxos"); + jaddstr(reqjson,"method","sendmessage"); + jaddstr(reqjson,"method2","postutxos"); jaddstr(reqjson,"coin",symbol); jaddstr(reqjson,"coinaddr",coin->smartaddr); jadd(reqjson,"utxos",array); From b93fcaeefcd1dfedb25056d84f0203774cc57a1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:46:27 +0200 Subject: [PATCH 034/520] Test --- iguana/exchanges/LP_utxo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 864586544..543167a4b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -191,8 +191,7 @@ void LP_postutxos(int32_t sock,char *symbol) else { memset(zero.bytes,0,sizeof(zero)); - jaddstr(reqjson,"method","sendmessage"); - jaddstr(reqjson,"method2","postutxos"); + jaddstr(reqjson,"method","postutxos"); jaddstr(reqjson,"coin",symbol); jaddstr(reqjson,"coinaddr",coin->smartaddr); jadd(reqjson,"utxos",array); From 46893adbc367bb569e03c5d0140de298cf0a7d65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:51:30 +0200 Subject: [PATCH 035/520] Test --- iguana/exchanges/LP_commands.c | 3 ++- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 8e81a5a5e..c0840b6c9 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -356,7 +356,7 @@ dividends(coin, height, )\n\ else if ( strcmp(method,"postprice") == 0 ) retstr = LP_postedprice(argjson); else if ( strcmp(method,"postutxos") == 0 ) - return(LP_postedutxos(argjson)); + retstr = LP_postedutxos(argjson); else if ( strcmp(method,"encrypted") == 0 ) retstr = clonestr("{\"result\":\"success\"}"); else if ( strcmp(method,"getprices") == 0 ) @@ -425,6 +425,7 @@ dividends(coin, height, )\n\ else { memset(zero.bytes,0,sizeof(zero)); + printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 543167a4b..7368580e6 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -205,9 +205,9 @@ void LP_postutxos(int32_t sock,char *symbol) char *LP_postedutxos(cJSON *argjson) { int32_t i,n,v,ht,errs,height; uint64_t value,val; cJSON *array,*item,*txobj; bits256 txid; char str[65],*symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; + printf("posted.(%s)\n",jprint(argjson,0)); if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig { - printf("posted.(%s)\n",jprint(argjson,0)); if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (array= jarray(&n,argjson,"utxos")) != 0 ) From c8b8ce05463546c6acf3011ba64883ab1ed9b5d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 15:57:27 +0200 Subject: [PATCH 036/520] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 7686d816d..aadc2f485 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -311,7 +311,7 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25 jdelete(argjson,"method2"); jaddstr(argjson,"method2",method); jaddstr(argjson,"method",method); - printf("CRC32.%u (%s)\n",crc32,(char *)msg); + //printf("CRC32.%u (%s)\n",crc32,(char *)msg); LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); } // else printf("no valid method in (%s)\n",msgstr); free_json(argjson); From 73e4b247bab25b74971403a03bae22f518d09f8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 16:00:00 +0200 Subject: [PATCH 037/520] Test --- iguana/exchanges/LP_commands.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c0840b6c9..f6e8ea920 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -361,6 +361,12 @@ dividends(coin, height, )\n\ retstr = clonestr("{\"result\":\"success\"}"); else if ( strcmp(method,"getprices") == 0 ) return(LP_prices()); + else if ( strcmp(method,"listunspent") == 0 ) + { + if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) + return(jprint(LP_address_utxos(ptr,jstr(argjson,"address"),1),1)); + else return(clonestr("{\"error\":\"cant find coind\"}")); + } else if ( strcmp(method,"orderbook") == 0 ) return(LP_orderbook(base,rel,jint(argjson,"duration"))); else if ( strcmp(method,"registerall") == 0 ) @@ -402,12 +408,6 @@ dividends(coin, height, )\n\ return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); else if ( strcmp(method,"lookup") == 0 ) return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); - else if ( strcmp(method,"listunspent") == 0 ) - { - if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) - return(jprint(LP_address_utxos(ptr,jstr(argjson,"address"),1),1)); - else return(clonestr("{\"error\":\"cant find coind\"}")); - } if ( strcmp(method,"broadcast") == 0 ) { bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; From f798253eb0c85803b5c5ad616ca51471907309e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 16:00:30 +0200 Subject: [PATCH 038/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index f6e8ea920..d96ccf52e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -425,7 +425,7 @@ dividends(coin, height, )\n\ else { memset(zero.bytes,0,sizeof(zero)); - printf("broadcast.(%s)\n",jprint(reqjson,0)); + //printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); From ce95a2067380f0d35b0a35dea802e0ce76d3da08 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 16:07:51 +0200 Subject: [PATCH 039/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 24 +++++++++++++----------- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- iguana/exchanges/LP_utxos.c | 18 ++++++++++++------ 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 6e9dffa92..50117b1b8 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -304,7 +304,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); -void LP_postutxos(int32_t pubsock,char *symbol); +void LP_postutxos(char *symbol); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a81626a0b..12fdbf2b0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -51,7 +51,6 @@ uint16_t LP_fixed_pairport,LP_publicport; int32_t LP_mybussock = -1; int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; -int32_t LP_mypushsock = -1; int32_t LP_pendingswaps,LP_showwif,USERPASS_COUNTER,IAMLP = 0; uint32_t LP_sessionid; double LP_profitratio = 1.; @@ -402,20 +401,23 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int lastresync = (uint32_t)time(NULL); //LP_peer_pricesquery(mostpeer->ipaddr,mostpeer->port); } - if ( enable_utxos && (counter % 6000) == 10 ) + if ( (counter % 6000) == 10 ) { LP_myutxo_updates(ctx,pubsock,passphrase); - HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp) + if ( enable_utxos ) { - LP_utxo_spentcheck(pubsock,utxo); - } - HASH_ITER(hh,LP_utxoinfos[1],utxo,utmp) - { - LP_utxo_spentcheck(pubsock,utxo); - if ( LP_isunspent(utxo) > 0 && utxo->T.lasttime == 0 && LP_ismine(utxo) > 0 ) + HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp) + { + LP_utxo_spentcheck(pubsock,utxo); + } + HASH_ITER(hh,LP_utxoinfos[1],utxo,utmp) { - char str[65]; printf("publish mybob %s\n",bits256_str(str,utxo->payment.txid)); - LP_utxo_clientpublish(utxo); + LP_utxo_spentcheck(pubsock,utxo); + if ( LP_isunspent(utxo) > 0 && utxo->T.lasttime == 0 && LP_ismine(utxo) > 0 ) + { + char str[65]; printf("publish mybob %s\n",bits256_str(str,utxo->payment.txid)); + LP_utxo_clientpublish(utxo); + } } } } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index d92fc720a..a0d875503 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -468,7 +468,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) - LP_postutxos(LP_mypushsock,coin->symbol); + LP_postutxos(coin->symbol); strcpy(coin->lastunspent,addr); coin->unspenttime = (uint32_t)time(NULL); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 7368580e6..bfe7fa206 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -180,7 +180,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum return(array); } -void LP_postutxos(int32_t sock,char *symbol) +void LP_postutxos(char *symbol) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c123b7303..1989b3f94 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -652,9 +652,10 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe return(mini); } -uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) +int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { - char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; + int32_t enable_utxos = 0; + char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; if ( coin == 0 ) { printf("coin not active\n"); @@ -696,9 +697,11 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); + flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } + if ( enable_utxos == 0 ) + continue; //printf("array.%d\n",n); while ( used < n-1 ) { @@ -785,10 +788,10 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr } } free_json(array); - LP_postutxos(mypubsock,coin->symbol); + LP_postutxos(coin->symbol); } //printf("privkey.%s %.8f\n",symbol,dstr(total)); - return(total); + return(flag); } char *LP_secretaddresses(void *ctx,char *passphrase,int32_t n,uint8_t taddr,uint8_t pubtype) @@ -904,7 +907,10 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t inito if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); if ( coin->inactive == 0 && initonly == 0 ) - LP_privkey_init(pubsock,coin,privkey,pubkey); + { + if ( LP_privkey_init(pubsock,coin,privkey,pubkey) > 0 ) + LP_postutxos(coin->symbol); + } } } From 7863f8c55b2b91666bed32de606c585a323b5ca8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 16:46:19 +0200 Subject: [PATCH 040/520] Test --- iguana/exchanges/LP_commands.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d96ccf52e..3ad0e7473 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -113,8 +113,7 @@ getcoins()\n\ getcoin(coin)\n\ portfolio()\n\ getpeers()\n\ -getutxos()\n\ -getutxos(coin, lastn)\n\ +listunspent(coin, address)\n\ orderbook(base, rel, duration=3600)\n\ getprices(base, rel)\n\ sendmessage(base=coin, rel="", pubkey=zero, )\n\ From d593091d824fbef2bbeafda1632b7ea6c435d36c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 16:52:30 +0200 Subject: [PATCH 041/520] Test --- iguana/exchanges/LP_utxos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 1989b3f94..369823855 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -700,8 +700,6 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } - if ( enable_utxos == 0 ) - continue; //printf("array.%d\n",n); while ( used < n-1 ) { @@ -785,6 +783,8 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } if ( iambob == 1 ) free(values); + if ( enable_utxos == 0 ) + break; } } free_json(array); From 917d48ce6aa504d4350ec6f550577de8559aee84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 22:11:51 +0200 Subject: [PATCH 042/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 369823855..b5846edc7 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -788,7 +788,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } } free_json(array); - LP_postutxos(coin->symbol); + //LP_postutxos(coin->symbol); } //printf("privkey.%s %.8f\n",symbol,dstr(total)); return(flag); From 5f131801c0ad2ac336298d67a7ca6c593f4e85d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 22:24:15 +0200 Subject: [PATCH 043/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b5846edc7..0b6deaa0d 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -665,7 +665,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) { txfee = LP_txfeecalc(coin,0); - if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) + if ( 0 && is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { for (iambob=0; iambob<=1; iambob++) { From 2637fcf122f353d499629311dddbe692691668a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 22:26:53 +0200 Subject: [PATCH 044/520] Test --- iguana/exchanges/LP_utxos.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0b6deaa0d..ad4cdfee2 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -665,7 +665,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) { txfee = LP_txfeecalc(coin,0); - if ( 0 && is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) + if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { for (iambob=0; iambob<=1; iambob++) { @@ -701,7 +701,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } else used++; } //printf("array.%d\n",n); - while ( used < n-1 ) + while ( 0 && used < n-1 ) { //for (i=0; isymbol); + if ( flag != 0 ) + LP_postutxos(coin->symbol); } //printf("privkey.%s %.8f\n",symbol,dstr(total)); return(flag); From c2d15a3c71c29500e851c7737b83634ef444fd75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 22:49:43 +0200 Subject: [PATCH 045/520] Test --- iguana/exchanges/LP_utxos.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index ad4cdfee2..8d0d99753 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -697,11 +697,11 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); + //flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } //printf("array.%d\n",n); - while ( 0 && used < n-1 ) + while ( used < n-1 ) { //for (i=0; i Date: Sat, 16 Sep 2017 23:16:37 +0200 Subject: [PATCH 046/520] test --- iguana/exchanges/LP_utxo.c | 12 +++++++----- iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index bfe7fa206..da4b15b63 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -99,7 +99,7 @@ struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr) int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; - portable_mutex_lock(&coin->txmutex); + printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); if ( (ap= _LP_address(coin,coinaddr)) != 0 ) { flag = 0; @@ -123,14 +123,16 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, up->U.height = height; up->U.value = value; up->spendheight = spendheight; + portable_mutex_lock(&coin->txmutex); DL_APPEND(ap->utxos,up); + portable_mutex_unlock(&coin->txmutex); retval = 1; - //char str[65]; - //if ( height > 0 ) - // printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); + char str[65]; + if ( height > 0 ) + printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } - portable_mutex_unlock(&coin->txmutex); + printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); return(retval); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 8d0d99753..ccb18e6b1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -697,7 +697,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - //flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); + flag += LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,height,-1); } else used++; } //printf("array.%d\n",n); From d362561a33cbeff29692f3d67d9f4c64fe13cd13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:20:59 +0200 Subject: [PATCH 047/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3ad0e7473..17293f33c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -//printf("stats_JSON(%s)\n",jprint(argjson,0)); +printf("stats_JSON(%s)\n",jprint(argjson,0)); if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) From c56e4d2913d6be769334b4bd09f59abeefa26120 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:29:54 +0200 Subject: [PATCH 048/520] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index aadc2f485..4f84b0dab 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -232,17 +232,16 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 peerind = 1; sock0 = LP_peerindsock(&peerind); } - portable_mutex_lock(&LP_networkmutex); if ( sock0 >= 0 ) _LP_sendqueueadd(crc32,sock0,msg,msglen,needack * peerind); if ( sock1 >= 0 ) _LP_sendqueueadd(crc32,sock1,msg,msglen,needack); - portable_mutex_unlock(&LP_networkmutex); } void LP_queuesend(uint32_t crc32,int32_t pubsock,char *base,char *rel,uint8_t *msg,int32_t msglen) { //struct iguana_info *coin; int32_t flag=0,socks[2]; + portable_mutex_lock(&LP_networkmutex); if ( pubsock >= 0 ) { //socks[0] = socks[1] = -1; @@ -254,6 +253,7 @@ void LP_queuesend(uint32_t crc32,int32_t pubsock,char *base,char *rel,uint8_t *m _LP_queuesend(crc32,pubsock,-1,msg,msglen,0); //else _LP_queuesend(socks[0],socks[1],msg,msglen,0); } else _LP_queuesend(crc32,-1,-1,msg,msglen,1); + portable_mutex_unlock(&LP_networkmutex); } // first 2 bytes == (crc32 & 0xffff) if encrypted, then nonce is next crypto_box_NONCEBYTES From 415351f36c9b518d01cdeae7a8d9f67cd3f01dad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:33:39 +0200 Subject: [PATCH 049/520] Test --- iguana/exchanges/LP_coins.c | 1 + iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_scan.c | 2 ++ iguana/exchanges/LP_utxo.c | 20 ++++++++++---------- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index be84416ad..6f0b1d76d 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -243,6 +243,7 @@ struct iguana_info *LP_coinadd(struct iguana_info *cdata) //printf("%s: (%s) (%s)\n",symbol,cdata.serverport,cdata.userpass); *coin = *cdata; portable_mutex_init(&coin->txmutex); + portable_mutex_init(&coin->addrmutex); portable_mutex_lock(&LP_coinmutex); HASH_ADD_KEYPTR(hh,LP_coins,coin->symbol,strlen(coin->symbol),coin); portable_mutex_unlock(&LP_coinmutex); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 50117b1b8..fe016e027 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -179,7 +179,7 @@ struct LP_transaction struct iguana_info { UT_hash_handle hh; - portable_mutex_t txmutex; struct LP_transaction *transactions; struct LP_address *addresses; + portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; uint32_t counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 12fdbf2b0..da09bfff5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -429,7 +429,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; if ( time(NULL) > coin->lastmonitor+60 ) { - portable_mutex_lock(&coin->txmutex); + portable_mutex_lock(&coin->addrmutex); HASH_ITER(hh,coin->addresses,ap,atmp) { if ( coin->electrum == 0 ) @@ -449,7 +449,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free_json(retjson); } } - portable_mutex_unlock(&coin->txmutex); + portable_mutex_unlock(&coin->addrmutex); coin->lastmonitor = (uint32_t)time(NULL); } if ( coin->electrum != 0 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index ddd95f458..5f0b4175b 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -184,6 +184,7 @@ cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) } } portable_mutex_lock(&coin->txmutex); + portable_mutex_lock(&coin->addrmutex); HASH_ITER(hh,coin->addresses,ap,atmp) { ap->balance = 0; @@ -220,6 +221,7 @@ cJSON *LP_snapshot(struct iguana_info *coin,int32_t height) } } HASH_SORT(coin->addresses,sort_balance); + portable_mutex_unlock(&coin->addrmutex); portable_mutex_unlock(&coin->txmutex); printf("%s balance %.8f at height.%d\n",coin->symbol,dstr(balance),height); array = cJSON_CreateArray(); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index da4b15b63..23486304a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -90,16 +90,16 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr) { struct LP_address *ap; - portable_mutex_lock(&coin->txmutex); + portable_mutex_lock(&coin->addrmutex); ap = _LP_addressfind(coin,coinaddr); - portable_mutex_unlock(&coin->txmutex); + portable_mutex_unlock(&coin->addrmutex); return(ap); } int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; - printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); + //printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); if ( (ap= _LP_address(coin,coinaddr)) != 0 ) { flag = 0; @@ -123,16 +123,16 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, up->U.height = height; up->U.value = value; up->spendheight = spendheight; - portable_mutex_lock(&coin->txmutex); + portable_mutex_lock(&coin->addrmutex); DL_APPEND(ap->utxos,up); - portable_mutex_unlock(&coin->txmutex); + portable_mutex_unlock(&coin->addrmutex); retval = 1; char str[65]; if ( height > 0 ) printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } - printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); + //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); return(retval); } @@ -163,7 +163,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum array = cJSON_CreateArray(); if ( coinaddr != 0 && coinaddr[0] != 0 ) { - portable_mutex_lock(&coin->txmutex); + portable_mutex_lock(&coin->addrmutex); if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) { DL_FOREACH_SAFE(ap->utxos,up,tmp) @@ -176,7 +176,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum } } } - portable_mutex_unlock(&coin->txmutex); + portable_mutex_unlock(&coin->addrmutex); } //printf("%s %s utxos.(%s) ap.%p\n",coin->symbol,coinaddr,jprint(array,0),ap); return(array); @@ -256,12 +256,12 @@ char *LP_postedutxos(cJSON *argjson) HASH_ITER(hh,LP_coins,coin,tmp) { bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - portable_mutex_lock(&coin->txmutex); + portable_mutex_lock(&coin->addrmutex); if ( (ap= _LP_address(coin,coinaddr)) != 0 ) { ap->monitor = (uint32_t)time(NULL); } - portable_mutex_unlock(&coin->txmutex); + portable_mutex_unlock(&coin->addrmutex); if ( coin->electrum != 0 ) { if ( (retjson= electrum_address_subscribe(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 ) From 3a0d70cdd260a92cec8e9c0b80cfb0673ea07de6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:35:47 +0200 Subject: [PATCH 050/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 17293f33c..3ad0e7473 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -printf("stats_JSON(%s)\n",jprint(argjson,0)); +//printf("stats_JSON(%s)\n",jprint(argjson,0)); if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) From fc1ae40804ff4120f8eba155fb2ebfdfa9250dbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:39:00 +0200 Subject: [PATCH 051/520] Fixed hang --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 23486304a..087ed766e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -128,7 +128,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, portable_mutex_unlock(&coin->addrmutex); retval = 1; char str[65]; - if ( height > 0 ) + if ( 0 && height > 0 ) printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } From 923f13dfbd86e636783500d2a7e7d24ecf58bea9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:55:42 +0200 Subject: [PATCH 052/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 087ed766e..af3dab692 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -163,7 +163,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum array = cJSON_CreateArray(); if ( coinaddr != 0 && coinaddr[0] != 0 ) { - portable_mutex_lock(&coin->addrmutex); + //portable_mutex_lock(&coin->addrmutex); if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) { DL_FOREACH_SAFE(ap->utxos,up,tmp) @@ -176,7 +176,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum } } } - portable_mutex_unlock(&coin->addrmutex); + //portable_mutex_unlock(&coin->addrmutex); } //printf("%s %s utxos.(%s) ap.%p\n",coin->symbol,coinaddr,jprint(array,0),ap); return(array); From faacb59dd0641ae02aac62a758a60b46d4bb776c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 16 Sep 2017 23:59:55 +0200 Subject: [PATCH 053/520] Listunspent script --- iguana/exchanges/listunspent | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 iguana/exchanges/listunspent diff --git a/iguana/exchanges/listunspent b/iguana/exchanges/listunspent new file mode 100755 index 000000000..98c5b137d --- /dev/null +++ b/iguana/exchanges/listunspent @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"listunspent\",\"coin\":\"BTC\",\"address\":\"1DPDsPCNNCF5SHhPPrddXcJe78rM6CBcH3\"}" From f841465d1aaf2634fb8b3ae753da110c72f2c524 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 00:09:11 +0200 Subject: [PATCH 054/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index af3dab692..fa2c411d4 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -231,7 +231,7 @@ char *LP_postedutxos(cJSON *argjson) errs++; } ht = coin->height - jint(txobj,"confirmations"); - if ( ht != height ) + if ( ht != height && ht+1 != height ) { printf("%s %s/v%d ht.%d vs %d\n",symbol,bits256_str(str,txid),v,ht,height); errs++; From 966c9b74fa0780ba784e3ccdd74e22b334dd4707 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 00:09:37 +0200 Subject: [PATCH 055/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fa2c411d4..935ab0527 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -227,13 +227,13 @@ char *LP_postedutxos(cJSON *argjson) value = LP_value_extract(txobj,0); if ( value != val ) { - printf("%s %s/v%d value.%llu vs %llu\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val); + printf("REJECT %s %s/v%d value.%llu vs %llu\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val); errs++; } ht = coin->height - jint(txobj,"confirmations"); if ( ht != height && ht+1 != height ) { - printf("%s %s/v%d ht.%d vs %d\n",symbol,bits256_str(str,txid),v,ht,height); + printf("REJECT %s %s/v%d ht.%d vs %d\n",symbol,bits256_str(str,txid),v,ht,height); errs++; } free_json(txobj); From a9a333c4eb0b52169cedfa2e451fc99b0dcd7a35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 00:13:20 +0200 Subject: [PATCH 056/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 935ab0527..7f9a2b778 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -231,7 +231,7 @@ char *LP_postedutxos(cJSON *argjson) errs++; } ht = coin->height - jint(txobj,"confirmations"); - if ( ht != height && ht+1 != height ) + if ( ht < height-2 ) { printf("REJECT %s %s/v%d ht.%d vs %d\n",symbol,bits256_str(str,txid),v,ht,height); errs++; From 7435f2070c8b009576a900411906db71a05dd98e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 00:28:32 +0200 Subject: [PATCH 057/520] Test --- iguana/exchanges/LP_commands.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3ad0e7473..ec67242fc 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -334,7 +334,11 @@ dividends(coin, height, )\n\ argjson = reqjson; } } - if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 ) + if ( strcmp(method,"postprice") == 0 ) + retstr = LP_postedprice(argjson); + else if ( strcmp(method,"postutxos") == 0 ) + retstr = LP_postedutxos(argjson); + else if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 ) return(clonestr("{\"result\":\"at least one of coins disabled\"}")); else if ( IAMLP == 0 && LP_isdisabled(jstr(argjson,"coin"),0) != 0 ) retstr = clonestr("{\"result\":\"coin is disabled\"}"); @@ -352,10 +356,6 @@ dividends(coin, height, )\n\ retstr = clonestr("{\"result\":\"couldnt add utxo\"}"); //return(LP_numutxos()); } - else if ( strcmp(method,"postprice") == 0 ) - retstr = LP_postedprice(argjson); - else if ( strcmp(method,"postutxos") == 0 ) - retstr = LP_postedutxos(argjson); else if ( strcmp(method,"encrypted") == 0 ) retstr = clonestr("{\"result\":\"success\"}"); else if ( strcmp(method,"getprices") == 0 ) From 9caeff592a1bc74b88ce97385eedb2bb02854234 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 00:29:41 +0200 Subject: [PATCH 058/520] Test --- iguana/exchanges/LP_commands.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index ec67242fc..8dd2fc418 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -338,6 +338,16 @@ dividends(coin, height, )\n\ retstr = LP_postedprice(argjson); else if ( strcmp(method,"postutxos") == 0 ) retstr = LP_postedutxos(argjson); + else if ( strcmp(method,"getprices") == 0 ) + return(LP_prices()); + else if ( strcmp(method,"orderbook") == 0 ) + return(LP_orderbook(base,rel,jint(argjson,"duration"))); + else if ( strcmp(method,"listunspent") == 0 ) + { + if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) + return(jprint(LP_address_utxos(ptr,jstr(argjson,"address"),1),1)); + else return(clonestr("{\"error\":\"cant find coind\"}")); + } else if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 ) return(clonestr("{\"result\":\"at least one of coins disabled\"}")); else if ( IAMLP == 0 && LP_isdisabled(jstr(argjson,"coin"),0) != 0 ) @@ -358,16 +368,6 @@ dividends(coin, height, )\n\ } else if ( strcmp(method,"encrypted") == 0 ) retstr = clonestr("{\"result\":\"success\"}"); - else if ( strcmp(method,"getprices") == 0 ) - return(LP_prices()); - else if ( strcmp(method,"listunspent") == 0 ) - { - if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) - return(jprint(LP_address_utxos(ptr,jstr(argjson,"address"),1),1)); - else return(clonestr("{\"error\":\"cant find coind\"}")); - } - else if ( strcmp(method,"orderbook") == 0 ) - return(LP_orderbook(base,rel,jint(argjson,"duration"))); else if ( strcmp(method,"registerall") == 0 ) return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); else if ( strcmp(method,"forward") == 0 ) From ef58f97c6915ecaca964f390bff344d056fc038e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 16:45:19 +0200 Subject: [PATCH 059/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_peers.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index fe016e027..7bb843f13 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -23,6 +23,7 @@ //#define LP_STRICTPEERS +#define LP_ELECTRUM_MINPORT 8777 #define LP_COMMAND_SENDSOCK NN_PUSH #define LP_COMMAND_RECVSOCK NN_PULL diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 806572415..e4551f0ac 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -58,7 +58,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char { uint32_t ipbits; int32_t pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; printf("addpeer (%s:%u)\n",ipaddr,port); - if ( port > 10000 ) + if ( port >= LP_ELECTRUM_MINPORT ) return(0); #ifdef LP_STRICTPEERS if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) From cdc82faa26135d3a23a36da5372062ab519a3d50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 16:48:28 +0200 Subject: [PATCH 060/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index a0d875503..ec819f99d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -616,7 +616,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - //printf("strjson.(%s)\n",jprint(strjson,0)); + printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 1631276c0f4fdd414190974e957886fa1c767a70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 17 Sep 2017 16:49:01 +0200 Subject: [PATCH 061/520] Test --- iguana/exchanges/electrum.kmd | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 iguana/exchanges/electrum.kmd diff --git a/iguana/exchanges/electrum.kmd b/iguana/exchanges/electrum.kmd new file mode 100755 index 000000000..747fba203 --- /dev/null +++ b/iguana/exchanges/electrum.kmd @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"96.44.166.176\",\"port\":8777}" From d1a4b07f07acf2a60b2dbef3716aec709b78efda Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 09:16:05 +0200 Subject: [PATCH 062/520] Test --- iguana/exchanges/LP_rpc.c | 11 ++++++----- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/electrum.kmd2 | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100755 iguana/exchanges/electrum.kmd2 diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 3add08caf..b8bb2f969 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -263,8 +263,8 @@ cJSON *LP_gettx(char *symbol,bits256 txid) serialized = malloc(len); decode_hex(serialized,len,hexstr+1); //printf("DATA.(%s)\n",hexstr+1); - extraspace = calloc(1,100000); - retjson = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,100000,serialized,len,0,0); + extraspace = calloc(1,1000000); + retjson = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,1000000,serialized,len,0,0); free(serialized); free(extraspace); //printf("TX.(%s) match.%d\n",jprint(retjson,0),bits256_cmp(txid,checktxid)); @@ -619,9 +619,10 @@ char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON * signedtx = calloc(1,len+1); strcpy(signedtx,hexstr); *completedp = is_cJSON_True(jobj(json,"complete")); - data = malloc(len >> 1); - decode_hex(data,len>>1,hexstr); - *signedtxidp = bits256_doublesha256(0,data,len >> 1); + len >>= 1; + data = malloc(len); + decode_hex(data,len,hexstr); + *signedtxidp = bits256_doublesha256(0,data,len); } //else printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index ec819f99d..854d52ec3 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -469,7 +469,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) LP_postutxos(coin->symbol); - strcpy(coin->lastunspent,addr); + safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); coin->unspenttime = (uint32_t)time(NULL); } } else retjson = LP_address_utxos(coin,addr,1); diff --git a/iguana/exchanges/electrum.kmd2 b/iguana/exchanges/electrum.kmd2 new file mode 100755 index 000000000..46b11276b --- /dev/null +++ b/iguana/exchanges/electrum.kmd2 @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"173.212.225.176\",\"port\":50011}" From 041963d66b46e079dae28e0ce5ece65e3db7c11a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:09:32 +0200 Subject: [PATCH 063/520] New orderbook --- iguana/exchanges/LP_nativeDEX.c | 5 ++- iguana/exchanges/LP_prices.c | 71 ++++++++++++++++++++++----------- iguana/exchanges/LP_utxo.c | 18 +++++++++ 3 files changed, 70 insertions(+), 24 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index da09bfff5..4c7d61328 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -84,8 +84,8 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_ #include "LP_bitcoin.c" #include "LP_coins.c" #include "LP_rpc.c" -#include "LP_prices.c" #include "LP_utxo.c" +#include "LP_prices.c" #include "LP_scan.c" #include "LP_transaction.c" #include "LP_remember.c" @@ -356,7 +356,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //if ( IAMLP != 0 && peer->numpeers != numpeers ) // printf("%s num.%d vs %d\n",peer->ipaddr,peer->numpeers,numpeers); if ( strcmp(peer->ipaddr,myipaddr) != 0 ) + { LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); + LP_peer_pricesquery(peer->ipaddr,peer->port); + } if ( enable_utxos && IAMLP != 0 && LP_mypeer != 0 && strcmp(peer->ipaddr,myipaddr) != 0 ) { if ( (retstr= issue_LP_numutxos(peer->ipaddr,peer->port,LP_mypeer->ipaddr,LP_mypeer->port,LP_mypeer->numpeers,LP_mypeer->numutxos)) != 0 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index eb1df8867..f0b20b3de 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -18,7 +18,7 @@ // marketmaker // -struct LP_orderbookentry { bits256 txid,txid2,pubkey; double price; uint64_t basesatoshis; int32_t vout,vout2,age; }; +struct LP_orderbookentry { bits256 pubkey; double price; uint64_t basesatoshis,maxsatoshis; int32_t age,numutxos; char coinaddr[64]; }; #define LP_MAXPRICEINFOS 256 struct LP_priceinfo @@ -513,8 +513,8 @@ static int _cmp_orderbook(const void *a,const void *b) { #undef ptr_a #undef ptr_b -#define ptr_a ((struct LP_orderbookentry *)a)->basesatoshis -#define ptr_b ((struct LP_orderbookentry *)b)->basesatoshis +#define ptr_a ((struct LP_orderbookentry *)a)->maxsatoshis +#define ptr_b ((struct LP_orderbookentry *)b)->maxsatoshis if ( ptr_b > ptr_a ) return(-1); else if ( ptr_b < ptr_a ) @@ -531,60 +531,83 @@ cJSON *LP_orderbookjson(struct LP_orderbookentry *op) cJSON *item = cJSON_CreateObject(); if ( LP_pricevalid(op->price) > 0 ) { + jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); - jaddnum(item,"volume",dstr(op->basesatoshis)); - jaddbits256(item,"txid",op->txid); - jaddnum(item,"vout",op->vout); + jaddnum(item,"numutxos",op->numutxos); + jaddnum(item,"minvolume",dstr(op->basesatoshis)); + jaddnum(item,"maxvolume",dstr(op->maxsatoshis)); + //jaddbits256(item,"txid",op->txid); + //jaddnum(item,"vout",op->vout); jaddbits256(item,"pubkey",op->pubkey); jaddnum(item,"age",op->age); } return(item); } -struct LP_orderbookentry *LP_orderbookentry(char *base,char *rel,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2,double price,uint64_t basesatoshis,bits256 pubkey,int32_t age) +struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,int32_t age) { struct LP_orderbookentry *op; if ( (op= calloc(1,sizeof(*op))) != 0 ) { - op->txid = txid; - op->vout = vout; - op->txid2 = txid2; - op->vout2 = vout2; + //op->txid = txid; + //op->vout = vout; + //op->txid2 = txid2; + //op->vout2 = vout2; + safecopy(op->coinaddr,address,sizeof(op->coinaddr)); op->price = price; + op->numutxos = numutxos; op->basesatoshis = basesatoshis; + op->maxsatoshis = maxsatoshis; op->pubkey = pubkey; op->age = age; } return(op); } -int32_t LP_orderbookfind(struct LP_orderbookentry **array,int32_t num,bits256 txid,int32_t vout) +/*int32_t LP_orderbookfind(struct LP_orderbookentry **array,int32_t num,bits256 txid,int32_t vout) { int32_t i; for (i=0; ivout == vout && bits256_cmp(array[i]->txid,txid) == 0) || (array[i]->vout2 == vout && bits256_cmp(array[i]->txid2,txid) == 0) ) return(i); return(-1); -} +}*/ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) { - struct LP_utxoinfo *utxo,*tmp; struct LP_pubkeyinfo *pubp=0; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; uint32_t oldest; double price; int32_t baseid,relid; uint64_t basesatoshis,val,val2; + char coinaddr[64]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t basesatoshis,maxsatoshis; if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) baseid = basepp->ind; else return(num); + if ( (basecoin= LP_coinfind(base)) == 0 ) + return(-1); now = (uint32_t)time(NULL); oldest = now - duration; - HASH_ITER(hh,LP_utxoinfos[1],utxo,tmp) + HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp) { - if ( pubp == 0 || bits256_cmp(pubp->pubkey,utxo->pubkey) != 0 ) - pubp = LP_pubkeyfind(utxo->pubkey); - if ( pubp != 0 && pubp->numerrors >= LP_MAXPUBKEY_ERRORS ) + if ( pubp->timestamp < oldest ) continue; + bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + basesatoshis = maxsatoshis = 0; //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); - if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL && pubp->timestamp > oldest && pubp->timestamp <= now ) + if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL && (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { - if ( LP_orderbookfind(*arrayp,cachednum,utxo->payment.txid,utxo->payment.vout) < 0 ) + n = LP_address_minmax(&basesatoshis,&maxsatoshis,ap); + //if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) + //if ( polarity > 0 ) + // basesatoshis = utxo->S.satoshis; + //else basesatoshis = utxo->S.satoshis * price; + if ( polarity < 0 ) + { + basesatoshis *= price; + maxsatoshis *= price; + } + if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,basesatoshis,maxsatoshis,pubp->pubkey,now - pubp->timestamp)) != 0 ) + { + *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); + (*arrayp)[num++] = op; + } + /*if ( LP_orderbookfind(*arrayp,cachednum,utxo->payment.txid,utxo->payment.vout) < 0 ) { if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->deposit.txid,utxo->deposit.vout) == 0 ) continue; @@ -599,7 +622,8 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) LP_utxo_clientpublish(utxo); } - } + }*/ + } } return(num); @@ -851,9 +875,10 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) } if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) { - if ( (rand() % 100) == 0 && fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) - printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); + if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { + if ( (rand() % 100) == 0 ) + printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); pubp->matrix[basepp->ind][relpp->ind] = price; dxblend(&basepp->relvals[relpp->ind],price,0.9); dxblend(&relpp->relvals[basepp->ind],1. / price,0.9); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 7f9a2b778..7cbfdd91b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -96,6 +96,24 @@ struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr) return(ap); } +int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) +{ + struct LP_address_utxo *up,*tmp; int32_t n = 0; + *minp = *maxp = 0; + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( up->spendheight <= 0 ) + { + if ( up->U.value > *maxp ) + *maxp = up->U.value; + if ( *minp == 0 || up->U.value < *minp ) + *minp = up->U.value; + n++; + } + } + return(n); +} + int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; From 3f9c935a6f125f75a457dcd3d25dad7915641948 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:12:48 +0200 Subject: [PATCH 064/520] Test --- iguana/exchanges/LP_prices.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index f0b20b3de..c39fcc898 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -575,7 +575,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) { - char coinaddr[64]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t basesatoshis,maxsatoshis; + char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t basesatoshis,maxsatoshis; if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) baseid = basepp->ind; else return(num); @@ -583,9 +583,12 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * return(-1); now = (uint32_t)time(NULL); oldest = now - duration; + memset(zeroes,0,sizeof(zeroes)); HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp) { - if ( pubp->timestamp < oldest ) + //if ( pubp->timestamp < oldest ) + // continue; + if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); basesatoshis = maxsatoshis = 0; From 40abdf0aa76ab346baa20602cfb5a2cd4e2f2778 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:18:05 +0200 Subject: [PATCH 065/520] Test --- iguana/exchanges/LP_prices.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index c39fcc898..eaf278b3f 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -592,6 +592,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); basesatoshis = maxsatoshis = 0; + printf("pubp.(%s)\n",coinaddr); //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL && (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { From 685abda748fa78ce0c0d0237fe19dd3792fdbaaf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:20:01 +0200 Subject: [PATCH 066/520] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index eaf278b3f..2066af15a 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -592,7 +592,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); basesatoshis = maxsatoshis = 0; - printf("pubp.(%s)\n",coinaddr); + ap = 0; //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL && (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { @@ -627,8 +627,8 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * LP_utxo_clientpublish(utxo); } }*/ - } + printf("pubp.(%s) %.8f %p\n",coinaddr,price,ap); } return(num); } From a7e1bdb26ffcb935c0d03c0a9f55c3ef3fef5dcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:23:25 +0200 Subject: [PATCH 067/520] Test --- iguana/exchanges/LP_prices.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 2066af15a..8fd07633d 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -591,20 +591,23 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - basesatoshis = maxsatoshis = 0; + basesatoshis = maxsatoshis = n = 0; ap = 0; //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); - if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL && (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) + //if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) + //if ( polarity > 0 ) + // basesatoshis = utxo->S.satoshis; + //else basesatoshis = utxo->S.satoshis * price; + if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL ) { - n = LP_address_minmax(&basesatoshis,&maxsatoshis,ap); - //if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) - //if ( polarity > 0 ) - // basesatoshis = utxo->S.satoshis; - //else basesatoshis = utxo->S.satoshis * price; - if ( polarity < 0 ) + if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { - basesatoshis *= price; - maxsatoshis *= price; + n = LP_address_minmax(&basesatoshis,&maxsatoshis,ap); + if ( polarity < 0 ) + { + basesatoshis *= price; + maxsatoshis *= price; + } } if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,basesatoshis,maxsatoshis,pubp->pubkey,now - pubp->timestamp)) != 0 ) { From afd6476a5ffd53a187f5c018b9aee25aa86b742c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:26:11 +0200 Subject: [PATCH 068/520] Test --- iguana/exchanges/LP_prices.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 8fd07633d..5a32af338 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -18,7 +18,7 @@ // marketmaker // -struct LP_orderbookentry { bits256 pubkey; double price; uint64_t basesatoshis,maxsatoshis; int32_t age,numutxos; char coinaddr[64]; }; +struct LP_orderbookentry { bits256 pubkey; double price; uint64_t basesatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; #define LP_MAXPRICEINFOS 256 struct LP_priceinfo @@ -539,12 +539,12 @@ cJSON *LP_orderbookjson(struct LP_orderbookentry *op) //jaddbits256(item,"txid",op->txid); //jaddnum(item,"vout",op->vout); jaddbits256(item,"pubkey",op->pubkey); - jaddnum(item,"age",op->age); + jaddnum(item,"age",time(NULL)-op->timestamp); } return(item); } -struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,int32_t age) +struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) { struct LP_orderbookentry *op; if ( (op= calloc(1,sizeof(*op))) != 0 ) @@ -559,7 +559,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d op->basesatoshis = basesatoshis; op->maxsatoshis = maxsatoshis; op->pubkey = pubkey; - op->age = age; + op->timestamp = timestamp; } return(op); } @@ -609,7 +609,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * maxsatoshis *= price; } } - if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,basesatoshis,maxsatoshis,pubp->pubkey,now - pubp->timestamp)) != 0 ) + if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,basesatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); (*arrayp)[num++] = op; From 7274abcf5172615c2127a00b4263422a0f61865a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:29:32 +0200 Subject: [PATCH 069/520] Test --- iguana/exchanges/LP_prices.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 5a32af338..543d6a019 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -216,7 +216,8 @@ char *LP_prices() void LP_prices_parse(cJSON *obj) { static uint8_t zeroes[20]; - struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid; char *base,*rel,*hexstr; double askprice; + struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid; char *base,*rel,*hexstr; double askprice; uint32_t now; + now = (uint32_t)time(NULL); pubkey = jbits256(obj,"pubkey"); if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { @@ -232,7 +233,10 @@ void LP_prices_parse(cJSON *obj) //LP_address_monitor(pubp); } } - if ( (timestamp= juint(obj,"timestamp")) > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 ) + timestamp = juint(obj,"timestamp"); + if ( timestamp > now ) + timestamp = now; + if ( timestamp > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 ) { pubp->timestamp = timestamp; for (i=0; i Date: Mon, 18 Sep 2017 10:45:13 +0200 Subject: [PATCH 070/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_peers.c | 24 ++++++++++++++++++++++++ iguana/exchanges/LP_prices.c | 17 ++++++++++++++--- iguana/exchanges/LP_rpc.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 7bb843f13..0be95d830 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -306,6 +306,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); void LP_postutxos(char *symbol); +uint16_t LP_randpeer(char *destip); #endif diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index e4551f0ac..f6c2bc4f5 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -254,3 +254,27 @@ int32_t LP_numpeers() } return(numpeers); } + +uint16_t LP_randpeer(char *destip) +{ + struct LP_peerinfo *peer,*tmp; uint16_t port = 0; int32_t n,r,numpeers = 0; + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + numpeers++; + } + if ( numpeers > 0 ) + { + r = rand() % numpeers; + n = 0; + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + if ( n++ == r ) + { + strcpy(destip,peer->ipaddr); + port = peer->port; + break; + } + } + } + return(port); +} diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 543d6a019..b604f29e8 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -530,11 +530,12 @@ static int _cmp_orderbook(const void *a,const void *b) #undef ptr_b } -cJSON *LP_orderbookjson(struct LP_orderbookentry *op) +cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) { cJSON *item = cJSON_CreateObject(); if ( LP_pricevalid(op->price) > 0 ) { + jaddstr(item,"coin",symbol); jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); @@ -548,6 +549,12 @@ cJSON *LP_orderbookjson(struct LP_orderbookentry *op) return(item); } +void LP_check_unspents(char *symbol,struct LP_orderbookentry *op) +{ + if ( op->numutxos == 0 ) + LP_listunspent_issue(symbol,op->coinaddr); +} + struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) { struct LP_orderbookentry *op; @@ -670,7 +677,9 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) } for (i=0; ielectrum,&retjson,coinaddr)); } +void LP_listunspent_issue(char *symbol,char *coinaddr) +{ + struct iguana_info *coin; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; + if ( (coin= LP_coinfind(symbol)) != 0 ) + { + if ( coin->electrum != 0 ) + retjson = electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr); + else + { + if ( (destport= LP_randpeer(destip)) > 0 ) + { + retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); + printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); + } + } + if ( retjson != 0 ) + free_json(retjson); + if ( retstr != 0 ) + free(retstr); + } +} + cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) { static void *ctx; From 3c7d8fe6e7a556f2d59ccb2cc585b0e76c588423 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 10:54:14 +0200 Subject: [PATCH 071/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_prices.c | 10 +++++++--- iguana/exchanges/LP_utxo.c | 25 ++++++++++++++++++++----- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4c7d61328..259fa5729 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -437,6 +437,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { if ( coin->electrum == 0 ) { + // issue listunspent DL_FOREACH_SAFE(ap->utxos,up,utmp) { if ( up->spendheight <= 0 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index b604f29e8..a73f1118b 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -649,7 +649,11 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * char *LP_orderbook(char *base,char *rel,int32_t duration) { - uint32_t now,i; struct LP_priceinfo *basepp=0,*relpp=0; struct LP_orderbookentry **bids = 0,**asks = 0; cJSON *retjson,*array; int32_t numbids=0,numasks=0,cachenumbids,cachenumasks,baseid,relid; + uint32_t now,i; struct LP_priceinfo *basepp=0,*relpp=0; struct LP_orderbookentry **bids = 0,**asks = 0; cJSON *retjson,*array; struct iguana_info *basecoin,*relcoin; int32_t numbids=0,numasks=0,cachenumbids,cachenumasks,baseid,relid; + basecoin = LP_coinfind(base); + relcoin = LP_coinfind(rel); + if ( basecoin == 0 || relcoin == 0 ) + return(clonestr("{\"error\":\"base or rel not added\"}")); if ( (basepp= LP_priceinfofind(base)) == 0 || (relpp= LP_priceinfofind(rel)) == 0 ) return(clonestr("{\"error\":\"base or rel not added\"}")); if ( duration <= 0 ) @@ -679,7 +683,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) { jaddi(array,LP_orderbookjson(rel,bids[i])); if ( i < 3 ) - LP_check_unspents(rel,bids[i]); + LP_address(relcoin,bids[i]->coinaddr); free(bids[i]); bids[i] = 0; } @@ -690,7 +694,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) { jaddi(array,LP_orderbookjson(base,asks[i])); if ( i < 3 ) - LP_check_unspents(base,asks[i]); + LP_address(basecoin,asks[i]->coinaddr); free(asks[i]); asks[i] = 0; } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 7cbfdd91b..76fdbed82 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -81,7 +81,7 @@ struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) { - struct LP_address *ap; + struct LP_address *ap = 0; if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 ) ap = _LP_addressadd(coin,coinaddr); return(ap); @@ -89,10 +89,25 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr) { - struct LP_address *ap; - portable_mutex_lock(&coin->addrmutex); - ap = _LP_addressfind(coin,coinaddr); - portable_mutex_unlock(&coin->addrmutex); + struct LP_address *ap = 0; + if ( coin != 0 ) + { + portable_mutex_lock(&coin->addrmutex); + ap = _LP_addressfind(coin,coinaddr); + portable_mutex_unlock(&coin->addrmutex); + } + return(ap); +} + +struct LP_address *LP_address(struct iguana_info *coin,char *coinaddr) +{ + struct LP_address *ap = 0; + if ( coin != 0 ) + { + portable_mutex_lock(&coin->addrmutex); + ap = _LP_address(coin,coinaddr); + portable_mutex_unlock(&coin->addrmutex); + } return(ap); } From 9b96ae4df7034d7e537096ec5109957b2add83c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:05:08 +0200 Subject: [PATCH 072/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 259fa5729..f8d7b7a90 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -447,7 +447,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } } } - else + else if ( 0 ) { if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,ap->coinaddr)) != 0 ) free_json(retjson); From d72d3184734018ed7bbd7bf131423f50641ac70d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:06:10 +0200 Subject: [PATCH 073/520] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f8d7b7a90..0af265262 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -432,7 +432,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; if ( time(NULL) > coin->lastmonitor+60 ) { - portable_mutex_lock(&coin->addrmutex); + //portable_mutex_lock(&coin->addrmutex); HASH_ITER(hh,coin->addresses,ap,atmp) { if ( coin->electrum == 0 ) @@ -447,13 +447,13 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } } } - else if ( 0 ) + else { if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,ap->coinaddr)) != 0 ) free_json(retjson); } } - portable_mutex_unlock(&coin->addrmutex); + //portable_mutex_unlock(&coin->addrmutex); coin->lastmonitor = (uint32_t)time(NULL); } if ( coin->electrum != 0 ) From de322cdfc18379cbbc983b031725b789b279a483 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:09:53 +0200 Subject: [PATCH 074/520] Test --- iguana/exchanges/LP_prices.c | 4 ++++ iguana/exchanges/LP_utxo.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index a73f1118b..1c273bb5a 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -698,6 +698,10 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) free(asks[i]); asks[i] = 0; } + if ( basecoin->lastmonitor > 60 ) + basecoin->lastmonitor -= 60; + if ( relcoin->lastmonitor > 60 ) + relcoin->lastmonitor -= 60; jadd(retjson,"asks",array); jaddnum(retjson,"numasks",numasks); jaddstr(retjson,"base",base); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 76fdbed82..134a08be0 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -126,6 +126,8 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) n++; } } + if ( n > 0 ) + printf("n.%d %s min %.8f max %.8f\n",n,ap->coinaddr,dstr(*minp),dstr(*maxp)); return(n); } From 20b41c1c1b2cf467790647b50edd1260680a9031 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:14:08 +0200 Subject: [PATCH 075/520] Test --- iguana/exchanges/LP_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 854d52ec3..c8e7840ca 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -466,7 +466,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + printf("%s %s LISTUNSPENT.(%s)\n",symbol,addr,jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) LP_postutxos(coin->symbol); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); @@ -616,7 +616,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - printf("strjson.(%s)\n",jprint(strjson,0)); + //printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 3d61c2761973d8d5c0080c93a09915448dc90494 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:19:27 +0200 Subject: [PATCH 076/520] Test --- iguana/exchanges/LP_socket.c | 14 ++++++++------ iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index c8e7840ca..57334e037 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -324,19 +324,21 @@ int32_t electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *ar if (tx->height <= 0 ) { tx->height = jint(item,"height"); - printf(">>>>>>>>>> set %s <- height %d\n",bits256_str(str,txid),tx->height); + printf("%s %s >>>>>>>>>> set %s <- height %d\n",coin->symbol,coinaddr,bits256_str(str,txid),tx->height); } - if ( jobj(item,"tx_pos") != 0 && jobj(item,"value") != 0 && (v= jint(item,"tx_pos")) >= 0 && v < tx->numvouts ) + value = j64bits(item,"value"); + v = jint(item,"tx_pos"); + if ( jobj(item,"tx_pos") != 0 && jobj(item,"value") != 0 && v >= 0 && v < tx->numvouts ) { - value = j64bits(item,"value"); if ( tx->outpoints[v].value == 0 && value != tx->outpoints[v].value ) { - printf(">>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); + printf("%s %s >>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); tx->outpoints[v].value = value; - flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); } } - printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); + if ( value != 0 && tx->height > 0 ) + flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); + //printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); } } } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 134a08be0..b42d1eed5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -163,8 +163,8 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, portable_mutex_unlock(&coin->addrmutex); retval = 1; char str[65]; - if ( 0 && height > 0 ) - printf(">>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); + if ( height > 0 ) + printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); From 02ffefac7f036afcddca81bdea3868914b080518 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:25:09 +0200 Subject: [PATCH 077/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_prices.c | 14 ++++---------- iguana/exchanges/LP_socket.c | 4 ++-- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0af265262..993e27e8f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -430,14 +430,14 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( coin->inactive != 0 ) continue; - if ( time(NULL) > coin->lastmonitor+60 ) + if ( time(NULL) > coin->lastmonitor+600 ) { //portable_mutex_lock(&coin->addrmutex); HASH_ITER(hh,coin->addresses,ap,atmp) { if ( coin->electrum == 0 ) { - // issue listunspent + LP_listunspent_issue(coin->symbol,ap->coinaddr); DL_FOREACH_SAFE(ap->utxos,up,utmp) { if ( up->spendheight <= 0 ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 1c273bb5a..40d71d55e 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -549,12 +549,6 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) return(item); } -void LP_check_unspents(char *symbol,struct LP_orderbookentry *op) -{ - if ( op->numutxos == 0 ) - LP_listunspent_issue(symbol,op->coinaddr); -} - struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) { struct LP_orderbookentry *op; @@ -698,10 +692,10 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) free(asks[i]); asks[i] = 0; } - if ( basecoin->lastmonitor > 60 ) - basecoin->lastmonitor -= 60; - if ( relcoin->lastmonitor > 60 ) - relcoin->lastmonitor -= 60; + if ( basecoin->lastmonitor > 3600 ) + basecoin->lastmonitor -= 3600; + if ( relcoin->lastmonitor > 3600 ) + relcoin->lastmonitor -= 3600; jadd(retjson,"asks",array); jaddnum(retjson,"numasks",numasks); jaddstr(retjson,"base",base); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 57334e037..9a16f7134 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -324,7 +324,7 @@ int32_t electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *ar if (tx->height <= 0 ) { tx->height = jint(item,"height"); - printf("%s %s >>>>>>>>>> set %s <- height %d\n",coin->symbol,coinaddr,bits256_str(str,txid),tx->height); + //printf("%s %s >>>>>>>>>> set %s <- height %d\n",coin->symbol,coinaddr,bits256_str(str,txid),tx->height); } value = j64bits(item,"value"); v = jint(item,"tx_pos"); @@ -468,7 +468,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - printf("%s %s LISTUNSPENT.(%s)\n",symbol,addr,jprint(retjson,0)); + //printf("%s %s LISTUNSPENT.(%s)\n",symbol,addr,jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) LP_postutxos(coin->symbol); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); From 835cd75dd18a570781c5bc3e8a28af97bf4b95cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:26:43 +0200 Subject: [PATCH 078/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 85ad454c2..1cffef1ba 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -455,7 +455,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) if ( (destport= LP_randpeer(destip)) > 0 ) { retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); - printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); + //printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); } } if ( retjson != 0 ) From 9fac1ebbb40d7b21c5e4f67f30d3c3050f53087b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:28:36 +0200 Subject: [PATCH 079/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index ccb18e6b1..76f302038 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -909,7 +909,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t inito privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); if ( coin->inactive == 0 && initonly == 0 ) { - if ( LP_privkey_init(pubsock,coin,privkey,pubkey) > 0 ) + if ( LP_privkey_init(pubsock,coin,privkey,pubkey) > 0 || (rand() % 10) == 0 ) LP_postutxos(coin->symbol); } } From 8056741b5e81fd1c8bea92d1ca66c790519bd50c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:33:26 +0200 Subject: [PATCH 080/520] Test --- iguana/exchanges/LP_rpc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 1cffef1ba..be0680f4e 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -455,6 +455,13 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) if ( (destport= LP_randpeer(destip)) > 0 ) { retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( electrum_process_array(coin,coinaddr,retjson) != 0 ) + { + LP_postutxos(symbol); + } + } //printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); } } From f7af7a5b1d68620f5b998ecf75100dbb30adce91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:42:31 +0200 Subject: [PATCH 081/520] Test --- iguana/exchanges/LP_prices.c | 4 ++-- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 40d71d55e..7b6e78ddb 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -676,7 +676,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=0; ielectrum == 0 ) LP_address(relcoin,bids[i]->coinaddr); free(bids[i]); bids[i] = 0; @@ -687,7 +687,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=0; ielectrum == 0 ) LP_address(basecoin,asks[i]->coinaddr); free(asks[i]); asks[i] = 0; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index be0680f4e..e90da1254 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -459,7 +459,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) { if ( electrum_process_array(coin,coinaddr,retjson) != 0 ) { - LP_postutxos(symbol); + LP_postutxos(symbol); // might be good to not saturate } } //printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); From 9ccadc4f0c70f66bc4a54f24cfb35ce7bd3080d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:47:06 +0200 Subject: [PATCH 082/520] Test --- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7b6e78ddb..0b3b6699b 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -249,7 +249,7 @@ void LP_prices_parse(cJSON *obj) { if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) { - char str[65]; printf("%s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); + //char str[65]; printf("%s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); pubp->matrix[basepp->ind][relid] = askprice; if ( (relpp= LP_priceinfofind(rel)) != 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index b42d1eed5..6047fb853 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -163,7 +163,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, portable_mutex_unlock(&coin->addrmutex); retval = 1; char str[65]; - if ( height > 0 ) + if ( 0 && height > 0 ) printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } From 1f003c90f1e73654fc475c9f582802b377bcb2cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 11:50:25 +0200 Subject: [PATCH 083/520] Test --- iguana/exchanges/LP_prices.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0b3b6699b..deef1f3a9 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -643,7 +643,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * char *LP_orderbook(char *base,char *rel,int32_t duration) { - uint32_t now,i; struct LP_priceinfo *basepp=0,*relpp=0; struct LP_orderbookentry **bids = 0,**asks = 0; cJSON *retjson,*array; struct iguana_info *basecoin,*relcoin; int32_t numbids=0,numasks=0,cachenumbids,cachenumasks,baseid,relid; + uint32_t now,i; struct LP_priceinfo *basepp=0,*relpp=0; struct LP_orderbookentry **bids = 0,**asks = 0; cJSON *retjson,*array; struct iguana_info *basecoin,*relcoin; int32_t n,numbids=0,numasks=0,cachenumbids,cachenumasks,baseid,relid; basecoin = LP_coinfind(base); relcoin = LP_coinfind(rel); if ( basecoin == 0 || relcoin == 0 ) @@ -673,22 +673,22 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) // printf("%.8f ",asks[i]->price); //printf("sorted asks.%d\n",numasks); } - for (i=0; ielectrum == 0 ) - LP_address(relcoin,bids[i]->coinaddr); + if ( bids[i]->numutxos == 0 && (n == 0 || relcoin->electrum == 0) ) + LP_address(relcoin,bids[i]->coinaddr), n++; free(bids[i]); bids[i] = 0; } jadd(retjson,"bids",array); jaddnum(retjson,"numbids",numbids); array = cJSON_CreateArray(); - for (i=0; ielectrum == 0 ) - LP_address(basecoin,asks[i]->coinaddr); + if ( asks[i]->numutxos == 0 && (n == 0 || basecoin->electrum == 0) ) + LP_address(basecoin,asks[i]->coinaddr), n++; free(asks[i]); asks[i] = 0; } From f4ebbd3d1171288d1e85412a10625b98a36a632f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 12:05:01 +0200 Subject: [PATCH 084/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 6 +++--- iguana/exchanges/LP_utxos.c | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0be95d830..2d0abd3c5 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -305,7 +305,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); -void LP_postutxos(char *symbol); +void LP_postutxos(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index e90da1254..0f78716db 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -459,7 +459,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) { if ( electrum_process_array(coin,coinaddr,retjson) != 0 ) { - LP_postutxos(symbol); // might be good to not saturate + LP_postutxos(symbol,coinaddr); // might be good to not saturate } } //printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 9a16f7134..a5204567c 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -470,7 +470,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { //printf("%s %s LISTUNSPENT.(%s)\n",symbol,addr,jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) - LP_postutxos(coin->symbol); + LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); coin->unspenttime = (uint32_t)time(NULL); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6047fb853..f0b80a966 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -217,10 +217,10 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum return(array); } -void LP_postutxos(char *symbol) +void LP_postutxos(char *symbol,char *coinaddr) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); - if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) + if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) { //printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr); if ( cJSON_GetArraySize(array) == 0 ) @@ -230,7 +230,7 @@ void LP_postutxos(char *symbol) memset(zero.bytes,0,sizeof(zero)); jaddstr(reqjson,"method","postutxos"); jaddstr(reqjson,"coin",symbol); - jaddstr(reqjson,"coinaddr",coin->smartaddr); + jaddstr(reqjson,"coinaddr",coinaddr); jadd(reqjson,"utxos",array); msg = jprint(reqjson,1); printf("post (%s) -> %d\n",msg,LP_mypubsock); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 76f302038..925354973 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -789,7 +789,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } free_json(array); if ( flag != 0 ) - LP_postutxos(coin->symbol); + LP_postutxos(coin->symbol,coin->smartaddr); } //printf("privkey.%s %.8f\n",symbol,dstr(total)); return(flag); @@ -909,8 +909,8 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t inito privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); if ( coin->inactive == 0 && initonly == 0 ) { - if ( LP_privkey_init(pubsock,coin,privkey,pubkey) > 0 || (rand() % 10) == 0 ) - LP_postutxos(coin->symbol); + if ( LP_privkey_init(pubsock,coin,privkey,pubkey) == 0 && (rand() % 10) == 0 ) + LP_postutxos(coin->symbol,coin->smartaddr); } } } From ee81a6b6679894ca41efaa5f7d1e2ecca89e8658 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 12:12:59 +0200 Subject: [PATCH 085/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f0b80a966..768a67286 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -242,7 +242,7 @@ void LP_postutxos(char *symbol,char *coinaddr) char *LP_postedutxos(cJSON *argjson) { int32_t i,n,v,ht,errs,height; uint64_t value,val; cJSON *array,*item,*txobj; bits256 txid; char str[65],*symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; - printf("posted.(%s)\n",jprint(argjson,0)); + //printf("posted.(%s)\n",jprint(argjson,0)); if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig { if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) From d1f3805b7668a26c8c066d667199a54f9532381b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 14:06:32 +0200 Subject: [PATCH 086/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index a5204567c..a67e2192a 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -618,7 +618,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - //printf("strjson.(%s)\n",jprint(strjson,0)); + printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 26c815cf639106a7079c4dfcd4e90f229f9ed53c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 14:19:11 +0200 Subject: [PATCH 087/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 2d0abd3c5..8e8f97c6f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -23,7 +23,7 @@ //#define LP_STRICTPEERS -#define LP_ELECTRUM_MINPORT 8777 +#define LP_ELECTRUM_MINPORT 8776 #define LP_COMMAND_SENDSOCK NN_PUSH #define LP_COMMAND_RECVSOCK NN_PULL diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index a67e2192a..a5204567c 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -618,7 +618,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - printf("strjson.(%s)\n",jprint(strjson,0)); + //printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 515dc4006dbc83e9b58946bf17d16d2c32cdac70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 14:21:19 +0200 Subject: [PATCH 088/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 768a67286..42388f807 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -233,7 +233,7 @@ void LP_postutxos(char *symbol,char *coinaddr) jaddstr(reqjson,"coinaddr",coinaddr); jadd(reqjson,"utxos",array); msg = jprint(reqjson,1); - printf("post (%s) -> %d\n",msg,LP_mypubsock); + //printf("post (%s) -> %d\n",msg,LP_mypubsock); LP_broadcast_message(LP_mypubsock,symbol,symbol,zero,msg); } } From 013760d47e49918d616471528703b237b610c6da Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 14:35:05 +0200 Subject: [PATCH 089/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 52d4f418d..d33f51efe 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -714,10 +714,13 @@ char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,ch desttxfee = LP_txfeecalc(LP_coinfind(rel),desttxfee); if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxopair\"}")); + printf("call LP_bestutxo\n"); if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); + printf("call LP_quoteinfoinit\n"); if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + printf("call LP_quotedestinfo\n"); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); return(jprint(LP_quotejson(&Q),1)); From fa42297feed7571d992d5334b769df18e09a4db8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 16:26:43 +0200 Subject: [PATCH 090/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d33f51efe..d5364249d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -602,7 +602,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, { if ( bestprice == 0. ) // assumes price ordered asks bestprice = price; - //printf("item.[%d] %s\n",i,jprint(item,0)); + printf("item.[%d] %s\n",i,jprint(item,0)); txid = jbits256(item,"txid"); vout = jint(item,"vout"); vol = jdouble(item,"volume"); @@ -689,6 +689,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, } free(obookstr); } + printf("bestutxo.%p %.8f %.8f\n",bestutxo,*ordermatchpricep,dstr(*bestdestsatoshisp)); if ( bestutxo == 0 || *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) return(0); bestutxo->T.bestflag = 1; From edc1568925cbe03586d3ba44147083cf1daf8e2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 16:36:31 +0200 Subject: [PATCH 091/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d5364249d..226e7a46d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -609,6 +609,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, metric = price / bestprice; if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { + printf("got butxo? %p\n",butxo); if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 ) { destsatoshis = ((butxo->S.satoshis - txfee) * price); From 054a87a548db3aaef6b81c7c5098de4c70bef88e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 17:55:50 +0200 Subject: [PATCH 092/520] Test --- iguana/exchanges/LP_rpc.c | 4 ++++ iguana/exchanges/LP_socket.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 0f78716db..70321218b 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -251,6 +251,8 @@ cJSON *LP_gettx(char *symbol,bits256 txid) coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); + if ( bits256_nonz(txid) == 0 ) + return(cJSON_Parse("{\"error\":\"null txid\"}")); if ( coin->electrum == 0 ) { sprintf(buf,"[\"%s\", 1]",bits256_str(str,txid)); @@ -290,6 +292,8 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); + if ( bits256_nonz(txid) == 0 ) + return(cJSON_Parse("{\"error\":\"null txid\"}")); if ( coin->electrum == 0 ) { sprintf(buf,"[\"%s\", %d, true]",bits256_str(str,txid),vout); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index a5204567c..dd79bb4e2 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -502,6 +502,8 @@ cJSON *electrum_getmerkle(char *symbol,struct electrum_info *ep,cJSON **retjsonp { char params[128],str[65]; sprintf(params,"[\"%s\", %d]",bits256_str(str,txid),height); + if ( bits256_nonz(txid) == 0 ) + return(cJSON_Parse("{\"error\":\"null txid\"}")); return(electrum_submit(symbol,ep,retjsonp,"blockchain.transaction.get_merkle",params,ELECTRUM_TIMEOUT)); } From d79d42663f16d3fde4024e96e7874674c83cb8f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 18:01:01 +0200 Subject: [PATCH 093/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 226e7a46d..51ff01bbf 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -607,6 +607,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, vout = jint(item,"vout"); vol = jdouble(item,"volume"); metric = price / bestprice; + printf("metric %f vol %f\n",metric,vol); if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { printf("got butxo? %p\n",butxo); From b6efc38aab2870f6f396e5258423b526d4254f44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 18:07:27 +0200 Subject: [PATCH 094/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 51ff01bbf..79551e8c1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -608,7 +608,8 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, vol = jdouble(item,"volume"); metric = price / bestprice; printf("metric %f vol %f\n",metric,vol); - if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) + // check utxos > 1 for pubkey + /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { printf("got butxo? %p\n",butxo); if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 ) @@ -655,7 +656,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, if ( butxo != 0 ) printf("%llu %llu %d %d %d: ",(long long)(vol*SATOSHIDEN),(long long)butxo->S.satoshis,vol*SATOSHIDEN == butxo->S.satoshis,LP_isavailable(butxo) > 0,LP_ismine(butxo) == 0); printf("cant find butxo.%p or value mismatch %.8f != %.8f or bestflag.%d\n",butxo,vol,butxo!=0?dstr(butxo->S.satoshis):0,butxo->T.bestflag); - } + }*/ } else printf("self trading or blacklisted peer\n"); } else From d8037e7b5dd49f5ad0ee8885504de7abd61c39ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 21:39:36 +0200 Subject: [PATCH 095/520] Test --- iguana/exchanges/LP_rpc.c | 2 ++ iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 70321218b..43ff407a2 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -139,6 +139,8 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) if ( coin != 0 ) { //printf("issue.(%s, %s, %s, %s, %s)\n",coin->symbol,coin->serverport,coin->userpass,method,params); + if ( coin->electrum != 0 && (strcmp(method,"getblock") == 0 || strcmp(method,"paxprice") == 0 || strcmp(method,"getrawmempool") == 0) ) + return(cJSON_Parse("{\"error\":\"illegal electrum call\"}")); if ( coin->inactive == 0 || strcmp(method,"importprivkey") == 0 || strcmp(method,"validateaddress") == 0 ) { if ( coin->electrum == 0 ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index dd79bb4e2..77b1c4004 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -644,7 +644,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) { *(ep->heightp) = height; *(ep->heighttimep) = (uint32_t)time(NULL); - printf("ELECTRUM >>>>>>>>> set height.%d\n",height); + printf("%s ELECTRUM >>>>>>>>> set height.%d\n",ep->symbol,height); } } idnum = juint(strjson,"id"); From 19ee1f5e4180f2e7299fb65e00d5e861be800bcc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 22:35:46 +0200 Subject: [PATCH 096/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 79551e8c1..566f5a8b6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -607,7 +607,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, vout = jint(item,"vout"); vol = jdouble(item,"volume"); metric = price / bestprice; - printf("metric %f vol %f\n",metric,vol); + printf("metric %f vol %f add pings, electrum cache\n",metric,vol); // check utxos > 1 for pubkey /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 77b1c4004..480b78d22 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -726,7 +726,7 @@ void LP_dedicatedloop(void *arg) } DL_APPEND(ep->pendingQ.list,&sitem->DL); portable_mutex_unlock(&ep->pendingQ.mutex);*/ - //printf("%p SEND.(%s) to %s:%u\n",sitem,sitem->str,ep->ipaddr,ep->port); + printf("%p SENT.(%s) to %s:%u\n",sitem,sitem->str,ep->ipaddr,ep->port); queue_enqueue("pendingQ",&ep->pendingQ,&sitem->DL); flag++; } From dad559237bb9a23f3bb7c5def65dc81a62816a7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 22:48:03 +0200 Subject: [PATCH 097/520] Test --- iguana/exchanges/LP_rpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 43ff407a2..69d4ad5ab 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -262,6 +262,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else { + printf("gettx\n"); sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { @@ -303,6 +304,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) } else { + printf("gettxout v%d\n",vout); sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); if ( (hexobj= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { From f0315e45adbe66266b2c72a3b170ca11d25e502b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 22:50:45 +0200 Subject: [PATCH 098/520] Test --- iguana/exchanges/LP_transaction.c | 2 ++ iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 51b6b2ec7..bead94605 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -799,6 +799,7 @@ int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vou { cJSON *retjson; coinaddr[0] = 0; + printf("LP_swap_getcoinaddr\n"); if ( (retjson= LP_gettx(symbol,txid)) != 0 ) { LP_txdestaddr(coinaddr,txid,vout,retjson); @@ -810,6 +811,7 @@ int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vou int32_t basilisk_swap_getsigscript(char *symbol,uint8_t *script,int32_t maxlen,bits256 txid,int32_t vini) { cJSON *retjson,*vins,*item,*skey; int32_t n,scriptlen = 0; char *hexstr; + printf("basilisk_swap_getsigscript\n"); if ( (retjson= LP_gettx(symbol,txid)) != 0 ) { if ( (vins= jarray(&n,retjson,"vin")) != 0 && vini < n ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 42388f807..83c149ad5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -412,7 +412,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { - //printf("TX.(%s)\n",jprint(txobj,0)); + printf("LP_transactioninit.(%s)\n",jprint(txobj,0)); if ( coin->electrum == 0 ) height = LP_txheight(coin,txid); else height = -1; From 3ceaa2820ced763b76ff1eeb070e0ed90bbbcfbe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 23:40:32 +0200 Subject: [PATCH 099/520] Fix duplicate gets --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_scan.c | 8 ++++---- iguana/exchanges/LP_socket.c | 6 +++--- iguana/exchanges/LP_transaction.c | 2 -- iguana/exchanges/LP_utxo.c | 22 ++++++++++++---------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 8e8f97c6f..5c27b039f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -300,7 +300,7 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr); int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); -int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); +int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 5f0b4175b..6d81a26c0 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -42,7 +42,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) if ( iter == 1 ) for (j=0; j<10; j++) { - if (LP_transactioninit(coin,txid,iter) == 0 ) + if (LP_transactioninit(coin,txid,iter,0) == 0 ) break; printf("transaction ht.%d init error.%d, pause\n",height,j); sleep(1); @@ -52,7 +52,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { for (j=0; j<10; j++) { - if (LP_transactioninit(coin,txid,iter) == 0 ) + if (LP_transactioninit(coin,txid,iter,0) == 0 ) break; printf("transaction ht.%d init error.%d, pause\n",height,j); sleep(1); @@ -435,8 +435,8 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) txid = jbits256i(array,i); if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { - LP_transactioninit(coin,txid,0); - LP_transactioninit(coin,txid,1); + LP_transactioninit(coin,txid,0,0); + LP_transactioninit(coin,txid,1,0); } if ( bits256_cmp(txid,searchtxid) == 0 ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 480b78d22..750ab4fe1 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -306,7 +306,7 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) int32_t electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *array) { - int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item; struct LP_transaction *tx; + int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; isymbol,txid)) != 0 ) + struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; + if ( txobj != 0 || (txobj= LP_gettx(coin->symbol,txid)) != 0 ) { - printf("LP_transactioninit.(%s)\n",jprint(txobj,0)); if ( coin->electrum == 0 ) height = LP_txheight(coin,txid); else height = -1; @@ -456,10 +455,13 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout); } } - free_json(txobj); - return(0); + if ( iter == 1 ) + { + free_json(txobj); + return(0); + } else return(txobj); } //else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid)); - return(-1); + return(0); } int32_t LP_txheight(struct iguana_info *coin,bits256 txid) @@ -532,7 +534,7 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { - struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65],_coinaddr[65]; + struct LP_transaction *tx; cJSON *txobj=0; uint64_t value; struct iguana_info *coin; char str[65],str2[65],_coinaddr[65]; if ( bits256_nonz(txid) == 0 ) return(0); if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) @@ -541,8 +543,8 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) coinaddr[0] = 0; if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { - LP_transactioninit(coin,txid,0); - LP_transactioninit(coin,txid,1); + txobj = LP_transactioninit(coin,txid,0,0); + LP_transactioninit(coin,txid,1,txobj); tx = LP_transactionfind(coin,txid); } if ( tx != 0 ) From 16dd1657e1157a57f3b073124bf2de65da970029 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 18 Sep 2017 23:41:27 +0200 Subject: [PATCH 100/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 5c27b039f..075669b2a 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -300,7 +300,7 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr); int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); -int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); +cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 5948ca276..f56c28fb2 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -407,7 +407,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf return(value); } -int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj) +cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj) { struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; cJSON *vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65]; if ( txobj != 0 || (txobj= LP_gettx(coin->symbol,txid)) != 0 ) From 8b2be4076d5a91fd681b3a79640654ae3a1a13ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 09:37:46 +0200 Subject: [PATCH 101/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 566f5a8b6..7984b3c13 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -608,7 +608,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, vol = jdouble(item,"volume"); metric = price / bestprice; printf("metric %f vol %f add pings, electrum cache\n",metric,vol); - // check utxos > 1 for pubkey + // check utxos > 1 for pubkey, SPV validate recv'ed /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { printf("got butxo? %p\n",butxo); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f56c28fb2..5212eac5b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -262,13 +262,13 @@ char *LP_postedutxos(cJSON *argjson) value = LP_value_extract(txobj,0); if ( value != val ) { - printf("REJECT %s %s/v%d value.%llu vs %llu\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val); + printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(item,0)); errs++; } ht = coin->height - jint(txobj,"confirmations"); if ( ht < height-2 ) { - printf("REJECT %s %s/v%d ht.%d vs %d\n",symbol,bits256_str(str,txid),v,ht,height); + printf("REJECT %s %s/v%d ht.%d vs %d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jprint(item,0)); errs++; } free_json(txobj); From 9a6e80c0732ba2489abe3ee2b09e942344e90815 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 09:39:40 +0200 Subject: [PATCH 102/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 750ab4fe1..8ae2565c2 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -620,7 +620,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - //printf("strjson.(%s)\n",jprint(strjson,0)); + printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 68069b33a90316c449e70eeb7840216e297da5c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 09:43:18 +0200 Subject: [PATCH 103/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 8ae2565c2..60571a6e6 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -26,7 +26,7 @@ #include #endif -#define ELECTRUM_TIMEOUT 3 +#define ELECTRUM_TIMEOUT 5 int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) { From 72158b0098d1563af406aeed0be8e026b3c105d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 09:47:23 +0200 Subject: [PATCH 104/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 5212eac5b..c7bac33cf 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -260,13 +260,13 @@ char *LP_postedutxos(cJSON *argjson) if ( coin->electrum == 0 && (txobj= LP_gettxout(symbol,txid,v)) != 0 ) { value = LP_value_extract(txobj,0); - if ( value != val ) + if ( value != 0 && value != val ) { printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(item,0)); errs++; } ht = coin->height - jint(txobj,"confirmations"); - if ( ht < height-2 ) + if ( ht != 0 && ht < height-2 ) { printf("REJECT %s %s/v%d ht.%d vs %d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jprint(item,0)); errs++; From 9439c26ee097e385d81f5669030409db16d1088a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 09:54:19 +0200 Subject: [PATCH 105/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 60571a6e6..685ca92f7 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -620,7 +620,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - printf("strjson.(%s)\n",jprint(strjson,0)); + //printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 569a3a0861661f7a322b9c77d11a83b76d903352 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 09:59:39 +0200 Subject: [PATCH 106/520] Test --- iguana/exchanges/LP_utxo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c7bac33cf..6ae0c00b6 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -265,7 +265,9 @@ char *LP_postedutxos(cJSON *argjson) printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(item,0)); errs++; } - ht = coin->height - jint(txobj,"confirmations"); + if ( coin->height != 0 ) + ht = coin->height - jint(txobj,"confirmations"); + else ht = 0; if ( ht != 0 && ht < height-2 ) { printf("REJECT %s %s/v%d ht.%d vs %d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jprint(item,0)); From a7582f93246d3a67d97798d40eab5c9a890b2423 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 10:00:20 +0200 Subject: [PATCH 107/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 685ca92f7..08765352f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -726,7 +726,7 @@ void LP_dedicatedloop(void *arg) } DL_APPEND(ep->pendingQ.list,&sitem->DL); portable_mutex_unlock(&ep->pendingQ.mutex);*/ - printf("%p SENT.(%s) to %s:%u\n",sitem,sitem->str,ep->ipaddr,ep->port); + //printf("%p SENT.(%s) to %s:%u\n",sitem,sitem->str,ep->ipaddr,ep->port); queue_enqueue("pendingQ",&ep->pendingQ,&sitem->DL); flag++; } From f03ffc970e3abe9fc931e824203990ff29a37c72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 10:02:23 +0200 Subject: [PATCH 108/520] Test --- iguana/exchanges/LP_rpc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 69d4ad5ab..a4b22b12f 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -262,7 +262,6 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else { - printf("gettx\n"); sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { From ddf24ad58478a2bc94e7cd69dcc0f36e4c072176 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 10:10:07 +0200 Subject: [PATCH 109/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7984b3c13..c5ec092f1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -607,7 +607,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, vout = jint(item,"vout"); vol = jdouble(item,"volume"); metric = price / bestprice; - printf("metric %f vol %f add pings, electrum cache\n",metric,vol); + printf("metric %f vol %f add pings numutxos.%d min %.8f max %.8f\n",metric,vol,jint(item,"numutxos"),jdouble(item,"minvolume"),jdouble(item,"maxvolume")); // check utxos > 1 for pubkey, SPV validate recv'ed /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { From 83978a01626cd3a7636df9f635528da4a050454c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 10:54:10 +0200 Subject: [PATCH 110/520] Test --- iguana/exchanges/LP_rpc.c | 17 ++++++++++++++++- iguana/exchanges/LP_transaction.c | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index a4b22b12f..71330a93a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -266,6 +266,12 @@ cJSON *LP_gettx(char *symbol,bits256 txid) if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); + if ( strlen(hexstr) > 50000 ) + { + printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); + free(hexstr); + return(cJSON_Parse("{\"error\":\"transaction too big\"}")); + } if ( hexstr[0] == '"' && hexstr[strlen(hexstr)-1] == '"' ) hexstr[strlen(hexstr)-1] = 0; if ( (len= is_hexstr(hexstr+1,0)) > 2 ) @@ -274,6 +280,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) len = (int32_t)strlen(hexstr+1) >> 1; serialized = malloc(len); decode_hex(serialized,len,hexstr+1); + free(hexstr); //printf("DATA.(%s)\n",hexstr+1); extraspace = calloc(1,1000000); retjson = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,1000000,serialized,len,0,0); @@ -282,6 +289,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) //printf("TX.(%s) match.%d\n",jprint(retjson,0),bits256_cmp(txid,checktxid)); return(retjson); } else printf("non-hex tx.(%s)\n",hexstr); + free(hexstr); return(cJSON_Parse("{\"error\":\"non hex transaction\"}")); } else printf("failed blockcjhain.transaction.get\n"); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); @@ -308,6 +316,12 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) if ( (hexobj= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(hexobj,1); + if ( strlen(hexstr) > 50000 ) + { + printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); + free(hexstr); + return(cJSON_Parse("{\"error\":\"transaction too big\"}")); + } if ( hexstr[0] == '"' && hexstr[strlen(hexstr)-1] == '"' ) hexstr[strlen(hexstr)-1] = 0; if ( (len= is_hexstr(hexstr+1,0)) > 2 ) @@ -317,6 +331,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) decode_hex(serialized,len,hexstr+1); LP_swap_coinaddr(coin,coinaddr,&value,serialized,len,vout); //printf("HEX.(%s) len.%d %s %.8f\n",hexstr+1,len,coinaddr,dstr(value)); + free(hexstr); if ( (array= electrum_address_listunspent(coin->symbol,0,&array,coinaddr)) != 0 ) { //printf("array.(%s)\n",jprint(array,0)); @@ -365,7 +380,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) } free_json(array); } - } + } else free(hexstr); return(retjson); } return(cJSON_Parse("{\"error\":\"couldnt get tx\"}")); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 51b6b2ec7..02c005b29 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -396,7 +396,7 @@ int64_t iguana_lockval(int32_t finalized,int64_t locktime) int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson) { - uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 65536; char *privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0; + uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 100000; char *privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0; maxsize = 1000000; memset(privkey.bytes,0,sizeof(privkey)); if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize ) @@ -417,7 +417,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ { //printf("numinputs.%d msgtx.%d\n",numinputs,msgtx->tx_in); memset(msgtx,0,sizeof(*msgtx)); - if ( iguana_rwmsgtx(taddr,pubtype,p2shtype,isPoS,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) + if ( iguana_rwmsgtx(taddr,pubtype,p2shtype,isPoS,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,extralen,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in ) { memset(pubkeys,0,sizeof(pubkeys)); memset(privkeys,0,sizeof(privkeys)); From e23d904fe7d132ac10909bde02c4e375e6fc947f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 10:57:38 +0200 Subject: [PATCH 111/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 075669b2a..99381bfe9 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -267,7 +267,7 @@ struct basilisk_swap struct basilisk_swapmessage *messages; int32_t nummessages,sentflag; char Bdeposit[64],Bpayment[64]; uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; - uint8_t persistent_pubkey33[33],changermd160[20],pad[15],verifybuf[65536]; + uint8_t persistent_pubkey33[33],changermd160[20],pad[15],verifybuf[100000]; }; diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 08765352f..c1cf15f3c 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -26,7 +26,7 @@ #include #endif -#define ELECTRUM_TIMEOUT 5 +#define ELECTRUM_TIMEOUT 10 int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) { From 26c1ea9b8d9a306ae9c82bbe04a5d927c0068608 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:12:15 +0200 Subject: [PATCH 112/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c5ec092f1..786b05f0c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -607,7 +607,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, vout = jint(item,"vout"); vol = jdouble(item,"volume"); metric = price / bestprice; - printf("metric %f vol %f add pings numutxos.%d min %.8f max %.8f\n",metric,vol,jint(item,"numutxos"),jdouble(item,"minvolume"),jdouble(item,"maxvolume")); + printf("maxdest %.8f metric %f vol %f add pings numutxos.%d min %.8f max %.8f\n",dstr(maxdestsatoshis),metric,vol,jint(item,"numutxos"),jdouble(item,"minvolume"),jdouble(item,"maxvolume")); // check utxos > 1 for pubkey, SPV validate recv'ed /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index deef1f3a9..1d6971004 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -636,7 +636,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * } }*/ } - printf("pubp.(%s) %.8f %p\n",coinaddr,price,ap); + //printf("pubp.(%s) %.8f %p\n",coinaddr,price,ap); } return(num); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index c1cf15f3c..a778d0c9d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -26,7 +26,7 @@ #include #endif -#define ELECTRUM_TIMEOUT 10 +#define ELECTRUM_TIMEOUT 3 int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) { From 49dd22bd017374fe402c9a962d639ae9f9ef4c73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:21:07 +0200 Subject: [PATCH 113/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 --- iguana/exchanges/LP_prices.c | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 786b05f0c..255ac95ca 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -718,13 +718,10 @@ char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,ch desttxfee = LP_txfeecalc(LP_coinfind(rel),desttxfee); if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxopair\"}")); - printf("call LP_bestutxo\n"); if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); - printf("call LP_quoteinfoinit\n"); if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - printf("call LP_quotedestinfo\n"); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); return(jprint(LP_quotejson(&Q),1)); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 1d6971004..84f91ce0e 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -18,7 +18,7 @@ // marketmaker // -struct LP_orderbookentry { bits256 pubkey; double price; uint64_t basesatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; +struct LP_orderbookentry { bits256 pubkey; double price; uint64_t minsatoshis,maxsatoshis; uint32_t timestamp; int32_t numutxos; char coinaddr[64]; }; #define LP_MAXPRICEINFOS 256 struct LP_priceinfo @@ -539,8 +539,10 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); - jaddnum(item,"minvolume",dstr(op->basesatoshis)); - jaddnum(item,"maxvolume",dstr(op->maxsatoshis)); + if ( op->minsatoshis != 0 ) + jaddnum(item,"minvolume",1./dstr(op->minsatoshis)); + if ( op->maxsatoshis != 0 ) + jaddnum(item,"maxvolume",1./dstr(op->maxsatoshis)); //jaddbits256(item,"txid",op->txid); //jaddnum(item,"vout",op->vout); jaddbits256(item,"pubkey",op->pubkey); @@ -549,7 +551,7 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) return(item); } -struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) +struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t minsatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp) { struct LP_orderbookentry *op; if ( (op= calloc(1,sizeof(*op))) != 0 ) @@ -561,7 +563,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d safecopy(op->coinaddr,address,sizeof(op->coinaddr)); op->price = price; op->numutxos = numutxos; - op->basesatoshis = basesatoshis; + op->minsatoshis = minsatoshis; op->maxsatoshis = maxsatoshis; op->pubkey = pubkey; op->timestamp = timestamp; @@ -580,7 +582,7 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) { - char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t basesatoshis,maxsatoshis; + char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t minsatoshis,maxsatoshis; if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) baseid = basepp->ind; else return(num); @@ -596,25 +598,25 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) continue; bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - basesatoshis = maxsatoshis = n = 0; + minsatoshis = maxsatoshis = n = 0; ap = 0; //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); //if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) //if ( polarity > 0 ) - // basesatoshis = utxo->S.satoshis; - //else basesatoshis = utxo->S.satoshis * price; + // minsatoshis = utxo->S.satoshis; + //else minsatoshis = utxo->S.satoshis * price; if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL ) { if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { - n = LP_address_minmax(&basesatoshis,&maxsatoshis,ap); + n = LP_address_minmax(&minsatoshis,&maxsatoshis,ap); if ( polarity < 0 ) { - basesatoshis *= price; + minsatoshis *= price; maxsatoshis *= price; } } - if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,basesatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) + if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); (*arrayp)[num++] = op; From 9759b211e843d9219f29995b02937f07b04025c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:23:42 +0200 Subject: [PATCH 114/520] Test --- iguana/exchanges/LP_prices.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 84f91ce0e..0e3397bdd 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -539,10 +539,10 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); - if ( op->minsatoshis != 0 ) - jaddnum(item,"minvolume",1./dstr(op->minsatoshis)); - if ( op->maxsatoshis != 0 ) - jaddnum(item,"maxvolume",1./dstr(op->maxsatoshis)); + //if ( op->minsatoshis != 0 ) + jaddnum(item,"minvolume",dstr(op->minsatoshis)); + //if ( op->maxsatoshis != 0 ) + jaddnum(item,"maxvolume",dstr(op->maxsatoshis)); //jaddbits256(item,"txid",op->txid); //jaddnum(item,"vout",op->vout); jaddbits256(item,"pubkey",op->pubkey); @@ -610,11 +610,11 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { n = LP_address_minmax(&minsatoshis,&maxsatoshis,ap); - if ( polarity < 0 ) + /*if ( polarity < 0 ) { minsatoshis *= price; maxsatoshis *= price; - } + }*/ } if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { From 0cec1db87e83fc032e810443974224ed7da2c578 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:26:08 +0200 Subject: [PATCH 115/520] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0e3397bdd..862a6e4c4 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -610,11 +610,11 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { n = LP_address_minmax(&minsatoshis,&maxsatoshis,ap); - /*if ( polarity < 0 ) + if ( polarity < 0 ) { minsatoshis *= price; maxsatoshis *= price; - }*/ + } } if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { From c6696a99d0429928f04be793fc4f7d37929fa2f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:28:02 +0200 Subject: [PATCH 116/520] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 862a6e4c4..e1b5b1da7 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -610,7 +610,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) { n = LP_address_minmax(&minsatoshis,&maxsatoshis,ap); - if ( polarity < 0 ) + if ( polarity > 0 ) { minsatoshis *= price; maxsatoshis *= price; From 5b2b57cdc83613b71df5e76bd2a2bf51bcd9be4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:31:43 +0200 Subject: [PATCH 117/520] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index e1b5b1da7..3ce4164a1 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -678,7 +678,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=n=0; inumutxos == 0 && (n == 0 || relcoin->electrum == 0) ) + if ( bids[i]->numutxos == 0 && relcoin->electrum == 0 ) LP_address(relcoin,bids[i]->coinaddr), n++; free(bids[i]); bids[i] = 0; @@ -689,7 +689,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=n=0; inumutxos == 0 && (n == 0 || basecoin->electrum == 0) ) + if ( asks[i]->numutxos == 0 && basecoin->electrum == 0 ) LP_address(basecoin,asks[i]->coinaddr), n++; free(asks[i]); asks[i] = 0; From 71c3f448ebbc0abb27939fddf1097eccb9c5f779 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:38:48 +0200 Subject: [PATCH 118/520] Test --- iguana/exchanges/LP_prices.c | 30 ++++++++++++++++++++++++++++-- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 3ce4164a1..54151f67a 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -524,7 +524,33 @@ static int _cmp_orderbook(const void *a,const void *b) else if ( ptr_b < ptr_a ) return(1); } - // printf("%.8f vs %.8f -> %d\n",ptr_a,ptr_b,retval); + // printf("%.8f vs %.8f -> %d\n",ptr_a,ptr_b,retval); + return(retval); +#undef ptr_a +#undef ptr_b +} + +static int _revcmp_orderbook(const void *a,const void *b) +{ + int32_t retval = 0; +#define ptr_a (*(struct LP_orderbookentry **)a)->price +#define ptr_b (*(struct LP_orderbookentry **)b)->price + if ( ptr_b > ptr_a ) + retval = 1; + else if ( ptr_b < ptr_a ) + retval = -1; + else + { +#undef ptr_a +#undef ptr_b +#define ptr_a ((struct LP_orderbookentry *)a)->maxsatoshis +#define ptr_b ((struct LP_orderbookentry *)b)->maxsatoshis + if ( ptr_b > ptr_a ) + return(-1); + else if ( ptr_b < ptr_a ) + return(1); + } + // printf("%.8f vs %.8f -> %d\n",ptr_a,ptr_b,retval); return(retval); #undef ptr_a #undef ptr_b @@ -664,7 +690,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) retjson = cJSON_CreateObject(); array = cJSON_CreateArray(); if ( numbids > 1 ) - qsort(bids,numbids,sizeof(*bids),_cmp_orderbook); + qsort(bids,numbids,sizeof(*bids),_revcmp_orderbook); if ( numasks > 1 ) { //for (i=0; ioutpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); if ( strcmp(coin->symbol,"BTC") != 0 ) printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); - } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); + } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d spendheight.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts,tx->outpoints[spentvout].spendheight); } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); if ( bits256_cmp(spenttxid,txid) == 0 ) printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout); From 9280314f649f7e493f302aefd5d4ed9ef3368952 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:39:39 +0200 Subject: [PATCH 119/520] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 54151f67a..afce2549e 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -704,7 +704,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=n=0; inumutxos == 0 && relcoin->electrum == 0 ) + if ( bids[i]->numutxos == 0 || relcoin->electrum == 0 ) LP_address(relcoin,bids[i]->coinaddr), n++; free(bids[i]); bids[i] = 0; @@ -715,7 +715,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=n=0; inumutxos == 0 && basecoin->electrum == 0 ) + if ( asks[i]->numutxos == 0 || basecoin->electrum == 0 ) LP_address(basecoin,asks[i]->coinaddr), n++; free(asks[i]); asks[i] = 0; From 2d27f58802c5246f13b051c69e6f4d15c6b0e335 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:39:56 +0200 Subject: [PATCH 120/520] Test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index afce2549e..fbcd54749 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -704,7 +704,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=n=0; inumutxos == 0 || relcoin->electrum == 0 ) + if ( bids[i]->numutxos == 0 )//|| relcoin->electrum == 0 ) LP_address(relcoin,bids[i]->coinaddr), n++; free(bids[i]); bids[i] = 0; @@ -715,7 +715,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) for (i=n=0; inumutxos == 0 || basecoin->electrum == 0 ) + if ( asks[i]->numutxos == 0 )//|| basecoin->electrum == 0 ) LP_address(basecoin,asks[i]->coinaddr), n++; free(asks[i]); asks[i] = 0; From d5b31da179834c2d3f7fd0dee7ad7de42ccb0ccf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 11:53:52 +0200 Subject: [PATCH 121/520] Test --- iguana/exchanges/LP_coins.c | 7 ++++++- iguana/exchanges/LP_prices.c | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 6f0b1d76d..6ab37355c 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -172,7 +172,7 @@ int32_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot,c cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) { - char wifstr[128]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); + struct electrum_info *ep; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); jaddstr(item,"coin",coin->symbol); if ( showwif != 0 ) { @@ -187,6 +187,11 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) else jaddstr(item,"status","active"); if ( coin->isPoS != 0 ) jaddstr(item,"type","PoS"); + if ( (ep= coin->electrum) != 0 ) + { + sprintf(ipaddr,"%s:%u",ep->ipaddr,ep->port); + jaddstr(item,"electrum",ipaddr); + } jaddstr(item,"smartaddress",coin->smartaddr); jaddstr(item,"rpc",coin->serverport); jaddnum(item,"pubtype",coin->pubtype); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index fbcd54749..430448a29 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -709,6 +709,8 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) free(bids[i]); bids[i] = 0; } + if ( n > 0 && relcoin->lastmonitor > 3600 ) + relcoin->lastmonitor -= 3600; jadd(retjson,"bids",array); jaddnum(retjson,"numbids",numbids); array = cJSON_CreateArray(); @@ -720,10 +722,8 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) free(asks[i]); asks[i] = 0; } - if ( basecoin->lastmonitor > 3600 ) + if ( n > 0 && basecoin->lastmonitor > 3600 ) basecoin->lastmonitor -= 3600; - if ( relcoin->lastmonitor > 3600 ) - relcoin->lastmonitor -= 3600; jadd(retjson,"asks",array); jaddnum(retjson,"numasks",numasks); jaddstr(retjson,"base",base); From c6cd9723e0faa5f4ac2511939d378db4b86079f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 14:02:16 +0200 Subject: [PATCH 122/520] Test --- iguana/exchanges/LP_commands.c | 21 ++- iguana/exchanges/LP_ordermatch.c | 213 +++++++++++++++++++++++++++++-- iguana/exchanges/LP_portfolio.c | 2 +- iguana/exchanges/LP_utxo.c | 15 +++ iguana/exchanges/buy | 2 + iguana/exchanges/install | 2 +- iguana/exchanges/sell | 2 + 7 files changed, 238 insertions(+), 19 deletions(-) create mode 100755 iguana/exchanges/buy create mode 100755 iguana/exchanges/sell diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 8dd2fc418..57718f917 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -103,9 +103,8 @@ enable(coin)\n\ disable(coin)\n\ inventory(coin)\n\ bestfit(rel, relvolume)\n\ -ordermatch(base, txfee=0, rel, desttxfee=0, price, relvolume=0, txid, vout, feetxid, feevout, duration=3600)\n\ -trade(price, timeout=10, duration=3600, )\n\ -autotrade(base, rel, price, relvolume, timeout=10, duration=3600)\n\ +buy(base, rel, price, relvolume, timeout=10, duration=3600)\n\ +sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ swapstatus()\n\ swapstatus(requestid, quoteid)\n\ public API:\n \ @@ -212,7 +211,7 @@ dividends(coin, height, )\n\ return(jprint(retjson,1)); } else return(clonestr("{\"error\":\"no price set\"}")); } - else if ( strcmp(method,"ordermatch") == 0 ) + /*else if ( strcmp(method,"ordermatch") == 0 ) { if ( price > SMALLVAL ) return(LP_ordermatch(base,j64bits(argjson,"txfee"),price,jdouble(argjson,"relvolume"),rel,jbits256(argjson,"txid"),jint(argjson,"vout"),jbits256(argjson,"feetxid"),jint(argjson,"feevout"),j64bits(argjson,"desttxfee"),jint(argjson,"duration"))); @@ -233,6 +232,20 @@ dividends(coin, height, )\n\ { return(LP_autotrade(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"))); } else return(clonestr("{\"error\":\"no price set\"}")); + }*/ + else if ( strcmp(method,"buy") == 0 ) + { + if ( price > SMALLVAL ) + { + return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); + } else return(clonestr("{\"error\":\"no price set\"}")); + } + else if ( strcmp(method,"sell") == 0 ) + { + if ( price > SMALLVAL ) + { + return(LP_autosell(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"))); + } else return(clonestr("{\"error\":\"no price set\"}")); } } else if ( rel != 0 && strcmp(method,"bestfit") == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 255ac95ca..30d656dc5 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -572,6 +572,17 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(retval); } +char *LP_bestfit(char *rel,double relvolume) +{ + struct LP_utxoinfo *autxo; + if ( relvolume <= 0. || LP_priceinfofind(rel) == 0 ) + return(clonestr("{\"error\":\"invalid parameter\"}")); + if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) + return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); + return(jprint(LP_utxojson(autxo),1)); +} + +#ifdef oldway struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,uint64_t maxdestsatoshis) { int64_t satoshis,destsatoshis; uint64_t val,val2; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item; struct LP_utxoinfo *butxo,*bestutxo = 0; int32_t i,n,j,vout,numasks; double bestmetric=0.,metric,vol,price,qprice,bestprice = 0.; struct LP_pubkeyinfo *pubp; @@ -701,16 +712,6 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, return(bestutxo); } -char *LP_bestfit(char *rel,double relvolume) -{ - struct LP_utxoinfo *autxo; - if ( relvolume <= 0. || LP_priceinfofind(rel) == 0 ) - return(clonestr("{\"error\":\"invalid parameter\"}")); - if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) - return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); - return(jprint(LP_utxojson(autxo),1)); -} - char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,char *rel,bits256 txid,int32_t vout,bits256 feetxid,int32_t feevout,int64_t desttxfee,int32_t duration) { struct LP_quoteinfo Q; int64_t bestsatoshis=0,bestdestsatoshis = 0; double ordermatchprice = 0.; struct LP_utxoinfo *autxo,*bestutxo; @@ -727,6 +728,37 @@ char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,ch return(jprint(LP_quotejson(&Q),1)); } +char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration) +{ + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + if ( duration <= 0 ) + duration = LP_ORDERBOOK_DURATION; + if ( timeout <= 0 ) + timeout = LP_AUTOTRADE_TIMEOUT; + if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) + return(clonestr("{\"error\":\"invalid parameter\"}")); + if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) + return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); + LP_txfees(&txfee,&desttxfee,base,rel); + if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*relvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + { + printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); + return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); + } + if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + { + printf("quote validate error %.0f\n",qprice); + return(clonestr("{\"error\":\"quote validation error\"}")); + } + printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); +} +#endif + char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration) { struct LP_utxoinfo *bobutxo,*aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; @@ -784,9 +816,132 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(jprint(bestitem,0)); } -char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration) +int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t targetval) { - uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + int32_t i,mini = -1; int64_t dist; uint64_t mindist = (1LL << 60); + for (i=0; iU.value - targetval); + //printf("(%.8f %.8f %.8f).%d ",dstr(values[i]),dstr(dist),dstr(mindist),mini); + if ( dist >= 0 && dist < mindist ) + { + mini = i; + mindist = dist; + } + } + } + return(mini); +} + +struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price) +{ + struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; + if ( (ap= LP_addressfind(coin,coinaddr)) != 0 ) + { + if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) + { + targetval = SATOSHIDEN * (relvolume / price) + 2*txfee; + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) + { + up = utxos[mini]; + utxos[mini] = 0; + targetval = (targetval / 8) * 9 + 2*txfee; + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) + { + if ( up != 0 && (up2= utxos[mini]) != 0 ) + { + safecopy(utxo->coin,coin->symbol,sizeof(utxo->coin)); + safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); + utxo->payment.txid = up->U.txid; + utxo->payment.vout = up->U.vout; + utxo->payment.value = up->U.value; + utxo->iambob = 1; + utxo->deposit.txid = up2->U.txid; + utxo->deposit.vout = up2->U.vout; + utxo->deposit.value = up2->U.value; + utxo->S.satoshis = SATOSHIDEN * (relvolume / price); + return(utxo); + } + } + } + } + } + return(0); +} + +struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) +{ + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + *ordermatchpricep = 0.; + *bestsatoshisp = *bestdestsatoshisp = 0; + basecoin = LP_coinfind(base); + if ( duration <= 0 ) + duration = LP_ORDERBOOK_DURATION; + if ( maxprice <= 0. || LP_priceinfofind(base) == 0 || basecoin == 0 ) + return(0); + utxos = calloc(max,sizeof(*utxos)); + LP_txfees(&txfee,&desttxfee,base,autxo->coin); + if ( (obookstr= LP_orderbook(base,autxo->coin,duration)) != 0 ) + { + if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) + { + if ( (asks= jarray(&numasks,orderbook,"asks")) != 0 ) + { + for (i=0; i 0 && price <= maxprice ) + { + pubkey = jbits256(item,"pubkey"); + if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) + { + if ( (n= jint(item,"numutxos")) > 1 ) + { + minvol = jdouble(item,"minvolume"); + maxvol = jdouble(item,"maxvolume"); + if ( relvolume >= minvol && relvolume <= maxvol ) + { + bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price)) != 0 ) + { + bestutxo->pubkey = pubp->pubkey; + safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); + *bestsatoshisp = bestutxo->S.satoshis; + *ordermatchpricep = price; + *bestdestsatoshisp = autxo->S.satoshis; + printf("ordermatch %.8f %.8f %.8f\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp)); + break; + } + } + } + } else printf("self trading or blacklisted peer\n"); + } + else + { + if ( i == 0 ) + printf("too expensive maxprice %.8f vs %.8f\n",maxprice,price); + break; + } + } + } + free_json(orderbook); + } + free(obookstr); + } + free(utxos); + if ( *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) + return(0); + int32_t changed; + LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep); + return(bestutxo); +} + +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) +{ + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; if ( timeout <= 0 ) @@ -796,7 +951,39 @@ char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *r if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); LP_txfees(&txfee,&desttxfee,base,rel); - if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*relvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + memset(&_best,0,sizeof(_best)); + if ( (bestutxo= LP_buyutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,relvolume,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + { + printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); + return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); + } + if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + { + printf("quote validate error %.0f\n",qprice); + return(clonestr("{\"error\":\"quote validation error\"}")); + } + printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); + return(clonestr("{\"result\":\"success\"}")); + //return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); +} + +char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double basevolume,int32_t timeout,int32_t duration) +{ + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + if ( duration <= 0 ) + duration = LP_ORDERBOOK_DURATION; + if ( timeout <= 0 ) + timeout = LP_AUTOTRADE_TIMEOUT; + if ( maxprice <= 0. || basevolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) + return(clonestr("{\"error\":\"invalid parameter\"}")); + if ( (autxo= LP_utxo_bestfit(base,SATOSHIDEN * basevolume)) == 0 ) + return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); + LP_txfees(&txfee,&desttxfee,base,rel); + //if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*basevolume*maxprice)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) { printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 15263a593..c7fcd1a04 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -437,7 +437,7 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str break; if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 ) { - if ( (retstr2= LP_autotrade(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600)) != 0 ) + if ( (retstr2= LP_autobuy(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600)) != 0 ) { if ( (retjson2= cJSON_Parse(retstr2)) != 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 718c46673..cff304b07 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -131,6 +131,21 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) return(n); } +int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap) +{ + struct LP_address_utxo *up,*tmp; int32_t n = 0; + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( up->spendheight <= 0 ) + { + utxos[n++] = up; + if ( n >= max ) + break; + } + } + return(n); +} + int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; diff --git a/iguana/exchanges/buy b/iguana/exchanges/buy new file mode 100755 index 000000000..4bed65f19 --- /dev/null +++ b/iguana/exchanges/buy @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"buy\",\"base\":\"KMD\",\"rel\":\"BTC\",\"relvolume\":0.005,\"price\":0.0005}" diff --git a/iguana/exchanges/install b/iguana/exchanges/install index 1b7a629d9..bda13d6ef 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,4 +1,4 @@ -cp electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall trade ordermatch bestfit orderbook autotrade client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts +cp electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir diff --git a/iguana/exchanges/sell b/iguana/exchanges/sell new file mode 100755 index 000000000..5f48ff299 --- /dev/null +++ b/iguana/exchanges/sell @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"BTC\",\"basevolume\":10.0\"price\":0.0005}" From 6126770bbbeda431c85e15cb7055ae45e80de8eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 14:05:14 +0200 Subject: [PATCH 123/520] Test --- iguana/exchanges/LP_portfolio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index c7fcd1a04..018f293da 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -415,7 +415,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) } } -int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,struct iguana_info *buy,struct iguana_info *sell,double relvolume,int32_t setbaserel) +int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,struct iguana_info *buy,struct iguana_info *sell,double relvolume,int32_t setbaserel,char *gui) { char *retstr2; double bid,ask,maxprice; uint32_t requestid,quoteid,iter,i; cJSON *retjson2; requestid = quoteid = 0; @@ -437,7 +437,7 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str break; if ( LP_utxo_bestfit(sell->symbol,SATOSHIDEN * relvolume) != 0 ) { - if ( (retstr2= LP_autobuy(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600)) != 0 ) + if ( (retstr2= LP_autobuy(ctx,"127.0.0.1",-1,buy->symbol,sell->symbol,maxprice,relvolume,60,24*3600,gui)) != 0 ) { if ( (retjson2= cJSON_Parse(retstr2)) != 0 ) { @@ -546,7 +546,7 @@ void prices_loop(void *ignore) { if ( (buycoin= jstr(retjson,"buycoin")) != 0 && (buy= LP_coinfind(buycoin)) != 0 && (sellcoin= jstr(retjson,"sellcoin")) != 0 && (sell= LP_coinfind(sellcoin)) != 0 && buy->inactive == 0 && sell->inactive == 0 ) { - if ( LP_portfolio_trade(ctx,&requestid,"eid,buy,sell,sell->relvolume,1) < 0 ) + if ( LP_portfolio_trade(ctx,&requestid,"eid,buy,sell,sell->relvolume,1,"portfolio") < 0 ) { array = jarray(&m,retjson,"portfolio"); if ( array != 0 && (n= LP_portfolio_order(trades,(int32_t)(sizeof(trades)/sizeof(*trades)),array)) > 0 ) @@ -557,7 +557,7 @@ void prices_loop(void *ignore) { buy = LP_coinfind(trades[i].buycoin); sell = LP_coinfind(trades[i].sellcoin); - if ( buy != 0 && sell != 0 && LP_portfolio_trade(ctx,&requestid,"eid,buy,sell,sell->relvolume,0) == 0 ) + if ( buy != 0 && sell != 0 && LP_portfolio_trade(ctx,&requestid,"eid,buy,sell,sell->relvolume,0,"portfolio") == 0 ) break; } } From deb7f0d4167a71494d34898edd37c59daeebde05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 14:10:51 +0200 Subject: [PATCH 124/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 30d656dc5..e48bbe8ac 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -942,6 +942,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr 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) { uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + printf("LP_autobuy\n"); if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; if ( timeout <= 0 ) From db7de81410cd15cb422e7bd3d9d183826c2a747f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 14:12:12 +0200 Subject: [PATCH 125/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index cff304b07..064db834e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -126,7 +126,7 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) n++; } } - if ( n > 0 ) + if ( 0 && n > 0 ) printf("n.%d %s min %.8f max %.8f\n",n,ap->coinaddr,dstr(*minp),dstr(*maxp)); return(n); } From c5c4bcb30612c0761b2220bdeac912fa48512c94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 14:21:14 +0200 Subject: [PATCH 126/520] Test --- iguana/exchanges/LP_ordermatch.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e48bbe8ac..ad76899eb 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -257,10 +257,9 @@ int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp) return(0); } -double LP_quote_validate(struct LP_utxoinfo **autxop,struct LP_utxoinfo **butxop,struct LP_quoteinfo *qp,int32_t iambob) +double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp,int32_t iambob) { double qprice; uint64_t txfee,desttxfee,srcvalue,srcvalue2,destvalue,destvalue2; - *autxop = *butxop = 0; if ( LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) { printf("bob not eligible\n"); @@ -273,19 +272,19 @@ double LP_quote_validate(struct LP_utxoinfo **autxop,struct LP_utxoinfo **butxop } if ( LP_quote_checkmempool(qp) < 0 ) return(-4); - if ( (*butxop= LP_utxofind(1,qp->txid,qp->vout)) == 0 ) - return(-5); - if ( bits256_cmp((*butxop)->deposit.txid,qp->txid2) != 0 || (*butxop)->deposit.vout != qp->vout2 ) + //if ( iambob != 0 && (*butxop= LP_utxofind(1,qp->txid,qp->vout)) == 0 ) + // return(-5); + if ( bits256_cmp(butxo->deposit.txid,qp->txid2) != 0 || butxo->deposit.vout != qp->vout2 ) return(-6); - if ( strcmp((*butxop)->coinaddr,qp->coinaddr) != 0 ) + if ( strcmp(butxo->coinaddr,qp->coinaddr) != 0 ) return(-7); if ( iambob == 0 ) { - if ( (*autxop= LP_utxofind(0,qp->desttxid,qp->destvout)) == 0 ) - return(-8); - if ( bits256_cmp((*autxop)->fee.txid,qp->feetxid) != 0 || (*autxop)->fee.vout != qp->feevout ) + //if ( (*autxop= LP_utxofind(0,qp->desttxid,qp->destvout)) == 0 ) + // return(-8); + if ( bits256_cmp(autxo->fee.txid,qp->feetxid) != 0 || autxo->fee.vout != qp->feevout ) return(-9); - if ( strcmp((*autxop)->coinaddr,qp->destaddr) != 0 ) + if ( strcmp(autxo->coinaddr,qp->destaddr) != 0 ) return(-10); } if ( destvalue < qp->desttxfee+qp->destsatoshis || srcvalue < qp->txfee+qp->satoshis ) @@ -446,7 +445,7 @@ char *LP_connectedalice(cJSON *argjson) // alice if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 ) return(clonestr("{\"result\",\"update stats\"}")); printf("CONNECTED.(%s)\n",jprint(argjson,0)); - if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + //if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); LP_pendingswaps--; @@ -529,7 +528,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,1)) <= SMALLVAL ) + //if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); return(-4); @@ -941,7 +940,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr 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) { - uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; printf("LP_autobuy\n"); if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; @@ -962,7 +961,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + if ( (qprice= LP_quote_validate(autxo,bestutxo,&Q,0)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); @@ -993,7 +992,7 @@ char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *re return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); From 39a4b60283571781ee81819b089ed89c147eb57e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 14:28:38 +0200 Subject: [PATCH 127/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ad76899eb..155b490e5 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -908,6 +908,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); + autxo->S.satoshis = bestutxo->S.satoshis * price; *bestsatoshisp = bestutxo->S.satoshis; *ordermatchpricep = price; *bestdestsatoshisp = autxo->S.satoshis; From a36e48c3cb30e8d7f5a16b3d5f2c3ce25b872240 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:03:38 +0200 Subject: [PATCH 128/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_ordermatch.c | 99 +++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 57718f917..c97693008 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -244,7 +244,7 @@ dividends(coin, height, )\n\ { if ( price > SMALLVAL ) { - return(LP_autosell(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"))); + return(LP_autosell(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 155b490e5..ea5a703ad 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -760,15 +760,15 @@ char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *r char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration) { - struct LP_utxoinfo *bobutxo,*aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; + struct LP_utxoinfo *aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; if ( (aliceutxo= LP_utxopairfind(0,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) == 0 ) { char str[65],str2[65]; printf("dest.(%s)/v%d fee.(%s)/v%d\n",bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); return(clonestr("{\"error\":\"cant find alice utxopair\"}")); } - if ( (bobutxo= LP_utxopairfind(1,qp->txid,qp->vout,qp->txid2,qp->vout2)) == 0 ) + /*if ( (bobutxo= LP_utxopairfind(1,qp->txid,qp->vout,qp->txid2,qp->vout2)) == 0 ) return(clonestr("{\"error\":\"cant find bob utxopair\"}")); - bobutxo->T.bestflag = (uint32_t)time(NULL); + bobutxo->T.bestflag = (uint32_t)time(NULL);*/ //if ( (retstr= LP_registerall(0)) != 0 ) // free(retstr); price = LP_query(ctx,myipaddr,mypubsock,"request",qp); @@ -778,7 +778,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q if ( price <= maxprice ) { price = LP_query(ctx,myipaddr,mypubsock,"connect",qp); - LP_requestinit(&qp->R,qp->srchash,qp->desthash,bobutxo->coin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); + LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); expiration = (uint32_t)time(NULL) + timeout; while ( time(NULL) < expiration ) { @@ -788,7 +788,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q } if ( aliceutxo->S.swap == 0 ) { - if ( (pubp= LP_pubkeyadd(bobutxo->pubkey)) != 0 ) + if ( (pubp= LP_pubkeyadd(qp->srchash)) != 0 ) pubp->numerrors++; jaddstr(bestitem,"status","couldnt establish connection"); } else jaddstr(bestitem,"status","connected"); @@ -939,6 +939,75 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr return(bestutxo); } +struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *rel,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) +{ + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *relcoin; + *ordermatchpricep = 0.; + *bestsatoshisp = *bestdestsatoshisp = 0; + relcoin = LP_coinfind(rel); + if ( duration <= 0 ) + duration = LP_ORDERBOOK_DURATION; + if ( maxprice <= 0. || LP_priceinfofind(rel) == 0 || relcoin == 0 ) + return(0); + utxos = calloc(max,sizeof(*utxos)); + LP_txfees(&txfee,&desttxfee,autxo->coin,rel); + if ( (obookstr= LP_orderbook(autxo->coin,rel,duration)) != 0 ) + { + if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) + { + if ( (asks= jarray(&numasks,orderbook,"bids")) != 0 ) + { + for (i=0; i 0 && price <= maxprice ) + { + pubkey = jbits256(item,"pubkey"); + if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) + { + if ( (n= jint(item,"numutxos")) > 1 ) + { + minvol = jdouble(item,"minvolume"); + maxvol = jdouble(item,"maxvolume"); + if ( relvolume >= minvol && relvolume <= maxvol ) + { + bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,txfee,relvolume,price)) != 0 ) + { + bestutxo->pubkey = pubp->pubkey; + safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); + autxo->S.satoshis = bestutxo->S.satoshis; + *bestsatoshisp = bestutxo->S.satoshis / price; + *ordermatchpricep = price; + *bestdestsatoshisp = autxo->S.satoshis; + printf("ordermatch %.8f %.8f %.8f\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp)); + break; + } + } + } + } else printf("self trading or blacklisted peer\n"); + } + else + { + if ( i == 0 ) + printf("too expensive maxprice %.8f vs %.8f\n",maxprice,price); + break; + } + } + } + free_json(orderbook); + } + free(obookstr); + } + free(utxos); + if ( *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) + return(0); + int32_t changed; + LP_mypriceset(&changed,autxo->coin,rel,*ordermatchpricep); + return(bestutxo); +} + 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) { uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; @@ -968,38 +1037,38 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"quote validation error\"}")); } printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); - return(clonestr("{\"result\":\"success\"}")); - //return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); } -char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double basevolume,int32_t timeout,int32_t duration) +char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double basevolume,int32_t timeout,int32_t duration,char *gui) { - uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *butxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; if ( timeout <= 0 ) timeout = LP_AUTOTRADE_TIMEOUT; if ( maxprice <= 0. || basevolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); - if ( (autxo= LP_utxo_bestfit(base,SATOSHIDEN * basevolume)) == 0 ) + if ( (butxo= LP_utxo_bestfit(base,SATOSHIDEN * basevolume)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); LP_txfees(&txfee,&desttxfee,base,rel); - //if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*basevolume*maxprice)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + if ( (bestutxo= LP_sellutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,butxo,rel,maxprice,duration,txfee,desttxfee,SATOSHIDEN*basevolume*maxprice,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) { printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); } - if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) + if ( LP_quoteinfoinit(&Q,bestutxo,base,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) + if ( LP_quotedestinfo(&Q,bestutxo->payment.txid,bestutxo->payment.vout,bestutxo->deposit.txid,bestutxo->deposit.vout,LP_mypub25519,bestutxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) + if ( (qprice= LP_quote_validate(bestutxo,butxo,&Q,0)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); } printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); - return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); + return(clonestr("{\"result\":\"success\"}")); + //return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); } From e2d416f57fe4b70c14d59f55b12b416d27065017 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:17:35 +0200 Subject: [PATCH 129/520] Test --- iguana/exchanges/LP_ordermatch.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ea5a703ad..cbf453f43 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -939,9 +939,9 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr return(bestutxo); } -struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *rel,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) +struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *rel,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double basevolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *relcoin; + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*bids,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *relcoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; relcoin = LP_coinfind(rel); @@ -955,11 +955,11 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) { - if ( (asks= jarray(&numasks,orderbook,"bids")) != 0 ) + if ( (bids= jarray(&numasks,orderbook,"bids")) != 0 ) { for (i=0; i 0 && price <= maxprice ) { @@ -970,10 +970,11 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { minvol = jdouble(item,"minvolume"); maxvol = jdouble(item,"maxvolume"); - if ( relvolume >= minvol && relvolume <= maxvol ) + printf("%s %.8f %.8f\n",jprint(item,0),minvol/price,maxvol/price); + if ( basevolume >= minvol/price && basevolume <= maxvol/price ) { bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,txfee,relvolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,txfee,basevolume,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From 96375467142c3f84544d40bae713a17f2ddf9d38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:25:16 +0200 Subject: [PATCH 130/520] Test --- iguana/exchanges/LP_ordermatch.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cbf453f43..082059ba9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -939,7 +939,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr return(bestutxo); } -struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *rel,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double basevolume,char *gui) +struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *rel,double minprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double basevolume,char *gui) { bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*bids,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *relcoin; *ordermatchpricep = 0.; @@ -947,7 +947,7 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp relcoin = LP_coinfind(rel); if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; - if ( maxprice <= 0. || LP_priceinfofind(rel) == 0 || relcoin == 0 ) + if ( minprice <= 0. || LP_priceinfofind(rel) == 0 || relcoin == 0 ) return(0); utxos = calloc(max,sizeof(*utxos)); LP_txfees(&txfee,&desttxfee,autxo->coin,rel); @@ -961,7 +961,7 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { item = jitem(bids,i); price = jdouble(item,"price"); - if ( LP_pricevalid(price) > 0 && price <= maxprice ) + if ( LP_pricevalid(price) > 0 && price >= minprice ) { pubkey = jbits256(item,"pubkey"); if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) @@ -970,11 +970,11 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { minvol = jdouble(item,"minvolume"); maxvol = jdouble(item,"maxvolume"); - printf("%s %.8f %.8f\n",jprint(item,0),minvol/price,maxvol/price); + printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol/price,basevolume,maxvol/price); if ( basevolume >= minvol/price && basevolume <= maxvol/price ) { bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,txfee,basevolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -1041,19 +1041,19 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); } -char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double basevolume,int32_t timeout,int32_t duration,char *gui) +char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double minprice,double basevolume,int32_t timeout,int32_t duration,char *gui) { uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *butxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; if ( timeout <= 0 ) timeout = LP_AUTOTRADE_TIMEOUT; - if ( maxprice <= 0. || basevolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) + if ( minprice <= 0. || basevolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); if ( (butxo= LP_utxo_bestfit(base,SATOSHIDEN * basevolume)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); LP_txfees(&txfee,&desttxfee,base,rel); - if ( (bestutxo= LP_sellutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,butxo,rel,maxprice,duration,txfee,desttxfee,SATOSHIDEN*basevolume*maxprice,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + if ( (bestutxo= LP_sellutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,butxo,rel,minprice,duration,txfee,desttxfee,basevolume,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) { printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); From fd35bced19c3c496c1bbc17fe762106173355abc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:30:55 +0200 Subject: [PATCH 131/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 082059ba9..b5d830bf1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -992,7 +992,7 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp else { if ( i == 0 ) - printf("too expensive maxprice %.8f vs %.8f\n",maxprice,price); + printf("too expensive maxprice %.8f vs %.8f\n",minprice,price); break; } } From 090207445cbd2561b5f6685d7f8a1884d8c90cd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:34:45 +0200 Subject: [PATCH 132/520] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b5d830bf1..4c1d0ea48 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -970,11 +970,11 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { minvol = jdouble(item,"minvolume"); maxvol = jdouble(item,"maxvolume"); - printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol/price,basevolume,maxvol/price); if ( basevolume >= minvol/price && basevolume <= maxvol/price ) { + printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol/price,basevolume,maxvol/price); bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume*price,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -992,7 +992,7 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp else { if ( i == 0 ) - printf("too expensive maxprice %.8f vs %.8f\n",minprice,price); + printf("too little minprice %.8f vs %.8f\n",minprice,price); break; } } From 0138625a809cbfacd81b713ad846ae0801a5722f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:39:03 +0200 Subject: [PATCH 133/520] Test --- iguana/exchanges/LP_ordermatch.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 4c1d0ea48..0bdc83eb5 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -834,14 +834,16 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t return(mini); } -struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price) +struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price) { struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; if ( (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) { - targetval = SATOSHIDEN * (relvolume / price) + 2*txfee; + if ( relflag != 0 ) + targetval = SATOSHIDEN * (volume / price) + 2*txfee; + else targetval = SATOSHIDEN * (volume*price) + 2*txfee; if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) { up = utxos[mini]; @@ -904,7 +906,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr if ( relvolume >= minvol && relvolume <= maxvol ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(1,bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -972,9 +974,9 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp maxvol = jdouble(item,"maxvolume"); if ( basevolume >= minvol/price && basevolume <= maxvol/price ) { - printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol/price,basevolume,maxvol/price); + printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol,basevolume*price,maxvol); bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume*price,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(0,bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From 9ace32f8df8556cf06cf7ec55a6eeb5b2ebf5606 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:42:22 +0200 Subject: [PATCH 134/520] Test --- iguana/exchanges/LP_ordermatch.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0bdc83eb5..313400107 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -844,6 +844,12 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo if ( relflag != 0 ) targetval = SATOSHIDEN * (volume / price) + 2*txfee; else targetval = SATOSHIDEN * (volume*price) + 2*txfee; + { + int32_t i; + for (i=0; iU.value)); + printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); + } if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) { up = utxos[mini]; From c68de697ff3153ebba64ee13f1298ef8e73496d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:43:47 +0200 Subject: [PATCH 135/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 313400107..4a0ac29a4 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -868,7 +868,9 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo utxo->deposit.txid = up2->U.txid; utxo->deposit.vout = up2->U.vout; utxo->deposit.value = up2->U.value; - utxo->S.satoshis = SATOSHIDEN * (relvolume / price); + if ( relflag != 0 ) + utxo->S.satoshis = SATOSHIDEN * (volume / price); + else utxo->S.satoshis = SATOSHIDEN * (volume * price); return(utxo); } } From 00238f0d6cf13ab7efc4cf8109e0e599e2792ec7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:46:42 +0200 Subject: [PATCH 136/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 4a0ac29a4..c32c17395 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -984,7 +984,7 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol,basevolume*price,maxvol); bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(0,bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(0,bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume*price,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From 06cbfc9d30af7f412f2b527e40248304ee7f3b6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:51:37 +0200 Subject: [PATCH 137/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c32c17395..abc0896c8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -989,9 +989,9 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); autxo->S.satoshis = bestutxo->S.satoshis; - *bestsatoshisp = bestutxo->S.satoshis / price; + *bestsatoshisp = autxo->S.satoshis; *ordermatchpricep = price; - *bestdestsatoshisp = autxo->S.satoshis; + *bestdestsatoshisp = bestutxo->S.satoshis; printf("ordermatch %.8f %.8f %.8f\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp)); break; } From a684a3df03971dfb76e627690a0d500507691d23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 15:55:04 +0200 Subject: [PATCH 138/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index abc0896c8..f17a2bd59 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -988,7 +988,6 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - autxo->S.satoshis = bestutxo->S.satoshis; *bestsatoshisp = autxo->S.satoshis; *ordermatchpricep = price; *bestdestsatoshisp = bestutxo->S.satoshis; From ede10528eb117725fc7867df76217c4d82187a34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 16:03:46 +0200 Subject: [PATCH 139/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index f17a2bd59..191d4abd7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -843,7 +843,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo { if ( relflag != 0 ) targetval = SATOSHIDEN * (volume / price) + 2*txfee; - else targetval = SATOSHIDEN * (volume*price) + 2*txfee; + else targetval = SATOSHIDEN * (volume * price) + 2*txfee; { int32_t i; for (i=0; ipubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); + // ordermatch 0.00050029 12.99990000 0.00000250 + // 0.00156398 0.01062943 0.00164483 0.00163831 0.00200000 0.00091512 0.03616972 0.00149051 0.00011714 0.03721034 0.02667164 0.00126502 0.03982604 0.00158423 0.00129022 0.04057810 0.00137594 0.00100000 0.00055601 0.00067499 0.00022800 0.12000000 0.03679745 0.00191550 0.00068144 0.00060983 0.00155659 0.03500084 0.00186860 0.00065110 0.00062265 0.00017046 0.00001468 0.00051851 0.00571714 0.00205292 0.00309702 0.03363277 targetval 0.00070640 vol 0.00500290 price 0.00050029 txfee 0.00035195 *bestsatoshisp = autxo->S.satoshis; *ordermatchpricep = price; *bestdestsatoshisp = bestutxo->S.satoshis; From 7a13cf930cffc3d93893329b385f159447d49bb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 16:06:20 +0200 Subject: [PATCH 140/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 191d4abd7..cf1a73f95 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -849,6 +849,9 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo for (i=0; iU.value)); printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); + //{"coin":"BTC","address":"1L7Kzud7jC3LnLyZmtg85XxxvADLuLwfwr","price":0.00050196,"numutxos":22,"minvolume":0.00011714,"maxvolume":0.10820861,"pubkey":"1bfcfc1d48dbe3e1332b09cb48e50e7789bdde2308b74f905299db12d093fa2d","age":13} 0.00011714 [0.00501960] 0.10820861 + //0.00100000 0.00100000 0.00200000 0.08947953 0.10820861 0.03616972 0.00126502 0.04057810 0.00091512 0.00011714 0.00164483 0.00149051 0.00158423 0.00129022 0.03982604 0.03721034 0.00163831 0.00137594 0.00156398 0.02667164 0.00099693 0.01062943 targetval 0.00070641 vol 0.00501960 price 0.00050196 txfee 0.00035195 + //ordermatch 0.00050196 12.99990000 0.00000251 } if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) { @@ -984,7 +987,7 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol,basevolume*price,maxvol); bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(0,bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume*price,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(0,bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From 0f6c01a75d7df4ae161d6ad3a556f94dc40610ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 16:12:33 +0200 Subject: [PATCH 141/520] Test --- iguana/exchanges/LP_ordermatch.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cf1a73f95..12773c12d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -167,7 +167,7 @@ int32_t LP_quoteinfoinit(struct LP_quoteinfo *qp,struct LP_utxoinfo *utxo,char * LP_txfees(&qp->txfee,&qp->desttxfee,utxo->coin,qp->destcoin); qp->satoshis = satoshis;//(destsatoshis / price) + 0.49; qp->destsatoshis = destsatoshis; - if ( utxo->iambob == 0 || qp->txfee >= qp->satoshis || qp->txfee >= utxo->deposit.value || utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis) ) + if ( qp->txfee >= qp->satoshis || qp->txfee >= utxo->deposit.value || utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis) ) //utxo->iambob == 0 || { printf("quoteinit error.(%d %d %d %d) %.8f vs %.8f\n",utxo->iambob == 0,qp->txfee >= qp->satoshis,qp->txfee >= utxo->deposit.value,utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis),dstr(utxo->deposit.value),dstr(LP_DEPOSITSATOSHIS(qp->satoshis))); return(-1); @@ -849,9 +849,6 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo for (i=0; iU.value)); printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); - //{"coin":"BTC","address":"1L7Kzud7jC3LnLyZmtg85XxxvADLuLwfwr","price":0.00050196,"numutxos":22,"minvolume":0.00011714,"maxvolume":0.10820861,"pubkey":"1bfcfc1d48dbe3e1332b09cb48e50e7789bdde2308b74f905299db12d093fa2d","age":13} 0.00011714 [0.00501960] 0.10820861 - //0.00100000 0.00100000 0.00200000 0.08947953 0.10820861 0.03616972 0.00126502 0.04057810 0.00091512 0.00011714 0.00164483 0.00149051 0.00158423 0.00129022 0.03982604 0.03721034 0.00163831 0.00137594 0.00156398 0.02667164 0.00099693 0.01062943 targetval 0.00070641 vol 0.00501960 price 0.00050196 txfee 0.00035195 - //ordermatch 0.00050196 12.99990000 0.00000251 } if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) { @@ -991,8 +988,6 @@ struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchp { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - // ordermatch 0.00050029 12.99990000 0.00000250 - // 0.00156398 0.01062943 0.00164483 0.00163831 0.00200000 0.00091512 0.03616972 0.00149051 0.00011714 0.03721034 0.02667164 0.00126502 0.03982604 0.00158423 0.00129022 0.04057810 0.00137594 0.00100000 0.00055601 0.00067499 0.00022800 0.12000000 0.03679745 0.00191550 0.00068144 0.00060983 0.00155659 0.03500084 0.00186860 0.00065110 0.00062265 0.00017046 0.00001468 0.00051851 0.00571714 0.00205292 0.00309702 0.03363277 targetval 0.00070640 vol 0.00500290 price 0.00050029 txfee 0.00035195 *bestsatoshisp = autxo->S.satoshis; *ordermatchpricep = price; *bestdestsatoshisp = bestutxo->S.satoshis; From 07f867358b00094632a5a4776ee3aa492c4228e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 16:14:25 +0200 Subject: [PATCH 142/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 12773c12d..227eef83a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -167,11 +167,11 @@ int32_t LP_quoteinfoinit(struct LP_quoteinfo *qp,struct LP_utxoinfo *utxo,char * LP_txfees(&qp->txfee,&qp->desttxfee,utxo->coin,qp->destcoin); qp->satoshis = satoshis;//(destsatoshis / price) + 0.49; qp->destsatoshis = destsatoshis; - if ( qp->txfee >= qp->satoshis || qp->txfee >= utxo->deposit.value || utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis) ) //utxo->iambob == 0 || + /*if ( qp->txfee >= qp->satoshis || qp->txfee >= utxo->deposit.value || utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis) ) //utxo->iambob == 0 || { printf("quoteinit error.(%d %d %d %d) %.8f vs %.8f\n",utxo->iambob == 0,qp->txfee >= qp->satoshis,qp->txfee >= utxo->deposit.value,utxo->deposit.value < LP_DEPOSITSATOSHIS(qp->satoshis),dstr(utxo->deposit.value),dstr(LP_DEPOSITSATOSHIS(qp->satoshis))); return(-1); - } + }*/ qp->txid = utxo->payment.txid; qp->vout = utxo->payment.vout; qp->txid2 = utxo->deposit.txid; From 2cd3632f9410e0d2accbf1c7395afecc07d9689d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 18:15:06 +0200 Subject: [PATCH 143/520] Test --- iguana/exchanges/LP_commands.c | 6 +- iguana/exchanges/LP_ordermatch.c | 140 ++++--------------------------- 2 files changed, 20 insertions(+), 126 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c97693008..e42f9de70 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -104,7 +104,6 @@ disable(coin)\n\ inventory(coin)\n\ bestfit(rel, relvolume)\n\ buy(base, rel, price, relvolume, timeout=10, duration=3600)\n\ -sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ swapstatus()\n\ swapstatus(requestid, quoteid)\n\ public API:\n \ @@ -124,7 +123,8 @@ snapshot(coin, height)\n\ snapshot_balance(coin, height, addresses[])\n\ dividends(coin, height, )\n\ \"}")); - + //sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ + base = jstr(argjson,"base"); rel = jstr(argjson,"rel"); if ( USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) @@ -244,7 +244,7 @@ dividends(coin, height, )\n\ { if ( price > SMALLVAL ) { - return(LP_autosell(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")*price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 227eef83a..d2ea61f18 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -439,13 +439,17 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 ) return(clonestr("{\"result\",\"update stats\"}")); printf("CONNECTED.(%s)\n",jprint(argjson,0)); - //if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + memset(&A,0,sizeof(A)); + memset(&B,0,sizeof(B)); + autxo = &A; + butxo = &B; + if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); LP_pendingswaps--; @@ -460,15 +464,7 @@ char *LP_connectedalice(cJSON *argjson) // alice return(clonestr("{\"error\":\"no price set\"}")); } printf("%s/%s bid %.8f ask %.8f\n",Q.srccoin,Q.destcoin,bid,ask); - //if ( (price= ask) == 0. ) - price = bid; - /*if ( SATOSHIDEN*qprice > (SATOSHIDEN * price) * 1.001 + 10 ) - { - printf("qprice %.8f too big vs %.8f\n",qprice,price); - LP_availableset(autxo); - LP_pendingswaps--; - return(clonestr("{\"error\":\"quote price too expensive\"}")); - }*/ + price = bid; if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) { LP_pendingswaps--; @@ -515,7 +511,7 @@ char *LP_connectedalice(cJSON *argjson) // alice int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q; + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q; if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); @@ -528,7 +524,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - //if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,1)) <= SMALLVAL ) + memset(&A,0,sizeof(A)); + memset(&B,0,sizeof(B)); + autxo = &A; + butxo = &B; + if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); return(-4); @@ -834,16 +834,14 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t return(mini); } -struct LP_utxoinfo *LP_address_utxopair(int32_t relflag,struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price) +struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price) { struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; if ( (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) { - if ( relflag != 0 ) - targetval = SATOSHIDEN * (volume / price) + 2*txfee; - else targetval = SATOSHIDEN * (volume * price) + 2*txfee; + targetval = SATOSHIDEN * (volume / price) + 2*txfee; { int32_t i; for (i=0; ideposit.txid = up2->U.txid; utxo->deposit.vout = up2->U.vout; utxo->deposit.value = up2->U.value; - if ( relflag != 0 ) - utxo->S.satoshis = SATOSHIDEN * (volume / price); - else utxo->S.satoshis = SATOSHIDEN * (volume * price); + utxo->S.satoshis = SATOSHIDEN * (volume / price); return(utxo); } } @@ -914,7 +910,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr if ( relvolume >= minvol && relvolume <= maxvol ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(1,bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -949,75 +945,6 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr return(bestutxo); } -struct LP_utxoinfo *LP_sellutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *rel,double minprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double basevolume,char *gui) -{ - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*bids,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *relcoin; - *ordermatchpricep = 0.; - *bestsatoshisp = *bestdestsatoshisp = 0; - relcoin = LP_coinfind(rel); - if ( duration <= 0 ) - duration = LP_ORDERBOOK_DURATION; - if ( minprice <= 0. || LP_priceinfofind(rel) == 0 || relcoin == 0 ) - return(0); - utxos = calloc(max,sizeof(*utxos)); - LP_txfees(&txfee,&desttxfee,autxo->coin,rel); - if ( (obookstr= LP_orderbook(autxo->coin,rel,duration)) != 0 ) - { - if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) - { - if ( (bids= jarray(&numasks,orderbook,"bids")) != 0 ) - { - for (i=0; i 0 && price >= minprice ) - { - pubkey = jbits256(item,"pubkey"); - if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) - { - if ( (n= jint(item,"numutxos")) > 1 ) - { - minvol = jdouble(item,"minvolume"); - maxvol = jdouble(item,"maxvolume"); - if ( basevolume >= minvol/price && basevolume <= maxvol/price ) - { - printf("%s %.8f [%.8f] %.8f\n",jprint(item,0),minvol,basevolume*price,maxvol); - bitcoin_address(coinaddr,relcoin->taddr,relcoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(0,bestutxo,utxos,max,relcoin,coinaddr,desttxfee,basevolume,price)) != 0 ) - { - bestutxo->pubkey = pubp->pubkey; - safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - *bestsatoshisp = autxo->S.satoshis; - *ordermatchpricep = price; - *bestdestsatoshisp = bestutxo->S.satoshis; - printf("ordermatch %.8f %.8f %.8f\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp)); - break; - } - } - } - } else printf("self trading or blacklisted peer\n"); - } - else - { - if ( i == 0 ) - printf("too little minprice %.8f vs %.8f\n",minprice,price); - break; - } - } - } - free_json(orderbook); - } - free(obookstr); - } - free(utxos); - if ( *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) - return(0); - int32_t changed; - LP_mypriceset(&changed,autxo->coin,rel,*ordermatchpricep); - return(bestutxo); -} - 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) { uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; @@ -1050,37 +977,4 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); } -char *LP_autosell(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double minprice,double basevolume,int32_t timeout,int32_t duration,char *gui) -{ - uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *butxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; - if ( duration <= 0 ) - duration = LP_ORDERBOOK_DURATION; - if ( timeout <= 0 ) - timeout = LP_AUTOTRADE_TIMEOUT; - if ( minprice <= 0. || basevolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) - return(clonestr("{\"error\":\"invalid parameter\"}")); - if ( (butxo= LP_utxo_bestfit(base,SATOSHIDEN * basevolume)) == 0 ) - return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); - LP_txfees(&txfee,&desttxfee,base,rel); - if ( (bestutxo= LP_sellutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,butxo,rel,minprice,duration,txfee,desttxfee,basevolume,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) - { - printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); - return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); - } - if ( LP_quoteinfoinit(&Q,bestutxo,base,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - if ( LP_quotedestinfo(&Q,bestutxo->payment.txid,bestutxo->payment.vout,bestutxo->deposit.txid,bestutxo->deposit.vout,LP_mypub25519,bestutxo->coinaddr) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(bestutxo,butxo,&Q,0)) <= SMALLVAL ) - { - printf("quote validate error %.0f\n",qprice); - return(clonestr("{\"error\":\"quote validation error\"}")); - } - printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); - return(clonestr("{\"result\":\"success\"}")); - //return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); -} - - - From bf8b2e73391accd95e3f61382c8cd4c458923406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 18:21:16 +0200 Subject: [PATCH 144/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d2ea61f18..597ddaa7f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -948,7 +948,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr 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) { uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; - printf("LP_autobuy\n"); + printf("LP_autobuy %s/%s price %.8f vol %.8f\n",base,rel,maxprice,relvolume); if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; if ( timeout <= 0 ) From ca1e4bb80167a00f474732b22aa144c51e239b6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 18:25:26 +0200 Subject: [PATCH 145/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 597ddaa7f..d9646c7af 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -907,6 +907,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr { minvol = jdouble(item,"minvolume"); maxvol = jdouble(item,"maxvolume"); + printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); if ( relvolume >= minvol && relvolume <= maxvol ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); From 45aa9edfa8fff33cf051b3b449fc221cce03f06c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 18:30:22 +0200 Subject: [PATCH 146/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e42f9de70..ba09dc42c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -244,7 +244,7 @@ dividends(coin, height, )\n\ { if ( price > SMALLVAL ) { - return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")*price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } From 22f2276c35c49b528a1b945f14f4be75b4b09680 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 18:47:56 +0200 Subject: [PATCH 147/520] Test --- iguana/exchanges/LP_ordermatch.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d9646c7af..bed5cf84d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -514,6 +514,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q; if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { + //LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); retval = 1; if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 ) @@ -524,10 +525,32 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - memset(&A,0,sizeof(A)); memset(&B,0,sizeof(B)); - autxo = &A; butxo = &B; + butxo->pubkey = Q.srchash; + safecopy(butxo->coin,Q.srccoin,sizeof(butxo->coin)); + safecopy(butxo->coinaddr,Q.coinaddr,sizeof(butxo->coinaddr)); + butxo->payment.txid = Q.txid; + butxo->payment.vout = Q.vout; + //butxo->payment.value = Q.value; + butxo->iambob = 1; + butxo->deposit.txid = Q.txid2; + butxo->deposit.vout = Q.vout2; + //butxo->deposit.value = up2->U.value; + butxo->S.satoshis = Q.satoshis; + memset(&A,0,sizeof(A)); + autxo = &A; + autxo->pubkey = Q.desthash; + safecopy(autxo->coin,Q.destcoin,sizeof(autxo->coin)); + safecopy(autxo->coinaddr,Q.destaddr,sizeof(autxo->coinaddr)); + autxo->payment.txid = Q.desttxid; + autxo->payment.vout = Q.destvout; + //autxo->payment.value = Q.value; + autxo->iambob = 0; + autxo->deposit.txid = Q.feetxid; + autxo->deposit.vout = Q.feevout; + //autxo->deposit.value = up2->U.value; + autxo->S.satoshis = Q.destsatoshis; if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); @@ -766,11 +789,6 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q char str[65],str2[65]; printf("dest.(%s)/v%d fee.(%s)/v%d\n",bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); return(clonestr("{\"error\":\"cant find alice utxopair\"}")); } - /*if ( (bobutxo= LP_utxopairfind(1,qp->txid,qp->vout,qp->txid2,qp->vout2)) == 0 ) - return(clonestr("{\"error\":\"cant find bob utxopair\"}")); - bobutxo->T.bestflag = (uint32_t)time(NULL);*/ - //if ( (retstr= LP_registerall(0)) != 0 ) - // free(retstr); price = LP_query(ctx,myipaddr,mypubsock,"request",qp); bestitem = LP_quotejson(qp); if ( LP_pricevalid(price) > 0 ) From 4910c95df39afa88005eb5638c944d9c1d7cbafc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 18:57:29 +0200 Subject: [PATCH 148/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_ordermatch.c | 177 ---------------------------- iguana/exchanges/LP_rpc.c | 6 +- iguana/exchanges/LP_statemachine.c | 178 +++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+), 181 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 99381bfe9..af0f0fee3 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -49,7 +49,7 @@ #define LP_MINVOL 10 #define LP_MINCLIENTVOL 20 #define LP_MINSIZE_TXFEEMULT 10 -#define LP_REQUIRED_TXFEE 0.95 +#define LP_REQUIRED_TXFEE 0.9 #define LP_DEXFEE(destsatoshis) ((destsatoshis) / INSTANTDEX_INSURANCEDIV) #define LP_DEPOSITSATOSHIS(satoshis) ((satoshis) + (satoshis >> 3)) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bed5cf84d..3f1cbd636 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -604,183 +604,6 @@ char *LP_bestfit(char *rel,double relvolume) return(jprint(LP_utxojson(autxo),1)); } -#ifdef oldway -struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,uint64_t maxdestsatoshis) -{ - int64_t satoshis,destsatoshis; uint64_t val,val2; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item; struct LP_utxoinfo *butxo,*bestutxo = 0; int32_t i,n,j,vout,numasks; double bestmetric=0.,metric,vol,price,qprice,bestprice = 0.; struct LP_pubkeyinfo *pubp; - *ordermatchpricep = 0.; - *bestsatoshisp = *bestdestsatoshisp = 0; - if ( duration <= 0 ) - duration = LP_ORDERBOOK_DURATION; - if ( maxprice <= 0. || LP_priceinfofind(base) == 0 ) - return(0); - LP_txfees(&txfee,&desttxfee,base,autxo->coin); - if ( (obookstr= LP_orderbook(base,autxo->coin,duration)) != 0 ) - { - if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) - { - if ( (asks= jarray(&numasks,orderbook,"asks")) != 0 ) - { - for (i=0; i 0 && price <= maxprice ) - { - //price *= 1.0001; - //if ( price > maxprice ) - // price = maxprice; - pubkey = jbits256(item,"pubkey"); - if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 && pubp->numerrors < LP_MAXPUBKEY_ERRORS ) - { - if ( bestprice == 0. ) // assumes price ordered asks - bestprice = price; - printf("item.[%d] %s\n",i,jprint(item,0)); - txid = jbits256(item,"txid"); - vout = jint(item,"vout"); - vol = jdouble(item,"volume"); - metric = price / bestprice; - printf("maxdest %.8f metric %f vol %f add pings numutxos.%d min %.8f max %.8f\n",dstr(maxdestsatoshis),metric,vol,jint(item,"numutxos"),jdouble(item,"minvolume"),jdouble(item,"maxvolume")); - // check utxos > 1 for pubkey, SPV validate recv'ed - /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) - { - printf("got butxo? %p\n",butxo); - if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 ) - { - destsatoshis = ((butxo->S.satoshis - txfee) * price); - satoshis = (destsatoshis / price + 0.49) - txfee; - if ( satoshis <= 0 ) - continue; - qprice = (double)destsatoshis / satoshis; - n = (int32_t)((double)destsatoshis / desttxfee); - if ( n < 10 ) - n = 10; - else n = 3; - for (j=0; jS.satoshis,txfee,autxo->payment.value,maxdestsatoshis,desttxfee)) > price+SMALLVAL ) - break; - } - //printf("j.%d/%d qprice %.8f vs price %.8f best.(%.8f %.8f)\n",j,n,qprice,price,dstr(satoshis),dstr(destsatoshis)); - if ( metric < 1.2 && destsatoshis > desttxfee && destsatoshis-desttxfee > (autxo->payment.value / LP_MINCLIENTVOL) && satoshis-txfee > (butxo->S.satoshis / LP_MINVOL) && satoshis <= butxo->payment.value-txfee ) - { - printf("value %.8f price %.8f/%.8f best %.8f destsatoshis %.8f * metric %.8f -> (%f)\n",dstr(autxo->payment.value),price,bestprice,bestmetric,dstr(destsatoshis),metric,dstr(destsatoshis) * metric * metric * metric); - metric = dstr(destsatoshis) * metric * metric * metric; - if ( bestmetric == 0. || metric < bestmetric ) - { - bestutxo = butxo; - *ordermatchpricep = price; - *bestdestsatoshisp = destsatoshis; - *bestsatoshisp = satoshis; - bestmetric = metric; - printf("set best!\n"); - } - } // else printf("skip.(%d %d %d %d %d) metric %f destsatoshis %.8f value %.8f destvalue %.8f txfees %.8f %.8f sats %.8f\n",metric < 1.2,destsatoshis > desttxfee,destsatoshis-desttxfee > (autxo->payment.value / LP_MINCLIENTVOL),satoshis-txfee > (butxo->S.satoshis / LP_MINVOL),satoshis < butxo->payment.value-txfee,metric,dstr(destsatoshis),dstr(butxo->S.satoshis),dstr(autxo->payment.value),dstr(txfee),dstr(desttxfee),dstr(satoshis)); - } - else - { - printf("ineligible.(%.8f %.8f)\n",price,dstr(butxo->S.satoshis)); - //if ( butxo->T.spentflag == 0 ) - // butxo->T.spentflag = (uint32_t)time(NULL); - } - } - else - { - if ( butxo != 0 ) - printf("%llu %llu %d %d %d: ",(long long)(vol*SATOSHIDEN),(long long)butxo->S.satoshis,vol*SATOSHIDEN == butxo->S.satoshis,LP_isavailable(butxo) > 0,LP_ismine(butxo) == 0); - printf("cant find butxo.%p or value mismatch %.8f != %.8f or bestflag.%d\n",butxo,vol,butxo!=0?dstr(butxo->S.satoshis):0,butxo->T.bestflag); - }*/ - } else printf("self trading or blacklisted peer\n"); - } - else - { - if ( i == 0 ) - printf("maxprice %.8f vs %.8f\n",maxprice,price); - break; - } - } - if ( bestutxo == 0 ) - { - int32_t numrestraints; - for (i=numrestraints=0; iT.bestflag = 0; - pubp->numerrors = 0; - } - } - } - printf("no bob utxo found -> cleared %d restraints\n",numrestraints); - } - } - free_json(orderbook); - } - free(obookstr); - } - printf("bestutxo.%p %.8f %.8f\n",bestutxo,*ordermatchpricep,dstr(*bestdestsatoshisp)); - if ( bestutxo == 0 || *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) - return(0); - bestutxo->T.bestflag = 1; - int32_t changed; - LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep); - return(bestutxo); -} - -char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,char *rel,bits256 txid,int32_t vout,bits256 feetxid,int32_t feevout,int64_t desttxfee,int32_t duration) -{ - struct LP_quoteinfo Q; int64_t bestsatoshis=0,bestdestsatoshis = 0; double ordermatchprice = 0.; struct LP_utxoinfo *autxo,*bestutxo; - txfee = LP_txfeecalc(LP_coinfind(base),txfee); - desttxfee = LP_txfeecalc(LP_coinfind(rel),desttxfee); - if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 ) - return(clonestr("{\"error\":\"cant find alice utxopair\"}")); - if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) - return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); - if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - return(jprint(LP_quotejson(&Q),1)); -} - -char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration) -{ - uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; - if ( duration <= 0 ) - duration = LP_ORDERBOOK_DURATION; - if ( timeout <= 0 ) - timeout = LP_AUTOTRADE_TIMEOUT; - if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) - return(clonestr("{\"error\":\"invalid parameter\"}")); - if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) - return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); - LP_txfees(&txfee,&desttxfee,base,rel); - if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*relvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) - { - printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); - return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); - } - if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) - { - printf("quote validate error %.0f\n",qprice); - return(clonestr("{\"error\":\"quote validation error\"}")); - } - printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); - return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); -} -#endif - char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration) { struct LP_utxoinfo *aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 71330a93a..5f6e34af4 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -571,9 +571,9 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime+600 ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { - sprintf(buf,"[%d]",3); + sprintf(buf,"[%d]",6); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { if ( retstr[0] != '-' ) @@ -581,7 +581,7 @@ double LP_getestimatedrate(struct iguana_info *coin) rate = atof(retstr) / 1024.; if ( rate < 0.00000020 ) rate = 0.00000020; - coin->rate = rate; + coin->rate = rate * 1.25; coin->ratetime = (uint32_t)time(NULL); printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 860c796e1..e22ca255f 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1601,3 +1601,181 @@ if ( (array= LP_tradecandidates(base)) != 0 ) }*/ +#ifdef oldway +struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,uint64_t maxdestsatoshis) +{ + int64_t satoshis,destsatoshis; uint64_t val,val2; bits256 txid,pubkey; char *obookstr; cJSON *orderbook,*asks,*item; struct LP_utxoinfo *butxo,*bestutxo = 0; int32_t i,n,j,vout,numasks; double bestmetric=0.,metric,vol,price,qprice,bestprice = 0.; struct LP_pubkeyinfo *pubp; + *ordermatchpricep = 0.; + *bestsatoshisp = *bestdestsatoshisp = 0; + if ( duration <= 0 ) + duration = LP_ORDERBOOK_DURATION; + if ( maxprice <= 0. || LP_priceinfofind(base) == 0 ) + return(0); + LP_txfees(&txfee,&desttxfee,base,autxo->coin); + if ( (obookstr= LP_orderbook(base,autxo->coin,duration)) != 0 ) + { + if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) + { + if ( (asks= jarray(&numasks,orderbook,"asks")) != 0 ) + { + for (i=0; i 0 && price <= maxprice ) + { + //price *= 1.0001; + //if ( price > maxprice ) + // price = maxprice; + pubkey = jbits256(item,"pubkey"); + if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 && pubp->numerrors < LP_MAXPUBKEY_ERRORS ) + { + if ( bestprice == 0. ) // assumes price ordered asks + bestprice = price; + printf("item.[%d] %s\n",i,jprint(item,0)); + txid = jbits256(item,"txid"); + vout = jint(item,"vout"); + vol = jdouble(item,"volume"); + metric = price / bestprice; + printf("maxdest %.8f metric %f vol %f add pings numutxos.%d min %.8f max %.8f\n",dstr(maxdestsatoshis),metric,vol,jint(item,"numutxos"),jdouble(item,"minvolume"),jdouble(item,"maxvolume")); + // check utxos > 1 for pubkey, SPV validate recv'ed + /*if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 ) + { + printf("got butxo? %p\n",butxo); + if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 ) + { + destsatoshis = ((butxo->S.satoshis - txfee) * price); + satoshis = (destsatoshis / price + 0.49) - txfee; + if ( satoshis <= 0 ) + continue; + qprice = (double)destsatoshis / satoshis; + n = (int32_t)((double)destsatoshis / desttxfee); + if ( n < 10 ) + n = 10; + else n = 3; + for (j=0; jS.satoshis,txfee,autxo->payment.value,maxdestsatoshis,desttxfee)) > price+SMALLVAL ) + break; + } + //printf("j.%d/%d qprice %.8f vs price %.8f best.(%.8f %.8f)\n",j,n,qprice,price,dstr(satoshis),dstr(destsatoshis)); + if ( metric < 1.2 && destsatoshis > desttxfee && destsatoshis-desttxfee > (autxo->payment.value / LP_MINCLIENTVOL) && satoshis-txfee > (butxo->S.satoshis / LP_MINVOL) && satoshis <= butxo->payment.value-txfee ) + { + printf("value %.8f price %.8f/%.8f best %.8f destsatoshis %.8f * metric %.8f -> (%f)\n",dstr(autxo->payment.value),price,bestprice,bestmetric,dstr(destsatoshis),metric,dstr(destsatoshis) * metric * metric * metric); + metric = dstr(destsatoshis) * metric * metric * metric; + if ( bestmetric == 0. || metric < bestmetric ) + { + bestutxo = butxo; + *ordermatchpricep = price; + *bestdestsatoshisp = destsatoshis; + *bestsatoshisp = satoshis; + bestmetric = metric; + printf("set best!\n"); + } + } // else printf("skip.(%d %d %d %d %d) metric %f destsatoshis %.8f value %.8f destvalue %.8f txfees %.8f %.8f sats %.8f\n",metric < 1.2,destsatoshis > desttxfee,destsatoshis-desttxfee > (autxo->payment.value / LP_MINCLIENTVOL),satoshis-txfee > (butxo->S.satoshis / LP_MINVOL),satoshis < butxo->payment.value-txfee,metric,dstr(destsatoshis),dstr(butxo->S.satoshis),dstr(autxo->payment.value),dstr(txfee),dstr(desttxfee),dstr(satoshis)); + } + else + { + printf("ineligible.(%.8f %.8f)\n",price,dstr(butxo->S.satoshis)); + //if ( butxo->T.spentflag == 0 ) + // butxo->T.spentflag = (uint32_t)time(NULL); + } + } + else + { + if ( butxo != 0 ) + printf("%llu %llu %d %d %d: ",(long long)(vol*SATOSHIDEN),(long long)butxo->S.satoshis,vol*SATOSHIDEN == butxo->S.satoshis,LP_isavailable(butxo) > 0,LP_ismine(butxo) == 0); + printf("cant find butxo.%p or value mismatch %.8f != %.8f or bestflag.%d\n",butxo,vol,butxo!=0?dstr(butxo->S.satoshis):0,butxo->T.bestflag); + }*/ + } else printf("self trading or blacklisted peer\n"); + } + else + { + if ( i == 0 ) + printf("maxprice %.8f vs %.8f\n",maxprice,price); + break; + } + } + if ( bestutxo == 0 ) + { + int32_t numrestraints; + for (i=numrestraints=0; iT.bestflag = 0; + pubp->numerrors = 0; + } + } + } + printf("no bob utxo found -> cleared %d restraints\n",numrestraints); + } + } + free_json(orderbook); + } + free(obookstr); + } + printf("bestutxo.%p %.8f %.8f\n",bestutxo,*ordermatchpricep,dstr(*bestdestsatoshisp)); + if ( bestutxo == 0 || *ordermatchpricep == 0. || *bestdestsatoshisp == 0 ) + return(0); + bestutxo->T.bestflag = 1; + int32_t changed; + LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep); + return(bestutxo); +} + +char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,char *rel,bits256 txid,int32_t vout,bits256 feetxid,int32_t feevout,int64_t desttxfee,int32_t duration) +{ + struct LP_quoteinfo Q; int64_t bestsatoshis=0,bestdestsatoshis = 0; double ordermatchprice = 0.; struct LP_utxoinfo *autxo,*bestutxo; + txfee = LP_txfeecalc(LP_coinfind(base),txfee); + desttxfee = LP_txfeecalc(LP_coinfind(rel),desttxfee); + if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 ) + return(clonestr("{\"error\":\"cant find alice utxopair\"}")); + if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); + if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + return(jprint(LP_quotejson(&Q),1)); +} + +char *LP_autotrade(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration) +{ + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*butxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + if ( duration <= 0 ) + duration = LP_ORDERBOOK_DURATION; + if ( timeout <= 0 ) + timeout = LP_AUTOTRADE_TIMEOUT; + if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) + return(clonestr("{\"error\":\"invalid parameter\"}")); + if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) + return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); + LP_txfees(&txfee,&desttxfee,base,rel); + if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*relvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + { + printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); + return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); + } + if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + if ( (qprice= LP_quote_validate(&autxo,&butxo,&Q,0)) <= SMALLVAL ) + { + printf("quote validate error %.0f\n",qprice); + return(clonestr("{\"error\":\"quote validation error\"}")); + } + printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); + return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); +} +#endif + + From 51dbfd15548ec480961091ec9a83adc8c30cc71d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 19:17:46 +0200 Subject: [PATCH 149/520] Test --- iguana/exchanges/LP_ordermatch.c | 58 +++++++++++++++++--------------- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_utxos.c | 4 +-- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3f1cbd636..838686adc 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -437,6 +437,34 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ return(retval); } +void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) +{ + memset(butxo,0,sizeof(*butxo)); + butxo->pubkey = qp->srchash; + safecopy(butxo->coin,qp->srccoin,sizeof(butxo->coin)); + safecopy(butxo->coinaddr,qp->coinaddr,sizeof(butxo->coinaddr)); + butxo->payment.txid = qp->txid; + butxo->payment.vout = qp->vout; + //butxo->payment.value = qp->value; + butxo->iambob = 1; + butxo->deposit.txid = qp->txid2; + butxo->deposit.vout = qp->vout2; + //butxo->deposit.value = up2->U.value; + butxo->S.satoshis = qp->satoshis; + memset(autxo,0,sizeof(*autxo)); + autxo->pubkey = qp->desthash; + safecopy(autxo->coin,qp->destcoin,sizeof(autxo->coin)); + safecopy(autxo->coinaddr,qp->destaddr,sizeof(autxo->coinaddr)); + autxo->payment.txid = qp->desttxid; + autxo->payment.vout = qp->destvout; + //autxo->payment.value = qp->value; + autxo->iambob = 0; + autxo->deposit.txid = qp->feetxid; + autxo->deposit.vout = qp->feevout; + //autxo->deposit.value = up2->U.value; + autxo->S.satoshis = qp->destsatoshis; +} + char *LP_connectedalice(cJSON *argjson) // alice { cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; @@ -445,10 +473,9 @@ char *LP_connectedalice(cJSON *argjson) // alice if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 ) return(clonestr("{\"result\",\"update stats\"}")); printf("CONNECTED.(%s)\n",jprint(argjson,0)); - memset(&A,0,sizeof(A)); - memset(&B,0,sizeof(B)); autxo = &A; butxo = &B; + LP_abutxo_set(autxo,butxo,&Q); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); @@ -525,32 +552,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - memset(&B,0,sizeof(B)); - butxo = &B; - butxo->pubkey = Q.srchash; - safecopy(butxo->coin,Q.srccoin,sizeof(butxo->coin)); - safecopy(butxo->coinaddr,Q.coinaddr,sizeof(butxo->coinaddr)); - butxo->payment.txid = Q.txid; - butxo->payment.vout = Q.vout; - //butxo->payment.value = Q.value; - butxo->iambob = 1; - butxo->deposit.txid = Q.txid2; - butxo->deposit.vout = Q.vout2; - //butxo->deposit.value = up2->U.value; - butxo->S.satoshis = Q.satoshis; - memset(&A,0,sizeof(A)); autxo = &A; - autxo->pubkey = Q.desthash; - safecopy(autxo->coin,Q.destcoin,sizeof(autxo->coin)); - safecopy(autxo->coinaddr,Q.destaddr,sizeof(autxo->coinaddr)); - autxo->payment.txid = Q.desttxid; - autxo->payment.vout = Q.destvout; - //autxo->payment.value = Q.value; - autxo->iambob = 0; - autxo->deposit.txid = Q.feetxid; - autxo->deposit.vout = Q.feevout; - //autxo->deposit.value = up2->U.value; - autxo->S.satoshis = Q.destsatoshis; + butxo = &B; + LP_abutxo_set(autxo,butxo,&Q); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 430448a29..b10faa211 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -929,7 +929,7 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price) { if ( fabs(pubp->matrix[basepp->ind][relpp->ind] - price) > SMALLVAL ) { - if ( (rand() % 100) == 0 ) + if ( (rand() % 5000) == 0 ) printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); pubp->matrix[basepp->ind][relpp->ind] = price; dxblend(&basepp->relvals[relpp->ind],price,0.9); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 925354973..bd27731cd 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -394,7 +394,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit tmpsatoshis = (((value2 - 2*txfee) / 9) << 3); else return(0); } else tmpsatoshis = (value - txfee); - char str[65],str2[65],dispflag = (iambob == 0); + char str[65],str2[65],dispflag = 0;//(iambob == 0); if ( iambob == 0 && bits256_cmp(pubkey,LP_mypub25519) != 0 ) { printf("trying to add Alice utxo when not mine? %s/v%d\n",bits256_str(str,txid),vout); @@ -681,7 +681,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri txid = jbits256(item,"txid"); vout = juint(item,"vout"); value = LP_value_extract(item,0); - height = coin->height - jint(item,"confirmations"); + height = LP_getheight(coin) - jint(item,"confirmations"); } else { From 2c36befb0cbc4eb93af9bb5da74b5528f1dcfd69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 19:35:11 +0200 Subject: [PATCH 150/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 838686adc..adb1043bb 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -589,7 +589,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else if ( strcmp(method,"connect") == 0 ) // bob { retval = 4; - if ( butxo->T.swappending != 0 && butxo->S.swap == 0 ) + if ( butxo->S.swap == 0 ) //butxo->T.swappending != 0 && LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } From 94804f2a63791ffd61767d1c37a4a87672c9085f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 19:46:04 +0200 Subject: [PATCH 151/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxo.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index adb1043bb..1b2a1ee76 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -401,7 +401,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ return(-1); } privkey = LP_privkey(utxo->coinaddr,coin->taddr); - if ( bits256_nonz(privkey) != 0 && qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && bits256_cmp(LP_mypub25519,qp->srchash) == 0 ) + if ( bits256_nonz(privkey) != 0 && bits256_cmp(LP_mypub25519,qp->srchash) == 0 ) //qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && { if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 064db834e..f55b13f5a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -193,7 +193,7 @@ cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32 { jaddbits256(item,"txid",up->U.txid); jaddnum(item,"vout",up->U.vout); - jaddnum(item,"confirmations",coin->height - up->U.height); + jaddnum(item,"confirmations",LP_getheight(coin) - up->U.height); jaddnum(item,"amount",dstr(up->U.value)); jaddstr(item,"scriptPubKey",""); } @@ -281,11 +281,11 @@ char *LP_postedutxos(cJSON *argjson) errs++; } if ( coin->height != 0 ) - ht = coin->height - jint(txobj,"confirmations"); + ht = LP_getheight(coin) - jint(txobj,"confirmations"); else ht = 0; if ( ht != 0 && ht < height-2 ) { - printf("REJECT %s %s/v%d ht.%d vs %d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jprint(item,0)); + printf("REJECT %s %s/v%d ht.%d vs %d confs.%d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jint(txobj,"confirmations"),jprint(item,0)); errs++; } free_json(txobj); From 3200ea2ba3715f0f3986dce362455e019c70a0b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 19:49:20 +0200 Subject: [PATCH 152/520] Test --- iguana/exchanges/LP_rpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 5f6e34af4..b2d89ce85 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -250,6 +250,8 @@ cJSON *LP_paxprice(char *fiat) cJSON *LP_gettx(char *symbol,bits256 txid) { char buf[128],str[65],*hexstr; int32_t len; bits256 checktxid; cJSON *retjson; struct iguana_info *coin; struct iguana_msgtx msgtx; uint8_t *extraspace,*serialized; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); From 87adf904271cc3109d63d9a232f96a0ef70f4f59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 19:55:05 +0200 Subject: [PATCH 153/520] Error checks --- iguana/exchanges/LP_rpc.c | 62 ++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b2d89ce85..8f3924833 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -120,6 +120,8 @@ char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coi char *LP_apicall(struct iguana_info *coin,char *method,char *params) { cJSON *retjson; char *retstr; + if ( coin == 0 ) + return(0); if ( coin->electrum != 0 ) { if ( (retjson= electrum_submit(coin->symbol,coin->electrum,&retjson,method,params,LP_HTTP_TIMEOUT)) != 0 ) @@ -211,9 +213,10 @@ cJSON *LP_assethbla(char *assetid) int32_t LP_getheight(struct iguana_info *coin) { - cJSON *retjson; char *method = "getinfo"; int32_t height = coin->height; + cJSON *retjson; char *method = "getinfo"; int32_t height; if ( coin == 0 ) return(-1); + height = coin->height; if ( coin->electrum == 0 && time(NULL) > coin->heighttime+60 ) { if ( strcmp(coin->symbol,"BTC") == 0 ) @@ -230,7 +233,10 @@ int32_t LP_getheight(struct iguana_info *coin) cJSON *LP_getmempool(char *symbol,char *coinaddr) { - cJSON *array; struct iguana_info *coin = LP_coinfind(symbol); + cJSON *array; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); + coin = LP_coinfind(symbol); if ( coin == 0 || (coin->electrum != 0 && coinaddr == 0) ) return(cJSON_Parse("{\"error\":\"no native coin\"}")); if ( coin->electrum == 0 ) @@ -301,6 +307,8 @@ cJSON *LP_gettx(char *symbol,bits256 txid) cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) { char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); @@ -402,7 +410,10 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) cJSON *LP_validateaddress(char *symbol,char *address) { - char buf[512],coinaddr[64],checkaddr[64],script[128]; int32_t i; uint8_t rmd160[20],addrtype; cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); + char buf[512],coinaddr[64],checkaddr[64],script[128]; int32_t i; uint8_t rmd160[20],addrtype; cJSON *retjson; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); + coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); if ( coin != 0 && coin->electrum != 0 ) @@ -438,6 +449,8 @@ cJSON *LP_validateaddress(char *symbol,char *address) int32_t LP_address_ismine(char *symbol,char *address) { int32_t doneflag = 0; cJSON *retjson; + if ( symbol == 0 || symbol[0] == 0 ) + return(0); if ( (retjson= LP_validateaddress(symbol,address)) != 0 ) { if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) @@ -453,7 +466,10 @@ int32_t LP_address_ismine(char *symbol,char *address) cJSON *LP_listunspent(char *symbol,char *coinaddr) { - char buf[128]; cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); + char buf[128]; cJSON *retjson; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); + coin = LP_coinfind(symbol); //printf("LP_listunspent.(%s %s)\n",symbol,coinaddr); if ( coin == 0 || coin->inactive != 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); @@ -470,6 +486,8 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) void LP_listunspent_issue(char *symbol,char *coinaddr) { struct iguana_info *coin; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; + if ( symbol == 0 || symbol[0] == 0 ) + return; if ( (coin= LP_coinfind(symbol)) != 0 ) { if ( coin->electrum != 0 ) @@ -500,6 +518,8 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) { static void *ctx; char buf[512],address[64]; cJSON *retjson; struct iguana_info *coin; int32_t doneflag = 0; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); @@ -529,7 +549,10 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) int32_t LP_importaddress(char *symbol,char *address) { - char buf[1024],*retstr; cJSON *validatejson,*retjson; int32_t isvalid=0,doneflag = 0; struct iguana_info *coin = LP_coinfind(symbol); + char buf[1024],*retstr; cJSON *validatejson,*retjson; int32_t isvalid=0,doneflag = 0; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(-2); + coin = LP_coinfind(symbol); if ( coin == 0 ) return(-2); if ( coin->electrum != 0 ) @@ -597,6 +620,8 @@ double LP_getestimatedrate(struct iguana_info *coin) char *LP_sendrawtransaction(char *symbol,char *signedtx) { cJSON *array; char *paramstr,*tmpstr,*retstr=0; int32_t n; cJSON *retjson; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(0); coin = LP_coinfind(symbol); if ( coin == 0 ) return(0); @@ -630,7 +655,10 @@ char *LP_sendrawtransaction(char *symbol,char *signedtx) char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkeys,struct vin_info *V) { - cJSON *array,*json,*retjson; int32_t len; uint8_t *data; char str[65],*paramstr,*retstr,*hexstr,*signedtx=0; struct iguana_msgtx msgtx; struct iguana_info *coin = LP_coinfind(symbol); + cJSON *array,*json,*retjson; int32_t len; uint8_t *data; char str[65],*paramstr,*retstr,*hexstr,*signedtx=0; struct iguana_msgtx msgtx; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(0); + coin = LP_coinfind(symbol); memset(signedtxidp,0,sizeof(*signedtxidp)); *completedp = 0; if ( coin == 0 ) @@ -697,7 +725,10 @@ char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON * cJSON *LP_getblock(char *symbol,bits256 txid) { - char buf[128],str[65]; struct iguana_info *coin = LP_coinfind(symbol); + char buf[128],str[65]; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); + coin = LP_coinfind(symbol); if ( coin == 0 || coin->electrum != 0 ) return(cJSON_Parse("{\"error\":\"no native coin\"}")); sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); @@ -708,6 +739,8 @@ cJSON *LP_getblock(char *symbol,bits256 txid) uint64_t LP_txfee(char *symbol) { uint64_t txfee = 0; + if ( symbol == 0 || symbol[0] == 0 ) + return(LP_MIN_TXFEE); if ( strcmp(symbol,"BTC") != 0 ) txfee = LP_MIN_TXFEE; return(txfee); @@ -715,7 +748,10 @@ uint64_t LP_txfee(char *symbol) char *LP_blockhashstr(char *symbol,int32_t height) { - cJSON *array; char *paramstr,*retstr; struct iguana_info *coin = LP_coinfind(symbol); + cJSON *array; char *paramstr,*retstr; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(0); + coin = LP_coinfind(symbol); if ( coin == 0 || coin->electrum != 0 ) return(0); array = cJSON_CreateArray(); @@ -728,7 +764,10 @@ char *LP_blockhashstr(char *symbol,int32_t height) cJSON *LP_getblockhashstr(char *symbol,char *blockhashstr) { - char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); + char buf[128]; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); + coin = LP_coinfind(symbol); if ( coin == 0 || coin->electrum != 0 ) return(cJSON_Parse("{\"error\":\"no native coin daemon\"}")); sprintf(buf,"[\"%s\"]",blockhashstr); @@ -737,7 +776,10 @@ cJSON *LP_getblockhashstr(char *symbol,char *blockhashstr) cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t height) { - cJSON *json = 0; int32_t flag = 0; struct iguana_info *coin = LP_coinfind(symbol); + cJSON *json = 0; int32_t flag = 0; struct iguana_info *coin; + if ( symbol == 0 || symbol[0] == 0 ) + return(cJSON_Parse("{\"error\":\"null symbol\"}")); + coin = LP_coinfind(symbol); if ( coin == 0 || coin->electrum != 0 ) { printf("unexpected electrum path for %s\n",symbol); From 61904047ee6728c41952b71cab845c02fca78339 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 19:59:09 +0200 Subject: [PATCH 154/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 1b2a1ee76..5d332a8d3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -459,8 +459,8 @@ void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP autxo->payment.vout = qp->destvout; //autxo->payment.value = qp->value; autxo->iambob = 0; - autxo->deposit.txid = qp->feetxid; - autxo->deposit.vout = qp->feevout; + autxo->fee.txid = qp->feetxid; + autxo->fee.vout = qp->feevout; //autxo->deposit.value = up2->U.value; autxo->S.satoshis = qp->destsatoshis; } From 6ca9d6518336ea54356aec33199080c00d95a694 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:15:58 +0200 Subject: [PATCH 155/520] Test --- iguana/exchanges/LP_rpc.c | 6 +++--- iguana/exchanges/LP_utxo.c | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 8f3924833..bb5c6d347 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -549,7 +549,7 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) int32_t LP_importaddress(char *symbol,char *address) { - char buf[1024],*retstr; cJSON *validatejson,*retjson; int32_t isvalid=0,doneflag = 0; struct iguana_info *coin; + char buf[1024],*retstr; cJSON *validatejson; int32_t isvalid=0,doneflag = 0; struct iguana_info *coin; if ( symbol == 0 || symbol[0] == 0 ) return(-2); coin = LP_coinfind(symbol); @@ -557,11 +557,11 @@ int32_t LP_importaddress(char *symbol,char *address) return(-2); if ( coin->electrum != 0 ) { - if ( (retjson= electrum_address_subscribe(symbol,coin->electrum,&retjson,address)) != 0 ) + /*if ( (retjson= electrum_address_subscribe(symbol,coin->electrum,&retjson,address)) != 0 ) { printf("importaddress.(%s) -> %s\n",address,jprint(retjson,0)); free_json(retjson); - } + }*/ return(0); } else diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f55b13f5a..52ba64e71 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -531,9 +531,12 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int else { if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) - numconfirms = (coin->height - ht); - else if ( mempool != 0 && LP_waitmempool(symbol,coinaddr,txid,-1) >= 0 ) - numconfirms = 0; + numconfirms = (LP_getheight(coin) - ht); + else if ( mempool != 0 ) + { + if (LP_waitmempool(symbol,coinaddr,txid,30) >= 0 ) + numconfirms = 0; + } } //#endif return(numconfirms); From 045619d15068f54077903d4750fa467e56b8e9f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:18:58 +0200 Subject: [PATCH 156/520] Test --- iguana/exchanges/LP_scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 6d81a26c0..5f74346a0 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -45,7 +45,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) if (LP_transactioninit(coin,txid,iter,0) == 0 ) break; printf("transaction ht.%d init error.%d, pause\n",height,j); - sleep(1); + sleep(10); } } else @@ -55,7 +55,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) if (LP_transactioninit(coin,txid,iter,0) == 0 ) break; printf("transaction ht.%d init error.%d, pause\n",height,j); - sleep(1); + sleep(10); } } } From 12e499b2549dd1046edbee10a0d3a04a56fc9ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:30:53 +0200 Subject: [PATCH 157/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 3 ++- iguana/exchanges/LP_transaction.c | 6 +++--- iguana/exchanges/LP_utxo.c | 4 ++-- iguana/exchanges/LP_utxos.c | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5d332a8d3..78b9a4a27 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -819,7 +819,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); } - printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); + //printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index bb5c6d347..11b310a66 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -608,7 +608,8 @@ double LP_getestimatedrate(struct iguana_info *coin) rate = 0.00000020; coin->rate = rate * 1.25; coin->ratetime = (uint32_t)time(NULL); - printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); + if ( (rand() % 10) == 0 ) + printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); } free(retstr); } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 02c005b29..a5dfcde32 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1313,7 +1313,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da printf("%02x",swap->aliceclaim.txbytes[i]); printf(" <- aliceclaim\n");*/ //basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration); - return(LP_waitmempool(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,10)); + return(LP_waitmempool(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); } printf("error with bobdeposit\n"); @@ -1331,7 +1331,7 @@ int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 ) swap->aliceunconf = 1; basilisk_dontforget_update(swap,&swap->alicepayment); - return(LP_waitmempool(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,10)); + return(LP_waitmempool(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,60)); //printf("import alicepayment address.(%s)\n",swap->alicepayment.p2shaddr); //LP_importaddress(swap->alicecoin.symbol,swap->alicepayment.p2shaddr); return(0); @@ -1378,7 +1378,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da printf("%02x",swap->alicespend.txbytes[i]); printf(" <- alicespend\n\n");*/ swap->I.alicespent = 1; - return(LP_waitmempool(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,10)); + return(LP_waitmempool(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr); } printf("error validating bobpayment\n"); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 52ba64e71..0350b78ec 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -573,7 +573,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) { - printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); + //printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); return(0); } else @@ -688,7 +688,7 @@ int32_t LP_inventory_prevent(int32_t iambob,char *symbol,bits256 txid,int32_t vo } if ( utxo->T.spentflag != 0 ) { - char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); + //char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); return(1); } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index bd27731cd..be104cc6b 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -691,7 +691,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri height = jint(item,"height"); } satoshis = LP_txvalue(destaddr,coin->symbol,txid,vout); - if ( satoshis != value ) + if ( satoshis != 0 && satoshis != value ) printf("unexpected privkey_init value mismatch %.8f vs %.8f (%s) %.8f %.8f\n",dstr(satoshis),dstr(value),jprint(item,0),jdouble(item,"amount"),jdouble(item,"interest")); if ( LP_inventory_prevent(iambob,coin->symbol,txid,vout) == 0 && height > 0 ) { From 0db4286d1435b2f4edb81ea03d6b4c837b8175d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:37:53 +0200 Subject: [PATCH 158/520] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index a778d0c9d..87324d4cd 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -26,7 +26,7 @@ #include #endif -#define ELECTRUM_TIMEOUT 3 +#define ELECTRUM_TIMEOUT 13 int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 0350b78ec..bf918e379 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -554,7 +554,7 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { - struct LP_transaction *tx; cJSON *txobj=0; uint64_t value; struct iguana_info *coin; char str[65],str2[65],_coinaddr[65]; + struct LP_transaction *tx; cJSON *txobj=0; uint64_t value; struct iguana_info *coin; char str[65],_coinaddr[65]; if ( bits256_nonz(txid) == 0 ) return(0); if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) From aa86b50a5fa095cc76b54c48383dc793bd15b7f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:43:44 +0200 Subject: [PATCH 159/520] Test --- iguana/exchanges/LP_utxo.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index bf918e379..ae9017281 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -30,12 +30,15 @@ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { - double val = 0.; uint64_t value; + double val = 0.; uint64_t value = 0; if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); - if ( val > SMALLVAL ) - value = ((val + jdouble(obj,"interest")*addinterest) * SATOSHIDEN + 0.0000000049); - else value = 0; + value = val * SATOSHIDEN + 0.0000000049; + if ( value != 0 ) + { + if ( addinterest != 0 && jobj(obj,"interest") != 0 ) + value += (jdouble(obj,"interest") * SATOSHIDEN); + } return(value); } @@ -464,7 +467,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); - if ( strcmp(coin->symbol,"BTC") != 0 ) + if ( 0 && strcmp(coin->symbol,"BTC") != 0 ) printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d spendheight.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts,tx->outpoints[spentvout].spendheight); } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); From 47aefb5a5cbae1dc6ee6e13d5225a02bff928b93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:47:27 +0200 Subject: [PATCH 160/520] Test --- iguana/exchanges/LP_scan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 5f74346a0..089cf9625 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -21,7 +21,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { - int32_t i,j,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; + char str[65]; int32_t i,j,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height ) { if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) @@ -44,7 +44,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { if (LP_transactioninit(coin,txid,iter,0) == 0 ) break; - printf("transaction ht.%d init error.%d, pause\n",height,j); + printf("%s transaction ht.%d init error.%d, pause\n",bits256_str(str,txid),height,j); sleep(10); } } @@ -54,7 +54,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { if (LP_transactioninit(coin,txid,iter,0) == 0 ) break; - printf("transaction ht.%d init error.%d, pause\n",height,j); + printf("%s transaction ht.%d init error.%d, pause\n",bits256_str(str,txid),height,j); sleep(10); } } From 0734cda9a0a51a5704bc8f9652b9d235ff343dc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:54:32 +0200 Subject: [PATCH 161/520] Test --- iguana/exchanges/LP_scan.c | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 089cf9625..7c49ed039 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -27,36 +27,22 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) { for (iter=0; iter<2; iter++) - for (i=0; iheight == 0 ) - tx->height = height; - else if ( tx->height != height ) + txid = jbits256i(txs,i); + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) { - printf("LP_blockinit: tx->height %d != %d\n",tx->height,height); - tx->height = height; - } - if ( iter == 1 ) - for (j=0; j<10; j++) + if ( tx->height == 0 ) + tx->height = height; + else if ( tx->height != height ) { - if (LP_transactioninit(coin,txid,iter,0) == 0 ) - break; - printf("%s transaction ht.%d init error.%d, pause\n",bits256_str(str,txid),height,j); - sleep(10); + printf("LP_blockinit: tx->height %d != %d\n",tx->height,height); + tx->height = height; } - } - else - { - for (j=0; j<10; j++) - { - if (LP_transactioninit(coin,txid,iter,0) == 0 ) - break; - printf("%s transaction ht.%d init error.%d, pause\n",bits256_str(str,txid),height,j); - sleep(10); - } + if ( iter == 1 ) + LP_transactioninit(coin,txid,iter,0); + } else LP_transactioninit(coin,txid,iter,0); } } } From 5d1d15b07bc5c99010d8e4775e0b23d0cc2db549 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 20:57:09 +0200 Subject: [PATCH 162/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 87324d4cd..47014d145 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -371,7 +371,7 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch usleep(10000); if ( *retjsonp == 0 ) { - printf("unexpected timeout with null retjson: %s %s\n",method,params); + printf("unexpected %s timeout with null retjson: %s %s\n",ep->symbol,method,params); *retjsonp = cJSON_Parse("{\"error\":\"timeout\"}"); } return(*retjsonp); From 8f159179ec329a3169f2f9c485f5267acf026223 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 21:03:29 +0200 Subject: [PATCH 163/520] Test --- iguana/exchanges/LP_utxo.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ae9017281..80ffb7e4c 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -286,11 +286,11 @@ char *LP_postedutxos(cJSON *argjson) if ( coin->height != 0 ) ht = LP_getheight(coin) - jint(txobj,"confirmations"); else ht = 0; - if ( ht != 0 && ht < height-2 ) + /*if ( ht != 0 && ht < height-2 ) { printf("REJECT %s %s/v%d ht.%d vs %d confs.%d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jint(txobj,"confirmations"),jprint(item,0)); errs++; - } + }*/ free_json(txobj); } if ( errs == 0 ) @@ -461,14 +461,17 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS continue; if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 ) { - if ( spentvout < tx->numvouts && tx->outpoints[spentvout].spendheight <= 0 ) + if ( spentvout < tx->numvouts ) { - tx->outpoints[spentvout].spendtxid = txid; - tx->outpoints[spentvout].spendvini = i; - tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; - LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); - if ( 0 && strcmp(coin->symbol,"BTC") != 0 ) - printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); + if ( tx->outpoints[spentvout].spendheight <= 0 ) + { + tx->outpoints[spentvout].spendtxid = txid; + tx->outpoints[spentvout].spendvini = i; + tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; + LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); + if ( 0 && strcmp(coin->symbol,"BTC") != 0 ) + printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); + } } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d spendheight.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts,tx->outpoints[spentvout].spendheight); } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); if ( bits256_cmp(spenttxid,txid) == 0 ) From aa06cb1c689192d80ae1987b0ee45c9124cf68a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 21:07:29 +0200 Subject: [PATCH 164/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 78b9a4a27..e31f663b0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -629,7 +629,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q { if ( aliceutxo->S.swap != 0 ) break; - sleep(1); + sleep(3); } if ( aliceutxo->S.swap == 0 ) { From 4583c8f73e127b6b9e9b9c00be230bb60737ca45 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 21:11:52 +0200 Subject: [PATCH 165/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 80ffb7e4c..af767fc98 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -33,7 +33,7 @@ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) double val = 0.; uint64_t value = 0; if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); - value = val * SATOSHIDEN + 0.0000000049; + value = val * SATOSHIDEN + 0.0000000059; if ( value != 0 ) { if ( addinterest != 0 && jobj(obj,"interest") != 0 ) @@ -280,7 +280,7 @@ char *LP_postedutxos(cJSON *argjson) value = LP_value_extract(txobj,0); if ( value != 0 && value != val ) { - printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(item,0)); + printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(txobj,0)); errs++; } if ( coin->height != 0 ) From 167dbf79240c065b0f2c89768a98f4e3c00982d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 21:32:51 +0200 Subject: [PATCH 166/520] Test --- iguana/exchanges/electrum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/electrum b/iguana/exchanges/electrum index 8bf0eb38a..e7f562b41 100755 --- a/iguana/exchanges/electrum +++ b/iguana/exchanges/electrum @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"46.4.125.2\",\"port\":50001}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"173.212.225.176\",\"port\":50001}" From 479bacbd8fd689a51b4f88a5bbbdf730f991a377 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 21:51:22 +0200 Subject: [PATCH 167/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 11b310a66..fad136744 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -274,7 +274,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); - if ( strlen(hexstr) > 50000 ) + if ( strlen(hexstr) > 100000 ) { printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); free(hexstr); From 5af45e2d6d6385eb29153e7f93a00907432dad77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:04:48 +0200 Subject: [PATCH 168/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index fad136744..2e2a1fd0b 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -274,7 +274,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); - if ( strlen(hexstr) > 100000 ) + if ( strlen(hexstr) > 10000 ) { printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); free(hexstr); From e2d492c4ffe21c6d6efbbf9f80a87dae6409535a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:09:38 +0200 Subject: [PATCH 169/520] Test --- iguana/exchanges/LP_utxo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index af767fc98..592f35b11 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -27,6 +27,10 @@ // electrum only, network for gettxout // locally track spends, height +/*spent.0 BTC txid or value 0.00980000 < 0.00937462 or val2 0.00000000 < 0.00043744, e85478826d74936168197a655bc81bb918a31c278295a5f68d0eaff32b1a3900/v1 83a8baea6a5741c2c96ac346aef905c0f694acf6beeb764508969271b8fe6db0/v0 or < 10x txfee 0.00042538 +BTC 83a8baea6a5741c2c96ac346aef905c0f694acf6beeb764508969271b8fe6db0 ineligible 0.00980000 0.00000000 +couldnt find.245433003 peerind.2 Q.13 err.0 match.5 +*/ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { @@ -649,6 +653,10 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol } // else printf("no val2\n"); } char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); + if ( val == 0 ) + LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,-1,1); + if ( val2 == 0 ) + LP_address_utxoadd(coin,destaddr,txid2,vout2,threshold,-1,1); /*for (iter=0; iter<2; iter++) { if ( (utxo= LP_utxofind(iter,txid,vout)) != 0 ) From d3e455ecad7e1ea561c0059bf870810a2d3a455d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:10:14 +0200 Subject: [PATCH 170/520] Test --- iguana/exchanges/LP_rpc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2e2a1fd0b..39ddac1a0 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -276,7 +276,9 @@ cJSON *LP_gettx(char *symbol,bits256 txid) hexstr = jprint(retjson,1); if ( strlen(hexstr) > 10000 ) { - printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); + static uint32_t counter; + if ( counter++ < 3 ) + printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); free(hexstr); return(cJSON_Parse("{\"error\":\"transaction too big\"}")); } @@ -326,9 +328,11 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) if ( (hexobj= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(hexobj,1); - if ( strlen(hexstr) > 50000 ) + if ( strlen(hexstr) > 10000 ) { - printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); + static uint32_t counter; + if ( counter++ < 3 ) + printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); free(hexstr); return(cJSON_Parse("{\"error\":\"transaction too big\"}")); } From e6482c377d5ff419c0783986acb3665291bf3e6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:19:06 +0200 Subject: [PATCH 171/520] Test --- iguana/exchanges/LP_utxo.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 592f35b11..da720368e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -153,6 +153,21 @@ int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct L return(n); } +struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout) +{ + struct LP_address *ap; struct LP_address_utxo *up,*tmp; + //printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); + if ( (ap= _LP_address(coin,coinaddr)) != 0 ) + { + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 ) + return(up); + } + } + return(0); +} + int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; @@ -619,7 +634,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2) { //struct LP_utxoinfo *utxo; - uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); + struct LP_address_utxo *up; uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 ) { printf("null txid not eligible\n"); @@ -631,6 +646,10 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol if ( bypass != 0 ) val = satoshis; else val = LP_txvalue(destaddr,symbol,txid,vout); + if ( (up= LP_address_utxofind(coin,destaddr,txid,vout)) != 0 && up->spendheight > 0 ) + return(-2); + if ( (up= LP_address_utxofind(coin,destaddr,txid2,vout2)) != 0 && up->spendheight > 0 ) + return(-3); txfee = LP_txfeecalc(LP_coinfind(symbol),0); if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee ) { From 5d9cc63da82964d1dfb00571e36335f4dae7ffa9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:21:23 +0200 Subject: [PATCH 172/520] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 47014d145..f4befdba9 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -26,7 +26,7 @@ #include #endif -#define ELECTRUM_TIMEOUT 13 +#define ELECTRUM_TIMEOUT 3 int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index da720368e..21ae3d676 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -26,11 +26,6 @@ // pruned node, network for external listunspent, gettxout to validate // electrum only, network for gettxout -// locally track spends, height -/*spent.0 BTC txid or value 0.00980000 < 0.00937462 or val2 0.00000000 < 0.00043744, e85478826d74936168197a655bc81bb918a31c278295a5f68d0eaff32b1a3900/v1 83a8baea6a5741c2c96ac346aef905c0f694acf6beeb764508969271b8fe6db0/v0 or < 10x txfee 0.00042538 -BTC 83a8baea6a5741c2c96ac346aef905c0f694acf6beeb764508969271b8fe6db0 ineligible 0.00980000 0.00000000 -couldnt find.245433003 peerind.2 Q.13 err.0 match.5 -*/ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { From f0b652864da8cb0b3ac8d6ac16e08718db0f9e1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:31:26 +0200 Subject: [PATCH 173/520] Test --- iguana/exchanges/LP_rpc.c | 7 +++++++ iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 39ddac1a0..2a6a0e89a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -159,6 +159,13 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) { if ( (retjson= electrum_submit(coin->symbol,coin->electrum,&retjson,method,params,LP_HTTP_TIMEOUT)) != 0 ) { + if ( jobj(retjson,"error") != 0 ) + { + free_json(retjson); + retjson = 0; + retjson = electrum_submit(coin->symbol,coin->electrum,&retjson,method,params,LP_HTTP_TIMEOUT); + printf("RETRY.(%s)\n",jprint(retjson,0)); + } //printf("electrum %s.%s -> (%s)\n",method,params,jprint(retjson,0)); /*if ( (resultjson= jobj(retjson,"result")) != 0 ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index f4befdba9..70af8f427 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -666,7 +666,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( stritem->expiration < ep->lasttime ) { DL_DELETE(ep->pendingQ.list,item); - printf("expired (%s)\n",stritem->str); + printf("expired %s (%s)\n",ep->symbol,stritem->str); errjson = cJSON_CreateObject(); jaddnum(errjson,"id",item->type); jaddstr(errjson,"error","timeout"); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 21ae3d676..4aa50918d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -26,6 +26,9 @@ // pruned node, network for external listunspent, gettxout to validate // electrum only, network for gettxout +// handle spurious errors +// handle invalid data + uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { From 6d2bff50cf5fe1e5aea60d63270d740a168e9aea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:41:23 +0200 Subject: [PATCH 174/520] Test --- iguana/exchanges/LP_rpc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2a6a0e89a..51f9bddba 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -163,8 +163,6 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) { free_json(retjson); retjson = 0; - retjson = electrum_submit(coin->symbol,coin->electrum,&retjson,method,params,LP_HTTP_TIMEOUT); - printf("RETRY.(%s)\n",jprint(retjson,0)); } //printf("electrum %s.%s -> (%s)\n",method,params,jprint(retjson,0)); /*if ( (resultjson= jobj(retjson,"result")) != 0 ) @@ -278,7 +276,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) else { sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); - if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) + if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 || (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); if ( strlen(hexstr) > 10000 ) From 3e5a040f828bfddf190dae040c8b736bd768fb5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:44:06 +0200 Subject: [PATCH 175/520] Test --- iguana/exchanges/LP_commands.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index ba09dc42c..e9099f018 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,8 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; //printf("stats_JSON(%s)\n",jprint(argjson,0)); - if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 ) + method = jstr(argjson,"method"); + if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) { @@ -60,7 +61,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r } else LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,argport,pushport,subport,jint(argjson,"numpeers"),jint(argjson,"numutxos"),juint(argjson,"session")); } } - if ( (method= jstr(argjson,"method")) == 0 ) + if ( method == 0 ) { if ( flag == 0 || jobj(argjson,"result") != 0 ) printf("stats_JSON no method: (%s) (%s:%u)\n",jprint(argjson,0),ipaddr,argport); From c905af95f081052310149c001f6ac50f41e8480a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:46:09 +0200 Subject: [PATCH 176/520] Test --- iguana/exchanges/LP_include.h | 1 - iguana/exchanges/LP_peers.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index af0f0fee3..292b997d6 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -23,7 +23,6 @@ //#define LP_STRICTPEERS -#define LP_ELECTRUM_MINPORT 8776 #define LP_COMMAND_SENDSOCK NN_PUSH #define LP_COMMAND_RECVSOCK NN_PULL diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index f6c2bc4f5..e249f099a 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -58,8 +58,6 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char { uint32_t ipbits; int32_t pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; printf("addpeer (%s:%u)\n",ipaddr,port); - if ( port >= LP_ELECTRUM_MINPORT ) - return(0); #ifdef LP_STRICTPEERS if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) return(0); From af899f856ff60839f7d03648b7a6c9923b171553 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:52:33 +0200 Subject: [PATCH 177/520] Test --- iguana/exchanges/LP_utxo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 4aa50918d..1a055033b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -622,9 +622,10 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) LP_destaddr(coinaddr,txobj); free_json(txobj); //printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); - return(value); + if ( value != 0 ) + return(value); } - printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); + printf("pruned node? LP_txvalue couldnt find %s tx %s/v%d\n",coin->symbol,bits256_str(str,txid),vout); } return(0); } From 90b8417b1e72cc8b2d8d68254f6cdabb472f65b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:56:35 +0200 Subject: [PATCH 178/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1a055033b..300dfb47b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -35,7 +35,7 @@ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) double val = 0.; uint64_t value = 0; if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); - value = val * SATOSHIDEN + 0.0000000059; + value = val * SATOSHIDEN + 0.000000009; if ( value != 0 ) { if ( addinterest != 0 && jobj(obj,"interest") != 0 ) From 95f0719156db5c060d107b34dfa97e9120004656 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 22:58:44 +0200 Subject: [PATCH 179/520] Test --- iguana/exchanges/LP_rpc.c | 4 +++- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 51f9bddba..aadc15035 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -276,7 +276,9 @@ cJSON *LP_gettx(char *symbol,bits256 txid) else { sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); - if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 || (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) + if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 || + (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 || + (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); if ( strlen(hexstr) > 10000 ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 70af8f427..9274ecbbb 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -26,7 +26,7 @@ #include #endif -#define ELECTRUM_TIMEOUT 3 +#define ELECTRUM_TIMEOUT 5 int32_t LP_socket(int32_t bindflag,char *hostname,uint16_t port) { From 24e35d53858710039ef802343742bc41595810d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 23:03:36 +0200 Subject: [PATCH 180/520] Test --- iguana/exchanges/LP_socket.c | 15 +++++++++------ iguana/exchanges/LP_utxo.c | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 9274ecbbb..493aa1ead 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -371,7 +371,7 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch usleep(10000); if ( *retjsonp == 0 ) { - printf("unexpected %s timeout with null retjson: %s %s\n",ep->symbol,method,params); + //printf("unexpected %s timeout with null retjson: %s %s\n",ep->symbol,method,params); *retjsonp = cJSON_Parse("{\"error\":\"timeout\"}"); } return(*retjsonp); @@ -666,11 +666,14 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( stritem->expiration < ep->lasttime ) { DL_DELETE(ep->pendingQ.list,item); - printf("expired %s (%s)\n",ep->symbol,stritem->str); - errjson = cJSON_CreateObject(); - jaddnum(errjson,"id",item->type); - jaddstr(errjson,"error","timeout"); - *((cJSON **)stritem->retptrp) = errjson; + if ( 0 ) + { + printf("expired %s (%s)\n",ep->symbol,stritem->str); + errjson = cJSON_CreateObject(); + jaddnum(errjson,"id",item->type); + jaddstr(errjson,"error","timeout"); + *((cJSON **)stritem->retptrp) = errjson; + } free(item); } } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 300dfb47b..2522ea529 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -29,6 +29,7 @@ // handle spurious errors // handle invalid data +//REJECT KMD ccee27b53b52ca61bbc9fdc7de5feb0a12c14d4d92639414d372f002cc3d092f/v0 value.468169379 vs 468169380 ({"bestblock":"080400d4216c02d100004fd2f4f3505ddb507b643785e02703d3412feba39fb1","confirmations":2356,"value":4.68169380,"scriptPubKey":{"asm":"0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842 OP_CHECKSIG","hex":"210224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842ac","reqSigs":1,"type":"pubkey","addresses":["RFssbc211PJdVy1bvcvAG5X2N4ovPAoy5o"]},"version":1,"coinbase":true}) uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) { From 26fb43d5e38736b11f05cc8baebe040fc3fb5136 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 19 Sep 2017 23:09:53 +0200 Subject: [PATCH 181/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 2522ea529..29ab3fc4a 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -36,7 +36,7 @@ uint64_t LP_value_extract(cJSON *obj,int32_t addinterest) double val = 0.; uint64_t value = 0; if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); - value = val * SATOSHIDEN + 0.000000009; + value = (val + 0.0000000049) * SATOSHIDEN; if ( value != 0 ) { if ( addinterest != 0 && jobj(obj,"interest") != 0 ) From 0f265b65a72dfcbb203f0fccd03e94c8674a9443 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Sep 2017 07:23:32 +0200 Subject: [PATCH 182/520] Test --- iguana/exchanges/LP_scan.c | 2 +- iguana/exchanges/LP_socket.c | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 7c49ed039..ce4a2b0ee 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -21,7 +21,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { - char str[65]; int32_t i,j,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; + int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height ) { if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 493aa1ead..fa41ecb01 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -198,7 +198,7 @@ int32_t LP_socketsend(int32_t sock,uint8_t *serialized,int32_t len) flags = MSG_NOSIGNAL; #endif remains = len; - while ( remains > 0 ) + while ( sock >= 0 && remains > 0 ) { if ( (numsent= (int32_t)send(sock,serialized,remains,flags)) < 0 ) { @@ -225,7 +225,7 @@ int32_t LP_socketsend(int32_t sock,uint8_t *serialized,int32_t len) int32_t LP_socketrecv(int32_t sock,uint8_t *recvbuf,int32_t maxlen) { int32_t recvlen = -1; - while ( 1 ) + while ( sock >= 0 ) { if ( (recvlen= (int32_t)recv(sock,recvbuf,maxlen,0)) < 0 ) { @@ -574,7 +574,7 @@ void electrum_test() struct electrum_info *LP_electrum_info(int32_t *alreadyp,char *symbol,char *ipaddr,uint16_t port,int32_t bufsize) { - struct electrum_info *ep=0; int32_t i; struct stritem *sitem; char name[512],*str = "init string"; + struct electrum_info *ep=0; int32_t i,sock; struct stritem *sitem; char name[512],*str = "init string"; *alreadyp = 0; portable_mutex_lock(&LP_electrummutex); for (i=0; isock = LP_socket(0,ipaddr,port); + ep->sock = sock; safecopy(ep->symbol,symbol,sizeof(ep->symbol)); safecopy(ep->ipaddr,ipaddr,sizeof(ep->ipaddr)); ep->port = port; @@ -771,7 +776,11 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port) struct electrum_info *ep; int32_t already; cJSON *retjson = cJSON_CreateObject(); jaddstr(retjson,"ipaddr",ipaddr); jaddnum(retjson,"port",port); - ep = LP_electrum_info(&already,coin->symbol,ipaddr,port,IGUANA_MAXPACKETSIZE * 10); + if ( (ep= LP_electrum_info(&already,coin->symbol,ipaddr,port,IGUANA_MAXPACKETSIZE * 10)) == 0 ) + { + jaddstr(retjson,"error","couldnt connect to electrum server"); + return(retjson); + } if ( already == 0 ) { if ( ep != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_dedicatedloop,(void *)ep) != 0 ) From cd0dddfdfc48aefc76a9fd087845640632e05156 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Sep 2017 07:24:33 +0200 Subject: [PATCH 183/520] Test --- iguana/exchanges/LP_rpc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index aadc15035..9e900a3c6 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -276,9 +276,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) else { sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); - if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 || - (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 || - (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) + if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); if ( strlen(hexstr) > 10000 ) @@ -308,7 +306,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else printf("non-hex tx.(%s)\n",hexstr); free(hexstr); return(cJSON_Parse("{\"error\":\"non hex transaction\"}")); - } else printf("failed blockcjhain.transaction.get\n"); + } else printf("failed blockchain.transaction.get\n"); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); } } From 3e6aa58744d2f68c3419f5d3bde654a7231afc4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Sep 2017 07:29:38 +0200 Subject: [PATCH 184/520] Test --- iguana/exchanges/LP_bitcoin.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index ba6a5b63f..67325c8dc 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2619,7 +2619,8 @@ cJSON *bitcoin_txscript(char *asmstr,char **vardata,int32_t numvars) { int32_t i; cJSON *scriptjson,*array; scriptjson = cJSON_CreateObject(); - jaddstr(scriptjson,"asm",asmstr); + if ( asmstr != 0 ) + jaddstr(scriptjson,"asm",asmstr); jaddnum(scriptjson,"numvars",numvars); if ( numvars > 0 ) { @@ -3186,7 +3187,7 @@ int32_t iguana_parsevoutobj(uint8_t *serialized,int32_t maxsize,struct iguana_ms cJSON *iguana_voutjson(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct iguana_msgvout *vout,int32_t txi,bits256 txid) { // 035f1321ed17d387e4433b2fa229c53616057964af065f98bfcae2233c5108055e OP_CHECKSIG - char scriptstr[IGUANA_MAXSCRIPTSIZE+1],asmstr[2*IGUANA_MAXSCRIPTSIZE+1]; int32_t i,m,n,scriptlen,asmtype; struct vin_info *vp; + char scriptstr[IGUANA_MAXSCRIPTSIZE+1]; int32_t i,m,n,scriptlen,asmtype; struct vin_info *vp; uint8_t space[8192]; cJSON *addrs,*skey,*json = cJSON_CreateObject(); vp = calloc(1,sizeof(*vp)); jadd64bits(json,"satoshis",vout->value); @@ -3196,12 +3197,12 @@ cJSON *iguana_voutjson(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,struct igu if ( vout->pk_script != 0 && vout->pk_scriptlen*2+1 < sizeof(scriptstr) ) { memset(vp,0,sizeof(*vp)); - if ( (asmtype= iguana_calcrmd160(taddr,pubtype,p2shtype,asmstr,vp,vout->pk_script,vout->pk_scriptlen,txid,txi,0xffffffff)) >= 0 ) + if ( (asmtype= iguana_calcrmd160(taddr,pubtype,p2shtype,0,vp,vout->pk_script,vout->pk_scriptlen,txid,txi,0xffffffff)) >= 0 ) { skey = cJSON_CreateObject(); - scriptlen = iguana_scriptgen(taddr,pubtype,p2shtype,&m,&n,vp->coinaddr,space,asmstr,vp->rmd160,asmtype,vp,txi); - if ( asmstr[0] != 0 ) - jaddstr(skey,"asm",asmstr); + scriptlen = iguana_scriptgen(taddr,pubtype,p2shtype,&m,&n,vp->coinaddr,space,0,vp->rmd160,asmtype,vp,txi); + //if ( asmstr[0] != 0 ) + // jaddstr(skey,"asm",asmstr); addrs = cJSON_CreateArray(); if ( vp->N == 1 ) { From e2cfe9f20eb7412a8e33c3252d2f23ff2c41bdea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Sep 2017 07:30:38 +0200 Subject: [PATCH 185/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 9e900a3c6..ab670a326 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -306,7 +306,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else printf("non-hex tx.(%s)\n",hexstr); free(hexstr); return(cJSON_Parse("{\"error\":\"non hex transaction\"}")); - } else printf("failed blockchain.transaction.get\n"); + } else printf("failed blockchain.transaction.get %s\n",buf); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); } } From a55abad6c44c96f12a7c6bb185ba3af460f20011 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:06:19 +0200 Subject: [PATCH 186/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 3 +- iguana/exchanges/LP_ordermatch.c | 344 ++++++++++++++++++++---------- iguana/exchanges/LP_scan.c | 6 +- iguana/exchanges/LP_socket.c | 60 +++--- iguana/exchanges/LP_transaction.c | 4 +- iguana/exchanges/LP_utxo.c | 11 +- iguana/exchanges/electrum.kmd3 | 2 + 8 files changed, 282 insertions(+), 149 deletions(-) create mode 100755 iguana/exchanges/electrum.kmd3 diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 292b997d6..6453ce80c 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -306,6 +306,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); void LP_postutxos(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); +int32_t LP_butxo_findeither(bits256 txid,int32_t vout); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 993e27e8f..def85d884 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -30,7 +30,7 @@ #include #include "LP_include.h" -portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex; +portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex; int32_t LP_canbind; struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; @@ -633,6 +633,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_electrummutex); portable_mutex_init(&LP_messagemutex); portable_mutex_init(&LP_portfoliomutex); + portable_mutex_init(&LP_butxomutex); LP_sessionid = (uint32_t)time(NULL); printf("getting myipaddr sessionid.%u\n",LP_sessionid); if ( system("curl -s4 checkip.amazonaws.com > /tmp/myipaddr") == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e31f663b0..ef81f9b54 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -241,15 +241,15 @@ char *LP_postedprice(cJSON *argjson) return(clonestr("{\"error\":\"missing fields in posted price\"}")); } -int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp) +int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp,struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo) { int32_t selector,spendvini; bits256 spendtxid; - if ( (selector= LP_mempool_vinscan(&spendtxid,&spendvini,qp->srccoin,qp->coinaddr,qp->txid,qp->vout,qp->txid2,qp->vout2)) >= 0 ) + if ( butxo != 0 && (selector= LP_mempool_vinscan(&spendtxid,&spendvini,qp->srccoin,qp->coinaddr,qp->txid,qp->vout,qp->txid2,qp->vout2)) >= 0 ) { char str[65]; printf("LP_tradecommand selector.%d in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); return(-1); } - if ( (selector= LP_mempool_vinscan(&spendtxid,&spendvini,qp->destcoin,qp->destaddr,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) >= 0 ) + if ( autxo != 0 && (selector= LP_mempool_vinscan(&spendtxid,&spendvini,qp->destcoin,qp->destaddr,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) >= 0 ) { char str[65]; printf("LP_tradecommand dest selector.%d in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); return(-1); @@ -259,26 +259,29 @@ int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp) double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp,int32_t iambob) { - double qprice; uint64_t txfee,desttxfee,srcvalue,srcvalue2,destvalue,destvalue2; - if ( LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) + double qprice=0.; uint64_t txfee,desttxfee,srcvalue=0,srcvalue2=0,destvalue=0,destvalue2=0; + if ( butxo != 0 ) { - printf("bob not eligible\n"); - return(-2); + if (LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) + { + printf("bob not eligible\n"); + return(-2); + } + if ( bits256_cmp(butxo->deposit.txid,qp->txid2) != 0 || butxo->deposit.vout != qp->vout2 ) + return(-6); + if ( strcmp(butxo->coinaddr,qp->coinaddr) != 0 ) + return(-7); } - if ( LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) + if ( autxo != 0 && LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) { char str[65]; printf("alice not eligible (%.8f %.8f) %s/v%d\n",dstr(destvalue),dstr(destvalue2),bits256_str(str,qp->feetxid),qp->feevout); return(-3); } - if ( LP_quote_checkmempool(qp) < 0 ) + if ( LP_quote_checkmempool(qp,autxo,butxo) < 0 ) return(-4); //if ( iambob != 0 && (*butxop= LP_utxofind(1,qp->txid,qp->vout)) == 0 ) // return(-5); - if ( bits256_cmp(butxo->deposit.txid,qp->txid2) != 0 || butxo->deposit.vout != qp->vout2 ) - return(-6); - if ( strcmp(butxo->coinaddr,qp->coinaddr) != 0 ) - return(-7); - if ( iambob == 0 ) + if ( iambob == 0 && autxo != 0 ) { //if ( (*autxop= LP_utxofind(0,qp->desttxid,qp->destvout)) == 0 ) // return(-8); @@ -292,16 +295,22 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str printf("destvalue %.8f srcvalue %.8f, destsatoshis %.8f or satoshis %.8f is too small txfees %.8f %.8f?\n",dstr(destvalue),dstr(srcvalue),dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->desttxfee),dstr(qp->txfee)); return(-11); } - qprice = ((double)qp->destsatoshis / qp->satoshis); - if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT ) + if ( qp->satoshis != 0 ) { - printf("utxo payment %.8f is less than %f covered by Q %.8f or <10x txfee %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis),dstr(qp->txfee)); - return(-12); + qprice = ((double)qp->destsatoshis / qp->satoshis); + if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT ) + { + printf("utxo payment %.8f is less than %f covered by Q %.8f or <10x txfee %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis),dstr(qp->txfee)); + return(-12); + } } - if ( qp->destsatoshis < (destvalue / LP_MINCLIENTVOL) || destvalue < qp->desttxfee*LP_MINSIZE_TXFEEMULT ) + if ( qp->destsatoshis != 0 ) { - printf("destsatoshis %.8f is less than %f of value %.8f or < 10x txfee %.8f\n",dstr(qp->destsatoshis),1./LP_MINCLIENTVOL,dstr(destvalue),dstr(qp->desttxfee)); - return(-13); + if ( qp->destsatoshis < (destvalue / LP_MINCLIENTVOL) || destvalue < qp->desttxfee*LP_MINSIZE_TXFEEMULT ) + { + printf("destsatoshis %.8f is less than %f of value %.8f or < 10x txfee %.8f\n",dstr(qp->destsatoshis),1./LP_MINCLIENTVOL,dstr(destvalue),dstr(qp->desttxfee)); + return(-13); + } } LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); @@ -390,6 +399,174 @@ int32_t LP_nanobind(void *ctx,char *pairstr) return(pairsock); } +struct LP_utxoinfo BUTXOS[100]; + +int32_t LP_butxo_findeither(bits256 txid,int32_t vout) +{ + struct LP_utxoinfo *utxo; int32_t i,retval = 0; + portable_mutex_lock(&LP_butxomutex); + for (i=0; ipayment.vout && bits256_cmp(txid,utxo->payment.txid)) == 0 || (vout == utxo->deposit.vout && bits256_cmp(txid,utxo->deposit.txid) == 0) ) + { + retval = 1; + break; + } + } + portable_mutex_unlock(&LP_butxomutex); + return(retval); +} + +struct LP_utxoinfo *LP_butxo_find(struct LP_utxoinfo *butxo) +{ + int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); + portable_mutex_lock(&LP_butxomutex); + for (i=0; ipayment.vout == utxo->payment.vout && butxo->deposit.vout == utxo->deposit.vout && bits256_nonz(butxo->payment.txid) != 0 && bits256_nonz(butxo->deposit.txid) != 0 && bits256_cmp(butxo->payment.txid,utxo->payment.txid) == 0 && bits256_cmp(butxo->deposit.txid,utxo->deposit.txid) == 0 ) + break; + if ( utxo->S.swap == 0 && now > utxo->T.swappending ) + memset(utxo,0,sizeof(*utxo)); + } + portable_mutex_unlock(&LP_butxomutex); + return(utxo); +} + +struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) +{ + static struct LP_utxoinfo zeroes; + int32_t i; struct LP_utxoinfo *utxo=0; + portable_mutex_lock(&LP_butxomutex); + if ( (utxo= LP_butxo_find(butxo)) == 0 ) + { + for (i=0; iU.value - targetval); + //printf("(%.8f %.8f %.8f).%d ",dstr(values[i]),dstr(dist),dstr(mindist),mini); + if ( dist >= 0 && dist < mindist ) + { + mini = i; + mindist = dist; + } + } + } + return(mini); +} + +struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,int32_t avoidflag) +{ + struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; + if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) + { + if ( (m= LP_address_utxo_ptrs(utxos,max,ap,avoidflag)) > 1 ) + { + targetval = SATOSHIDEN * (volume / price) + 2*txfee; + { + int32_t i; + for (i=0; iU.value)); + printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); + } + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) + { + up = utxos[mini]; + utxos[mini] = 0; + targetval = (targetval / 8) * 9 + 2*txfee; + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) + { + if ( up != 0 && (up2= utxos[mini]) != 0 ) + { + safecopy(utxo->coin,coin->symbol,sizeof(utxo->coin)); + safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); + utxo->payment.txid = up->U.txid; + utxo->payment.vout = up->U.vout; + utxo->payment.value = up->U.value; + utxo->iambob = 1; + utxo->deposit.txid = up2->U.txid; + utxo->deposit.vout = up2->U.vout; + utxo->deposit.value = up2->U.value; + utxo->S.satoshis = SATOSHIDEN * (volume / price); + return(utxo); + } + } + } + } + } + return(0); +} + +void LP_butxo_swapfields_copy(struct LP_utxoinfo *destutxo,struct LP_utxoinfo *srcutxo) +{ + destutxo->S = srcutxo->S; + destutxo->T.swappending = srcutxo->T.swappending; +} + +void LP_butxo_swapfields(struct LP_utxoinfo *butxo) +{ + struct LP_utxoinfo *getutxo=0; + if ( (getutxo= LP_butxo_find(butxo)) != 0 ) + LP_butxo_swapfields_copy(butxo,getutxo); +} + +void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) +{ + struct LP_utxoinfo *setutxo; + if ( (setutxo= LP_butxo_add(butxo)) != 0 ) + LP_butxo_swapfields_copy(setutxo,butxo); +} + +void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) +{ + if ( butxo != 0 ) + { + memset(butxo,0,sizeof(*butxo)); + butxo->pubkey = qp->srchash; + safecopy(butxo->coin,qp->srccoin,sizeof(butxo->coin)); + safecopy(butxo->coinaddr,qp->coinaddr,sizeof(butxo->coinaddr)); + butxo->payment.txid = qp->txid; + butxo->payment.vout = qp->vout; + //butxo->payment.value = qp->value; + butxo->iambob = 1; + butxo->deposit.txid = qp->txid2; + butxo->deposit.vout = qp->vout2; + //butxo->deposit.value = up2->U.value; + butxo->S.satoshis = qp->satoshis; + } + if ( autxo != 0 ) + { + memset(autxo,0,sizeof(*autxo)); + autxo->pubkey = qp->desthash; + safecopy(autxo->coin,qp->destcoin,sizeof(autxo->coin)); + safecopy(autxo->coinaddr,qp->destaddr,sizeof(autxo->coinaddr)); + autxo->payment.txid = qp->desttxid; + autxo->payment.vout = qp->destvout; + //autxo->payment.value = qp->value; + autxo->iambob = 0; + autxo->fee.txid = qp->feetxid; + autxo->fee.vout = qp->feevout; + //autxo->deposit.value = up2->U.value; + autxo->S.satoshis = qp->destsatoshis; + } +} + int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJSON *argjson,char *base,char *rel,double price,struct LP_quoteinfo *qp) { char pairstr[512],*msg; cJSON *retjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin; @@ -401,7 +578,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ return(-1); } privkey = LP_privkey(utxo->coinaddr,coin->taddr); - if ( bits256_nonz(privkey) != 0 && bits256_cmp(LP_mypub25519,qp->srchash) == 0 ) //qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && + if ( bits256_nonz(privkey) != 0 && bits256_cmp(LP_mypub25519,qp->srchash) == 0 ) //qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && { if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 ) { @@ -434,37 +611,10 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ nn_close(pair); LP_availableset(utxo); } else LP_unavailableset(utxo,utxo->S.otherpubkey); + LP_butxo_swapfields(utxo); return(retval); } -void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) -{ - memset(butxo,0,sizeof(*butxo)); - butxo->pubkey = qp->srchash; - safecopy(butxo->coin,qp->srccoin,sizeof(butxo->coin)); - safecopy(butxo->coinaddr,qp->coinaddr,sizeof(butxo->coinaddr)); - butxo->payment.txid = qp->txid; - butxo->payment.vout = qp->vout; - //butxo->payment.value = qp->value; - butxo->iambob = 1; - butxo->deposit.txid = qp->txid2; - butxo->deposit.vout = qp->vout2; - //butxo->deposit.value = up2->U.value; - butxo->S.satoshis = qp->satoshis; - memset(autxo,0,sizeof(*autxo)); - autxo->pubkey = qp->desthash; - safecopy(autxo->coin,qp->destcoin,sizeof(autxo->coin)); - safecopy(autxo->coinaddr,qp->destaddr,sizeof(autxo->coinaddr)); - autxo->payment.txid = qp->desttxid; - autxo->payment.vout = qp->destvout; - //autxo->payment.value = qp->value; - autxo->iambob = 0; - autxo->fee.txid = qp->feetxid; - autxo->fee.vout = qp->feevout; - //autxo->deposit.value = up2->U.value; - autxo->S.satoshis = qp->destsatoshis; -} - char *LP_connectedalice(cJSON *argjson) // alice { cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; @@ -490,6 +640,7 @@ char *LP_connectedalice(cJSON *argjson) // alice LP_pendingswaps--; return(clonestr("{\"error\":\"no price set\"}")); } + // SPV validate bobs printf("%s/%s bid %.8f ask %.8f\n",Q.srccoin,Q.destcoin,bid,ask); price = bid; if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) @@ -538,7 +689,7 @@ char *LP_connectedalice(cJSON *argjson) // alice int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; int32_t retval = -1; struct LP_quoteinfo Q; + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_address_utxo **utxos; struct LP_quoteinfo Q; int32_t retval = -1,max=10000; if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { //LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); @@ -554,7 +705,23 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price = ask; autxo = &A; butxo = &B; + if ( strcmp(method,"request") == 0 ) + { + utxos = calloc(max,sizeof(*utxos)); + butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.satoshis),price,1); + free(utxos); + } + if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) + { + char str[65]; printf("couldnt find bob utxos for autxo %s/v%d %.8f\n",bits256_str(str,autxo->payment.txid),autxo->payment.vout,dstr(autxo->S.satoshis)); + return(-44); + } + Q.txid = butxo->payment.txid; + Q.vout = butxo->payment.vout; + Q.txid2 = butxo->deposit.txid; + Q.vout2 = butxo->deposit.vout; LP_abutxo_set(autxo,butxo,&Q); + LP_butxo_swapfields(butxo); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); @@ -589,10 +756,14 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else if ( strcmp(method,"connect") == 0 ) // bob { retval = 4; - if ( butxo->S.swap == 0 ) //butxo->T.swappending != 0 && + if ( butxo->S.swap == 0 && butxo->T.swappending != 0 ) + { + // validate SPV alice LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); + } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } + LP_butxo_swapfields_set(butxo); } } return(retval); @@ -660,70 +831,9 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(jprint(bestitem,0)); } -int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t targetval) -{ - int32_t i,mini = -1; int64_t dist; uint64_t mindist = (1LL << 60); - for (i=0; iU.value - targetval); - //printf("(%.8f %.8f %.8f).%d ",dstr(values[i]),dstr(dist),dstr(mindist),mini); - if ( dist >= 0 && dist < mindist ) - { - mini = i; - mindist = dist; - } - } - } - return(mini); -} - -struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price) -{ - struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; - if ( (ap= LP_addressfind(coin,coinaddr)) != 0 ) - { - if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) - { - targetval = SATOSHIDEN * (volume / price) + 2*txfee; - { - int32_t i; - for (i=0; iU.value)); - printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); - } - if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) - { - up = utxos[mini]; - utxos[mini] = 0; - targetval = (targetval / 8) * 9 + 2*txfee; - if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) - { - if ( up != 0 && (up2= utxos[mini]) != 0 ) - { - safecopy(utxo->coin,coin->symbol,sizeof(utxo->coin)); - safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); - utxo->payment.txid = up->U.txid; - utxo->payment.vout = up->U.vout; - utxo->payment.value = up->U.value; - utxo->iambob = 1; - utxo->deposit.txid = up2->U.txid; - utxo->deposit.vout = up2->U.vout; - utxo->deposit.value = up2->U.value; - utxo->S.satoshis = SATOSHIDEN * (volume / price); - return(utxo); - } - } - } - } - } - return(0); -} - struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 1000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -733,6 +843,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr return(0); utxos = calloc(max,sizeof(*utxos)); LP_txfees(&txfee,&desttxfee,base,autxo->coin); + printf("LP_buyutxo %s/%s %.8f %.8f\n",base,autxo->coin,dstr(txfee),dstr(desttxfee)); if ( (obookstr= LP_orderbook(base,autxo->coin,duration)) != 0 ) { if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) @@ -745,6 +856,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr price = jdouble(item,"price"); if ( LP_pricevalid(price) > 0 && price <= maxprice ) { + printf("%s\n",jprint(item,0)); pubkey = jbits256(item,"pubkey"); if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { @@ -756,7 +868,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr if ( relvolume >= minvol && relvolume <= maxvol ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price,0)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -814,7 +926,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(autxo,bestutxo,&Q,0)) <= SMALLVAL ) + if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index ce4a2b0ee..019767670 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -440,7 +440,10 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration { struct iguana_info *coin; struct LP_transaction *tx; cJSON *array,*item; uint32_t expiration,i,n; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + { + printf("LP_waitmempool missing coin.%p or inactive\n",coin); return(-1); + } expiration = (uint32_t)time(NULL) + duration; while ( 1 ) { @@ -453,11 +456,12 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration { if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height >= 0 ) { - char str[65]; printf("LP_waitmempool found %s %s\n",symbol,bits256_str(str,txid)); + char str[65]; printf("LP_waitmempool found confirmed %s %s\n",symbol,bits256_str(str,txid)); return(tx->height); } if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 ) { + char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; isock >= 0 && retjsonp != 0 ) { - *retjsonp = cJSON_Parse("{\"error\":\"unsupported method\"}"); - return(*retjsonp); - } - sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params); - ep->buf[0] = 0; - sitem = (struct stritem *)queueitem(stratumreq); - sitem->expiration = timeout; - sitem->DL.type = ep->stratumid++; - sitem->retptrp = (void **)retjsonp; - queue_enqueue("sendQ",&ep->sendQ,&sitem->DL); - expiration = (uint32_t)time(NULL) + timeout + 1; - while ( *retjsonp == 0 && time(NULL) <= expiration ) - usleep(10000); - if ( *retjsonp == 0 ) - { - //printf("unexpected %s timeout with null retjson: %s %s\n",ep->symbol,method,params); - *retjsonp = cJSON_Parse("{\"error\":\"timeout\"}"); - } - return(*retjsonp); - } else printf("couldnt find electrum server for (%s %s) or no retjsonp.%p\n",method,params,retjsonp); + *retjsonp = 0; + sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params); + memset(ep->buf,0,ep->bufsize); + sitem = (struct stritem *)queueitem(stratumreq); + sitem->expiration = timeout; + sitem->DL.type = ep->stratumid++; + sitem->retptrp = (void **)retjsonp; + queue_enqueue("sendQ",&ep->sendQ,&sitem->DL); + expiration = (uint32_t)time(NULL) + timeout + 1; + while ( *retjsonp == 0 && time(NULL) <= expiration ) + usleep(10000); + if ( ep->prev == 0 ) + { + if ( *retjsonp == 0 ) + { + //printf("unexpected %s timeout with null retjson: %s %s\n",ep->symbol,method,params); + *retjsonp = cJSON_Parse("{\"error\":\"timeout\"}"); + } + return(*retjsonp); + } + } else printf("couldnt find electrum server for (%s %s) or no retjsonp.%p\n",method,params,retjsonp); + ep = ep->prev; + } return(0); } @@ -753,7 +756,12 @@ void LP_dedicatedloop(void *arg) usleep(100000); } } - printf("close %s:%u\n",ep->ipaddr,ep->port); + if ( coin->electrum == ep ) + { + coin->electrum = ep->prev; + printf("set %s electrum to %s\n",coin->symbol,coin->electrum); + } else printf("backup electrum server closing\n"); + printf(">>>>>>>>>> electrum close %s:%u\n",ep->ipaddr,ep->port); if ( Num_electrums > 0 ) { portable_mutex_lock(&LP_electrummutex); @@ -768,7 +776,8 @@ void LP_dedicatedloop(void *arg) } portable_mutex_unlock(&LP_electrummutex); } - free(ep); + ep->sock = -1; + //free(ep); } cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port) @@ -792,6 +801,7 @@ cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port) { printf("launched.(%s:%u)\n",ep->ipaddr,ep->port); jaddstr(retjson,"result","success"); + ep->prev = coin->electrum; coin->electrum = ep; } } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index a5dfcde32..5153646c9 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1306,12 +1306,12 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da retval = 0; if ( (retval= basilisk_rawtx_sign(swap->bobcoin.symbol,swap->bobcoin.wiftaddr,swap->bobcoin.taddr,swap->bobcoin.pubtype,swap->bobcoin.p2shtype,swap->bobcoin.isPoS,swap->bobcoin.wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr)) == 0 ) { - /*for (i=0; ibobdeposit.I.datalen; i++) + int32_t i; for (i=0; ibobdeposit.I.datalen; i++) printf("%02x",swap->bobdeposit.txbytes[i]); printf(" <- bobdeposit\n"); for (i=0; ialiceclaim.I.datalen; i++) printf("%02x",swap->aliceclaim.txbytes[i]); - printf(" <- aliceclaim\n");*/ + printf(" <- aliceclaim\n"); //basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration); return(LP_waitmempool(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 29ab3fc4a..1617a3cd3 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -137,16 +137,19 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) return(n); } -int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap) +int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap,int32_t avoidflag) { struct LP_address_utxo *up,*tmp; int32_t n = 0; DL_FOREACH_SAFE(ap->utxos,up,tmp) { if ( up->spendheight <= 0 ) { - utxos[n++] = up; - if ( n >= max ) - break; + if ( avoidflag == 0 || LP_butxo_findeither(up->U.txid,up->U.vout) == 0 ) + { + utxos[n++] = up; + if ( n >= max ) + break; + } } } return(n); diff --git a/iguana/exchanges/electrum.kmd3 b/iguana/exchanges/electrum.kmd3 new file mode 100755 index 000000000..449658cac --- /dev/null +++ b/iguana/exchanges/electrum.kmd3 @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140 \",\"port\":8777}" From 330365aaffd64385a2243688cebe9defed55e398 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:08:25 +0200 Subject: [PATCH 187/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 2739f17a6..80691bfc6 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -759,7 +759,7 @@ void LP_dedicatedloop(void *arg) if ( coin->electrum == ep ) { coin->electrum = ep->prev; - printf("set %s electrum to %s\n",coin->symbol,coin->electrum); + printf("set %s electrum to %p\n",coin->symbol,coin->electrum); } else printf("backup electrum server closing\n"); printf(">>>>>>>>>> electrum close %s:%u\n",ep->ipaddr,ep->port); if ( Num_electrums > 0 ) From 0205423fb6c168e58636de3ddc38829780f760ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:16:25 +0200 Subject: [PATCH 188/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_socket.c | 6 +++--- iguana/exchanges/LP_utxo.c | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index def85d884..b8a4c8f6c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -430,7 +430,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( coin->inactive != 0 ) continue; - if ( time(NULL) > coin->lastmonitor+600 ) + if ( time(NULL) > coin->lastmonitor+60 ) { //portable_mutex_lock(&coin->addrmutex); HASH_ITER(hh,coin->addresses,ap,atmp) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 80691bfc6..335c403e4 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -467,17 +467,17 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); - if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) + //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - //printf("%s %s LISTUNSPENT.(%s)\n",symbol,addr,jprint(retjson,0)); + printf("%s %s LISTUNSPENT.(%s)\n",symbol,addr,jprint(retjson,0)); if ( electrum_process_array(coin,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); coin->unspenttime = (uint32_t)time(NULL); } - } else retjson = LP_address_utxos(coin,addr,1); + } //else retjson = LP_address_utxos(coin,addr,1); return(retjson); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1617a3cd3..83cd9da0b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -81,6 +81,7 @@ struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) struct LP_address *ap; ap = calloc(1,sizeof(*ap)); safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr)); + printf("LP_ADDRESS %s ADD.(%s)\n",coin->symbol,coinaddr); HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); return(ap); } From 34385c7085fae220c59b1d0c6e816bbca0c742ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:22:37 +0200 Subject: [PATCH 189/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 335c403e4..6046ef31f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -310,6 +310,7 @@ int32_t electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *ar int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { + printf("PROCESS %s %s num.%d\n",coin->symbol,coinaddr,n); for (i=0; isymbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); From b8542cce6f1517a7bb1e390b89fdd04d9c8885c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:30:49 +0200 Subject: [PATCH 190/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 19 ++++++++++++------- iguana/exchanges/LP_socket.c | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b8a4c8f6c..4681b589a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -447,7 +447,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } } } - else + else if ( 0 ) { if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,ap->coinaddr)) != 0 ) free_json(retjson); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ef81f9b54..9c98c7c59 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -833,7 +833,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double minvol,maxvol,price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*array,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -860,14 +860,19 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr pubkey = jbits256(item,"pubkey"); if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { - if ( (n= jint(item,"numutxos")) > 1 ) + bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + if ( (array= electrum_address_listunspent(basecoin->symbol,basecoin->electrum,&array,coinaddr)) != 0 ) { - minvol = jdouble(item,"minvolume"); - maxvol = jdouble(item,"maxvolume"); - printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); - if ( relvolume >= minvol && relvolume <= maxvol ) + n = cJSON_GetArraySize(array); + free_json(array); + } else n = 0; + if ( n > 1 ) + { + //minvol = jdouble(item,"minvolume"); + //maxvol = jdouble(item,"maxvolume"); + //printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); + //if ( relvolume >= minvol && relvolume <= maxvol ) { - bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price,0)) != 0 ) { bestutxo->pubkey = pubp->pubkey; diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 6046ef31f..1dda5a683 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -468,7 +468,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); - //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) + if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { From 7a6158b226356dea139db07dee19b2e8847ff174 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:41:16 +0200 Subject: [PATCH 191/520] Test --- iguana/exchanges/LP_utxo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 83cd9da0b..9036b3e6b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -175,7 +175,10 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); - if ( (ap= _LP_address(coin,coinaddr)) != 0 ) + if ( spendheight > 0 ) // dont autocreate entries for spends we dont care about + ap = LP_addressfind(coin,coinaddr); + else ap = LP_address(coin,coinaddr); + if ( ap != 0 ) { flag = 0; DL_FOREACH_SAFE(ap->utxos,up,tmp) From 85120d993d675c402a416140c2bfbe303133039f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:46:24 +0200 Subject: [PATCH 192/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 1dda5a683..de2268507 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -467,7 +467,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON * cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); - //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); + printf("electrum.%s/%s listunspent last.(%s lag %d)\n",ep->symbol,coin->symbol,coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) From 550e1327bdeb1b47442e89e6408857f955bc3019 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:54:51 +0200 Subject: [PATCH 193/520] Test --- iguana/exchanges/LP_ordermatch.c | 15 ++++++++------- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_socket.c | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9c98c7c59..a6fa028ea 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -290,21 +290,26 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str if ( strcmp(autxo->coinaddr,qp->destaddr) != 0 ) return(-10); } - if ( destvalue < qp->desttxfee+qp->destsatoshis || srcvalue < qp->txfee+qp->satoshis ) + if ( (autxo != 0 && destvalue < qp->desttxfee+qp->destsatoshis) || (butxo != 0 && srcvalue < qp->txfee+qp->satoshis) ) { printf("destvalue %.8f srcvalue %.8f, destsatoshis %.8f or satoshis %.8f is too small txfees %.8f %.8f?\n",dstr(destvalue),dstr(srcvalue),dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->desttxfee),dstr(qp->txfee)); return(-11); } if ( qp->satoshis != 0 ) - { qprice = ((double)qp->destsatoshis / qp->satoshis); + LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); + printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); + if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee ) + return(-14); + if ( butxo != 0 ) + { if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT ) { printf("utxo payment %.8f is less than %f covered by Q %.8f or <10x txfee %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis),dstr(qp->txfee)); return(-12); } } - if ( qp->destsatoshis != 0 ) + if ( autxo != 0 ) { if ( qp->destsatoshis < (destvalue / LP_MINCLIENTVOL) || destvalue < qp->desttxfee*LP_MINSIZE_TXFEEMULT ) { @@ -312,10 +317,6 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str return(-13); } } - LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); - printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); - if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee ) - return(-14); return(qprice); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index ab670a326..644838101 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -508,7 +508,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( electrum_process_array(coin,coinaddr,retjson) != 0 ) + if ( electrum_process_array(coin,coin->electrum,coinaddr,retjson) != 0 ) { LP_postutxos(symbol,coinaddr); // might be good to not saturate } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index de2268507..28e7a582d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -305,12 +305,12 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) return(ep); } -int32_t electrum_process_array(struct iguana_info *coin,char *coinaddr,cJSON *array) +int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep,char *coinaddr,cJSON *array) { int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - printf("PROCESS %s %s num.%d\n",coin->symbol,coinaddr,n); + printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); for (i=0; isymbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); coin->unspenttime = (uint32_t)time(NULL); From c356f45b27ac9978a97ff393e93a46fab4e43ec8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 12:57:44 +0200 Subject: [PATCH 194/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a6fa028ea..b5b4bc9ae 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -706,6 +706,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price = ask; autxo = &A; butxo = &B; + LP_abutxo_set(autxo,0,&Q); if ( strcmp(method,"request") == 0 ) { utxos = calloc(max,sizeof(*utxos)); @@ -721,7 +722,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, Q.vout = butxo->payment.vout; Q.txid2 = butxo->deposit.txid; Q.vout2 = butxo->deposit.vout; - LP_abutxo_set(autxo,butxo,&Q); + LP_abutxo_set(0,butxo,&Q); LP_butxo_swapfields(butxo); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 28e7a582d..32747b63a 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -467,7 +467,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON * cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); - printf("electrum.%s/%s listunspent last.(%s lag %d)\n",ep->symbol,coin->symbol,coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); + //printf("electrum.%s/%s listunspent last.(%s lag %d)\n",ep->symbol,coin->symbol,coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) From 8e86a244b75a53d8d93edc23e04f7b4370cd5dcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:05:26 +0200 Subject: [PATCH 195/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b5b4bc9ae..501fccd5d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -710,7 +710,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"request") == 0 ) { utxos = calloc(max,sizeof(*utxos)); - butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.satoshis),price,1); + butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1); free(utxos); } if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 32747b63a..84be2f097 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -468,7 +468,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); //printf("electrum.%s/%s listunspent last.(%s lag %d)\n",ep->symbol,coin->symbol,coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); - if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) + if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+30 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { From 31458d94c35f40721edb46bbbb735e5209f4e4fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:17:37 +0200 Subject: [PATCH 196/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 - iguana/exchanges/LP_rpc.c | 3 ++- iguana/exchanges/LP_utxos.c | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 501fccd5d..26c9dff54 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -693,7 +693,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_address_utxo **utxos; struct LP_quoteinfo Q; int32_t retval = -1,max=10000; if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { - //LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); retval = 1; if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 644838101..d781decd7 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -508,8 +508,9 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( electrum_process_array(coin,coin->electrum,coinaddr,retjson) != 0 ) + if ( electrum_process_array(coin,0,coinaddr,retjson) != 0 ) { + printf("PROCESS INTERNAL.(%s)\n",coin->symbol); LP_postutxos(symbol,coinaddr); // might be good to not saturate } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index be104cc6b..b20f871ed 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -882,13 +882,17 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan userpub = curve25519(userpass,curve25519_basepoint9()); printf("userpass.(%s)\n",bits256_str(USERPASS,userpub)); } - if ( coin->electrum == 0 && (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 ) + if ( coin->electrum == 0 ) { - if ( jobj(retjson,"error") != 0 ) + LP_listunspent_issue(coin->symbol,coin->smartaddr); + if ( (retjson= LP_importprivkey(coin->symbol,tmpstr,coin->smartaddr,-1)) != 0 ) { - printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); - exit(-1); - } + if ( jobj(retjson,"error") != 0 ) + { + printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); + exit(-1); + } + } else free_json(retjson); } } LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); From 87fa15308326ea82b39226f68fb2d921b9d70c5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:32:53 +0200 Subject: [PATCH 197/520] Test --- iguana/exchanges/LP_rpc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d781decd7..4c25b26a4 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -503,18 +503,20 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) retjson = electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr); else { - if ( (destport= LP_randpeer(destip)) > 0 ) + if ( strcmp(coin->smartaddr,coinaddr) == 0 ) + { + retjson = LP_listunspent(symbol,coinaddr); + printf("SELF_LISTUNSPENT.(%s %s)\n",symbol,coinaddr); + } + else if ( (destport= LP_randpeer(destip)) > 0 ) { retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( electrum_process_array(coin,0,coinaddr,retjson) != 0 ) - { - printf("PROCESS INTERNAL.(%s)\n",coin->symbol); - LP_postutxos(symbol,coinaddr); // might be good to not saturate - } - } - //printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr); + retjson = cJSON_Parse(retstr); + } + if ( retjson != 0 ) + { + if ( electrum_process_array(coin,0,coinaddr,retjson) != 0 ) + LP_postutxos(symbol,coinaddr); // might be good to not saturate } } if ( retjson != 0 ) From 949699aa86a8cad358e6275aab077afe04744ff5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:34:27 +0200 Subject: [PATCH 198/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 26c9dff54..7318f5545 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -353,6 +353,7 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L msg = jprint(reqjson,1); printf("QUERY.(%s)\n",msg); LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); + LP_broadcast_message(-1,qp->srccoin,qp->destcoin,qp->srchash,msg); for (i=0; i<30; i++) { if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) From 5c382bef3074535b985f4d2e1e7ef7dcfd7f3b4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:37:54 +0200 Subject: [PATCH 199/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7318f5545..eb9446ed6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -334,7 +334,7 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout) double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; char *msg; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; + cJSON *reqjson; char *msg,*msg2; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -351,9 +351,10 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); msg = jprint(reqjson,1); + msg2 = clonestr(msg); printf("QUERY.(%s)\n",msg); LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); - LP_broadcast_message(-1,qp->srccoin,qp->destcoin,qp->srchash,msg); + LP_broadcast_message(-1,qp->srccoin,qp->destcoin,qp->srchash,msg2); for (i=0; i<30; i++) { if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) From 280924f3a1d58c4f092f730e81e0ce5459b030df Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:45:59 +0200 Subject: [PATCH 200/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index eb9446ed6..2f910abea 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -334,7 +334,7 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout) double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; char *msg,*msg2; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -354,7 +354,8 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L msg2 = clonestr(msg); printf("QUERY.(%s)\n",msg); LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); - LP_broadcast_message(-1,qp->srccoin,qp->destcoin,qp->srchash,msg2); + memset(&zero,0,sizeof(zero)); + LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg2); for (i=0; i<30; i++) { if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 84be2f097..091233f4c 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -310,7 +310,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); + //printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); for (i=0; icoinaddr,coinaddr,sizeof(ap->coinaddr)); - printf("LP_ADDRESS %s ADD.(%s)\n",coin->symbol,coinaddr); + //printf("LP_ADDRESS %s ADD.(%s)\n",coin->symbol,coinaddr); HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); return(ap); } From b20d39f8632cb156651f8bf91ee7d589d2c46e7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 13:53:35 +0200 Subject: [PATCH 201/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 2f910abea..a77b983a7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -696,10 +696,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_address_utxo **utxos; struct LP_quoteinfo Q; int32_t retval = -1,max=10000; if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { - printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); retval = 1; - if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 ) + printf("LP_tradecommand: check received %s\n",method); + if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) { + printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); if ( (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) { printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 4c25b26a4..013e25114 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -506,7 +506,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) if ( strcmp(coin->smartaddr,coinaddr) == 0 ) { retjson = LP_listunspent(symbol,coinaddr); - printf("SELF_LISTUNSPENT.(%s %s)\n",symbol,coinaddr); + //printf("SELF_LISTUNSPENT.(%s %s)\n",symbol,coinaddr); } else if ( (destport= LP_randpeer(destip)) > 0 ) { From bd1324bf10101239a5206c6c09ac069600c159f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:08:02 +0200 Subject: [PATCH 202/520] Test --- iguana/exchanges/LP_commands.c | 1 + iguana/exchanges/LP_nativeDEX.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e9099f018..11732e063 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -440,6 +440,7 @@ dividends(coin, height, )\n\ memset(zero.bytes,0,sizeof(zero)); //printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); + Broadcaststr = jprint(reqjson,0); } retstr = clonestr("{\"result\":\"success\"}"); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4681b589a..11e20ba8e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -32,7 +32,7 @@ #include "LP_include.h" portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex; int32_t LP_canbind; - +char *Broadcaststr; struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; struct LP_peerinfo *LP_peerinfos,*LP_mypeer; struct LP_forwardinfo *LP_forwardinfos; @@ -266,7 +266,7 @@ int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pu int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock) { - int32_t recvlen=1,nonz = 0; void *ptr; char *retstr; struct nn_pollfd pfd; + int32_t recvlen=1,nonz = 0; void *ptr; char *retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { while ( nonz < 1000 && recvlen > 0 ) @@ -281,6 +281,15 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); + if ( Broadcaststr != 0 ) + { + printf("self broadcast.(%s)\n",Broadcaststr); + str = Broadcaststr; + Broadcaststr = 0; + if ( (retstr= LP_process_message(ctx,"selfbroadcast",myipaddr,-1,(void *)str,(int32_t)strlen(str)+1,-1)) != 0 ) + free(retstr); + free(str); + } } } } From 853b3a608f787156e2cc7921ba4583b9d8899379 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:12:00 +0200 Subject: [PATCH 203/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 11e20ba8e..2815f3ae0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -286,7 +286,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int printf("self broadcast.(%s)\n",Broadcaststr); str = Broadcaststr; Broadcaststr = 0; - if ( (retstr= LP_process_message(ctx,"selfbroadcast",myipaddr,-1,(void *)str,(int32_t)strlen(str)+1,-1)) != 0 ) + if ( (retstr= LP_process_message(ctx,"selfbroadcast",myipaddr,pubsock,(void *)str,(int32_t)strlen(str)+1,sock)) != 0 ) free(retstr); free(str); } From eba155dc06159e3edd834cb6d0214957a417fbac Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:15:35 +0200 Subject: [PATCH 204/520] Test --- iguana/exchanges/LP_nativeDEX.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2815f3ae0..80da2a32d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -266,7 +266,7 @@ int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pu int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock) { - int32_t recvlen=1,nonz = 0; void *ptr; char *retstr,*str; struct nn_pollfd pfd; + int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { while ( nonz < 1000 && recvlen > 0 ) @@ -286,8 +286,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int printf("self broadcast.(%s)\n",Broadcaststr); str = Broadcaststr; Broadcaststr = 0; - if ( (retstr= LP_process_message(ctx,"selfbroadcast",myipaddr,pubsock,(void *)str,(int32_t)strlen(str)+1,sock)) != 0 ) - free(retstr); + if ( (argjson= cJSON_Parse(str)) != 0 ) + { + LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0); + free_json(argjson); + } free(str); } } From 68a2efe25d1b4376153f176be3d7f7cf0cc3ce96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:20:29 +0200 Subject: [PATCH 205/520] test --- iguana/exchanges/LP_nativeDEX.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 80da2a32d..153ba5522 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -264,7 +264,7 @@ int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pu return(n); } -int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock) +int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr) { int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) @@ -288,7 +288,9 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int Broadcaststr = 0; if ( (argjson= cJSON_Parse(str)) != 0 ) { - LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0); + if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) + free(retstr); + //LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0); free_json(argjson); } free(str); @@ -317,7 +319,7 @@ void command_rpcloop(void *myipaddr) else continue; } //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); - nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock); + nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { @@ -327,7 +329,7 @@ void command_rpcloop(void *myipaddr) nonz += LP_sock_check(coin->symbol,ctx,origipaddr,-1,coin->bussock,LP_profitratio - 1.); }*/ if ( LP_mypullsock >= 0 ) - nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock); + nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1"); //if ( LP_mybussock >= 0 ) // nonz += LP_sock_check("BUS",ctx,origipaddr,-1,LP_mybussock); if ( nonz == 0 ) From ad148cc9bf9cecb6876832d03fbfdd5906a37829 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:26:45 +0200 Subject: [PATCH 206/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 11732e063..e47cc1a0e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -438,7 +438,7 @@ dividends(coin, height, )\n\ else { memset(zero.bytes,0,sizeof(zero)); - //printf("broadcast.(%s)\n",jprint(reqjson,0)); + printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); Broadcaststr = jprint(reqjson,0); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 153ba5522..3ff8cde32 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -283,7 +283,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int free(retstr); if ( Broadcaststr != 0 ) { - printf("self broadcast.(%s)\n",Broadcaststr); + //printf("self broadcast.(%s)\n",Broadcaststr); str = Broadcaststr; Broadcaststr = 0; if ( (argjson= cJSON_Parse(str)) != 0 ) From f9d5d8ad6a79bbb95fe9a9e279bd28a3c102ede3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:34:07 +0200 Subject: [PATCH 207/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e47cc1a0e..c06b28d25 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -426,6 +426,7 @@ dividends(coin, height, )\n\ bits256 zero; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE]; if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 ) { + Broadcaststr = jprint(reqjson,0); if ( (cipherstr= jstr(reqjson,"cipher")) != 0 ) { cipherlen = (int32_t)strlen(cipherstr) >> 1; @@ -440,7 +441,6 @@ dividends(coin, height, )\n\ memset(zero.bytes,0,sizeof(zero)); printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); - Broadcaststr = jprint(reqjson,0); } retstr = clonestr("{\"result\":\"success\"}"); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); From 316e4f8395d529a6c2a6134c3f932a5675087049 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:45:13 +0200 Subject: [PATCH 208/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c06b28d25..bb13e0f6d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -439,7 +439,7 @@ dividends(coin, height, )\n\ else { memset(zero.bytes,0,sizeof(zero)); - printf("broadcast.(%s)\n",jprint(reqjson,0)); + //printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3ff8cde32..05de2d87c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -288,8 +288,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int Broadcaststr = 0; if ( (argjson= cJSON_Parse(str)) != 0 ) { - if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) + if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 ) + { + if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) free(retstr); + } //LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0); free_json(argjson); } From b04d15e08f6d08f5cbe86b13c37a6510d02765e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:54:17 +0200 Subject: [PATCH 209/520] Test --- iguana/exchanges/LP_commands.c | 3 ++- iguana/exchanges/LP_nativeDEX.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index bb13e0f6d..43c41e08d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -439,7 +439,8 @@ dividends(coin, height, )\n\ else { memset(zero.bytes,0,sizeof(zero)); - //printf("broadcast.(%s)\n",jprint(reqjson,0)); + if ( strcmp("connect",method) == 0 ) + printf("broadcast.(%s)\n",jprint(reqjson,0)); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 05de2d87c..48fdfd9fa 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -288,12 +288,13 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int Broadcaststr = 0; if ( (argjson= cJSON_Parse(str)) != 0 ) { + if ( jobj(argjson,"method") != 0 && strcmp("connect",jstr(argjson,"method")) == 0 ) + printf("self.(%s)\n",str); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 ) { if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) free(retstr); } - //LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0); free_json(argjson); } free(str); From 9cf32d3d7e041c3ebc344b27190fb436e090d54a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 14:59:07 +0200 Subject: [PATCH 210/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a77b983a7..da5931e5a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -366,7 +366,7 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L break; } } - usleep(100000); + usleep(1000000); } return(price); } From 00b5f918e92909653d7820c028b8d1f37892a2ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 15:21:08 +0200 Subject: [PATCH 211/520] Test --- iguana/exchanges/LP_ordermatch.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index da5931e5a..cf8620ab7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -334,7 +334,7 @@ int32_t LP_arrayfind(cJSON *array,bits256 txid,int32_t vout) double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_quoteinfo *qp) { - cJSON *reqjson; bits256 zero; char *msg,*msg2; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; + cJSON *reqjson; bits256 zero; char *msg; int32_t i,flag = 0; double price = 0.; struct LP_utxoinfo *utxo; if ( strcmp(method,"request") == 0 ) { if ( (utxo= LP_utxofind(0,qp->desttxid,qp->destvout)) != 0 && LP_ismine(utxo) > 0 && LP_isavailable(utxo) > 0 ) @@ -351,22 +351,29 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); msg = jprint(reqjson,1); - msg2 = clonestr(msg); printf("QUERY.(%s)\n",msg); - LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); - memset(&zero,0,sizeof(zero)); - LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg2); - for (i=0; i<30; i++) + if ( strcmp(method,"connect") == 0 ) { - if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) + sleep(3); + memset(&zero,0,sizeof(zero)); + LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg); + } + else + { + memset(&zero,0,sizeof(zero)); + LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg); + for (i=0; i<30; i++) { - if ( flag == 0 || bits256_nonz(qp->desthash) != 0 ) + if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) { - printf("break out of loop.%d price %.8f %s/%s\n",i,price,qp->srccoin,qp->destcoin); - break; + if ( flag == 0 || bits256_nonz(qp->desthash) != 0 ) + { + printf("break out of loop.%d price %.8f %s/%s\n",i,price,qp->srccoin,qp->destcoin); + break; + } } + usleep(1000000); } - usleep(1000000); } return(price); } From dfb41e5c9d4888850589031852e6337fa8d7184b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 16:49:56 +0200 Subject: [PATCH 212/520] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_network.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 48fdfd9fa..fd2893593 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -274,10 +274,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int memset(&pfd,0,sizeof(pfd)); pfd.fd = sock; pfd.events = NN_POLLIN; - if ( nn_poll(&pfd,1,1) != 1 ) + if ( nn_poll(&pfd,1,10) != 1 ) break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { + printf("received %d\n",recvlen); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 4f84b0dab..58bc2d728 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -57,7 +57,7 @@ int32_t LP_sockcheck(int32_t sock) struct nn_pollfd pfd; pfd.fd = sock; pfd.events = NN_POLLOUT; - if ( nn_poll(&pfd,1,1) > 0 ) + if ( nn_poll(&pfd,1,10) > 0 ) return(1); else return(-1); } @@ -162,7 +162,7 @@ void queue_loop(void *ignore) if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); else flag = 1; - } + } else printf("sock not ready to send.%d\n",ptr->msglen); } else if ( time(NULL) > ptr->starttime+13 ) { @@ -562,7 +562,7 @@ char *LP_psock(char *myipaddr,int32_t ispaired) { if ( nn_bind(pullsock,pushaddr) >= 0 && nn_bind(pubsock,subaddr) >= 0 ) { - timeout = 1; + timeout = 10; nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); if ( ispaired != 0 ) @@ -700,7 +700,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char exit(-1); } } - timeout = 1; + timeout = 10; nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); //maxsize = 2 * 1024 * 1024; From 61a47af1189aece543b30a8ad38bbb2bf994614a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 17:01:05 +0200 Subject: [PATCH 213/520] Test --- iguana/exchanges/LP_nativeDEX.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fd2893593..6eb22fc7f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -278,7 +278,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - printf("received %d\n",recvlen); + fprintf(stderr,"%d ",recvlen); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); @@ -333,8 +333,8 @@ void command_rpcloop(void *myipaddr) if ( coin->bussock >= 0 ) nonz += LP_sock_check(coin->symbol,ctx,origipaddr,-1,coin->bussock,LP_profitratio - 1.); }*/ - if ( LP_mypullsock >= 0 ) - nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1"); + //if ( LP_mypullsock >= 0 ) + // nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1"); //if ( LP_mybussock >= 0 ) // nonz += LP_sock_check("BUS",ctx,origipaddr,-1,LP_mybussock); if ( nonz == 0 ) @@ -725,10 +725,16 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } //if ( (retstr= basilisk_swapentry(0,0)) != 0 ) // free(retstr); + int32_t nonz; while ( 1 ) { + nonz = 0; //fprintf(stderr,"."); - if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) == 0 ) + if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) != 0 ) + nonz++; + if ( LP_mypullsock >= 0 ) + nonz += LP_sock_check("SUB",ctx,myipaddr,-1,LP_mypullsock,"127.0.0.1"); + if ( nonz == 0 ) usleep(1000000 / MAINLOOP_PERSEC); } } From 7901b725f3123631088a6597f9e04981d5c97b6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 17:08:59 +0200 Subject: [PATCH 214/520] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_ordermatch.c | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6eb22fc7f..9827eecbd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -278,7 +278,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - fprintf(stderr,"%d ",recvlen); + if ( recvlen > 1500 ) + fprintf(stderr,"%d ",recvlen); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cf8620ab7..458a264f8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -761,7 +761,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, jaddstr(retjson,"method","reserved"); msg = jprint(retjson,1); printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)",butxo->T.swappending,qprice,price,msg); - LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); + { + bits256 zero; + memset(&zero,0,sizeof(zero)); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey + } butxo->T.lasttime = (uint32_t)time(NULL); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } From 3314cf4cd26295799e44aafe89a5d63b6ffd3f2a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 17:18:45 +0200 Subject: [PATCH 215/520] Test --- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_network.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9827eecbd..78b3ad787 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,6 +202,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; + printf("%s\n",jstr(argjson,"method")); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } @@ -334,8 +335,8 @@ void command_rpcloop(void *myipaddr) if ( coin->bussock >= 0 ) nonz += LP_sock_check(coin->symbol,ctx,origipaddr,-1,coin->bussock,LP_profitratio - 1.); }*/ - //if ( LP_mypullsock >= 0 ) - // nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1"); + if ( LP_mypullsock >= 0 ) + nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1"); //if ( LP_mybussock >= 0 ) // nonz += LP_sock_check("BUS",ctx,origipaddr,-1,LP_mybussock); if ( nonz == 0 ) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 58bc2d728..4519c855d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -87,7 +87,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) { - static uint32_t crcs[8192]; static unsigned long dup,total; + static uint32_t crcs[16]; static unsigned long dup,total; int32_t i; *duplicatep = 0; if ( ind < 0 ) From fb98099b49c92438945ae302365b7db24119884a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 17:35:25 +0200 Subject: [PATCH 216/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_network.c | 4 ++-- iguana/exchanges/LP_utxos.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 78b3ad787..44f5714c9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,7 +202,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - printf("%s\n",jstr(argjson,"method")); + fprintf(stderr,"%s ",jstr(argjson,"method")); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 4519c855d..f3c6c1355 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -157,7 +157,7 @@ void queue_loop(void *ignore) { if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); - // else printf("%d %p qsent %u msglen.%d peerind.%d\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind); + else printf("%d %p qsent %u msglen.%d peerind.%d\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind); ptr->sock = -1; if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); @@ -214,7 +214,7 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); else { - //printf("Q sent %u\n",crc32); + printf("Q sent %u\n",crc32); sock0 = -1; } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b20f871ed..479500d3c 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -193,7 +193,7 @@ int32_t LP_utxopurge(int32_t allutxos) cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) { struct _LP_utxoinfo u; - jaddstr(item,"method","utxo"); + jaddstr(item,"method","oldutxo"); if ( utxo == 0 ) return(item); if ( utxo->gui[0] != 0 ) From 59f36f01b52d70a47808ffd535b85fb77a9502b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 17:53:20 +0200 Subject: [PATCH 217/520] Test --- iguana/exchanges/LP_commands.c | 9 ++++++++- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_ordermatch.c | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 43c41e08d..cf47309d6 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -441,7 +441,14 @@ dividends(coin, height, )\n\ memset(zero.bytes,0,sizeof(zero)); if ( strcmp("connect",method) == 0 ) printf("broadcast.(%s)\n",jprint(reqjson,0)); - LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); + if ( LP_mypubsock >= 0 ) + { + char *msg; + msg = jprint(reqjson,0); + nn_send(pubsock,(void *)msg,(int32_t)strlen(msg)+1,0); + free(msg); + } + //LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 44f5714c9..1c82749c5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,7 +202,8 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - fprintf(stderr,"%s ",jstr(argjson,"method")); + if ( strcmp(method,"postprice") != 0 ) + fprintf(stderr,"%s ",jstr(argjson,"method")); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index f3c6c1355..2262efcd8 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -214,7 +214,7 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); else { - printf("Q sent %u\n",crc32); + printf("Q sent %u msglen.%d\n",crc32,msglen); sock0 = -1; } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 458a264f8..2a3776542 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -594,7 +594,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 ) { LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); + printf("call swapinit\n"); swap = LP_swapinit(1,0,privkey,&qp->R,qp); + printf("swapinit.%p\n",swap); swap->N.pair = pair; utxo->S.swap = swap; swap->utxo = utxo; @@ -764,6 +766,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); + if ( pubsock >= 0 ) + nn_send(pubsock,msg,(int32_t)strlen(msg)+1,0); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey } butxo->T.lasttime = (uint32_t)time(NULL); From d16961b53102a34d8c189c918c81aeb6a69433ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 17:58:09 +0200 Subject: [PATCH 218/520] test --- iguana/exchanges/LP_commands.c | 9 +-------- iguana/exchanges/LP_ordermatch.c | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index cf47309d6..43c41e08d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -441,14 +441,7 @@ dividends(coin, height, )\n\ memset(zero.bytes,0,sizeof(zero)); if ( strcmp("connect",method) == 0 ) printf("broadcast.(%s)\n",jprint(reqjson,0)); - if ( LP_mypubsock >= 0 ) - { - char *msg; - msg = jprint(reqjson,0); - nn_send(pubsock,(void *)msg,(int32_t)strlen(msg)+1,0); - free(msg); - } - //LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); + LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); } retstr = clonestr("{\"result\":\"success\"}"); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 2a3776542..afaab7ab6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -766,8 +766,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); - if ( pubsock >= 0 ) - nn_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + //if ( pubsock >= 0 ) + // nn_send(pubsock,msg,(int32_t)strlen(msg)+1,0); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey } butxo->T.lasttime = (uint32_t)time(NULL); From 2132bf2ef27a4b2f7e89b2d409339c7adc5b5b8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:03:14 +0200 Subject: [PATCH 219/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index afaab7ab6..9931fa6d7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -766,8 +766,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); - //if ( pubsock >= 0 ) - // nn_send(pubsock,msg,(int32_t)strlen(msg)+1,0); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey } butxo->T.lasttime = (uint32_t)time(NULL); From a4ce26cba6b3f55faec8b75b8136ff0fcfbb08aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:06:46 +0200 Subject: [PATCH 220/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_ordermatch.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1c82749c5..f6843d7dc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,7 +202,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - if ( strcmp(method,"postprice") != 0 ) + if ( jobj(argjson,"method") && strcmp(method,"postprice") != 0 ) fprintf(stderr,"%s ",jstr(argjson,"method")); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 2262efcd8..bef1b9972 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -46,7 +46,7 @@ int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) } if ( (sentbytes= nn_send(sock,msg,sendlen,0)) != sendlen ) printf("LP_send sent %d instead of %d\n",sentbytes,sendlen); - //else printf("SENT.(%s)\n",msg); + else printf("SENT.(%s)\n",msg); if ( freeflag != 0 ) free(msg); return(sentbytes); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9931fa6d7..9010c4217 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -767,6 +767,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, bits256 zero; memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey + _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); } butxo->T.lasttime = (uint32_t)time(NULL); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); From a39af0a2acff1ce30b680f940700a6f85edbf81c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:10:33 +0200 Subject: [PATCH 221/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_network.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f6843d7dc..ce362c933 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,7 +202,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - if ( jobj(argjson,"method") && strcmp(method,"postprice") != 0 ) + if ( jobj(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"postprice") != 0 ) fprintf(stderr,"%s ",jstr(argjson,"method")); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index bef1b9972..37bbaebc1 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -46,7 +46,7 @@ int32_t _LP_send(int32_t sock,void *msg,int32_t sendlen,int32_t freeflag) } if ( (sentbytes= nn_send(sock,msg,sendlen,0)) != sendlen ) printf("LP_send sent %d instead of %d\n",sentbytes,sendlen); - else printf("SENT.(%s)\n",msg); + else printf("SENT.(%s)\n",(char *)msg); if ( freeflag != 0 ) free(msg); return(sentbytes); From 9f56ccf2870b5a3994b73603b842c0f610d3a5f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:17:00 +0200 Subject: [PATCH 222/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9010c4217..83775a4a3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -766,8 +766,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); - LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey } butxo->T.lasttime = (uint32_t)time(NULL); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); From 939eca54b59e2555e41d514b08d846ba018ffbe0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:27:20 +0200 Subject: [PATCH 223/520] Test --- iguana/exchanges/LP_commands.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 43c41e08d..7908202c8 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -438,10 +438,13 @@ dividends(coin, height, )\n\ } else { + char *msg; memset(zero.bytes,0,sizeof(zero)); if ( strcmp("connect",method) == 0 ) printf("broadcast.(%s)\n",jprint(reqjson,0)); - LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,jprint(reqjson,0)); + msg = jprint(reqjson,0); + _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,msg); } retstr = clonestr("{\"result\":\"success\"}"); } else retstr = clonestr("{\"error\":\"couldnt dereference sendmessage\"}"); From e3f1d1193793b3c9d304bde5ab4a9faeb5212bd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:38:58 +0200 Subject: [PATCH 224/520] test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- iguana/exchanges/LP_network.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ce362c933..2d2b41679 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,7 +202,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - if ( jobj(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"postprice") != 0 ) + if ( jobj(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"connect") == 0 ) fprintf(stderr,"%s ",jstr(argjson,"method")); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { @@ -280,8 +280,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - if ( recvlen > 1500 ) - fprintf(stderr,"%d ",recvlen); + //if ( recvlen > 1500 ) + // fprintf(stderr,"%d ",recvlen); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); @@ -732,7 +732,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu while ( 1 ) { nonz = 0; - //fprintf(stderr,"."); + fprintf(stderr,"."); if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) != 0 ) nonz++; if ( LP_mypullsock >= 0 ) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 37bbaebc1..48d3ef687 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -199,7 +199,7 @@ void queue_loop(void *ignore) //if ( n != 0 ) // printf("LP_Q.[%d]\n",n); if ( nonz == 0 ) - usleep(500000); + usleep(50000); } } From 65d2e5c9b29ba91bb822528cce1cd172c5b9398a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 18:52:16 +0200 Subject: [PATCH 225/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_ordermatch.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 7908202c8..7b6ae9411 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -443,7 +443,7 @@ dividends(coin, height, )\n\ if ( strcmp("connect",method) == 0 ) printf("broadcast.(%s)\n",jprint(reqjson,0)); msg = jprint(reqjson,0); - _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + //_LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,msg); } retstr = clonestr("{\"result\":\"success\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2d2b41679..9d4db2c22 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,8 +202,8 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - if ( jobj(argjson,"method") != 0 && strcmp(jstr(argjson,"method"),"connect") == 0 ) - fprintf(stderr,"%s ",jstr(argjson,"method")); + if ( jobj(argjson,"method") != 0 && strncmp(jstr(argjson,"method"),"connect",7) == 0 ) + fprintf(stderr,"%s\n",jsonstr); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 83775a4a3..ec77e2dc8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -766,7 +766,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); - _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + //_LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey } butxo->T.lasttime = (uint32_t)time(NULL); From ccd629415d7de33d3da8c0229eaa3ad147153ddc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 19:01:41 +0200 Subject: [PATCH 226/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9d4db2c22..0a409cbb1 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -732,7 +732,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu while ( 1 ) { nonz = 0; - fprintf(stderr,"."); + //fprintf(stderr,"."); if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) != 0 ) nonz++; if ( LP_mypullsock >= 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ec77e2dc8..0b8a24b31 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -820,6 +820,8 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q if ( aliceutxo->S.swap != 0 ) break; sleep(3); + price = LP_query(ctx,myipaddr,mypubsock,"connect",qp); + LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); } if ( aliceutxo->S.swap == 0 ) { From b47d43aab27b60956471b677dca9c96c3c71b80f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 19:15:21 +0200 Subject: [PATCH 227/520] Test --- iguana/exchanges/LP_network.c | 5 +++-- iguana/exchanges/LP_ordermatch.c | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 48d3ef687..525a13d5c 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -214,7 +214,7 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); else { - printf("Q sent %u msglen.%d\n",crc32,msglen); + //printf("Q sent %u msglen.%d\n",crc32,msglen); sock0 = -1; } } @@ -311,7 +311,8 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25 jdelete(argjson,"method2"); jaddstr(argjson,"method2",method); jaddstr(argjson,"method",method); - //printf("CRC32.%u (%s)\n",crc32,(char *)msg); + if ( strncmp(method,"connect",7) == 0 ) + printf("CRC32.%u (%s)\n",crc32,msgstr); LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); } // else printf("no valid method in (%s)\n",msgstr); free_json(argjson); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0b8a24b31..24e99a821 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -762,7 +762,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, jaddbits256(retjson,"pubkey",butxo->S.otherpubkey); jaddstr(retjson,"method","reserved"); msg = jprint(retjson,1); - printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)",butxo->T.swappending,qprice,price,msg); + printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); { bits256 zero; memset(&zero,0,sizeof(zero)); @@ -820,8 +820,8 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q if ( aliceutxo->S.swap != 0 ) break; sleep(3); - price = LP_query(ctx,myipaddr,mypubsock,"connect",qp); - LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); + //price = LP_query(ctx,myipaddr,mypubsock,"connect",qp); + //LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); } if ( aliceutxo->S.swap == 0 ) { From dc0ff5f3896e7499ae8e4bd549a1b240fc681427 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 19:40:33 +0200 Subject: [PATCH 228/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_network.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0a409cbb1..45b19f561 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -735,8 +735,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) != 0 ) nonz++; - if ( LP_mypullsock >= 0 ) - nonz += LP_sock_check("SUB",ctx,myipaddr,-1,LP_mypullsock,"127.0.0.1"); + //if ( LP_mypullsock >= 0 ) + // nonz += LP_sock_check("SUB",ctx,myipaddr,-1,LP_mypullsock,"127.0.0.1"); if ( nonz == 0 ) usleep(1000000 / MAINLOOP_PERSEC); } diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 525a13d5c..de2861cd1 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -311,7 +311,7 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25 jdelete(argjson,"method2"); jaddstr(argjson,"method2",method); jaddstr(argjson,"method",method); - if ( strncmp(method,"connect",7) == 0 ) + if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) printf("CRC32.%u (%s)\n",crc32,msgstr); LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); } // else printf("no valid method in (%s)\n",msgstr); From 9a5965ab3d1c9f30d00e14476ae3d92fb0d5c996 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 19:53:52 +0200 Subject: [PATCH 229/520] Test --- iguana/exchanges/LP_ordermatch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 24e99a821..d4b2e342f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -541,7 +541,10 @@ void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) { struct LP_utxoinfo *setutxo; if ( (setutxo= LP_butxo_add(butxo)) != 0 ) + { LP_butxo_swapfields_copy(setutxo,butxo); + printf("LP_butxo_swapfields_copy set\n"); + } } void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) @@ -766,8 +769,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); - //_LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); - LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey + _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + //LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey } butxo->T.lasttime = (uint32_t)time(NULL); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); From a497f744b944852fa8ad56592ddacedad67beccf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:05:12 +0200 Subject: [PATCH 230/520] Test --- iguana/exchanges/LP_ordermatch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d4b2e342f..3db672af0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -709,7 +709,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { retval = 1; - printf("LP_tradecommand: check received %s\n",method); if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) { printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); @@ -765,14 +764,16 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, jaddbits256(retjson,"pubkey",butxo->S.otherpubkey); jaddstr(retjson,"method","reserved"); msg = jprint(retjson,1); + butxo->T.lasttime = (uint32_t)time(NULL); printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); { bits256 zero; memset(&zero,0,sizeof(zero)); - _LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + //_LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); //LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey + LP_butxo_swapfields_set(butxo); + return(1); } - butxo->T.lasttime = (uint32_t)time(NULL); } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } else if ( strcmp(method,"connect") == 0 ) // bob @@ -782,12 +783,15 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { // validate SPV alice LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); + LP_butxo_swapfields_set(butxo); + return(2); } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } - LP_butxo_swapfields_set(butxo); } } + if ( method != 0 ) + printf("LP_tradecommand: check received %s\n",method); return(retval); } From f7b9a735e388a407dd192bdce8a5f3e12d128e9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:15:22 +0200 Subject: [PATCH 231/520] Test --- iguana/exchanges/LP_ordermatch.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3db672af0..43be9afb7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -705,10 +705,11 @@ char *LP_connectedalice(cJSON *argjson) // alice int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_address_utxo **utxos; struct LP_quoteinfo Q; int32_t retval = -1,max=10000; + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { - retval = 1; + printf("LP_tradecommand: check received %s\n",method); + //retval = 1; if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) { printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); @@ -723,9 +724,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, LP_abutxo_set(autxo,0,&Q); if ( strcmp(method,"request") == 0 ) { - utxos = calloc(max,sizeof(*utxos)); + //utxos = calloc(max,sizeof(*utxos)); butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1); - free(utxos); + //free(utxos), utxos = 0; } if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { @@ -767,10 +768,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo->T.lasttime = (uint32_t)time(NULL); printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); { - bits256 zero; - memset(&zero,0,sizeof(zero)); - //_LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); - //LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); //butxo->S.otherpubkey + //bits256 zero; + //memset(&zero,0,sizeof(zero)); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); LP_butxo_swapfields_set(butxo); return(1); } @@ -788,10 +788,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } + LP_butxo_swapfields_set(butxo); } } - if ( method != 0 ) - printf("LP_tradecommand: check received %s\n",method); return(retval); } From c6f25ab279bee143c79e4d5d9d31fbfc32504878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:18:46 +0200 Subject: [PATCH 232/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 45b19f561..ffa8eec48 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -271,7 +271,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { - while ( nonz < 1000 && recvlen > 0 ) + while ( nonz < 1 && recvlen > 0 ) { memset(&pfd,0,sizeof(pfd)); pfd.fd = sock; @@ -280,8 +280,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - //if ( recvlen > 1500 ) - // fprintf(stderr,"%d ",recvlen); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); From d3c0cbec0d1fd7d9a0cdbfba025f86c6ea366d1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:23:58 +0200 Subject: [PATCH 233/520] Test --- iguana/exchanges/LP_commands.c | 6 ++++++ iguana/exchanges/LP_ordermatch.c | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 7b6ae9411..a28c0217f 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -367,9 +367,15 @@ dividends(coin, height, )\n\ else if ( IAMLP == 0 && LP_isdisabled(jstr(argjson,"coin"),0) != 0 ) retstr = clonestr("{\"result\":\"coin is disabled\"}"); else if ( strcmp(method,"reserved") == 0 ) + { + printf("RESERVED.(%s)\n",jprint(argjson,0)); retstr = LP_quotereceived(argjson); + } else if ( strcmp(method,"connected") == 0 ) + { + printf("CONNECTED.(%s)\n",jprint(argjson,0)); retstr = LP_connectedalice(argjson); + } else if ( strcmp(method,"checktxid") == 0 ) retstr = LP_spentcheck(argjson); else if ( strcmp(method,"getcoins") == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 43be9afb7..e627e4102 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -709,7 +709,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); - //retval = 1; + retval = 1; if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) { printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); @@ -772,7 +772,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); LP_butxo_swapfields_set(butxo); - return(1); + return(2); } } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } @@ -784,7 +784,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, // validate SPV alice LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); LP_butxo_swapfields_set(butxo); - return(2); + return(3); } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } From 80537395ade272489b5c4618dd278522047deb9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:39:56 +0200 Subject: [PATCH 234/520] Test --- iguana/exchanges/LP_nativeDEX.c | 10 ++++++++-- iguana/exchanges/LP_ordermatch.c | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ffa8eec48..4878d0fc4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -207,6 +207,8 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } + if ( jobj(argjson,"method") != 0 && strncmp(jstr(argjson,"method"),"connect",7) == 0 ) + fprintf(stderr,"finished %s\n",jsonstr); free_json(argjson); } } @@ -320,9 +322,13 @@ void command_rpcloop(void *myipaddr) { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 10000) == 0 ) + if ( (rand() % 100) == 0 ) peer->errors--; - else continue; + else + { + printf("skip %s\n",peer->ipaddr); + continue; + } } //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e627e4102..d86298e92 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -712,7 +712,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, retval = 1; if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) { - printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); if ( (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) { printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); @@ -733,6 +732,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, char str[65]; printf("couldnt find bob utxos for autxo %s/v%d %.8f\n",bits256_str(str,autxo->payment.txid),autxo->payment.vout,dstr(autxo->S.satoshis)); return(-44); } + printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); Q.txid = butxo->payment.txid; Q.vout = butxo->payment.vout; Q.txid2 = butxo->deposit.txid; @@ -772,7 +772,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); LP_butxo_swapfields_set(butxo); - return(2); + return(0); } } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } @@ -784,7 +784,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, // validate SPV alice LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); LP_butxo_swapfields_set(butxo); - return(3); + return(0); } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } From c2d6d15c9785d55e351e5594540f8031674606b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:47:46 +0200 Subject: [PATCH 235/520] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_ordermatch.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4878d0fc4..1984ebfea 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -111,7 +111,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } - } + } else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); } @@ -207,7 +207,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } - if ( jobj(argjson,"method") != 0 && strncmp(jstr(argjson,"method"),"connect",7) == 0 ) + //if ( jobj(argjson,"method") != 0 && strncmp(jstr(argjson,"method"),"connect",7) == 0 ) fprintf(stderr,"finished %s\n",jsonstr); free_json(argjson); } @@ -322,7 +322,7 @@ void command_rpcloop(void *myipaddr) { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 100) == 0 ) + if ( (rand() % 1000) == 0 ) peer->errors--; else { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d86298e92..104a98872 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -772,6 +772,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); LP_butxo_swapfields_set(butxo); + printf("return after RESERVED\n"); return(0); } } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); From 905ca8f620dcd679fad9d725da0affceefa19a88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 20:59:08 +0200 Subject: [PATCH 236/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_network.c | 2 ++ iguana/exchanges/LP_ordermatch.c | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1984ebfea..86f1eca78 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -207,7 +207,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } - //if ( jobj(argjson,"method") != 0 && strncmp(jstr(argjson,"method"),"connect",7) == 0 ) + if ( jobj(argjson,"method") != 0 && (strncmp(jstr(argjson,"method"),"connect",7) == 0 || strncmp(jstr(argjson,"method"),"reserve",7) == 0) ) fprintf(stderr,"finished %s\n",jsonstr); free_json(argjson); } diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index de2861cd1..30b83e127 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -314,6 +314,8 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25 if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) printf("CRC32.%u (%s)\n",crc32,msgstr); LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); + if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) + printf("finished %u\n",crc32); } // else printf("no valid method in (%s)\n",msgstr); free_json(argjson); } else printf("couldnt parse (%s)\n",msgstr); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 104a98872..c50265c66 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -768,9 +768,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo->T.lasttime = (uint32_t)time(NULL); printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); { - //bits256 zero; - //memset(&zero,0,sizeof(zero)); - LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); + bits256 zero; + memset(&zero,0,sizeof(zero)); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg);//butxo->S.otherpubkey,msg); LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); return(0); From 2570123d2ffd07a244ed2dd6a58ee25d18b8f350 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 21:08:12 +0200 Subject: [PATCH 237/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c50265c66..9f0b15e0f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -456,7 +456,10 @@ struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) { utxo = &BUTXOS[i]; if ( memcmp(&zeroes,utxo,sizeof(*utxo)) == 0 ) + { *utxo = *butxo; + break; + } } } portable_mutex_unlock(&LP_butxomutex); @@ -771,6 +774,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, bits256 zero; memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg);//butxo->S.otherpubkey,msg); + printf("return after RESERVED\n"); LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); return(0); From 57cd0d812c43dd753c9aa3cfc69adb0bb4fdee24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 21:12:58 +0200 Subject: [PATCH 238/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 -- iguana/exchanges/LP_ordermatch.c | 76 ++++++++++++++++---------------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 86f1eca78..c6274457e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -202,13 +202,9 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( jsonstr != 0 && argjson != 0 ) { len = (int32_t)strlen(jsonstr) + 1; - if ( jobj(argjson,"method") != 0 && strncmp(jstr(argjson,"method"),"connect",7) == 0 ) - fprintf(stderr,"%s\n",jsonstr); if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } - if ( jobj(argjson,"method") != 0 && (strncmp(jstr(argjson,"method"),"connect",7) == 0 || strncmp(jstr(argjson,"method"),"reserve",7) == 0) ) - fprintf(stderr,"finished %s\n",jsonstr); free_json(argjson); } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9f0b15e0f..0e5fe431b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -429,43 +429,6 @@ int32_t LP_butxo_findeither(bits256 txid,int32_t vout) return(retval); } -struct LP_utxoinfo *LP_butxo_find(struct LP_utxoinfo *butxo) -{ - int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); - portable_mutex_lock(&LP_butxomutex); - for (i=0; ipayment.vout == utxo->payment.vout && butxo->deposit.vout == utxo->deposit.vout && bits256_nonz(butxo->payment.txid) != 0 && bits256_nonz(butxo->deposit.txid) != 0 && bits256_cmp(butxo->payment.txid,utxo->payment.txid) == 0 && bits256_cmp(butxo->deposit.txid,utxo->deposit.txid) == 0 ) - break; - if ( utxo->S.swap == 0 && now > utxo->T.swappending ) - memset(utxo,0,sizeof(*utxo)); - } - portable_mutex_unlock(&LP_butxomutex); - return(utxo); -} - -struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) -{ - static struct LP_utxoinfo zeroes; - int32_t i; struct LP_utxoinfo *utxo=0; - portable_mutex_lock(&LP_butxomutex); - if ( (utxo= LP_butxo_find(butxo)) == 0 ) - { - for (i=0; ipayment.vout == utxo->payment.vout && butxo->deposit.vout == utxo->deposit.vout && bits256_nonz(butxo->payment.txid) != 0 && bits256_nonz(butxo->deposit.txid) != 0 && bits256_cmp(butxo->payment.txid,utxo->payment.txid) == 0 && bits256_cmp(butxo->deposit.txid,utxo->deposit.txid) == 0 ) + break; + if ( utxo->S.swap == 0 && now > utxo->T.swappending ) + memset(utxo,0,sizeof(*utxo)); + utxo = 0; + } + portable_mutex_unlock(&LP_butxomutex); + return(utxo); +} + +struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) +{ + static struct LP_utxoinfo zeroes; + int32_t i; struct LP_utxoinfo *utxo=0; + portable_mutex_lock(&LP_butxomutex); + if ( (utxo= LP_butxo_find(butxo)) == 0 ) + { + for (i=0; iS = srcutxo->S; From 52e4929a4b452a974cf853b6619fdf107ce22972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 21:19:41 +0200 Subject: [PATCH 239/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_network.c | 10 +++++----- iguana/exchanges/LP_ordermatch.c | 12 +++++++----- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a28c0217f..ae78f9a98 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -368,7 +368,7 @@ dividends(coin, height, )\n\ retstr = clonestr("{\"result\":\"coin is disabled\"}"); else if ( strcmp(method,"reserved") == 0 ) { - printf("RESERVED.(%s)\n",jprint(argjson,0)); + //printf("RESERVED.(%s)\n",jprint(argjson,0)); retstr = LP_quotereceived(argjson); } else if ( strcmp(method,"connected") == 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c6274457e..0b5113618 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -111,7 +111,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } - } else printf("finished tradecommand (%s)\n",jprint(argjson,0)); + } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); } diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 30b83e127..1a6a758b9 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -157,7 +157,7 @@ void queue_loop(void *ignore) { if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); - else printf("%d %p qsent %u msglen.%d peerind.%d\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind); + //else printf("%d %p qsent %u msglen.%d peerind.%d\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind); ptr->sock = -1; if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); @@ -311,11 +311,11 @@ void LP_broadcast_message(int32_t pubsock,char *base,char *rel,bits256 destpub25 jdelete(argjson,"method2"); jaddstr(argjson,"method2",method); jaddstr(argjson,"method",method); - if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) - printf("CRC32.%u (%s)\n",crc32,msgstr); + //if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) + // printf("CRC32.%u (%s)\n",crc32,msgstr); LP_broadcast_finish(pubsock,base,rel,msg,argjson,0); - if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) - printf("finished %u\n",crc32); + //if ( strncmp(method,"connect",7) == 0 || strcmp(method,"reserved") == 0 ) + // printf("finished %u\n",crc32); } // else printf("no valid method in (%s)\n",msgstr); free_json(argjson); } else printf("couldnt parse (%s)\n",msgstr); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0e5fe431b..f8ae7c857 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -490,10 +490,10 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre return(0); } -struct LP_utxoinfo *LP_butxo_find(struct LP_utxoinfo *butxo) +struct LP_utxoinfo *_LP_butxo_find(struct LP_utxoinfo *butxo) { int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); - portable_mutex_lock(&LP_butxomutex); + //portable_mutex_lock(&LP_butxomutex); for (i=0; i Date: Thu, 21 Sep 2017 21:26:09 +0200 Subject: [PATCH 240/520] Test --- iguana/exchanges/LP_ordermatch.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index f8ae7c857..4be94c444 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -494,6 +494,7 @@ struct LP_utxoinfo *_LP_butxo_find(struct LP_utxoinfo *butxo) { int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); //portable_mutex_lock(&LP_butxomutex); + printf("_LP_butxo_find\n"); for (i=0; iS = srcutxo->S; destutxo->T.swappending = srcutxo->T.swappending; } @@ -538,6 +543,7 @@ void LP_butxo_swapfields_copy(struct LP_utxoinfo *destutxo,struct LP_utxoinfo *s void LP_butxo_swapfields(struct LP_utxoinfo *butxo) { struct LP_utxoinfo *getutxo=0; + printf("swapfields\n"); portable_mutex_lock(&LP_butxomutex); if ( (getutxo= _LP_butxo_find(butxo)) != 0 ) LP_butxo_swapfields_copy(butxo,getutxo); @@ -547,6 +553,7 @@ void LP_butxo_swapfields(struct LP_utxoinfo *butxo) void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) { struct LP_utxoinfo *setutxo; + printf("swapfields set\n"); if ( (setutxo= LP_butxo_add(butxo)) != 0 ) { LP_butxo_swapfields_copy(setutxo,butxo); From 80bf841fadc4a4b439059cae1823987842978609 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 21:28:52 +0200 Subject: [PATCH 241/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0b5113618..ec4748f02 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -318,11 +318,11 @@ void command_rpcloop(void *myipaddr) { if ( peer->errors >= LP_MAXPEER_ERRORS ) { - if ( (rand() % 1000) == 0 ) + if ( (rand() % 10000) == 0 ) peer->errors--; else { - printf("skip %s\n",peer->ipaddr); + //printf("skip %s\n",peer->ipaddr); continue; } } From 61a14b3b946fa65a9f10ab28453ad650f64d6bd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 21:51:38 +0200 Subject: [PATCH 242/520] Test --- iguana/exchanges/LP_ordermatch.c | 13 ++++++------- iguana/exchanges/LP_scan.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 4be94c444..3d3a9bdcf 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -352,16 +352,16 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L jaddstr(reqjson,"method",method); msg = jprint(reqjson,1); printf("QUERY.(%s)\n",msg); - if ( strcmp(method,"connect") == 0 ) + memset(&zero,0,sizeof(zero)); + if ( 0 && strcmp(method,"connect") == 0 ) { sleep(3); - memset(&zero,0,sizeof(zero)); LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg); } else { memset(&zero,0,sizeof(zero)); - LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg); + LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); for (i=0; i<30; i++) { if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) @@ -744,7 +744,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { char str[65]; printf("couldnt find bob utxos for autxo %s/v%d %.8f\n",bits256_str(str,autxo->payment.txid),autxo->payment.vout,dstr(autxo->S.satoshis)); - return(-44); + return(1); } printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); Q.txid = butxo->payment.txid; @@ -785,10 +785,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, bits256 zero; memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg);//butxo->S.otherpubkey,msg); - printf("return after RESERVED\n"); LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); - return(0); + return(2); } } else printf("warning swappending.%u swap.%p\n",butxo->T.swappending,butxo->S.swap); } @@ -800,7 +799,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, // validate SPV alice LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); LP_butxo_swapfields_set(butxo); - return(0); + return(3); } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 019767670..7d2bf6dda 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -478,7 +478,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration free(array); } } - if ( time(NULL) < expiration ) + if ( time(NULL) > expiration ) break; usleep(500000); } From e58d85a2675e3e9caf3724cb4cea9957006dd7eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 22:06:34 +0200 Subject: [PATCH 243/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3d3a9bdcf..038ef08a4 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -738,7 +738,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"request") == 0 ) { //utxos = calloc(max,sizeof(*utxos)); - butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1); + butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis+Q.desttxfee),price,1); //free(utxos), utxos = 0; } if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) From f944b19624ceaf787ab9fa07e7308bff573a78a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 22:15:40 +0200 Subject: [PATCH 244/520] Test --- iguana/exchanges/LP_ordermatch.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 038ef08a4..dadcbb6d8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -290,11 +290,16 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str if ( strcmp(autxo->coinaddr,qp->destaddr) != 0 ) return(-10); } - if ( (autxo != 0 && destvalue < qp->desttxfee+qp->destsatoshis) || (butxo != 0 && srcvalue < qp->txfee+qp->satoshis) ) + if ( autxo != 0 && destvalue < qp->desttxfee+qp->destsatoshis ) { - printf("destvalue %.8f srcvalue %.8f, destsatoshis %.8f or satoshis %.8f is too small txfees %.8f %.8f?\n",dstr(destvalue),dstr(srcvalue),dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->desttxfee),dstr(qp->txfee)); + printf("destvalue %.8f destsatoshis %.8f is too small txfee %.8f?\n",dstr(destvalue),dstr(qp->destsatoshis),dstr(qp->desttxfee)); return(-11); } + if ( butxo != 0 && srcvalue < qp->txfee+qp->satoshis ) + { + printf("srcvalue %.8f satoshis %.8f is too small txfee %.8f?\n",dstr(srcvalue),dstr(qp->satoshis),dstr(qp->txfee)); + return(-33); + } if ( qp->satoshis != 0 ) qprice = ((double)qp->destsatoshis / qp->satoshis); LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); @@ -448,14 +453,14 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t return(mini); } -struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,int32_t avoidflag) +struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,int32_t avoidflag,uint64_t desttxfee) { struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (m= LP_address_utxo_ptrs(utxos,max,ap,avoidflag)) > 1 ) { - targetval = SATOSHIDEN * (volume / price) + 2*txfee; + targetval = SATOSHIDEN * ((volume+desttxfee) / price) + 2*txfee; { int32_t i; for (i=0; ipayment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) @@ -915,7 +920,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr //printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); //if ( relvolume >= minvol && relvolume <= maxvol ) { - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price,0)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From 7d12954ab7a4ecdf80d4b5aca792714e8cdac6c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 22:23:02 +0200 Subject: [PATCH 245/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index dadcbb6d8..36723b31d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -460,7 +460,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre { if ( (m= LP_address_utxo_ptrs(utxos,max,ap,avoidflag)) > 1 ) { - targetval = SATOSHIDEN * ((volume+desttxfee) / price) + 2*txfee; + targetval = SATOSHIDEN * ((volume + dstr(desttxfee)) / price) + 2*txfee; { int32_t i; for (i=0; i Date: Thu, 21 Sep 2017 22:26:16 +0200 Subject: [PATCH 246/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 36723b31d..9a5359155 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -442,9 +442,9 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t if ( utxos[i] != 0 ) { dist = (utxos[i]->U.value - targetval); - //printf("(%.8f %.8f %.8f).%d ",dstr(values[i]),dstr(dist),dstr(mindist),mini); if ( dist >= 0 && dist < mindist ) { + printf("(%.8f %.8f %.8f).%d ",dstr(utxos[i]->U.value),dstr(dist),dstr(mindist),mini); mini = i; mindist = dist; } From bedfcabde3c20152abf837cf321804c9fdf05ab1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 22:36:16 +0200 Subject: [PATCH 247/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9a5359155..ba0a495fc 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -471,7 +471,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre { up = utxos[mini]; utxos[mini] = 0; - targetval = (targetval / 8) * 9 + 2*txfee; + targetval = (up->U.value / 8) * 9 + 2*txfee; if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) { if ( up != 0 && (up2= utxos[mini]) != 0 ) @@ -485,7 +485,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre utxo->deposit.txid = up2->U.txid; utxo->deposit.vout = up2->U.vout; utxo->deposit.value = up2->U.value; - utxo->S.satoshis = SATOSHIDEN * (volume / price); + utxo->S.satoshis = SATOSHIDEN * ((volume + dstr(desttxfee)) / price); return(utxo); } } @@ -924,8 +924,8 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - autxo->S.satoshis = bestutxo->S.satoshis * price; - *bestsatoshisp = bestutxo->S.satoshis; + autxo->S.satoshis = bestutxo->S.satoshis * price - desttxfee; + *bestsatoshisp = bestutxo->S.satoshis - txfee; *ordermatchpricep = price; *bestdestsatoshisp = autxo->S.satoshis; printf("ordermatch %.8f %.8f %.8f\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp)); From 8774869824e4aef5ada203b62189ef1e51325c26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 22:43:30 +0200 Subject: [PATCH 248/520] Test --- iguana/exchanges/LP_include.h | 2 ++ iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 22 ++++++++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 6453ce80c..9ca3cdb5f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -284,6 +284,7 @@ int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,bits256 pubkey,char int32_t LP_ismine(struct LP_utxoinfo *utxo); int32_t LP_isavailable(struct LP_utxoinfo *utxo); struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port); +uint64_t LP_value_extract(cJSON *obj,int32_t addinterest); char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen); void LP_availableset(struct LP_utxoinfo *utxo); int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2); @@ -307,6 +308,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum void LP_postutxos(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); int32_t LP_butxo_findeither(bits256 txid,int32_t vout); +cJSON *LP_listunspent(char *symbol,char *coinaddr); #endif diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ba0a495fc..2b222070d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -903,7 +903,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr price = jdouble(item,"price"); if ( LP_pricevalid(price) > 0 && price <= maxprice ) { - printf("%s\n",jprint(item,0)); + //printf("%s\n",jprint(item,0)); pubkey = jbits256(item,"pubkey"); if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 013e25114..8fdaf0c68 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -313,7 +313,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) { - char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; + char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value,val; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; if ( symbol == 0 || symbol[0] == 0 ) return(cJSON_Parse("{\"error\":\"null symbol\"}")); coin = LP_coinfind(symbol); @@ -351,7 +351,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) LP_swap_coinaddr(coin,coinaddr,&value,serialized,len,vout); //printf("HEX.(%s) len.%d %s %.8f\n",hexstr+1,len,coinaddr,dstr(value)); free(hexstr); - if ( (array= electrum_address_listunspent(coin->symbol,0,&array,coinaddr)) != 0 ) + if ( (array= LP_listunspent(coin->symbol,coinaddr)) != 0 ) { //printf("array.(%s)\n",jprint(array,0)); if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 ) @@ -359,8 +359,20 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) for (i=0; ielectrum == 0 ) + { + t = jbits256(item,"txid"); + v = jint(item,"vout"); + val = LP_value_extract(item,0); + } + else + { + t = jbits256(item,"tx_hash"); + v = jint(item,"tx_pos"); + val = j64bits(item,"value"); + } + if ( value != val ) + printf("LP_gettxout: value %llu != %llu\n",(long long)value,(long long)val); if ( v == vout && bits256_cmp(t,txid) == 0 ) { retjson = cJSON_CreateObject(); @@ -380,8 +392,6 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) "version": 1, "coinbase": false }*/ - if ( value != j64bits(item,"value") ) - printf("LP_gettxout: value %llu != %llu\n",(long long)value,(long long)j64bits(item,"value")); jaddnum(retjson,"value",dstr(value)); jaddbits256(retjson,"txid",t); jaddnum(retjson,"vout",v); From b8a69ad98e3c93ac15b4174875fcb6a9dbdd192a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 22:52:56 +0200 Subject: [PATCH 249/520] Test --- iguana/exchanges/LP_ordermatch.c | 7 ++++--- iguana/exchanges/LP_rpc.c | 30 +++++++++++------------------- iguana/exchanges/LP_socket.c | 25 +++++++++++++++++++------ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 2b222070d..ee012976e 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -880,7 +880,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*array,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -908,11 +908,12 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( (array= electrum_address_listunspent(basecoin->symbol,basecoin->electrum,&array,coinaddr)) != 0 ) + /*if ( (array= LP_listunspent(basecoin->symbol,coinaddr)) != 0 ) { n = cJSON_GetArraySize(array); free_json(array); - } else n = 0; + } else n = 0;*/ + n = LP_listunspent_issue(basecoin->symbol,coinaddr); if ( n > 1 ) { //minvol = jdouble(item,"minvolume"); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 8fdaf0c68..b5725f181 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -313,7 +313,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) { - char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value,val; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; + char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; if ( symbol == 0 || symbol[0] == 0 ) return(cJSON_Parse("{\"error\":\"null symbol\"}")); coin = LP_coinfind(symbol); @@ -351,7 +351,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) LP_swap_coinaddr(coin,coinaddr,&value,serialized,len,vout); //printf("HEX.(%s) len.%d %s %.8f\n",hexstr+1,len,coinaddr,dstr(value)); free(hexstr); - if ( (array= LP_listunspent(coin->symbol,coinaddr)) != 0 ) + if ( (array= electrum_address_listunspent(coin->symbol,0,&array,coinaddr)) != 0 ) { //printf("array.(%s)\n",jprint(array,0)); if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 ) @@ -359,20 +359,8 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) for (i=0; ielectrum == 0 ) - { - t = jbits256(item,"txid"); - v = jint(item,"vout"); - val = LP_value_extract(item,0); - } - else - { - t = jbits256(item,"tx_hash"); - v = jint(item,"tx_pos"); - val = j64bits(item,"value"); - } - if ( value != val ) - printf("LP_gettxout: value %llu != %llu\n",(long long)value,(long long)val); + t = jbits256(item,"tx_hash"); + v = jint(item,"tx_pos"); if ( v == vout && bits256_cmp(t,txid) == 0 ) { retjson = cJSON_CreateObject(); @@ -392,6 +380,8 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) "version": 1, "coinbase": false }*/ + if ( value != j64bits(item,"value") ) + printf("LP_gettxout: value %llu != %llu\n",(long long)value,(long long)j64bits(item,"value")); jaddnum(retjson,"value",dstr(value)); jaddbits256(retjson,"txid",t); jaddnum(retjson,"vout",v); @@ -502,11 +492,11 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)); } -void LP_listunspent_issue(char *symbol,char *coinaddr) +int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { - struct iguana_info *coin; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; + struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; if ( symbol == 0 || symbol[0] == 0 ) - return; + return(0); if ( (coin= LP_coinfind(symbol)) != 0 ) { if ( coin->electrum != 0 ) @@ -525,6 +515,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) } if ( retjson != 0 ) { + n = cJSON_GetArraySize(retjson); if ( electrum_process_array(coin,0,coinaddr,retjson) != 0 ) LP_postutxos(symbol,coinaddr); // might be good to not saturate } @@ -534,6 +525,7 @@ void LP_listunspent_issue(char *symbol,char *coinaddr) if ( retstr != 0 ) free(retstr); } + return(n); } cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 091233f4c..02f9387fc 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -307,14 +307,29 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep,char *coinaddr,cJSON *array) { - int32_t i,v,n,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; + int32_t i,v,n,ht,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { //printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); for (i=0; ielectrum == 0 ) + { + txid = jbits256(item,"txid"); + v = jint(item,"vout"); + value = LP_value_extract(item,0); + ht = LP_txheight(coin,txid); + } + else + { + txid = jbits256(item,"tx_hash"); + v = jint(item,"tx_pos"); + value = j64bits(item,"value"); + ht = jint(item,"height"); + } + if ( bits256_nonz(txid) == 0 ) + continue; if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { txobj = LP_transactioninit(coin,txid,0,0); @@ -325,12 +340,10 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep { if (tx->height <= 0 ) { - tx->height = jint(item,"height"); + tx->height = ht; //printf("%s %s >>>>>>>>>> set %s <- height %d\n",coin->symbol,coinaddr,bits256_str(str,txid),tx->height); } - value = j64bits(item,"value"); - v = jint(item,"tx_pos"); - if ( jobj(item,"tx_pos") != 0 && jobj(item,"value") != 0 && v >= 0 && v < tx->numvouts ) + if ( v >= 0 && v < tx->numvouts ) { if ( tx->outpoints[v].value == 0 && value != tx->outpoints[v].value ) { From dced1b5f90b19a9dcb616d8ef60cdfb743561642 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:01:21 +0200 Subject: [PATCH 250/520] Test --- iguana/exchanges/LP_ordermatch.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ee012976e..405d2960c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -880,7 +880,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*array,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -903,17 +903,19 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr price = jdouble(item,"price"); if ( LP_pricevalid(price) > 0 && price <= maxprice ) { - //printf("%s\n",jprint(item,0)); + printf("%s\n",jprint(item,0)); pubkey = jbits256(item,"pubkey"); if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - /*if ( (array= LP_listunspent(basecoin->symbol,coinaddr)) != 0 ) + if ( basecoin->electrum != 0 ) { - n = cJSON_GetArraySize(array); - free_json(array); - } else n = 0;*/ - n = LP_listunspent_issue(basecoin->symbol,coinaddr); + if ( (array= LP_listunspent(basecoin->symbol,coinaddr)) != 0 ) + { + n = cJSON_GetArraySize(array); + free_json(array); + } else n = 0; + } else n = LP_listunspent_issue(basecoin->symbol,coinaddr); if ( n > 1 ) { //minvol = jdouble(item,"minvolume"); From c4056761f2ac8740f6e38998e7425c802cd0e311 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:10:56 +0200 Subject: [PATCH 251/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 405d2960c..00cc9b639 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -923,7 +923,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr //printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); //if ( relvolume >= minvol && relvolume <= maxvol ) { - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,relvolume,price,0,desttxfee)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,dstr(bestutxo->S.satoshis * price - desttxfee),price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -931,7 +931,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr *bestsatoshisp = bestutxo->S.satoshis - txfee; *ordermatchpricep = price; *bestdestsatoshisp = autxo->S.satoshis; - printf("ordermatch %.8f %.8f %.8f\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp)); + printf("ordermatch %.8f %.8f %.8f txfees (%.8f %.8f)\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp),dstr(txfee),dstr(desttxfee)); break; } } From 98b38fa81e1a36626970d1ddb3c03fc45c38412e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:13:17 +0200 Subject: [PATCH 252/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 00cc9b639..d1f2e3f93 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -968,9 +968,9 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel timeout = LP_AUTOTRADE_TIMEOUT; if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); - if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume)) == 0 ) - return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); LP_txfees(&txfee,&desttxfee,base,rel); + if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume + desttxfee)) == 0 ) + return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); memset(&_best,0,sizeof(_best)); if ( (bestutxo= LP_buyutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,relvolume,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) { From 43a445509aed3ec617f626d33be2394f59bfc668 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:18:24 +0200 Subject: [PATCH 253/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++---- iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d1f2e3f93..c24a163ac 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -485,7 +485,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre utxo->deposit.txid = up2->U.txid; utxo->deposit.vout = up2->U.vout; utxo->deposit.value = up2->U.value; - utxo->S.satoshis = SATOSHIDEN * ((volume + dstr(desttxfee)) / price); + utxo->S.satoshis = SATOSHIDEN * (volume / price); return(utxo); } } @@ -923,12 +923,12 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr //printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); //if ( relvolume >= minvol && relvolume <= maxvol ) { - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,dstr(bestutxo->S.satoshis * price - desttxfee),price,0,desttxfee)) != 0 ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,dstr(autxo->S.satoshis),price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - autxo->S.satoshis = bestutxo->S.satoshis * price - desttxfee; - *bestsatoshisp = bestutxo->S.satoshis - txfee; + //autxo->S.satoshis = bestutxo->S.satoshis * price - desttxfee; + *bestsatoshisp = bestutxo->S.satoshis; *ordermatchpricep = price; *bestdestsatoshisp = autxo->S.satoshis; printf("ordermatch %.8f %.8f %.8f txfees (%.8f %.8f)\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp),dstr(txfee),dstr(desttxfee)); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 479500d3c..0889cef7c 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -290,7 +290,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) continue; if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 ) { - if ( utxo->S.satoshis >= destsatoshis/2 && (bestutxo == 0 || (bestutxo->S.satoshis < destsatoshis && utxo->S.satoshis >= destsatoshis) || (bestutxo->S.satoshis >= destsatoshis && utxo->S.satoshis < bestutxo->S.satoshis)) ) + if ( utxo->S.satoshis >= destsatoshis && (bestutxo == 0 || (bestutxo->S.satoshis < destsatoshis && utxo->S.satoshis >= destsatoshis) || (bestutxo->S.satoshis >= destsatoshis && utxo->S.satoshis < bestutxo->S.satoshis)) ) { if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 ) { From bb4681b6baa6ca7923107dda6b28a6bb56cc12e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:37:26 +0200 Subject: [PATCH 254/520] Test --- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_ordermatch.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 1a6a758b9..55fffe825 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -162,7 +162,7 @@ void queue_loop(void *ignore) if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); else flag = 1; - } else printf("sock not ready to send.%d\n",ptr->msglen); + } //else printf("sock not ready to send.%d\n",ptr->msglen); } else if ( time(NULL) > ptr->starttime+13 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c24a163ac..9ba930ee3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -724,14 +724,14 @@ char *LP_connectedalice(cJSON *argjson) // alice int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg; cJSON *retjson,*array; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t n,retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); retval = 1; if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) { - if ( (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) + if ( (coin= LP_coinfind(Q.srccoin)) == 0 || (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) { printf("this node has no price for %s/%s\n",Q.srccoin,Q.destcoin); return(-3); @@ -743,6 +743,14 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( strcmp(method,"request") == 0 ) { //utxos = calloc(max,sizeof(*utxos)); + if ( coin->electrum != 0 ) + { + if ( (array= LP_listunspent(coin->symbol,Q.coinaddr)) != 0 ) + { + n = cJSON_GetArraySize(array); + free_json(array); + } else n = 0; + } else n = LP_listunspent_issue(coin->symbol,Q.coinaddr); butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1,Q.desttxfee); //free(utxos), utxos = 0; } From a7435eef4e11a2165bead8982b2ca839456c34e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:47:43 +0200 Subject: [PATCH 255/520] Test --- iguana/exchanges/LP_ordermatch.c | 38 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9ba930ee3..ac76c941d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -739,20 +739,32 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price = ask; autxo = &A; butxo = &B; - LP_abutxo_set(autxo,0,&Q); + LP_abutxo_set(autxo,butxo,&Q); if ( strcmp(method,"request") == 0 ) { - //utxos = calloc(max,sizeof(*utxos)); - if ( coin->electrum != 0 ) + if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { - if ( (array= LP_listunspent(coin->symbol,Q.coinaddr)) != 0 ) + if ( coin->electrum != 0 ) { - n = cJSON_GetArraySize(array); - free_json(array); - } else n = 0; - } else n = LP_listunspent_issue(coin->symbol,Q.coinaddr); - butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1,Q.desttxfee); - //free(utxos), utxos = 0; + if ( (array= LP_listunspent(coin->symbol,Q.coinaddr)) != 0 ) + { + n = cJSON_GetArraySize(array); + free_json(array); + } else n = 0; + } + else + { + n = LP_listunspent_issue(coin->symbol,Q.coinaddr); + printf("need to verify\n"); + } + butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1,Q.desttxfee); + Q.txid = butxo->payment.txid; + Q.vout = butxo->payment.vout; + Q.txid2 = butxo->deposit.txid; + Q.vout2 = butxo->deposit.vout; + LP_abutxo_set(0,butxo,&Q); + LP_butxo_swapfields(butxo); + } } if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { @@ -760,12 +772,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(1); } printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); - Q.txid = butxo->payment.txid; - Q.vout = butxo->payment.vout; - Q.txid2 = butxo->deposit.txid; - Q.vout2 = butxo->deposit.vout; - LP_abutxo_set(0,butxo,&Q); - LP_butxo_swapfields(butxo); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); From 2af509d711cd7845007a446f23a8d930284d2aa2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Sep 2017 23:53:17 +0200 Subject: [PATCH 256/520] Test --- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_ordermatch.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 55fffe825..02905f29a 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -87,7 +87,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) { - static uint32_t crcs[16]; static unsigned long dup,total; + static uint32_t crcs[256]; static unsigned long dup,total; int32_t i; *duplicatep = 0; if ( ind < 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ac76c941d..aee95fbe9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -540,9 +540,9 @@ struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) void LP_butxo_swapfields_copy(struct LP_utxoinfo *destutxo,struct LP_utxoinfo *srcutxo) { - printf("LP_butxo_swapfields_copy\n"); + printf("LP_butxo_swapfields_copy %u <- %u\n",destutxo->T.swappending,srcutxo->T.swappending); destutxo->S = srcutxo->S; - destutxo->T.swappending = srcutxo->T.swappending; + destutxo->T = srcutxo->T; } void LP_butxo_swapfields(struct LP_utxoinfo *butxo) @@ -740,6 +740,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, autxo = &A; butxo = &B; LP_abutxo_set(autxo,butxo,&Q); + LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) @@ -755,7 +756,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else { n = LP_listunspent_issue(coin->symbol,Q.coinaddr); - printf("need to verify\n"); + //printf("need to verify\n"); } butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1,Q.desttxfee); Q.txid = butxo->payment.txid; From ba4e114b8fb9730a4f46d7e307ecb491c5844089 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 00:06:35 +0200 Subject: [PATCH 257/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_scan.c | 13 ++++++++----- iguana/exchanges/LP_swap.c | 2 +- iguana/exchanges/LP_transaction.c | 6 +++--- iguana/exchanges/LP_utxo.c | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 9ca3cdb5f..3e5eaff8e 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -298,7 +298,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee); struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr); int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson); -int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration); +int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 7d2bf6dda..2cf8bd599 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -436,9 +436,9 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) return(-1); } -int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration) +int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration) { - struct iguana_info *coin; struct LP_transaction *tx; cJSON *array,*item; uint32_t expiration,i,n; + struct iguana_info *coin; cJSON *array,*item; uint32_t expiration,i,n; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) { printf("LP_waitmempool missing coin.%p or inactive\n",coin); @@ -454,10 +454,13 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration } else { - if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height >= 0 ) + LP_listunspent_issue(coin->symbol,coinaddr); + struct LP_address_utxo *up; + if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) + //if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height > 0 ) { - char str[65]; printf("LP_waitmempool found confirmed %s %s\n",symbol,bits256_str(str,txid)); - return(tx->height); + char str[65]; printf("address_utxofind found confirmed %s %s ht.%d vs %d\n",symbol,bits256_str(str,txid),up->U.height,coin->height); + return(coin->height - up->U.height); } if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 ) { diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index bcfe946cd..dab03cc91 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -635,7 +635,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3 if ( suppress_swapsend == 0 ) { retval = LP_swapsend(pairsock,swap,msgbits,sendbuf,sendlen,nextbits,rawtx->I.crcs); - if ( LP_waitmempool(rawtx->coin->symbol,rawtx->I.destaddr,rawtx->I.signedtxid,LP_SWAPSTEP_TIMEOUT*10) < 0 ) + if ( LP_waitmempool(rawtx->coin->symbol,rawtx->I.destaddr,rawtx->I.signedtxid,0,LP_SWAPSTEP_TIMEOUT*10) < 0 ) { char str[65]; printf("failed to find %s %s %s in the mempool?\n",rawtx->name,rawtx->I.destaddr,bits256_str(str,rawtx->I.actualtxid)); retval = -1; diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 5153646c9..073c947a0 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1313,7 +1313,7 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da printf("%02x",swap->aliceclaim.txbytes[i]); printf(" <- aliceclaim\n"); //basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration); - return(LP_waitmempool(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,60)); + return(LP_waitmempool(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr); } printf("error with bobdeposit\n"); @@ -1331,7 +1331,7 @@ int32_t LP_verify_alicepayment(struct basilisk_swap *swap,uint8_t *data,int32_t if ( bits256_nonz(swap->alicepayment.I.signedtxid) != 0 ) swap->aliceunconf = 1; basilisk_dontforget_update(swap,&swap->alicepayment); - return(LP_waitmempool(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,60)); + return(LP_waitmempool(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,60)); //printf("import alicepayment address.(%s)\n",swap->alicepayment.p2shaddr); //LP_importaddress(swap->alicecoin.symbol,swap->alicepayment.p2shaddr); return(0); @@ -1378,7 +1378,7 @@ int32_t LP_verify_bobpayment(struct basilisk_swap *swap,uint8_t *data,int32_t da printf("%02x",swap->alicespend.txbytes[i]); printf(" <- alicespend\n\n");*/ swap->I.alicespent = 1; - return(LP_waitmempool(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,60)); + return(LP_waitmempool(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,60)); } else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->alicespend.I.suppress_pubkeys,swap->bobpayment.I.destaddr); } printf("error validating bobpayment\n"); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6a91957a7..af5db5094 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -565,7 +565,7 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int numconfirms = (LP_getheight(coin) - ht); else if ( mempool != 0 ) { - if (LP_waitmempool(symbol,coinaddr,txid,30) >= 0 ) + if (LP_waitmempool(symbol,coinaddr,txid,vout,30) >= 0 ) numconfirms = 0; } } From a7ee6eb61e9141ee564d132b1b5df8cba526fc53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 00:14:47 +0200 Subject: [PATCH 258/520] Test --- iguana/exchanges/LP_scan.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 2cf8bd599..14825a425 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -438,7 +438,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration) { - struct iguana_info *coin; cJSON *array,*item; uint32_t expiration,i,n; + struct iguana_info *coin; cJSON *array,*item; uint32_t expiration,i,n,numconfirms = -1; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) { printf("LP_waitmempool missing coin.%p or inactive\n",coin); @@ -454,14 +454,6 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int } else { - LP_listunspent_issue(coin->symbol,coinaddr); - struct LP_address_utxo *up; - if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) - //if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height > 0 ) - { - char str[65]; printf("address_utxofind found confirmed %s %s ht.%d vs %d\n",symbol,bits256_str(str,txid),up->U.height,coin->height); - return(coin->height - up->U.height); - } if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 ) { char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0)); @@ -472,20 +464,29 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int item = jitem(array,i); if ( bits256_cmp(txid,jbits256(item,"tx_hash")) == 0 ) { - free(array); char str[65]; printf("found %s %s in mempool\n",symbol,bits256_str(str,txid)); - return(0); + numconfirms = 0; + break; } } } free(array); } + LP_listunspent_issue(coin->symbol,coinaddr); + struct LP_address_utxo *up; + if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) + //if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height > 0 ) + { + char str[65]; printf("address_utxofind found confirmed %s %s ht.%d vs %d\n",symbol,bits256_str(str,txid),up->U.height,coin->height); + if ( coin->height >= up->U.height ) + numconfirms = (coin->height - up->U.height + 1); + } } - if ( time(NULL) > expiration ) + if ( time(NULL) > expiration || numconfirms >= 1 ) break; usleep(500000); } - return(-1); + return(numconfirms); } int32_t LP_mempool_vinscan(bits256 *spendtxidp,int32_t *spendvinp,char *symbol,char *coinaddr,bits256 searchtxid,int32_t searchvout,bits256 searchtxid2,int32_t searchvout2) From dbadf8ae1cfbcd1c0b1a484435c7f5da2a360b66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 08:27:57 +0200 Subject: [PATCH 259/520] Test --- iguana/exchanges/LP_commands.c | 4 +--- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_network.c | 8 ++++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index ae78f9a98..14ee2325d 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -446,10 +446,8 @@ dividends(coin, height, )\n\ { char *msg; memset(zero.bytes,0,sizeof(zero)); - if ( strcmp("connect",method) == 0 ) - printf("broadcast.(%s)\n",jprint(reqjson,0)); msg = jprint(reqjson,0); - //_LP_send(pubsock,msg,(int32_t)strlen(msg)+1,0); + printf("broadcast.(%s)\n",msg); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,msg); } retstr = clonestr("{\"result\":\"success\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ec4748f02..d75b4d901 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -269,12 +269,12 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { - while ( nonz < 1 && recvlen > 0 ) + while ( nonz < 100 && recvlen > 0 ) { memset(&pfd,0,sizeof(pfd)); pfd.fd = sock; pfd.events = NN_POLLIN; - if ( nn_poll(&pfd,1,10) != 1 ) + if ( nn_poll(&pfd,1,1) != 1 ) break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { @@ -677,7 +677,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu { if ( nn_bind(pubsock,bindaddr) >= 0 ) { - timeout = 10; + timeout = 1; nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); } else diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 02905f29a..6f453c9bc 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -57,7 +57,7 @@ int32_t LP_sockcheck(int32_t sock) struct nn_pollfd pfd; pfd.fd = sock; pfd.events = NN_POLLOUT; - if ( nn_poll(&pfd,1,10) > 0 ) + if ( nn_poll(&pfd,1,1) > 0 ) return(1); else return(-1); } @@ -87,7 +87,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) { - static uint32_t crcs[256]; static unsigned long dup,total; + static uint32_t crcs[8192]; static unsigned long dup,total; int32_t i; *duplicatep = 0; if ( ind < 0 ) @@ -565,7 +565,7 @@ char *LP_psock(char *myipaddr,int32_t ispaired) { if ( nn_bind(pullsock,pushaddr) >= 0 && nn_bind(pubsock,subaddr) >= 0 ) { - timeout = 10; + timeout = 1; nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); if ( ispaired != 0 ) @@ -703,7 +703,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char exit(-1); } } - timeout = 10; + timeout = 1; nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); //maxsize = 2 * 1024 * 1024; From 8e3172d1a8427738020057f092757c3a5d4bcf20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 08:33:11 +0200 Subject: [PATCH 260/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 14ee2325d..ce593eb77 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -447,7 +447,7 @@ dividends(coin, height, )\n\ char *msg; memset(zero.bytes,0,sizeof(zero)); msg = jprint(reqjson,0); - printf("broadcast.(%s)\n",msg); + //printf("broadcast.(%s)\n",msg); LP_broadcast_message(LP_mypubsock,base!=0?base:jstr(argjson,"coin"),rel,zero,msg); } retstr = clonestr("{\"result\":\"success\"}"); From 9a9e7ce40dcbdd7746e64ad1040146b853c6cc12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:05:20 +0200 Subject: [PATCH 261/520] Test --- iguana/exchanges/LP_bitcoin.c | 16 +- iguana/exchanges/LP_coins.c | 4 +- iguana/exchanges/LP_commands.c | 71 ++++---- iguana/exchanges/LP_include.h | 8 +- iguana/exchanges/LP_nativeDEX.c | 198 +++++---------------- iguana/exchanges/LP_ordermatch.c | 22 +-- iguana/exchanges/LP_peers.c | 15 +- iguana/exchanges/LP_portfolio.c | 6 +- iguana/exchanges/LP_prices.c | 30 ++-- iguana/exchanges/LP_rpc.c | 52 ++---- iguana/exchanges/LP_statemachine.c | 276 +++++++++++++++++++++++++++++ iguana/exchanges/LP_utxo.c | 24 ++- iguana/exchanges/LP_utxos.c | 274 +++++++++------------------- 13 files changed, 520 insertions(+), 476 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 67325c8dc..20cc5858f 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -325,14 +325,12 @@ enum opcodetype OP_INVALIDOPCODE = 0xff, }; -struct { bits256 privkey; uint8_t rmd160[20]; } LP_privkeys[100]; int32_t LP_numprivkeys; - bits256 LP_privkeyfind(uint8_t rmd160[20]) { int32_t i; static bits256 zero; - for (i=0; i no privkey\n"); @@ -345,13 +343,13 @@ int32_t LP_privkeyadd(bits256 privkey,uint8_t rmd160[20]) tmpkey = LP_privkeyfind(rmd160); if ( bits256_nonz(tmpkey) != 0 ) return(-bits256_cmp(privkey,tmpkey)); - LP_privkeys[LP_numprivkeys].privkey = privkey; - memcpy(LP_privkeys[LP_numprivkeys].rmd160,rmd160,20); + G.LP_privkeys[G.LP_numprivkeys].privkey = privkey; + memcpy(G.LP_privkeys[G.LP_numprivkeys].rmd160,rmd160,20); //int32_t i; for (i=0; i<20; i++) // printf("%02x",rmd160[i]); //char str[65]; printf(" -> add privkey.(%s)\n",bits256_str(str,privkey)); - LP_numprivkeys++; - return(LP_numprivkeys); + G.LP_numprivkeys++; + return(G.LP_numprivkeys); } int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 6ab37355c..6898e1ad3 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -176,9 +176,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) jaddstr(item,"coin",coin->symbol); if ( showwif != 0 ) { - bitcoin_priv2wif(coin->wiftaddr,wifstr,LP_mypriv25519,coin->wiftype); + bitcoin_priv2wif(coin->wiftaddr,wifstr,G.LP_mypriv25519,coin->wiftype); bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,wifstr); - if ( bits256_cmp(LP_mypriv25519,checkkey) == 0 ) + if ( bits256_cmp(G.LP_mypriv25519,checkkey) == 0 ) jaddstr(item,"wif",wifstr); else jaddstr(item,"wif","error creating wif"); } diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index ce593eb77..5eec41e3c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -25,16 +25,16 @@ char *LP_numutxos() { jaddstr(retjson,"ipaddr",LP_mypeer->ipaddr); jaddnum(retjson,"port",LP_mypeer->port); - jaddnum(retjson,"numutxos",LP_mypeer->numutxos); + //jaddnum(retjson,"numutxos",LP_mypeer->numutxos); jaddnum(retjson,"numpeers",LP_mypeer->numpeers); - jaddnum(retjson,"session",LP_sessionid); + jaddnum(retjson,"session",G.LP_sessionid); } else jaddstr(retjson,"error","client node"); return(jprint(retjson,1)); } char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { - char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,othernumutxos,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; + char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; //printf("stats_JSON(%s)\n",jprint(argjson,0)); method = jstr(argjson,"method"); if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) @@ -50,11 +50,11 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { if ( 0 && (otherpeers= jint(argjson,"numpeers")) > peer->numpeers ) peer->numpeers = otherpeers; - if ( 0 && (othernumutxos= jint(argjson,"numutxos")) > peer->numutxos ) + /*if ( 0 && (othernumutxos= jint(argjson,"numutxos")) > peer->numutxos ) { printf("change.(%s) numutxos.%d -> %d mynumutxos.%d\n",peer->ipaddr,peer->numutxos,othernumutxos,LP_mypeer != 0 ? LP_mypeer->numutxos:0); peer->numutxos = othernumutxos; - } + }*/ if ( peer->sessionid == 0 ) peer->sessionid = juint(argjson,"session"); //printf("peer.(%s) found (%d %d) (%d %d) (%s)\n",peer->ipaddr,peer->numpeers,peer->numutxos,otherpeers,othernumutxos,jprint(argjson,0)); @@ -76,7 +76,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { static char *laststr; char *newstr; bits256 pubkey = jbits256(argjson,"pubkey"); - if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,LP_mypub25519) == 0 ) + if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,G.LP_mypub25519) == 0 ) { newstr = jprint(argjson,0); if ( laststr == 0 || strcmp(laststr,newstr) != 0 ) @@ -112,6 +112,7 @@ getcoins()\n\ getcoin(coin)\n\ portfolio()\n\ getpeers()\n\ +passphrase(passphrase)\n\ listunspent(coin, address)\n\ orderbook(base, rel, duration=3600)\n\ getprices(base, rel)\n\ @@ -128,18 +129,18 @@ dividends(coin, height, )\n\ base = jstr(argjson,"base"); rel = jstr(argjson,"rel"); - if ( USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) + if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) { - if ( USERPASS_COUNTER == 0 ) + if ( G.USERPASS_COUNTER == 0 ) { - USERPASS_COUNTER = 1; + G.USERPASS_COUNTER = 1; retjson = cJSON_CreateObject(); - jaddstr(retjson,"userpass",USERPASS); - jaddbits256(retjson,"mypubkey",LP_mypub25519); + jaddstr(retjson,"userpass",G.USERPASS); + jaddbits256(retjson,"mypubkey",G.LP_mypub25519); jadd(retjson,"coins",LP_coinsjson(LP_showwif)); return(jprint(retjson,1)); } - if ( (userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,USERPASS) != 0 ) + if ( (userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,G.USERPASS) != 0 ) return(clonestr("{\"error\":\"authentication error\"}")); jdelete(argjson,"userpass"); if ( strcmp(method,"sendmessage") == 0 ) @@ -162,6 +163,12 @@ dividends(coin, height, )\n\ LP_deletemessages(jint(argjson,"firsti"),jint(argjson,"num")); return(clonestr("{\"result\":\"success\"}")); } + else if ( strcmp(method,"passphrase") == 0 ) + { + if ( LP_passphrase_init(jstr(argjson,"passphrase")) < 0 ) + return(clonestr("{\"error\":\"couldnt change passphrase\"}")); + else return(clonestr("{\"result\":\"success\"}")); + } else if ( strcmp(method,"portfolio") == 0 ) { return(LP_portfolio()); @@ -212,28 +219,6 @@ dividends(coin, height, )\n\ return(jprint(retjson,1)); } else return(clonestr("{\"error\":\"no price set\"}")); } - /*else if ( strcmp(method,"ordermatch") == 0 ) - { - if ( price > SMALLVAL ) - return(LP_ordermatch(base,j64bits(argjson,"txfee"),price,jdouble(argjson,"relvolume"),rel,jbits256(argjson,"txid"),jint(argjson,"vout"),jbits256(argjson,"feetxid"),jint(argjson,"feevout"),j64bits(argjson,"desttxfee"),jint(argjson,"duration"))); - else return(clonestr("{\"error\":\"no price set\"}")); - } - else if ( strcmp(method,"trade") == 0 ) - { - struct LP_quoteinfo Q; - if ( price > SMALLVAL || jobj(argjson,"quote") != 0 ) - { - LP_quoteparse(&Q,jobj(argjson,"quote")); - return(LP_trade(ctx,myipaddr,pubsock,&Q,price,jint(argjson,"timeout"),jint(argjson,"duration"))); - } else return(clonestr("{\"error\":\"no price set or no quote object\"}")); - } - else if ( strcmp(method,"autotrade") == 0 ) - { - if ( price > SMALLVAL ) - { - return(LP_autotrade(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"))); - } else return(clonestr("{\"error\":\"no price set\"}")); - }*/ else if ( strcmp(method,"buy") == 0 ) { if ( price > SMALLVAL ) @@ -305,14 +290,14 @@ dividends(coin, height, )\n\ { //privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,ptr,"",USERPASS_WIFSTR); //LP_utxopurge(0); - if ( bits256_nonz(LP_mypriv25519) != 0 ) - LP_privkey_init(-1,ptr,LP_mypriv25519,LP_mypub25519); + if ( bits256_nonz(G.LP_mypriv25519) != 0 ) + LP_privkey_init(-1,ptr,G.LP_mypriv25519,G.LP_mypub25519); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddstr(retjson,"coin",coin); jaddnum(retjson,"timestamp",time(NULL)); - jadd(retjson,"alice",LP_inventory(coin,0)); - jadd(retjson,"bob",LP_inventory(coin,1)); + jadd(retjson,"alice",LP_inventory(coin)); + //jadd(retjson,"bob",LP_inventory(coin,1)); return(jprint(retjson,1)); } } @@ -466,7 +451,17 @@ dividends(coin, height, )\n\ else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); } else if ( strcmp(method,"notify") == 0 ) + { + char *rmd160str,str[65]; bits256 pub; struct LP_pubkeyinfo *pubp; + pub = jbits256(argjson,"pub"); + if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) + { + if ( (pubp= LP_pubkeyadd(pub)) != 0 ) + decode_hex(pubp->rmd160,20,rmd160str); + printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); + } retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); + } } else { diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 3e5eaff8e..f89011c73 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -75,8 +75,8 @@ #define DEX_SLEEP 3 #define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2)) -extern char GLOBAL_DBDIR[],USERPASS[],USERPASS_WIFSTR[]; -extern int32_t IAMLP,USERPASS_COUNTER; +extern char GLOBAL_DBDIR[]; +extern int32_t IAMLP; struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*userdata,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,userdatalen,spendlen; }; @@ -235,7 +235,7 @@ struct LP_peerinfo { UT_hash_handle hh; uint64_t ip_port; - uint32_t ipbits,errortime,errors,numpeers,numutxos,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; + uint32_t ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; int32_t pushsock,subsock; uint16_t port; char ipaddr[64]; @@ -290,7 +290,7 @@ void LP_availableset(struct LP_utxoinfo *utxo); int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2); int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock); uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); -void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); +//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); int32_t LP_coinbus(uint16_t coin_busport); struct iguana_info *LP_coinfind(char *symbol); int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d75b4d901..22229e365 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -33,7 +33,6 @@ portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex; int32_t LP_canbind; char *Broadcaststr; -struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; struct LP_peerinfo *LP_peerinfos,*LP_mypeer; struct LP_forwardinfo *LP_forwardinfos; struct iguana_info *LP_coins; @@ -41,7 +40,7 @@ struct iguana_info *LP_coins; char *activecoins[] = { "BTC", "KMD" }; char GLOBAL_DBDIR[] = { "DB" }; -char USERPASS[65],USERPASS_WIFSTR[64],LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; +char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", };//"5.9.253.204" }; // @@ -51,11 +50,22 @@ uint16_t LP_fixed_pairport,LP_publicport; int32_t LP_mybussock = -1; int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; -int32_t LP_pendingswaps,LP_showwif,USERPASS_COUNTER,IAMLP = 0; -uint32_t LP_sessionid; +int32_t LP_showwif,IAMLP = 0; double LP_profitratio = 1.; -bits256 LP_mypub25519,LP_mypriv25519; -uint8_t LP_myrmd160[20]; + + +struct LP_privkey { bits256 privkey; uint8_t rmd160[20]; }; + +struct LP_globals +{ + struct LP_utxoinfo *LP_utxoinfos,*LP_utxoinfos2; + bits256 LP_mypub25519,LP_mypriv25519; + uint8_t LP_myrmd160[20]; + uint32_t LP_sessionid,counter; + int32_t LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting; + char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41]; + struct LP_privkey LP_privkeys[100]; +} G; // stubs @@ -124,7 +134,7 @@ char *LP_decrypt(uint8_t *ptr,int32_t *recvlenp) cipherlen = recvlen - (2 + crypto_box_NONCEBYTES); if ( cipherlen > 0 && cipherlen <= sizeof(decoded) ) { - if ( (jsonstr= (char *)_SuperNET_decipher(nonce,cipher,decoded,cipherlen,GENESIS_PUBKEY,LP_mypriv25519)) != 0 ) + if ( (jsonstr= (char *)_SuperNET_decipher(nonce,cipher,decoded,cipherlen,GENESIS_PUBKEY,G.LP_mypriv25519)) != 0 ) { recvlen = (cipherlen - crypto_box_ZEROBYTES); if ( strlen(jsonstr)+1 != recvlen ) @@ -151,7 +161,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, dup++; else uniq++; if ( (rand() % 1000) == 0 ) - printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x U.%d\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff,LP_mypeer != 0 ? LP_mypeer->numutxos : -1); + printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff); if ( duplicate == 0 ) { if ( i >= 0 ) @@ -217,53 +227,6 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, return(retstr); } -void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo) -{ - struct _LP_utxoinfo u; struct iguana_info *coin; char str[65]; uint32_t now = (uint32_t)time(NULL); - if ( IAMLP != 0 && (coin= LP_coinfind(utxo->coin)) != 0 && coin->inactive != 0 ) - return; - //printf("%s lag.%d\n",bits256_str(str,utxo->txid),now-utxo->lastspentcheck); - if ( utxo->T.spentflag == 0 && now > utxo->T.lastspentcheck+60 ) - { - u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; - utxo->T.lastspentcheck = now; - if ( LP_txvalue(0,utxo->coin,utxo->payment.txid,utxo->payment.vout) == 0 ) - { - printf("txid.%s %s/v%d %.8f has been spent\n",utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout,dstr(utxo->payment.value)); - LP_spentnotify(utxo,0); - } - else if ( LP_txvalue(0,utxo->coin,u.txid,u.vout) == 0 ) - { - printf("txid2.%s %s/v%d %.8f has been spent\n",utxo->coin,bits256_str(str,u.txid),u.vout,dstr(u.value)); - LP_spentnotify(utxo,1); - } - } -} - -void LP_myutxo_updates(void *ctx,int32_t pubsock,char *passphrase) -{ - //LP_utxopurge(0); not good to disrupt existing pointers - LP_privkey_updates(ctx,pubsock,passphrase,0); -} - -int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,int32_t interval,int32_t maxentries) -{ - int32_t lastn,n = -1; - if ( peer->lastutxos < now-interval ) - { - //lastn = peer->numutxos - mypeer->numutxos + LP_PROPAGATION_SLACK; - //if ( lastn < LP_PROPAGATION_SLACK * 2 ) - lastn = LP_PROPAGATION_SLACK * 2; - if ( mypeer == 0 || strcmp(peer->ipaddr,mypeer->ipaddr) != 0 ) - { - peer->lastutxos = now; - //printf("query utxos from %s\n",peer->ipaddr); - n = LP_utxosquery(mypeer,pubsock,peer->ipaddr,peer->port,"",lastn,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,maxentries); - } - } //else printf("LP_peer_utxosquery skip.(%s) %u\n",peer->ipaddr,peer->lastutxos); - return(n); -} - int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr) { int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char *retstr,*str; struct nn_pollfd pfd; @@ -307,7 +270,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int void command_rpcloop(void *myipaddr) { - int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; void *ctx; //struct iguana_info *coin,*ctmp; + int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; void *ctx; ctx = bitcoin_ctx(); if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; @@ -345,19 +308,16 @@ void command_rpcloop(void *myipaddr) } } -int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport,char *passphrase) +int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { - int32_t enable_utxos = 0; - static uint32_t counter,numpeers,lastresync; //lastforward - struct LP_utxoinfo *utxo,*utmp; cJSON *retjson; struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp,*mostpeer; uint32_t id,now; int32_t mostutxos,nonz = 0,n=0,num,lastn=-1; + static uint32_t counter,numpeers; + struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0; now = (uint32_t)time(NULL); if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; if ( mypeer == 0 ) myipaddr = "127.0.0.1"; numpeers = LP_numpeers(); - mostutxos = 0; - mostpeer = 0; HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( peer->errors >= LP_MAXPEER_ERRORS ) @@ -372,112 +332,35 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) ) { - //if ( IAMLP != 0 ) - // printf("numpeers.%d updatepeer.%s lag.%d\n",numpeers,peer->ipaddr,now-peer->lastpeers); peer->lastpeers = now; - //if ( IAMLP != 0 && peer->numpeers != numpeers ) - // printf("%s num.%d vs %d\n",peer->ipaddr,peer->numpeers,numpeers); if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); - LP_peer_pricesquery(peer->ipaddr,peer->port); - } - if ( enable_utxos && IAMLP != 0 && LP_mypeer != 0 && strcmp(peer->ipaddr,myipaddr) != 0 ) - { - if ( (retstr= issue_LP_numutxos(peer->ipaddr,peer->port,LP_mypeer->ipaddr,LP_mypeer->port,LP_mypeer->numpeers,LP_mypeer->numutxos)) != 0 ) + LP_peer_pricesquery(peer); + if ( peer->needping != 0 ) { - //printf("%d <- (%s)\n",peer->numutxos,retstr); - if ( (retjson= cJSON_Parse(retstr)) != 0 ) - { - if ( (num= jint(retjson,"numutxos")) > peer->numutxos ) - peer->numutxos = num; - if ( (num= jint(retjson,"numpeers")) > peer->numpeers ) - peer->numpeers = num; - if ( (id= juint(retjson,"session")) != 0 ) - peer->sessionid = id; - free_json(retjson); - } - free(retstr); - retstr = 0; + if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) + free(retstr); + peer->needping = 0; } } } if ( peer->diduquery == 0 ) { - if ( enable_utxos && (lastn != n || n < 20) ) - { - lastn = n; - n = LP_peer_utxosquery(mypeer,myport,pubsock,peer,now,60,100); - } - LP_peer_pricesquery(peer->ipaddr,peer->port); + LP_peer_pricesquery(peer); peer->diduquery = now; } - if ( peer->numutxos > mostutxos ) - { - mostutxos = peer->numutxos; - mostpeer = peer; - } - } - //printf("numutxos vs mine.%d\n",LP_mypeer != 0 ? LP_mypeer->numutxos : -1); - if ( enable_utxos && LP_mypeer != 0 && mostpeer != 0 && ((LP_mypeer->numutxos < mostutxos && time(NULL) > lastresync+10) || time(NULL) > lastresync+60) ) - { - //printf("myutxos.%d most.%d %s\n",LP_mypeer->numutxos,mostutxos,mostpeer->ipaddr); - LP_peer_utxosquery(LP_mypeer,myport,pubsock,mostpeer,now,60,(mostutxos-LP_mypeer->numutxos) * 2); - lastresync = (uint32_t)time(NULL); - //LP_peer_pricesquery(mostpeer->ipaddr,mostpeer->port); } if ( (counter % 6000) == 10 ) { - LP_myutxo_updates(ctx,pubsock,passphrase); - if ( enable_utxos ) - { - HASH_ITER(hh,LP_utxoinfos[0],utxo,utmp) - { - LP_utxo_spentcheck(pubsock,utxo); - } - HASH_ITER(hh,LP_utxoinfos[1],utxo,utmp) - { - LP_utxo_spentcheck(pubsock,utxo); - if ( LP_isunspent(utxo) > 0 && utxo->T.lasttime == 0 && LP_ismine(utxo) > 0 ) - { - char str[65]; printf("publish mybob %s\n",bits256_str(str,utxo->payment.txid)); - LP_utxo_clientpublish(utxo); - } - } - } + LP_privkey_updates(ctx,pubsock,0); } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height; bits256 zero; struct LP_address *ap,*atmp; struct LP_address_utxo *up,*utmp; + int32_t height; bits256 zero; //struct LP_address *ap,*atmp; struct LP_address_utxo *up,*utmp; //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( coin->inactive != 0 ) continue; - if ( time(NULL) > coin->lastmonitor+60 ) - { - //portable_mutex_lock(&coin->addrmutex); - HASH_ITER(hh,coin->addresses,ap,atmp) - { - if ( coin->electrum == 0 ) - { - LP_listunspent_issue(coin->symbol,ap->coinaddr); - DL_FOREACH_SAFE(ap->utxos,up,utmp) - { - if ( up->spendheight <= 0 ) - { - if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) - up->spendheight = 1; - } - } - } - else if ( 0 ) - { - if ( (retjson= electrum_address_listunspent(coin->symbol,coin->electrum,&retjson,ap->coinaddr)) != 0 ) - free_json(retjson); - } - } - //portable_mutex_unlock(&coin->addrmutex); - coin->lastmonitor = (uint32_t)time(NULL); - } if ( coin->electrum != 0 ) continue; memset(zero.bytes,0,sizeof(zero)); @@ -533,7 +416,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int return(nonz); } -void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins,char *passphrase) +void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) { int32_t i,n; cJSON *item; for (i=0; i /tmp/myipaddr") == 0 ) { if ( (myipaddr= OS_filestr(&filesize,"/tmp/myipaddr")) != 0 && myipaddr[0] != 0 ) @@ -700,7 +580,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //LP_deadman_switch = (uint32_t)time(NULL); printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); printf("initcoins\n"); - LP_initcoins(ctx,pubsock,jobj(argjson,"coins"),passphrase); + LP_initcoins(ctx,pubsock,jobj(argjson,"coins")); + LP_passphrase_init(passphrase); if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 ) { printf("error launching LP_psockloop for (%s)\n",myipaddr); @@ -732,11 +613,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu while ( 1 ) { nonz = 0; - //fprintf(stderr,"."); - if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) != 0 ) + G.waiting = 1; + while ( G.initializing != 0 ) + { + fprintf(stderr,"."); + sleep(3); + } + if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; - //if ( LP_mypullsock >= 0 ) - // nonz += LP_sock_check("SUB",ctx,myipaddr,-1,LP_mypullsock,"127.0.0.1"); if ( nonz == 0 ) usleep(1000000 / MAINLOOP_PERSEC); } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index aee95fbe9..e1ce01255 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -215,7 +215,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re { bits256 zero; char *msg; cJSON *reqjson = cJSON_CreateObject(); memset(zero.bytes,0,sizeof(zero)); - jaddbits256(reqjson,"pubkey",LP_mypub25519); + jaddbits256(reqjson,"pubkey",G.LP_mypub25519); jaddstr(reqjson,"base",base); jaddstr(reqjson,"rel",rel); jaddnum(reqjson,"price",price); @@ -611,7 +611,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ return(-1); } privkey = LP_privkey(utxo->coinaddr,coin->taddr); - if ( bits256_nonz(privkey) != 0 && bits256_cmp(LP_mypub25519,qp->srchash) == 0 ) //qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && + if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 ) //qp->quotetime >= qp->timestamp-3 && qp->quotetime <= utxo->T.swappending && { if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 ) { @@ -638,7 +638,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ } else { - printf("dest %.8f vs required %.8f (%d %d %d %d %d)\n",dstr(qp->destsatoshis),dstr(price*(utxo->S.satoshis-qp->txfee)),bits256_nonz(privkey) != 0 ,qp->timestamp == utxo->T.swappending-LP_RESERVETIME,qp->quotetime >= qp->timestamp-3,qp->quotetime < utxo->T.swappending,bits256_cmp(LP_mypub25519,qp->srchash) == 0); + printf("dest %.8f vs required %.8f (%d %d %d %d %d)\n",dstr(qp->destsatoshis),dstr(price*(utxo->S.satoshis-qp->txfee)),bits256_nonz(privkey) != 0 ,qp->timestamp == utxo->T.swappending-LP_RESERVETIME,qp->quotetime >= qp->timestamp-3,qp->quotetime < utxo->T.swappending,bits256_cmp(G.LP_mypub25519,qp->srchash) == 0); } if ( retval < 0 ) { @@ -655,7 +655,7 @@ char *LP_connectedalice(cJSON *argjson) // alice cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); - if ( bits256_cmp(Q.desthash,LP_mypub25519) != 0 ) + if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) return(clonestr("{\"result\",\"update stats\"}")); printf("CONNECTED.(%s)\n",jprint(argjson,0)); autxo = &A; @@ -664,7 +664,7 @@ char *LP_connectedalice(cJSON *argjson) // alice if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); - LP_pendingswaps--; + G.LP_pendingswaps--; printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); } @@ -672,7 +672,7 @@ char *LP_connectedalice(cJSON *argjson) // alice { printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask); LP_availableset(autxo); - LP_pendingswaps--; + G.LP_pendingswaps--; return(clonestr("{\"error\":\"no price set\"}")); } // SPV validate bobs @@ -680,7 +680,7 @@ char *LP_connectedalice(cJSON *argjson) // alice price = bid; if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) { - LP_pendingswaps--; + G.LP_pendingswaps--; return(clonestr("{\"error\":\"cant get alicecoin\"}")); } Q.privkey = LP_privkey(Q.destaddr,coin->taddr); @@ -711,7 +711,7 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("connected result.(%s)\n",jprint(retjson,0)); if ( jobj(retjson,"error") != 0 ) LP_availableset(autxo); - else LP_pendingswaps++; + else G.LP_pendingswaps++; return(jprint(retjson,1)); } else @@ -729,7 +729,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { printf("LP_tradecommand: check received %s\n",method); retval = 1; - if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(LP_mypub25519,Q.srchash) == 0 && bits256_cmp(LP_mypub25519,Q.desthash) != 0 ) + if ( LP_quoteparse(&Q,argjson) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0 ) { if ( (coin= LP_coinfind(Q.srccoin)) == 0 || (price= LP_myprice(&bid,&ask,Q.srccoin,Q.destcoin)) <= SMALLVAL || ask <= SMALLVAL ) { @@ -920,7 +920,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr { printf("%s\n",jprint(item,0)); pubkey = jbits256(item,"pubkey"); - if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) + if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); if ( basecoin->electrum != 0 ) @@ -994,7 +994,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel } if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,LP_mypub25519,autxo->coinaddr) < 0 ) + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 ) return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) { diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index e249f099a..5c7efb7e7 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -35,9 +35,9 @@ cJSON *LP_peerjson(struct LP_peerinfo *peer) jaddnum(item,"port",peer->port); if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 ) { - jaddnum(item,"session",LP_sessionid); - if ( LP_mypeer != 0 ) - jaddnum(item,"numutxos",LP_mypeer->numutxos); + jaddnum(item,"session",G.LP_sessionid); + //if ( LP_mypeer != 0 ) + // jaddnum(item,"numutxos",LP_mypeer->numutxos); } else jaddnum(item,"session",peer->sessionid); //jaddnum(item,"profit",peer->profitmargin); return(item); @@ -79,7 +79,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char { peer = calloc(1,sizeof(*peer)); if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 ) - peer->sessionid = LP_sessionid; + peer->sessionid = G.LP_sessionid; else peer->sessionid = sessionid; peer->pushsock = peer->subsock = pushsock = subsock = -1; strcpy(peer->ipaddr,ipaddr); @@ -217,9 +217,9 @@ int32_t LP_peersparse(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipa void LP_peersquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *myipaddr,uint16_t myport) { - char *retstr; struct LP_peerinfo *peer,*tmp; uint32_t now,flag = 0; + char *retstr; struct LP_peerinfo *peer,*tmp; bits256 zero; uint32_t now,flag = 0; peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); - if ( (retstr= issue_LP_getpeers(destipaddr,destport,myipaddr,myport,mypeer!=0?mypeer->numpeers:0,mypeer!=0?mypeer->numutxos:0)) != 0 ) + if ( (retstr= issue_LP_getpeers(destipaddr,destport,myipaddr,myport,mypeer!=0?mypeer->numpeers:0)) != 0 ) { //printf("got.(%s)\n",retstr); now = (uint32_t)time(NULL); @@ -233,7 +233,8 @@ void LP_peersquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr { printf("{%s:%u}.%d ",peer->ipaddr,peer->port,peer->lasttime - now); flag++; - if ( (retstr= issue_LP_notify(destipaddr,destport,peer->ipaddr,peer->port,peer->numpeers,0,peer->sessionid)) != 0 ) + memset(&zero,0,sizeof(zero)); + if ( (retstr= issue_LP_notify(destipaddr,destport,peer->ipaddr,peer->port,peer->numpeers,peer->sessionid,0,zero)) != 0 ) free(retstr); } } diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 018f293da..585f236f1 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -63,7 +63,7 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr) } free_json(array); } - if ( (array= LP_inventory(symbol,iambob)) != 0 ) + if ( (array= LP_inventory(symbol)) != 0 ) { if ( (n= cJSON_GetArraySize(array)) > 0 && is_cJSON_Array(array) != 0 ) { @@ -93,7 +93,7 @@ char *LP_portfolio() continue; if ( iter == 0 ) { - LP_privkey_init(-1,coin,LP_mypriv25519,LP_mypub25519); + LP_privkey_init(-1,coin,G.LP_mypriv25519,G.LP_mypub25519); coin->balanceA = LP_balance(&coin->valuesumA,0,coin->symbol,coin->smartaddr); coin->balanceB = LP_balance(&coin->valuesumB,1,coin->symbol,coin->smartaddr); if ( strcmp(coin->symbol,"KMD") != 0 ) @@ -427,7 +427,7 @@ int32_t LP_portfolio_trade(void *ctx,uint32_t *requestidp,uint32_t *quoteidp,str strcpy(LP_portfolio_rel,""); LP_portfolio_relvolume = 0.; } - printf("pending.%d base buy.%s, rel sell.%s relvolume %f maxprice %.8f (%.8f %.8f)\n",LP_pendingswaps,buy->symbol,sell->symbol,sell->relvolume,maxprice,bid,ask); + printf("pending.%d base buy.%s, rel sell.%s relvolume %f maxprice %.8f (%.8f %.8f)\n",G.LP_pendingswaps,buy->symbol,sell->symbol,sell->relvolume,maxprice,bid,ask); if ( LP_pricevalid(maxprice) > 0 ) { relvolume = sell->relvolume; diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index b10faa211..2889e2a76 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -143,8 +143,8 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) portable_mutex_lock(&LP_pubkeymutex); pubp = calloc(1,sizeof(*pubp)); pubp->pubkey = pubkey; - if ( bits256_cmp(LP_mypub25519,pubkey) == 0 ) - memcpy(pubp->rmd160,LP_myrmd160,sizeof(pubp->rmd160)); + if ( bits256_cmp(G.LP_mypub25519,pubkey) == 0 ) + memcpy(pubp->rmd160,G.LP_myrmd160,sizeof(pubp->rmd160)); HASH_ADD_KEYPTR(hh,LP_pubkeyinfos,&pubp->pubkey,sizeof(pubp->pubkey),pubp); portable_mutex_unlock(&LP_pubkeymutex); if ( (pubp= LP_pubkeyfind(pubkey)) == 0 ) @@ -213,10 +213,10 @@ char *LP_prices() return(jprint(array,1)); } -void LP_prices_parse(cJSON *obj) +void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) { static uint8_t zeroes[20]; - struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid; char *base,*rel,*hexstr; double askprice; uint32_t now; + struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr; double askprice; uint32_t now; now = (uint32_t)time(NULL); pubkey = jbits256(obj,"pubkey"); if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) @@ -224,7 +224,12 @@ void LP_prices_parse(cJSON *obj) if ( (hexstr= jstr(obj,"rmd160")) != 0 && strlen(hexstr) == 2*sizeof(rmd160) ) { decode_hex(rmd160,sizeof(rmd160),hexstr); - if ( memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 && memcmp(pubp->rmd160,rmd160,sizeof(rmd160)) != 0 ) + if ( memcmp(pubp->rmd160,rmd160,sizeof(rmd160)) != 0 ) + mismatch = 1; + else mismatch = 0; + if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 ) + peer->needping = 0; + if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) { for (i=0; i<20; i++) printf("%02x",pubp->rmd160[i]); @@ -263,22 +268,27 @@ void LP_prices_parse(cJSON *obj) } } -void LP_peer_pricesquery(char *destipaddr,uint16_t destport) +void LP_peer_pricesquery(struct LP_peerinfo *peer) { char *retstr; cJSON *array; int32_t i,n; - if ( (retstr= issue_LP_getprices(destipaddr,destport)) != 0 ) + peer->needping = (uint32_t)time(NULL); + if ( (retstr= issue_LP_getprices(peer->ipaddr,peer->port)) != 0 ) { if ( (array= cJSON_Parse(retstr)) != 0 ) { if ( is_cJSON_Array(array) && (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; ineedping != 0 ) + { + printf("%s needs ping\n",peer->ipaddr); + } } double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,int32_t vout) @@ -387,7 +397,7 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) basepp->myprices[relpp->ind] = price; // ask //printf("LP_mypriceset base.%s rel.%s <- price %.8f\n",base,rel,price); //relpp->myprices[basepp->ind] = (1. / price); // bid - if ( (pubp= LP_pubkeyadd(LP_mypub25519)) != 0 ) + if ( (pubp= LP_pubkeyadd(G.LP_mypub25519)) != 0 ) { pubp->matrix[basepp->ind][relpp->ind] = price; //pubp->matrix[relpp->ind][basepp->ind] = (1. / price); @@ -750,7 +760,7 @@ char *LP_pricestr(char *base,char *rel,double origprice) retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddstr(retjson,"method","postprice"); - jaddbits256(retjson,"pubkey",LP_mypub25519); + jaddbits256(retjson,"pubkey",G.LP_mypub25519); jaddstr(retjson,"base",base); jaddstr(retjson,"rel",rel); jaddnum(retjson,"price",price); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b5725f181..5555f9767 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -48,54 +48,26 @@ char *LP_isitme(char *destip,uint16_t destport) } else return(0); } -char *issue_LP_getpeers(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) +char *issue_LP_getpeers(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers) { char url[512],*retstr; - sprintf(url,"http://%s:%u/api/stats/getpeers?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,ipaddr,port,numpeers,numutxos); + sprintf(url,"http://%s:%u/api/stats/getpeers?ipaddr=%s&port=%u&numpeers=%d",destip,destport,ipaddr,port,numpeers); retstr = LP_issue_curl("getpeers",destip,port,url); //printf("%s -> getpeers.(%s)\n",destip,retstr); return(retstr); } -char *issue_LP_numutxos(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) +char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,uint32_t sessionid,char *rmd160str,bits256 pub) { - char url[512],*retstr; - printf("deprecated issue_LP_numutxos\n"); - return(0); - sprintf(url,"http://%s:%u/api/stats/numutxos?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,ipaddr,port,numpeers,numutxos); - retstr = LP_issue_curl("numutxos",destip,port,url); - //printf("%s -> getpeers.(%s)\n",destip,retstr); - return(retstr); -} - -char *issue_LP_getutxos(char *destip,uint16_t destport,char *coin,int32_t lastn,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) -{ - char url[512]; - printf("deprecated issue_LP_getutxos\n"); - return(0); - sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,coin,lastn,ipaddr,port,numpeers,numutxos); - return(LP_issue_curl("getutxos",destip,destport,url)); - //return(issue_curlt(url,LP_HTTP_TIMEOUT)); -} - -char *issue_LP_clientgetutxos(char *destip,uint16_t destport,char *coin,int32_t lastn) -{ - char url[512];//,*retstr; - printf("deprecated issue_LP_clientgetutxos\n"); - return(0); - sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=127.0.0.1&port=0",destip,destport,coin,lastn); - return(LP_issue_curl("clientgetutxos",destip,destport,url)); - //retstr = issue_curlt(url,LP_HTTP_TIMEOUT); - //printf("%s clientgetutxos.(%s)\n",url,retstr); - //return(retstr); -} - -char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos,uint32_t sessionid) -{ - char url[512],*retstr; + char url[512],*retstr,str[65]; if ( (retstr= LP_isitme(destip,destport)) != 0 ) return(retstr); - sprintf(url,"http://%s:%u/api/stats/notify?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d&session=%u",destip,destport,ipaddr,port,numpeers,numutxos,sessionid); + sprintf(url,"http://%s:%u/api/stats/notify?ipaddr=%s&port=%u&numpeers=%d&session=%u",destip,destport,ipaddr,port,numpeers,sessionid); + if ( rmd160str != 0 && bits256_nonz(pub) != 0 ) + { + sprintf(url+strlen(url),"&rmd160=%s&pub=%s",rmd160str,bits256_str(str,pub)); + printf("SEND (%s)\n",url); + } return(LP_issue_curl("notify",destip,destport,url)); //return(issue_curlt(url,LP_HTTP_TIMEOUT)); } @@ -306,7 +278,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else printf("non-hex tx.(%s)\n",hexstr); free(hexstr); return(cJSON_Parse("{\"error\":\"non hex transaction\"}")); - } else printf("failed blockchain.transaction.get %s\n",buf); + } else printf("failed blockchain.transaction.get %s %s\n",coin->symbol,buf); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); } } @@ -441,7 +413,7 @@ cJSON *LP_validateaddress(char *symbol,char *address) strcat(script,"88ac"); jaddstr(retjson,"scriptPubKey",script); } - bitcoin_address(coinaddr,coin->taddr,coin->pubtype,LP_myrmd160,20); + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,20); if ( strcmp(address,coinaddr) == 0 ) jadd(retjson,"ismine",cJSON_CreateTrue()); jadd(retjson,"iswatchonly",cJSON_CreateFalse()); diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index e22ca255f..5294b71f2 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1473,6 +1473,282 @@ if ( (array= LP_tradecandidates(base)) != 0 ) printf("metrics, best %f\n",bestmetric); */ +int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,int32_t maxentries) +{ + char *retstr; struct LP_peerinfo *peer; uint32_t now; int32_t retval = -1; + printf("deprecated LP_utxosquery\n"); + return(-1); + peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); + if ( coin == 0 ) + coin = ""; + //printf("utxo query.(%s)\n",destipaddr); + if ( IAMLP != 0 ) + retstr = issue_LP_getutxos(destipaddr,destport,coin,lastn,myipaddr,myport,mypeer != 0 ? mypeer->numpeers : 0,maxentries); + else retstr = issue_LP_clientgetutxos(destipaddr,destport,coin,maxentries); + if ( retstr != 0 ) + { + now = (uint32_t)time(NULL); + retval = LP_utxosparse(destipaddr,destport,retstr,now); + //printf("got.(%s)\n",retstr); + free(retstr); + } + return(retval); +} + +char *issue_LP_numutxos(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) +{ + char url[512],*retstr; + printf("deprecated issue_LP_numutxos\n"); + return(0); + sprintf(url,"http://%s:%u/api/stats/numutxos?ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,ipaddr,port,numpeers,numutxos); + retstr = LP_issue_curl("numutxos",destip,port,url); + //printf("%s -> getpeers.(%s)\n",destip,retstr); + return(retstr); +} + +char *issue_LP_getutxos(char *destip,uint16_t destport,char *coin,int32_t lastn,char *ipaddr,uint16_t port,int32_t numpeers,int32_t numutxos) +{ + char url[512]; + printf("deprecated issue_LP_getutxos\n"); + return(0); + sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=%s&port=%u&numpeers=%d&numutxos=%d",destip,destport,coin,lastn,ipaddr,port,numpeers,numutxos); + return(LP_issue_curl("getutxos",destip,destport,url)); + //return(issue_curlt(url,LP_HTTP_TIMEOUT)); +} + +char *issue_LP_clientgetutxos(char *destip,uint16_t destport,char *coin,int32_t lastn) +{ + char url[512];//,*retstr; + printf("deprecated issue_LP_clientgetutxos\n"); + return(0); + sprintf(url,"http://%s:%u/api/stats/getutxos?coin=%s&lastn=%d&ipaddr=127.0.0.1&port=0",destip,destport,coin,lastn); + return(LP_issue_curl("clientgetutxos",destip,destport,url)); + //retstr = issue_curlt(url,LP_HTTP_TIMEOUT); + //printf("%s clientgetutxos.(%s)\n",url,retstr); + //return(retstr); +} +/*else if ( strcmp(method,"ordermatch") == 0 ) + { + if ( price > SMALLVAL ) + return(LP_ordermatch(base,j64bits(argjson,"txfee"),price,jdouble(argjson,"relvolume"),rel,jbits256(argjson,"txid"),jint(argjson,"vout"),jbits256(argjson,"feetxid"),jint(argjson,"feevout"),j64bits(argjson,"desttxfee"),jint(argjson,"duration"))); + else return(clonestr("{\"error\":\"no price set\"}")); + } + else if ( strcmp(method,"trade") == 0 ) + { + struct LP_quoteinfo Q; + if ( price > SMALLVAL || jobj(argjson,"quote") != 0 ) + { + LP_quoteparse(&Q,jobj(argjson,"quote")); + return(LP_trade(ctx,myipaddr,pubsock,&Q,price,jint(argjson,"timeout"),jint(argjson,"duration"))); + } else return(clonestr("{\"error\":\"no price set or no quote object\"}")); + } + else if ( strcmp(method,"autotrade") == 0 ) + { + if ( price > SMALLVAL ) + { + return(LP_autotrade(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"))); + } else return(clonestr("{\"error\":\"no price set\"}")); + }*/ +int32_t LP_utxopurge(int32_t allutxos) +{ + char str[65]; struct LP_utxoinfo *utxo,*tmp; int32_t iambob,n = 0; + printf("LP_utxopurge mypub.(%s)\n",bits256_str(str,LP_mypub25519)); + portable_mutex_lock(&LP_utxomutex); + for (iambob=0; iambob<=1; iambob++) + { + HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) + { + if ( LP_isavailable(utxo) > 0 ) + { + if ( allutxos != 0 || LP_ismine(utxo) > 0 ) + { + printf("iambob.%d delete.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); + HASH_DELETE(hh,LP_utxoinfos[iambob],utxo); + //free(utxo); let the LP_utxoinfos2 free the utxo, should be 1:1 + } else n++; + } else n++; + } + HASH_ITER(hh,LP_utxoinfos2[iambob],utxo,tmp) + { + if ( LP_isavailable(utxo) > 0 ) + { + if ( allutxos != 0 || LP_ismine(utxo) > 0 ) + { + printf("iambob.%d delete2.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); + HASH_DELETE(hh2,LP_utxoinfos2[iambob],utxo); + free(utxo); + } else n++; + } else n++; + } + } + portable_mutex_unlock(&LP_utxomutex); + return(n); +} +int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t now) +{ + struct LP_peerinfo *peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; bits256 txid; struct LP_utxoinfo *utxo; + //printf("parse.(%s)\n",retstr); + if ( (array= cJSON_Parse(retstr)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; iT.lasttime = now; + } + } + if ( (destpeer= LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport)) != 0 ) + { + destpeer->numutxos = n; + } + } + free_json(array); + } + return(n); +} +void LP_spentnotify(struct LP_utxoinfo *utxo,int32_t selector) +{ + //cJSON *argjson; struct _LP_utxoinfo u; char *msg; + if ( utxo == 0 ) + return; + utxo->T.spentflag = (uint32_t)time(NULL); + /*if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) + LP_mypeer->numutxos--; + if ( LP_mypubsock >= 0 ) + { + argjson = cJSON_CreateObject(); + jaddstr(argjson,"method","checktxid"); + jaddbits256(argjson,"txid",utxo->payment.txid); + jaddnum(argjson,"vout",utxo->payment.vout); + if ( selector != 0 ) + { + if ( bits256_nonz(utxo->deposit.txid) != 0 ) + u = utxo->deposit; + else u = utxo->fee; + jaddbits256(argjson,"checktxid",u.txid); + jaddnum(argjson,"checkvout",u.vout); + } + msg = jprint(argjson,1); + /LP_send(LP_mypubsock,msg,(int32_t)strlen(msg)+1,1); + }*/ +} +char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t lastn) +{ + int32_t i,n,m; uint64_t val,val2; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo,*tmp; cJSON *utxosjson = cJSON_CreateArray(); + printf("deprecated! LP_utxos\n"); + //n = mypeer != 0 ? mypeer->numutxos : 0; + if ( lastn <= 0 ) + lastn = LP_PROPAGATION_SLACK * 2; + HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) + { + //char str[65]; printf("check %s.%s\n",utxo->coin,bits256_str(str,utxo->payment.txid)); + if ( (symbol == 0 || symbol[0] == 0 || strcmp(symbol,utxo->coin) == 0) && utxo->T.spentflag == 0 ) + { + u = (iambob != 0) ? utxo->deposit : utxo->fee; + if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) + { + char str[65]; printf("iambob.%d not eligible (%.8f %.8f) %s %s/v%d\n",iambob,dstr(val),dstr(val2),utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout); + continue; + } else jaddi(utxosjson,LP_utxojson(utxo)); + } + } + if ( (n= cJSON_GetArraySize(utxosjson)) > lastn ) + { + m = n - lastn; + for (i=0; i 0 ) + { + memset(zero.bytes,0,sizeof(zero)); + msg = jprint(LP_utxojson(utxo),1); + LP_broadcast_message(LP_mypubsock,utxo->coin,"",zero,msg); + } +} + +void LP_utxo_spentcheck(int32_t pubsock,struct LP_utxoinfo *utxo) +{ + struct _LP_utxoinfo u; struct iguana_info *coin; char str[65]; uint32_t now = (uint32_t)time(NULL); + if ( IAMLP != 0 && (coin= LP_coinfind(utxo->coin)) != 0 && coin->inactive != 0 ) + return; + //printf("%s lag.%d\n",bits256_str(str,utxo->txid),now-utxo->lastspentcheck); + if ( utxo->T.spentflag == 0 && now > utxo->T.lastspentcheck+60 ) + { + u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; + utxo->T.lastspentcheck = now; + if ( LP_txvalue(0,utxo->coin,utxo->payment.txid,utxo->payment.vout) == 0 ) + { + printf("txid.%s %s/v%d %.8f has been spent\n",utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout,dstr(utxo->payment.value)); + LP_spentnotify(utxo,0); + } + else if ( LP_txvalue(0,utxo->coin,u.txid,u.vout) == 0 ) + { + printf("txid2.%s %s/v%d %.8f has been spent\n",utxo->coin,bits256_str(str,u.txid),u.vout,dstr(u.value)); + LP_spentnotify(utxo,1); + } + } +} + +int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pubsock,struct LP_peerinfo *peer,uint32_t now,int32_t interval,int32_t maxentries) +{ + int32_t lastn,n = -1; + if ( peer->lastutxos < now-interval ) + { + //lastn = peer->numutxos - mypeer->numutxos + LP_PROPAGATION_SLACK; + //if ( lastn < LP_PROPAGATION_SLACK * 2 ) + lastn = LP_PROPAGATION_SLACK * 2; + if ( mypeer == 0 || strcmp(peer->ipaddr,mypeer->ipaddr) != 0 ) + { + peer->lastutxos = now; + //printf("query utxos from %s\n",peer->ipaddr); + n = LP_utxosquery(mypeer,pubsock,peer->ipaddr,peer->port,"",lastn,mypeer != 0 ? mypeer->ipaddr : "127.0.0.1",myport,maxentries); + } + } //else printf("LP_peer_utxosquery skip.(%s) %u\n",peer->ipaddr,peer->lastutxos); + return(n); +} +/*if ( time(NULL) > coin->lastmonitor+60 ) + { + //portable_mutex_lock(&coin->addrmutex); + HASH_ITER(hh,coin->addresses,ap,atmp) + { + if ( coin->electrum == 0 ) + { + LP_listunspent_issue(coin->symbol,ap->coinaddr); + DL_FOREACH_SAFE(ap->utxos,up,utmp) + { + if ( up->spendheight <= 0 ) + { + if ( LP_txvalue(0,coin->symbol,up->U.txid,up->U.vout) == 0 ) + up->spendheight = 1; + } + } + } + } + //portable_mutex_unlock(&coin->addrmutex); + coin->lastmonitor = (uint32_t)time(NULL); + }*/ + /*cJSON *LP_tradecandidates(char *base) { struct LP_peerinfo *peer,*tmp; struct LP_quoteinfo Q; char *utxostr,coinstr[16]; cJSON *array,*retarray=0,*item; int32_t i,n,totaladded,added; diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index af5db5094..a4d637804 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -363,22 +363,37 @@ void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo=0; uint8_t key[sizeof(txid) + sizeof(vout)]; + if ( iambob != 0 ) + { + printf("_LP_utxofind deprecated iambob\n"); + return(0); + } LP_utxosetkey(key,txid,vout); - HASH_FIND(hh,LP_utxoinfos[iambob],key,sizeof(key),utxo); + HASH_FIND(hh,G.LP_utxoinfos,key,sizeof(key),utxo); return(utxo); } struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) { struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)]; + if ( iambob != 0 ) + { + printf("_LP_utxo2find deprecated iambob\n"); + return(0); + } LP_utxosetkey(key2,txid2,vout2); - HASH_FIND(hh2,LP_utxoinfos2[iambob],key2,sizeof(key2),utxo); + HASH_FIND(hh2,G.LP_utxoinfos2,key2,sizeof(key2),utxo); return(utxo); } struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo=0; + if ( iambob != 0 ) + { + printf("LP_utxofind deprecated iambob\n"); + return(0); + } portable_mutex_lock(&LP_utxomutex); utxo = _LP_utxofind(iambob,txid,vout); portable_mutex_unlock(&LP_utxomutex); @@ -388,6 +403,11 @@ struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) struct LP_utxoinfo *LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) { struct LP_utxoinfo *utxo=0; + if ( iambob != 0 ) + { + printf("LP_utxo2find deprecated iambob\n"); + return(0); + } portable_mutex_lock(&LP_utxomutex); utxo = _LP_utxo2find(iambob,txid2,vout2); portable_mutex_unlock(&LP_utxomutex); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0889cef7c..c69de1953 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -20,7 +20,7 @@ int32_t LP_ismine(struct LP_utxoinfo *utxo) { - if ( utxo != 0 && bits256_cmp(utxo->pubkey,LP_mypub25519) == 0 ) + if ( utxo != 0 && bits256_cmp(utxo->pubkey,G.LP_mypub25519) == 0 ) return(1); else return(0); } @@ -154,42 +154,6 @@ void LP_availableset(struct LP_utxoinfo *utxo) } } -int32_t LP_utxopurge(int32_t allutxos) -{ - char str[65]; struct LP_utxoinfo *utxo,*tmp; int32_t iambob,n = 0; - printf("LP_utxopurge mypub.(%s)\n",bits256_str(str,LP_mypub25519)); - portable_mutex_lock(&LP_utxomutex); - for (iambob=0; iambob<=1; iambob++) - { - HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) - { - if ( LP_isavailable(utxo) > 0 ) - { - if ( allutxos != 0 || LP_ismine(utxo) > 0 ) - { - printf("iambob.%d delete.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); - HASH_DELETE(hh,LP_utxoinfos[iambob],utxo); - //free(utxo); let the LP_utxoinfos2 free the utxo, should be 1:1 - } else n++; - } else n++; - } - HASH_ITER(hh,LP_utxoinfos2[iambob],utxo,tmp) - { - if ( LP_isavailable(utxo) > 0 ) - { - if ( allutxos != 0 || LP_ismine(utxo) > 0 ) - { - printf("iambob.%d delete2.(%s)\n",iambob,bits256_str(str,utxo->payment.txid)); - HASH_DELETE(hh2,LP_utxoinfos2[iambob],utxo); - free(utxo); - } else n++; - } else n++; - } - } - portable_mutex_unlock(&LP_utxomutex); - return(n); -} - cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) { struct _LP_utxoinfo u; @@ -246,35 +210,6 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo) return(item); } -char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t lastn) -{ - int32_t i,n,m; uint64_t val,val2; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo,*tmp; cJSON *utxosjson = cJSON_CreateArray(); - printf("deprecated! LP_utxos\n"); - //n = mypeer != 0 ? mypeer->numutxos : 0; - if ( lastn <= 0 ) - lastn = LP_PROPAGATION_SLACK * 2; - HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) - { - //char str[65]; printf("check %s.%s\n",utxo->coin,bits256_str(str,utxo->payment.txid)); - if ( (symbol == 0 || symbol[0] == 0 || strcmp(symbol,utxo->coin) == 0) && utxo->T.spentflag == 0 ) - { - u = (iambob != 0) ? utxo->deposit : utxo->fee; - if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) - { - char str[65]; printf("iambob.%d not eligible (%.8f %.8f) %s %s/v%d\n",iambob,dstr(val),dstr(val2),utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout); - continue; - } else jaddi(utxosjson,LP_utxojson(utxo)); - } - } - if ( (n= cJSON_GetArraySize(utxosjson)) > lastn ) - { - m = n - lastn; - for (i=0; i= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); if ( strcmp(symbol,utxo->coin) != 0 ) @@ -307,29 +242,9 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) void LP_spentnotify(struct LP_utxoinfo *utxo,int32_t selector) { - //cJSON *argjson; struct _LP_utxoinfo u; char *msg; if ( utxo == 0 ) return; utxo->T.spentflag = (uint32_t)time(NULL); - if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) - LP_mypeer->numutxos--; - /*if ( LP_mypubsock >= 0 ) - { - argjson = cJSON_CreateObject(); - jaddstr(argjson,"method","checktxid"); - jaddbits256(argjson,"txid",utxo->payment.txid); - jaddnum(argjson,"vout",utxo->payment.vout); - if ( selector != 0 ) - { - if ( bits256_nonz(utxo->deposit.txid) != 0 ) - u = utxo->deposit; - else u = utxo->fee; - jaddbits256(argjson,"checktxid",u.txid); - jaddnum(argjson,"checkvout",u.vout); - } - msg = jprint(argjson,1); - /LP_send(LP_mypubsock,msg,(int32_t)strlen(msg)+1,1); - }*/ } char *LP_spentcheck(cJSON *argjson) @@ -350,8 +265,8 @@ char *LP_spentcheck(cJSON *argjson) } if ( LP_txvalue(0,utxo->coin,checktxid,checkvout) == 0 ) { - if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) - LP_mypeer->numutxos--; + //if ( LP_mypeer != 0 && LP_mypeer->numutxos > 0 ) + // LP_mypeer->numutxos--; utxo->T.spentflag = (uint32_t)time(NULL); retval++; printf("indeed txid was spent\n"); @@ -363,17 +278,6 @@ char *LP_spentcheck(cJSON *argjson) return(clonestr("{\"error\":\"cant find txid to check spent status\"}")); } -void LP_utxo_clientpublish(struct LP_utxoinfo *utxo) -{ - bits256 zero; char *msg; - if ( 0 && LP_isunspent(utxo) > 0 ) - { - memset(zero.bytes,0,sizeof(zero)); - msg = jprint(LP_utxojson(utxo),1); - LP_broadcast_message(LP_mypubsock,utxo->coin,"",zero,msg); - } -} - struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *spendscript,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) { uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; @@ -382,6 +286,11 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,spendscript == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } + if ( iambob != 0 ) + { + printf("deprecated bob utxos\n"); + return(0); + } if ( (coin= LP_coinfind(symbol)) == 0 || (IAMLP == 0 && coin->inactive != 0) ) { printf("LP_utxoadd reject inactive %s\n",symbol); @@ -395,7 +304,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit else return(0); } else tmpsatoshis = (value - txfee); char str[65],str2[65],dispflag = 0;//(iambob == 0); - if ( iambob == 0 && bits256_cmp(pubkey,LP_mypub25519) != 0 ) + if ( iambob == 0 && bits256_cmp(pubkey,G.LP_mypub25519) != 0 ) { printf("trying to add Alice utxo when not mine? %s/v%d\n",bits256_str(str,txid),vout); return(0); @@ -484,26 +393,24 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit LP_utxosetkey(utxo->key,txid,vout); LP_utxosetkey(utxo->key2,txid2,vout2); if ( LP_ismine(utxo) > 0 ) - utxo->T.sessionid = LP_sessionid; + utxo->T.sessionid = G.LP_sessionid; else utxo->T.sessionid = sessionid; if ( coin->inactive == 0 && (selector= LP_mempool_vinscan(&spendtxid,&spendvini,symbol,coinaddr,txid,vout,txid2,vout2)) >= 0 ) { printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - printf("U.%d %s %.8f %.8f addutxo.%d pubkey.%s session.%u\n",LP_mypeer!=0?LP_mypeer->numutxos:-1,symbol,dstr(value),dstr(value2),LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); + printf(" %s %.8f %.8f addutxo.%d pubkey.%s session.%u\n",symbol,dstr(value),dstr(value2),LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); portable_mutex_lock(&LP_utxomutex); - HASH_ADD_KEYPTR(hh,LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); + HASH_ADD_KEYPTR(hh,G.LP_utxoinfos,utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) - HASH_ADD_KEYPTR(hh2,LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); + HASH_ADD_KEYPTR(hh2,G.LP_utxoinfos2,utxo->key2,sizeof(utxo->key2),utxo); portable_mutex_unlock(&LP_utxomutex); if ( iambob != 0 ) { - if ( LP_mypeer != 0 ) - LP_mypeer->numutxos++; if ( LP_ismine(utxo) > 0 ) { - LP_utxo_clientpublish(utxo); + //LP_utxo_clientpublish(utxo); if ( LP_mypeer != 0 ) utxo->T.lasttime = (uint32_t)time(NULL); } @@ -530,75 +437,14 @@ struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson return(utxo); } -int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t now) +cJSON *LP_inventory(char *symbol) { - struct LP_peerinfo *destpeer,*peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; bits256 txid; struct LP_utxoinfo *utxo; - //printf("parse.(%s)\n",retstr); - if ( (array= cJSON_Parse(retstr)) != 0 ) - { - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - for (i=0; iT.lasttime = now; - } - } - if ( (destpeer= LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport)) != 0 ) - { - destpeer->numutxos = n; - } - } - free_json(array); - } - return(n); -} - -int32_t LP_utxosquery(struct LP_peerinfo *mypeer,int32_t mypubsock,char *destipaddr,uint16_t destport,char *coin,int32_t lastn,char *myipaddr,uint16_t myport,int32_t maxentries) -{ - char *retstr; struct LP_peerinfo *peer; uint32_t now; int32_t retval = -1; - printf("deprecated LP_utxosquery\n"); - return(-1); - peer = LP_peerfind((uint32_t)calc_ipbits(destipaddr),destport); - if ( coin == 0 ) - coin = ""; - //printf("utxo query.(%s)\n",destipaddr); - if ( IAMLP != 0 ) - retstr = issue_LP_getutxos(destipaddr,destport,coin,lastn,myipaddr,myport,mypeer != 0 ? mypeer->numpeers : 0,maxentries); - else retstr = issue_LP_clientgetutxos(destipaddr,destport,coin,maxentries); - if ( retstr != 0 ) - { - now = (uint32_t)time(NULL); - retval = LP_utxosparse(destipaddr,destport,retstr,now); - //printf("got.(%s)\n",retstr); - free(retstr); - } - return(retval); -} - -cJSON *LP_inventory(char *symbol,int32_t iambob) -{ - struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; + struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; array = cJSON_CreateArray(); if ( LP_mypeer != 0 ) myipaddr = LP_mypeer->ipaddr; else myipaddr = "127.0.0.1"; - HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) + HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) { char str[65]; //printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519)); @@ -612,8 +458,8 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2)); continue; } - if ( iambob != 0 ) - LP_utxo_clientpublish(utxo); + //if ( iambob != 0 ) + // LP_utxo_clientpublish(utxo); jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); } else if ( LP_ismine(utxo) > 0 && strcmp(symbol,utxo->coin) == 0 ) @@ -764,14 +610,14 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri portable_mutex_lock(&LP_UTXOmutex); if ( iambob != 0 ) { - if ( (utxo= LP_utxoadd(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_gui,LP_sessionid)) != 0 ) + if ( (utxo= LP_utxoadd(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) { } } else { //printf("call utxoadd\n"); - if ( (utxo= LP_utxoadd(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,LP_gui,LP_sessionid)) != 0 ) + if ( (utxo= LP_utxoadd(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) { } } @@ -839,7 +685,7 @@ char *LP_secretaddresses(void *ctx,char *passphrase,int32_t n,uint8_t taddr,uint bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) { - static uint32_t counter; + //static uint32_t counter; bits256 privkey,userpub,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; if ( passphrase != 0 && passphrase[0] != 0 ) { @@ -864,23 +710,23 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan { coin->counter++; bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); - bitcoin_addr2rmd160(coin->taddr,&tmptype,LP_myrmd160,coin->smartaddr); - LP_privkeyadd(privkey,LP_myrmd160); + bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr); + LP_privkeyadd(privkey,G.LP_myrmd160); if ( 0 && (coin->pubtype != 60 || strcmp(coin->symbol,"KMD") == 0) ) printf("%s (%s) %d wif.(%s) (%s)\n",coin->symbol,coin->smartaddr,coin->pubtype,tmpstr,passphrase); - if ( counter++ == 0 ) + if ( G.counter++ == 0 ) { - bitcoin_priv2wif(coin->wiftaddr,USERPASS_WIFSTR,privkey,188); - bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,USERPASS_WIFSTR); + bitcoin_priv2wif(coin->wiftaddr,G.USERPASS_WIFSTR,privkey,188); + bitcoin_wif2priv(coin->wiftaddr,&tmptype,&checkkey,G.USERPASS_WIFSTR); if ( bits256_cmp(checkkey,privkey) != 0 ) { char str[65],str2[65]; - printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); + printf("FATAL ERROR converting USERPASS_WIFSTR %s -> %s != %s\n",G.USERPASS_WIFSTR,bits256_str(str,checkkey),bits256_str(str2,privkey)); exit(-1); } - conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)USERPASS_WIFSTR,(int32_t)strlen(USERPASS_WIFSTR)); + conv_NXTpassword(userpass.bytes,pubkeyp->bytes,(uint8_t *)G.USERPASS_WIFSTR,(int32_t)strlen(G.USERPASS_WIFSTR)); userpub = curve25519(userpass,curve25519_basepoint9()); - printf("userpass.(%s)\n",bits256_str(USERPASS,userpub)); + printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub)); } if ( coin->electrum == 0 ) { @@ -895,23 +741,29 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan } else free_json(retjson); } } - LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); - LP_mypriv25519 = privkey; + G.LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); + G.LP_mypriv25519 = privkey; //printf("privkey.(%s) -> LP_mypub25519.(%s)\n",bits256_str(str,privkey),bits256_str(str2,LP_mypub25519)); return(privkey); } -void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t initonly) +void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) { - struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; + struct iguana_info *coin,*tmp; bits256 pubkey,privkey; uint8_t pubkey33[33]; int32_t initonly; + initonly = (passphrase != 0); memset(privkey.bytes,0,sizeof(privkey)); - pubkey = privkey; + memset(pubkey.bytes,0,sizeof(pubkey)); HASH_ITER(hh,LP_coins,coin,tmp) { + if ( initonly != 0 ) + { + coin->counter = 0; + memset(coin->smartaddr,0,sizeof(coin->smartaddr)); + if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) + privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); + } //printf("i.%d of %d\n",i,LP_numcoins); - if ( bits256_nonz(privkey) == 0 || coin->smartaddr[0] == 0 ) - privkey = LP_privkeycalc(ctx,pubkey33,&pubkey,coin,passphrase,""); - if ( coin->inactive == 0 && initonly == 0 ) + else if ( coin->inactive == 0 ) { if ( LP_privkey_init(pubsock,coin,privkey,pubkey) == 0 && (rand() % 10) == 0 ) LP_postutxos(coin->symbol,coin->smartaddr); @@ -919,4 +771,40 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase,int32_t inito } } +int32_t LP_passphrase_init(char *passphrase) +{ + static void *ctx; struct LP_utxoinfo *utxo,*tmp; + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + if ( G.LP_pendingswaps != 0 ) + return(-1); + G.initializing = 1; + while ( G.waiting == 0 ) + { + printf("waiting for G.waiting\n"); + sleep(5); + } + if ( G.LP_utxoinfos != 0 ) + { + HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) + { + HASH_DELETE(hh,G.LP_utxoinfos,utxo); + free(utxo); + } + } + if ( G.LP_utxoinfos2 != 0 ) + { + HASH_ITER(hh,G.LP_utxoinfos2,utxo,tmp) + { + HASH_DELETE(hh,G.LP_utxoinfos2,utxo); + free(utxo); + } + } + memset(&G,0,sizeof(G)); + LP_privkey_updates(ctx,LP_mypubsock,passphrase); + init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); + G.LP_sessionid = (uint32_t)time(NULL); + return(0); +} + From 4fe35e79fa186ba05c7905f068665dd1d2515e65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:09:32 +0200 Subject: [PATCH 262/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 22229e365..048b54368 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -581,6 +581,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); printf("initcoins\n"); LP_initcoins(ctx,pubsock,jobj(argjson,"coins")); + G.waiting = 1; LP_passphrase_init(passphrase); if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 ) { From 5ffb1a8d4eaae72ff7232a8b93fdddfc6749d535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:13:17 +0200 Subject: [PATCH 263/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c69de1953..6cbb86a44 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -157,7 +157,7 @@ void LP_availableset(struct LP_utxoinfo *utxo) cJSON *LP_inventoryjson(cJSON *item,struct LP_utxoinfo *utxo) { struct _LP_utxoinfo u; - jaddstr(item,"method","oldutxo"); + //jaddstr(item,"method","oldutxo"); if ( utxo == 0 ) return(item); if ( utxo->gui[0] != 0 ) From 5b447f82114cf438dec4b6392c13559c657eeaf8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:16:51 +0200 Subject: [PATCH 264/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 6cbb86a44..0c76c1976 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -765,7 +765,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) //printf("i.%d of %d\n",i,LP_numcoins); else if ( coin->inactive == 0 ) { - if ( LP_privkey_init(pubsock,coin,privkey,pubkey) == 0 && (rand() % 10) == 0 ) + if ( LP_privkey_init(pubsock,coin,G.LP_mypriv25519,G.LP_mypub25519) == 0 && (rand() % 10) == 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } } From ad0e5819e7156061640c74232f5aef213c9154b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:23:40 +0200 Subject: [PATCH 265/520] Test --- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 2889e2a76..33348e387 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -287,7 +287,7 @@ void LP_peer_pricesquery(struct LP_peerinfo *peer) } if ( peer->needping != 0 ) { - printf("%s needs ping\n",peer->ipaddr); + //printf("%s needs ping\n",peer->ipaddr); } } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 5555f9767..b128fbd39 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -66,7 +66,7 @@ char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port, if ( rmd160str != 0 && bits256_nonz(pub) != 0 ) { sprintf(url+strlen(url),"&rmd160=%s&pub=%s",rmd160str,bits256_str(str,pub)); - printf("SEND (%s)\n",url); + //printf("SEND (%s)\n",url); } return(LP_issue_curl("notify",destip,destport,url)); //return(issue_curlt(url,LP_HTTP_TIMEOUT)); From d2d4a1f0ba871e0cc0f580aed50b30fc4af706ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:31:05 +0200 Subject: [PATCH 266/520] Test --- iguana/exchanges/LP_commands.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 5eec41e3c..5e0c28b39 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -167,7 +167,13 @@ dividends(coin, height, )\n\ { if ( LP_passphrase_init(jstr(argjson,"passphrase")) < 0 ) return(clonestr("{\"error\":\"couldnt change passphrase\"}")); - else return(clonestr("{\"result\":\"success\"}")); + { + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"userpass",G.USERPASS); + jaddbits256(retjson,"mypubkey",G.LP_mypub25519); + return(jprint(retjson,1)); + } } else if ( strcmp(method,"portfolio") == 0 ) { From 311b740b5b45f681ded2573b875555c4d75905ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:43:49 +0200 Subject: [PATCH 267/520] Test --- iguana/exchanges/LP_ordermatch.c | 65 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e1ce01255..1861f3bb9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -722,9 +722,47 @@ char *LP_connectedalice(cJSON *argjson) // alice } } +int32_t LP_listunspent_both(char *symbol,char *coinaddr) +{ + int32_t i,v,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); + if ( coin != 0 ) + { + if ( coin->electrum != 0 ) + { + if ( (array= LP_listunspent(coin->symbol,coinaddr)) != 0 ) + { + n = cJSON_GetArraySize(array); + free_json(array); + } else n = 0; + } + else + { + sprintf(buf,"[1, 99999999, [\"%s\"]]",coinaddr); + if ( (array= bitcoin_json(coin,"listunspent",buf)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; ielectrum != 0 ) - { - if ( (array= LP_listunspent(coin->symbol,Q.coinaddr)) != 0 ) - { - n = cJSON_GetArraySize(array); - free_json(array); - } else n = 0; - } - else - { - n = LP_listunspent_issue(coin->symbol,Q.coinaddr); - //printf("need to verify\n"); - } + LP_listunspent_both(Q.srccoin,Q.coinaddr); butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1,Q.desttxfee); Q.txid = butxo->payment.txid; Q.vout = butxo->payment.vout; @@ -895,7 +921,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*array,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -923,14 +949,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ( basecoin->electrum != 0 ) - { - if ( (array= LP_listunspent(basecoin->symbol,coinaddr)) != 0 ) - { - n = cJSON_GetArraySize(array); - free_json(array); - } else n = 0; - } else n = LP_listunspent_issue(basecoin->symbol,coinaddr); + n = LP_listunspent_both(base,coinaddr); if ( n > 1 ) { //minvol = jdouble(item,"minvolume"); From 8a26850f169932b047ec5d45ffa2c2658028503e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 11:48:18 +0200 Subject: [PATCH 268/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 048b54368..c49df3c55 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -611,6 +611,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //if ( (retstr= basilisk_swapentry(0,0)) != 0 ) // free(retstr); int32_t nonz; + printf("start mainloop\n"); while ( 1 ) { nonz = 0; From f5fb60c7227f58aade90f4025e336b02addf1737 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:17:04 +0200 Subject: [PATCH 269/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 02f9387fc..cb37f36fe 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -490,7 +490,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); coin->unspenttime = (uint32_t)time(NULL); } - } //else retjson = LP_address_utxos(coin,addr,1); + } else retjson = LP_address_utxos(coin,addr,1); return(retjson); } From 71a4444ad3291b4a6c751be2a2a8eb3fcfc84e19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:22:46 +0200 Subject: [PATCH 270/520] Test --- iguana/exchanges/LP_ordermatch.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 1861f3bb9..9a2675245 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -727,13 +727,9 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t i,v,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); if ( coin != 0 ) { - if ( coin->electrum != 0 ) + if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) < 0 ) { - if ( (array= LP_listunspent(coin->symbol,coinaddr)) != 0 ) - { - n = cJSON_GetArraySize(array); - free_json(array); - } else n = 0; + n = LP_listunspent_issue(symbol,coinaddr); } else { @@ -754,7 +750,6 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) } } } - //printf("need to verify\n"); } } return(n); From 38012c594226f17f911c22a03fb7340dc6f54bb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:24:22 +0200 Subject: [PATCH 271/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b128fbd39..d941ed7ee 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -85,7 +85,7 @@ char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coi { char url[512]; sprintf(url,"http://%s:%u/api/stats/listunspent?coin=%s&address=%s",destip,destport,symbol,coinaddr); - //printf("listunspent.(%s)\n",url); + printf("listunspent.(%s)\n",url); return(LP_issue_curl("listunspent",destip,destport,url)); } From b13496766b69cba6da4248af71fae3c679e2b6bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:27:47 +0200 Subject: [PATCH 272/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_rpc.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9a2675245..234ae5ff6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -733,6 +733,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) } else { + //printf("my coin\n"); sprintf(buf,"[1, 99999999, [\"%s\"]]",coinaddr); if ( (array= bitcoin_json(coin,"listunspent",buf)) != 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d941ed7ee..b8fb1688e 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -484,7 +484,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); retjson = cJSON_Parse(retstr); - } + } else printf("LP_listunspent_issue couldnt get a random peer?\n"); if ( retjson != 0 ) { n = cJSON_GetArraySize(retjson); @@ -492,6 +492,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) LP_postutxos(symbol,coinaddr); // might be good to not saturate } } + printf("issue listunspent %s (%s)\n",coinaddr,jprint(retjson,0)); if ( retjson != 0 ) free_json(retjson); if ( retstr != 0 ) From 528926a708c2db05a80c275da9dabbf7e4b9cf62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:30:58 +0200 Subject: [PATCH 273/520] Test --- iguana/exchanges/LP_ordermatch.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 234ae5ff6..4a37fbbc0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -725,7 +725,7 @@ char *LP_connectedalice(cJSON *argjson) // alice int32_t LP_listunspent_both(char *symbol,char *coinaddr) { int32_t i,v,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); - if ( coin != 0 ) + if ( coin != 0 && coin->inactive == 0 ) { if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) < 0 ) { @@ -917,7 +917,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -940,32 +940,26 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr price = jdouble(item,"price"); if ( LP_pricevalid(price) > 0 && price <= maxprice ) { - printf("%s\n",jprint(item,0)); pubkey = jbits256(item,"pubkey"); + printf("%s -> %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); n = LP_listunspent_both(base,coinaddr); if ( n > 1 ) { - //minvol = jdouble(item,"minvolume"); - //maxvol = jdouble(item,"maxvolume"); - //printf("%s minvol %.8f %.8f maxvol %.8f\n",jprint(item,0),minvol,relvolume,maxvol); - //if ( relvolume >= minvol && relvolume <= maxvol ) + if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,dstr(autxo->S.satoshis),price,0,desttxfee)) != 0 ) { - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,dstr(autxo->S.satoshis),price,0,desttxfee)) != 0 ) - { - bestutxo->pubkey = pubp->pubkey; - safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - //autxo->S.satoshis = bestutxo->S.satoshis * price - desttxfee; - *bestsatoshisp = bestutxo->S.satoshis; - *ordermatchpricep = price; - *bestdestsatoshisp = autxo->S.satoshis; - printf("ordermatch %.8f %.8f %.8f txfees (%.8f %.8f)\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp),dstr(txfee),dstr(desttxfee)); - break; - } + bestutxo->pubkey = pubp->pubkey; + safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); + //autxo->S.satoshis = bestutxo->S.satoshis * price - desttxfee; + *bestsatoshisp = bestutxo->S.satoshis; + *ordermatchpricep = price; + *bestdestsatoshisp = autxo->S.satoshis; + printf("ordermatch %.8f %.8f %.8f txfees (%.8f %.8f)\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp),dstr(txfee),dstr(desttxfee)); + break; } - } + } else printf("no unspents %s\n",bits256_str(str,pubkey)); } else printf("self trading or blacklisted peer\n"); } else From d36b68a6a9b8082756d3974771d648c60993faef Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:33:02 +0200 Subject: [PATCH 274/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 4a37fbbc0..77a8215ce 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -752,7 +752,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) } } } - } + } else printf("%s coin.%p inactive.%d\n",symbol,coin,coin!=0?coin->inactive:-1); return(n); } From 4d48070b85c0141c15f8260f2c9bee19a67bdc1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:35:43 +0200 Subject: [PATCH 275/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- iguana/exchanges/LP_rpc.c | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 77a8215ce..787fc7581 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -729,11 +729,12 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) { if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) < 0 ) { + printf("issue path\n"); n = LP_listunspent_issue(symbol,coinaddr); } else { - //printf("my coin\n"); + printf("my coin\n"); sprintf(buf,"[1, 99999999, [\"%s\"]]",coinaddr); if ( (array= bitcoin_json(coin,"listunspent",buf)) != 0 ) { @@ -941,7 +942,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr if ( LP_pricevalid(price) > 0 && price <= maxprice ) { pubkey = jbits256(item,"pubkey"); - printf("%s -> %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); + printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b8fb1688e..eef057b00 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -469,6 +469,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; if ( symbol == 0 || symbol[0] == 0 ) return(0); + printf("LP_listunspent_issue\n"); if ( (coin= LP_coinfind(symbol)) != 0 ) { if ( coin->electrum != 0 ) From 51bb827d6184ab5ae5dc3d28797b081b4d9b5015 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:38:33 +0200 Subject: [PATCH 276/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 787fc7581..e392e7d23 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -729,7 +729,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) { if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) < 0 ) { - printf("issue path\n"); + printf("issue path electrum.%p\n",coin->electrum); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index eef057b00..904c48d77 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -414,8 +414,7 @@ cJSON *LP_validateaddress(char *symbol,char *address) jaddstr(retjson,"scriptPubKey",script); } bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,20); - if ( strcmp(address,coinaddr) == 0 ) - jadd(retjson,"ismine",cJSON_CreateTrue()); + jadd(retjson,"ismine",strcmp(address,coin->smartaddr) == 0 ? cJSON_CreateTrue() : cJSON_CreateFalse()); jadd(retjson,"iswatchonly",cJSON_CreateFalse()); jadd(retjson,"isscript",addrtype == coin->p2shtype ? cJSON_CreateTrue() : cJSON_CreateFalse()); return(retjson); @@ -437,7 +436,7 @@ int32_t LP_address_ismine(char *symbol,char *address) if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) { doneflag = 1; - //printf("%s already ismine\n",address); + printf("%s ismine (%s)\n",address,jprint(retjson,0)); } //printf("%s\n",jprint(retjson,0)); free_json(retjson); From d82dec1aae48a7c7f555121f16b3b45d78010d4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:41:38 +0200 Subject: [PATCH 277/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e392e7d23..8b5f10629 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -734,7 +734,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) } else { - printf("my coin\n"); + printf("my coin electrum.%p\n",coin->electrum); sprintf(buf,"[1, 99999999, [\"%s\"]]",coinaddr); if ( (array= bitcoin_json(coin,"listunspent",buf)) != 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 904c48d77..b883d1a5c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -436,7 +436,7 @@ int32_t LP_address_ismine(char *symbol,char *address) if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) { doneflag = 1; - printf("%s ismine (%s)\n",address,jprint(retjson,0)); + //printf("%s ismine (%s)\n",address,jprint(retjson,0)); } //printf("%s\n",jprint(retjson,0)); free_json(retjson); From a130e8f48e23405c4563ea7274a326d89e67664a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 12:43:12 +0200 Subject: [PATCH 278/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 8b5f10629..261fb1a82 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -727,7 +727,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t i,v,height,n=0; uint64_t value; bits256 txid; char buf[512]; cJSON *array,*item; struct iguana_info *coin = LP_coinfind(symbol); if ( coin != 0 && coin->inactive == 0 ) { - if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) < 0 ) + if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) { printf("issue path electrum.%p\n",coin->electrum); n = LP_listunspent_issue(symbol,coinaddr); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b883d1a5c..904c48d77 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -436,7 +436,7 @@ int32_t LP_address_ismine(char *symbol,char *address) if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) { doneflag = 1; - //printf("%s ismine (%s)\n",address,jprint(retjson,0)); + printf("%s ismine (%s)\n",address,jprint(retjson,0)); } //printf("%s\n",jprint(retjson,0)); free_json(retjson); From 0e07e93ebab65e5b7e33a6c308ee8ee05923daca Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 14:09:53 +0200 Subject: [PATCH 279/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_rpc.c | 4 ++-- iguana/exchanges/LP_scan.c | 5 ++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 5e0c28b39..30424456a 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -236,7 +236,7 @@ dividends(coin, height, )\n\ { 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"))); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")*price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c49df3c55..2daa76cbf 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -343,6 +343,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); peer->needping = 0; } + //sync listunspent, parse arrays in ordermatch, electrum history to prune, spv } } if ( peer->diduquery == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 261fb1a82..379670a7c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -729,12 +729,12 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) { if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) { - printf("issue path electrum.%p\n",coin->electrum); + //printf("issue path electrum.%p\n",coin->electrum); n = LP_listunspent_issue(symbol,coinaddr); } else { - printf("my coin electrum.%p\n",coin->electrum); + //printf("my coin electrum.%p\n",coin->electrum); sprintf(buf,"[1, 99999999, [\"%s\"]]",coinaddr); if ( (array= bitcoin_json(coin,"listunspent",buf)) != 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 904c48d77..6b04e22e1 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -436,7 +436,7 @@ int32_t LP_address_ismine(char *symbol,char *address) if ( jobj(retjson,"ismine") != 0 && is_cJSON_True(jobj(retjson,"ismine")) != 0 ) { doneflag = 1; - printf("%s ismine (%s)\n",address,jprint(retjson,0)); + //printf("%s ismine (%s)\n",address,jprint(retjson,0)); } //printf("%s\n",jprint(retjson,0)); free_json(retjson); @@ -492,7 +492,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) LP_postutxos(symbol,coinaddr); // might be good to not saturate } } - printf("issue listunspent %s (%s)\n",coinaddr,jprint(retjson,0)); + //printf("issue listunspent %s (%s)\n",coinaddr,jprint(retjson,0)); if ( retjson != 0 ) free_json(retjson); if ( retstr != 0 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 14825a425..5cbbabf43 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -438,7 +438,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration) { - struct iguana_info *coin; cJSON *array,*item; uint32_t expiration,i,n,numconfirms = -1; + struct iguana_info *coin; cJSON *array,*item; uint32_t expiration,i,n; int32_t numconfirms = -1; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) { printf("LP_waitmempool missing coin.%p or inactive\n",coin); @@ -475,14 +475,13 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int LP_listunspent_issue(coin->symbol,coinaddr); struct LP_address_utxo *up; if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) - //if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height > 0 ) { char str[65]; printf("address_utxofind found confirmed %s %s ht.%d vs %d\n",symbol,bits256_str(str,txid),up->U.height,coin->height); if ( coin->height >= up->U.height ) numconfirms = (coin->height - up->U.height + 1); } } - if ( time(NULL) > expiration || numconfirms >= 1 ) + if ( time(NULL) > expiration || numconfirms >= 0 ) break; usleep(500000); } From 451e6c21e22ad4e10fe7523fab1312d864d703b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 14:53:06 +0200 Subject: [PATCH 280/520] Test --- iguana/exchanges/LP_nativeDEX.c | 18 +++++++++++++++++- iguana/exchanges/LP_ordermatch.c | 2 ++ iguana/exchanges/LP_rpc.c | 1 - iguana/exchanges/LP_scan.c | 17 +++++++++++------ iguana/exchanges/LP_socket.c | 31 +++++++++++++++++++++++++++---- iguana/exchanges/LP_utxo.c | 22 +++++++++++----------- 6 files changed, 68 insertions(+), 23 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2daa76cbf..5285f4da7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -343,7 +343,23 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); peer->needping = 0; } - //sync listunspent, parse arrays in ordermatch, electrum history to prune, spv + HASH_ITER(hh,LP_coins,coin,ctmp) + { + char coinaddr[64]; cJSON *array; int32_t n; + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,sizeof(G.LP_myrmd160)); + if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) + { + printf("compare (%s) vs (%s)\n",jprint(array,0),retstr); + free(retstr); + } + } + free_json(array); + } + //sync listunspent,, spv } } if ( peer->diduquery == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 379670a7c..25bb7a3e3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -730,6 +730,8 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) { //printf("issue path electrum.%p\n",coin->electrum); + if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) + free_json(array); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 6b04e22e1..c42d5c3d7 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -468,7 +468,6 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; if ( symbol == 0 || symbol[0] == 0 ) return(0); - printf("LP_listunspent_issue\n"); if ( (coin= LP_coinfind(symbol)) != 0 ) { if ( coin->electrum != 0 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 5cbbabf43..9f65fa7ef 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -21,13 +21,14 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { - int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; + int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs,*txobj; bits256 txid; struct LP_transaction *tx; if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height ) { if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) { for (iter=0; iter<2; iter++) { + txobj = 0; for (i=0; iheight = height; } if ( iter == 1 ) - LP_transactioninit(coin,txid,iter,0); - } else LP_transactioninit(coin,txid,iter,0); + txobj = LP_transactioninit(coin,txid,iter,0); + } else txobj = LP_transactioninit(coin,txid,iter,0); + if ( txobj != 0 ) + free_json(txobj), txobj = 0; } } } @@ -409,7 +412,7 @@ int32_t LP_spendsearch(bits256 *spendtxidp,int32_t *indp,char *symbol,bits256 se int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) { - int32_t i,n; cJSON *array; bits256 txid; struct iguana_info *coin; struct LP_transaction *tx; + int32_t i,n; cJSON *array,*txobj; bits256 txid; struct iguana_info *coin; struct LP_transaction *tx; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 || coin->electrum != 0 ) return(-1); if ( (array= LP_getmempool(symbol,0)) != 0 ) @@ -421,8 +424,10 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) txid = jbits256i(array,i); if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { - LP_transactioninit(coin,txid,0,0); - LP_transactioninit(coin,txid,1,0); + txobj = LP_transactioninit(coin,txid,0,0); + txobj = LP_transactioninit(coin,txid,1,txobj); + if ( txobj != 0 ) + free_json(txobj); } if ( bits256_cmp(txid,searchtxid) == 0 ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index cb37f36fe..80f1f230b 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -334,6 +334,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep { txobj = LP_transactioninit(coin,txid,0,0); LP_transactioninit(coin,txid,1,txobj); + free_json(txobj); tx = LP_transactionfind(coin,txid); } if ( tx != 0 ) @@ -351,7 +352,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep tx->outpoints[v].value = value; } } - if ( value != 0 && tx->height > 0 ) + if ( value != 0 || tx->height > 0 ) flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); //printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); } @@ -461,10 +462,32 @@ cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON ** cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { - cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); + struct LP_transaction *tx; cJSON *retjson,*txobj,*item; int32_t i,n,height; bits256 txid; struct iguana_info *coin = LP_coinfind(symbol); retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT); - printf("history.(%s)\n",jprint(retjson,0)); - electrum_process_array(coin,ep,addr,retjson); + //printf("history.(%s)\n",jprint(retjson,0)); + if ( retjson != 0 && (n= cJSON_GetArraySize(retjson)) > 0 ) + { + for (i=0; i 0 ) + { + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + tx->height = height; + //for (j=0; jnumvouts; j++) + // LP_address_utxoadd(coin,coinaddr,txid,j,0,height,-1); + } + } + } + } return(retjson); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a4d637804..6f0dc3f84 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -185,11 +185,12 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, { if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 ) { - if ( up->U.height <= 0 && height > 0 ) - up->U.height = height; - if ( spendheight > 0 ) - up->spendheight = spendheight; - flag = 1; + if ( up->U.height <= 0 && height > 0 && up->U.height != height ) + up->U.height = height, flag = 1; + if ( spendheight > 0 && up->spendheight != spendheight ) + up->spendheight = spendheight, flag = 1; + if ( up->U.value == 0 && up->U.value != value ) + up->U.value = value, flag = 1; break; } } @@ -492,6 +493,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[i].value = LP_value_extract(vout,0); tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); LP_destaddr(tx->outpoints[i].coinaddr,vout); + LP_address_utxoadd(coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1); } //printf("numvouts.%d\n",numvouts); } @@ -523,11 +525,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout); } } - if ( iter == 1 ) - { - free_json(txobj); - return(0); - } else return(txobj); + return(txobj); } //else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid)); return(0); } @@ -615,7 +613,9 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { txobj = LP_transactioninit(coin,txid,0,0); - LP_transactioninit(coin,txid,1,txobj); + txobj = LP_transactioninit(coin,txid,1,txobj); + if ( txobj != 0 ) + free_json(txobj); tx = LP_transactionfind(coin,txid); } if ( tx != 0 ) From 01d18eb8b59b8342fc915fa41ce4efe19c10170e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:02:52 +0200 Subject: [PATCH 281/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 41 ++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index f89011c73..d18c94000 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -306,6 +306,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); void LP_postutxos(char *symbol,char *coinaddr); +int32_t LP_listunspent_both(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); int32_t LP_butxo_findeither(bits256 txid,int32_t vout); cJSON *LP_listunspent(char *symbol,char *coinaddr); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5285f4da7..c6da0806f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -343,23 +343,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); peer->needping = 0; } - HASH_ITER(hh,LP_coins,coin,ctmp) - { - char coinaddr[64]; cJSON *array; int32_t n; - bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,sizeof(G.LP_myrmd160)); - if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) - { - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) - { - printf("compare (%s) vs (%s)\n",jprint(array,0),retstr); - free(retstr); - } - } - free_json(array); - } - //sync listunspent,, spv + //sync listunspent,, spv } } if ( peer->diduquery == 0 ) @@ -374,8 +358,27 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height; bits256 zero; //struct LP_address *ap,*atmp; struct LP_address_utxo *up,*utmp; - //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); + int32_t height; bits256 zero; char coinaddr[64]; cJSON *array; int32_t n; + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,sizeof(G.LP_myrmd160)); + LP_listunspent_both(coin->symbol,coinaddr); + if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + if ( peer->errors < LP_MAXPEER_ERRORS ) + { + if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) + { + printf(">>>>>>>> compare (%s) vs (%s)\n",jprint(array,0),retstr); + free(retstr); + } + } + } + } + free_json(array); + } if ( coin->inactive != 0 ) continue; if ( coin->electrum != 0 ) From 66a4fe3e52f8b5cd5c95c2bde4833abb2ceff108 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:05:55 +0200 Subject: [PATCH 282/520] Test --- iguana/exchanges/LP_nativeDEX.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c6da0806f..6c6deb35b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -343,7 +343,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); peer->needping = 0; } - //sync listunspent,, spv } } if ( peer->diduquery == 0 ) @@ -358,20 +357,20 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height; bits256 zero; char coinaddr[64]; cJSON *array; int32_t n; - bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,sizeof(G.LP_myrmd160)); - LP_listunspent_both(coin->symbol,coinaddr); - if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + int32_t height; bits256 zero; cJSON *array; int32_t n; + LP_listunspent_both(coin->symbol,coin->smartaddr); + if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { if ( (n= cJSON_GetArraySize(array)) > 0 ) { + printf("[%s]\n\n",jprint(array,0)); HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( peer->errors < LP_MAXPEER_ERRORS ) { - if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) + if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr)) != 0 ) { - printf(">>>>>>>> compare (%s) vs (%s)\n",jprint(array,0),retstr); + printf(">>>>>>>> compare %s %s (%s)\n",coin->symbol,coin->smartaddr,retstr); free(retstr); } } From e7f1933a817a80064f47122f1d4128014a67192c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:15:15 +0200 Subject: [PATCH 283/520] Test --- iguana/exchanges/LP_nativeDEX.c | 27 +++++++++++++++------------ iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 7 ++++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6c6deb35b..f9616e367 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -358,28 +358,31 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { int32_t height; bits256 zero; cJSON *array; int32_t n; - LP_listunspent_both(coin->symbol,coin->smartaddr); - if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) + if ( coin->inactive != 0 ) + continue; + if ( (rand() % 100) == 0 ) { - if ( (n= cJSON_GetArraySize(array)) > 0 ) + LP_listunspent_both(coin->symbol,coin->smartaddr); + if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { - printf("[%s]\n\n",jprint(array,0)); - HASH_ITER(hh,LP_peerinfos,peer,tmp) + if ( (n= cJSON_GetArraySize(array)) > 0 ) { - if ( peer->errors < LP_MAXPEER_ERRORS ) + printf("[%s]\n\n",jprint(array,0)); + HASH_ITER(hh,LP_peerinfos,peer,tmp) { - if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr)) != 0 ) + if ( strcmp(peer->ipaddr,LP_myipaddr) != 0 && peer->errors < LP_MAXPEER_ERRORS ) { - printf(">>>>>>>> compare %s %s (%s)\n",coin->symbol,coin->smartaddr,retstr); - free(retstr); + if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr)) != 0 ) + { + printf(">>>>>>>> compare %s %s (%s)\n",coin->symbol,coin->smartaddr,retstr); + free(retstr); + } } } } + free_json(array); } - free_json(array); } - if ( coin->inactive != 0 ) - continue; if ( coin->electrum != 0 ) continue; memset(zero.bytes,0,sizeof(zero)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 80f1f230b..de90fcb96 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -472,7 +472,7 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * item = jitem(retjson,i); txid = jbits256(item,"tx_hash"); height = jint(item,"height"); - char str[65]; printf("history txinit %s ht.%d\n",bits256_str(str,txid),height); + //char str[65]; printf("history txinit %s ht.%d\n",bits256_str(str,txid),height); txobj = LP_transactioninit(coin,txid,0,0); txobj = LP_transactioninit(coin,txid,1,txobj); if ( txobj != 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6f0dc3f84..8ed5aa5e4 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -185,12 +185,13 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, { if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 ) { + flag = 1; if ( up->U.height <= 0 && height > 0 && up->U.height != height ) - up->U.height = height, flag = 1; + up->U.height = height, flag |= 2; if ( spendheight > 0 && up->spendheight != spendheight ) - up->spendheight = spendheight, flag = 1; + up->spendheight = spendheight, flag |= 4; if ( up->U.value == 0 && up->U.value != value ) - up->U.value = value, flag = 1; + up->U.value = value, flag |= 8; break; } } From 891215ff1611e9e4c08d9142d8e1f06e3284b7c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:16:24 +0200 Subject: [PATCH 284/520] Test --- iguana/exchanges/LP_socket.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index de90fcb96..e6a40ce38 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -472,18 +472,21 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * item = jitem(retjson,i); txid = jbits256(item,"tx_hash"); height = jint(item,"height"); - //char str[65]; printf("history txinit %s ht.%d\n",bits256_str(str,txid),height); - txobj = LP_transactioninit(coin,txid,0,0); - txobj = LP_transactioninit(coin,txid,1,txobj); - if ( txobj != 0 ) - free_json(txobj); - if ( height > 0 ) + if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { - if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + char str[65]; printf("history txinit %s ht.%d\n",bits256_str(str,txid),height); + txobj = LP_transactioninit(coin,txid,0,0); + txobj = LP_transactioninit(coin,txid,1,txobj); + if ( txobj != 0 ) + free_json(txobj); + if ( height > 0 ) { - tx->height = height; - //for (j=0; jnumvouts; j++) - // LP_address_utxoadd(coin,coinaddr,txid,j,0,height,-1); + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + tx->height = height; + //for (j=0; jnumvouts; j++) + // LP_address_utxoadd(coin,coinaddr,txid,j,0,height,-1); + } } } } From b77c53e825b0f9f93c806b225b79eeabcfd3b54f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:31:23 +0200 Subject: [PATCH 285/520] Test --- iguana/exchanges/LP_nativeDEX.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f9616e367..7684415da 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -357,7 +357,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height; bits256 zero; cJSON *array; int32_t n; + int32_t height,i,n,m; bits256 zero; cJSON *array,*item,*array2; uint64_t total,total2; if ( coin->inactive != 0 ) continue; if ( (rand() % 100) == 0 ) @@ -367,14 +367,33 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { if ( (n= cJSON_GetArraySize(array)) > 0 ) { - printf("[%s]\n\n",jprint(array,0)); + total = 0; + for (i=0; iipaddr,LP_myipaddr) != 0 && peer->errors < LP_MAXPEER_ERRORS ) { + total2 = m = 0; if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr)) != 0 ) { - printf(">>>>>>>> compare %s %s (%s)\n",coin->symbol,coin->smartaddr,retstr); + if ( (array2= cJSON_Parse(retstr)) != 0 ) + { + if ( (m= cJSON_GetArraySize(array2)) > 0 ) + { + for (i=0; i>>>>>>> compare %s %s (%.8f n%d) (%.8f m%d)\n",coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); free(retstr); } } From 6cc6f2e8778f2d6a6a5cd82e395ff6b18d2ada32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:36:12 +0200 Subject: [PATCH 286/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7684415da..9fd422cb7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -373,7 +373,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int item = jitem(array,i); total += j64bits(item,"value"); } - //printf("[%s]\n\n",jprint(array,0)); + printf("[%s]\n%s %s %.8f %d\n",jprint(array,0),coin->symbol,coin->smartaddr,dstr(total),n); HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( strcmp(peer->ipaddr,LP_myipaddr) != 0 && peer->errors < LP_MAXPEER_ERRORS ) From 15a92afd30c67035a4fa032007d4603be891e075 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:43:45 +0200 Subject: [PATCH 287/520] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++++-- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9fd422cb7..504012b05 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -373,7 +373,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int item = jitem(array,i); total += j64bits(item,"value"); } - printf("[%s]\n%s %s %.8f %d\n",jprint(array,0),coin->symbol,coin->smartaddr,dstr(total),n); + //printf("[%s]\n%s %s %.8f %d\n",jprint(array,0),coin->symbol,coin->smartaddr,dstr(total),n); HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( strcmp(peer->ipaddr,LP_myipaddr) != 0 && peer->errors < LP_MAXPEER_ERRORS ) @@ -393,7 +393,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } free_json(array2); } - printf(">>>>>>>> compare %s %s (%.8f n%d) (%.8f m%d)\n",coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); + if ( total != total || n != m ) + { + printf(">>>>>>>> compare %s %s (%.8f n%d) (%.8f m%d)\n",coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); + LP_postutxos(coin->symbol,coin->smartaddr); + } free(retstr); } } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index c42d5c3d7..a7da800ef 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -85,7 +85,7 @@ char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coi { char url[512]; sprintf(url,"http://%s:%u/api/stats/listunspent?coin=%s&address=%s",destip,destport,symbol,coinaddr); - printf("listunspent.(%s)\n",url); + //printf("listunspent.(%s)\n",url); return(LP_issue_curl("listunspent",destip,destport,url)); } From c5bfa7492c526d92f45f2b4f89b94834804bd8f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 15:51:21 +0200 Subject: [PATCH 288/520] Test --- iguana/exchanges/LP_nativeDEX.c | 11 +++++++---- iguana/exchanges/LP_ordermatch.c | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 504012b05..bb13642da 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -357,11 +357,12 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height,i,n,m; bits256 zero; cJSON *array,*item,*array2; uint64_t total,total2; + int32_t height,i,n,m,post; bits256 zero; cJSON *array,*item,*array2; uint64_t total,total2; if ( coin->inactive != 0 ) continue; if ( (rand() % 100) == 0 ) { + post = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { @@ -393,10 +394,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } free_json(array2); } - if ( total != total || n != m ) + if ( total != total2 || n != m ) { - printf(">>>>>>>> compare %s %s (%.8f n%d) (%.8f m%d)\n",coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); - LP_postutxos(coin->symbol,coin->smartaddr); + printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); + post++; } free(retstr); } @@ -405,6 +406,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } free_json(array); } + if ( post > 0 ) + LP_postutxos(coin->symbol,coin->smartaddr); } if ( coin->electrum != 0 ) continue; diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 25bb7a3e3..6ebc79aa9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -749,7 +749,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) v = jint(item,"vout"); value = LP_value_extract(item,0); height = LP_txheight(coin,txid); - char str[65]; printf("LP_listunspent_both: %s/v%d ht.%d %.8f\n",bits256_str(str,txid),v,height,dstr(value)); + //char str[65]; printf("LP_listunspent_both: %s/v%d ht.%d %.8f\n",bits256_str(str,txid),v,height,dstr(value)); LP_address_utxoadd(coin,coinaddr,txid,v,value,height,-1); } } From e49443e9be581d7db6d550c1d8b1dce6ee414cbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 16:15:01 +0200 Subject: [PATCH 289/520] Test --- iguana/exchanges/LP_nativeDEX.c | 30 +++++++++++++++++++++++------- iguana/exchanges/LP_statemachine.c | 24 ++++++++++++++++++++++++ iguana/exchanges/LP_utxo.c | 25 ------------------------- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index bb13642da..e703bed80 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -357,7 +357,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height,i,n,m,post; bits256 zero; cJSON *array,*item,*array2; uint64_t total,total2; + int32_t height,i,j,n,m,v,post; bits256 zero,txid,txid2; cJSON *array,*item,*item2,*array2; uint64_t total,total2; + memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; if ( (rand() % 100) == 0 ) @@ -387,18 +388,33 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( (m= cJSON_GetArraySize(array2)) > 0 ) { for (i=0; i>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); + for (i=0; iipaddr,jprint(item,0)); + } } + post++; } free_json(array2); } - if ( total != total2 || n != m ) - { - printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); - post++; - } free(retstr); } } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 5294b71f2..4f2e21d35 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1527,6 +1527,30 @@ char *issue_LP_clientgetutxos(char *destip,uint16_t destport,char *coin,int32_t //printf("%s clientgetutxos.(%s)\n",url,retstr); //return(retstr); } +void LP_address_monitor(struct LP_pubkeyinfo *pubp) +{ + struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; + return; + HASH_ITER(hh,LP_coins,coin,tmp) + { + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + portable_mutex_lock(&coin->addrmutex); + if ( (ap= _LP_address(coin,coinaddr)) != 0 ) + { + ap->monitor = (uint32_t)time(NULL); + } + portable_mutex_unlock(&coin->addrmutex); + if ( coin->electrum != 0 ) + { + if ( (retjson= electrum_address_subscribe(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 ) + { + printf("%s MONITOR.(%s) -> %s\n",coin->symbol,coinaddr,jprint(retjson,0)); + free_json(retjson); + } + } + } +} + /*else if ( strcmp(method,"ordermatch") == 0 ) { if ( price > SMALLVAL ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8ed5aa5e4..8afc2a18f 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -331,31 +331,6 @@ char *LP_postedutxos(cJSON *argjson) return(clonestr("{\"result\":\"success\"}")); } -/*void LP_address_monitor(struct LP_pubkeyinfo *pubp) -{ - struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; - return; - HASH_ITER(hh,LP_coins,coin,tmp) - { - bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - portable_mutex_lock(&coin->addrmutex); - if ( (ap= _LP_address(coin,coinaddr)) != 0 ) - { - ap->monitor = (uint32_t)time(NULL); - } - portable_mutex_unlock(&coin->addrmutex); - if ( coin->electrum != 0 ) - { - if ( (retjson= electrum_address_subscribe(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 ) - { - printf("%s MONITOR.(%s) -> %s\n",coin->symbol,coinaddr,jprint(retjson,0)); - free_json(retjson); - } - } - } -} -*/ - void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) { memcpy(key,txid.bytes,sizeof(txid)); From e1ae0f661cbe3875859e08777674009a27adf1a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 16:27:17 +0200 Subject: [PATCH 290/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_rpc.c | 4 ++++ iguana/exchanges/LP_utxo.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e703bed80..f20f0165f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -357,11 +357,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height,i,j,n,m,v,post; bits256 zero,txid,txid2; cJSON *array,*item,*item2,*array2; uint64_t total,total2; + int32_t height,i,j,n,m,v,post; bits256 zero,txid; cJSON *array,*item,*item2,*array2; uint64_t total,total2; memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; - if ( (rand() % 100) == 0 ) + if ( (rand() % 1000) == 0 ) { post = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index a7da800ef..9b19e18d9 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -372,6 +372,10 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) free_json(array); } } else free(hexstr); + if ( retjson == 0 ) + { + + } return(retjson); } return(cJSON_Parse("{\"error\":\"couldnt get tx\"}")); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8afc2a18f..ea9ecccb9 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -249,7 +249,7 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum DL_FOREACH_SAFE(ap->utxos,up,tmp) { //char str[65]; printf("LP_address_utxos %s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->U.height,up->spendheight); - if ( up->spendheight <= 0 ) + if ( up->spendheight <= 0 && up->U.height > 0 ) { jaddi(array,LP_address_item(coin,up,electrumret)); //printf("new array %s\n",jprint(array,0)); From 748add6a0afdb28907412e31a93a57d1807ba3e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 16:37:46 +0200 Subject: [PATCH 291/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_socket.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index d18c94000..0b36a086f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -305,6 +305,7 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); +cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout); void LP_postutxos(char *symbol,char *coinaddr); int32_t LP_listunspent_both(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index e6a40ce38..c41fe36f5 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -307,7 +307,7 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep,char *coinaddr,cJSON *array) { - int32_t i,v,n,ht,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*txobj; struct LP_transaction *tx; + int32_t i,v,n,ht,flag = 0; char str[65]; uint64_t value; bits256 txid; cJSON *item,*retjson,*txobj; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { //printf("PROCESS %s/%s %s num.%d\n",coin->symbol,ep!=0?ep->symbol:"nanolistunspent",coinaddr,n); @@ -320,6 +320,13 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep v = jint(item,"vout"); value = LP_value_extract(item,0); ht = LP_txheight(coin,txid); + if ( (retjson= LP_gettxout(coin->symbol,txid,v)) != 0 ) + free_json(retjson); + else + { + printf("external unspent has no gettxout\n"); + flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,0,1); + } } else { From 37d0db4eb16d84c80b6aaba98351539f33048faf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 16:59:51 +0200 Subject: [PATCH 292/520] Test --- iguana/exchanges/LP_commands.c | 15 +++++++++++++++ iguana/exchanges/LP_nativeDEX.c | 11 +++++++---- iguana/exchanges/LP_rpc.c | 9 +++++++++ iguana/exchanges/LP_utxo.c | 2 ++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 30424456a..14e1f6cbc 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -129,6 +129,7 @@ dividends(coin, height, )\n\ base = jstr(argjson,"base"); rel = jstr(argjson,"rel"); + coin = jstr(argjson,"coin"); if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) { if ( G.USERPASS_COUNTER == 0 ) @@ -345,6 +346,20 @@ dividends(coin, height, )\n\ retstr = LP_postedutxos(argjson); else if ( strcmp(method,"getprices") == 0 ) return(LP_prices()); + else if ( strcmp(method,"uitem") == 0 ) + { + bits256 txid; int32_t vout,height; uint64_t value; char *coinaddr; + txid = jbits256(argjson,"txid"); + vout = jint(argjson,"vout"); + height = jint(argjson,"ht"); + value = j64bits(argjson,"value"); + coinaddr = jstr(argjson,"coinaddr"); + if ( coin != 0 && coinaddr != 0 ) + { + char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",coin,coinaddr,bits256_str(str,txid),vout,dstr(value),height); + LP_address_utxoadd(LP_coinfind(coin),coinaddr,txid,vout,value,height,-1); + } + } else if ( strcmp(method,"orderbook") == 0 ) return(LP_orderbook(base,rel,jint(argjson,"duration"))); else if ( strcmp(method,"listunspent") == 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f20f0165f..74fb5f1f1 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -311,7 +311,7 @@ void command_rpcloop(void *myipaddr) int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { static uint32_t counter,numpeers; - struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0; + struct iguana_info *coin,*ctmp; char *retstr,*retstr2,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0; now = (uint32_t)time(NULL); if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; @@ -408,10 +408,13 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( j == m ) { + //5.9.253.202 missing {"tx_hash":"3ff8700d545186b1dcb29f50ccb2d1a48b9b5a36dfae59254a96a7057ca55a3f","tx_pos":1,"height":8242,"value":"1000000000"} printf("%s missing %s\n",peer->ipaddr,jprint(item,0)); + if ( (retstr2= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,v,jint(item,"height"),j64bits(item,"value"))) != 0 ) + free(retstr2); + post++; } } - post++; } free_json(array2); } @@ -422,8 +425,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } free_json(array); } - if ( post > 0 ) - LP_postutxos(coin->symbol,coin->smartaddr); + //if ( post > 0 ) + // LP_postutxos(coin->symbol,coin->smartaddr); } if ( coin->electrum != 0 ) continue; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 9b19e18d9..2d11e0ef5 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -57,6 +57,15 @@ char *issue_LP_getpeers(char *destip,uint16_t destport,char *ipaddr,uint16_t por return(retstr); } +char *issue_LP_uitem(char *destip,uint16_t destport,char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t height,uint64_t value) +{ + char url[512],*retstr,str[65]; + if ( (retstr= LP_isitme(destip,destport)) != 0 ) + return(retstr); + sprintf(url,"http://%s:%u/api/stats/uitem?coin=%s&coinaddr=%s&txid=%s&vout=%d&ht=%d&value=%llu",destip,destport,symbol,coinaddr,bits256_str(str,txid),vout,height,(long long)value); + return(LP_issue_curl("uitem",destip,destport,url)); +} + char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,uint32_t sessionid,char *rmd160str,bits256 pub) { char url[512],*retstr,str[65]; diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ea9ecccb9..473b62ae1 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -175,6 +175,8 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, { struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); + if ( coin == 0 ) + return(0); if ( spendheight > 0 ) // dont autocreate entries for spends we dont care about ap = LP_addressfind(coin,coinaddr); else ap = LP_address(coin,coinaddr); From f0f7c1d78e9c9a2e3421f018bc6d86400eacbffd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:02:33 +0200 Subject: [PATCH 293/520] Test --- iguana/exchanges/LP_commands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 14e1f6cbc..0f3acf555 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -359,6 +359,7 @@ dividends(coin, height, )\n\ char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",coin,coinaddr,bits256_str(str,txid),vout,dstr(value),height); LP_address_utxoadd(LP_coinfind(coin),coinaddr,txid,vout,value,height,-1); } + return(clonestr("{\"result\":\"success\"}")); } else if ( strcmp(method,"orderbook") == 0 ) return(LP_orderbook(base,rel,jint(argjson,"duration"))); From cc859e9357507d1a6e1a6f27b00114be13acc45c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:03:05 +0200 Subject: [PATCH 294/520] Test --- iguana/exchanges/LP_rpc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2d11e0ef5..3d87ebc8f 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -63,7 +63,9 @@ char *issue_LP_uitem(char *destip,uint16_t destport,char *symbol,char *coinaddr, if ( (retstr= LP_isitme(destip,destport)) != 0 ) return(retstr); sprintf(url,"http://%s:%u/api/stats/uitem?coin=%s&coinaddr=%s&txid=%s&vout=%d&ht=%d&value=%llu",destip,destport,symbol,coinaddr,bits256_str(str,txid),vout,height,(long long)value); - return(LP_issue_curl("uitem",destip,destport,url)); + retstr = LP_issue_curl("uitem",destip,destport,url); + printf("uitem.(%s)\n",retstr); + return(retstr); } char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,int32_t numpeers,uint32_t sessionid,char *rmd160str,bits256 pub) From 122d685016c778ec17d086a357fcd00be2a9d208 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:04:48 +0200 Subject: [PATCH 295/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 0f3acf555..6f983a9cc 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -356,7 +356,7 @@ dividends(coin, height, )\n\ coinaddr = jstr(argjson,"coinaddr"); if ( coin != 0 && coinaddr != 0 ) { - char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",coin,coinaddr,bits256_str(str,txid),vout,dstr(value),height); + //char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",coin,coinaddr,bits256_str(str,txid),vout,dstr(value),height); LP_address_utxoadd(LP_coinfind(coin),coinaddr,txid,vout,value,height,-1); } return(clonestr("{\"result\":\"success\"}")); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 3d87ebc8f..748da0614 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -64,7 +64,7 @@ char *issue_LP_uitem(char *destip,uint16_t destport,char *symbol,char *coinaddr, return(retstr); sprintf(url,"http://%s:%u/api/stats/uitem?coin=%s&coinaddr=%s&txid=%s&vout=%d&ht=%d&value=%llu",destip,destport,symbol,coinaddr,bits256_str(str,txid),vout,height,(long long)value); retstr = LP_issue_curl("uitem",destip,destport,url); - printf("uitem.(%s)\n",retstr); + //printf("uitem.(%s)\n",retstr); return(retstr); } From 05e866bd31f77711464d1744208d2fa51f3e01b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:09:28 +0200 Subject: [PATCH 296/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 74fb5f1f1..21157a645 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -415,7 +415,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int post++; } } - } + } else printf("%s matches\n",peer->ipaddr); free_json(array2); } free(retstr); From 46222bcb9da6efb71efaba25a09525440707b4a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:14:16 +0200 Subject: [PATCH 297/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 21157a645..6091795e9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -409,13 +409,13 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( j == m ) { //5.9.253.202 missing {"tx_hash":"3ff8700d545186b1dcb29f50ccb2d1a48b9b5a36dfae59254a96a7057ca55a3f","tx_pos":1,"height":8242,"value":"1000000000"} - printf("%s missing %s\n",peer->ipaddr,jprint(item,0)); + //printf("%s missing %s\n",peer->ipaddr,jprint(item,0)); if ( (retstr2= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,v,jint(item,"height"),j64bits(item,"value"))) != 0 ) free(retstr2); post++; } } - } else printf("%s matches\n",peer->ipaddr); + } //else printf("%s matches\n",peer->ipaddr); free_json(array2); } free(retstr); From 7b91d763e705c8038e6e81fb69ffba7d9b6b0e16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:22:46 +0200 Subject: [PATCH 298/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_socket.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 6ebc79aa9..d2b5d3673 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -730,8 +730,8 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) { //printf("issue path electrum.%p\n",coin->electrum); - if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) - free_json(array); + //if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) + // free_json(array); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index c41fe36f5..4681fa7aa 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -518,6 +518,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { + printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,ep,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); From ce728c5109e4aa09065ccc7cb170ab19a3d8e1de Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:26:04 +0200 Subject: [PATCH 299/520] Test --- iguana/exchanges/LP_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 4681fa7aa..af2370c41 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -361,8 +361,8 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep } if ( value != 0 || tx->height > 0 ) flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); - //printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); - } + printf("v.%d numvouts.%d %.8f (%s)\n",v,tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); + } else printf("cant find tx\n"); } } return(flag); From f728ff72df5f36723064887f7fb24cef3db67fff Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:28:18 +0200 Subject: [PATCH 300/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 473b62ae1..9b351ee1d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -464,7 +464,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS // maybe filter so only addresses we care about are using RAM if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { - //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); + printf("create txid %s numvouts.%d numvins.%d\n",bits256_str(str,txid),numvouts,numvins); for (i=0; i Date: Fri, 22 Sep 2017 17:32:18 +0200 Subject: [PATCH 301/520] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6091795e9..84615a2b0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -395,7 +395,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( total != total2 || n != m ) { - printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); for (i=0; i>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); } //else printf("%s matches\n",peer->ipaddr); free_json(array2); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 9b351ee1d..f68f112ec 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -210,7 +210,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, portable_mutex_unlock(&coin->addrmutex); retval = 1; char str[65]; - if ( 0 && height > 0 ) + if ( height > 0 ) printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } From 8c2b15532cf6cb0064e076b14d80abd37438ec9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:34:40 +0200 Subject: [PATCH 302/520] Test --- iguana/exchanges/LP_utxo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f68f112ec..fce5339bd 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -173,8 +173,8 @@ struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coina int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { - struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; - //printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); + struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; char str[65]; + //printf("%s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); if ( coin == 0 ) return(0); if ( spendheight > 0 ) // dont autocreate entries for spends we dont care about @@ -194,6 +194,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, up->spendheight = spendheight, flag |= 4; if ( up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; + printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); break; } } @@ -209,11 +210,10 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); retval = 1; - char str[65]; if ( height > 0 ) printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } - } + } else printf("cant get ap %s %s\n",coin->symbol,coinaddr); //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); return(retval); } From e3372f328887e326d2c70820126a88642be1442d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:40:36 +0200 Subject: [PATCH 303/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index d2b5d3673..a0964d57b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -962,7 +962,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr printf("ordermatch %.8f %.8f %.8f txfees (%.8f %.8f)\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp),dstr(txfee),dstr(desttxfee)); break; } - } else printf("no unspents %s\n",bits256_str(str,pubkey)); + } else printf("no unspents %s %s %s\n",base,coinaddr,bits256_str(str,pubkey)); } else printf("self trading or blacklisted peer\n"); } else diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 748da0614..3e683545c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -486,7 +486,10 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) if ( (coin= LP_coinfind(symbol)) != 0 ) { if ( coin->electrum != 0 ) - retjson = electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr); + { + if ( (retjson= electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)) != 0 ) + n = cJSON_GetArraySize(retjson); + } else { if ( strcmp(coin->smartaddr,coinaddr) == 0 ) @@ -503,7 +506,9 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { n = cJSON_GetArraySize(retjson); if ( electrum_process_array(coin,0,coinaddr,retjson) != 0 ) - LP_postutxos(symbol,coinaddr); // might be good to not saturate + { + //LP_postutxos(symbol,coinaddr); // might be good to not saturate + } } } //printf("issue listunspent %s (%s)\n",coinaddr,jprint(retjson,0)); From 748986f3f9a0fe4baf8b0f593c51f7770fbb5919 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:43:06 +0200 Subject: [PATCH 304/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_socket.c | 4 ++-- iguana/exchanges/LP_utxo.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a0964d57b..8a82fcca0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -755,7 +755,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) } } } - } else printf("%s coin.%p inactive.%d\n",symbol,coin,coin!=0?coin->inactive:-1); + } //else printf("%s coin.%p inactive.%d\n",symbol,coin,coin!=0?coin->inactive:-1); return(n); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index af2370c41..81d7a83bb 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -361,8 +361,8 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep } if ( value != 0 || tx->height > 0 ) flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); - printf("v.%d numvouts.%d %.8f (%s)\n",v,tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); - } else printf("cant find tx\n"); + //printf("v.%d numvouts.%d %.8f (%s)\n",v,tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); + } //else printf("cant find tx\n"); } } return(flag); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fce5339bd..a9098c199 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -194,7 +194,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, up->spendheight = spendheight, flag |= 4; if ( up->U.value == 0 && up->U.value != value ) up->U.value = value, flag |= 8; - printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); + //printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); break; } } @@ -210,10 +210,10 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); retval = 1; - if ( height > 0 ) + if ( 0 && height > 0 ) printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } - } else printf("cant get ap %s %s\n",coin->symbol,coinaddr); + } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); return(retval); } @@ -464,7 +464,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS // maybe filter so only addresses we care about are using RAM if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { - printf("create txid %s numvouts.%d numvins.%d\n",bits256_str(str,txid),numvouts,numvins); + //printf("create txid %s numvouts.%d numvins.%d\n",bits256_str(str,txid),numvouts,numvins); for (i=0; i Date: Fri, 22 Sep 2017 17:44:48 +0200 Subject: [PATCH 305/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 81d7a83bb..6afb10ba1 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -518,7 +518,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,ep,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); From a1f80c3b8d9671f0b3448257ed6637e3e9ab7011 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 17:53:21 +0200 Subject: [PATCH 306/520] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 8a82fcca0..927b9998e 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -918,9 +918,9 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(jprint(bestitem,0)); } -struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) +struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; + bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; struct LP_utxoinfo *bestutxo = 0; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -951,7 +951,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *bestutxo,double *ordermatchpr n = LP_listunspent_both(base,coinaddr); if ( n > 1 ) { - if ( (bestutxo= LP_address_utxopair(bestutxo,utxos,max,basecoin,coinaddr,txfee,dstr(autxo->S.satoshis),price,0,desttxfee)) != 0 ) + if ( (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(autxo->S.satoshis),price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From 15b8cf0666ce89127737b3ebc93f9016bf76f5c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 18:14:22 +0200 Subject: [PATCH 307/520] Test --- iguana/exchanges/LP_include.h | 4 ++-- iguana/exchanges/LP_ordermatch.c | 13 +++---------- iguana/exchanges/LP_utxo.c | 4 +++- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0b36a086f..ab04eab46 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -45,8 +45,8 @@ #define LP_SWAPSTEP_TIMEOUT 30 #define LP_AUTOTRADE_TIMEOUT 60 #define LP_MIN_TXFEE 10000 -#define LP_MINVOL 10 -#define LP_MINCLIENTVOL 20 +#define LP_MINVOL 20 +#define LP_MINCLIENTVOL 50 #define LP_MINSIZE_TXFEEMULT 10 #define LP_REQUIRED_TXFEE 0.9 diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 927b9998e..0e0741a25 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -308,6 +308,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str return(-14); if ( butxo != 0 ) { + //qprice 2259.01692494 <- 10.34279604/0.00457845 txfees.(0.00042631 0.00010000) vs (0.00042791 0.00010000) if ( qp->satoshis < (srcvalue / LP_MINVOL) || srcvalue < qp->txfee*LP_MINSIZE_TXFEEMULT ) { printf("utxo payment %.8f is less than %f covered by Q %.8f or <10x txfee %.8f\n",dstr(srcvalue),1./LP_MINVOL,dstr(qp->satoshis),dstr(qp->txfee)); @@ -467,7 +468,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre printf("%.8f ",dstr(utxos[i]->U.value)); printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); } - if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL ) { up = utxos[mini]; utxos[mini] = 0; @@ -499,7 +500,6 @@ struct LP_utxoinfo *_LP_butxo_find(struct LP_utxoinfo *butxo) { int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); //portable_mutex_lock(&LP_butxomutex); - printf("_LP_butxo_find\n"); for (i=0; iT.swappending,srcutxo->T.swappending); destutxo->S = srcutxo->S; destutxo->T = srcutxo->T; } @@ -548,7 +544,6 @@ void LP_butxo_swapfields_copy(struct LP_utxoinfo *destutxo,struct LP_utxoinfo *s void LP_butxo_swapfields(struct LP_utxoinfo *butxo) { struct LP_utxoinfo *getutxo=0; - printf("swapfields\n"); portable_mutex_lock(&LP_butxomutex); if ( (getutxo= _LP_butxo_find(butxo)) != 0 ) LP_butxo_swapfields_copy(butxo,getutxo); @@ -558,11 +553,9 @@ void LP_butxo_swapfields(struct LP_utxoinfo *butxo) void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) { struct LP_utxoinfo *setutxo; - printf("swapfields set\n"); if ( (setutxo= LP_butxo_add(butxo)) != 0 ) { LP_butxo_swapfields_copy(setutxo,butxo); - printf("LP_butxo_swapfields_copy set\n"); } } @@ -944,7 +937,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice if ( LP_pricevalid(price) > 0 && price <= maxprice ) { pubkey = jbits256(item,"pubkey"); - printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); + //printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a9098c199..549d774e7 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -344,7 +344,9 @@ struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) struct LP_utxoinfo *utxo=0; uint8_t key[sizeof(txid) + sizeof(vout)]; if ( iambob != 0 ) { - printf("_LP_utxofind deprecated iambob\n"); + static uint32_t counter; + if ( counter++ < 3 ) + printf("_LP_utxofind deprecated iambob\n"); return(0); } LP_utxosetkey(key,txid,vout); From 47c99040d1f6ffd0f2beca6db37226b49078d758 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 19:00:13 +0200 Subject: [PATCH 308/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_scan.c | 4 +++- iguana/exchanges/LP_socket.c | 3 +-- iguana/exchanges/LP_swap.c | 8 ++++---- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 84615a2b0..3b5c8a8d7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -414,7 +414,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int post++; } } - if ( post != 0 ) + if ( 0 && post != 0 ) printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); } //else printf("%s matches\n",peer->ipaddr); free_json(array2); diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 9f65fa7ef..f50df4b1f 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -481,7 +481,9 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int struct LP_address_utxo *up; if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) { - char str[65]; printf("address_utxofind found confirmed %s %s ht.%d vs %d\n",symbol,bits256_str(str,txid),up->U.height,coin->height); + char str[65]; printf("address_utxofind found confirmed %s %s %s ht.%d vs %d\n",symbol,coinaddr,bits256_str(str,txid),up->U.height,coin->height); + if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) + free_json(array); if ( coin->height >= up->U.height ) numconfirms = (coin->height - up->U.height + 1); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 6afb10ba1..6682a782d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -491,8 +491,7 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * if ( (tx= LP_transactionfind(coin,txid)) != 0 ) { tx->height = height; - //for (j=0; jnumvouts; j++) - // LP_address_utxoadd(coin,coinaddr,txid,j,0,height,-1); + LP_address_utxoadd(coin,addr,txid,0,0,height,-1); } } } diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index dab03cc91..9c27b1dce 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -733,7 +733,7 @@ void LP_bobloop(void *_swap) else m = 1; while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice { - char str[65];printf("%d waiting for alicepayment to be confirmed.%d %s %s\n",n,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",swap->alicepayment.I.destaddr,n,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(3); } if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) @@ -786,7 +786,7 @@ void LP_aliceloop(void *_swap) else m = 1; while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) { - char str[65];printf("%d waiting for alicepayment to be confirmed.%d %s %s\n",n,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",n,swap->alicepayment.I.destaddr,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(10); } swap->sentflag = 1; @@ -796,14 +796,14 @@ void LP_aliceloop(void *_swap) { while ( (n= LP_numconfirms(swap->bobcoin.symbol,swap->bobpayment.I.destaddr,swap->bobpayment.I.signedtxid,0,1)) < swap->I.bobconfirms ) { - char str[65];printf("%d waiting for bobpayment to be confirmed.%d %s %s\n",n,swap->I.bobconfirms,swap->bobcoin.symbol,bits256_str(str,swap->bobpayment.I.signedtxid)); + char str[65];printf("%d waiting for bobpayment %s to be confirmed.%d %s %s\n",n,swap->bobpayment.I.destaddr,swap->I.bobconfirms,swap->bobcoin.symbol,bits256_str(str,swap->bobpayment.I.signedtxid)); sleep(LP_SWAPSTEP_TIMEOUT); } if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 ) printf("error sending alicespend\n"); while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicespend.I.destaddr,swap->alicespend.I.signedtxid,0,1)) < swap->I.aliceconfirms ) { - char str[65];printf("%d waiting for alicespend to be confirmed.%d %s %s\n",n,swap->I.aliceconfirms,swap->bobcoin.symbol,bits256_str(str,swap->alicespend.I.signedtxid)); + char str[65];printf("%d waiting for alicespend %s to be confirmed.%d %s %s\n",n,swap->alicespend.I.destaddr,swap->I.aliceconfirms,swap->bobcoin.symbol,bits256_str(str,swap->alicespend.I.signedtxid)); sleep(LP_SWAPSTEP_TIMEOUT); } if ( swap->N.pair >= 0 ) From 46821e6124d49e2d81caa70560a7e2009bfdbbee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 19:01:18 +0200 Subject: [PATCH 309/520] Test --- iguana/exchanges/LP_swap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 9c27b1dce..de83c61dd 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -733,7 +733,7 @@ void LP_bobloop(void *_swap) else m = 1; while ( (n= LP_numconfirms(swap->alicecoin.symbol,swap->alicepayment.I.destaddr,swap->alicepayment.I.signedtxid,0,1)) < m ) // sync with alice { - char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",swap->alicepayment.I.destaddr,n,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); + char str[65];printf("%d waiting for alicepayment %s to be confirmed.%d %s %s\n",n,swap->alicepayment.I.destaddr,1,swap->alicecoin.symbol,bits256_str(str,swap->alicepayment.I.signedtxid)); sleep(3); } if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000,0) == 0 ) From 437de9d6a0f679b2b5c816d6472e9b6611d0d1c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 19:18:10 +0200 Subject: [PATCH 310/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0e0741a25..7af723c6e 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -297,7 +297,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str } if ( butxo != 0 && srcvalue < qp->txfee+qp->satoshis ) { - printf("srcvalue %.8f satoshis %.8f is too small txfee %.8f?\n",dstr(srcvalue),dstr(qp->satoshis),dstr(qp->txfee)); + printf("srcvalue %.8f [%.8f] satoshis %.8f is too small txfee %.8f?\n",dstr(srcvalue),dstr(srcvalue) - dstr(qp->txfee+qp->satoshis),dstr(qp->satoshis),dstr(qp->txfee)); return(-33); } if ( qp->satoshis != 0 ) From 8d487e2cd32d9b9988aa569723e275c029f1a45e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 00:44:37 +0200 Subject: [PATCH 311/520] # --- iguana/exchanges/electrum.chips | 2 ++ iguana/exchanges/electrum.chips2 | 2 ++ iguana/exchanges/install | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100755 iguana/exchanges/electrum.chips create mode 100755 iguana/exchanges/electrum.chips2 diff --git a/iguana/exchanges/electrum.chips b/iguana/exchanges/electrum.chips new file mode 100755 index 000000000..be36abd88 --- /dev/null +++ b/iguana/exchanges/electrum.chips @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CHIPS\",\"ipaddr\":\"173.212.225.176\",\"port\":50076}" diff --git a/iguana/exchanges/electrum.chips2 b/iguana/exchanges/electrum.chips2 new file mode 100755 index 000000000..72e3f2f70 --- /dev/null +++ b/iguana/exchanges/electrum.chips2 @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CHIPS\",\"ipaddr\":\"136.243.45.140\",\"port\":50076}" diff --git a/iguana/exchanges/install b/iguana/exchanges/install index bda13d6ef..3b1981f97 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,4 +1,4 @@ cp electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . -echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir +#echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir From ff2907f8a639bbd970af14508a2c3d947442b39a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 15:23:09 +0200 Subject: [PATCH 312/520] Fixes --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_ordermatch.c | 39 +++++++++++++-------- iguana/exchanges/LP_rpc.c | 29 +++++++++++----- iguana/exchanges/LP_scan.c | 57 +++++++++++++++++-------------- iguana/exchanges/LP_transaction.c | 23 +++++++++++-- iguana/exchanges/LP_utxo.c | 4 +-- 6 files changed, 101 insertions(+), 52 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index ab04eab46..0cae842bf 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -311,6 +311,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); int32_t LP_butxo_findeither(bits256 txid,int32_t vout); cJSON *LP_listunspent(char *symbol,char *coinaddr); +int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid); #endif diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7af723c6e..192e95976 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -454,26 +454,31 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t return(mini); } +uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t desttxfee) +{ + return(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee); +} + struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,int32_t avoidflag,uint64_t desttxfee) { - struct LP_address *ap; uint64_t targetval; int32_t m,mini; struct LP_address_utxo *up,*up2; + struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (m= LP_address_utxo_ptrs(utxos,max,ap,avoidflag)) > 1 ) { - targetval = SATOSHIDEN * ((volume + dstr(desttxfee)) / price) + 2*txfee; + targetval = LP_basesatoshis(volume,price,txfee,desttxfee); { int32_t i; for (i=0; iU.value)); printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); } - if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL ) + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL-1 ) { up = utxos[mini]; utxos[mini] = 0; - targetval = (up->U.value / 8) * 9 + 2*txfee; - if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 ) + targetval2 = (up->U.value / 8) * 9 + 2*txfee; + if ( (mini= LP_nearest_utxovalue(utxos,m,targetval2)) >= 0 ) { if ( up != 0 && (up2= utxos[mini]) != 0 ) { @@ -486,7 +491,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre utxo->deposit.txid = up2->U.txid; utxo->deposit.vout = up2->U.vout; utxo->deposit.value = up2->U.value; - utxo->S.satoshis = SATOSHIDEN * (volume / price); + utxo->S.satoshis = targetval; return(utxo); } } @@ -911,9 +916,9 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(jprint(bestitem,0)); } -struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,double relvolume,char *gui) +struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui) { - bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; struct LP_utxoinfo *bestutxo = 0; + bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; uint64_t basesatoshis; struct LP_utxoinfo *bestutxo = 0; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -944,11 +949,11 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice n = LP_listunspent_both(base,coinaddr); if ( n > 1 ) { - if ( (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(autxo->S.satoshis),price,0,desttxfee)) != 0 ) + basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); + if ( (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis),price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - //autxo->S.satoshis = bestutxo->S.satoshis * price - desttxfee; *bestsatoshisp = bestutxo->S.satoshis; *ordermatchpricep = price; *bestdestsatoshisp = autxo->S.satoshis; @@ -980,7 +985,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice 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) { - uint64_t desttxfee,txfee; int64_t bestsatoshis=0,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_best,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; + uint64_t desttxfee,txfee; int64_t bestsatoshis=0,destsatoshis,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_bestB,_bestA,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; printf("LP_autobuy %s/%s price %.8f vol %.8f\n",base,rel,maxprice,relvolume); if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; @@ -989,10 +994,16 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); LP_txfees(&txfee,&desttxfee,base,rel); - if ( (autxo= LP_utxo_bestfit(rel,SATOSHIDEN * relvolume + desttxfee)) == 0 ) + memset(&_bestA,0,sizeof(_bestA)); + memset(&_bestB,0,sizeof(_bestB)); + destsatoshis = SATOSHIDEN * relvolume + desttxfee; + if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); - memset(&_best,0,sizeof(_best)); - if ( (bestutxo= LP_buyutxo(&_best,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,relvolume,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + _bestA = *autxo; + autxo = &_bestA; + if ( destsatoshis < autxo->S.satoshis ) + autxo->S.satoshis = destsatoshis; + if ( (bestutxo= LP_buyutxo(&_bestB,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) { printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 3e683545c..aaabcc46f 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -626,7 +626,7 @@ double LP_getestimatedrate(struct iguana_info *coin) char *LP_sendrawtransaction(char *symbol,char *signedtx) { - cJSON *array; char *paramstr,*tmpstr,*retstr=0; int32_t n; cJSON *retjson; struct iguana_info *coin; + cJSON *array,*errobj; char *paramstr,*tmpstr,*retstr=0; int32_t n,alreadyflag = 0; cJSON *retjson; struct iguana_info *coin; if ( symbol == 0 || symbol[0] == 0 ) return(0); coin = LP_coinfind(symbol); @@ -646,14 +646,27 @@ char *LP_sendrawtransaction(char *symbol,char *signedtx) if ( (retjson= electrum_sendrawtransaction(symbol,coin->electrum,&retjson,signedtx)) != 0 ) { retstr = jprint(retjson,1); - printf("electrum sendrawtx.(%s) -> %s\n",signedtx,retstr); - n = (int32_t)strlen(retstr); - if ( retstr[0] == '"' && retstr[n-1] == '"' ) + //electrum sendrawtx (the transaction was rejected by network rules.\n\ntransaction already in block chain) + if ( strstr(retstr,"already in block") != 0 ) + alreadyflag = 1; + printf("electrum sendrawtx.(%s) -> %s already.%d\n",signedtx,retstr,alreadyflag); + if ( alreadyflag != 0 ) { - retstr[n-1] = 0; - tmpstr = clonestr(retstr+1); - free(retstr); - retstr = tmpstr; + errobj = cJSON_CreateObject(); + jaddstr(errobj,"error","rejected"); + jaddnum(errobj,"code",-27); + retstr = jprint(errobj,1); + } + else + { + n = (int32_t)strlen(retstr); + if ( retstr[0] == '"' && retstr[n-1] == '"' ) + { + retstr[n-1] = 0; + tmpstr = clonestr(retstr+1); + free(retstr); + retstr = tmpstr; + } } } } diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index f50df4b1f..2af0d9f9f 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -452,46 +452,53 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int expiration = (uint32_t)time(NULL) + duration; while ( 1 ) { - if ( coin->electrum == 0 ) - { - if ( LP_mempoolscan(symbol,txid) >= 0 ) - return(0); - } + if ( LP_gettx_presence(symbol,txid) != 0 ) + numconfirms = 0; else { - if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 ) + if ( coin->electrum == 0 ) + { + if ( LP_mempoolscan(symbol,txid) >= 0 ) + numconfirms = 0; + } + else { - char str[65]; printf("check %s mempool.(%s)\n",bits256_str(str,txid),jprint(array,0)); - if ( (n= cJSON_GetArraySize(array)) > 0 ) + if ( (array= electrum_address_getmempool(symbol,coin->electrum,&array,coinaddr)) != 0 ) { - for (i=0; i 0 ) { - item = jitem(array,i); - if ( bits256_cmp(txid,jbits256(item,"tx_hash")) == 0 ) + for (i=0; isymbol,coinaddr); + struct LP_address_utxo *up; + if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) + { + char str[65]; printf("address_utxofind found confirmed %s %s %s ht.%d vs %d\n",symbol,coinaddr,bits256_str(str,txid),up->U.height,coin->height); + if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) + free_json(array); + if ( coin->height >= up->U.height ) + numconfirms = (coin->height - up->U.height + 1); } - free(array); - } - LP_listunspent_issue(coin->symbol,coinaddr); - struct LP_address_utxo *up; - if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) - { - char str[65]; printf("address_utxofind found confirmed %s %s %s ht.%d vs %d\n",symbol,coinaddr,bits256_str(str,txid),up->U.height,coin->height); - if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) - free_json(array); - if ( coin->height >= up->U.height ) - numconfirms = (coin->height - up->U.height + 1); } } if ( time(NULL) > expiration || numconfirms >= 0 ) break; usleep(500000); } + if ( numconfirms <= 0 ) + numconfirms = LP_numconfirms(symbol,coinaddr,txid,vout,1); return(numconfirms); } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 073c947a0..f93374066 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -19,13 +19,31 @@ // marketmaker // +int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid) +{ + cJSON *txobj; bits256 txid; int32_t flag = 0; + if ( (txobj= LP_gettx(symbol,expectedtxid)) != 0 ) + { + txid = jbits256(txobj,"txid"); + if ( jobj(txobj,"error") == 0 && bits256_cmp(txid,expectedtxid) == 0 ) + { + char str[65]; printf("%s already in gettx (%s)\n",bits256_str(str,txid),jprint(txobj,0)); + flag = 1; + } + free_json(txobj); + } + return(flag); +} + bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxid) { char *retstr; bits256 txid; cJSON *retjson,*errorobj; int32_t i,sentflag = 0; memset(&txid,0,sizeof(txid)); - for (i=0; i<1; i++) + for (i=0; i<2; i++) { - if ( (retstr= LP_sendrawtransaction(symbol,txbytes)) != 0 ) + if ( sentflag == 0 && LP_gettx_presence(symbol,expectedtxid) != 0 ) + sentflag = 1; + if ( sentflag == 0 && (retstr= LP_sendrawtransaction(symbol,txbytes)) != 0 ) { if ( is_hexstr(retstr,0) == 64 ) { @@ -50,6 +68,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi } if ( sentflag != 0 ) break; + sleep(3); } return(txid); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 549d774e7..00b361531 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -542,7 +542,6 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid) int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool) { struct iguana_info *coin; int32_t ht,numconfirms = 100; - //#ifndef BASILISK_DISABLEWAITTX cJSON *txobj; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) return(-1); @@ -560,14 +559,13 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int else { if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) - numconfirms = (LP_getheight(coin) - ht); + numconfirms = (LP_getheight(coin) - ht + 1); else if ( mempool != 0 ) { if (LP_waitmempool(symbol,coinaddr,txid,vout,30) >= 0 ) numconfirms = 0; } } - //#endif return(numconfirms); } From 5ba2d0e1aa700f250340a51f6a4aec6fa347d558 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 15:40:24 +0200 Subject: [PATCH 313/520] Test --- iguana/exchanges/LP_ordermatch.c | 42 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 192e95976..b5ff74124 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -916,9 +916,9 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(jprint(bestitem,0)); } -struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui) +struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui,bits256 *avoids,int32_t numavoids) { - bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; uint64_t basesatoshis; struct LP_utxoinfo *bestutxo = 0; + bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,j,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; uint64_t basesatoshis; struct LP_utxoinfo *bestutxo = 0; *ordermatchpricep = 0.; *bestsatoshisp = *bestdestsatoshisp = 0; basecoin = LP_coinfind(base); @@ -942,6 +942,11 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice if ( LP_pricevalid(price) > 0 && price <= maxprice ) { pubkey = jbits256(item,"pubkey"); + for (j=0; jS.satoshis ) autxo->S.satoshis = destsatoshis; - if ( (bestutxo= LP_buyutxo(&_bestB,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + while ( 1 ) { - printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); - return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); - } - if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); - if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 ) - return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); - if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) - { - printf("quote validate error %.0f\n",qprice); - return(clonestr("{\"error\":\"quote validation error\"}")); + if ( (bestutxo= LP_buyutxo(&_bestB,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui,pubkeys,numpubs)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + { + printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); + return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); + } + pubkeys[numpubs++] = bestutxo->pubkey; + if ( LP_quoteinfoinit(&Q,bestutxo,rel,ordermatchprice,bestsatoshis,bestdestsatoshis) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote\"}")); + if ( LP_quotedestinfo(&Q,autxo->payment.txid,autxo->payment.vout,autxo->fee.txid,autxo->fee.vout,G.LP_mypub25519,autxo->coinaddr) < 0 ) + return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); + if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) + { + printf("quote validate error %.0f\n",qprice); + continue; + //return(clonestr("{\"error\":\"quote validation error\"}")); + } + break; } //printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); From 3568e90bbb3a50f2efc0990c97f194875ab58abb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 15:52:39 +0200 Subject: [PATCH 314/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b5ff74124..8e6b58346 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -928,7 +928,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice return(0); utxos = calloc(max,sizeof(*utxos)); LP_txfees(&txfee,&desttxfee,base,autxo->coin); - printf("LP_buyutxo %s/%s %.8f %.8f\n",base,autxo->coin,dstr(txfee),dstr(desttxfee)); + printf("LP_buyutxo maxprice %.8f relvol %.8f %s/%s %.8f %.8f\n",maxprice,dstr(autxo->S.satoshis),base,autxo->coin,dstr(txfee),dstr(desttxfee)); if ( (obookstr= LP_orderbook(base,autxo->coin,duration)) != 0 ) { if ( (orderbook= cJSON_Parse(obookstr)) != 0 ) @@ -959,7 +959,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); - *bestsatoshisp = bestutxo->S.satoshis; + *bestsatoshisp = basesatoshis; *ordermatchpricep = price; *bestdestsatoshisp = autxo->S.satoshis; printf("ordermatch %.8f %.8f %.8f txfees (%.8f %.8f)\n",price,dstr(*bestsatoshisp),dstr(*bestdestsatoshisp),dstr(txfee),dstr(desttxfee)); From 110460e6f0238db8e39bd57b3ff1a595f2b22580 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 15:59:20 +0200 Subject: [PATCH 315/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 8e6b58346..944bb51ac 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -260,6 +260,7 @@ int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp,struct LP_utxoinfo *autxo, double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp,int32_t iambob) { double qprice=0.; uint64_t txfee,desttxfee,srcvalue=0,srcvalue2=0,destvalue=0,destvalue2=0; + printf("quote %s %.8f -> %s %.8f\n",qp->srccoin,dstr(qp->satoshis),qp->destcoin,dstr(qp->destsatoshis)); if ( butxo != 0 ) { if (LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) @@ -456,6 +457,7 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t desttxfee) { + printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee),relvolume,price); return(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee); } @@ -1024,6 +1026,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); +exit(-1); continue; //return(clonestr("{\"error\":\"quote validation error\"}")); } From 7eac682ea1fb6fc98939346ebaa863cb7595b655 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:09:07 +0200 Subject: [PATCH 316/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 6f983a9cc..d9915c479 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -237,7 +237,7 @@ dividends(coin, height, )\n\ { if ( price > SMALLVAL ) { - return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")*price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")/price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } From b099fdba4cafbc2b94227a391d66035e399fb980 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:16:29 +0200 Subject: [PATCH 317/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d9915c479..6f983a9cc 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -237,7 +237,7 @@ dividends(coin, height, )\n\ { if ( price > SMALLVAL ) { - return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")/price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")*price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } From 99fe7be3d38bfb86ac4dff40b21f070d25abbd10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:17:13 +0200 Subject: [PATCH 318/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 6f983a9cc..d65652d86 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -237,7 +237,7 @@ dividends(coin, height, )\n\ { if ( price > SMALLVAL ) { - return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume")*price,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"))); } else return(clonestr("{\"error\":\"no price set\"}")); } } From 7d4d25a855194c98597c6c3bd4b5ac4fd9f225e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:26:21 +0200 Subject: [PATCH 319/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index aaabcc46f..8c626beea 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -604,7 +604,7 @@ double LP_getestimatedrate(struct iguana_info *coin) { if ( coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { - sprintf(buf,"[%d]",6); + sprintf(buf,"[%d]",3); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { if ( retstr[0] != '-' ) From ccd17f629f15879b30517d47b18d42cb8b7db386 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:28:25 +0200 Subject: [PATCH 320/520] Test --- iguana/exchanges/LP_rpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 8c626beea..4cf3fbe59 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -613,6 +613,8 @@ double LP_getestimatedrate(struct iguana_info *coin) if ( rate < 0.00000020 ) rate = 0.00000020; coin->rate = rate * 1.25; + if ( coin->electrum != 0 ) + coin->rate *= 2; coin->ratetime = (uint32_t)time(NULL); if ( (rand() % 10) == 0 ) printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); From b1f66fe018f0964996a3c87a01056ce6063971e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:36:25 +0200 Subject: [PATCH 321/520] Test --- iguana/exchanges/LP_rpc.c | 2 -- iguana/exchanges/LP_utxo.c | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 4cf3fbe59..8c626beea 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -613,8 +613,6 @@ double LP_getestimatedrate(struct iguana_info *coin) if ( rate < 0.00000020 ) rate = 0.00000020; coin->rate = rate * 1.25; - if ( coin->electrum != 0 ) - coin->rate *= 2; coin->ratetime = (uint32_t)time(NULL); if ( (rand() % 10) == 0 ) printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 00b361531..ca6e6f352 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -626,12 +626,16 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) if ( coinaddr == 0 ) coinaddr = _coinaddr; LP_destaddr(coinaddr,txobj); - free_json(txobj); //printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); if ( value != 0 ) + { + free_json(txobj); return(value); + } } - printf("pruned node? LP_txvalue couldnt find %s tx %s/v%d\n",coin->symbol,bits256_str(str,txid),vout); + printf("pruned node? LP_txvalue couldnt find %s tx %s/v%d (%s)\n",coin->symbol,bits256_str(str,txid),vout,txobj!=0?jprint(txobj,0):""); + if ( txobj != 0 ) + free_json(txobj); } return(0); } From 36e4d8b14dc08e07d3e35756347eb50aac1283d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:41:04 +0200 Subject: [PATCH 322/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 944bb51ac..b1f3a221e 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -469,6 +469,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre if ( (m= LP_address_utxo_ptrs(utxos,max,ap,avoidflag)) > 1 ) { targetval = LP_basesatoshis(volume,price,txfee,desttxfee); + if ( 0 ) { int32_t i; for (i=0; iU.value / 8) * 9 + 2*txfee; + printf("targetval %.8f, found val %.8f | targetval2 %.8f\n",dstr(targetval),dstr(up->U.value),dstr(targetval2)); if ( (mini= LP_nearest_utxovalue(utxos,m,targetval2)) >= 0 ) { if ( up != 0 && (up2= utxos[mini]) != 0 ) From ac76eebdc68a7e355cc2ac761b780a65a21acb9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 16:48:15 +0200 Subject: [PATCH 323/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b1f3a221e..ba5f5ec7d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -481,7 +481,6 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre up = utxos[mini]; utxos[mini] = 0; targetval2 = (up->U.value / 8) * 9 + 2*txfee; - printf("targetval %.8f, found val %.8f | targetval2 %.8f\n",dstr(targetval),dstr(up->U.value),dstr(targetval2)); if ( (mini= LP_nearest_utxovalue(utxos,m,targetval2)) >= 0 ) { if ( up != 0 && (up2= utxos[mini]) != 0 ) @@ -496,6 +495,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre utxo->deposit.vout = up2->U.vout; utxo->deposit.value = up2->U.value; utxo->S.satoshis = targetval; + printf("targetval %.8f, found val %.8f | targetval2 %.8f val2 %.8f\n",dstr(targetval),dstr(up->U.value),dstr(targetval2),dstr(up2->U.value)); return(utxo); } } @@ -959,7 +959,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice if ( n > 1 ) { basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); - if ( (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis),price,0,desttxfee)) != 0 ) + if ( (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); From aa8ddd7107a67f0f1f8ad36fc058e4f472df30ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:01:01 +0200 Subject: [PATCH 324/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 8c626beea..93d1f524c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime+60 ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime ) { sprintf(buf,"[%d]",3); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) From b489e4d0fb01a64e6505a8acae456db39dec6344 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:04:36 +0200 Subject: [PATCH 325/520] Test --- iguana/exchanges/LP_rpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 93d1f524c..9bf2a0894 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime+3 ) { sprintf(buf,"[%d]",3); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) @@ -614,7 +614,7 @@ double LP_getestimatedrate(struct iguana_info *coin) rate = 0.00000020; coin->rate = rate * 1.25; coin->ratetime = (uint32_t)time(NULL); - if ( (rand() % 10) == 0 ) + //if ( (rand() % 10) == 0 ) printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); } free(retstr); From eef5a1a73a93d3cb4ae6694b92f5c5ab41f9969f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:06:23 +0200 Subject: [PATCH 326/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ba5f5ec7d..dea7a0c75 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -304,6 +304,10 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str if ( qp->satoshis != 0 ) qprice = ((double)qp->destsatoshis / qp->satoshis); LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); + if ( txfee < qp->txfee ) + qp->txfee = txfee; + if ( desttxfee < qp->desttxfee ) + qp->desttxfee = desttxfee; printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee ) return(-14); From 9eb88737f0c04785a329f40cc8560415261d4ce8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:12:00 +0200 Subject: [PATCH 327/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index dea7a0c75..24ea79c7f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -305,9 +305,9 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str qprice = ((double)qp->destsatoshis / qp->satoshis); LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); if ( txfee < qp->txfee ) - qp->txfee = txfee; + txfee = qp->txfee; if ( desttxfee < qp->desttxfee ) - qp->desttxfee = desttxfee; + desttxfee = qp->desttxfee; printf("qprice %.8f <- %.8f/%.8f txfees.(%.8f %.8f) vs (%.8f %.8f)\n",qprice,dstr(qp->destsatoshis),dstr(qp->satoshis),dstr(qp->txfee),dstr(qp->desttxfee),dstr(txfee),dstr(desttxfee)); if ( qp->txfee < LP_REQUIRED_TXFEE*txfee || qp->desttxfee < LP_REQUIRED_TXFEE*desttxfee ) return(-14); From 697a807d83ba1df2394e5e8af4956ac6f2960a60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:14:18 +0200 Subject: [PATCH 328/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 24ea79c7f..7f4ddeed1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -39,6 +39,7 @@ void LP_txfees(uint64_t *txfeep,uint64_t *desttxfeep,char *base,char *rel) { *txfeep = LP_txfeecalc(LP_coinfind(base),0); *desttxfeep = LP_txfeecalc(LP_coinfind(rel),0); + printf("LP_txfees(%.8f %.8f)\n",dstr(*txfeep),dstr(*desttxfeep)); } double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee) From e3734626931141b38ac63b317eb197f90d5c5869 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:18:50 +0200 Subject: [PATCH 329/520] Test --- iguana/exchanges/LP_rpc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 9bf2a0894..2f375cfd0 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -612,10 +612,11 @@ double LP_getestimatedrate(struct iguana_info *coin) rate = atof(retstr) / 1024.; if ( rate < 0.00000020 ) rate = 0.00000020; - coin->rate = rate * 1.25; + rate *= 1.25; + coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); //if ( (rand() % 10) == 0 ) - printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate); + printf("estimated rate.(%s) (%s) -> %.8f\n",coin->symbol,retstr,rate); } free(retstr); } From a325746fa1e097d0b13035326318c8cd6eddd3fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:26:27 +0200 Subject: [PATCH 330/520] Test --- iguana/exchanges/LP_ordermatch.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7f4ddeed1..754617a84 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -365,27 +365,22 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L msg = jprint(reqjson,1); printf("QUERY.(%s)\n",msg); memset(&zero,0,sizeof(zero)); - if ( 0 && strcmp(method,"connect") == 0 ) + if ( 1 && strcmp(method,"request") == 0 ) { sleep(3); LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,zero,msg); - } - else + } else LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); + for (i=0; i<30; i++) { - memset(&zero,0,sizeof(zero)); - LP_broadcast_message(LP_mypubsock,qp->srccoin,qp->destcoin,qp->srchash,msg); - for (i=0; i<30; i++) + if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) { - if ( (price= LP_pricecache(qp,qp->srccoin,qp->destcoin,qp->txid,qp->vout)) > SMALLVAL ) + if ( flag == 0 || bits256_nonz(qp->desthash) != 0 ) { - if ( flag == 0 || bits256_nonz(qp->desthash) != 0 ) - { - printf("break out of loop.%d price %.8f %s/%s\n",i,price,qp->srccoin,qp->destcoin); - break; - } + printf("break out of loop.%d price %.8f %s/%s\n",i,price,qp->srccoin,qp->destcoin); + break; } - usleep(1000000); } + usleep(1000000); } return(price); } From 728bc913537b3dadf5cfce8d4aceb312d880e929 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:28:50 +0200 Subject: [PATCH 331/520] TRC and UIS tweaks --- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/coins | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2f375cfd0..c5a20b532 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime+3 ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime+13 ) { sprintf(buf,"[%d]",3); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index 0a7680a30..258a3be5e 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,2 +1,2 @@ -export coins="[{\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":1000000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"Mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":50000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":1000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" +export coins="[{\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"Mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":50000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":1000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" From ce9fd69b835dc783ad50b4f3e67c223d22232661 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:35:22 +0200 Subject: [PATCH 332/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0cae842bf..6063e22f0 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -48,7 +48,7 @@ #define LP_MINVOL 20 #define LP_MINCLIENTVOL 50 #define LP_MINSIZE_TXFEEMULT 10 -#define LP_REQUIRED_TXFEE 0.9 +#define LP_REQUIRED_TXFEE 0.8 #define LP_DEXFEE(destsatoshis) ((destsatoshis) / INSTANTDEX_INSURANCEDIV) #define LP_DEPOSITSATOSHIS(satoshis) ((satoshis) + (satoshis >> 3)) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index c5a20b532..42e9f514c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -604,7 +604,7 @@ double LP_getestimatedrate(struct iguana_info *coin) { if ( coin->rate == 0. || time(NULL) > coin->ratetime+13 ) { - sprintf(buf,"[%d]",3); + sprintf(buf,"[%d]",6); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { if ( retstr[0] != '-' ) From cdb8d187763965998b8476f8f720d41bf4ecdcde Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:38:37 +0200 Subject: [PATCH 333/520] Test --- iguana/exchanges/LP_rpc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 42e9f514c..659d18644 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -613,6 +613,8 @@ double LP_getestimatedrate(struct iguana_info *coin) if ( rate < 0.00000020 ) rate = 0.00000020; rate *= 1.25; + if ( coin->electrum != 0 ) + rate *= 1.25; coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); //if ( (rand() % 10) == 0 ) From 89357303686ff55192ca5ac73c5b274a3aafbc8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 17:50:48 +0200 Subject: [PATCH 334/520] Test --- iguana/exchanges/LP_ordermatch.c | 10 ++++++---- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 754617a84..98a921117 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -39,7 +39,7 @@ void LP_txfees(uint64_t *txfeep,uint64_t *desttxfeep,char *base,char *rel) { *txfeep = LP_txfeecalc(LP_coinfind(base),0); *desttxfeep = LP_txfeecalc(LP_coinfind(rel),0); - printf("LP_txfees(%.8f %.8f)\n",dstr(*txfeep),dstr(*desttxfeep)); + //printf("LP_txfees(%.8f %.8f)\n",dstr(*txfeep),dstr(*desttxfeep)); } double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee) @@ -458,7 +458,9 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t desttxfee) { printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee),relvolume,price); - return(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee); + if ( relvolume > dstr(desttxfee) ) + return(SATOSHIDEN * ((relvolume - dstr(desttxfee)) / price)); + else return(0); } struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,int32_t avoidflag,uint64_t desttxfee) @@ -476,7 +478,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre printf("%.8f ",dstr(utxos[i]->U.value)); printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); } - if ( (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL-1 ) + if ( targetval != 0 && (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL-1 ) { up = utxos[mini]; utxos[mini] = 0; @@ -959,7 +961,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice if ( n > 1 ) { basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); - if ( (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,0,desttxfee)) != 0 ) + if ( basesatoshis != 0 && (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,0,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 659d18644..837294e64 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -617,7 +617,7 @@ double LP_getestimatedrate(struct iguana_info *coin) rate *= 1.25; coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); - //if ( (rand() % 10) == 0 ) + if ( (rand() % 10) == 0 ) printf("estimated rate.(%s) (%s) -> %.8f\n",coin->symbol,retstr,rate); } free(retstr); From d1da4d74462bf294b52434e6e711ed2f3de0d89b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:04:47 +0200 Subject: [PATCH 335/520] Test --- iguana/exchanges/LP_transaction.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index f93374066..3d4e00068 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -27,7 +27,7 @@ int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid) txid = jbits256(txobj,"txid"); if ( jobj(txobj,"error") == 0 && bits256_cmp(txid,expectedtxid) == 0 ) { - char str[65]; printf("%s already in gettx (%s)\n",bits256_str(str,txid),jprint(txobj,0)); + //char str[65]; printf("%s already in gettx (%s)\n",bits256_str(str,txid),jprint(txobj,0)); flag = 1; } free_json(txobj); @@ -545,7 +545,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) { - char *rawtxbytes=0,*signedtx=0,tmpaddr[64],hexstr[999],wifstr[128],txdestaddr[64],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*item,*privkeys; int32_t completed,spendlen,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value,change = 0; struct iguana_msgtx msgtx; + char *rawtxbytes=0,*signedtx=0,tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*vin,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; *destamountp = 0; memset(signedtxidp,0,sizeof(*signedtxidp)); if ( finalseqid == 0 ) @@ -554,12 +554,24 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch if ( redeemlen < 0 ) return(0); #ifndef BASILISK_DISABLESENDTX - if ( (value= LP_txvalue(txdestaddr,symbol,utxotxid,vout)) == 0 ) + if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) { - char str[65]; - printf("basilisk_swap_bobtxspend.%s %s utxo.(%s) already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid)); - return(0); + if ( (vins= jarray(&n,txobj,"vin")) != 0 && vout < n ) + { + vin = jitem(vins,vout); + value = LP_value_extract(vin,1); + } + free_json(txobj); } + /*if ( coin->electrum == 0 ) + { + if ( (value= LP_txvalue(txdestaddr,symbol,utxotxid,vout)) == 0 ) + { + char str[65]; + printf("basilisk_swap_bobtxspend.%s %s utxo.(%s) already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid)); + return(0); + } + }*/ #else value = satoshis; #endif From ebd43ac9121b9c53dec9527ad411eec63107db17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:08:58 +0200 Subject: [PATCH 336/520] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_ordermatch.c | 4 +++- iguana/exchanges/LP_socket.c | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 6063e22f0..20ee19193 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -312,6 +312,7 @@ uint16_t LP_randpeer(char *destip); int32_t LP_butxo_findeither(bits256 txid,int32_t vout); cJSON *LP_listunspent(char *symbol,char *coinaddr); int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid); +double LP_getestimatedrate(struct iguana_info *coin); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3b5c8a8d7..ef54689e0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -470,6 +470,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; } coin->lastscanht++; + LP_getestimatedrate(coin); break; } if ( (counter % 6000) == 60 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 98a921117..4ef246c55 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,7 +25,9 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - if ( txfee == 0 && (txfee= LP_getestimatedrate(coin) * LP_AVETXSIZE) < LP_MIN_TXFEE ) + if ( coin->rate == 0. ) + coin->rate = LP_getestimatedrate(coin); + if ( txfee == 0 && (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; } else txfee = coin->txfee; diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 6682a782d..f7a7c5c5d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -685,6 +685,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) for (i=0; isymbol)); } /*else if ( strcmp(method,"blockchain.address.subscribe") == 0 ) never is called { From 52b6672cc4c77e0937192f01e35f4dab3eba801c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:20:17 +0200 Subject: [PATCH 337/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 ++ iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ef54689e0..1d93e3540 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -361,6 +361,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; + if ( coin->rate == 0. ) + LP_getestimatedrate(coin); if ( (rand() % 1000) == 0 ) { post = 0; diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 4ef246c55..9dc4c0eaa 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -460,7 +460,7 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t desttxfee) { printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee),relvolume,price); - if ( relvolume > dstr(desttxfee) ) + if ( relvolume > dstr(desttxfee) && price > SMALLVAL ) return(SATOSHIDEN * ((relvolume - dstr(desttxfee)) / price)); else return(0); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 837294e64..90a40581f 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -617,8 +617,7 @@ double LP_getestimatedrate(struct iguana_info *coin) rate *= 1.25; coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); - if ( (rand() % 10) == 0 ) - printf("estimated rate.(%s) (%s) -> %.8f\n",coin->symbol,retstr,rate); + printf("estimated rate.(%s) (%s) -> %.8f\n",coin->symbol,retstr,rate); } free(retstr); } From a021fe94e1bde282d41c5f7828667d447520f81d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:21:23 +0200 Subject: [PATCH 338/520] Test --- iguana/exchanges/LP_coins.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 6898e1ad3..dc682216b 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -296,6 +296,8 @@ int32_t LP_isdisabled(char *base,char *rel) struct iguana_info *LP_coinfind(char *symbol) { struct iguana_info *coin,cdata; int32_t isinactive,isPoS,longestchain = 1; uint16_t port,busport; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name,*assetname; + if ( symbol == 0 || symbol[0] == 0 ) + return(0); if ( (coin= LP_coinsearch(symbol)) != 0 ) return(coin); if ( (port= LP_rpcport(symbol)) == 0 ) From 7d6f51823147b01b98538c84919f53d5626e4763 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:34:03 +0200 Subject: [PATCH 339/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 6 +++++- iguana/exchanges/LP_rpc.c | 10 ++++++++-- iguana/exchanges/LP_socket.c | 5 +++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 20ee19193..06d16ad6f 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -182,7 +182,7 @@ struct iguana_info portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; - uint32_t counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime; + uint32_t updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag; char symbol[16],smartaddr[64],userpass[1024],serverport[128],lastunspent[64]; // portfolio diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1d93e3540..b5b0008d4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -361,8 +361,12 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; - if ( coin->rate == 0. ) + if ( coin->updaterate != 0 || (coin->electrum == 0 && coin->rate == 0.) ) + { LP_getestimatedrate(coin); + if ( coin->rate != 0 ) + coin->updaterate = 0; + } if ( (rand() % 1000) == 0 ) { post = 0; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 90a40581f..cb660ef9d 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -597,7 +597,7 @@ int32_t LP_importaddress(char *symbol,char *address) double LP_getestimatedrate(struct iguana_info *coin) { - char buf[512],*retstr; double rate = 0.00000020; + char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; if ( coin == 0 ) return(0.0001); if ( (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) @@ -607,7 +607,13 @@ double LP_getestimatedrate(struct iguana_info *coin) sprintf(buf,"[%d]",6); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { - if ( retstr[0] != '-' ) + if ( (errjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(errjson,"error") != 0 ) + rate = 0.; + free_json(errjson); + } + else if ( retstr[0] != '-' ) { rate = atof(retstr) / 1024.; if ( rate < 0.00000020 ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index f7a7c5c5d..cd8def659 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -669,7 +669,7 @@ struct electrum_info *LP_electrum_info(int32_t *alreadyp,char *symbol,char *ipad int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) { - cJSON *strjson,*errjson,*resultjson,*paramsjson; char *method; int32_t i,n,height; uint32_t idnum=0; struct stritem *stritem; struct queueitem *tmp,*item = 0; + cJSON *strjson,*errjson,*resultjson,*paramsjson; char *method; int32_t i,n,height; uint32_t idnum=0; struct stritem *stritem; struct iguana_info *coin; struct queueitem *tmp,*item = 0; ep->lasttime = (uint32_t)time(NULL); if ( (strjson= cJSON_Parse(str)) != 0 ) { @@ -685,7 +685,8 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) for (i=0; isymbol)); + if ( (coin= LP_coinfind(ep->symbol)) != 0 ) + coin->updaterate = (uint32_t)time(NULL); } /*else if ( strcmp(method,"blockchain.address.subscribe") == 0 ) never is called { From 862800577406eaac5ba5d0971d0df7c58e98c474 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:39:17 +0200 Subject: [PATCH 340/520] Test --- iguana/exchanges/LP_coins.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index dc682216b..f9ae0c9a8 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -261,6 +261,7 @@ int32_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asset memset(coin,0,sizeof(*coin)); safecopy(coin->symbol,symbol,sizeof(coin->symbol)); sprintf(coin->serverport,"127.0.0.1:%u",port); + coin->updaterate = (uint32_t)time(NULL); coin->isPoS = isPoS; coin->taddr = taddr; coin->wiftaddr = wiftaddr; From dbfc5f0d58d6210cad05e41efa7ed91d2f2429b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:42:42 +0200 Subject: [PATCH 341/520] Test --- iguana/exchanges/LP_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index cd8def659..94f689a22 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -685,8 +685,6 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) for (i=0; isymbol)) != 0 ) - coin->updaterate = (uint32_t)time(NULL); } /*else if ( strcmp(method,"blockchain.address.subscribe") == 0 ) never is called { @@ -700,6 +698,8 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) { *(ep->heightp) = height; *(ep->heighttimep) = (uint32_t)time(NULL); + if ( (coin= LP_coinfind(ep->symbol)) != 0 ) + coin->updaterate = (uint32_t)time(NULL); printf("%s ELECTRUM >>>>>>>>> set height.%d\n",ep->symbol,height); } } From 6e6c18bc41dc4b4e40d2e81208eb389254b9448d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:46:48 +0200 Subject: [PATCH 342/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b5b0008d4..194f0f9b7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -363,6 +363,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; if ( coin->updaterate != 0 || (coin->electrum == 0 && coin->rate == 0.) ) { + printf("issue LP_getestimatedrate(%s)\n",coin->symbol); LP_getestimatedrate(coin); if ( coin->rate != 0 ) coin->updaterate = 0; From 0b14d95f8783fd3d878a9096f5119fd222b0877f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:49:45 +0200 Subject: [PATCH 343/520] Test --- iguana/exchanges/LP_rpc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index cb660ef9d..33b7ea020 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -600,9 +600,9 @@ double LP_getestimatedrate(struct iguana_info *coin) char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; if ( coin == 0 ) return(0.0001); - if ( (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) ) + if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime+13 ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime ) { sprintf(buf,"[%d]",6); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) @@ -623,8 +623,8 @@ double LP_getestimatedrate(struct iguana_info *coin) rate *= 1.25; coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); - printf("estimated rate.(%s) (%s) -> %.8f\n",coin->symbol,retstr,rate); } + printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); free(retstr); } } else rate = coin->rate; From 908c3918d9e371e87bffaf34c17edacf5b71d9e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 18:57:17 +0200 Subject: [PATCH 344/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 - iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 194f0f9b7..b5b0008d4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -363,7 +363,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; if ( coin->updaterate != 0 || (coin->electrum == 0 && coin->rate == 0.) ) { - printf("issue LP_getestimatedrate(%s)\n",coin->symbol); LP_getestimatedrate(coin); if ( coin->rate != 0 ) coin->updaterate = 0; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 33b7ea020..b5f510c92 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -607,7 +607,7 @@ double LP_getestimatedrate(struct iguana_info *coin) sprintf(buf,"[%d]",6); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { - if ( (errjson= cJSON_Parse(retstr)) != 0 ) + if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) { if ( jobj(errjson,"error") != 0 ) rate = 0.; From 93f5168424af545c67a5bfcab7361310492f3eef Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 19:03:15 +0200 Subject: [PATCH 345/520] Test --- iguana/exchanges/LP_rpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b5f510c92..d74288e4c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -604,7 +604,7 @@ double LP_getestimatedrate(struct iguana_info *coin) { if ( coin->rate == 0. || time(NULL) > coin->ratetime ) { - sprintf(buf,"[%d]",6); + sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) @@ -623,8 +623,8 @@ double LP_getestimatedrate(struct iguana_info *coin) rate *= 1.25; coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); + printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); } - printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); free(retstr); } } else rate = coin->rate; From 5114c52c2c41df024edbafc4ef95e2b426003566 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 19:07:47 +0200 Subject: [PATCH 346/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9dc4c0eaa..a55526eb4 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -835,7 +835,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { bits256 zero; memset(&zero,0,sizeof(zero)); - LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg);//butxo->S.otherpubkey,msg); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); return(2); From 8eba304588a91cf902d04b8363352f7b580d19a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 19:21:58 +0200 Subject: [PATCH 347/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d74288e4c..9fded7317 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime ) + if ( strcmp(coin->symbol,"BTC") == 0 || coin->rate == 0. || time(NULL) > coin->ratetime ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) From a23e3b58b891afd539b9e65d082c0f7bf44cdb36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 19:25:47 +0200 Subject: [PATCH 348/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a55526eb4..cbcd0f851 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,7 +25,7 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - if ( coin->rate == 0. ) + //if ( coin->rate == 0. ) coin->rate = LP_getestimatedrate(coin); if ( txfee == 0 && (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; @@ -41,7 +41,7 @@ void LP_txfees(uint64_t *txfeep,uint64_t *desttxfeep,char *base,char *rel) { *txfeep = LP_txfeecalc(LP_coinfind(base),0); *desttxfeep = LP_txfeecalc(LP_coinfind(rel),0); - //printf("LP_txfees(%.8f %.8f)\n",dstr(*txfeep),dstr(*desttxfeep)); + printf("LP_txfees(%.8f %.8f)\n",dstr(*txfeep),dstr(*desttxfeep)); } double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee) From a1bd02aacdfb6665ddcb057e4edf96c21719e24e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 19:33:30 +0200 Subject: [PATCH 349/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cbcd0f851..36a1b9fac 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -129,7 +129,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) jadd64bits(retjson,"destsatoshis",qp->destsatoshis); if ( qp->satoshis != 0 ) { - price = (double)qp->destsatoshis / qp->satoshis; + price = (double)(qp->destsatoshis-qp->desttxfee) / (qp->satoshis - qp->txfee); jaddnum(retjson,"price",price); } } @@ -205,7 +205,7 @@ char *LP_quotereceived(cJSON *argjson) { struct LP_cacheinfo *ptr; double price; struct LP_quoteinfo Q; LP_quoteparse(&Q,argjson); - price = (double)Q.destsatoshis / Q.satoshis; + price = (double)(Q.destsatoshis-Q.desttxfee) / (Q.satoshis - Q.txfee); if ( (ptr= LP_cacheadd(Q.srccoin,Q.destcoin,Q.txid,Q.vout,price,&Q)) != 0 ) { ptr->Q = Q; @@ -305,7 +305,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str return(-33); } if ( qp->satoshis != 0 ) - qprice = ((double)qp->destsatoshis / qp->satoshis); + qprice = ((double)(qp->destsatoshis-qp->desttxfee) / (qp->satoshis-qp->txfee)); LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); if ( txfee < qp->txfee ) txfee = qp->txfee; @@ -461,7 +461,7 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d { printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee),relvolume,price); if ( relvolume > dstr(desttxfee) && price > SMALLVAL ) - return(SATOSHIDEN * ((relvolume - dstr(desttxfee)) / price)); + return(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + txfee); else return(0); } From 8b6574434986e16fe4cdb42c5e0bf17884987f10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 19:58:59 +0200 Subject: [PATCH 350/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_transaction.c | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 9fded7317..a1f10e9d7 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) { - if ( strcmp(coin->symbol,"BTC") == 0 || coin->rate == 0. || time(NULL) > coin->ratetime ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 3d4e00068..1f2deff8a 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -545,7 +545,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) { - char *rawtxbytes=0,*signedtx=0,tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*vin,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; + char *rawtxbytes=0,*signedtx=0,tmpaddr[64],txdestaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*item,*privkeys; int32_t completed,spendlen,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; *destamountp = 0; memset(signedtxidp,0,sizeof(*signedtxidp)); if ( finalseqid == 0 ) @@ -554,24 +554,24 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch if ( redeemlen < 0 ) return(0); #ifndef BASILISK_DISABLESENDTX - if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) + if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 ) { - if ( (vins= jarray(&n,txobj,"vin")) != 0 && vout < n ) + if ( (value= LP_txvalue(txdestaddr,symbol,utxotxid,vout)) == 0 ) { - vin = jitem(vins,vout); - value = LP_value_extract(vin,1); + char str[65]; + printf("basilisk_swap_bobtxspend.%s %s utxo.(%s) already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid)); + return(0); } - free_json(txobj); - } - /*if ( coin->electrum == 0 ) - { - if ( (value= LP_txvalue(txdestaddr,symbol,utxotxid,vout)) == 0 ) - { - char str[65]; - printf("basilisk_swap_bobtxspend.%s %s utxo.(%s) already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid)); - return(0); + /*if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) + { + if ( (vins= jarray(&n,txobj,"vin")) != 0 && vout < n ) + { + vin = jitem(vins,vout); + value = LP_value_extract(vin,1); + } + free_json(txobj); + }*/ } - }*/ #else value = satoshis; #endif From a7a17853b8b7f450c8580644797039ed74db8aae Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:08:07 +0200 Subject: [PATCH 351/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index a1f10e9d7..96a9b4747 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) { - if ( coin->rate == 0. || time(NULL) > coin->ratetime+60 ) + if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) || time(NULL) > coin->ratetime+60 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) From ceb2583e1cc179fcf19f083fb6c3a5c906b658ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:10:21 +0200 Subject: [PATCH 352/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 36a1b9fac..70d3f4f97 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,12 +25,11 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - //if ( coin->rate == 0. ) + if ( coin->rate == 0. || txfee < LP_MIN_TXFEE ) coin->rate = LP_getestimatedrate(coin); if ( txfee == 0 && (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; - } - else txfee = coin->txfee; + } else txfee = coin->txfee; if ( txfee < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; } From fb983df693e0bb5fa80e58c71243f600429fea94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:14:49 +0200 Subject: [PATCH 353/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 96a9b4747..703e4b40d 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -602,7 +602,7 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) { - if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) || time(NULL) > coin->ratetime+60 ) + if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) || time(NULL) > coin->ratetime+6 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) From a06f8a32aa4417201e7750ffd01e68d185ce53c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:20:59 +0200 Subject: [PATCH 354/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +-- iguana/exchanges/LP_rpc.c | 64 ++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 70d3f4f97..6ecf8a7c6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,9 +25,8 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - if ( coin->rate == 0. || txfee < LP_MIN_TXFEE ) - coin->rate = LP_getestimatedrate(coin); - if ( txfee == 0 && (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) + coin->rate = _LP_getestimatedrate(coin); + if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; } else txfee = coin->txfee; if ( txfee < LP_MIN_TXFEE ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 703e4b40d..b0c4866c1 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -595,39 +595,47 @@ int32_t LP_importaddress(char *symbol,char *address) } } -double LP_getestimatedrate(struct iguana_info *coin) +double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; + sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); + if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) + { + if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(errjson,"error") != 0 ) + rate = 0.; + free_json(errjson); + } + else if ( retstr[0] != '-' ) + { + rate = atof(retstr) / 1024.; + if ( rate < 0.00000020 ) + rate = 0.00000020; + rate *= 1.25; + if ( coin->electrum != 0 ) + rate *= 1.25; + coin->rate = rate; + coin->ratetime = (uint32_t)time(NULL); + printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); + } + free(retstr); + } + return(rate); +} + +double LP_getestimatedrate(struct iguana_info *coin) +{ + double rate = 0.00000020; if ( coin == 0 ) return(0.0001); - if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. ) + if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { - if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) || time(NULL) > coin->ratetime+6 ) - { - sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); - if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) - { - if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) - { - if ( jobj(errjson,"error") != 0 ) - rate = 0.; - free_json(errjson); - } - else if ( retstr[0] != '-' ) - { - rate = atof(retstr) / 1024.; - if ( rate < 0.00000020 ) - rate = 0.00000020; - rate *= 1.25; - if ( coin->electrum != 0 ) - rate *= 1.25; - coin->rate = rate; - coin->ratetime = (uint32_t)time(NULL); - printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); - } - free(retstr); - } - } else rate = coin->rate; + if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) ) + rate = _LP_getestimatedrate(coin); + else rate = coin->rate; + if ( rate != 0. ) + coin->txfee = (coin->rate * LP_AVETXSIZE); } else return((double)coin->txfee / LP_AVETXSIZE); return(SATOSHIDEN * rate); } From fde15b1521f4f66c4e58053d6ff68793d73d0d80 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:26:38 +0200 Subject: [PATCH 355/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 6ecf8a7c6..9458d1eff 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,9 +25,13 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - coin->rate = _LP_getestimatedrate(coin); + coin->rate = LP_getestimatedrate(coin); if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) - txfee = LP_MIN_TXFEE; + { + coin->rate = _LP_getestimatedrate(coin); + if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) + txfee = LP_MIN_TXFEE; + } } else txfee = coin->txfee; if ( txfee < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; From c2f8bb5e6568d81d989d86c1be01ae1970eba26e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:37:42 +0200 Subject: [PATCH 356/520] Test --- iguana/exchanges/LP_rpc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b0c4866c1..7508dda6e 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -631,12 +631,10 @@ double LP_getestimatedrate(struct iguana_info *coin) return(0.0001); if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { - if ( coin->rate == 0. || (strcmp(coin->symbol,"BTC") == 0 && coin->txfee == 10000) ) - rate = _LP_getestimatedrate(coin); - else rate = coin->rate; + rate = _LP_getestimatedrate(coin); if ( rate != 0. ) - coin->txfee = (coin->rate * LP_AVETXSIZE); - } else return((double)coin->txfee / LP_AVETXSIZE); + coin->txfee = SATOSHIDEN * (coin->rate * LP_AVETXSIZE); + } else return((double)coin->txfee / (LP_AVETXSIZE * SATOSHIDEN)); return(SATOSHIDEN * rate); } From c9916394e0ae34eba97c1d808ec3648f7f4afeb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:41:32 +0200 Subject: [PATCH 357/520] Test --- iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9458d1eff..a40924bd1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,6 +25,7 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { + coin->rate = 0.; coin->rate = LP_getestimatedrate(coin); if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 7508dda6e..71629c0d6 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -629,7 +629,7 @@ double LP_getestimatedrate(struct iguana_info *coin) double rate = 0.00000020; if ( coin == 0 ) return(0.0001); - if ( strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+60 ) + if ( coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+60 ) { rate = _LP_getestimatedrate(coin); if ( rate != 0. ) From 62329e286674876edf4c8b1e48d6c0a182e68bf5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:45:39 +0200 Subject: [PATCH 358/520] Test --- iguana/exchanges/LP_transaction.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 1f2deff8a..8b7644211 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -553,6 +553,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch //printf("bobtxspend.%s redeem.[%d]\n",symbol,redeemlen); if ( redeemlen < 0 ) return(0); + value = satoshis; #ifndef BASILISK_DISABLESENDTX if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 ) { @@ -572,8 +573,6 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch free_json(txobj); }*/ } -#else - value = satoshis; #endif if ( satoshis != 0 ) { From 1fe35f02143cdec784099619a0a54aa8c162b269 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:46:43 +0200 Subject: [PATCH 359/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 71629c0d6..ba7febf73 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -616,8 +616,8 @@ double _LP_getestimatedrate(struct iguana_info *coin) if ( coin->electrum != 0 ) rate *= 1.25; coin->rate = rate; + printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->ratetime = (uint32_t)time(NULL); - printf("estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->symbol,retstr,rate,coin->rate); } free(retstr); } From f10cbf5eeab475b34a695a6288a63c893f8f7ca5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:49:10 +0200 Subject: [PATCH 360/520] Test --- iguana/exchanges/LP_rpc.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index ba7febf73..e5c1cad47 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -598,28 +598,31 @@ int32_t LP_importaddress(char *symbol,char *address) double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; - sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); - if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) + if ( coin->rate == 0. || time(NULL) > time(NULL) > coin->ratetime+6 ) { - if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) + sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); + if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) { - if ( jobj(errjson,"error") != 0 ) - rate = 0.; - free_json(errjson); - } - else if ( retstr[0] != '-' ) - { - rate = atof(retstr) / 1024.; - if ( rate < 0.00000020 ) - rate = 0.00000020; - rate *= 1.25; - if ( coin->electrum != 0 ) + if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(errjson,"error") != 0 ) + rate = 0.; + free_json(errjson); + } + else if ( retstr[0] != '-' ) + { + rate = atof(retstr) / 1024.; + if ( rate < 0.00000020 ) + rate = 0.00000020; rate *= 1.25; - coin->rate = rate; - printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); - coin->ratetime = (uint32_t)time(NULL); + if ( coin->electrum != 0 ) + rate *= 1.25; + coin->rate = rate; + printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); + coin->ratetime = (uint32_t)time(NULL); + } + free(retstr); } - free(retstr); } return(rate); } From 03ac83100955c31025e2e6fdceeae20aea89dcee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:50:05 +0200 Subject: [PATCH 361/520] Test --- iguana/exchanges/LP_rpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index e5c1cad47..e614cbc49 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -598,7 +598,7 @@ int32_t LP_importaddress(char *symbol,char *address) double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; - if ( coin->rate == 0. || time(NULL) > time(NULL) > coin->ratetime+6 ) + if ( coin->rate == 0. || time(NULL) > time(NULL) > coin->ratetime+30 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) @@ -632,7 +632,7 @@ double LP_getestimatedrate(struct iguana_info *coin) double rate = 0.00000020; if ( coin == 0 ) return(0.0001); - if ( coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+60 ) + if ( coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+600 ) { rate = _LP_getestimatedrate(coin); if ( rate != 0. ) From c2392cc4278cf073b032275a406ca6c04a56fe3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:55:13 +0200 Subject: [PATCH 362/520] Test --- iguana/exchanges/electrum.kmd3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/electrum.kmd3 b/iguana/exchanges/electrum.kmd3 index 449658cac..275990eef 100755 --- a/iguana/exchanges/electrum.kmd3 +++ b/iguana/exchanges/electrum.kmd3 @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140 \",\"port\":8777}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140 \",\"port\":50011}" From 2e997c5beda10a679e960530fe57ee00f5d3a6f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:58:24 +0200 Subject: [PATCH 363/520] Test --- iguana/exchanges/electrum.kmd3 | 2 +- iguana/exchanges/electrums | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 iguana/exchanges/electrums diff --git a/iguana/exchanges/electrum.kmd3 b/iguana/exchanges/electrum.kmd3 index 275990eef..5fb7a6b9a 100755 --- a/iguana/exchanges/electrum.kmd3 +++ b/iguana/exchanges/electrum.kmd3 @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140 \",\"port\":50011}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140\",\"port\":50011}" diff --git a/iguana/exchanges/electrums b/iguana/exchanges/electrums new file mode 100755 index 000000000..5e4db6c70 --- /dev/null +++ b/iguana/exchanges/electrums @@ -0,0 +1,36 @@ +ource userpass + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"ARG\",\"ipaddr\":\"173.212.225.176\",\"port\":50081}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"136.243.45.140\",\"port\":50001}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"173.212.225.176\",\"port\":50001}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CRW\",\"ipaddr\":\"173.212.225.176\",\"port\":50041}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"DASH\",\"ipaddr\":\"173.212.225.176\",\"port\":50098}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"DGB\",\"ipaddr\":\"136.243.45.140\",\"port\":50022}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"DGB\",\"ipaddr\":\"173.212.225.176\",\"port\":50022}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"DOGE\",\"ipaddr\":\"173.212.225.176\",\"port\":50015}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"FAIR\",\"ipaddr\":\"173.212.225.176\",\"port\":50005}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"HUSH\",\"ipaddr\":\"173.212.225.176\",\"port\":50013}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140\",\"port\":50011}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"173.212.225.176\",\"port\":50011}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"LTC\",\"ipaddr\":\"173.212.225.176\",\"port\":50012}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"MONA\",\"ipaddr\":\"173.212.225.176\",\"port\":50002}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"NMC\",\"ipaddr\":\"173.212.225.176\",\"port\":50036}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"VTC\",\"ipaddr\":\"173.212.225.176\",\"port\":50088}" + +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"ZEC\",\"ipaddr\":\"173.212.225.176\",\"port\":50032}" + From e01a090b6e13b5b4d2342639ab02a18a4ee83d10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 20:59:34 +0200 Subject: [PATCH 364/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a40924bd1..cbbd17e38 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -25,10 +25,10 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) { if ( strcmp(coin->symbol,"BTC") == 0 ) { - coin->rate = 0.; coin->rate = LP_getestimatedrate(coin); if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) { + coin->rate = 0.; coin->rate = _LP_getestimatedrate(coin); if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index e614cbc49..cd4fc2366 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -598,7 +598,7 @@ int32_t LP_importaddress(char *symbol,char *address) double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; - if ( coin->rate == 0. || time(NULL) > time(NULL) > coin->ratetime+30 ) + if ( coin->rate == 0. || time(NULL) > coin->ratetime+30 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) From b457d7737d865ecf71e3265cff0bbfb417138bf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:01:37 +0200 Subject: [PATCH 365/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b5b0008d4..7847460ff 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -361,12 +361,12 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; - if ( coin->updaterate != 0 || (coin->electrum == 0 && coin->rate == 0.) ) + /*if ( coin->updaterate != 0 || (coin->electrum == 0 && coin->rate == 0.) ) { LP_getestimatedrate(coin); if ( coin->rate != 0 ) coin->updaterate = 0; - } + }*/ if ( (rand() % 1000) == 0 ) { post = 0; From dae7e62c99ae4ee96a95767d5ed11c5e2cb4019b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:02:41 +0200 Subject: [PATCH 366/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index cd4fc2366..63b8a02b1 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -617,8 +617,8 @@ double _LP_getestimatedrate(struct iguana_info *coin) rate *= 1.25; if ( coin->electrum != 0 ) rate *= 1.25; - coin->rate = rate; printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); + coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); } free(retstr); From 40a013fe43494b3dbc2ca06aa2f0a6ceb0a40b65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:09:18 +0200 Subject: [PATCH 367/520] Test --- iguana/exchanges/LP_rpc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 63b8a02b1..d1b0d5b3c 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -598,7 +598,7 @@ int32_t LP_importaddress(char *symbol,char *address) double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; - if ( coin->rate == 0. || time(NULL) > coin->ratetime+30 ) + if ( time(NULL) > coin->ratetime+30 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) @@ -623,7 +623,7 @@ double _LP_getestimatedrate(struct iguana_info *coin) } free(retstr); } - } + } else rate = coin->rate; return(rate); } @@ -632,12 +632,9 @@ double LP_getestimatedrate(struct iguana_info *coin) double rate = 0.00000020; if ( coin == 0 ) return(0.0001); - if ( coin->txfee == 0 || coin->rate == 0. || time(NULL) > coin->ratetime+600 ) - { - rate = _LP_getestimatedrate(coin); - if ( rate != 0. ) - coin->txfee = SATOSHIDEN * (coin->rate * LP_AVETXSIZE); - } else return((double)coin->txfee / (LP_AVETXSIZE * SATOSHIDEN)); + if ( (rate= _LP_getestimatedrate(coin)) != 0. ) + coin->txfee = LP_AVETXSIZE * (coin->rate * SATOSHIDEN); + else rate = dstr(coin->txfee) / LP_AVETXSIZE; return(SATOSHIDEN * rate); } From e9113f5897a07c23d74cda079ffe314e7e871288 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:11:48 +0200 Subject: [PATCH 368/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cbbd17e38..70f49c12a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -26,11 +26,11 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) if ( strcmp(coin->symbol,"BTC") == 0 ) { coin->rate = LP_getestimatedrate(coin); - if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) + if ( (txfee= coin->rate * LP_AVETXSIZE) <= LP_MIN_TXFEE ) { coin->rate = 0.; coin->rate = _LP_getestimatedrate(coin); - if ( (txfee= coin->rate * LP_AVETXSIZE) < LP_MIN_TXFEE ) + if ( (txfee= coin->rate * LP_AVETXSIZE) <= LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; } } else txfee = coin->txfee; From 52690233a3cab3a9ca5909dbe38a4d7a5f31a3cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:15:44 +0200 Subject: [PATCH 369/520] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- iguana/exchanges/LP_rpc.c | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 70f49c12a..06ca2e6a0 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -26,11 +26,11 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee) if ( strcmp(coin->symbol,"BTC") == 0 ) { coin->rate = LP_getestimatedrate(coin); - if ( (txfee= coin->rate * LP_AVETXSIZE) <= LP_MIN_TXFEE ) + if ( (txfee= SATOSHIDEN * coin->rate * LP_AVETXSIZE) <= LP_MIN_TXFEE ) { - coin->rate = 0.; + coin->rate = -1.; coin->rate = _LP_getestimatedrate(coin); - if ( (txfee= coin->rate * LP_AVETXSIZE) <= LP_MIN_TXFEE ) + if ( (txfee= SATOSHIDEN * coin->rate * LP_AVETXSIZE) <= LP_MIN_TXFEE ) txfee = LP_MIN_TXFEE; } } else txfee = coin->txfee; diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d1b0d5b3c..f7b065506 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -598,7 +598,7 @@ int32_t LP_importaddress(char *symbol,char *address) double _LP_getestimatedrate(struct iguana_info *coin) { char buf[512],*retstr; cJSON *errjson; double rate = 0.00000020; - if ( time(NULL) > coin->ratetime+30 ) + if ( coin->rate < 0. || time(NULL) > coin->ratetime+30 ) { sprintf(buf,"[%d]",strcmp(coin->symbol,"BTC") == 0 ? 6 : 2); if ( (retstr= LP_apicall(coin,coin->electrum==0?"estimatefee" : "blockchain.estimatefee",buf)) != 0 ) @@ -631,11 +631,10 @@ double LP_getestimatedrate(struct iguana_info *coin) { double rate = 0.00000020; if ( coin == 0 ) - return(0.0001); - if ( (rate= _LP_getestimatedrate(coin)) != 0. ) - coin->txfee = LP_AVETXSIZE * (coin->rate * SATOSHIDEN); - else rate = dstr(coin->txfee) / LP_AVETXSIZE; - return(SATOSHIDEN * rate); + return(rate); + if ( (rate= _LP_getestimatedrate(coin)) <= 0. ) + rate = dstr(coin->txfee) / LP_AVETXSIZE; + return(rate); } char *LP_sendrawtransaction(char *symbol,char *signedtx) From 4d5f6abce573d0b2833573c0064a5e5f29bf2087 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:17:58 +0200 Subject: [PATCH 370/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 06ca2e6a0..bd3269ec2 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -837,8 +837,9 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); { bits256 zero; - memset(&zero,0,sizeof(zero)); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); + memset(&zero,0,sizeof(zero)); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); return(2); From 484dbbd3f9daf601c2f88e56133283a4c0a5a19d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:23:49 +0200 Subject: [PATCH 371/520] Test --- iguana/exchanges/LP_ordermatch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bd3269ec2..9afd05a61 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -836,10 +836,11 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo->T.lasttime = (uint32_t)time(NULL); printf("set swappending.%u accept qprice %.8f, min %.8f\n(%s)\n",butxo->T.swappending,qprice,price,msg); { - bits256 zero; - LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg); + bits256 zero; char *msg2; memset(&zero,0,sizeof(zero)); + msg2 = clonestr(msg); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); + LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg2); LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); return(2); From e166758bda077913b47a005fbc5adfa119e19ad5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:39:00 +0200 Subject: [PATCH 372/520] Test --- iguana/exchanges/LP_transaction.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 8b7644211..467608907 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -545,7 +545,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) { - char *rawtxbytes=0,*signedtx=0,tmpaddr[64],txdestaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*item,*privkeys; int32_t completed,spendlen,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; + char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],txdestaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*vin,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; *destamountp = 0; memset(signedtxidp,0,sizeof(*signedtxidp)); if ( finalseqid == 0 ) @@ -555,24 +555,26 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch return(0); value = satoshis; #ifndef BASILISK_DISABLESENDTX - if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 ) + if ( (coin= LP_coinfind(symbol)) != 0 ) { - if ( (value= LP_txvalue(txdestaddr,symbol,utxotxid,vout)) == 0 ) - { - char str[65]; - printf("basilisk_swap_bobtxspend.%s %s utxo.(%s) already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid)); - return(0); - } - /*if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) + if ( coin->electrum == 0 ) + value = LP_txvalue(txdestaddr,symbol,utxotxid,vout); + else if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) { if ( (vins= jarray(&n,txobj,"vin")) != 0 && vout < n ) { vin = jitem(vins,vout); value = LP_value_extract(vin,1); - } + printf("value in vout.%d %.8f\n",vout,dstr(value)); + } else value = 0; free_json(txobj); - }*/ - } + } + if ( value == 0 ) + { + printf("basilisk_swap_bobtxspend.%s %s utxo.(%s) already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid)); + return(0); + } + } #endif if ( satoshis != 0 ) { From 5b98fe68cacbed8277c5082e6a16ec439c78dbc9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:47:14 +0200 Subject: [PATCH 373/520] Test --- iguana/exchanges/LP_network.c | 4 ++-- iguana/exchanges/LP_rpc.c | 4 ++-- iguana/exchanges/LP_transaction.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 6f453c9bc..fd33179f2 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -157,7 +157,7 @@ void queue_loop(void *ignore) { if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); - //else printf("%d %p qsent %u msglen.%d peerind.%d\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind); + else printf("%d %p qsent %u msglen.%d peerind.%d (%s)\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind,ptr->msg); ptr->sock = -1; if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); @@ -214,7 +214,7 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); else { - //printf("Q sent %u msglen.%d\n",crc32,msglen); + printf("Q sent %u msglen.%d (%s)\n",crc32,msglen,msg); sock0 = -1; } } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index f7b065506..72a210cbb 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -262,7 +262,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(retjson,1); - if ( strlen(hexstr) > 10000 ) + if ( strlen(hexstr) > 20000 ) { static uint32_t counter; if ( counter++ < 3 ) @@ -316,7 +316,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) if ( (hexobj= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) { hexstr = jprint(hexobj,1); - if ( strlen(hexstr) > 10000 ) + if ( strlen(hexstr) > 20000 ) { static uint32_t counter; if ( counter++ < 3 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 467608907..75a9f7222 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -565,7 +565,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch { vin = jitem(vins,vout); value = LP_value_extract(vin,1); - printf("value in vout.%d %.8f\n",vout,dstr(value)); + printf("value in vout.%d %.8f (%S)\n",vout,dstr(value),jprint(txobj,0)); } else value = 0; free_json(txobj); } From 3db83282ccdc3ecc311c997558df7d532780ac7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:49:28 +0200 Subject: [PATCH 374/520] test --- iguana/exchanges/LP_transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 75a9f7222..cc428bf40 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -565,7 +565,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch { vin = jitem(vins,vout); value = LP_value_extract(vin,1); - printf("value in vout.%d %.8f (%S)\n",vout,dstr(value),jprint(txobj,0)); + printf("value in vout.%d %.8f (%s)\n",vout,dstr(value),jprint(txobj,0)); } else value = 0; free_json(txobj); } From 9619f0a129844528f79c650346cbd16980e74fe8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 21:52:28 +0200 Subject: [PATCH 375/520] Test --- iguana/exchanges/LP_transaction.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index cc428bf40..a08e73df7 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -545,7 +545,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) { - char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],txdestaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*vin,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; + char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],txdestaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; *destamountp = 0; memset(signedtxidp,0,sizeof(*signedtxidp)); if ( finalseqid == 0 ) @@ -553,20 +553,18 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch //printf("bobtxspend.%s redeem.[%d]\n",symbol,redeemlen); if ( redeemlen < 0 ) return(0); - value = satoshis; + value = 0; #ifndef BASILISK_DISABLESENDTX if ( (coin= LP_coinfind(symbol)) != 0 ) { - if ( coin->electrum == 0 ) - value = LP_txvalue(txdestaddr,symbol,utxotxid,vout); - else if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) + if ( (txobj= LP_gettx(symbol,utxotxid)) != 0 ) { - if ( (vins= jarray(&n,txobj,"vin")) != 0 && vout < n ) + if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n ) { - vin = jitem(vins,vout); - value = LP_value_extract(vin,1); - printf("value in vout.%d %.8f (%s)\n",vout,dstr(value),jprint(txobj,0)); - } else value = 0; + obj = jitem(vouts,vout); + value = LP_value_extract(obj,1); + //printf("value in vout.%d %.8f (%s)\n",vout,dstr(value),jprint(txobj,0)); + } free_json(txobj); } if ( value == 0 ) From 1a15fad37cd6379e13053fef7d76d8dbf568939d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 22:14:46 +0200 Subject: [PATCH 376/520] Test --- iguana/exchanges/LP_swap.c | 2 +- iguana/exchanges/LP_transaction.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index de83c61dd..46c55141c 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -560,7 +560,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba if ( recvlen != datalen+rawtx->I.redeemlen+75 ) printf("RECVLEN %d != %d + %d\n",recvlen,datalen,rawtx->I.redeemlen); txid = bits256_doublesha256(0,data,datalen); - //char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid)); + char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid)); if ( bits256_cmp(txid,rawtx->I.actualtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 ) rawtx->I.actualtxid = txid; if ( (txobj= bitcoin_data2json(rawtx->coin->taddr,rawtx->coin->pubtype,rawtx->coin->p2shtype,rawtx->coin->isPoS,height,&rawtx->I.signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index a08e73df7..ef8b778bc 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -545,7 +545,7 @@ int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t vout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys) { - char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],txdestaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; + char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[2]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin; *destamountp = 0; memset(signedtxidp,0,sizeof(*signedtxidp)); if ( finalseqid == 0 ) @@ -1313,10 +1313,12 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da if ( LP_rawtx_spendscript(swap,swap->bobcoin.longestchain,&swap->bobdeposit,0,data,datalen,0) == 0 ) { swap->aliceclaim.utxovout = 0; - swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid = LP_broadcast_tx(swap->bobdeposit.name,swap->bobcoin.symbol,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); + swap->bobdeposit.I.signedtxid = LP_broadcast_tx(swap->bobdeposit.name,swap->bobcoin.symbol,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen); if ( bits256_nonz(swap->bobdeposit.I.signedtxid) != 0 ) swap->depositunconf = 1; + else swap->bobdeposit.I.signedtxid = swap->bobdeposit.I.actualtxid; len = basilisk_swapuserdata(userdata,zero,1,swap->I.myprivs[0],swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); + swap->aliceclaim.utxotxid = swap->bobdeposit.I.signedtxid; memcpy(swap->I.userdata_aliceclaim,userdata,len); swap->I.userdata_aliceclaimlen = len; bitcoin_address(swap->bobdeposit.p2shaddr,swap->bobcoin.taddr,swap->bobcoin.p2shtype,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); From 4284c3bb40ad3317580dd32bc4f2f9f38958fc0b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 22:30:07 +0200 Subject: [PATCH 377/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_network.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7847460ff..5a2a4f37d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -241,6 +241,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { +printf("RECV.(%s)\n",(char *)ptr); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index fd33179f2..582c1f37a 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -157,7 +157,7 @@ void queue_loop(void *ignore) { if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); - else printf("%d %p qsent %u msglen.%d peerind.%d (%s)\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind,ptr->msg); + //else printf("%d %p qsent %u msglen.%d peerind.%d (%s)\n",n,ptr,ptr->crc32,ptr->msglen,ptr->peerind,ptr->msg); ptr->sock = -1; if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); @@ -214,7 +214,7 @@ void _LP_queuesend(uint32_t crc32,int32_t sock0,int32_t sock1,uint8_t *msg,int32 printf("_LP_queuesend0 sent %d instead of %d\n",sentbytes,msglen); else { - printf("Q sent %u msglen.%d (%s)\n",crc32,msglen,msg); + //printf("Q sent %u msglen.%d (%s)\n",crc32,msglen,msg); sock0 = -1; } } From ef616e37a2b1e43368ca7d90b7eff4f1644b9d8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 22:34:44 +0200 Subject: [PATCH 378/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d65652d86..e8f41b51e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -//printf("stats_JSON(%s)\n",jprint(argjson,0)); +printf("stats_JSON(%s)\n",jprint(argjson,0)); method = jstr(argjson,"method"); if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5a2a4f37d..b3c546f6c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -241,7 +241,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int break; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { -printf("RECV.(%s)\n",(char *)ptr); +//printf("RECV.(%s)\n",(char *)ptr); nonz++; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); From d70d7f9104d05d0c4fe0dd832c2f8b38b298ebf6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 22:42:01 +0200 Subject: [PATCH 379/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e8f41b51e..d65652d86 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*ipaddr,*userpass,*base,*rel,*coin,*retstr = 0; uint16_t argport=0,pushport,subport; int32_t changed,otherpeers,flag = 0; struct LP_peerinfo *peer; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -printf("stats_JSON(%s)\n",jprint(argjson,0)); +//printf("stats_JSON(%s)\n",jprint(argjson,0)); method = jstr(argjson,"method"); if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b3c546f6c..051396535 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -368,7 +368,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->rate != 0 ) coin->updaterate = 0; }*/ - if ( (rand() % 1000) == 0 ) + if ( (rand() % 10000) == 0 ) { post = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); @@ -700,7 +700,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) - usleep(1000000 / MAINLOOP_PERSEC); + usleep(100000); + else usleep(10000); } } From 5f628d87c55fc6cde3c156cb2daa36b0e94e3459 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 22:48:30 +0200 Subject: [PATCH 380/520] Test --- iguana/exchanges/LP_swap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 46c55141c..32d255a5b 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -720,7 +720,7 @@ void LP_bobloop(void *_swap) printf("error waiting for alicefee\n"); else if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x200,data,maxlen,&swap->bobdeposit,0x100,0) == 0 ) printf("error sending bobdeposit\n"); - else if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_alicepayment) < 0 ) + else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_alicepayment) < 0 ) printf("error waiting for alicepayment\n"); else { @@ -775,7 +775,7 @@ void LP_aliceloop(void *_swap) LP_swapsfp_update(&swap->I.req); if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x80,data,maxlen,&swap->myfee,0x40,0) == 0 ) printf("error sending alicefee\n"); - else if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_bobdeposit) < 0 ) + else if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_bobdeposit) < 0 ) printf("error waiting for bobdeposit\n"); else if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x1000,data,maxlen,&swap->alicepayment,0x800,0) == 0 ) printf("error sending alicepayment\n"); @@ -790,7 +790,7 @@ void LP_aliceloop(void *_swap) sleep(10); } swap->sentflag = 1; - if ( LP_waitfor(swap->N.pair,swap,LP_SWAPSTEP_TIMEOUT*10,LP_verify_bobpayment) < 0 ) + if ( LP_waitfor(swap->N.pair,swap,1800,LP_verify_bobpayment) < 0 ) printf("error waiting for bobpayment\n"); else { From 4c13862a4b300282cad5ca206a67ad38ab0d8535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 22:57:52 +0200 Subject: [PATCH 381/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_rpc.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 051396535..24f54eb05 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -700,8 +700,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) - usleep(100000); - else usleep(10000); + usleep(500000); + else usleep(50000); } } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 72a210cbb..633633af3 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -617,7 +617,8 @@ double _LP_getestimatedrate(struct iguana_info *coin) rate *= 1.25; if ( coin->electrum != 0 ) rate *= 1.25; - printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); + if ( fabs(rate - coin->rate) > SMALLVAL ) + printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->rate = rate; coin->ratetime = (uint32_t)time(NULL); } From dd41578ec72f7331590729c18dc3889a23ae80fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 23:15:10 +0200 Subject: [PATCH 382/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 24f54eb05..8f309c38d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -331,7 +331,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( IAMLP == 0 ) continue; } - if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) ) + if ( now > peer->lastpeers+300 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 50000) == 0) ) { peer->lastpeers = now; if ( strcmp(peer->ipaddr,myipaddr) != 0 ) From b4cfb14154ceb80b66d953b9ae6e0b2f9e17a98f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 23:17:47 +0200 Subject: [PATCH 383/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8f309c38d..6d8a97e03 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -331,7 +331,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( IAMLP == 0 ) continue; } - if ( now > peer->lastpeers+300 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 50000) == 0) ) + if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) ) { peer->lastpeers = now; if ( strcmp(peer->ipaddr,myipaddr) != 0 ) @@ -352,7 +352,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int peer->diduquery = now; } } - if ( (counter % 6000) == 10 ) + if ( (counter % 60000) == 10 ) { LP_privkey_updates(ctx,pubsock,0); } From bf903468b807fdef8ad99f602559985c3ecc7252 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 23:19:01 +0200 Subject: [PATCH 384/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6d8a97e03..14210edbc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -352,7 +352,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int peer->diduquery = now; } } - if ( (counter % 60000) == 10 ) + if ( (counter % 6000) == 10 ) { LP_privkey_updates(ctx,pubsock,0); } @@ -368,7 +368,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->rate != 0 ) coin->updaterate = 0; }*/ - if ( (rand() % 10000) == 0 ) + if ( (rand() % 100000) == 0 ) { post = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); From 50e34a7d7812fa08853e42e48649cfce94c727a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 23:26:12 +0200 Subject: [PATCH 385/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 14210edbc..24f54eb05 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -368,7 +368,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->rate != 0 ) coin->updaterate = 0; }*/ - if ( (rand() % 100000) == 0 ) + if ( (rand() % 10000) == 0 ) { post = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); From 767d5b821eba1c05226b653c2c7f9f38e4687c3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 23:27:28 +0200 Subject: [PATCH 386/520] Test --- iguana/exchanges/mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 57c56fdee..a0e96cd24 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -793,7 +793,7 @@ void LP_main(void *ptr) LP_profitratio += profitmargin; if ( (port= juint(argjson,"rpcport")) < 1000 ) port = LP_RPCPORT; - LPinit(port,LP_RPCPORT+1,LP_RPCPORT+2,LP_RPCPORT+3,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); + LPinit(port,LP_RPCPORT+10,LP_RPCPORT+20,LP_RPCPORT+30,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); } } From 894b27baa2da4fefe9895c7cbb853285f273961d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Sep 2017 23:30:13 +0200 Subject: [PATCH 387/520] Test --- iguana/exchanges/mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index a0e96cd24..57c56fdee 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -793,7 +793,7 @@ void LP_main(void *ptr) LP_profitratio += profitmargin; if ( (port= juint(argjson,"rpcport")) < 1000 ) port = LP_RPCPORT; - LPinit(port,LP_RPCPORT+10,LP_RPCPORT+20,LP_RPCPORT+30,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); + LPinit(port,LP_RPCPORT+1,LP_RPCPORT+2,LP_RPCPORT+3,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); } } From 8b85d6cbffce92cf3d4ede6b42e434d25faee415 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Sep 2017 05:30:53 +0200 Subject: [PATCH 388/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 24f54eb05..5e9743a67 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -700,8 +700,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; if ( nonz == 0 ) - usleep(500000); - else usleep(50000); + usleep(50000); + else usleep(5000); } } From ad0dc4a2dbf1bd9116a5715f9f8af807002809ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Sep 2017 05:34:18 +0200 Subject: [PATCH 389/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9afd05a61..c0ad3b6b8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1015,7 +1015,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel LP_txfees(&txfee,&desttxfee,base,rel); memset(&_bestA,0,sizeof(_bestA)); memset(&_bestB,0,sizeof(_bestB)); - destsatoshis = SATOSHIDEN * relvolume + desttxfee; + destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); _bestA = *autxo; From 74269170dcd38e84cb0878c2b9abebb4ecd7184b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Sep 2017 05:39:23 +0200 Subject: [PATCH 390/520] Test --- iguana/exchanges/LP_ordermatch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c0ad3b6b8..032be2256 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -132,7 +132,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) jadd64bits(retjson,"destsatoshis",qp->destsatoshis); if ( qp->satoshis != 0 ) { - price = (double)(qp->destsatoshis-qp->desttxfee) / (qp->satoshis - qp->txfee); + price = (double)qp->destsatoshis / (qp->satoshis - qp->txfee); jaddnum(retjson,"price",price); } } @@ -208,7 +208,7 @@ char *LP_quotereceived(cJSON *argjson) { struct LP_cacheinfo *ptr; double price; struct LP_quoteinfo Q; LP_quoteparse(&Q,argjson); - price = (double)(Q.destsatoshis-Q.desttxfee) / (Q.satoshis - Q.txfee); + price = (double)Q.destsatoshis / (Q.satoshis - Q.txfee); if ( (ptr= LP_cacheadd(Q.srccoin,Q.destcoin,Q.txid,Q.vout,price,&Q)) != 0 ) { ptr->Q = Q; @@ -308,7 +308,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str return(-33); } if ( qp->satoshis != 0 ) - qprice = ((double)(qp->destsatoshis-qp->desttxfee) / (qp->satoshis-qp->txfee)); + qprice = ((double)qp->destsatoshis / (qp->satoshis-qp->txfee)); LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); if ( txfee < qp->txfee ) txfee = qp->txfee; From 9c949cb15af020cdc72f7081b5ff42986a57cd1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Sep 2017 05:43:43 +0200 Subject: [PATCH 391/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 032be2256..0fde80a5c 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -462,9 +462,9 @@ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t t uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t desttxfee) { - printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + 2*txfee),relvolume,price); + printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume) / price) + 2*txfee),relvolume,price); if ( relvolume > dstr(desttxfee) && price > SMALLVAL ) - return(SATOSHIDEN * ((relvolume + dstr(desttxfee)) / price) + txfee); + return(SATOSHIDEN * (relvolume / price) + txfee); else return(0); } From 714be722e1a06affe692259c52f008ce675ea045 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Sep 2017 18:24:47 +0200 Subject: [PATCH 392/520] Faster --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 22 ++++++++++++---------- iguana/exchanges/LP_transaction.c | 2 ++ iguana/exchanges/LP_utxo.c | 4 +++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 06d16ad6f..f3666f833 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -182,7 +182,7 @@ struct iguana_info portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; - uint32_t updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime; + uint32_t lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag; char symbol[16],smartaddr[64],userpass[1024],serverport[128],lastunspent[64]; // portfolio diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5e9743a67..42664d9ea 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -326,24 +326,19 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( (rand() % 10000) == 0 ) { peer->errors--; - peer->diduquery = 0; + if ( peer->errors < LP_MAXPEER_ERRORS ) + peer->diduquery = 0; } if ( IAMLP == 0 ) continue; } - if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 10000) == 0) ) + if ( now > peer->lastpeers+60 && peer->numpeers > 0 && (peer->numpeers != numpeers || (rand() % 1000) == 0) ) { peer->lastpeers = now; if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); - LP_peer_pricesquery(peer); - if ( peer->needping != 0 ) - { - if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) - free(retstr); - peer->needping = 0; - } + peer->diduquery = 0; } } if ( peer->diduquery == 0 ) @@ -351,6 +346,12 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int LP_peer_pricesquery(peer); peer->diduquery = now; } + if ( peer->needping != 0 ) + { + if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) + free(retstr); + peer->needping = 0; + } } if ( (counter % 6000) == 10 ) { @@ -368,8 +369,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->rate != 0 ) coin->updaterate = 0; }*/ - if ( (rand() % 10000) == 0 ) + if ( now > coin->lastutxos+60 || (rand() % 10000) == 0 ) { + coin->lastutxos = now; post = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index ef8b778bc..c05ae4613 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -566,6 +566,8 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch //printf("value in vout.%d %.8f (%s)\n",vout,dstr(value),jprint(txobj,0)); } free_json(txobj); + //if ( value != 0 ) + // gettxout } if ( value == 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ca6e6f352..04127b1bd 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -680,7 +680,9 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol } } // else printf("no val2\n"); } - char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); + char str[65],str2[65]; + if ( val != 0 && val2 != 0 ) + printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); if ( val == 0 ) LP_address_utxoadd(coin,destaddr,txid,vout,satoshis,-1,1); if ( val2 == 0 ) From 20547949fbf7f65ebee51f4758e84338dfe755ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 17:59:39 +0300 Subject: [PATCH 393/520] New unspent sync --- iguana/exchanges/LP_include.h | 4 +- iguana/exchanges/LP_nativeDEX.c | 180 ++++++++++++++++++-------------- iguana/exchanges/LP_prices.c | 47 +++++++-- iguana/exchanges/LP_utxo.c | 94 +++++++++++------ iguana/exchanges/LP_utxos.c | 1 + iguana/exchanges/electrums | 1 + 6 files changed, 209 insertions(+), 118 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index f3666f833..6a7499747 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -226,8 +226,8 @@ struct LP_address { UT_hash_handle hh; struct LP_address_utxo *utxos; - int64_t balance; - uint32_t monitor; + int64_t balance,total; + uint32_t timestamp,n; char coinaddr[40]; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 42664d9ea..673f951bc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -60,7 +60,7 @@ struct LP_globals { struct LP_utxoinfo *LP_utxoinfos,*LP_utxoinfos2; bits256 LP_mypub25519,LP_mypriv25519; - uint8_t LP_myrmd160[20]; + uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; int32_t LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting; char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41]; @@ -309,10 +309,108 @@ void command_rpcloop(void *myipaddr) } } +int32_t LP_utxos_sync(struct LP_peerinfo *peer) +{ + int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr; + HASH_ITER(hh,LP_coins,coin,ctmp) + { + if ( coin->inactive != 0 ) + continue; + total = 0; + LP_listunspent_both(coin->symbol,coin->smartaddr); + if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i 0 && total > 0 && (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr)) != 0 ) + { + total2 = 0; + if ( (array2= cJSON_Parse(retstr)) != 0 ) + { + if ( (m= cJSON_GetArraySize(array2)) > 0 ) + { + for (i=0; iipaddr,jprint(item,0)); + if ( (retstr2= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,v,jint(item,"height"),j64bits(item,"value"))) != 0 ) + free(retstr2); + posted++; + } + } + if ( 1 && posted != 0 ) + printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); + } //else printf("%s matches\n",peer->ipaddr); + free_json(array2); + } + free(retstr); + } + } + if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,"")) != 0 ) + { + if ( (array2= cJSON_Parse(retstr)) != 0 ) + { + if ( (m= cJSON_GetArraySize(array2)) > 0 ) + { + for (j=0; jtotal,ap->n) != metric ) + { + if ( ap->n < (metric & 0xffff) ) + { + if ( (retstr2= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) + { + if ( (array3= cJSON_Parse(retstr2)) != 0 ) + { + LP_unspents_array(coin,coinaddr,array3); + printf("pulled.(%s)\n",retstr2); + free_json(array3); + } + free(retstr2); + } + } else printf("wait for %s to pull %d vs %d\n",peer->ipaddr,ap->n,(uint16_t)metric); + } + } + } + } + free_json(array2); + } + } + } + return(posted); +} + int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { static uint32_t counter,numpeers; - struct iguana_info *coin,*ctmp; char *retstr,*retstr2,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t nonz = 0; + struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; bits256 zero; int32_t height,nonz = 0; now = (uint32_t)time(NULL); if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; @@ -339,6 +437,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); peer->diduquery = 0; + LP_utxos_sync(peer); } } if ( peer->diduquery == 0 ) @@ -359,88 +458,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height,i,j,n,m,v,post; bits256 zero,txid; cJSON *array,*item,*item2,*array2; uint64_t total,total2; memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; - /*if ( coin->updaterate != 0 || (coin->electrum == 0 && coin->rate == 0.) ) - { - LP_getestimatedrate(coin); - if ( coin->rate != 0 ) - coin->updaterate = 0; - }*/ - if ( now > coin->lastutxos+60 || (rand() % 10000) == 0 ) - { - coin->lastutxos = now; - post = 0; - LP_listunspent_both(coin->symbol,coin->smartaddr); - if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) - { - if ( (n= cJSON_GetArraySize(array)) > 0 ) - { - total = 0; - for (i=0; isymbol,coin->smartaddr,dstr(total),n); - HASH_ITER(hh,LP_peerinfos,peer,tmp) - { - if ( strcmp(peer->ipaddr,LP_myipaddr) != 0 && peer->errors < LP_MAXPEER_ERRORS ) - { - total2 = m = 0; - if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr)) != 0 ) - { - if ( (array2= cJSON_Parse(retstr)) != 0 ) - { - if ( (m= cJSON_GetArraySize(array2)) > 0 ) - { - for (i=0; iipaddr,jprint(item,0)); - if ( (retstr2= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,v,jint(item,"height"),j64bits(item,"value"))) != 0 ) - free(retstr2); - post++; - } - } - if ( 0 && post != 0 ) - printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); - } //else printf("%s matches\n",peer->ipaddr); - free_json(array2); - } - free(retstr); - } - } - } - } - free_json(array); - } - //if ( post > 0 ) - // LP_postutxos(coin->symbol,coin->smartaddr); - } if ( coin->electrum != 0 ) continue; - memset(zero.bytes,0,sizeof(zero)); if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { if ( (height= LP_getheight(coin)) > coin->longestchain ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 33348e387..5b7dcfc5d 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -52,7 +52,7 @@ struct LP_pubkeyinfo bits256 pubkey; double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; uint32_t timestamp,istrusted,numerrors; - uint8_t rmd160[20]; + uint8_t rmd160[20],pubsecp[33]; } *LP_pubkeyinfos; int32_t LP_pricevalid(double price) @@ -144,7 +144,10 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) pubp = calloc(1,sizeof(*pubp)); pubp->pubkey = pubkey; if ( bits256_cmp(G.LP_mypub25519,pubkey) == 0 ) + { memcpy(pubp->rmd160,G.LP_myrmd160,sizeof(pubp->rmd160)); + memcpy(pubp->pubsecp,G.LP_pubsecp,sizeof(pubp->pubsecp)); + } HASH_ADD_KEYPTR(hh,LP_pubkeyinfos,&pubp->pubkey,sizeof(pubp->pubkey),pubp); portable_mutex_unlock(&LP_pubkeymutex); if ( (pubp= LP_pubkeyfind(pubkey)) == 0 ) @@ -172,11 +175,32 @@ char *LP_pubkey_trustset(bits256 pubkey,uint32_t trustval) return(clonestr("{\"error\":\"pubkey not found\"}")); } +uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) +{ + cJSON *array,*item; int32_t i,n; uint64_t metric=0,total; + LP_listunspent_both(coin->symbol,coinaddr); + if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + { + total = 0; + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; itaddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); + if ((metric= LP_unspents_metric(coin,coinaddr)) != 0 ) + jadd64bits(item,base,metric); + } + jaddi(unspents,item); } jaddbits256(obj,"pubkey",pubp->pubkey); init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); jaddstr(obj,"rmd160",hexstr); + init_hexbytes_noT(hexstr,pubp->pubsecp,sizeof(pubp->pubsecp)); + jaddstr(obj,"pubsecp",hexstr); jaddnum(obj,"timestamp",pubp->timestamp); jadd(obj,"asks",array); + jadd(obj,"unspents",unspents); if ( pubp->istrusted != 0 ) jaddnum(obj,"istrusted",pubp->istrusted); return(obj); @@ -216,7 +251,7 @@ char *LP_prices() void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) { static uint8_t zeroes[20]; - struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr; double askprice; uint32_t now; + struct LP_pubkeyinfo *pubp; struct LP_priceinfo *basepp,*relpp; uint32_t timestamp; bits256 pubkey; cJSON *asks,*item; uint8_t rmd160[20]; int32_t i,n,relid,mismatch; char *base,*rel,*hexstr,*pubsecpstr; double askprice; uint32_t now; now = (uint32_t)time(NULL); pubkey = jbits256(obj,"pubkey"); if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) @@ -229,13 +264,13 @@ void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) else mismatch = 0; if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 ) peer->needping = 0; - if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) + if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 && (pubsecpstr= jstr(obj,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) { for (i=0; i<20; i++) printf("%02x",pubp->rmd160[i]); - char str[65]; printf(" -> rmd160.(%s) for %s\n",hexstr,bits256_str(str,pubkey)); + char str[65]; printf(" -> rmd160.(%s) for %s (%s)\n",hexstr,bits256_str(str,pubkey),pubsecpstr); memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); - //LP_address_monitor(pubp); + decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),pubsecpstr); } } timestamp = juint(obj,"timestamp"); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 04127b1bd..e0df1e85d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -239,27 +239,46 @@ cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32 return(item); } +uint64_t _LP_unspents_metric(uint64_t total,int32_t n) { return((total<<16) | (n & 0xffff)); } + cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret) { - cJSON *array; struct LP_address *ap=0; struct LP_address_utxo *up,*tmp; + cJSON *array,*item; int32_t n; uint64_t total; struct LP_address *ap=0,*atmp; struct LP_address_utxo *up,*tmp; array = cJSON_CreateArray(); if ( coinaddr != 0 && coinaddr[0] != 0 ) { //portable_mutex_lock(&coin->addrmutex); if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) { + total = n = 0; DL_FOREACH_SAFE(ap->utxos,up,tmp) { //char str[65]; printf("LP_address_utxos %s/v%d %.8f ht.%d spend.%d\n",bits256_str(str,up->U.txid),up->U.vout,dstr(up->U.value),up->U.height,up->spendheight); if ( up->spendheight <= 0 && up->U.height > 0 ) { jaddi(array,LP_address_item(coin,up,electrumret)); + n++; + total += up->U.value; //printf("new array %s\n",jprint(array,0)); } } + ap->total = total; + ap->n = n; } //portable_mutex_unlock(&coin->addrmutex); } + else + { + HASH_ITER(hh,coin->addresses,ap,atmp) + { + if ( ap->total > 0 && ap->n > 0 ) + { + item = cJSON_CreateObject(); + jadd64bits(item,ap->coinaddr,_LP_unspents_metric(ap->total,ap->n)); + jaddi(array,item); + } + } + } //printf("%s %s utxos.(%s) ap.%p\n",coin->symbol,coinaddr,jprint(array,0),ap); return(array); } @@ -286,9 +305,49 @@ void LP_postutxos(char *symbol,char *coinaddr) } } +int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) +{ + int32_t i,n,v,ht,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid; + if ( (n= cJSON_GetArraySize(array)) <= 0 ) + return(0); + for (i=0; ielectrum == 0 && (txobj= LP_gettxout(coin->symbol,txid,v)) != 0 ) + { + value = LP_value_extract(txobj,0); + if ( value != 0 && value != val ) + { + char str[65]; printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",coin->symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(txobj,0)); + errs++; + } + if ( coin->height != 0 ) + ht = LP_getheight(coin) - jint(txobj,"confirmations"); + else ht = 0; + /*if ( ht != 0 && ht < height-2 ) + { + printf("REJECT %s %s/v%d ht.%d vs %d confs.%d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jint(txobj,"confirmations"),jprint(item,0)); + errs++; + }*/ + free_json(txobj); + } + if ( errs == 0 ) + { + LP_address_utxoadd(coin,coinaddr,txid,v,val,height,-1); + count++; + } + } + return(count); +} + char *LP_postedutxos(cJSON *argjson) { - int32_t i,n,v,ht,errs,height; uint64_t value,val; cJSON *array,*item,*txobj; bits256 txid; char str[65],*symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; + int32_t n; char *symbol,*coinaddr; struct LP_address *ap; struct iguana_info *coin; cJSON *array; //printf("posted.(%s)\n",jprint(argjson,0)); if ( (coinaddr= jstr(argjson,"coinaddr")) != 0 && (symbol= jstr(argjson,"coin")) != 0 && (coin= LP_coinfind(symbol)) != 0 ) // addsig { @@ -296,35 +355,8 @@ char *LP_postedutxos(cJSON *argjson) { if ( (array= jarray(&n,argjson,"utxos")) != 0 ) { - for (i=0; ielectrum == 0 && (txobj= LP_gettxout(symbol,txid,v)) != 0 ) - { - value = LP_value_extract(txobj,0); - if ( value != 0 && value != val ) - { - printf("REJECT %s %s/v%d value.%llu vs %llu (%s)\n",symbol,bits256_str(str,txid),v,(long long)value,(long long)val,jprint(txobj,0)); - errs++; - } - if ( coin->height != 0 ) - ht = LP_getheight(coin) - jint(txobj,"confirmations"); - else ht = 0; - /*if ( ht != 0 && ht < height-2 ) - { - printf("REJECT %s %s/v%d ht.%d vs %d confs.%d (%s)\n",symbol,bits256_str(str,txid),v,ht,height,jint(txobj,"confirmations"),jprint(item,0)); - errs++; - }*/ - free_json(txobj); - } - if ( errs == 0 ) - LP_address_utxoadd(coin,coinaddr,txid,v,val,height,-1); - } + LP_unspents_array(coin,coinaddr,array); + free_json(array); } } else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr)) != 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 0c76c1976..990c5f4d1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -709,6 +709,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan if ( coin->counter == 0 ) { coin->counter++; + memcpy(G.LP_pubsecp,coin->pubkey33,33); bitcoin_priv2wif(coin->wiftaddr,tmpstr,privkey,coin->wiftype); bitcoin_addr2rmd160(coin->taddr,&tmptype,G.LP_myrmd160,coin->smartaddr); LP_privkeyadd(privkey,G.LP_myrmd160); diff --git a/iguana/exchanges/electrums b/iguana/exchanges/electrums index 5e4db6c70..06efc8f02 100755 --- a/iguana/exchanges/electrums +++ b/iguana/exchanges/electrums @@ -1,5 +1,6 @@ ource userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CHIPS\",\"ipaddr\":\"173.212.225.176\",\"port\":50076}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"ARG\",\"ipaddr\":\"173.212.225.176\",\"port\":50081}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"136.243.45.140\",\"port\":50001}" From 7fb8414c19527065fd046bd1d0732a45b0fd0917 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 18:09:52 +0300 Subject: [PATCH 394/520] Test --- iguana/exchanges/LP_nativeDEX.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 673f951bc..255df4033 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -380,10 +380,11 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) item = jitem(array2,j); if ( (coinaddr= jfieldname(item)) != 0 ) { - metric = j64bits(item,0); + metric = j64bits(item,"coinaddr"); + printf("(%s) -> %.8f n.%d\n",coinaddr,dstr(metric>>16),(uint16_t)metric); if ( (ap= LP_addressfind(coin,coinaddr)) == 0 || _LP_unspents_metric(ap->total,ap->n) != metric ) { - if ( ap->n < (metric & 0xffff) ) + if ( ap == 0 || ap->n < (metric & 0xffff) ) { if ( (retstr2= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) { @@ -395,13 +396,14 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) } free(retstr2); } - } else printf("wait for %s to pull %d vs %d\n",peer->ipaddr,ap->n,(uint16_t)metric); + } else printf("wait for %s to pull %d vs %d\n",peer->ipaddr,ap!=0?ap->n:-1,(uint16_t)metric); } } } } free_json(array2); } + free(retstr); } } return(posted); From 57490f793dba1c1488de8c17657348647e393be9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 18:15:49 +0300 Subject: [PATCH 395/520] Test --- iguana/exchanges/LP_utxo.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e0df1e85d..e1020e7fa 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -354,10 +354,7 @@ char *LP_postedutxos(cJSON *argjson) if ( coin->electrum == 0 || (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (array= jarray(&n,argjson,"utxos")) != 0 ) - { LP_unspents_array(coin,coinaddr,array); - free_json(array); - } } else if ( (array= electrum_address_listunspent(symbol,coin->electrum,&array,coinaddr)) != 0 ) free_json(array); From 0e3e89d7708ea7b9f950d4ba257104b918aa6d02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 18:27:03 +0300 Subject: [PATCH 396/520] Test --- iguana/exchanges/LP_nativeDEX.c | 7 ++++--- iguana/exchanges/LP_prices.c | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 255df4033..85dbef365 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -381,7 +381,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) if ( (coinaddr= jfieldname(item)) != 0 ) { metric = j64bits(item,"coinaddr"); - printf("(%s) -> %.8f n.%d\n",coinaddr,dstr(metric>>16),(uint16_t)metric); + //printf("(%s) -> %.8f n.%d\n",coinaddr,dstr(metric>>16),(uint16_t)metric); if ( (ap= LP_addressfind(coin,coinaddr)) == 0 || _LP_unspents_metric(ap->total,ap->n) != metric ) { if ( ap == 0 || ap->n < (metric & 0xffff) ) @@ -391,18 +391,19 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) if ( (array3= cJSON_Parse(retstr2)) != 0 ) { LP_unspents_array(coin,coinaddr,array3); - printf("pulled.(%s)\n",retstr2); + //printf("pulled.(%s)\n",retstr2); free_json(array3); } free(retstr2); } - } else printf("wait for %s to pull %d vs %d\n",peer->ipaddr,ap!=0?ap->n:-1,(uint16_t)metric); + } //else printf("wait for %s to pull %d vs %d\n",peer->ipaddr,ap!=0?ap->n:-1,(uint16_t)metric); } } } } free_json(array2); } + printf("processed.(%s)\n",retstr); free(retstr); } } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 5b7dcfc5d..3cc3856ba 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -197,7 +197,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { - int32_t baseid,relid; uint64_t metric; char *base,coinaddr[64],hexstr[41]; double price; cJSON *item,*array,*obj,*unspents; struct iguana_info *coin; + int32_t baseid,relid,i,j; uint64_t metric; char *base,coinaddr[64],hexstr[67],hexstr2[67]; double price; cJSON *item,*array,*obj,*unspents; struct iguana_info *coin; obj = cJSON_CreateObject(); array = cJSON_CreateArray(); unspents = cJSON_CreateArray(); @@ -226,10 +226,23 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) jaddi(unspents,item); } jaddbits256(obj,"pubkey",pubp->pubkey); - init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); - jaddstr(obj,"rmd160",hexstr); - init_hexbytes_noT(hexstr,pubp->pubsecp,sizeof(pubp->pubsecp)); - jaddstr(obj,"pubsecp",hexstr); + for (i=0; irmd160); i++) + { + if ( pubp->rmd160[i] != 0 ) + { + for (j=0; ipubsecp); i++) + { + if ( pubp->pubsecp[i] != 0 ) + { + init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); + jaddstr(obj,"rmd160",hexstr); + init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); + jaddstr(obj,"pubsecp",hexstr2); + printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); + } + } + } + } jaddnum(obj,"timestamp",pubp->timestamp); jadd(obj,"asks",array); jadd(obj,"unspents",unspents); From f1c4918b613ab4b107170cb25e32e28b0b6169e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 18:31:23 +0300 Subject: [PATCH 397/520] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_prices.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 85dbef365..2e94838d8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -355,13 +355,13 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) } if ( j == m ) { - printf("%s missing %s\n",peer->ipaddr,jprint(item,0)); + //printf("%s missing %s\n",peer->ipaddr,jprint(item,0)); if ( (retstr2= issue_LP_uitem(peer->ipaddr,peer->port,coin->symbol,coin->smartaddr,txid,v,jint(item,"height"),j64bits(item,"value"))) != 0 ) free(retstr2); posted++; } } - if ( 1 && posted != 0 ) + if ( 0 && posted != 0 ) printf(">>>>>>>> %s compare %s %s (%.8f n%d) (%.8f m%d)\n",peer->ipaddr,coin->symbol,coin->smartaddr,dstr(total),n,dstr(total2),m); } //else printf("%s matches\n",peer->ipaddr); free_json(array2); @@ -403,7 +403,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) } free_json(array2); } - printf("processed.(%s)\n",retstr); + //printf("processed.(%s)\n",retstr); free(retstr); } } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 3cc3856ba..79a15ade2 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -238,7 +238,7 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) jaddstr(obj,"rmd160",hexstr); init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); jaddstr(obj,"pubsecp",hexstr2); - printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); + //printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); } } } From b3e5aa4b3a66755eb10de674309576babb5dfae2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 19:36:16 +0300 Subject: [PATCH 398/520] Test --- iguana/exchanges/LP_prices.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 79a15ade2..36b1f7462 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -197,10 +197,9 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { - int32_t baseid,relid,i,j; uint64_t metric; char *base,coinaddr[64],hexstr[67],hexstr2[67]; double price; cJSON *item,*array,*obj,*unspents; struct iguana_info *coin; + int32_t baseid,relid,i,j; char *base,hexstr[67],hexstr2[67]; double price; cJSON *item,*array,*obj; obj = cJSON_CreateObject(); array = cJSON_CreateArray(); - unspents = cJSON_CreateArray(); for (baseid=0; baseidtaddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); - if ((metric= LP_unspents_metric(coin,coinaddr)) != 0 ) - jadd64bits(item,base,metric); - } - jaddi(unspents,item); } jaddbits256(obj,"pubkey",pubp->pubkey); for (i=0; irmd160); i++) @@ -239,13 +230,14 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); jaddstr(obj,"pubsecp",hexstr2); //printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); + break; } } + break; } } jaddnum(obj,"timestamp",pubp->timestamp); jadd(obj,"asks",array); - jadd(obj,"unspents",unspents); if ( pubp->istrusted != 0 ) jaddnum(obj,"istrusted",pubp->istrusted); return(obj); From b0e3393747035804813f5877c7e4fa02ec6f4e63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 19:52:06 +0300 Subject: [PATCH 399/520] Test --- iguana/exchanges/LP_ordermatch.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0fde80a5c..5f443beaf 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -670,6 +670,16 @@ char *LP_connectedalice(cJSON *argjson) // alice autxo = &A; butxo = &B; LP_abutxo_set(autxo,butxo,&Q); + if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) + { + printf("cant find autxo in quote\n"); + return(clonestr("{\"error\":\"quote autxo find error\"}")); + } + if ( autxo->S.swap != 0 ) + { + printf("swap already pending\n"); + return(clonestr("{\"error\":\"swap already pending\"}")); + } if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); From b2a491c0d75038c14cc89301643f81da76e7b385 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 19:59:50 +0300 Subject: [PATCH 400/520] Test --- iguana/exchanges/LP_prices.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 36b1f7462..a418b0ac6 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -269,13 +269,16 @@ void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) else mismatch = 0; if ( bits256_cmp(pubkey,G.LP_mypub25519) == 0 && mismatch == 0 ) peer->needping = 0; - if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 && (pubsecpstr= jstr(obj,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) + if ( mismatch != 0 && memcmp(zeroes,rmd160,sizeof(rmd160)) != 0 ) { for (i=0; i<20; i++) printf("%02x",pubp->rmd160[i]); - char str[65]; printf(" -> rmd160.(%s) for %s (%s)\n",hexstr,bits256_str(str,pubkey),pubsecpstr); memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); - decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),pubsecpstr); + if ( (pubsecpstr= jstr(obj,"pubsecp")) != 0 && is_hexstr(pubsecpstr,0) == 66 ) + { + decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),pubsecpstr); + char str[65]; printf(" -> rmd160.(%s) for %s (%s)\n",hexstr,bits256_str(str,pubkey),pubsecpstr); + } } } timestamp = juint(obj,"timestamp"); From 73dfa150eb966556b4414c992ac9783785aaae4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 20:00:36 +0300 Subject: [PATCH 401/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d65652d86..e3f63ca96 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -142,7 +142,7 @@ dividends(coin, height, )\n\ return(jprint(retjson,1)); } if ( (userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,G.USERPASS) != 0 ) - return(clonestr("{\"error\":\"authentication error\"}")); + return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); jdelete(argjson,"userpass"); if ( strcmp(method,"sendmessage") == 0 ) { From cdf87cd0add6d3b4d298e4d3cda7a71f15804337 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 20:04:01 +0300 Subject: [PATCH 402/520] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index a418b0ac6..b5d9d22cb 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -297,7 +297,7 @@ void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) { if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) { - //char str[65]; printf("%s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); + char str[65]; printf("gotprice %s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); pubp->matrix[basepp->ind][relid] = askprice; if ( (relpp= LP_priceinfofind(rel)) != 0 ) { From 2c99b7b4ffc755c9e90a2d8673cdf24a63831d35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 20:47:05 +0300 Subject: [PATCH 403/520] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_utxo.c | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index e3f63ca96..a1f4db3bc 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -474,13 +474,13 @@ dividends(coin, height, )\n\ } else if ( strcmp(method,"notify") == 0 ) { - char *rmd160str,str[65]; bits256 pub; struct LP_pubkeyinfo *pubp; + char *rmd160str; bits256 pub; struct LP_pubkeyinfo *pubp; pub = jbits256(argjson,"pub"); if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) { if ( (pubp= LP_pubkeyadd(pub)) != 0 ) decode_hex(pubp->rmd160,20,rmd160str); - printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); + //printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); } retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index b5d9d22cb..7c3574286 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -297,7 +297,7 @@ void LP_prices_parse(struct LP_peerinfo *peer,cJSON *obj) { if ( (basepp= LP_priceinfoptr(&relid,base,rel)) != 0 ) { - char str[65]; printf("gotprice %s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); + //char str[65]; printf("gotprice %s %s/%s (%d/%d) %.8f\n",bits256_str(str,pubkey),base,rel,basepp->ind,relid,askprice); pubp->matrix[basepp->ind][relid] = askprice; if ( (relpp= LP_priceinfofind(rel)) != 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e1020e7fa..580a669cd 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -310,6 +310,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) int32_t i,n,v,ht,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid; if ( (n= cJSON_GetArraySize(array)) <= 0 ) return(0); + printf("%s %s LP_unspents.(%s)\n",coin->symbol,coinaddr,jprint(array,0)); for (i=0; isymbol,"LBC") == 0 ) + printf("(%s)\n",jprint(item,0)); if ( coin->electrum == 0 && (txobj= LP_gettxout(coin->symbol,txid,v)) != 0 ) { value = LP_value_extract(txobj,0); From a92caa82224d4e9333f1103356ba8c71ac98a8b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 20:50:49 +0300 Subject: [PATCH 404/520] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 580a669cd..2a93fd278 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -210,7 +210,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); retval = 1; - if ( 0 && height > 0 ) + if ( 1 && height > 0 ) printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); From c849a147f670b426abaacd1e579640c187e4b05b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 20:55:28 +0300 Subject: [PATCH 405/520] Test --- iguana/exchanges/LP_prices.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7c3574286..72680478d 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -694,6 +694,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * minsatoshis *= price; maxsatoshis *= price; } + printf("%s/%s %s n.%d ap->n.%d %.8f\n",base,rel,coinaddr,n,ap->n,dstr(ap->total)); } if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { From 2a4946d0dea22f88504bcabcbf6904f883de2225 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 21:05:29 +0300 Subject: [PATCH 406/520] Test --- iguana/exchanges/LP_prices.c | 53 +++++------------------------- iguana/exchanges/LP_statemachine.c | 29 ++++++++++++++++ iguana/exchanges/LP_utxo.c | 2 +- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 72680478d..0d9f82450 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -221,12 +221,12 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { if ( pubp->rmd160[i] != 0 ) { + init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); + jaddstr(obj,"rmd160",hexstr); for (j=0; ipubsecp); i++) { if ( pubp->pubsecp[i] != 0 ) { - init_hexbytes_noT(hexstr,pubp->rmd160,sizeof(pubp->rmd160)); - jaddstr(obj,"rmd160",hexstr); init_hexbytes_noT(hexstr2,pubp->pubsecp,sizeof(pubp->pubsecp)); jaddstr(obj,"pubsecp",hexstr2); //printf("nonz rmd160 (%s %s)\n",hexstr,hexstr2); @@ -618,12 +618,8 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) jaddstr(item,"address",op->coinaddr); jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); - //if ( op->minsatoshis != 0 ) - jaddnum(item,"minvolume",dstr(op->minsatoshis)); - //if ( op->maxsatoshis != 0 ) - jaddnum(item,"maxvolume",dstr(op->maxsatoshis)); - //jaddbits256(item,"txid",op->txid); - //jaddnum(item,"vout",op->vout); + jaddnum(item,"minvolume",dstr(op->minsatoshis)); + jaddnum(item,"maxvolume",dstr(op->maxsatoshis)); jaddbits256(item,"pubkey",op->pubkey); jaddnum(item,"age",time(NULL)-op->timestamp); } @@ -635,10 +631,6 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d struct LP_orderbookentry *op; if ( (op= calloc(1,sizeof(*op))) != 0 ) { - //op->txid = txid; - //op->vout = vout; - //op->txid2 = txid2; - //op->vout2 = vout2; safecopy(op->coinaddr,address,sizeof(op->coinaddr)); op->price = price; op->numutxos = numutxos; @@ -650,15 +642,6 @@ struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,d return(op); } -/*int32_t LP_orderbookfind(struct LP_orderbookentry **array,int32_t num,bits256 txid,int32_t vout) -{ - int32_t i; - for (i=0; ivout == vout && bits256_cmp(array[i]->txid,txid) == 0) || (array[i]->vout2 == vout && bits256_cmp(array[i]->txid2,txid) == 0) ) - return(i); - return(-1); -}*/ - int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char *rel,struct LP_orderbookentry *(**arrayp),int32_t num,int32_t cachednum,int32_t duration) { char coinaddr[64]; uint8_t zeroes[20]; struct LP_pubkeyinfo *pubp=0,*tmp; struct LP_priceinfo *basepp; struct LP_orderbookentry *op; struct LP_address *ap; struct iguana_info *basecoin; uint32_t oldest; double price; int32_t baseid,relid,n; uint64_t minsatoshis,maxsatoshis; @@ -672,18 +655,14 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * memset(zeroes,0,sizeof(zeroes)); HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp) { - //if ( pubp->timestamp < oldest ) - // continue; if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) + { + printf("skip pubp since no rmd160\n"); continue; + } bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); minsatoshis = maxsatoshis = n = 0; ap = 0; - //char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); - //if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) - //if ( polarity > 0 ) - // minsatoshis = utxo->S.satoshis; - //else minsatoshis = utxo->S.satoshis * price; if ( (price= pubp->matrix[baseid][relid]) > SMALLVAL ) { if ( (ap= LP_addressfind(basecoin,coinaddr)) != 0 ) @@ -694,29 +673,13 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * minsatoshis *= price; maxsatoshis *= price; } - printf("%s/%s %s n.%d ap->n.%d %.8f\n",base,rel,coinaddr,n,ap->n,dstr(ap->total)); + //printf("%s/%s %s n.%d ap->n.%d %.8f\n",base,rel,coinaddr,n,ap->n,dstr(ap->total)); } if ( (op= LP_orderbookentry(coinaddr,base,rel,polarity > 0 ? price : 1./price,n,minsatoshis,maxsatoshis,pubp->pubkey,pubp->timestamp)) != 0 ) { *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); (*arrayp)[num++] = op; } - /*if ( LP_orderbookfind(*arrayp,cachednum,utxo->payment.txid,utxo->payment.vout) < 0 ) - { - if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->deposit.txid,utxo->deposit.vout) == 0 ) - continue; - if ( polarity > 0 ) - basesatoshis = utxo->S.satoshis; - else basesatoshis = utxo->S.satoshis * price; - //char str[65]; printf("found utxo not in orderbook %s/v%d %.8f %.8f\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,dstr(basesatoshis),polarity > 0 ? price : 1./price); - if ( (op= LP_orderbookentry(base,rel,utxo->payment.txid,utxo->payment.vout,utxo->deposit.txid,utxo->deposit.vout,polarity > 0 ? price : 1./price,basesatoshis,utxo->pubkey,now - pubp->timestamp)) != 0 ) - { - *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); - (*arrayp)[num++] = op; - if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) - LP_utxo_clientpublish(utxo); - } - }*/ } //printf("pubp.(%s) %.8f %p\n",coinaddr,price,ap); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 4f2e21d35..b70c7342a 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1900,6 +1900,35 @@ int32_t LP_peer_utxosquery(struct LP_peerinfo *mypeer,uint16_t myport,int32_t pu } }*/ +/*int32_t LP_orderbookfind(struct LP_orderbookentry **array,int32_t num,bits256 txid,int32_t vout) + { + int32_t i; + for (i=0; ivout == vout && bits256_cmp(array[i]->txid,txid) == 0) || (array[i]->vout2 == vout && bits256_cmp(array[i]->txid2,txid) == 0) ) + return(i); + return(-1); + }*/ +//char str[65],str2[65]; printf("check utxo.%s/v%d from %s\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,bits256_str(str2,utxo->pubkey)); +//if ( strcmp(base,utxo->coin) == 0 && LP_isavailable(utxo) > 0 && pubp != 0 && (price= pubp->matrix[baseid][relid]) > SMALLVAL ) +//if ( polarity > 0 ) +// minsatoshis = utxo->S.satoshis; +//else minsatoshis = utxo->S.satoshis * price; +/*if ( LP_orderbookfind(*arrayp,cachednum,utxo->payment.txid,utxo->payment.vout) < 0 ) + { + if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->deposit.txid,utxo->deposit.vout) == 0 ) + continue; + if ( polarity > 0 ) + basesatoshis = utxo->S.satoshis; + else basesatoshis = utxo->S.satoshis * price; + //char str[65]; printf("found utxo not in orderbook %s/v%d %.8f %.8f\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout,dstr(basesatoshis),polarity > 0 ? price : 1./price); + if ( (op= LP_orderbookentry(base,rel,utxo->payment.txid,utxo->payment.vout,utxo->deposit.txid,utxo->deposit.vout,polarity > 0 ? price : 1./price,basesatoshis,utxo->pubkey,now - pubp->timestamp)) != 0 ) + { + *arrayp = realloc(*arrayp,sizeof(*(*arrayp)) * (num+1)); + (*arrayp)[num++] = op; + if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) + LP_utxo_clientpublish(utxo); + } + }*/ #ifdef oldway struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,uint64_t maxdestsatoshis) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 2a93fd278..81273ece5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -310,7 +310,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) int32_t i,n,v,ht,errs,height,count=0; uint64_t value,val; cJSON *item,*txobj; bits256 txid; if ( (n= cJSON_GetArraySize(array)) <= 0 ) return(0); - printf("%s %s LP_unspents.(%s)\n",coin->symbol,coinaddr,jprint(array,0)); + //printf("%s %s LP_unspents.(%s)\n",coin->symbol,coinaddr,jprint(array,0)); for (i=0; i Date: Thu, 28 Sep 2017 21:18:38 +0300 Subject: [PATCH 407/520] Test --- iguana/exchanges/LP_commands.c | 9 ++++++++- iguana/exchanges/LP_nativeDEX.c | 9 ++++++++- iguana/exchanges/LP_ordermatch.c | 13 +++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a1f4db3bc..bb16a60ee 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -474,12 +474,19 @@ dividends(coin, height, )\n\ } else if ( strcmp(method,"notify") == 0 ) { - char *rmd160str; bits256 pub; struct LP_pubkeyinfo *pubp; + char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; pub = jbits256(argjson,"pub"); if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) { if ( (pubp= LP_pubkeyadd(pub)) != 0 ) + { decode_hex(pubp->rmd160,20,rmd160str); + if ( (secpstr= jstr(argjson,"pubsecp")) != 0 ) + { + decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr); + printf("got pubkey.(%s)\n",secpstr); + } + } //printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); } retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2e94838d8..07af4de99 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -413,13 +413,14 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { static uint32_t counter,numpeers; - struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; bits256 zero; int32_t height,nonz = 0; + struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; bits256 zero; int32_t needpings,height,nonz = 0; now = (uint32_t)time(NULL); if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; if ( mypeer == 0 ) myipaddr = "127.0.0.1"; numpeers = LP_numpeers(); + needpings = 0; HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( peer->errors >= LP_MAXPEER_ERRORS ) @@ -450,11 +451,17 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( peer->needping != 0 ) { + needpings++; if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) free(retstr); peer->needping = 0; } } + if ( needpings != 0 ) + { + printf("needpings.%d send notify\n",needpings); + LP_notify_pubkeys(ctx,pubsock); + } if ( (counter % 6000) == 10 ) { LP_privkey_updates(ctx,pubsock,0); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5f443beaf..9a536a236 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -231,6 +231,19 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re return(clonestr("{\"result\":\"success\"}")); } +void LP_notify_pubkeys(void *ctx,int32_t pubsock) +{ + bits256 zero; char *msg,secpstr[67]; cJSON *reqjson = cJSON_CreateObject(); + memset(zero.bytes,0,sizeof(zero)); + jaddstr(reqjson,"method","notify"); + jaddstr(reqjson,"rmd160",G.LP_myrmd160str); + jaddbits256(reqjson,"pub",G.LP_mypub25519); + init_hexbytes_noT(secpstr,G.LP_pubsecp,33); + jaddstr(reqjson,"pubsecp",secpstr); + msg = jprint(reqjson,1); + LP_broadcast_message(pubsock,"","",zero,msg); +} + char *LP_postedprice(cJSON *argjson) { bits256 pubkey; double price; char *base,*rel; From b6c9603b75bf22a82387de7f278e6489f6066df8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 21:29:08 +0300 Subject: [PATCH 408/520] Test --- iguana/exchanges/LP_utxo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 81273ece5..a38aef168 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -210,7 +210,7 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, DL_APPEND(ap->utxos,up); portable_mutex_unlock(&coin->addrmutex); retval = 1; - if ( 1 && height > 0 ) + if ( 0 && height > 0 ) printf("ADDRESS_UTXO >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value)); } } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); @@ -319,8 +319,8 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) v = jint(item,"tx_pos"); height = jint(item,"height"); val = j64bits(item,"value"); - if ( strcmp(coin->symbol,"LBC") == 0 ) - printf("(%s)\n",jprint(item,0)); + //if ( strcmp(coin->symbol,"LBC") == 0 ) + // printf("(%s)\n",jprint(item,0)); if ( coin->electrum == 0 && (txobj= LP_gettxout(coin->symbol,txid,v)) != 0 ) { value = LP_value_extract(txobj,0); From f263049b6f4c9ad659e52cde43069845254ac0c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 21:33:33 +0300 Subject: [PATCH 409/520] Test --- iguana/exchanges/LP_commands.c | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index bb16a60ee..9afc92556 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -428,6 +428,25 @@ dividends(coin, height, )\n\ firsttime = (uint32_t)(time(NULL)-30*24*3600); return(jprint(LP_pricearray(base,rel,firsttime,juint(argjson,"lasttime"),jint(argjson,"timescale")),1)); } + else if ( strcmp(method,"notify") == 0 ) + { + char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; + pub = jbits256(argjson,"pub"); + if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) + { + if ( (pubp= LP_pubkeyadd(pub)) != 0 ) + { + decode_hex(pubp->rmd160,20,rmd160str); + if ( (secpstr= jstr(argjson,"pubsecp")) != 0 ) + { + decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr); + printf("got pubkey.(%s)\n",secpstr); + } + } + //printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); + } + retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); + } if ( IAMLP != 0 ) { if ( strcmp(method,"register") == 0 ) @@ -472,25 +491,6 @@ dividends(coin, height, )\n\ return(LP_psock(myipaddr,jint(argjson,"ispaired"))); else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}")); } - else if ( strcmp(method,"notify") == 0 ) - { - char *rmd160str,*secpstr; bits256 pub; struct LP_pubkeyinfo *pubp; - pub = jbits256(argjson,"pub"); - if ( bits256_nonz(pub) != 0 && (rmd160str= jstr(argjson,"rmd160")) != 0 && strlen(rmd160str) == 40 ) - { - if ( (pubp= LP_pubkeyadd(pub)) != 0 ) - { - decode_hex(pubp->rmd160,20,rmd160str); - if ( (secpstr= jstr(argjson,"pubsecp")) != 0 ) - { - decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr); - printf("got pubkey.(%s)\n",secpstr); - } - } - //printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); - } - retstr = clonestr("{\"result\":\"success\",\"notify\":\"received\"}"); - } } else { From 9677a385f0d8821ad0ed023b02c845246fbf359e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 21:43:42 +0300 Subject: [PATCH 410/520] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 9afc92556..df62ebfb1 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -440,7 +440,7 @@ dividends(coin, height, )\n\ if ( (secpstr= jstr(argjson,"pubsecp")) != 0 ) { decode_hex(pubp->pubsecp,sizeof(pubp->pubsecp),secpstr); - printf("got pubkey.(%s)\n",secpstr); + //printf("got pubkey.(%s)\n",secpstr); } } //printf("NOTIFIED pub %s rmd160 %s\n",bits256_str(str,pub),rmd160str); From bed61a7abd5ed0e2d16cf10a1989575db7703b29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 21:45:20 +0300 Subject: [PATCH 411/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 07af4de99..e9810ba40 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -457,9 +457,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int peer->needping = 0; } } - if ( needpings != 0 ) + if ( needpings != 0 || (counter % 6000) == 5 ) { - printf("needpings.%d send notify\n",needpings); + //printf("needpings.%d send notify\n",needpings); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 ) From 85ee2a87719b799d71d740f00173067c590040e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 22:21:44 +0300 Subject: [PATCH 412/520] Test --- iguana/exchanges/LP_ordermatch.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9a536a236..95a3d616f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -683,16 +683,17 @@ char *LP_connectedalice(cJSON *argjson) // alice autxo = &A; butxo = &B; LP_abutxo_set(autxo,butxo,&Q); - if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) - { - printf("cant find autxo in quote\n"); - return(clonestr("{\"error\":\"quote autxo find error\"}")); - } - if ( autxo->S.swap != 0 ) + if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) { printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); } + autxo = LP_utxoadd(0,LP_mypubsock,Q.destcoin,Q.desttxid,Q.destvout,Q.destsatoshis,Q.feetxid,Q.feevout,0,"",Q.destaddr,Q.desthash,LP_gui,G.LP_sessionid); + if ( autxo == 0 ) + { + printf("couldnt create autxo\n"); + return(clonestr("{\"error\":\"couldnt create autxo\"}")); + } if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); From c9c0ec3b542c9818b2c64ba09e756cf473488390 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 22:38:23 +0300 Subject: [PATCH 413/520] Test --- iguana/exchanges/LP_ordermatch.c | 17 +++++++++++------ iguana/exchanges/LP_swap.c | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 95a3d616f..7ebda4f53 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -679,11 +679,16 @@ char *LP_connectedalice(cJSON *argjson) // alice clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) return(clonestr("{\"result\",\"update stats\"}")); - printf("CONNECTED.(%s)\n",jprint(argjson,0)); + printf("CONNECTED.(%s) numpending.%d\n",jprint(argjson,0),G.LP_pendingswaps); + if ( G.LP_pendingswaps > 0 ) + { + printf("swap already pending\n"); + return(clonestr("{\"error\":\"swap already pending\"}")); + } autxo = &A; butxo = &B; LP_abutxo_set(autxo,butxo,&Q); - if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) + /*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) { printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); @@ -693,11 +698,11 @@ char *LP_connectedalice(cJSON *argjson) // alice { printf("couldnt create autxo\n"); return(clonestr("{\"error\":\"couldnt create autxo\"}")); - } + }*/ if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); - G.LP_pendingswaps--; + //G.LP_pendingswaps--; printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); } @@ -705,7 +710,7 @@ char *LP_connectedalice(cJSON *argjson) // alice { printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask); LP_availableset(autxo); - G.LP_pendingswaps--; + //G.LP_pendingswaps--; return(clonestr("{\"error\":\"no price set\"}")); } // SPV validate bobs @@ -713,7 +718,7 @@ char *LP_connectedalice(cJSON *argjson) // alice price = bid; if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) { - G.LP_pendingswaps--; + //G.LP_pendingswaps--; return(clonestr("{\"error\":\"cant get alicecoin\"}")); } Q.privkey = LP_privkey(Q.destaddr,coin->taddr); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 32d255a5b..3821605c7 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -821,6 +821,7 @@ void LP_aliceloop(void *_swap) nn_close(swap->N.pair); swap->N.pair = -1; } + G.LP_pendingswaps--; } bits256 instantdex_derivekeypair(void *ctx,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash) From d512b2f13e76751592274f1e79a32fe7df139c7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Sep 2017 23:39:09 +0300 Subject: [PATCH 414/520] Test --- iguana/exchanges/LP_swap.c | 8 ++++++-- iguana/exchanges/LP_transaction.c | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 3821605c7..306cab38c 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -613,8 +613,11 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3 rawtx->I.actualtxid = LP_broadcast_tx(rawtx->name,rawtx->coin->symbol,rawtx->txbytes,rawtx->I.datalen); if ( bits256_cmp(rawtx->I.actualtxid,rawtx->I.signedtxid) != 0 ) { - //printf("%s rawtxsend.[%d] %s vs %s\n",rawtx->name,rawtx->I.datalen,bits256_str(str,rawtx->I.signedtxid),bits256_str(str2,rawtx->I.actualtxid)); - rawtx->I.actualtxid = rawtx->I.signedtxid; + char str[65],str2[65]; + printf("%s rawtxsend.[%d] %s vs %s\n",rawtx->name,rawtx->I.datalen,bits256_str(str,rawtx->I.signedtxid),bits256_str(str2,rawtx->I.actualtxid)); + if ( bits256_nonz(rawtx->I.signedtxid) != 0 ) + rawtx->I.actualtxid = rawtx->I.signedtxid; + else rawtx->I.signedtxid = rawtx->I.actualtxid; } if ( bits256_nonz(rawtx->I.actualtxid) != 0 && msgbits != 0 ) { @@ -662,6 +665,7 @@ int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleep(10); if ( sleeptime < divisor*60 ) sleeptime = divisor * 60; + //check for completed one being spent, prevent autxo reuse, add extra hash to keypair25519, sign, spv check while ( time(NULL) < expiration ) { if ( (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index c05ae4613..489de1632 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -70,6 +70,8 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi break; sleep(3); } + if ( sentflag != 0 ) + return(expectedtxid); return(txid); } From 68d230eb0e7d3336eced903d9edd3c9b8854a82e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 11:20:38 +0300 Subject: [PATCH 415/520] Test --- iguana/exchanges/LP_scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 2af0d9f9f..006b4b6cf 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -495,7 +495,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int } if ( time(NULL) > expiration || numconfirms >= 0 ) break; - usleep(500000); + sleep(10); } if ( numconfirms <= 0 ) numconfirms = LP_numconfirms(symbol,coinaddr,txid,vout,1); From 6405f8f37e82e85ac914fe79c0c44804c389ee28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 11:24:41 +0300 Subject: [PATCH 416/520] Iterate through sellers --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 7ebda4f53..0869399f2 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1070,7 +1070,7 @@ exit(-1); continue; //return(clonestr("{\"error\":\"quote validation error\"}")); } - break; + //break; } //printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); From a5ec865a41ef0167f7298b291e5568877744ab52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 14:13:53 +0300 Subject: [PATCH 417/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_ordermatch.c | 2 -- iguana/exchanges/LP_swap.c | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e9810ba40..41c2267f5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -23,10 +23,10 @@ // bittrex balancing // detect port conflicts on enable // stats -// dynamic txid2 allocation // unduplicated bugs: // swap cancel should cleanly cancel +// check for completed one being spent, prevent autxo reuse, add extra hash to keypair25519, sign, spv check #include #include "LP_include.h" @@ -514,7 +514,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int LP_getestimatedrate(coin); break; } - if ( (counter % 6000) == 60 ) + if ( 0 && (counter % 6000) == 60 ) { if ( (retstr= basilisk_swapentry(0,0)) != 0 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0869399f2..e61e92913 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -713,7 +713,6 @@ char *LP_connectedalice(cJSON *argjson) // alice //G.LP_pendingswaps--; return(clonestr("{\"error\":\"no price set\"}")); } - // SPV validate bobs printf("%s/%s bid %.8f ask %.8f\n",Q.srccoin,Q.destcoin,bid,ask); price = bid; if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) @@ -1066,7 +1065,6 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); -exit(-1); continue; //return(clonestr("{\"error\":\"quote validation error\"}")); } diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 306cab38c..55341236f 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -665,7 +665,6 @@ int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleep(10); if ( sleeptime < divisor*60 ) sleeptime = divisor * 60; - //check for completed one being spent, prevent autxo reuse, add extra hash to keypair25519, sign, spv check while ( time(NULL) < expiration ) { if ( (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) From be872ded56b4062131aecdae868eacdfa7941a0c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 15:06:57 +0300 Subject: [PATCH 418/520] Reentrancy --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_ordermatch.c | 12 ++++++------ iguana/exchanges/LP_swap.c | 7 +++++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 6a7499747..fa0eb746d 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -298,6 +298,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee); struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr); int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson); +void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 41c2267f5..25b34acd7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -26,7 +26,8 @@ // unduplicated bugs: // swap cancel should cleanly cancel -// check for completed one being spent, prevent autxo reuse, add extra hash to keypair25519, sign, spv check +// check for completed one being spent +// prevent autxo reuse, add extra hash to keypair25519, sign, spv check #include #include "LP_include.h" diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e61e92913..6c249ff39 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -674,7 +674,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) @@ -685,8 +685,8 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); } - autxo = &A; - butxo = &B; + autxo = calloc(1,sizeof(*autxo)); + butxo = calloc(1,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); /*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) { @@ -798,7 +798,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); @@ -811,8 +811,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - autxo = &A; - butxo = &B; + autxo = calloc(1,sizeof(*autxo)); + butxo = calloc(1,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 55341236f..90e565c6d 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -121,7 +121,10 @@ void basilisk_swap_finished(struct basilisk_swap *swap) { int32_t i; if ( swap->utxo != 0 && swap->sentflag == 0 ) + { LP_availableset(swap->utxo); + LP_butxo_swapfields_set(swap->utxo); + } swap->I.finished = (uint32_t)time(NULL); // save to permanent storage basilisk_rawtx_purge(&swap->bobdeposit); @@ -815,8 +818,6 @@ void LP_aliceloop(void *_swap) } } } - basilisk_swap_finished(swap); - free(swap); } free(data); if ( swap->N.pair >= 0 ) @@ -824,6 +825,8 @@ void LP_aliceloop(void *_swap) nn_close(swap->N.pair); swap->N.pair = -1; } + basilisk_swap_finished(swap); + free(swap); G.LP_pendingswaps--; } From 8d029bfe68751c7c5513b58bd2957c75689564b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 22:56:30 +0300 Subject: [PATCH 419/520] Test --- iguana/exchanges/LP_ordermatch.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 6c249ff39..e61e92913 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -674,7 +674,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) @@ -685,8 +685,8 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); } - autxo = calloc(1,sizeof(*autxo)); - butxo = calloc(1,sizeof(*butxo)); + autxo = &A; + butxo = &B; LP_abutxo_set(autxo,butxo,&Q); /*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) { @@ -798,7 +798,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); @@ -811,8 +811,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - autxo = calloc(1,sizeof(*autxo)); - butxo = calloc(1,sizeof(*butxo)); + autxo = &A; + butxo = &B; LP_abutxo_set(autxo,butxo,&Q); LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) From 9ca0c5f7142052c0af9af80e9a360ef1343df587 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 22:59:47 +0300 Subject: [PATCH 420/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e61e92913..98676988f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1068,7 +1068,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel continue; //return(clonestr("{\"error\":\"quote validation error\"}")); } - //break; + break; } //printf("do quote.(%s)\n",jprint(LP_quotejson(&Q),1)); return(LP_trade(ctx,myipaddr,mypubsock,&Q,maxprice,timeout,duration)); From 7f248db8b8c3d4a6d6177ee7f6ddb67229ce865c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 23:03:08 +0300 Subject: [PATCH 421/520] Test --- iguana/exchanges/LP_ordermatch.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 98676988f..115c81ff8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -674,7 +674,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) @@ -685,8 +685,8 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); } - autxo = &A; - butxo = &B; + autxo = calloc(1,sizeof(*autxo));//&A; + butxo = calloc(1,sizeof(*butxo));//&B; LP_abutxo_set(autxo,butxo,&Q); /*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) { @@ -798,7 +798,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); @@ -811,8 +811,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - autxo = &A; - butxo = &B; + autxo = calloc(1,sizeof(*autxo));//&A; + butxo = calloc(1,sizeof(*butxo));//&B; LP_abutxo_set(autxo,butxo,&Q); LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) From a4dac78ecd1f4848f4921988005c3454fbe67ddb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Sep 2017 23:10:05 +0300 Subject: [PATCH 422/520] Test --- iguana/exchanges/LP_ordermatch.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 115c81ff8..98676988f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -674,7 +674,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) @@ -685,8 +685,8 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); } - autxo = calloc(1,sizeof(*autxo));//&A; - butxo = calloc(1,sizeof(*butxo));//&B; + autxo = &A; + butxo = &B; LP_abutxo_set(autxo,butxo,&Q); /*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) { @@ -798,7 +798,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo *autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); @@ -811,8 +811,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, return(-3); } price = ask; - autxo = calloc(1,sizeof(*autxo));//&A; - butxo = calloc(1,sizeof(*butxo));//&B; + autxo = &A; + butxo = &B; LP_abutxo_set(autxo,butxo,&Q); LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) From 9a2f5c735cc2f3ba4d1f4b0e9d08d3513b4fa5b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 13:34:18 +0300 Subject: [PATCH 423/520] fixes detect port conflicts on enable check for completed swap tx being spent prevent autxo reuse add extra hash to keypair25519 --- iguana/exchanges/LP_coins.c | 13 +++ iguana/exchanges/LP_commands.c | 10 ++- iguana/exchanges/LP_include.h | 12 ++- iguana/exchanges/LP_nativeDEX.c | 13 +-- iguana/exchanges/LP_ordermatch.c | 125 +++++++++++++++-------------- iguana/exchanges/LP_prices.c | 46 +++++++++++ iguana/exchanges/LP_statemachine.c | 20 +++++ iguana/exchanges/LP_swap.c | 3 +- iguana/exchanges/LP_utxo.c | 37 +++++---- iguana/exchanges/LP_utxos.c | 49 ++++------- 10 files changed, 204 insertions(+), 124 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index f9ae0c9a8..bf02bc11a 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -201,6 +201,19 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) return(item); } +struct iguana_info *LP_conflicts_find(struct iguana_info *refcoin) +{ + struct iguana_info *coin=0,*tmp; + HASH_ITER(hh,LP_coins,coin,tmp) + { + if ( coin->inactive != 0 || coin->electrum != 0 || coin == refcoin ) + continue; + if ( strcmp(coin->serverport,refcoin->serverport) == 0 ) + break; + } + return(coin); +} + cJSON *LP_coinsjson(int32_t showwif) { struct iguana_info *coin,*tmp; cJSON *array = cJSON_CreateArray(); diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index df62ebfb1..bb7d1e49b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -112,7 +112,7 @@ getcoins()\n\ getcoin(coin)\n\ portfolio()\n\ getpeers()\n\ -passphrase(passphrase)\n\ +passphrase(passphrase, gui)\n\ listunspent(coin, address)\n\ orderbook(base, rel, duration=3600)\n\ getprices(base, rel)\n\ @@ -166,7 +166,7 @@ dividends(coin, height, )\n\ } else if ( strcmp(method,"passphrase") == 0 ) { - if ( LP_passphrase_init(jstr(argjson,"passphrase")) < 0 ) + if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui")) < 0 ) return(clonestr("{\"error\":\"couldnt change passphrase\"}")); { retjson = cJSON_CreateObject(); @@ -253,7 +253,11 @@ dividends(coin, height, )\n\ if ( strcmp(method,"enable") == 0 ) { if ( (ptr= LP_coinsearch(coin)) != 0 ) - ptr->inactive = 0; + { + if ( LP_conflicts_find(ptr) == 0 ) + ptr->inactive = 0; + else return(clonestr("{\"error\":\"coin port conflicts with existing coin\"}")); + } return(jprint(LP_coinsjson(0),1)); } else if ( strcmp(method,"disable") == 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index fa0eb746d..233c1a70e 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -212,7 +212,7 @@ struct LP_utxoinfo int32_t iambob,iamlp; uint8_t key[sizeof(bits256) + sizeof(int32_t)]; uint8_t key2[sizeof(bits256) + sizeof(int32_t)]; - char coin[16],coinaddr[64],spendscript[256],gui[16]; + char coin[16],coinaddr[64],gui[16];//spendscript[256]; }; struct LP_address_utxo @@ -226,9 +226,11 @@ struct LP_address { UT_hash_handle hh; struct LP_address_utxo *utxos; + bits256 pubkey; int64_t balance,total; uint32_t timestamp,n; char coinaddr[40]; + uint8_t pubsecp[33],pad; }; struct LP_peerinfo @@ -297,8 +299,10 @@ int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price); uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee); struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr); +struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr); +struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr); int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson); -void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo); +//void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); @@ -310,10 +314,12 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout); void LP_postutxos(char *symbol,char *coinaddr); int32_t LP_listunspent_both(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); -int32_t LP_butxo_findeither(bits256 txid,int32_t vout); +//int32_t LP_butxo_findeither(bits256 txid,int32_t vout); cJSON *LP_listunspent(char *symbol,char *coinaddr); int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid); double LP_getestimatedrate(struct iguana_info *coin); +struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout); +struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid,int32_t vout); #endif diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 25b34acd7..945c2a1d8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -20,14 +20,17 @@ // marketmaker // // new features: +// sign, spv check // bittrex balancing -// detect port conflicts on enable // stats +// -detect port conflicts on enable +// -check for completed one being spent +// -prevent autxo reuse +// -add extra hash to keypair25519 + // unduplicated bugs: // swap cancel should cleanly cancel -// check for completed one being spent -// prevent autxo reuse, add extra hash to keypair25519, sign, spv check #include #include "LP_include.h" @@ -64,7 +67,7 @@ struct LP_globals uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; int32_t LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting; - char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41]; + char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16]; struct LP_privkey LP_privkeys[100]; } G; @@ -693,7 +696,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("initcoins\n"); LP_initcoins(ctx,pubsock,jobj(argjson,"coins")); G.waiting = 1; - LP_passphrase_init(passphrase); + LP_passphrase_init(passphrase,jstr(argjson,"gui")); if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 ) { printf("error launching LP_psockloop for (%s)\n",myipaddr); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 98676988f..02b67ddf9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -435,7 +435,7 @@ int32_t LP_nanobind(void *ctx,char *pairstr) return(pairsock); } -struct LP_utxoinfo BUTXOS[100]; +/*struct LP_utxoinfo BUTXOS[100]; int32_t LP_butxo_findeither(bits256 txid,int32_t vout) { @@ -452,7 +452,7 @@ int32_t LP_butxo_findeither(bits256 txid,int32_t vout) } portable_mutex_unlock(&LP_butxomutex); return(retval); -} +}*/ int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t targetval) { @@ -481,12 +481,12 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d else return(0); } -struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,int32_t avoidflag,uint64_t desttxfee) +struct LP_utxoinfo *LP_address_utxopair(struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,uint64_t desttxfee) { - struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; + struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; struct LP_utxoinfo *utxo = 0; if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) { - if ( (m= LP_address_utxo_ptrs(utxos,max,ap,avoidflag)) > 1 ) + if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) { targetval = LP_basesatoshis(volume,price,txfee,desttxfee); if ( 0 ) @@ -505,18 +505,12 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre { if ( up != 0 && (up2= utxos[mini]) != 0 ) { - safecopy(utxo->coin,coin->symbol,sizeof(utxo->coin)); - safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); - utxo->payment.txid = up->U.txid; - utxo->payment.vout = up->U.vout; - utxo->payment.value = up->U.value; - utxo->iambob = 1; - utxo->deposit.txid = up2->U.txid; - utxo->deposit.vout = up2->U.vout; - utxo->deposit.value = up2->U.value; - utxo->S.satoshis = targetval; - printf("targetval %.8f, found val %.8f | targetval2 %.8f val2 %.8f\n",dstr(targetval),dstr(up->U.value),dstr(targetval2),dstr(up2->U.value)); - return(utxo); + if ( (utxo= LP_utxoadd(1,coin->symbol,up->U.txid,up->U.vout,up->U.value,up2->U.txid,up2->U.vout,up2->U.value,coinaddr,ap->pubkey,G.gui,0)) != 0 ) + { + utxo->S.satoshis = targetval; + printf("targetval %.8f, found val %.8f | targetval2 %.8f val2 %.8f\n",dstr(targetval),dstr(up->U.value),dstr(targetval2),dstr(up2->U.value)); + return(utxo); + } } } } @@ -525,7 +519,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_utxoinfo *utxo,struct LP_addre return(0); } -struct LP_utxoinfo *_LP_butxo_find(struct LP_utxoinfo *butxo) +/*struct LP_utxoinfo *_LP_butxo_find(struct LP_utxoinfo *butxo) { int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); //portable_mutex_lock(&LP_butxomutex); @@ -586,7 +580,7 @@ void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) { LP_butxo_swapfields_copy(setutxo,butxo); } -} +}*/ void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) { @@ -668,37 +662,49 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ nn_close(pair); LP_availableset(utxo); } else LP_unavailableset(utxo,utxo->S.otherpubkey); - LP_butxo_swapfields(utxo); + //LP_butxo_swapfields(utxo); return(retval); } char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo A,B,*autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; uint64_t value,value2; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) return(clonestr("{\"result\",\"update stats\"}")); printf("CONNECTED.(%s) numpending.%d\n",jprint(argjson,0),G.LP_pendingswaps); - if ( G.LP_pendingswaps > 0 ) + /*if ( G.LP_pendingswaps > 0 ) { printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); - } - autxo = &A; - butxo = &B; - LP_abutxo_set(autxo,butxo,&Q); - /*if ( (autxo= LP_utxopairfind(0,Q.txid,Q.vout,Q.txid2,Q.vout2)) != 0 && autxo->S.swap != 0 ) + }*/ + if ( (autxo= LP_utxopairfind(1,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) { - printf("swap already pending\n"); - return(clonestr("{\"error\":\"swap already pending\"}")); + printf("cant find autxo\n"); + return(clonestr("{\"error\":\"cant find autxo\"}")); } - autxo = LP_utxoadd(0,LP_mypubsock,Q.destcoin,Q.desttxid,Q.destvout,Q.destsatoshis,Q.feetxid,Q.feevout,0,"",Q.destaddr,Q.desthash,LP_gui,G.LP_sessionid); - if ( autxo == 0 ) + LP_abutxo_set(autxo,0,&Q); + if ( (butxo= LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) { - printf("couldnt create autxo\n"); - return(clonestr("{\"error\":\"couldnt create autxo\"}")); - }*/ + value = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid,Q.vout); + value2 = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid2,Q.vout2); + if ( value == 0 || value2 == 0 ) + { + printf("zero value %.8f or value2 %.8f\n",dstr(value),dstr(value2)); + return(clonestr("{\"error\":\"spent txid or txid2 for bob?\"}")); + } + if ( (butxo= LP_utxoadd(1,Q.srccoin,Q.txid,Q.vout,value,Q.txid2,Q.vout2,value2,Q.coinaddr,Q.srchash,LP_gui,0)) == 0 ) + { + printf("cant find or create butxo\n"); + return(clonestr("{\"error\":\"cant find or create butxo\"}")); + } + if ( value < Q.satoshis ) + { + printf("butxo value %.8f less satoshis %.8f\n",dstr(value),dstr(Q.satoshis)); + return(clonestr("{\"error\":\"butxo value less than satoshis\"}")); + } + } if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); @@ -713,7 +719,7 @@ char *LP_connectedalice(cJSON *argjson) // alice //G.LP_pendingswaps--; return(clonestr("{\"error\":\"no price set\"}")); } - printf("%s/%s bid %.8f ask %.8f\n",Q.srccoin,Q.destcoin,bid,ask); + printf("%s/%s bid %.8f ask %.8f values %.8f %.8f\n",Q.srccoin,Q.destcoin,bid,ask,dstr(butxo->payment.value),dstr(butxo->deposit.value)); price = bid; if ( (coin= LP_coinfind(Q.destcoin)) == 0 ) { @@ -813,22 +819,26 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, price = ask; autxo = &A; butxo = &B; + memset(autxo,0,sizeof(*autxo)); + memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); - LP_butxo_swapfields(butxo); + //LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { - if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) + if ( LP_unallocated(butxo->payment.txid,butxo->payment.vout) != 0 || LP_unallocated(butxo->deposit.txid,butxo->deposit.vout) != 0 || (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { LP_listunspent_both(Q.srccoin,Q.coinaddr); - butxo = LP_address_utxopair(butxo,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,1,Q.desttxfee); - Q.txid = butxo->payment.txid; - Q.vout = butxo->payment.vout; - Q.txid2 = butxo->deposit.txid; - Q.vout2 = butxo->deposit.vout; - LP_abutxo_set(0,butxo,&Q); - LP_butxo_swapfields(butxo); - } - } + if ( (butxo= LP_address_utxopair(utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) + { + Q.txid = butxo->payment.txid; + Q.vout = butxo->payment.vout; + Q.txid2 = butxo->deposit.txid; + Q.vout2 = butxo->deposit.vout; + } + //LP_abutxo_set(0,butxo,&Q); + //LP_butxo_swapfields(butxo); + } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); + } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { char str[65]; printf("couldnt find bob utxos for autxo %s/v%d %.8f\n",bits256_str(str,autxo->payment.txid),autxo->payment.vout,dstr(autxo->S.satoshis)); @@ -869,7 +879,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, msg2 = clonestr(msg); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,zero,msg); LP_broadcast_message(pubsock,Q.srccoin,Q.destcoin,butxo->S.otherpubkey,msg2); - LP_butxo_swapfields_set(butxo); + //LP_butxo_swapfields_set(butxo); printf("return after RESERVED\n"); return(2); } @@ -882,12 +892,12 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { // validate SPV alice LP_connectstartbob(ctx,pubsock,butxo,argjson,Q.srccoin,Q.destcoin,qprice,&Q); - LP_butxo_swapfields_set(butxo); + //LP_butxo_swapfields_set(butxo); return(3); } else printf("pend.%u swap %p when connect came in (%s)\n",butxo->T.swappending,butxo->S.swap,jprint(argjson,0)); } - LP_butxo_swapfields_set(butxo); + //LP_butxo_swapfields_set(butxo); } } return(retval); @@ -925,8 +935,6 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q if ( aliceutxo->S.swap != 0 ) break; sleep(3); - //price = LP_query(ctx,myipaddr,mypubsock,"connect",qp); - //LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); } if ( aliceutxo->S.swap == 0 ) { @@ -957,7 +965,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q return(jprint(bestitem,0)); } -struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui,bits256 *avoids,int32_t numavoids) +struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,int64_t *bestdestsatoshisp,struct LP_utxoinfo *autxo,char *base,double maxprice,int32_t duration,uint64_t txfee,uint64_t desttxfee,char *gui,bits256 *avoids,int32_t numavoids) { bits256 pubkey; char *obookstr,coinaddr[64],str[65]; cJSON *orderbook,*asks,*item; int32_t i,j,n,numasks,max = 10000; struct LP_address_utxo **utxos; double price; struct LP_pubkeyinfo *pubp; struct iguana_info *basecoin; uint64_t basesatoshis; struct LP_utxoinfo *bestutxo = 0; *ordermatchpricep = 0.; @@ -996,7 +1004,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice if ( n > 1 ) { basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); - if ( basesatoshis != 0 && (bestutxo= LP_address_utxopair(space,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,0,desttxfee)) != 0 ) + if ( basesatoshis != 0 && (bestutxo= LP_address_utxopair(utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); @@ -1031,7 +1039,7 @@ struct LP_utxoinfo *LP_buyutxo(struct LP_utxoinfo *space,double *ordermatchprice 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) { - uint64_t desttxfee,txfee; int32_t numpubs = 0; int64_t bestsatoshis=0,destsatoshis,bestdestsatoshis=0; struct LP_utxoinfo *autxo,_bestB,_bestA,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; bits256 pubkeys[100]; + uint64_t desttxfee,txfee; int32_t numpubs = 0; int64_t bestsatoshis=0,destsatoshis,bestdestsatoshis=0; struct LP_utxoinfo *autxo,*bestutxo = 0; double qprice,ordermatchprice=0.; struct LP_quoteinfo Q; bits256 pubkeys[100]; printf("LP_autobuy %s/%s price %.8f vol %.8f\n",base,rel,maxprice,relvolume); if ( duration <= 0 ) duration = LP_ORDERBOOK_DURATION; @@ -1041,18 +1049,14 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"invalid parameter\"}")); memset(pubkeys,0,sizeof(pubkeys)); LP_txfees(&txfee,&desttxfee,base,rel); - memset(&_bestA,0,sizeof(_bestA)); - memset(&_bestB,0,sizeof(_bestB)); destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); - _bestA = *autxo; - autxo = &_bestA; if ( destsatoshis < autxo->S.satoshis ) autxo->S.satoshis = destsatoshis; while ( 1 ) { - if ( (bestutxo= LP_buyutxo(&_bestB,&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui,pubkeys,numpubs)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) + if ( (bestutxo= LP_buyutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,gui,pubkeys,numpubs)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 ) { printf("bestutxo.%p ordermatchprice %.8f bestdestsatoshis %.8f\n",bestutxo,ordermatchprice,dstr(bestdestsatoshis)); return(clonestr("{\"error\":\"cant find ordermatch utxo\"}")); @@ -1064,9 +1068,8 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"cant set ordermatch quote info\"}")); if ( (qprice= LP_quote_validate(autxo,0,&Q,0)) <= SMALLVAL ) { - printf("quote validate error %.0f\n",qprice); + printf("continue searching, quote validate error %.0f\n",qprice); continue; - //return(clonestr("{\"error\":\"quote validation error\"}")); } break; } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0d9f82450..bf347411d 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -126,6 +126,52 @@ struct LP_cacheinfo *LP_cachefind(char *base,char *rel,bits256 txid,int32_t vout return(ptr); } +struct LP_pubkeyinfo *LP_pubkey_rmd160find(uint8_t rmd160[20]) +{ + struct LP_pubkeyinfo *pubp=0,*tmp; + portable_mutex_lock(&LP_pubkeymutex); + HASH_ITER(hh,LP_pubkeyinfos,pubp,tmp) + { + if ( memcmp(rmd160,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) + break; + pubp = 0; + } + portable_mutex_unlock(&LP_pubkeymutex); + return(pubp); +} + +struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) +{ + uint8_t rmd160[20],addrtype; struct LP_address *ap; struct LP_pubkeyinfo *pubp; + HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap); + if ( bits256_nonz(ap->pubkey) == 0 ) + { + bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,coinaddr); + if ( (pubp= LP_pubkey_rmd160find(rmd160)) != 0 ) + { + ap->pubkey = pubp->pubkey; + memcpy(ap->pubsecp,pubp->pubsecp,sizeof(ap->pubsecp)); + } + } + return(ap); +} + +struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) +{ + uint8_t rmd160[20],addrtype; struct LP_address *ap; struct LP_pubkeyinfo *pubp; + ap = calloc(1,sizeof(*ap)); + safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr)); + bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,coinaddr); + if ( (pubp= LP_pubkey_rmd160find(rmd160)) != 0 ) + { + ap->pubkey = pubp->pubkey; + memcpy(ap->pubsecp,pubp->pubsecp,sizeof(ap->pubsecp)); + } + //printf("LP_ADDRESS %s ADD.(%s)\n",coin->symbol,coinaddr); + HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); + return(ap); +} + struct LP_pubkeyinfo *LP_pubkeyfind(bits256 pubkey) { struct LP_pubkeyinfo *pubp=0; diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index b70c7342a..073832675 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1608,6 +1608,26 @@ int32_t LP_utxopurge(int32_t allutxos) portable_mutex_unlock(&LP_utxomutex); return(n); } +struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson) +{ + struct LP_utxoinfo *utxo; + if ( jobj(argjson,"iambob") == 0 || iambob != jint(argjson,"iambob") ) + { + printf("LP_utxoaddjson: iambob.%d != arg.%d obj.%p (%s)\n",iambob,jint(argjson,"iambob"),jobj(argjson,"iambob"),jprint(argjson,0)); + return(0); + } + portable_mutex_lock(&LP_UTXOmutex); + utxo = LP_utxoadd(iambob,pubsock,jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),j64bits(argjson,"value"),jbits256(argjson,"txid2"),jint(argjson,"vout2"),j64bits(argjson,"value2"),jstr(argjson,"script"),jstr(argjson,"address"),jbits256(argjson,"pubkey"),jstr(argjson,"gui"),juint(argjson,"session")); + if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) + { + utxo->T.lasttime = (uint32_t)time(NULL); + printf("set lasttime!\n"); + } + portable_mutex_unlock(&LP_UTXOmutex); + return(utxo); +} + + int32_t LP_utxosparse(char *destipaddr,uint16_t destport,char *retstr,uint32_t now) { struct LP_peerinfo *peer; uint32_t argipbits; char *argipaddr; uint16_t argport,pushport,subport; cJSON *array,*item; int32_t i,n=0; bits256 txid; struct LP_utxoinfo *utxo; diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 90e565c6d..6300e0dbf 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -123,7 +123,8 @@ void basilisk_swap_finished(struct basilisk_swap *swap) if ( swap->utxo != 0 && swap->sentflag == 0 ) { LP_availableset(swap->utxo); - LP_butxo_swapfields_set(swap->utxo); + swap->utxo = 0; + //LP_butxo_swapfields_set(swap->utxo); } swap->I.finished = (uint32_t)time(NULL); // save to permanent storage diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a38aef168..6cd607f4b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -69,23 +69,6 @@ int32_t LP_txdestaddr(char *destaddr,bits256 txid,int32_t vout,cJSON *txobj) return(retval); } -struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) -{ - struct LP_address *ap; - HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap); - return(ap); -} - -struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr) -{ - struct LP_address *ap; - ap = calloc(1,sizeof(*ap)); - safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr)); - //printf("LP_ADDRESS %s ADD.(%s)\n",coin->symbol,coinaddr); - HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap); - return(ap); -} - struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) { struct LP_address *ap = 0; @@ -138,14 +121,29 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) return(n); } -int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap,int32_t avoidflag) +struct LP_utxoinfo *LP_unallocated(bits256 txid,int32_t vout) +{ + struct LP_utxoinfo *utxo; + if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + return(0); + if ( (utxo= _LP_utxo2find(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + return(0); + if ( (utxo= _LP_utxofind(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + return(0); + if ( (utxo= _LP_utxo2find(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + return(0); + return(utxo); +} + +int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap) { struct LP_address_utxo *up,*tmp; int32_t n = 0; + portable_mutex_lock(&LP_utxomutex); DL_FOREACH_SAFE(ap->utxos,up,tmp) { if ( up->spendheight <= 0 ) { - if ( avoidflag == 0 || LP_butxo_findeither(up->U.txid,up->U.vout) == 0 ) + if ( LP_unallocated(up->U.txid,up->U.vout) != 0 ) { utxos[n++] = up; if ( n >= max ) @@ -153,6 +151,7 @@ int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct L } } } + portable_mutex_unlock(&LP_utxomutex); return(n); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 990c5f4d1..94487dc3b 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -206,7 +206,7 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo) jaddbits256(item,"pubkey",utxo->pubkey); //jaddnum(item,"profit",utxo->S.profitmargin); jaddstr(item,"base",utxo->coin); - jaddstr(item,"script",utxo->spendscript); + //jaddstr(item,"script",utxo->spendscript); return(item); } @@ -278,12 +278,12 @@ char *LP_spentcheck(cJSON *argjson) return(clonestr("{\"error\":\"cant find txid to check spent status\"}")); } -struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *spendscript,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) +struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) { uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; - if ( symbol == 0 || symbol[0] == 0 || spendscript == 0 || spendscript[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 || sessionid == 0 ) + if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 || sessionid == 0 ) { - printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,spendscript == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); + printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } if ( iambob != 0 ) @@ -343,7 +343,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit printf("duplicate %.8f %.8f %.8f vs utxo.(%.8f %.8f %.8f)\n",dstr(value),dstr(value2),dstr(tmpsatoshis),dstr(utxo->payment.value),dstr(utxo->deposit.value),dstr(utxo->S.satoshis)); } u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee; - if ( bits256_cmp(txid,utxo->payment.txid) != 0 || bits256_cmp(txid2,u.txid) != 0 || vout != utxo->payment.vout || value != utxo->payment.value || tmpsatoshis != utxo->S.satoshis || vout2 != u.vout || value2 != u.value || strcmp(symbol,utxo->coin) != 0 || strcmp(spendscript,utxo->spendscript) != 0 || strcmp(coinaddr,utxo->coinaddr) != 0 || bits256_cmp(pubkey,utxo->pubkey) != 0 ) + if ( bits256_cmp(txid,utxo->payment.txid) != 0 || bits256_cmp(txid2,u.txid) != 0 || vout != utxo->payment.vout || value != utxo->payment.value || tmpsatoshis != utxo->S.satoshis || vout2 != u.vout || value2 != u.value || strcmp(symbol,utxo->coin) != 0 || strcmp(coinaddr,utxo->coinaddr) != 0 || bits256_cmp(pubkey,utxo->pubkey) != 0 ) { utxo->T.errors++; char str[65],str2[65],str3[65],str4[65],str5[65],str6[65]; @@ -353,7 +353,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit // utxo->T.spentflag = (uint32_t)time(NULL); printf("original utxo pair not valid\n"); if ( dispflag != 0 ) - printf("error on subsequent utxo iambob.%d %.8f %.8f add.(%s %s) when.(%s %s) %d %d %d %d %d %d %d %d %d %d %d pubkeys.(%s vs %s)\n",iambob,dstr(val),dstr(val2),bits256_str(str,txid),bits256_str(str2,txid2),bits256_str(str3,utxo->payment.txid),bits256_str(str4,utxo->deposit.txid),bits256_cmp(txid,utxo->payment.txid) != 0,bits256_cmp(txid2,u.txid) != 0,vout != utxo->payment.vout,tmpsatoshis != utxo->S.satoshis,vout2 != u.vout,value2 != u.value,strcmp(symbol,utxo->coin) != 0,strcmp(spendscript,utxo->spendscript) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,bits256_cmp(pubkey,utxo->pubkey) != 0,value != utxo->payment.value,bits256_str(str5,pubkey),bits256_str(str6,utxo->pubkey)); + printf("error on subsequent utxo iambob.%d %.8f %.8f add.(%s %s) when.(%s %s) %d %d %d %d %d %d %d %d %d %d pubkeys.(%s vs %s)\n",iambob,dstr(val),dstr(val2),bits256_str(str,txid),bits256_str(str2,txid2),bits256_str(str3,utxo->payment.txid),bits256_str(str4,utxo->deposit.txid),bits256_cmp(txid,utxo->payment.txid) != 0,bits256_cmp(txid2,u.txid) != 0,vout != utxo->payment.vout,tmpsatoshis != utxo->S.satoshis,vout2 != u.vout,value2 != u.value,strcmp(symbol,utxo->coin) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,bits256_cmp(pubkey,utxo->pubkey) != 0,value != utxo->payment.value,bits256_str(str5,pubkey),bits256_str(str6,utxo->pubkey)); utxo = 0; } } @@ -373,7 +373,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit safecopy(utxo->gui,gui,sizeof(utxo->gui)); safecopy(utxo->coin,symbol,sizeof(utxo->coin)); safecopy(utxo->coinaddr,coinaddr,sizeof(utxo->coinaddr)); - safecopy(utxo->spendscript,spendscript,sizeof(utxo->spendscript)); + //safecopy(utxo->spendscript,spendscript,sizeof(utxo->spendscript)); utxo->payment.txid = txid; utxo->payment.vout = vout; utxo->payment.value = value; @@ -418,25 +418,6 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit return(utxo); } -struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson) -{ - struct LP_utxoinfo *utxo; - if ( jobj(argjson,"iambob") == 0 || iambob != jint(argjson,"iambob") ) - { - printf("LP_utxoaddjson: iambob.%d != arg.%d obj.%p (%s)\n",iambob,jint(argjson,"iambob"),jobj(argjson,"iambob"),jprint(argjson,0)); - return(0); - } - portable_mutex_lock(&LP_UTXOmutex); - utxo = LP_utxoadd(iambob,pubsock,jstr(argjson,"coin"),jbits256(argjson,"txid"),jint(argjson,"vout"),j64bits(argjson,"value"),jbits256(argjson,"txid2"),jint(argjson,"vout2"),j64bits(argjson,"value2"),jstr(argjson,"script"),jstr(argjson,"address"),jbits256(argjson,"pubkey"),jstr(argjson,"gui"),juint(argjson,"session")); - if ( LP_ismine(utxo) > 0 && utxo->T.lasttime == 0 ) - { - utxo->T.lasttime = (uint32_t)time(NULL); - printf("set lasttime!\n"); - } - portable_mutex_unlock(&LP_UTXOmutex); - return(utxo); -} - cJSON *LP_inventory(char *symbol) { struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; @@ -610,14 +591,14 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri portable_mutex_lock(&LP_UTXOmutex); if ( iambob != 0 ) { - if ( (utxo= LP_utxoadd(1,mypubsock,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,script,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) + if ( (utxo= LP_utxoadd(1,coin->symbol,txid,vout,value,deposittxid,depositvout,depositval,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) { } } else { //printf("call utxoadd\n"); - if ( (utxo= LP_utxoadd(0,mypubsock,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,script,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) + if ( (utxo= LP_utxoadd(0,coin->symbol,deposittxid,depositvout,depositval,txid,vout,value,coin->smartaddr,mypub,LP_gui,G.LP_sessionid)) != 0 ) { } } @@ -742,9 +723,10 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan } else free_json(retjson); } } - G.LP_mypub25519 = *pubkeyp = curve25519(privkey,curve25519_basepoint9()); - G.LP_mypriv25519 = privkey; - //printf("privkey.(%s) -> LP_mypub25519.(%s)\n",bits256_str(str,privkey),bits256_str(str2,LP_mypub25519)); + vcalc_sha256(0,checkkey.bytes,privkey.bytes,sizeof(privkey)); + checkkey.bytes[0] &= 248, checkkey.bytes[31] &= 127, checkkey.bytes[31] |= 64; + G.LP_mypub25519 = *pubkeyp = curve25519(checkkey,curve25519_basepoint9()); + G.LP_mypriv25519 = checkkey; return(privkey); } @@ -772,7 +754,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) } } -int32_t LP_passphrase_init(char *passphrase) +int32_t LP_passphrase_init(char *passphrase,char *gui) { static void *ctx; struct LP_utxoinfo *utxo,*tmp; if ( ctx == 0 ) @@ -780,6 +762,8 @@ int32_t LP_passphrase_init(char *passphrase) if ( G.LP_pendingswaps != 0 ) return(-1); G.initializing = 1; + if ( gui == 0 ) + gui = "cli"; while ( G.waiting == 0 ) { printf("waiting for G.waiting\n"); @@ -805,6 +789,7 @@ int32_t LP_passphrase_init(char *passphrase) LP_privkey_updates(ctx,LP_mypubsock,passphrase); init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); G.LP_sessionid = (uint32_t)time(NULL); + safecopy(G.gui,gui,sizeof(G.gui)); return(0); } From b821e216c30006e932a3f3d6c4c8dd57d0fb1607 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 13:48:07 +0300 Subject: [PATCH 424/520] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index bf347411d..0a051e362 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -144,7 +144,7 @@ struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr) { uint8_t rmd160[20],addrtype; struct LP_address *ap; struct LP_pubkeyinfo *pubp; HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap); - if ( bits256_nonz(ap->pubkey) == 0 ) + if ( ap != 0 && bits256_nonz(ap->pubkey) == 0 ) { bitcoin_addr2rmd160(coin->taddr,&addrtype,rmd160,coinaddr); if ( (pubp= LP_pubkey_rmd160find(rmd160)) != 0 ) From 781a8fe03472a43c3d9dbb2b84d1eae09d6f47b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 13:57:25 +0300 Subject: [PATCH 425/520] Test --- iguana/exchanges/LP_utxos.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 94487dc3b..1698afa57 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -420,11 +420,13 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t cJSON *LP_inventory(char *symbol) { - struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; + struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; struct iguana_info *coin; array = cJSON_CreateArray(); if ( LP_mypeer != 0 ) myipaddr = LP_mypeer->ipaddr; else myipaddr = "127.0.0.1"; + if ( (coin= LP_coinfind(symbol)) != 0 ) + LP_listunspent_both(symbol,coin->smartaddr); HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) { char str[65]; From 714bff33e275ab375b03088defe443c6bac3a561 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 14:03:30 +0300 Subject: [PATCH 426/520] Test --- iguana/exchanges/LP_utxo.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6cd607f4b..76aa1fb30 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -373,13 +373,13 @@ void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo=0; uint8_t key[sizeof(txid) + sizeof(vout)]; - if ( iambob != 0 ) + /*if ( iambob != 0 ) { static uint32_t counter; if ( counter++ < 3 ) printf("_LP_utxofind deprecated iambob\n"); return(0); - } + }*/ LP_utxosetkey(key,txid,vout); HASH_FIND(hh,G.LP_utxoinfos,key,sizeof(key),utxo); return(utxo); @@ -388,11 +388,11 @@ struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) { struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)]; - if ( iambob != 0 ) + /*if ( iambob != 0 ) { printf("_LP_utxo2find deprecated iambob\n"); return(0); - } + }*/ LP_utxosetkey(key2,txid2,vout2); HASH_FIND(hh2,G.LP_utxoinfos2,key2,sizeof(key2),utxo); return(utxo); @@ -401,11 +401,11 @@ struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo=0; - if ( iambob != 0 ) + /*if ( iambob != 0 ) { printf("LP_utxofind deprecated iambob\n"); return(0); - } + }*/ portable_mutex_lock(&LP_utxomutex); utxo = _LP_utxofind(iambob,txid,vout); portable_mutex_unlock(&LP_utxomutex); @@ -415,11 +415,11 @@ struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) struct LP_utxoinfo *LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) { struct LP_utxoinfo *utxo=0; - if ( iambob != 0 ) + /*if ( iambob != 0 ) { printf("LP_utxo2find deprecated iambob\n"); return(0); - } + }*/ portable_mutex_lock(&LP_utxomutex); utxo = _LP_utxo2find(iambob,txid2,vout2); portable_mutex_unlock(&LP_utxomutex); From 5b666b01a972eb5317e042d063786beb61ba916e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 14:08:04 +0300 Subject: [PATCH 427/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 02b67ddf9..b7609e229 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -996,11 +996,12 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i break; if ( j != numavoids ) continue; - //printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); + printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); n = LP_listunspent_both(base,coinaddr); + printf("unspent.(%s) n.%d\n",coinaddr,n); if ( n > 1 ) { basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); From c66ee29f76090e19a6ddc0d154aaf568bad7d367 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 14:12:01 +0300 Subject: [PATCH 428/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b7609e229..07e917fbf 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -489,7 +489,7 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_address_utxo **utxos,int32_t m if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) { targetval = LP_basesatoshis(volume,price,txfee,desttxfee); - if ( 0 ) + if ( 1 ) { int32_t i; for (i=0; i Date: Sat, 30 Sep 2017 14:15:29 +0300 Subject: [PATCH 429/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 07e917fbf..206bb80c9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -514,8 +514,8 @@ struct LP_utxoinfo *LP_address_utxopair(struct LP_address_utxo **utxos,int32_t m } } else printf("cant find targetval2 %.8f\n",dstr(targetval2)); } - } - } + } else printf("no utxos pass LP_address_utxo_ptrs filter\n"); + } else printf("couldnt find %s %s\n",coin->symbol,coinaddr); return(0); } From 7ffdef7d26ae5f825c32672555b5fdbb9b070b0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 14:20:33 +0300 Subject: [PATCH 430/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 ++++---- iguana/exchanges/LP_utxo.c | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 206bb80c9..97ac19e96 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -481,12 +481,12 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d else return(0); } -struct LP_utxoinfo *LP_address_utxopair(struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,uint64_t desttxfee) +struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,uint64_t desttxfee) { struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; struct LP_utxoinfo *utxo = 0; if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) { - if ( (m= LP_address_utxo_ptrs(utxos,max,ap)) > 1 ) + if ( (m= LP_address_utxo_ptrs(iambob,utxos,max,ap)) > 1 ) { targetval = LP_basesatoshis(volume,price,txfee,desttxfee); if ( 1 ) @@ -828,7 +828,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, if ( LP_unallocated(butxo->payment.txid,butxo->payment.vout) != 0 || LP_unallocated(butxo->deposit.txid,butxo->deposit.vout) != 0 || (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { LP_listunspent_both(Q.srccoin,Q.coinaddr); - if ( (butxo= LP_address_utxopair(utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) + if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { Q.txid = butxo->payment.txid; Q.vout = butxo->payment.vout; @@ -1005,7 +1005,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i if ( n > 1 ) { basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); - if ( basesatoshis != 0 && (bestutxo= LP_address_utxopair(utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,desttxfee)) != 0 ) + if ( basesatoshis != 0 && (bestutxo= LP_address_utxopair(0,utxos,max,basecoin,coinaddr,txfee,dstr(basesatoshis)*price,price,desttxfee)) != 0 ) { bestutxo->pubkey = pubp->pubkey; safecopy(bestutxo->gui,gui,sizeof(bestutxo->gui)); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 76aa1fb30..4eaaece84 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -121,21 +121,23 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) return(n); } -struct LP_utxoinfo *LP_unallocated(bits256 txid,int32_t vout) +struct LP_utxoinfo *LP_unallocated(int32_t iambob,bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo; - if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) - return(0); - if ( (utxo= _LP_utxo2find(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) - return(0); - if ( (utxo= _LP_utxofind(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + if ( (utxo= _LP_utxofind(iambob,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); return(0); - if ( (utxo= _LP_utxo2find(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + } + if ( (utxo= _LP_utxo2find(iambob,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); return(0); + } return(utxo); } -int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap) +int32_t LP_address_utxo_ptrs(int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap) { struct LP_address_utxo *up,*tmp; int32_t n = 0; portable_mutex_lock(&LP_utxomutex); @@ -143,7 +145,7 @@ int32_t LP_address_utxo_ptrs(struct LP_address_utxo **utxos,int32_t max,struct L { if ( up->spendheight <= 0 ) { - if ( LP_unallocated(up->U.txid,up->U.vout) != 0 ) + if ( LP_unallocated(iambob,up->U.txid,up->U.vout) != 0 ) { utxos[n++] = up; if ( n >= max ) From 32704381dd8ec17461a15af71ec206183b7f26dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 14:42:49 +0300 Subject: [PATCH 431/520] Test --- iguana/exchanges/LP_utxo.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 4eaaece84..32e7d5df1 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -121,20 +121,30 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) return(n); } -struct LP_utxoinfo *LP_unallocated(int32_t iambob,bits256 txid,int32_t vout) +struct LP_utxoinfo *LP_unallocated(bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo; - if ( (utxo= _LP_utxofind(iambob,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) { char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); - return(0); + return(utxo); } - if ( (utxo= _LP_utxo2find(iambob,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + if ( (utxo= _LP_utxo2find(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) { char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); - return(0); + return(utxo); } - return(utxo); + if ( (utxo= _LP_utxofind(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); + return(utxo); + } + if ( (utxo= _LP_utxo2find(1,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) + { + char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); + return(utxo); + } + return(0); } int32_t LP_address_utxo_ptrs(int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap) @@ -145,7 +155,7 @@ int32_t LP_address_utxo_ptrs(int32_t iambob,struct LP_address_utxo **utxos,int32 { if ( up->spendheight <= 0 ) { - if ( LP_unallocated(iambob,up->U.txid,up->U.vout) != 0 ) + if ( LP_unallocated(up->U.txid,up->U.vout) == 0 ) { utxos[n++] = up; if ( n >= max ) From a59682132b1f38ceabf24a5bbde0da3ec5179a28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 15:02:31 +0300 Subject: [PATCH 432/520] Test --- iguana/exchanges/LP_ordermatch.c | 16 +++++++++------- iguana/exchanges/LP_utxo.c | 4 ++-- iguana/exchanges/LP_utxos.c | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 97ac19e96..20da8791e 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -481,21 +481,22 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d else return(0); } -struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double volume,double price,uint64_t desttxfee) +struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct iguana_info *coin,char *coinaddr,uint64_t txfee,double relvolume,double price,uint64_t desttxfee) { struct LP_address *ap; uint64_t targetval,targetval2; int32_t m,mini; struct LP_address_utxo *up,*up2; struct LP_utxoinfo *utxo = 0; if ( coin != 0 && (ap= LP_addressfind(coin,coinaddr)) != 0 ) { if ( (m= LP_address_utxo_ptrs(iambob,utxos,max,ap)) > 1 ) { - targetval = LP_basesatoshis(volume,price,txfee,desttxfee); + targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee); if ( 1 ) { int32_t i; for (i=0; iU.value)); - printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),volume,price,dstr(txfee)); + printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),relvolume,price,dstr(txfee)); } + mini = -1; if ( targetval != 0 && (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL-1 ) { up = utxos[mini]; @@ -513,7 +514,8 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** } } } else printf("cant find targetval2 %.8f\n",dstr(targetval2)); - } + } else if ( targetval != 0 && mini >= 0 ) + printf("targetval %.8f mini.%d ratio %.8f\n",dstr(targetval),mini,(double)utxos[mini]->U.value/targetval); } else printf("no utxos pass LP_address_utxo_ptrs filter\n"); } else printf("couldnt find %s %s\n",coin->symbol,coinaddr); return(0); @@ -825,7 +827,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { - if ( LP_unallocated(butxo->payment.txid,butxo->payment.vout) != 0 || LP_unallocated(butxo->deposit.txid,butxo->deposit.vout) != 0 || (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) + if ( LP_allocated(butxo->payment.txid,butxo->payment.vout) != 0 || LP_allocated(butxo->deposit.txid,butxo->deposit.vout) != 0 || (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { LP_listunspent_both(Q.srccoin,Q.coinaddr); if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) @@ -996,12 +998,12 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i break; if ( j != numavoids ) continue; - printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); + //printf("%s pubcmp %d\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519)); if ( bits256_cmp(pubkey,G.LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 ) { bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); n = LP_listunspent_both(base,coinaddr); - printf("unspent.(%s) n.%d\n",coinaddr,n); + //printf("unspent.(%s) n.%d\n",coinaddr,n); if ( n > 1 ) { basesatoshis = LP_basesatoshis(dstr(autxo->S.satoshis),price,txfee,desttxfee); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 32e7d5df1..ed740ffad 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -121,7 +121,7 @@ int32_t LP_address_minmax(uint64_t *minp,uint64_t *maxp,struct LP_address *ap) return(n); } -struct LP_utxoinfo *LP_unallocated(bits256 txid,int32_t vout) +struct LP_utxoinfo *LP_allocated(bits256 txid,int32_t vout) { struct LP_utxoinfo *utxo; if ( (utxo= _LP_utxofind(0,txid,vout)) != 0 && LP_isavailable(utxo) == 0 ) @@ -155,7 +155,7 @@ int32_t LP_address_utxo_ptrs(int32_t iambob,struct LP_address_utxo **utxos,int32 { if ( up->spendheight <= 0 ) { - if ( LP_unallocated(up->U.txid,up->U.vout) == 0 ) + if ( LP_allocated(up->U.txid,up->U.vout) == 0 ) { utxos[n++] = up; if ( n >= max ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 1698afa57..034f72e38 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -332,6 +332,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t val = value; val2 = value2; } + dispflag = 1; if ( dispflag != 0 ) printf("%.8f %.8f %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",dstr(val),dstr(val2),coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); dispflag = 1; From 59ef13c7fc629996791dbb2a2cd4bbf1a643b425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 15:11:27 +0300 Subject: [PATCH 433/520] Test --- iguana/exchanges/LP_utxos.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 034f72e38..fa0aebdc4 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -283,6 +283,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 || sessionid == 0 ) { + char str[65],str2[65]; printf("%.8f %.8f %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",dstr(val),dstr(val2),coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } From 82d2401b3fa9bdddfb60bf2945a9f4bd12765097 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 15:11:46 +0300 Subject: [PATCH 434/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index fa0aebdc4..e1496b174 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -283,7 +283,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 || sessionid == 0 ) { - char str[65],str2[65]; printf("%.8f %.8f %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",dstr(val),dstr(val2),coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); + char str[65],str2[65]; printf("%s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } From 4a496c751faed353d609f15142e629adf80efe54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 15:15:31 +0300 Subject: [PATCH 435/520] Test --- iguana/exchanges/LP_utxos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e1496b174..255d595c3 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -281,10 +281,10 @@ char *LP_spentcheck(cJSON *argjson) struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t vout,int64_t value,bits256 txid2,int32_t vout2,int64_t value2,char *coinaddr,bits256 pubkey,char *gui,uint32_t sessionid) { uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; - if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 || sessionid == 0 ) + if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 )//|| sessionid == 0 ) { char str[65],str2[65]; printf("%s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); - printf("session.%u malformed addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); + printf("session.%u addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } if ( iambob != 0 ) From cb94dc218cacfc195fef659556e6e64b2749a345 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 15:17:25 +0300 Subject: [PATCH 436/520] Test --- iguana/exchanges/LP_utxos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 255d595c3..fbd5defa4 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -287,11 +287,11 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("session.%u addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } - if ( iambob != 0 ) + /*if ( iambob != 0 ) { printf("deprecated bob utxos\n"); return(0); - } + }*/ if ( (coin= LP_coinfind(symbol)) == 0 || (IAMLP == 0 && coin->inactive != 0) ) { printf("LP_utxoadd reject inactive %s\n",symbol); From c45761becbd88f5296c401a29dfab05bc5d324f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 19:29:28 +0300 Subject: [PATCH 437/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 20da8791e..30e2fb408 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -843,7 +843,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { - char str[65]; printf("couldnt find bob utxos for autxo %s/v%d %.8f\n",bits256_str(str,autxo->payment.txid),autxo->payment.vout,dstr(autxo->S.satoshis)); + char str[65],str2[65]; printf("couldnt find bob utxos for autxo %s/v%d %s/v%d %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(autxo->S.satoshis)); return(1); } printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); From 2403fc95813f2f13410cf6f0a3d2c2ab399e5cd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 19:44:15 +0300 Subject: [PATCH 438/520] Test --- iguana/exchanges/LP_ordermatch.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 30e2fb408..35cc517c3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -509,7 +509,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** if ( (utxo= LP_utxoadd(1,coin->symbol,up->U.txid,up->U.vout,up->U.value,up2->U.txid,up2->U.vout,up2->U.value,coinaddr,ap->pubkey,G.gui,0)) != 0 ) { utxo->S.satoshis = targetval; - printf("targetval %.8f, found val %.8f | targetval2 %.8f val2 %.8f\n",dstr(targetval),dstr(up->U.value),dstr(targetval2),dstr(up2->U.value)); + char str[65],str2[65]; printf("targetval %.8f, found val %.8f %s | targetval2 %.8f val2 %.8f %s\n",dstr(targetval),dstr(up->U.value),bits256_str(str,up->U.txid),dstr(targetval2),dstr(up2->U.value),bits256_str(str2,up2->U.txid)); return(utxo); } } @@ -836,17 +836,23 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, Q.vout = butxo->payment.vout; Q.txid2 = butxo->deposit.txid; Q.vout2 = butxo->deposit.vout; - } + char str[65],str2[65]; printf("set utxo %s/v%d %s/v%d %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(autxo->S.satoshis)); + } else printf("cant find utxopair\n"); //LP_abutxo_set(0,butxo,&Q); //LP_butxo_swapfields(butxo); - } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); + } + else + { + printf("other path %p %p %.8f\n",LP_allocated(butxo->payment.txid,butxo->payment.vout),LP_allocated(butxo->deposit.txid,butxo->deposit.vout), LP_quote_validate(autxo,butxo,&Q,1)); + butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); + } } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); + printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { char str[65],str2[65]; printf("couldnt find bob utxos for autxo %s/v%d %s/v%d %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(autxo->S.satoshis)); return(1); } - printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { printf("quote validate error %.0f\n",qprice); From 6c69eeb09fabc4660879d013404965371d957b95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 20:00:38 +0300 Subject: [PATCH 439/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxos.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 35cc517c3..3054f8940 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -836,7 +836,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, Q.vout = butxo->payment.vout; Q.txid2 = butxo->deposit.txid; Q.vout2 = butxo->deposit.vout; - char str[65],str2[65]; printf("set utxo %s/v%d %s/v%d %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(autxo->S.satoshis)); + char str[65],str2[65]; printf("set utxo %s/v%d %s/v%d %.8f %.8f -> bsat %.8f asat %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(butxo->payment.value),dstr(butxo->deposit.value),dstr(butxo->S.satoshis),dstr(autxo->S.satoshis)); } else printf("cant find utxopair\n"); //LP_abutxo_set(0,butxo,&Q); //LP_butxo_swapfields(butxo); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index fbd5defa4..25cc2ea0d 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -302,7 +302,11 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t { if ( value2 > 2*txfee ) tmpsatoshis = (((value2 - 2*txfee) / 9) << 3); - else return(0); + else + { + printf("value2 %.8f <= 2 * %.8f\n",dstr(value2),dstr(txfee)); + return(0); + } } else tmpsatoshis = (value - txfee); char str[65],str2[65],dispflag = 0;//(iambob == 0); if ( iambob == 0 && bits256_cmp(pubkey,G.LP_mypub25519) != 0 ) @@ -339,7 +343,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t dispflag = 1; if ( (utxo= LP_utxofinds(iambob,txid,vout,txid2,vout2)) != 0 ) { - if ( 0 && LP_ismine(utxo) == 0 ) + //if ( 0 && LP_ismine(utxo) == 0 ) { char str2[65],str3[65]; printf("iambob.%d %s %s utxoadd.(%.8f %.8f) %s %s\n",iambob,bits256_str(str3,pubkey),symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); printf("duplicate %.8f %.8f %.8f vs utxo.(%.8f %.8f %.8f)\n",dstr(value),dstr(value2),dstr(tmpsatoshis),dstr(utxo->payment.value),dstr(utxo->deposit.value),dstr(utxo->S.satoshis)); @@ -366,6 +370,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t //else if ( profitmargin > SMALLVAL ) // utxo->S.profitmargin = profitmargin; utxo->T.lasttime = (uint32_t)time(NULL); + printf("return existing utxo\n"); return(utxo); } } From 61f674400dfb33d3e328ec72d629eb9a34154a8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 20:01:12 +0300 Subject: [PATCH 440/520] Test --- iguana/exchanges/LP_utxos.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 25cc2ea0d..d61df3473 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -318,7 +318,9 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t { if ( LP_iseligible(&val,&val2,iambob,symbol,txid,vout,tmpsatoshis,txid2,vout2) <= 0 ) { - printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f:%.8f, value2 %.8f:%.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(val),dstr(value2),dstr(val2),dstr(tmpsatoshis)); + static uint32_t counter; + if ( counter++ < 3 ) + printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f:%.8f, value2 %.8f:%.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(val),dstr(value2),dstr(val2),dstr(tmpsatoshis)); return(0); } if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,0)) <= 0 ) From 0e7283022e125fe26895c22fa356d8fb25e10fb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 20:14:51 +0300 Subject: [PATCH 441/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 +++++--- iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3054f8940..5a45ee9e5 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -509,7 +509,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** if ( (utxo= LP_utxoadd(1,coin->symbol,up->U.txid,up->U.vout,up->U.value,up2->U.txid,up2->U.vout,up2->U.value,coinaddr,ap->pubkey,G.gui,0)) != 0 ) { utxo->S.satoshis = targetval; - char str[65],str2[65]; printf("targetval %.8f, found val %.8f %s | targetval2 %.8f val2 %.8f %s\n",dstr(targetval),dstr(up->U.value),bits256_str(str,up->U.txid),dstr(targetval2),dstr(up2->U.value),bits256_str(str2,up2->U.txid)); + char str[65],str2[65]; printf("butxo.%p targetval %.8f, found val %.8f %s | targetval2 %.8f val2 %.8f %s\n",utxo,dstr(targetval),dstr(up->U.value),bits256_str(str,up->U.txid),dstr(targetval2),dstr(up2->U.value),bits256_str(str2,up2->U.txid)); return(utxo); } } @@ -827,8 +827,10 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, //LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { + char str[65],str2[65]; if ( LP_allocated(butxo->payment.txid,butxo->payment.vout) != 0 || LP_allocated(butxo->deposit.txid,butxo->deposit.vout) != 0 || (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) { + printf("butxo.%p replace path %p %s, %p %s, %.8f\n",butxo,LP_allocated(butxo->payment.txid,butxo->payment.vout),bits256_str(str,butxo->payment.txid),LP_allocated(butxo->deposit.txid,butxo->deposit.vout),bits256_str(str2,butxo->deposit.txid),LP_quote_validate(autxo,butxo,&Q,1)); LP_listunspent_both(Q.srccoin,Q.coinaddr); if ( (butxo= LP_address_utxopair(1,utxos,max,LP_coinfind(Q.srccoin),Q.coinaddr,Q.txfee,dstr(Q.destsatoshis),price,Q.desttxfee)) != 0 ) { @@ -836,7 +838,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, Q.vout = butxo->payment.vout; Q.txid2 = butxo->deposit.txid; Q.vout2 = butxo->deposit.vout; - char str[65],str2[65]; printf("set utxo %s/v%d %s/v%d %.8f %.8f -> bsat %.8f asat %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(butxo->payment.value),dstr(butxo->deposit.value),dstr(butxo->S.satoshis),dstr(autxo->S.satoshis)); + printf("set butxo.%p %s/v%d %s/v%d %.8f %.8f -> bsat %.8f asat %.8f\n",butxo,bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(butxo->payment.value),dstr(butxo->deposit.value),dstr(butxo->S.satoshis),dstr(autxo->S.satoshis)); } else printf("cant find utxopair\n"); //LP_abutxo_set(0,butxo,&Q); //LP_butxo_swapfields(butxo); @@ -847,7 +849,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); } } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); - printf("TRADECOMMAND.(%s)\n",jprint(argjson,0)); + printf("butxo.%p TRADECOMMAND.(%s)\n",butxo,jprint(argjson,0)); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { char str[65],str2[65]; printf("couldnt find bob utxos for autxo %s/v%d %s/v%d %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(autxo->S.satoshis)); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index d61df3473..349f3ad22 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -345,7 +345,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t dispflag = 1; if ( (utxo= LP_utxofinds(iambob,txid,vout,txid2,vout2)) != 0 ) { - //if ( 0 && LP_ismine(utxo) == 0 ) + if ( 0 && LP_ismine(utxo) == 0 ) { char str2[65],str3[65]; printf("iambob.%d %s %s utxoadd.(%.8f %.8f) %s %s\n",iambob,bits256_str(str3,pubkey),symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); printf("duplicate %.8f %.8f %.8f vs utxo.(%.8f %.8f %.8f)\n",dstr(value),dstr(value2),dstr(tmpsatoshis),dstr(utxo->payment.value),dstr(utxo->deposit.value),dstr(utxo->S.satoshis)); From 8dce8b57652f4d60d6de63642d5d2e662bcd146b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 20:33:22 +0300 Subject: [PATCH 442/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- iguana/exchanges/LP_rpc.c | 4 ++-- iguana/exchanges/LP_utxos.c | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5a45ee9e5..6e902dcd3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -509,7 +509,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** if ( (utxo= LP_utxoadd(1,coin->symbol,up->U.txid,up->U.vout,up->U.value,up2->U.txid,up2->U.vout,up2->U.value,coinaddr,ap->pubkey,G.gui,0)) != 0 ) { utxo->S.satoshis = targetval; - char str[65],str2[65]; printf("butxo.%p targetval %.8f, found val %.8f %s | targetval2 %.8f val2 %.8f %s\n",utxo,dstr(targetval),dstr(up->U.value),bits256_str(str,up->U.txid),dstr(targetval2),dstr(up2->U.value),bits256_str(str2,up2->U.txid)); + char str[65],str2[65]; printf("butxo.%p targetval %.8f, found val %.8f %s | targetval2 %.8f val2 %.8f %s\n",utxo,dstr(targetval),dstr(up->U.value),bits256_str(str,utxo->payment.txid),dstr(targetval2),dstr(up2->U.value),bits256_str(str2,utxo->deposit.txid)); return(utxo); } } @@ -824,6 +824,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, memset(autxo,0,sizeof(*autxo)); memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); + printf("A %p, B %p\n",autxo,butxo); //LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 633633af3..107cca7a0 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -614,9 +614,9 @@ double _LP_getestimatedrate(struct iguana_info *coin) rate = atof(retstr) / 1024.; if ( rate < 0.00000020 ) rate = 0.00000020; - rate *= 1.25; + rate *= 1.1; if ( coin->electrum != 0 ) - rate *= 1.25; + rate *= 1.667; if ( fabs(rate - coin->rate) > SMALLVAL ) printf("t%u estimated rate.(%s) (%s) -> %.8f %.8f\n",coin->ratetime,coin->symbol,retstr,rate,coin->rate); coin->rate = rate; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 349f3ad22..f3f269b5f 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -283,7 +283,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t uint64_t val,val2=0,tmpsatoshis,txfee; int32_t spendvini,numconfirms,selector; bits256 spendtxid; struct iguana_info *coin; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo = 0; if ( symbol == 0 || symbol[0] == 0 || coinaddr == 0 || coinaddr[0] == 0 || bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 || vout < 0 || vout2 < 0 || value <= 0 || value2 <= 0 )//|| sessionid == 0 ) { - char str[65],str2[65]; printf("%s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); + char str[65],str2[65]; printf("REJECT %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); printf("session.%u addutxo %d %d %d %d %d %d %d %d\n",sessionid,symbol == 0,coinaddr == 0,bits256_nonz(txid) == 0,bits256_nonz(txid2) == 0,vout < 0,vout2 < 0,value <= 0,value2 <= 0); return(0); } @@ -372,7 +372,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t //else if ( profitmargin > SMALLVAL ) // utxo->S.profitmargin = profitmargin; utxo->T.lasttime = (uint32_t)time(NULL); - printf("return existing utxo\n"); + printf("return existing utxo %s %s\n",bits256_str(str,utxo->payment.txid),bits256_str(str2,utxo->deposit.txid)); return(utxo); } } @@ -409,7 +409,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - printf(" %s %.8f %.8f addutxo.%d pubkey.%s session.%u\n",symbol,dstr(value),dstr(value2),LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); + printf(" %s %.8f %.8f %p addutxo.%d pubkey.%s session.%u\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); portable_mutex_lock(&LP_utxomutex); HASH_ADD_KEYPTR(hh,G.LP_utxoinfos,utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) From 2a2dcf6210380ac4c1f174ff09332e83da8d0c15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 20:39:23 +0300 Subject: [PATCH 443/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 6e902dcd3..a83a6e230 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -806,7 +806,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { - char *method,*msg; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); + char *method,*msg; uint64_t value,value2; cJSON *retjson; double qprice,price,bid,ask; struct LP_utxoinfo A,B,*autxo,*butxo; struct iguana_info *coin; struct LP_address_utxo *utxos[1000]; struct LP_quoteinfo Q; int32_t retval = -1,max=(int32_t)(sizeof(utxos)/sizeof(*utxos)); if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"request") == 0 ||strcmp(method,"connect") == 0) ) { printf("LP_tradecommand: check received %s\n",method); @@ -850,6 +850,12 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); } } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); + if ( butxo == 0 ) + { + value = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid,Q.vout); + value2 = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid2,Q.vout2); + butxo = LP_utxoadd(1,Q.srccoin,Q.txid,Q.vout,value,Q.txid2,Q.vout2,value2,Q.coinaddr,Q.srchash,LP_gui,0); + } printf("butxo.%p TRADECOMMAND.(%s)\n",butxo,jprint(argjson,0)); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { From 69db057143414660d95af502ba158c6c1a1d7571 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 20:55:50 +0300 Subject: [PATCH 444/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxos.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a83a6e230..2f1700f02 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -859,7 +859,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, printf("butxo.%p TRADECOMMAND.(%s)\n",butxo,jprint(argjson,0)); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { - char str[65],str2[65]; printf("couldnt find bob utxos for autxo %s/v%d %s/v%d %.8f\n",bits256_str(str,butxo->payment.txid),butxo->payment.vout,bits256_str(str2,butxo->deposit.txid),butxo->deposit.vout,dstr(autxo->S.satoshis)); + char str[65],str2[65]; printf("couldnt find bob utxos for autxo %s/v%d %s/v%d %.8f -> %.8f\n",bits256_str(str,Q.txid),Q.vout,bits256_str(str2,Q.txid2),Q.vout2,dstr(Q.satoshis),dstr(Q.destsatoshis)); return(1); } if ( (qprice= LP_quote_validate(autxo,butxo,&Q,1)) <= SMALLVAL ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index f3f269b5f..679cda5e7 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -339,7 +339,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t val = value; val2 = value2; } - dispflag = 1; + dispflag = 0; if ( dispflag != 0 ) printf("%.8f %.8f %s iambob.%d %s utxoadd.(%.8f %.8f) %s %s\n",dstr(val),dstr(val2),coinaddr,iambob,symbol,dstr(value),dstr(value2),bits256_str(str,txid),bits256_str(str2,txid2)); dispflag = 1; @@ -372,7 +372,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t //else if ( profitmargin > SMALLVAL ) // utxo->S.profitmargin = profitmargin; utxo->T.lasttime = (uint32_t)time(NULL); - printf("return existing utxo %s %s\n",bits256_str(str,utxo->payment.txid),bits256_str(str2,utxo->deposit.txid)); + printf("return existing utxo[%d] %s %s\n",iambob,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid)); return(utxo); } } @@ -409,7 +409,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - printf(" %s %.8f %.8f %p addutxo.%d pubkey.%s session.%u\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->pubkey),utxo->T.sessionid); + printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); portable_mutex_lock(&LP_utxomutex); HASH_ADD_KEYPTR(hh,G.LP_utxoinfos,utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) From edde7e3dae41b78d887cc06e8f612e1d492abfd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:03:19 +0300 Subject: [PATCH 445/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_utxo.c | 4 ++-- iguana/exchanges/LP_utxos.c | 35 ++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 945c2a1d8..931906904 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -62,7 +62,7 @@ struct LP_privkey { bits256 privkey; uint8_t rmd160[20]; }; struct LP_globals { - struct LP_utxoinfo *LP_utxoinfos,*LP_utxoinfos2; + struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; bits256 LP_mypub25519,LP_mypriv25519; uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ed740ffad..28cb9cfca 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -393,7 +393,7 @@ struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) return(0); }*/ LP_utxosetkey(key,txid,vout); - HASH_FIND(hh,G.LP_utxoinfos,key,sizeof(key),utxo); + HASH_FIND(hh,G.LP_utxoinfos[iambob],key,sizeof(key),utxo); return(utxo); } @@ -406,7 +406,7 @@ struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) return(0); }*/ LP_utxosetkey(key2,txid2,vout2); - HASH_FIND(hh2,G.LP_utxoinfos2,key2,sizeof(key2),utxo); + HASH_FIND(hh2,G.LP_utxoinfos2[iambob],key2,sizeof(key2),utxo); return(utxo); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 679cda5e7..e9783ca29 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -212,13 +212,13 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo) struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) { - uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; + uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; int32_t iambob = 0; if ( symbol == 0 || destsatoshis == 0 ) { printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis)); return(0); } - HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) + HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) { //char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); if ( strcmp(symbol,utxo->coin) != 0 ) @@ -411,9 +411,9 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t } printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); portable_mutex_lock(&LP_utxomutex); - HASH_ADD_KEYPTR(hh,G.LP_utxoinfos,utxo->key,sizeof(utxo->key),utxo); + HASH_ADD_KEYPTR(hh,G.LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) - HASH_ADD_KEYPTR(hh2,G.LP_utxoinfos2,utxo->key2,sizeof(utxo->key2),utxo); + HASH_ADD_KEYPTR(hh2,G.LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); portable_mutex_unlock(&LP_utxomutex); if ( iambob != 0 ) { @@ -436,7 +436,7 @@ cJSON *LP_inventory(char *symbol) else myipaddr = "127.0.0.1"; if ( (coin= LP_coinfind(symbol)) != 0 ) LP_listunspent_both(symbol,coin->smartaddr); - HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) + HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) { char str[65]; //printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519)); @@ -767,7 +767,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) int32_t LP_passphrase_init(char *passphrase,char *gui) { - static void *ctx; struct LP_utxoinfo *utxo,*tmp; + static void *ctx; int32_t iambob; struct LP_utxoinfo *utxo,*tmp; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( G.LP_pendingswaps != 0 ) @@ -780,20 +780,23 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) printf("waiting for G.waiting\n"); sleep(5); } - if ( G.LP_utxoinfos != 0 ) + for (iambob=0; iambob<2; iambob++) { - HASH_ITER(hh,G.LP_utxoinfos,utxo,tmp) + if ( G.LP_utxoinfos[iambob] != 0 ) { - HASH_DELETE(hh,G.LP_utxoinfos,utxo); - free(utxo); + HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) + { + HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo); + free(utxo); + } } - } - if ( G.LP_utxoinfos2 != 0 ) - { - HASH_ITER(hh,G.LP_utxoinfos2,utxo,tmp) + if ( G.LP_utxoinfos2[iambob] != 0 ) { - HASH_DELETE(hh,G.LP_utxoinfos2,utxo); - free(utxo); + HASH_ITER(hh,G.LP_utxoinfos2[iambob],utxo,tmp) + { + HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo); + free(utxo); + } } } memset(&G,0,sizeof(G)); From 59d2919d3a65c5ccd802fcabb485c151a442d55c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:10:36 +0300 Subject: [PATCH 446/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxos.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 2f1700f02..a9dec4dfd 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -681,7 +681,7 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("swap already pending\n"); return(clonestr("{\"error\":\"swap already pending\"}")); }*/ - if ( (autxo= LP_utxopairfind(1,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) + if ( (autxo= LP_utxopairfind(0,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) { printf("cant find autxo\n"); return(clonestr("{\"error\":\"cant find autxo\"}")); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e9783ca29..83885e4e1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -372,7 +372,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t //else if ( profitmargin > SMALLVAL ) // utxo->S.profitmargin = profitmargin; utxo->T.lasttime = (uint32_t)time(NULL); - printf("return existing utxo[%d] %s %s\n",iambob,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid)); + //printf("return existing utxo[%d] %s %s\n",iambob,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid)); return(utxo); } } @@ -409,7 +409,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("utxoadd selector.%d spent in mempool %s vini.%d",selector,bits256_str(str,spendtxid),spendvini); utxo->T.spentflag = (uint32_t)time(NULL); } - printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); + //printf(" %s %.8f %.8f %p addutxo.%d (%s %s) session.%u iambob.%d <<<<<<<<<<<<<<<\n",symbol,dstr(value),dstr(value2),utxo,LP_ismine(utxo) > 0,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid),utxo->T.sessionid,iambob); portable_mutex_lock(&LP_utxomutex); HASH_ADD_KEYPTR(hh,G.LP_utxoinfos[iambob],utxo->key,sizeof(utxo->key),utxo); if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) From 8c57f70db6b7301c8ffdde7173afbd9a33ccf7a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:13:30 +0300 Subject: [PATCH 447/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a9dec4dfd..48ad01f89 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1067,7 +1067,7 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel return(clonestr("{\"error\":\"invalid parameter\"}")); memset(pubkeys,0,sizeof(pubkeys)); LP_txfees(&txfee,&desttxfee,base,rel); - destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee; + destsatoshis = SATOSHIDEN * relvolume + 3*desttxfee; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); if ( destsatoshis < autxo->S.satoshis ) From fdbe1c744c2f3086cd71c2116c9e65cdfcd11bb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:17:10 +0300 Subject: [PATCH 448/520] Test --- iguana/exchanges/LP_ordermatch.c | 3 ++- iguana/exchanges/LP_prices.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 48ad01f89..c444653a7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1065,9 +1065,10 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel timeout = LP_AUTOTRADE_TIMEOUT; if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); + maxprice *= 1.005; memset(pubkeys,0,sizeof(pubkeys)); LP_txfees(&txfee,&desttxfee,base,rel); - destsatoshis = SATOSHIDEN * relvolume + 3*desttxfee; + destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis)) == 0 ) return(clonestr("{\"error\":\"cant find utxo that is big enough\"}")); if ( destsatoshis < autxo->S.satoshis ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0a051e362..f60b025b4 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -703,7 +703,7 @@ int32_t LP_orderbook_utxoentries(uint32_t now,int32_t polarity,char *base,char * { if ( memcmp(zeroes,pubp->rmd160,sizeof(pubp->rmd160)) == 0 ) { - printf("skip pubp since no rmd160\n"); + //printf("skip pubp since no rmd160\n"); continue; } bitcoin_address(coinaddr,basecoin->taddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); From fdc370461f4c2389aa2ec805a9f2a66e22fd9a4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:30:26 +0300 Subject: [PATCH 449/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_swap.c | 7 ++++--- iguana/exchanges/LP_transaction.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index c444653a7..cfc356d81 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -686,7 +686,7 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("cant find autxo\n"); return(clonestr("{\"error\":\"cant find autxo\"}")); } - LP_abutxo_set(autxo,0,&Q); + //LP_abutxo_set(autxo,0,&Q); if ( (butxo= LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) { value = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid,Q.vout); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 6300e0dbf..50fd58e36 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -412,10 +412,10 @@ int32_t LP_waitfor(int32_t pairsock,struct basilisk_swap *swap,int32_t timeout,i pfd.events = NN_POLLIN; if ( nn_poll(&pfd,1,1) > 0 ) { - //printf("start wait\n"); + printf("start wait\n"); if ( (datalen= nn_recv(pairsock,&data,NN_MSG,0)) >= 0 ) { - //printf("wait for got.%d\n",datalen); + printf("wait for got.%d\n",datalen); retval = (*verify)(swap,data,datalen); nn_freemsg(data); //printf("retval.%d\n",retval); @@ -827,7 +827,8 @@ void LP_aliceloop(void *_swap) swap->N.pair = -1; } basilisk_swap_finished(swap); - free(swap); + printf("finish swap.%p\n",swap); + //free(swap); G.LP_pendingswaps--; } diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 489de1632..1facc6725 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1329,12 +1329,12 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da strcpy(swap->bobdeposit.I.destaddr,swap->bobdeposit.p2shaddr); basilisk_dontforget_update(swap,&swap->bobdeposit); //LP_importaddress(swap->bobcoin.symbol,swap->bobdeposit.I.destaddr); - /*for (i=0; ibobdeposit.I.datalen; i++) + int32_t i; char str[65]; for (i=0; ibobdeposit.I.datalen; i++) printf("%02x",swap->bobdeposit.txbytes[i]); printf(" <- bobdeposit.%d %s\n",swap->bobdeposit.I.datalen,bits256_str(str,swap->bobdeposit.I.signedtxid)); for (i=0; ibobdeposit.I.redeemlen; i++) printf("%02x",swap->bobdeposit.redeemscript[i]); - printf(" <- bobdeposit redeem %d %s suppress.%d\n",i,swap->bobdeposit.I.destaddr,swap->aliceclaim.I.suppress_pubkeys);*/ + printf(" <- bobdeposit redeem %d %s suppress.%d\n",i,swap->bobdeposit.I.destaddr,swap->aliceclaim.I.suppress_pubkeys); memcpy(swap->aliceclaim.redeemscript,swap->bobdeposit.redeemscript,swap->bobdeposit.I.redeemlen); swap->aliceclaim.I.redeemlen = swap->bobdeposit.I.redeemlen; memcpy(swap->aliceclaim.I.pubkey33,swap->persistent_pubkey33,33); From 34d4d38b41c8eb90957f09f9da7bd4f3b2848b99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:38:51 +0300 Subject: [PATCH 450/520] Test --- iguana/exchanges/LP_utxo.c | 6 +++--- iguana/exchanges/LP_utxos.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 28cb9cfca..3224428b0 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -596,16 +596,16 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int numconfirms = jint(txobj,"confirmations"); free_json(txobj); } - else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) + if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) numconfirms = 0; } else { if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) numconfirms = (LP_getheight(coin) - ht + 1); - else if ( mempool != 0 ) + if ( mempool != 0 ) { - if (LP_waitmempool(symbol,coinaddr,txid,vout,30) >= 0 ) + if ( LP_waitmempool(symbol,coinaddr,txid,vout,30) >= 0 ) numconfirms = 0; } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 83885e4e1..f3cc3ad7e 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -323,12 +323,12 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f:%.8f, value2 %.8f:%.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(val),dstr(value2),dstr(val2),dstr(tmpsatoshis)); return(0); } - if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,0)) <= 0 ) + if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,1)) <= 0 ) { printf("LP_utxoadd reject numconfirms.%d %s.%s\n",numconfirms,symbol,bits256_str(str,txid)); return(0); } - if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,vout2,0)) <= 0 ) + if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,vout2,1)) <= 0 ) { printf("LP_utxoadd reject2 numconfirms.%d\n",numconfirms); return(0); From 2c076856e6e321fe1177d91efd5867139e76b4de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:43:49 +0300 Subject: [PATCH 451/520] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxos.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 94f689a22..d7ca44dcd 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -324,7 +324,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep free_json(retjson); else { - printf("external unspent has no gettxout\n"); + //printf("external unspent has no gettxout\n"); flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,0,1); } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index f3cc3ad7e..b35e2e9c5 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -218,6 +218,7 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis)); return(0); } + // jl777 remove mempool HASH_ITER(hh,G.LP_utxoinfos[iambob],utxo,tmp) { //char str[65]; printf("s%u %d [%.8f vs %.8f] check %s.%s avail.%d ismine.%d >= %d\n",utxo->T.spentflag,LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout),dstr(destsatoshis),dstr(utxo->S.satoshis),utxo->coin,bits256_str(str,utxo->payment.txid),LP_isavailable(utxo) > 0,LP_ismine(utxo) > 0,utxo->S.satoshis >= destsatoshis); @@ -323,12 +324,12 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t printf("iambob.%d utxoadd %s inactive.%u got ineligible txid value %.8f:%.8f, value2 %.8f:%.8f, tmpsatoshis %.8f\n",iambob,symbol,coin->inactive,dstr(value),dstr(val),dstr(value2),dstr(val2),dstr(tmpsatoshis)); return(0); } - if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,1)) <= 0 ) + if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid,vout,0)) <= 0 ) { printf("LP_utxoadd reject numconfirms.%d %s.%s\n",numconfirms,symbol,bits256_str(str,txid)); return(0); } - if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,vout2,1)) <= 0 ) + if ( (numconfirms= LP_numconfirms(symbol,coinaddr,txid2,vout2,0)) <= 0 ) { printf("LP_utxoadd reject2 numconfirms.%d\n",numconfirms); return(0); From 320f0294c9b31b520b3649334aa08d184869dbe0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 21:48:09 +0300 Subject: [PATCH 452/520] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 3224428b0..b109e3130 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -596,14 +596,14 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int numconfirms = jint(txobj,"confirmations"); free_json(txobj); } - if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) + else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) numconfirms = 0; } else { if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) numconfirms = (LP_getheight(coin) - ht + 1); - if ( mempool != 0 ) + else if ( mempool != 0 ) { if ( LP_waitmempool(symbol,coinaddr,txid,vout,30) >= 0 ) numconfirms = 0; From f45a9670ec263fc0d0d6a8eddb4729537c9ce140 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 22:00:55 +0300 Subject: [PATCH 453/520] Test --- iguana/exchanges/LP_utxos.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b35e2e9c5..49009c739 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -506,6 +506,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri txfee = LP_txfeecalc(coin,0); if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { + printf("%s %s\n",coin->symbol,jprint(array,0)); for (iambob=0; iambob<=1; iambob++) { if ( iambob == 0 ) @@ -620,8 +621,6 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } //else printf("nothing near i.%d\n",i); } else break; } - if ( iambob == 1 ) - free(values); if ( enable_utxos == 0 ) break; } @@ -630,6 +629,8 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( flag != 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } + if ( values != 0 ) + free(values); //printf("privkey.%s %.8f\n",symbol,dstr(total)); return(flag); } From 8b8c7856e89092059956ec7f57680d78da39d189 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 22:10:53 +0300 Subject: [PATCH 454/520] Test --- iguana/exchanges/LP_ordermatch.c | 86 +----------------------------- iguana/exchanges/LP_statemachine.c | 81 ++++++++++++++++++++++++++++ iguana/exchanges/LP_utxos.c | 2 +- 3 files changed, 84 insertions(+), 85 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cfc356d81..32d740ab7 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -435,25 +435,6 @@ int32_t LP_nanobind(void *ctx,char *pairstr) return(pairsock); } -/*struct LP_utxoinfo BUTXOS[100]; - -int32_t LP_butxo_findeither(bits256 txid,int32_t vout) -{ - struct LP_utxoinfo *utxo; int32_t i,retval = 0; - portable_mutex_lock(&LP_butxomutex); - for (i=0; ipayment.vout && bits256_cmp(txid,utxo->payment.txid)) == 0 || (vout == utxo->deposit.vout && bits256_cmp(txid,utxo->deposit.txid) == 0) ) - { - retval = 1; - break; - } - } - portable_mutex_unlock(&LP_butxomutex); - return(retval); -}*/ - int32_t LP_nearest_utxovalue(struct LP_address_utxo **utxos,int32_t n,uint64_t targetval) { int32_t i,mini = -1; int64_t dist; uint64_t mindist = (1LL << 60); @@ -489,7 +470,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** if ( (m= LP_address_utxo_ptrs(iambob,utxos,max,ap)) > 1 ) { targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee); - if ( 1 ) + if ( 0 ) { int32_t i; for (i=0; ipayment.vout == utxo->payment.vout && butxo->deposit.vout == utxo->deposit.vout && bits256_nonz(butxo->payment.txid) != 0 && bits256_nonz(butxo->deposit.txid) != 0 && bits256_cmp(butxo->payment.txid,utxo->payment.txid) == 0 && bits256_cmp(butxo->deposit.txid,utxo->deposit.txid) == 0 ) - break; - if ( utxo->S.swap == 0 && now > utxo->T.swappending ) - memset(utxo,0,sizeof(*utxo)); - utxo = 0; - } - //portable_mutex_unlock(&LP_butxomutex); - return(utxo); -} - -struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) -{ - static struct LP_utxoinfo zeroes; - int32_t i; struct LP_utxoinfo *utxo=0; - portable_mutex_lock(&LP_butxomutex); - if ( (utxo= _LP_butxo_find(butxo)) == 0 ) - { - for (i=0; iS = srcutxo->S; - destutxo->T = srcutxo->T; -} - -void LP_butxo_swapfields(struct LP_utxoinfo *butxo) -{ - struct LP_utxoinfo *getutxo=0; - portable_mutex_lock(&LP_butxomutex); - if ( (getutxo= _LP_butxo_find(butxo)) != 0 ) - LP_butxo_swapfields_copy(butxo,getutxo); - portable_mutex_unlock(&LP_butxomutex); -} - -void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) -{ - struct LP_utxoinfo *setutxo; - if ( (setutxo= LP_butxo_add(butxo)) != 0 ) - { - LP_butxo_swapfields_copy(setutxo,butxo); - } -}*/ - void LP_abutxo_set(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,struct LP_quoteinfo *qp) { if ( butxo != 0 ) @@ -824,7 +742,6 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, memset(autxo,0,sizeof(*autxo)); memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); - printf("A %p, B %p\n",autxo,butxo); //LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { @@ -974,6 +891,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q } else { + printf("invalid price %.8f\n",price); jaddnum(bestitem,"maxprice",maxprice); jaddstr(bestitem,"status","no response to request"); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 073832675..29af48553 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -1608,6 +1608,87 @@ int32_t LP_utxopurge(int32_t allutxos) portable_mutex_unlock(&LP_utxomutex); return(n); } +/*struct LP_utxoinfo *_LP_butxo_find(struct LP_utxoinfo *butxo) + { + int32_t i; struct LP_utxoinfo *utxo=0; uint32_t now = (uint32_t)time(NULL); + //portable_mutex_lock(&LP_butxomutex); + for (i=0; ipayment.vout == utxo->payment.vout && butxo->deposit.vout == utxo->deposit.vout && bits256_nonz(butxo->payment.txid) != 0 && bits256_nonz(butxo->deposit.txid) != 0 && bits256_cmp(butxo->payment.txid,utxo->payment.txid) == 0 && bits256_cmp(butxo->deposit.txid,utxo->deposit.txid) == 0 ) + break; + if ( utxo->S.swap == 0 && now > utxo->T.swappending ) + memset(utxo,0,sizeof(*utxo)); + utxo = 0; + } + //portable_mutex_unlock(&LP_butxomutex); + return(utxo); + } + + struct LP_utxoinfo *LP_butxo_add(struct LP_utxoinfo *butxo) + { + static struct LP_utxoinfo zeroes; + int32_t i; struct LP_utxoinfo *utxo=0; + portable_mutex_lock(&LP_butxomutex); + if ( (utxo= _LP_butxo_find(butxo)) == 0 ) + { + for (i=0; iS = srcutxo->S; + destutxo->T = srcutxo->T; + } + + void LP_butxo_swapfields(struct LP_utxoinfo *butxo) + { + struct LP_utxoinfo *getutxo=0; + portable_mutex_lock(&LP_butxomutex); + if ( (getutxo= _LP_butxo_find(butxo)) != 0 ) + LP_butxo_swapfields_copy(butxo,getutxo); + portable_mutex_unlock(&LP_butxomutex); + } + + void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo) + { + struct LP_utxoinfo *setutxo; + if ( (setutxo= LP_butxo_add(butxo)) != 0 ) + { + LP_butxo_swapfields_copy(setutxo,butxo); + } + }*/ +/*struct LP_utxoinfo BUTXOS[100]; + + int32_t LP_butxo_findeither(bits256 txid,int32_t vout) + { + struct LP_utxoinfo *utxo; int32_t i,retval = 0; + portable_mutex_lock(&LP_butxomutex); + for (i=0; ipayment.vout && bits256_cmp(txid,utxo->payment.txid)) == 0 || (vout == utxo->deposit.vout && bits256_cmp(txid,utxo->deposit.txid) == 0) ) + { + retval = 1; + break; + } + } + portable_mutex_unlock(&LP_butxomutex); + return(retval); + }*/ + struct LP_utxoinfo *LP_utxoaddjson(int32_t iambob,int32_t pubsock,cJSON *argjson) { struct LP_utxoinfo *utxo; diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 49009c739..e98fd497a 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -506,7 +506,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri txfee = LP_txfeecalc(coin,0); if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - printf("%s %s\n",coin->symbol,jprint(array,0)); + //printf("%s %s\n",coin->symbol,jprint(array,0)); for (iambob=0; iambob<=1; iambob++) { if ( iambob == 0 ) From 75f83217536ccf99460473708f36511e24b69c82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 22:15:46 +0300 Subject: [PATCH 455/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 32d740ab7..de9658f40 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -398,7 +398,7 @@ double LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct L break; } } - usleep(1000000); + usleep(250000); } return(price); } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index f60b025b4..2755710a7 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -392,12 +392,12 @@ double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,i ptr->price = (double)ptr->Q.destsatoshis / ptr->Q.satoshis; if ( LP_pricevalid(ptr->price) <= 0 ) ptr->price = 0.; - //printf("LP_pricecache: set %s/%s ptr->price %.8f\n",base,rel,ptr->price); + printf("LP_pricecache: set %s/%s ptr->price %.8f\n",base,rel,ptr->price); } - //printf("found %s/%s %.8f\n",base,rel,ptr->price); + printf("found %s/%s %.8f\n",base,rel,ptr->price); return(ptr->price); } - //char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout); + char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout); return(0.); } From 884c33f6a641579085ec0f6dd68d5c3d35bc3fb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Sep 2017 22:32:03 +0300 Subject: [PATCH 456/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index de9658f40..b32108f0b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -983,7 +983,9 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel timeout = LP_AUTOTRADE_TIMEOUT; if ( maxprice <= 0. || relvolume <= 0. || LP_priceinfofind(base) == 0 || LP_priceinfofind(rel) == 0 ) return(clonestr("{\"error\":\"invalid parameter\"}")); - maxprice *= 1.005; + 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; From 2b9e3c7ba5b86f2ddf58a9b877642f8eba3696dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 09:34:41 +0300 Subject: [PATCH 457/520] Test --- iguana/exchanges/LP_nativeDEX.c | 11 ++++++----- iguana/exchanges/electrums | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 931906904..f5ca48945 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -20,14 +20,15 @@ // marketmaker // // new features: +// -check for completed one being spent +// make remember remember // sign, spv check // bittrex balancing // stats - -// -detect port conflicts on enable -// -check for completed one being spent -// -prevent autxo reuse -// -add extra hash to keypair25519 +// so alice doesnt detect swap complete and electrum doesnt get .finished after swapstatus. ok, seems like an electrum tx construction/detection issue in the swapstatus path and some wonkiness with SWAP complete detection in general. I need to cleanup that logic a lot +// gettxout mempool a few other local network calls +// electrum cache for blockchain.transaction.get +// scan history for electrum after swap // unduplicated bugs: // swap cancel should cleanly cancel diff --git a/iguana/exchanges/electrums b/iguana/exchanges/electrums index 06efc8f02..43b4d8811 100755 --- a/iguana/exchanges/electrums +++ b/iguana/exchanges/electrums @@ -1,5 +1,6 @@ -ource userpass +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"REVS\",\"ipaddr\":\"173.212.225.176\",\"port\":50050}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CHIPS\",\"ipaddr\":\"173.212.225.176\",\"port\":50076}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"ARG\",\"ipaddr\":\"173.212.225.176\",\"port\":50081}" From 436c57d0adb8e54a852f79db63eeb9588ba11291 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 09:56:58 +0300 Subject: [PATCH 458/520] Test --- iguana/exchanges/LP_coins.c | 1 + iguana/exchanges/LP_socket.c | 16 ++-------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index bf02bc11a..e1eca4ab0 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -174,6 +174,7 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) { struct electrum_info *ep; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); jaddstr(item,"coin",coin->symbol); + jaddnum(item,"height",coin->height); if ( showwif != 0 ) { bitcoin_priv2wif(coin->wiftaddr,wifstr,G.LP_mypriv25519,coin->wiftype); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index d7ca44dcd..d72b9d1b3 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -253,16 +253,6 @@ struct electrum_info } *Electrums[8192]; int32_t Num_electrums; -// purge timedout -/* -if ( (retjson= electrum_address_listunspent(symbol,ep,&retjson,addr)) != 0 ) -you can call it like the above, where symbol is the coin, ep is the electrum server info pointer, the 0 is a callback ptr where 0 means to block till it is done -all the API calls have the same three args -if the callback ptr is &retjson, then on completion it will put the cJSON *ptr into it, so to spawn a bunch of calls you need to call with symbol,ep,&retjsons[i],... -default timeout is set to 2 seconds, not sure if that is enough, on each receive from any server, requests that are timeout are purged (and if a callback set, will just return and "error" timeout JSON -a null value for ep will make it choose a random server for that coin - */ - struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) { struct electrum_info *rbuf[128],*recent_ep; uint32_t recent,mostrecent = 0; int32_t i,n = 0; @@ -442,8 +432,6 @@ cJSON *electrum_hasharg(char *symbol,struct electrum_info *ep,cJSON **retjsonp,c return(electrum_submit(symbol,ep,retjsonp,method,params,timeout)); } -//" "--blockchain.numblocks.subscribe", "--blockchain.address.get_proof", "--blockchain.utxo.get_address", - cJSON *electrum_version(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.version",ELECTRUM_TIMEOUT)); } cJSON *electrum_banner(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.banner",ELECTRUM_TIMEOUT)); } cJSON *electrum_donation(char *symbol,struct electrum_info *ep,cJSON **retjsonp) { return(electrum_noargs(symbol,ep,retjsonp,"server.donation_address",ELECTRUM_TIMEOUT)); } @@ -517,7 +505,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,ep,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); @@ -700,7 +688,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) *(ep->heighttimep) = (uint32_t)time(NULL); if ( (coin= LP_coinfind(ep->symbol)) != 0 ) coin->updaterate = (uint32_t)time(NULL); - printf("%s ELECTRUM >>>>>>>>> set height.%d\n",ep->symbol,height); + //printf("%s ELECTRUM >>>>>>>>> set height.%d\n",ep->symbol,height); } } idnum = juint(strjson,"id"); From 54f39a1b3d3dc4178f567b5cdf59e4bbcc876c5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 09:58:15 +0300 Subject: [PATCH 459/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index d72b9d1b3..7ae75f3ad 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -529,7 +529,7 @@ cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp, cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { - char str[65]; printf("%s TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); + char str[65]; printf("%s add cache here -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); if ( bits256_nonz(txid) != 0 ) return(electrum_hasharg(symbol,ep,retjsonp,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT)); else return(cJSON_Parse("{\"error\":\"null txid\"}")); From 0fff37ae5a829dee74dad63995557e8971382dc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:22:15 +0300 Subject: [PATCH 460/520] Test --- iguana/exchanges/LP_rpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 107cca7a0..88ab41795 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -259,7 +259,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid) else { sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); - if ( (retjson= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) + if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid)) != 0 ) { hexstr = jprint(retjson,1); if ( strlen(hexstr) > 20000 ) @@ -313,7 +313,7 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) { printf("gettxout v%d\n",vout); sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); - if ( (hexobj= bitcoin_json(coin,"blockchain.transaction.get",buf)) != 0 ) + if ( (hexobj= electrum_transaction(symbol,coin->electrum,&hexobj,txid)) != 0 ) { hexstr = jprint(hexobj,1); if ( strlen(hexstr) > 20000 ) From bf87f475770cb5c4266d26d9ded2a069ed439ce6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:25:08 +0300 Subject: [PATCH 461/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 7ae75f3ad..efac000e8 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -505,7 +505,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,ep,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); From 46e80013974ef86ba70d3c4f59e681e238fa4f20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:30:39 +0300 Subject: [PATCH 462/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index efac000e8..f4809d1f1 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -501,7 +501,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); //printf("electrum.%s/%s listunspent last.(%s lag %d)\n",ep->symbol,coin->symbol,coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); - if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+30 ) + if ( 1 || strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+30 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { From 8e3bb99773f64b4816d8977f2dd4940804c76938 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:41:33 +0300 Subject: [PATCH 463/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b32108f0b..3f114c46d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -470,7 +470,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** if ( (m= LP_address_utxo_ptrs(iambob,utxos,max,ap)) > 1 ) { targetval = LP_basesatoshis(relvolume,price,txfee,desttxfee); - if ( 0 ) + if ( 1 ) { int32_t i; for (i=0; i Date: Mon, 2 Oct 2017 10:45:05 +0300 Subject: [PATCH 464/520] Test --- iguana/exchanges/enable | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/enable b/iguana/exchanges/enable index bb2b70d30..c4b2a56e3 100755 --- a/iguana/exchanges/enable +++ b/iguana/exchanges/enable @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"REVS\"}" From ad3dbdc24c5e98153d02988570561182334b8378 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:46:48 +0300 Subject: [PATCH 465/520] Test --- iguana/exchanges/inv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/inv b/iguana/exchanges/inv index 1a86e88f4..bdd1d58c1 100755 --- a/iguana/exchanges/inv +++ b/iguana/exchanges/inv @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"REVS\"}" From baa5e38cf03c3499e363b1294af17672b602f9db Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:49:19 +0300 Subject: [PATCH 466/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 3f114c46d..9df87e3fa 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -475,7 +475,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo ** int32_t i; for (i=0; iU.value)); - printf("targetval %.8f vol %.8f price %.8f txfee %.8f\n",dstr(targetval),relvolume,price,dstr(txfee)); + printf("targetval %.8f vol %.8f price %.8f txfee %.8f %s\n",dstr(targetval),relvolume,price,dstr(txfee),coinaddr); } mini = -1; if ( targetval != 0 && (mini= LP_nearest_utxovalue(utxos,m,targetval)) >= 0 && (double)utxos[mini]->U.value/targetval < LP_MINVOL-1 ) From db6f65706ac010703a48fd92c4490a4e7c915137 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:54:02 +0300 Subject: [PATCH 467/520] Test --- iguana/exchanges/LP_rpc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 88ab41795..d84e55dc2 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -488,7 +488,10 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) if ( coin->electrum != 0 ) { if ( (retjson= electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)) != 0 ) + { n = cJSON_GetArraySize(retjson); + printf("LP_listunspent_issue %s.%d %s\n",coinaddr,n,jprint(retjson,0)); + } } else { From 3e71c2f28ef60c2ad20b7e4f297ffcf8d852bc8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 10:56:02 +0300 Subject: [PATCH 468/520] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d84e55dc2..4f7e66fdc 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -490,7 +490,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) if ( (retjson= electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)) != 0 ) { n = cJSON_GetArraySize(retjson); - printf("LP_listunspent_issue %s.%d %s\n",coinaddr,n,jprint(retjson,0)); + printf("LP_listunspent_issue.%s %s.%d %s\n",symbol,coinaddr,n,jprint(retjson,0)); } } else From b2dce8dcca1115d40afcf10770e574c9f20a4b68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:02:18 +0300 Subject: [PATCH 469/520] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9df87e3fa..ee90ee06a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -923,15 +923,15 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i { item = jitem(asks,i); price = jdouble(item,"price"); + pubkey = jbits256(item,"pubkey"); + printf("%s pubcmp %d price %.8f vs maxprice %.8f\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519),price,maxprice); if ( LP_pricevalid(price) > 0 && price <= maxprice ) { - pubkey = jbits256(item,"pubkey"); for (j=0; jtaddr,basecoin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); From 903a90af5ede0810acc3f144def39211400ddbb7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:07:52 +0300 Subject: [PATCH 470/520] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 ++ iguana/exchanges/LP_prices.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 233c1a70e..a83393913 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -182,7 +182,7 @@ struct iguana_info portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; - uint32_t lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime; + uint32_t lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag; char symbol[16],smartaddr[64],userpass[1024],serverport[128],lastunspent[64]; // portfolio diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f5ca48945..9c3197e16 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -478,6 +478,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; if ( coin->electrum != 0 ) continue; + if ( coin->obooktime == 0 ) + continue; if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { if ( (height= LP_getheight(coin)) > coin->longestchain ) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 2755710a7..93733a9b0 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -746,6 +746,8 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) baseid = basepp->ind; relid = relpp->ind; now = (uint32_t)time(NULL); + basecoin->obooktime = now; + relcoin->obooktime = now; cachenumbids = numbids, cachenumasks = numasks; //printf("start cache.(%d %d) numbids.%d numasks.%d\n",cachenumbids,cachenumasks,numbids,numasks); numasks = LP_orderbook_utxoentries(now,1,base,rel,&asks,numasks,cachenumasks,duration); From 1bd1f35047cc37304ac5f4491b632de761cd0684 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:16:35 +0300 Subject: [PATCH 471/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_rpc.c | 1 + iguana/exchanges/LP_scan.c | 1 + 4 files changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9c3197e16..be9a939bb 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -322,6 +322,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) if ( coin->inactive != 0 ) continue; total = 0; + printf("from utxos_sync\n"); LP_listunspent_both(coin->symbol,coin->smartaddr); if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ee90ee06a..38e5e9685 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -695,6 +695,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) //printf("issue path electrum.%p\n",coin->electrum); //if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) // free_json(array); + printf("listunspent_both\n"); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 4f7e66fdc..25a3479c4 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -481,6 +481,7 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; +printf("LP_listunspent_issue.%s %s\n",symbol,coinaddr); if ( symbol == 0 || symbol[0] == 0 ) return(0); if ( (coin= LP_coinfind(symbol)) != 0 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 006b4b6cf..f8ec39a14 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -481,6 +481,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int } free(array); } + printf("from waitmempool\n"); LP_listunspent_issue(coin->symbol,coinaddr); struct LP_address_utxo *up; if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) From 198448308f70819bb0fb8c859a8690318cbe66f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:18:17 +0300 Subject: [PATCH 472/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index be9a939bb..3fe84aff7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -319,7 +319,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr; HASH_ITER(hh,LP_coins,coin,ctmp) { - if ( coin->inactive != 0 ) + if ( coin->inactive != 0 || coin->obooktime == 0 ) continue; total = 0; printf("from utxos_sync\n"); From 164b5c285c9b67832b979e7b355487ad6a4ed9a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:25:44 +0300 Subject: [PATCH 473/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_prices.c | 1 + iguana/exchanges/LP_rpc.c | 1 - iguana/exchanges/LP_scan.c | 1 - 5 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3fe84aff7..e906b24fc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -322,7 +322,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) if ( coin->inactive != 0 || coin->obooktime == 0 ) continue; total = 0; - printf("from utxos_sync\n"); + //printf("from utxos_sync\n"); LP_listunspent_both(coin->symbol,coin->smartaddr); if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 38e5e9685..bd4ba1ae3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -695,7 +695,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) //printf("issue path electrum.%p\n",coin->electrum); //if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) // free_json(array); - printf("listunspent_both\n"); + //printf("listunspent_both\n"); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 93733a9b0..5cbff8581 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -224,6 +224,7 @@ char *LP_pubkey_trustset(bits256 pubkey,uint32_t trustval) uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) { cJSON *array,*item; int32_t i,n; uint64_t metric=0,total; + printf("unspents metric\n"); LP_listunspent_both(coin->symbol,coinaddr); if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 25a3479c4..4f7e66fdc 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -481,7 +481,6 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; -printf("LP_listunspent_issue.%s %s\n",symbol,coinaddr); if ( symbol == 0 || symbol[0] == 0 ) return(0); if ( (coin= LP_coinfind(symbol)) != 0 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index f8ec39a14..006b4b6cf 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -481,7 +481,6 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int } free(array); } - printf("from waitmempool\n"); LP_listunspent_issue(coin->symbol,coinaddr); struct LP_address_utxo *up; if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) From 943d261e7ca5cd0970609a178462f8f034c48daf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:30:05 +0300 Subject: [PATCH 474/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e906b24fc..3fe84aff7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -322,7 +322,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) if ( coin->inactive != 0 || coin->obooktime == 0 ) continue; total = 0; - //printf("from utxos_sync\n"); + printf("from utxos_sync\n"); LP_listunspent_both(coin->symbol,coin->smartaddr); if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bd4ba1ae3..38e5e9685 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -695,7 +695,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) //printf("issue path electrum.%p\n",coin->electrum); //if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) // free_json(array); - //printf("listunspent_both\n"); + printf("listunspent_both\n"); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 4f7e66fdc..973fa2f5e 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -491,7 +491,9 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { n = cJSON_GetArraySize(retjson); printf("LP_listunspent_issue.%s %s.%d %s\n",symbol,coinaddr,n,jprint(retjson,0)); - } + if ( strcmp(symbol,"ARG") == 0 ) + assert(0); + } } else { From 3ef1dc48076f106a6412df22ead93a62bf116afc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:37:13 +0300 Subject: [PATCH 475/520] Test --- iguana/exchanges/LP_nativeDEX.c | 1 - iguana/exchanges/LP_ordermatch.c | 1 - iguana/exchanges/LP_portfolio.c | 6 +++++- iguana/exchanges/LP_prices.c | 1 - iguana/exchanges/LP_rpc.c | 4 +--- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3fe84aff7..e15ab19b5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -322,7 +322,6 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) if ( coin->inactive != 0 || coin->obooktime == 0 ) continue; total = 0; - printf("from utxos_sync\n"); LP_listunspent_both(coin->symbol,coin->smartaddr); if ( (array= LP_address_utxos(coin,coin->smartaddr,1)) != 0 ) { diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 38e5e9685..ee90ee06a 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -695,7 +695,6 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) //printf("issue path electrum.%p\n",coin->electrum); //if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) // free_json(array); - printf("listunspent_both\n"); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 585f236f1..e648e3381 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -89,7 +89,7 @@ char *LP_portfolio() { HASH_ITER(hh,LP_coins,coin,tmp) { - if ( coin->inactive != 0 ) + if ( coin->inactive != 0 || coin->obooktime == 0 ) continue; if ( iter == 0 ) { @@ -184,12 +184,16 @@ char *LP_portfolio_goal(char *symbol,double goal) coin->goal = kmdbtc * 0.5; if ( (coin= LP_coinfind("BTC")) != 0 && coin->inactive == 0 ) coin->goal = kmdbtc * 0.5; + if ( coin->goal != 0 ) + coin->obooktime = (uint32_t)time(NULL); return(LP_portfolio()); } else if ( (coin= LP_coinfind(symbol)) != 0 && coin->inactive == 0 ) { coin->goal = goal; printf("set %s goal %f\n",coin->symbol,goal); + if ( coin->goal != 0 ) + coin->obooktime = (uint32_t)time(NULL); return(LP_portfolio()); } else return(clonestr("{\"error\":\"cant set goal for inactive coin\"}")); } diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 5cbff8581..93733a9b0 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -224,7 +224,6 @@ char *LP_pubkey_trustset(bits256 pubkey,uint32_t trustval) uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) { cJSON *array,*item; int32_t i,n; uint64_t metric=0,total; - printf("unspents metric\n"); LP_listunspent_both(coin->symbol,coinaddr); if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) { diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 973fa2f5e..4f7e66fdc 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -491,9 +491,7 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) { n = cJSON_GetArraySize(retjson); printf("LP_listunspent_issue.%s %s.%d %s\n",symbol,coinaddr,n,jprint(retjson,0)); - if ( strcmp(symbol,"ARG") == 0 ) - assert(0); - } + } } else { From a07824a362f33dce10fa37e84c5000f40d19096e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 11:43:27 +0300 Subject: [PATCH 476/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ee90ee06a..ef3cefd06 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -924,7 +924,7 @@ struct LP_utxoinfo *LP_buyutxo(double *ordermatchpricep,int64_t *bestsatoshisp,i item = jitem(asks,i); price = jdouble(item,"price"); pubkey = jbits256(item,"pubkey"); - printf("%s pubcmp %d price %.8f vs maxprice %.8f\n",jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519),price,maxprice); + printf("[%d/%d] %s pubcmp %d price %.8f vs maxprice %.8f\n",i,numasks,jprint(item,0),bits256_cmp(pubkey,G.LP_mypub25519),price,maxprice); if ( LP_pricevalid(price) > 0 && price <= maxprice ) { for (j=0; jelectrum,&retjson,coinaddr)) != 0 ) { n = cJSON_GetArraySize(retjson); - printf("LP_listunspent_issue.%s %s.%d %s\n",symbol,coinaddr,n,jprint(retjson,0)); + //printf("LP_listunspent_issue.%s %s.%d %s\n",symbol,coinaddr,n,jprint(retjson,0)); } } else From 760a31b337e12326a8c30eaf2da28bca741957ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 12:59:44 +0300 Subject: [PATCH 477/520] Electrum tx cache --- iguana/exchanges/LP_include.h | 8 +- iguana/exchanges/LP_prices.c | 4 +- iguana/exchanges/LP_rpc.c | 161 +++++++++++++--------------------- iguana/exchanges/LP_socket.c | 77 ++++++++++++++-- iguana/exchanges/LP_utxo.c | 8 +- 5 files changed, 143 insertions(+), 115 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a83393913..d1a85727e 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -172,7 +172,8 @@ struct LP_outpoint { bits256 spendtxid; uint64_t value,interest; int32_t spendvi struct LP_transaction { UT_hash_handle hh; - bits256 txid; int32_t height,numvouts,numvins; //uint32_t timestamp; + bits256 txid; int32_t height,numvouts,numvins,len; //uint32_t timestamp; + uint8_t *serialized; struct LP_outpoint outpoints[]; }; @@ -303,6 +304,8 @@ struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr); struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr); int32_t iguana_signrawtransaction(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson); //void LP_butxo_swapfields_set(struct LP_utxoinfo *butxo); +struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout); +int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJSON *txobj); @@ -310,10 +313,11 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); -cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout); +cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout); void LP_postutxos(char *symbol,char *coinaddr); int32_t LP_listunspent_both(char *symbol,char *coinaddr); uint16_t LP_randpeer(char *destip); +cJSON *bitcoin_data2json(uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len,cJSON *vins,int32_t suppress_pubkeys); //int32_t LP_butxo_findeither(bits256 txid,int32_t vout); cJSON *LP_listunspent(char *symbol,char *coinaddr); int32_t LP_gettx_presence(char *symbol,bits256 expectedtxid); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 93733a9b0..b7c9e04b0 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -394,10 +394,10 @@ double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,i ptr->price = 0.; printf("LP_pricecache: set %s/%s ptr->price %.8f\n",base,rel,ptr->price); } - printf("found %s/%s %.8f\n",base,rel,ptr->price); + printf(">>>>>>>>>> found %s/%s %.8f\n",base,rel,ptr->price); return(ptr->price); } - char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout); + //char str[65]; printf("cachemiss %s/%s %s/v%d\n",base,rel,bits256_str(str,txid),vout); return(0.); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 3a632d6c1..deffe3bf6 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -243,7 +243,7 @@ cJSON *LP_paxprice(char *fiat) cJSON *LP_gettx(char *symbol,bits256 txid) { - char buf[128],str[65],*hexstr; int32_t len; bits256 checktxid; cJSON *retjson; struct iguana_info *coin; struct iguana_msgtx msgtx; uint8_t *extraspace,*serialized; + struct iguana_info *coin; char buf[512],str[65]; cJSON *retjson; if ( symbol == 0 || symbol[0] == 0 ) return(cJSON_Parse("{\"error\":\"null symbol\"}")); coin = LP_coinfind(symbol); @@ -258,49 +258,38 @@ cJSON *LP_gettx(char *symbol,bits256 txid) } else { - sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid)) != 0 ) - { - hexstr = jprint(retjson,1); - if ( strlen(hexstr) > 20000 ) - { - static uint32_t counter; - if ( counter++ < 3 ) - printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); - free(hexstr); - return(cJSON_Parse("{\"error\":\"transaction too big\"}")); - } - if ( hexstr[0] == '"' && hexstr[strlen(hexstr)-1] == '"' ) - hexstr[strlen(hexstr)-1] = 0; - if ( (len= is_hexstr(hexstr+1,0)) > 2 ) - { - memset(&msgtx,0,sizeof(msgtx)); - len = (int32_t)strlen(hexstr+1) >> 1; - serialized = malloc(len); - decode_hex(serialized,len,hexstr+1); - free(hexstr); - //printf("DATA.(%s)\n",hexstr+1); - extraspace = calloc(1,1000000); - retjson = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,1000000,serialized,len,0,0); - free(serialized); - free(extraspace); - //printf("TX.(%s) match.%d\n",jprint(retjson,0),bits256_cmp(txid,checktxid)); - return(retjson); - } else printf("non-hex tx.(%s)\n",hexstr); - free(hexstr); - return(cJSON_Parse("{\"error\":\"non hex transaction\"}")); - } else printf("failed blockchain.transaction.get %s %s\n",coin->symbol,buf); + return(retjson); + else printf("failed blockchain.transaction.get %s %s\n",coin->symbol,buf); return(cJSON_Parse("{\"error\":\"no transaction bytes\"}")); } } -cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) +cJSON *LP_gettxout_json(bits256 txid,int32_t vout,int32_t height,char *coinaddr,uint64_t value) +{ + cJSON *retjson,*addresses,*sobj; + retjson = cJSON_CreateObject(); + jaddnum(retjson,"value",dstr(value)); + jaddnum(retjson,"height",height); + jaddbits256(retjson,"txid",txid); + jaddnum(retjson,"vout",vout); + addresses = cJSON_CreateArray(); + jaddistr(addresses,coinaddr); + sobj = cJSON_CreateObject(); + jaddnum(sobj,"reqSigs",1); + jaddstr(sobj,"type","pubkey"); + jadd(sobj,"addresses",addresses); + jadd(retjson,"scriptPubKey",sobj); + printf("GETTXOUT.(%s)\n",jprint(retjson,0)); + return(retjson); +} + +cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout) { - char buf[128],str[65],coinaddr[64],*hexstr; uint64_t value; uint8_t *serialized; cJSON *sobj,*addresses,*item,*array,*hexobj,*retjson=0; int32_t i,n,v,len; bits256 t; struct iguana_info *coin; + char buf[128],str[65]; cJSON *item,*array,*vouts,*txobj,*retjson=0; int32_t i,v,n; bits256 t; struct iguana_info *coin; struct LP_transaction *tx; struct LP_address_utxo *up; if ( symbol == 0 || symbol[0] == 0 ) return(cJSON_Parse("{\"error\":\"null symbol\"}")); - coin = LP_coinfind(symbol); - if ( coin == 0 ) + if ( (coin= LP_coinfind(symbol)) == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); if ( bits256_nonz(txid) == 0 ) return(cJSON_Parse("{\"error\":\"null txid\"}")); @@ -311,84 +300,52 @@ cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout) } else { - printf("gettxout v%d\n",vout); - sprintf(buf,"[\"%s\"]",bits256_str(str,txid)); - if ( (hexobj= electrum_transaction(symbol,coin->electrum,&hexobj,txid)) != 0 ) + if ( (tx= LP_transactionfind(coin,txid)) != 0 && vout < tx->numvouts ) + { + if ( tx->outpoints[vout].spendheight > 0 ) + return(0); + return(LP_gettxout_json(txid,vout,tx->height,tx->outpoints[vout].coinaddr,tx->outpoints[vout].value)); + } + if ( coinaddr[0] == 0 ) + { + if ( (txobj= electrum_transaction(symbol,coin->electrum,&txobj,txid)) != 0 ) + { + if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n > 0 ) + LP_destaddr(coinaddr,jitem(vouts,vout)); + free_json(txobj); + } + } + if ( coinaddr[0] != 0 ) { - hexstr = jprint(hexobj,1); - if ( strlen(hexstr) > 20000 ) + if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) != 0 ) { - static uint32_t counter; - if ( counter++ < 3 ) - printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); - free(hexstr); - return(cJSON_Parse("{\"error\":\"transaction too big\"}")); + if ( up->spendheight > 0 ) + return(0); + return(LP_gettxout_json(txid,vout,up->U.height,coinaddr,up->U.value)); } - if ( hexstr[0] == '"' && hexstr[strlen(hexstr)-1] == '"' ) - hexstr[strlen(hexstr)-1] = 0; - if ( (len= is_hexstr(hexstr+1,0)) > 2 ) + if ( (array= electrum_address_listunspent(coin->symbol,0,&array,coinaddr)) != 0 ) { - len = (int32_t)strlen(hexstr+1) >> 1; - serialized = malloc(len); - decode_hex(serialized,len,hexstr+1); - LP_swap_coinaddr(coin,coinaddr,&value,serialized,len,vout); - //printf("HEX.(%s) len.%d %s %.8f\n",hexstr+1,len,coinaddr,dstr(value)); - free(hexstr); - if ( (array= electrum_address_listunspent(coin->symbol,0,&array,coinaddr)) != 0 ) + //printf("array.(%s)\n",jprint(array,0)); + if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - //printf("array.(%s)\n",jprint(array,0)); - if ( array != 0 && (n= cJSON_GetArraySize(array)) > 0 ) + for (i=0; isymbol,txid,v)) != 0 ) + if ( (retjson= LP_gettxout(coin->symbol,coinaddr,txid,v)) != 0 ) free_json(retjson); else { @@ -527,12 +527,79 @@ cJSON *electrum_estimatefee(char *symbol,struct electrum_info *ep,cJSON **retjso cJSON *electrum_getheader(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_header",n,ELECTRUM_TIMEOUT)); } cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp,int32_t n) { return(electrum_intarg(symbol,ep,retjsonp,"blockchain.block.get_chunk",n,ELECTRUM_TIMEOUT)); } +cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *serialized,int32_t len) +{ + uint8_t *extraspace; cJSON *txobj; char str[65],str2[65]; struct iguana_msgtx msgtx; bits256 checktxid; + extraspace = calloc(1,1000000); + memset(&msgtx,0,sizeof(msgtx)); + txobj = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,1000000,serialized,len,0,0); + //printf("TX.(%s) match.%d\n",jprint(retjson,0),bits256_cmp(txid,checktxid)); + free(extraspace); + if ( bits256_cmp(txid,checktxid) != 0 ) + { + printf("LP_transaction_fromdata mismatched txid %s vs %s\n",bits256_str(str,txid),bits256_str(str2,checktxid)); + free_json(txobj); + txobj = 0; + } + return(txobj); +} + cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { - char str[65]; printf("%s add cache here -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); - if ( bits256_nonz(txid) != 0 ) - return(electrum_hasharg(symbol,ep,retjsonp,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT)); - else return(cJSON_Parse("{\"error\":\"null txid\"}")); + char *hexstr,str[65]; int32_t len; cJSON *hexjson,*txobj=0; struct iguana_info *coin; uint8_t *serialized; struct LP_transaction *tx; + if ( bits256_nonz(txid) != 0 && (coin= LP_coinfind(symbol)) != 0 ) + { + if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) + { + char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); + if ( (txobj= LP_transaction_fromdata(coin,txid,tx->serialized,tx->len)) != 0 ) + { + *retjsonp = txobj; + return(txobj); + } + } + hexjson = electrum_hasharg(symbol,ep,&hexjson,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT); + hexstr = jprint(hexjson,1); + if ( strlen(hexstr) > 60000 ) + { + static uint32_t counter; + if ( counter++ < 3 ) + printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); + free(hexstr); + *retjsonp = cJSON_Parse("{\"error\":\"transaction too big\"}"); + return(*retjsonp); + } + if ( hexstr[0] == '"' && hexstr[strlen(hexstr)-1] == '"' ) + hexstr[strlen(hexstr)-1] = 0; + if ( (len= is_hexstr(hexstr+1,0)) > 2 ) + { + len = (int32_t)strlen(hexstr+1) >> 1; + serialized = malloc(len); + decode_hex(serialized,len,hexstr+1); + free(hexstr); + //printf("DATA.(%s)\n",hexstr+1); + if ( (tx= LP_transactionfind(coin,txid)) == 0 || tx->serialized == 0 ) + { + txobj = LP_transactioninit(coin,txid,0,0); + LP_transactioninit(coin,txid,1,txobj); + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + tx->serialized = serialized; + tx->len = len; + } + else + { + printf("unexpected couldnt find tx %s %s\n",coin->symbol,bits256_str(str,txid)); + free(serialized); + } + } + *retjsonp = txobj; + return(*retjsonp); + } else printf("non-hex tx.(%s)\n",hexstr); + free(hexstr); + } + *retjsonp = cJSON_Parse("{\"error\":\"null txid\"}"); + return(*retjsonp); } cJSON *electrum_getmerkle(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,int32_t height) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index b109e3130..202af4e49 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -332,7 +332,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array) val = j64bits(item,"value"); //if ( strcmp(coin->symbol,"LBC") == 0 ) // printf("(%s)\n",jprint(item,0)); - if ( coin->electrum == 0 && (txobj= LP_gettxout(coin->symbol,txid,v)) != 0 ) + if ( coin->electrum == 0 && (txobj= LP_gettxout(coin->symbol,coinaddr,txid,v)) != 0 ) { value = LP_value_extract(txobj,0); if ( value != 0 && value != val ) @@ -475,7 +475,7 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf uint64_t interest,value = 0; cJSON *txobj; *interestp = 0; destaddr[0] = 0; - if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) + if ( (txobj= LP_gettxout(coin->symbol,destaddr,txid,vout)) != 0 ) { if ( (value= LP_value_extract(txobj,0)) == 0 ) { @@ -591,7 +591,7 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int if ( coin->electrum == 0 ) { numconfirms = -1; - if ( (txobj= LP_gettxout(symbol,txid,vout)) != 0 ) + if ( (txobj= LP_gettxout(symbol,coinaddr,txid,vout)) != 0 ) { numconfirms = jint(txobj,"confirmations"); free_json(txobj); @@ -663,7 +663,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) } else { - if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) + if ( (txobj= LP_gettxout(coin->symbol,coinaddr,txid,vout)) != 0 ) { value = LP_value_extract(txobj,0);//SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest")); if ( coinaddr == 0 ) From 9e790d2f20541e674cad517d2a450293118b15bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:04:42 +0300 Subject: [PATCH 478/520] Test --- iguana/exchanges/LP_socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 1a953c9af..66ccabd59 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -577,7 +577,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso serialized = malloc(len); decode_hex(serialized,len,hexstr+1); free(hexstr); - //printf("DATA.(%s)\n",hexstr+1); + printf("DATA.(%s)\n",hexstr+1); if ( (tx= LP_transactionfind(coin,txid)) == 0 || tx->serialized == 0 ) { txobj = LP_transactioninit(coin,txid,0,0); @@ -594,6 +594,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso } } *retjsonp = txobj; + printf("return from electrum_transaction\n"); return(*retjsonp); } else printf("non-hex tx.(%s)\n",hexstr); free(hexstr); From eff4c7440858669e15a98dfdd59b98ac25880c85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:06:44 +0300 Subject: [PATCH 479/520] Test --- iguana/exchanges/LP_socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 66ccabd59..ed9f47392 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -533,7 +533,7 @@ cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *se extraspace = calloc(1,1000000); memset(&msgtx,0,sizeof(msgtx)); txobj = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,1000000,serialized,len,0,0); - //printf("TX.(%s) match.%d\n",jprint(retjson,0),bits256_cmp(txid,checktxid)); + printf("TX.(%s) match.%d\n",jprint(txobj,0),bits256_cmp(txid,checktxid)); free(extraspace); if ( bits256_cmp(txid,checktxid) != 0 ) { @@ -547,6 +547,7 @@ cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *se cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { char *hexstr,str[65]; int32_t len; cJSON *hexjson,*txobj=0; struct iguana_info *coin; uint8_t *serialized; struct LP_transaction *tx; + printf("electrum_transaction %s\n",bits256_str(str,txid)); if ( bits256_nonz(txid) != 0 && (coin= LP_coinfind(symbol)) != 0 ) { if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) From 167f5cf8b752681845786bd57290c91225bbf904 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:11:17 +0300 Subject: [PATCH 480/520] Test --- iguana/exchanges/LP_socket.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index ed9f47392..7fae05545 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -547,7 +547,7 @@ cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *se cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { char *hexstr,str[65]; int32_t len; cJSON *hexjson,*txobj=0; struct iguana_info *coin; uint8_t *serialized; struct LP_transaction *tx; - printf("electrum_transaction %s\n",bits256_str(str,txid)); + printf("electrum_transaction %s %s\n",symbol,bits256_str(str,txid)); if ( bits256_nonz(txid) != 0 && (coin= LP_coinfind(symbol)) != 0 ) { if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) @@ -560,13 +560,14 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso } } hexjson = electrum_hasharg(symbol,ep,&hexjson,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT); - hexstr = jprint(hexjson,1); + hexstr = jprint(hexjson,0); if ( strlen(hexstr) > 60000 ) { static uint32_t counter; if ( counter++ < 3 ) printf("rawtransaction too big %d\n",(int32_t)strlen(hexstr)); free(hexstr); + free_json(hexjson); *retjsonp = cJSON_Parse("{\"error\":\"transaction too big\"}"); return(*retjsonp); } @@ -578,7 +579,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso serialized = malloc(len); decode_hex(serialized,len,hexstr+1); free(hexstr); - printf("DATA.(%s)\n",hexstr+1); + printf("DATA.(%s) from (%s)\n",hexstr+1,jprint(hexjson,0)); if ( (tx= LP_transactionfind(coin,txid)) == 0 || tx->serialized == 0 ) { txobj = LP_transactioninit(coin,txid,0,0); @@ -595,10 +596,12 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso } } *retjsonp = txobj; + free_json(hexjson); printf("return from electrum_transaction\n"); return(*retjsonp); - } else printf("non-hex tx.(%s)\n",hexstr); + } else printf("non-hex tx.(%s)\n",jprint(hexjson,0)); free(hexstr); + free_json(hexjson); } *retjsonp = cJSON_Parse("{\"error\":\"null txid\"}"); return(*retjsonp); From f0e4ea026af479f358d2d82eb0ab69fa4d0fc9f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:16:05 +0300 Subject: [PATCH 481/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 7fae05545..7cbbe6036 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -582,7 +582,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso printf("DATA.(%s) from (%s)\n",hexstr+1,jprint(hexjson,0)); if ( (tx= LP_transactionfind(coin,txid)) == 0 || tx->serialized == 0 ) { - txobj = LP_transactioninit(coin,txid,0,0); + txobj = LP_transactioninit(coin,txid,0,LP_transaction_fromdata(coin,txid,serialized,len)); LP_transactioninit(coin,txid,1,txobj); if ( (tx= LP_transactionfind(coin,txid)) != 0 ) { From 73340b4cda1eecf54a33e13eaa305b4e6ae2f2f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:19:54 +0300 Subject: [PATCH 482/520] Test --- iguana/exchanges/LP_socket.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 7cbbe6036..365e7ba3f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -547,7 +547,7 @@ cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *se cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { char *hexstr,str[65]; int32_t len; cJSON *hexjson,*txobj=0; struct iguana_info *coin; uint8_t *serialized; struct LP_transaction *tx; - printf("electrum_transaction %s %s\n",symbol,bits256_str(str,txid)); + //printf("electrum_transaction %s %s\n",symbol,bits256_str(str,txid)); if ( bits256_nonz(txid) != 0 && (coin= LP_coinfind(symbol)) != 0 ) { if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) @@ -579,21 +579,23 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso serialized = malloc(len); decode_hex(serialized,len,hexstr+1); free(hexstr); - printf("DATA.(%s) from (%s)\n",hexstr+1,jprint(hexjson,0)); + //printf("DATA.(%s) from (%s)\n",hexstr+1,jprint(hexjson,0)); + txobj = LP_transaction_fromdata(coin,txid,serialized,len); if ( (tx= LP_transactionfind(coin,txid)) == 0 || tx->serialized == 0 ) { - txobj = LP_transactioninit(coin,txid,0,LP_transaction_fromdata(coin,txid,serialized,len)); + txobj = LP_transactioninit(coin,txid,0,txobj); LP_transactioninit(coin,txid,1,txobj); - if ( (tx= LP_transactionfind(coin,txid)) != 0 ) - { - tx->serialized = serialized; - tx->len = len; - } - else - { - printf("unexpected couldnt find tx %s %s\n",coin->symbol,bits256_str(str,txid)); - free(serialized); - } + tx = LP_transactionfind(coin,txid); + } + if ( tx != 0 ) + { + tx->serialized = serialized; + tx->len = len; + } + else + { + printf("unexpected couldnt find tx %s %s\n",coin->symbol,bits256_str(str,txid)); + free(serialized); } *retjsonp = txobj; free_json(hexjson); From f2b93ce4a9236d4231cfe5ae119368d7554d02d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:21:45 +0300 Subject: [PATCH 483/520] Test --- iguana/exchanges/LP_socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 365e7ba3f..3e3a05765 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -533,7 +533,7 @@ cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *se extraspace = calloc(1,1000000); memset(&msgtx,0,sizeof(msgtx)); txobj = bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->height,&checktxid,&msgtx,extraspace,1000000,serialized,len,0,0); - printf("TX.(%s) match.%d\n",jprint(txobj,0),bits256_cmp(txid,checktxid)); + //printf("TX.(%s) match.%d\n",jprint(txobj,0),bits256_cmp(txid,checktxid)); free(extraspace); if ( bits256_cmp(txid,checktxid) != 0 ) { @@ -599,7 +599,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso } *retjsonp = txobj; free_json(hexjson); - printf("return from electrum_transaction\n"); + //printf("return from electrum_transaction\n"); return(*retjsonp); } else printf("non-hex tx.(%s)\n",jprint(hexjson,0)); free(hexstr); From 04781e77b7b1e74bd60c180b1709784e3dd3c48e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:26:28 +0300 Subject: [PATCH 484/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 3e3a05765..d0759257d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -552,7 +552,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso { if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) { - char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); + //char str[65]; printf("%s cache hit -> TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); if ( (txobj= LP_transaction_fromdata(coin,txid,tx->serialized,tx->len)) != 0 ) { *retjsonp = txobj; From f9638cfa35f8bfdd4a8fd2788490e0671da51a65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:42:09 +0300 Subject: [PATCH 485/520] #!/bin/bash --- iguana/exchanges/autofill | 1 + iguana/exchanges/autoprice | 1 + iguana/exchanges/autotrade | 1 + iguana/exchanges/balance_loop | 1 + iguana/exchanges/bestfit | 1 + iguana/exchanges/buy | 1 + iguana/exchanges/cancelorder | 1 + iguana/exchanges/client | 1 + iguana/exchanges/client_osx | 1 + iguana/exchanges/debug | 1 + iguana/exchanges/deletemessages | 1 + iguana/exchanges/disable | 1 + iguana/exchanges/dividends | 1 + iguana/exchanges/electrum | 1 + iguana/exchanges/electrum.chips | 1 + iguana/exchanges/electrum.chips2 | 1 + iguana/exchanges/electrum.kmd | 1 + iguana/exchanges/electrum.kmd2 | 1 + iguana/exchanges/electrum.kmd3 | 1 + iguana/exchanges/electrums | 1 + iguana/exchanges/enable | 1 + iguana/exchanges/getcoin | 1 + iguana/exchanges/getcoins | 1 + iguana/exchanges/getmessages | 1 + iguana/exchanges/getpeers | 1 + iguana/exchanges/getpeersIP | 1 + iguana/exchanges/getprices | 1 + iguana/exchanges/getutxos | 1 + iguana/exchanges/goal | 1 + iguana/exchanges/goals | 1 + iguana/exchanges/help | 1 + iguana/exchanges/install | 1 + iguana/exchanges/inv | 1 + iguana/exchanges/listunspent | 1 + iguana/exchanges/loop | 1 + iguana/exchanges/message | 1 + iguana/exchanges/myprice | 1 + iguana/exchanges/myprices | 1 + iguana/exchanges/numutxos | 1 + iguana/exchanges/orderbook | 1 + iguana/exchanges/ordermatch | 1 + iguana/exchanges/portfolio | 1 + iguana/exchanges/pricearray | 1 + iguana/exchanges/pub | 1 + iguana/exchanges/register | 1 + iguana/exchanges/registerall | 1 + iguana/exchanges/run | 1 + iguana/exchanges/run_osx | 1 + iguana/exchanges/secretaddresses | 1 + iguana/exchanges/sell | 1 + iguana/exchanges/setprice | 1 + iguana/exchanges/snapshot | 1 + iguana/exchanges/snapshot_balance | 1 + iguana/exchanges/snapshot_loop | 1 + iguana/exchanges/status | 1 + iguana/exchanges/swapstatus | 1 + iguana/exchanges/trade | 1 + iguana/exchanges/utxos | 1 + 58 files changed, 58 insertions(+) diff --git a/iguana/exchanges/autofill b/iguana/exchanges/autofill index f05962ea7..b0724a9db 100755 --- a/iguana/exchanges/autofill +++ b/iguana/exchanges/autofill @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autofill\",\"base\":\"KMD\",\"rel\":\"BTC\",\"price\":0.0005,\"relvolume\":0.1}" diff --git a/iguana/exchanges/autoprice b/iguana/exchanges/autoprice index b709aa0e4..a95a3f5e3 100755 --- a/iguana/exchanges/autoprice +++ b/iguana/exchanges/autoprice @@ -1,3 +1,4 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTC\",\"margin\":0.0001}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTC\",\"rel\":\"KMD\",\"margin\":0.0001}" diff --git a/iguana/exchanges/autotrade b/iguana/exchanges/autotrade index 0ea5e5f11..72e14f84a 100755 --- a/iguana/exchanges/autotrade +++ b/iguana/exchanges/autotrade @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autotrade\",\"base\":\"REVS\",\"rel\":\"KMD\",\"relvolume\":1.01,\"price\":1.234}" diff --git a/iguana/exchanges/balance_loop b/iguana/exchanges/balance_loop index 8a75e0e22..ad28ac741 100755 --- a/iguana/exchanges/balance_loop +++ b/iguana/exchanges/balance_loop @@ -1,3 +1,4 @@ +#!/bin/bash source userpass ht=$1 while true diff --git a/iguana/exchanges/bestfit b/iguana/exchanges/bestfit index c926713ff..bae6a79ac 100755 --- a/iguana/exchanges/bestfit +++ b/iguana/exchanges/bestfit @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"bestfit\",\"rel\":\"KMD\",\"relvolume\":1.01}" diff --git a/iguana/exchanges/buy b/iguana/exchanges/buy index 4bed65f19..cf83a91df 100755 --- a/iguana/exchanges/buy +++ b/iguana/exchanges/buy @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"buy\",\"base\":\"KMD\",\"rel\":\"BTC\",\"relvolume\":0.005,\"price\":0.0005}" diff --git a/iguana/exchanges/cancelorder b/iguana/exchanges/cancelorder index 78394c4c7..31fe7ea8c 100755 --- a/iguana/exchanges/cancelorder +++ b/iguana/exchanges/cancelorder @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"REVS\",\"rel\":\"KMD\",\"price\":9999999.99}" diff --git a/iguana/exchanges/client b/iguana/exchanges/client index 8b3f8a7ba..a36758376 100755 --- a/iguana/exchanges/client +++ b/iguana/exchanges/client @@ -1,3 +1,4 @@ +#!/bin/bash source passphrase source coins pkill -15 marketmaker; diff --git a/iguana/exchanges/client_osx b/iguana/exchanges/client_osx index 9e1cada67..463a08eb4 100755 --- a/iguana/exchanges/client_osx +++ b/iguana/exchanges/client_osx @@ -1,3 +1,4 @@ +#!/bin/bash source passphrase source coins pkill -15 marketmaker; diff --git a/iguana/exchanges/debug b/iguana/exchanges/debug index 02017001a..a4f2297a3 100755 --- a/iguana/exchanges/debug +++ b/iguana/exchanges/debug @@ -1,3 +1,4 @@ +#!/bin/bash source passphrase source coins pkill -15 marketmaker; diff --git a/iguana/exchanges/deletemessages b/iguana/exchanges/deletemessages index a65985a7e..5aba784a4 100755 --- a/iguana/exchanges/deletemessages +++ b/iguana/exchanges/deletemessages @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"deletemessages\",\"firsti\":0,\"num\":10}" diff --git a/iguana/exchanges/disable b/iguana/exchanges/disable index e32c24a6f..636fc952f 100755 --- a/iguana/exchanges/disable +++ b/iguana/exchanges/disable @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"disable\",\"coin\":\"REVS\"}" diff --git a/iguana/exchanges/dividends b/iguana/exchanges/dividends index c5b2ac714..5385b9454 100755 --- a/iguana/exchanges/dividends +++ b/iguana/exchanges/dividends @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"dividends\",\"coin\":\"KMD\",\"height\":$1,\"prefix\":\"fiat/jumblr sendtoaddress\",\"suffix\":\"\",\"dividend\":50000,\"dust\":1}" diff --git a/iguana/exchanges/electrum b/iguana/exchanges/electrum index e7f562b41..375d3d8f4 100755 --- a/iguana/exchanges/electrum +++ b/iguana/exchanges/electrum @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"173.212.225.176\",\"port\":50001}" diff --git a/iguana/exchanges/electrum.chips b/iguana/exchanges/electrum.chips index be36abd88..f5cd61e8c 100755 --- a/iguana/exchanges/electrum.chips +++ b/iguana/exchanges/electrum.chips @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CHIPS\",\"ipaddr\":\"173.212.225.176\",\"port\":50076}" diff --git a/iguana/exchanges/electrum.chips2 b/iguana/exchanges/electrum.chips2 index 72e3f2f70..2be709e78 100755 --- a/iguana/exchanges/electrum.chips2 +++ b/iguana/exchanges/electrum.chips2 @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"CHIPS\",\"ipaddr\":\"136.243.45.140\",\"port\":50076}" diff --git a/iguana/exchanges/electrum.kmd b/iguana/exchanges/electrum.kmd index 747fba203..865205062 100755 --- a/iguana/exchanges/electrum.kmd +++ b/iguana/exchanges/electrum.kmd @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"96.44.166.176\",\"port\":8777}" diff --git a/iguana/exchanges/electrum.kmd2 b/iguana/exchanges/electrum.kmd2 index 46b11276b..40bd30c93 100755 --- a/iguana/exchanges/electrum.kmd2 +++ b/iguana/exchanges/electrum.kmd2 @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"173.212.225.176\",\"port\":50011}" diff --git a/iguana/exchanges/electrum.kmd3 b/iguana/exchanges/electrum.kmd3 index 5fb7a6b9a..4bf1a6c10 100755 --- a/iguana/exchanges/electrum.kmd3 +++ b/iguana/exchanges/electrum.kmd3 @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"136.243.45.140\",\"port\":50011}" diff --git a/iguana/exchanges/electrums b/iguana/exchanges/electrums index 43b4d8811..a4cabe5e3 100755 --- a/iguana/exchanges/electrums +++ b/iguana/exchanges/electrums @@ -1,3 +1,4 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"REVS\",\"ipaddr\":\"173.212.225.176\",\"port\":50050}" diff --git a/iguana/exchanges/enable b/iguana/exchanges/enable index c4b2a56e3..d6a287b3a 100755 --- a/iguana/exchanges/enable +++ b/iguana/exchanges/enable @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"REVS\"}" diff --git a/iguana/exchanges/getcoin b/iguana/exchanges/getcoin index 063185f57..b37ccc666 100755 --- a/iguana/exchanges/getcoin +++ b/iguana/exchanges/getcoin @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getcoin\",\"coin\":\"LTC\"}" diff --git a/iguana/exchanges/getcoins b/iguana/exchanges/getcoins index 71778acfb..64b1d7461 100755 --- a/iguana/exchanges/getcoins +++ b/iguana/exchanges/getcoins @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getcoins\"}" diff --git a/iguana/exchanges/getmessages b/iguana/exchanges/getmessages index 0bfadf518..121e8ec0b 100755 --- a/iguana/exchanges/getmessages +++ b/iguana/exchanges/getmessages @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getmessages\",\"firsti\":0,\"num\":10}" diff --git a/iguana/exchanges/getpeers b/iguana/exchanges/getpeers index ea91cb791..9ed1daf77 100755 --- a/iguana/exchanges/getpeers +++ b/iguana/exchanges/getpeers @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getpeers\"}" diff --git a/iguana/exchanges/getpeersIP b/iguana/exchanges/getpeersIP index c5a7fdd74..7c532e609 100755 --- a/iguana/exchanges/getpeersIP +++ b/iguana/exchanges/getpeersIP @@ -1,3 +1,4 @@ +#!/bin/bash curl --url "http://5.9.253.195:7783" --data "{\"method\":\"getpeers\"}" curl --url "http://5.9.253.196:7783" --data "{\"method\":\"getpeers\"}" curl --url "http://5.9.253.197:7783" --data "{\"method\":\"getpeers\"}" diff --git a/iguana/exchanges/getprices b/iguana/exchanges/getprices index 2a0428d1c..57031035c 100755 --- a/iguana/exchanges/getprices +++ b/iguana/exchanges/getprices @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getprices\",\"coin\":\"REVS\"}" diff --git a/iguana/exchanges/getutxos b/iguana/exchanges/getutxos index 38f26f654..4782c9a0a 100755 --- a/iguana/exchanges/getutxos +++ b/iguana/exchanges/getutxos @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getutxos\",\"coin\":\"REVS\"}" diff --git a/iguana/exchanges/goal b/iguana/exchanges/goal index ecfd491e6..74fd1fcda 100755 --- a/iguana/exchanges/goal +++ b/iguana/exchanges/goal @@ -1,3 +1,4 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"goal\",\"coin\":\"KMD\",\"val\":99}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"goal\",\"coin\":\"BTC\",\"val\":10}" diff --git a/iguana/exchanges/goals b/iguana/exchanges/goals index b29e0f49f..22f31bab8 100755 --- a/iguana/exchanges/goals +++ b/iguana/exchanges/goals @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"goal\"}" diff --git a/iguana/exchanges/help b/iguana/exchanges/help index f51f15b8d..a16fa1181 100755 --- a/iguana/exchanges/help +++ b/iguana/exchanges/help @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"help\"}" diff --git a/iguana/exchanges/install b/iguana/exchanges/install index 3b1981f97..a3632447b 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,3 +1,4 @@ +#!/bin/bash cp electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . diff --git a/iguana/exchanges/inv b/iguana/exchanges/inv index bdd1d58c1..a42ac5d51 100755 --- a/iguana/exchanges/inv +++ b/iguana/exchanges/inv @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"REVS\"}" diff --git a/iguana/exchanges/listunspent b/iguana/exchanges/listunspent index 98c5b137d..aa7ca4963 100755 --- a/iguana/exchanges/listunspent +++ b/iguana/exchanges/listunspent @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"listunspent\",\"coin\":\"BTC\",\"address\":\"1DPDsPCNNCF5SHhPPrddXcJe78rM6CBcH3\"}" diff --git a/iguana/exchanges/loop b/iguana/exchanges/loop index 43228b96e..2ad08f45b 100755 --- a/iguana/exchanges/loop +++ b/iguana/exchanges/loop @@ -1,3 +1,4 @@ +#!/bin/bash while true do source userpass diff --git a/iguana/exchanges/message b/iguana/exchanges/message index 0182aa093..f36c45c81 100755 --- a/iguana/exchanges/message +++ b/iguana/exchanges/message @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"$1\",\"method\":\"sendmessage\",\"message\":\"some sort of message\"}" diff --git a/iguana/exchanges/myprice b/iguana/exchanges/myprice index 8080023ed..6dfac2dbb 100755 --- a/iguana/exchanges/myprice +++ b/iguana/exchanges/myprice @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"myprice\",\"base\":\"REVS\",\"rel\":\"KMD\"}" diff --git a/iguana/exchanges/myprices b/iguana/exchanges/myprices index 3fef298b2..1c82512c0 100755 --- a/iguana/exchanges/myprices +++ b/iguana/exchanges/myprices @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"myprices\"}" diff --git a/iguana/exchanges/numutxos b/iguana/exchanges/numutxos index f8d921078..9455dd239 100755 --- a/iguana/exchanges/numutxos +++ b/iguana/exchanges/numutxos @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"numutxos\"}" diff --git a/iguana/exchanges/orderbook b/iguana/exchanges/orderbook index 8ca15bc87..0f6e553b4 100755 --- a/iguana/exchanges/orderbook +++ b/iguana/exchanges/orderbook @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"JUMBLR\",\"rel\":\"KMD\"}" diff --git a/iguana/exchanges/ordermatch b/iguana/exchanges/ordermatch index 85c74cfea..f4b2ca61c 100755 --- a/iguana/exchanges/ordermatch +++ b/iguana/exchanges/ordermatch @@ -1,3 +1,4 @@ +#!/bin/bash source userpass #ordermatch(base, txfee=0, rel, desttxfee=0, price, txid, vout, feetxid, feevout, duration=3600)\n\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"ordermatch\",\"base\":\"REVS\",\"rel\":\"KMD\",\"price\":1.234,\"duration\":600,\"txfee\":0,\"desttxfee\":0,\"txid\":\"$1\",\"vout\":$2,\"feetxid\":\"$3\",\"feevout\":$4}" diff --git a/iguana/exchanges/portfolio b/iguana/exchanges/portfolio index 92bd9f236..b22adbc06 100755 --- a/iguana/exchanges/portfolio +++ b/iguana/exchanges/portfolio @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"portfolio\"}" diff --git a/iguana/exchanges/pricearray b/iguana/exchanges/pricearray index f39ab51ae..dc812dba6 100755 --- a/iguana/exchanges/pricearray +++ b/iguana/exchanges/pricearray @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"pricearray\",\"base\":\"KMD\",\"rel\":\"BTC\",\"timescale\":60}" diff --git a/iguana/exchanges/pub b/iguana/exchanges/pub index 8d9712607..2e3241fee 100755 --- a/iguana/exchanges/pub +++ b/iguana/exchanges/pub @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"pubkey\":\"6578099f6474d9b8bd66a7a136b922029a989818ec0309aee962dd6ac1862b74\",\"method\":\"forward\",\"method2\":\"publish\",\"data\":\"nonsense\"}" diff --git a/iguana/exchanges/register b/iguana/exchanges/register index ca64e4ace..d00160beb 100755 --- a/iguana/exchanges/register +++ b/iguana/exchanges/register @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://5.9.253.195:7783" --data "{\"userpass\":\"9bb4846d24136fc7c33515e45bccbab5c8fb7b57b411aa20057b371da9358255\",\"agent\":\"stats\",\"method\":\"register\",\"client\":\"6d3332be4904feafd326609bd76b66528dc7b2e2d75a7bd110c6bf8d19c4cf58\",\"pushaddr\":\"5.9.253.195\",\"pushport\":\"10000\"}" diff --git a/iguana/exchanges/registerall b/iguana/exchanges/registerall index b3cfe5f06..927f0b2f9 100755 --- a/iguana/exchanges/registerall +++ b/iguana/exchanges/registerall @@ -1,3 +1,4 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"registerall\",\"numnodes\":10}" diff --git a/iguana/exchanges/run b/iguana/exchanges/run index 59e4ec2e4..ec549c0c7 100755 --- a/iguana/exchanges/run +++ b/iguana/exchanges/run @@ -1,3 +1,4 @@ +#!/bin/bash source passphrase source coins pkill -15 marketmaker; diff --git a/iguana/exchanges/run_osx b/iguana/exchanges/run_osx index c8924d6f4..970217843 100755 --- a/iguana/exchanges/run_osx +++ b/iguana/exchanges/run_osx @@ -1,3 +1,4 @@ +#!/bin/bash source passphrase source coins pkill -15 marketmaker; diff --git a/iguana/exchanges/secretaddresses b/iguana/exchanges/secretaddresses index a2d6ba2d2..29ebd0041 100755 --- a/iguana/exchanges/secretaddresses +++ b/iguana/exchanges/secretaddresses @@ -1,3 +1,4 @@ +#!/bin/bash source userpass echo "usage: ./secretaddresses 'passphrase'" diff --git a/iguana/exchanges/sell b/iguana/exchanges/sell index 5f48ff299..6410148c8 100755 --- a/iguana/exchanges/sell +++ b/iguana/exchanges/sell @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sell\",\"base\":\"KMD\",\"rel\":\"BTC\",\"basevolume\":10.0\"price\":0.0005}" diff --git a/iguana/exchanges/setprice b/iguana/exchanges/setprice index 0909118fb..40b88e0a5 100755 --- a/iguana/exchanges/setprice +++ b/iguana/exchanges/setprice @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"setprice\",\"base\":\"REVS\",\"rel\":\"KMD\",\"price\":1.234}" diff --git a/iguana/exchanges/snapshot b/iguana/exchanges/snapshot index e9056f1cf..75a0a60aa 100755 --- a/iguana/exchanges/snapshot +++ b/iguana/exchanges/snapshot @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\",\"height\":$1}" diff --git a/iguana/exchanges/snapshot_balance b/iguana/exchanges/snapshot_balance index 88b0f9823..b66f1a9e4 100644 --- a/iguana/exchanges/snapshot_balance +++ b/iguana/exchanges/snapshot_balance @@ -1,3 +1,4 @@ +#!/bin/bash source userpass ht=$1 curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot_balance\",\"coin\":\"KMD\",\"height\":$ht,\"addresses\":[\"RSAzPFzgTZHNcxLNLdGyVPbjbMA8PRY7Ss\", \"RBgD5eMGwZppid4x7PTEC2Wg1AzvxbsQqB\"]}" diff --git a/iguana/exchanges/snapshot_loop b/iguana/exchanges/snapshot_loop index 38a0c3156..05bedaa82 100755 --- a/iguana/exchanges/snapshot_loop +++ b/iguana/exchanges/snapshot_loop @@ -1,3 +1,4 @@ +#!/bin/bash source userpass ht=$1 while true diff --git a/iguana/exchanges/status b/iguana/exchanges/status index a05aa72ee..0499bba6b 100755 --- a/iguana/exchanges/status +++ b/iguana/exchanges/status @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"swapstatus\"}" diff --git a/iguana/exchanges/swapstatus b/iguana/exchanges/swapstatus index ce9dbbed0..abc6dbb64 100755 --- a/iguana/exchanges/swapstatus +++ b/iguana/exchanges/swapstatus @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"swapstatus\",\"requestid\":2291973695,\"quoteid\":3387529385}" diff --git a/iguana/exchanges/trade b/iguana/exchanges/trade index 155de037a..1bad74aa9 100755 --- a/iguana/exchanges/trade +++ b/iguana/exchanges/trade @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"trade\",\"price\":1.234,\"base\":\"REVS\",\"rel\":\"KMD\",\"quote\":{}}" diff --git a/iguana/exchanges/utxos b/iguana/exchanges/utxos index 38f26f654..4782c9a0a 100755 --- a/iguana/exchanges/utxos +++ b/iguana/exchanges/utxos @@ -1,2 +1,3 @@ +#!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getutxos\",\"coin\":\"REVS\"}" From aa08f922c65d423450dd80251ce04ffb64ab3531 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 13:46:13 +0300 Subject: [PATCH 486/520] Test --- iguana/exchanges/LP_ordermatch.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index ef3cefd06..940b0b4bc 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -284,13 +284,19 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str { if (LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) { - printf("bob not eligible\n"); + printf("bob not eligible %s\n",jprint(LP_quotejson(qp),1)); return(-2); } if ( bits256_cmp(butxo->deposit.txid,qp->txid2) != 0 || butxo->deposit.vout != qp->vout2 ) + { + char str[65],str2[65]; printf("%s != %s v%d != %d\n",bits256_str(str,butxo->deposit.txid),bits256_str(str2,qp->txid2),butxo->deposit.vout,qp->vout2); return(-6); + } if ( strcmp(butxo->coinaddr,qp->coinaddr) != 0 ) + { + printf("(%s) != (%s)\n",butxo->coinaddr,qp->coinaddr); return(-7); + } } if ( autxo != 0 && LP_iseligible(&destvalue,&destvalue2,0,qp->destcoin,qp->desttxid,qp->destvout,qp->destsatoshis,qp->feetxid,qp->feevout) == 0 ) { From b495c46421b1ce9e1fc76980fccc3bbbe93d15ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 14:03:24 +0300 Subject: [PATCH 487/520] Test --- iguana/exchanges/LP_ordermatch.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 940b0b4bc..028661339 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -779,7 +779,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, value2 = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid2,Q.vout2); butxo = LP_utxoadd(1,Q.srccoin,Q.txid,Q.vout,value,Q.txid2,Q.vout2,value2,Q.coinaddr,Q.srchash,LP_gui,0); } - printf("butxo.%p TRADECOMMAND.(%s)\n",butxo,jprint(argjson,0)); + char str[65],str2[65]; printf("butxo.%p (%s %s) TRADECOMMAND.(%s)\n",butxo,butxo!=0?bits256_str(str,butxo->payment.txid):"",butxo!=0?bits256_str(str2,butxo->deposit.txid):"",jprint(argjson,0)); if ( butxo == 0 || bits256_nonz(butxo->payment.txid) == 0 || bits256_nonz(butxo->deposit.txid) == 0 || butxo->payment.vout < 0 || butxo->deposit.vout < 0 ) { char str[65],str2[65]; printf("couldnt find bob utxos for autxo %s/v%d %s/v%d %.8f -> %.8f\n",bits256_str(str,Q.txid),Q.vout,bits256_str(str2,Q.txid2),Q.vout2,dstr(Q.satoshis),dstr(Q.destsatoshis)); @@ -855,7 +855,7 @@ char *LP_bestfit(char *rel,double relvolume) char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *qp,double maxprice,int32_t timeout,int32_t duration) { - struct LP_utxoinfo *aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; + struct LP_utxoinfo *aliceutxo; cJSON *bestitem=0; int32_t DEXselector=0; uint32_t expiration; double price; struct LP_pubkeyinfo *pubp; struct basilisk_swap *swap; if ( (aliceutxo= LP_utxopairfind(0,qp->desttxid,qp->destvout,qp->feetxid,qp->feevout)) == 0 ) { char str[65],str2[65]; printf("dest.(%s)/v%d fee.(%s)/v%d\n",bits256_str(str,qp->desttxid),qp->destvout,bits256_str(str2,qp->feetxid),qp->feevout); @@ -876,17 +876,21 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q break; sleep(3); } - if ( aliceutxo->S.swap == 0 ) + jaddnum(bestitem,"quotedprice",price); + jaddnum(bestitem,"maxprice",maxprice); + if ( (swap= aliceutxo->S.swap) == 0 ) { if ( (pubp= LP_pubkeyadd(qp->srchash)) != 0 ) pubp->numerrors++; jaddstr(bestitem,"status","couldnt establish connection"); - } else jaddstr(bestitem,"status","connected"); - jaddnum(bestitem,"quotedprice",price); - jaddnum(bestitem,"maxprice",maxprice); - jaddnum(bestitem,"requestid",qp->R.requestid); - jaddnum(bestitem,"quoteid",qp->R.quoteid); - printf("Alice r.%u qp->%u\n",qp->R.requestid,qp->R.quoteid); + } + else + { + jaddstr(bestitem,"status","connected"); + jaddnum(bestitem,"requestid",swap->I.req.requestid); + jaddnum(bestitem,"quoteid",swap->I.req.quoteid); + printf("Alice r.%u qp->%u\n",swap->I.req.requestid,swap->I.req.quoteid); + } } else { From 8e1d1f0a0912b37c1834ff75ce231cc171f6edfb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 14:19:15 +0300 Subject: [PATCH 488/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 028661339..0fa47c237 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -464,7 +464,7 @@ uint64_t LP_basesatoshis(double relvolume,double price,uint64_t txfee,uint64_t d { printf("basesatoshis %.8f (rel %.8f / price %.8f)\n",dstr(SATOSHIDEN * ((relvolume) / price) + 2*txfee),relvolume,price); if ( relvolume > dstr(desttxfee) && price > SMALLVAL ) - return(SATOSHIDEN * (relvolume / price) + txfee); + return(SATOSHIDEN * (relvolume / price) + 2*txfee); else return(0); } From a5969147fe7aa790c4d8545629f8dd0988bddc5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 16:59:58 +0300 Subject: [PATCH 489/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index d0759257d..c3b4ede4d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -605,7 +605,7 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso free(hexstr); free_json(hexjson); } - *retjsonp = cJSON_Parse("{\"error\":\"null txid\"}"); + *retjsonp = 0; return(*retjsonp); } From aea3d93920f9800ef8cee742f04a3870b0339a06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:07:28 +0300 Subject: [PATCH 490/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e98fd497a..fbd875dd5 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -506,7 +506,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri txfee = LP_txfeecalc(coin,0); if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - //printf("%s %s\n",coin->symbol,jprint(array,0)); + printf("LP_privkey_init %s %s\n",coin->symbol,jprint(array,0)); for (iambob=0; iambob<=1; iambob++) { if ( iambob == 0 ) From 5fc86e18a9ab35628e9d82a042504bb8f6401134 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:10:10 +0300 Subject: [PATCH 491/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index c3b4ede4d..c0855ab41 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -505,7 +505,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,ep,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); From e96941c0770de1f7b79bd575091b675640880dfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:12:35 +0300 Subject: [PATCH 492/520] Test --- iguana/exchanges/LP_utxos.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index fbd875dd5..a1fe1800c 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -501,6 +501,8 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri return(0); } //printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr); + if ( coin->inactive == 0 ) + LP_listunspent_issue(coin->symbol,coin->smartaddr); if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) { txfee = LP_txfeecalc(coin,0); From 4897ac61a0b048136f82e9fe752bad965bc0bedc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:14:40 +0300 Subject: [PATCH 493/520] Test --- iguana/exchanges/LP_commands.c | 1 + iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index bb7d1e49b..b52500832 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -303,6 +303,7 @@ dividends(coin, height, )\n\ //LP_utxopurge(0); if ( bits256_nonz(G.LP_mypriv25519) != 0 ) LP_privkey_init(-1,ptr,G.LP_mypriv25519,G.LP_mypub25519); + else printf("no LP_mypriv25519\n"); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddstr(retjson,"coin",coin); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index a1fe1800c..7a52aaefc 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -500,7 +500,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri printf("coin not active\n"); return(0); } - //printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr); + printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr); if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) From 6fffc5232db8069f48468df4b687d46738ae6a07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:16:34 +0300 Subject: [PATCH 494/520] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 7a52aaefc..d3303a259 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -495,7 +495,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri { int32_t enable_utxos = 0; char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,flag=0,height,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; - if ( coin == 0 ) + if ( coin == 0 || coin->inactive != 0 ) { printf("coin not active\n"); return(0); From d273e99876b835d0e74f42401b99fef514544786 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:22:52 +0300 Subject: [PATCH 495/520] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxos.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index c0855ab41..c3b4ede4d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -505,7 +505,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { - printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + //printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); if ( electrum_process_array(coin,ep,addr,retjson) != 0 ) LP_postutxos(coin->symbol,addr); safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent)); diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index d3303a259..9f975ca4f 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -500,7 +500,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri printf("coin not active\n"); return(0); } - printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr); + //printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr); if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 ) @@ -508,7 +508,7 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri txfee = LP_txfeecalc(coin,0); if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { - printf("LP_privkey_init %s %s\n",coin->symbol,jprint(array,0)); + //printf("LP_privkey_init %s %s\n",coin->symbol,jprint(array,0)); for (iambob=0; iambob<=1; iambob++) { if ( iambob == 0 ) From 108ab2019f1eb6c21f60e4b8ade789369e4cf121 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 17:46:26 +0300 Subject: [PATCH 496/520] Test --- iguana/exchanges/LP_ordermatch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0fa47c237..e719ea9e6 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -748,6 +748,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, memset(autxo,0,sizeof(*autxo)); memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(autxo,butxo,&Q); + if ( (butxo= LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) + butxo = &B; //LP_butxo_swapfields(butxo); if ( strcmp(method,"request") == 0 ) { @@ -770,9 +772,10 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else { printf("other path %p %p %.8f\n",LP_allocated(butxo->payment.txid,butxo->payment.vout),LP_allocated(butxo->deposit.txid,butxo->deposit.vout), LP_quote_validate(autxo,butxo,&Q,1)); - butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); } - } else butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); + } + if ( butxo == 0 || butxo == &B ) + butxo = LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2); if ( butxo == 0 ) { value = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid,Q.vout); From c5954cf6ad6d95e070d1d1c24ca9e747754dd1fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 18:01:46 +0300 Subject: [PATCH 497/520] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_portfolio.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e15ab19b5..15a821f18 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -319,7 +319,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr; HASH_ITER(hh,LP_coins,coin,ctmp) { - if ( coin->inactive != 0 || coin->obooktime == 0 ) + if ( coin->inactive != 0 || (coin->electrum != 0 && coin->obooktime == 0) ) continue; total = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); @@ -478,8 +478,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; if ( coin->electrum != 0 ) continue; - if ( coin->obooktime == 0 ) - continue; + //if ( coin->obooktime == 0 ) + // continue; if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { if ( (height= LP_getheight(coin)) > coin->longestchain ) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index e648e3381..b328e8138 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -89,7 +89,7 @@ char *LP_portfolio() { HASH_ITER(hh,LP_coins,coin,tmp) { - if ( coin->inactive != 0 || coin->obooktime == 0 ) + if ( coin->inactive != 0 || (coin->electrum != 0 && coin->obooktime == 0) ) continue; if ( iter == 0 ) { From 629677ebad611d10406c81b01e4ec362b3be05f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 18:09:23 +0300 Subject: [PATCH 498/520] Test --- iguana/exchanges/LP_scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 006b4b6cf..23e76098e 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -497,8 +497,8 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int break; sleep(10); } - if ( numconfirms <= 0 ) - numconfirms = LP_numconfirms(symbol,coinaddr,txid,vout,1); + //if ( numconfirms <= 0 ) + // numconfirms = LP_numconfirms(symbol,coinaddr,txid,vout,1); // no, no recursion occurs! return(numconfirms); } From 6078af69a2ffd14064714e95b9c818b752c7ddfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 18:22:58 +0300 Subject: [PATCH 499/520] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_ordermatch.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b52500832..615976163 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -385,7 +385,7 @@ dividends(coin, height, )\n\ } else if ( strcmp(method,"connected") == 0 ) { - printf("CONNECTED.(%s)\n",jprint(argjson,0)); + //printf("CONNECTED.(%s)\n",jprint(argjson,0)); retstr = LP_connectedalice(argjson); } else if ( strcmp(method,"checktxid") == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index e719ea9e6..a192b195b 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -594,7 +594,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; uint64_t value,value2; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,B,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; uint64_t value,value2; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) @@ -610,8 +610,12 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("cant find autxo\n"); return(clonestr("{\"error\":\"cant find autxo\"}")); } - //LP_abutxo_set(autxo,0,&Q); - if ( (butxo= LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) + if ( autxo->S.swap != 0 ) + return(clonestr("{\"error\":\"ignore duplicate swap\"}")); + butxo = &B; + memset(butxo,0,sizeof(*butxo)); + LP_abutxo_set(0,butxo,&Q); + /*if ( (butxo= LP_utxopairfind(1,Q.txid,Q.vout,Q.txid2,Q.vout2)) == 0 ) { value = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid,Q.vout); value2 = LP_txvalue(Q.coinaddr,Q.srccoin,Q.txid2,Q.vout2); @@ -630,7 +634,7 @@ char *LP_connectedalice(cJSON *argjson) // alice printf("butxo value %.8f less satoshis %.8f\n",dstr(value),dstr(Q.satoshis)); return(clonestr("{\"error\":\"butxo value less than satoshis\"}")); } - } + }*/ if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); From 3334759043caad8f32776f52f4c50ce580036537 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 18:47:50 +0300 Subject: [PATCH 500/520] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxo.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index a192b195b..a3570d889 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -594,7 +594,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,struct LP_utxoinfo *utxo,cJ char *LP_connectedalice(cJSON *argjson) // alice { - cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,B,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; uint64_t value,value2; + cJSON *retjson; double bid,ask,price,qprice; int32_t pairsock = -1; char *pairstr; int32_t DEXselector = 0; struct LP_utxoinfo *autxo,B,*butxo; struct LP_quoteinfo Q; struct basilisk_swap *swap; struct iguana_info *coin; //uint64_t value,value2; if ( LP_quoteparse(&Q,argjson) < 0 ) clonestr("{\"error\":\"cant parse quote\"}"); if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 202af4e49..f16749018 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -601,6 +601,7 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int } else { + LP_listunspent_issue(symbol,coinaddr); if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) numconfirms = (LP_getheight(coin) - ht + 1); else if ( mempool != 0 ) From 7d1a36c5b97b56a4e9f4713315a7733fdd8f7193 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 20:30:13 +0300 Subject: [PATCH 501/520] Balance api --- iguana/exchanges/LP_commands.c | 7 +++++++ iguana/exchanges/LP_utxo.c | 15 +++++++++++++++ iguana/exchanges/balance | 3 +++ 3 files changed, 25 insertions(+) create mode 100755 iguana/exchanges/balance diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 615976163..e76f2c691 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -114,6 +114,7 @@ portfolio()\n\ getpeers()\n\ passphrase(passphrase, gui)\n\ listunspent(coin, address)\n\ +balance(coin, address)\n\ orderbook(base, rel, duration=3600)\n\ getprices(base, rel)\n\ sendmessage(base=coin, rel="", pubkey=zero, )\n\ @@ -374,6 +375,12 @@ dividends(coin, height, )\n\ return(jprint(LP_address_utxos(ptr,jstr(argjson,"address"),1),1)); else return(clonestr("{\"error\":\"cant find coind\"}")); } + else if ( strcmp(method,"balance") == 0 ) + { + if ( (ptr= LP_coinsearch(jstr(argjson,"coin"))) != 0 ) + return(jprint(LP_address_balance(ptr,jstr(argjson,"address"),1),1)); + else return(clonestr("{\"error\":\"cant find coind\"}")); + } else if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 ) return(clonestr("{\"result\":\"at least one of coins disabled\"}")); else if ( IAMLP == 0 && LP_isdisabled(jstr(argjson,"coin"),0) != 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f16749018..fe7040494 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -294,6 +294,21 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum return(array); } +cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electrumret) +{ + cJSON *array,*retjson; double balance = 0.; + if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + { + + } + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"coin",coin->symbol); + jaddstr(retjson,"address",coinaddr); + jaddnum(retjson,"balance",balance); + return(retjson); +} + void LP_postutxos(char *symbol,char *coinaddr) { bits256 zero; char *msg; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); diff --git a/iguana/exchanges/balance b/iguana/exchanges/balance new file mode 100755 index 000000000..4a184f8f4 --- /dev/null +++ b/iguana/exchanges/balance @@ -0,0 +1,3 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"balance\",\"coin\":\"BTC\",\"address\":\"1DPDsPCNNCF5SHhPPrddXcJe78rM6CBcH3\"}" From a6b934d24d64882325034dee551896e6b70ed647 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 20:33:01 +0300 Subject: [PATCH 502/520] Test --- iguana/exchanges/LP_utxo.c | 10 +++++++--- iguana/exchanges/balance | 2 +- iguana/exchanges/install | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fe7040494..ab9219412 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -296,16 +296,20 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electrumret) { - cJSON *array,*retjson; double balance = 0.; + cJSON *array,*retjson; int32_t i,n; uint64_t balance = 0; if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) { - + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; isymbol); jaddstr(retjson,"address",coinaddr); - jaddnum(retjson,"balance",balance); + jaddnum(retjson,"balance",dstr(balance)); return(retjson); } diff --git a/iguana/exchanges/balance b/iguana/exchanges/balance index 4a184f8f4..22f84cdee 100755 --- a/iguana/exchanges/balance +++ b/iguana/exchanges/balance @@ -1,3 +1,3 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"balance\",\"coin\":\"BTC\",\"address\":\"1DPDsPCNNCF5SHhPPrddXcJe78rM6CBcH3\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"balance\",\"coin\":\"KMD\",\"address\":\"RHV2As4rox97BuE3LK96vMeNY8VsGRTmBj\"}" diff --git a/iguana/exchanges/install b/iguana/exchanges/install index a3632447b..3f64033f1 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,5 +1,5 @@ #!/bin/bash -cp electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts +cp balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . #echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir From 941275ecfaef91dd6824511bcce426795739be9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Oct 2017 20:38:32 +0300 Subject: [PATCH 503/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_portfolio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 15a821f18..8fe03c09e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -319,7 +319,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr; HASH_ITER(hh,LP_coins,coin,ctmp) { - if ( coin->inactive != 0 || (coin->electrum != 0 && coin->obooktime == 0) ) + if ( coin->inactive != 0 )//|| (coin->electrum != 0 && coin->obooktime == 0) ) continue; total = 0; LP_listunspent_both(coin->symbol,coin->smartaddr); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index b328e8138..80ce16c7b 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -89,7 +89,7 @@ char *LP_portfolio() { HASH_ITER(hh,LP_coins,coin,tmp) { - if ( coin->inactive != 0 || (coin->electrum != 0 && coin->obooktime == 0) ) + if ( coin->inactive != 0 )//|| (coin->electrum != 0 && coin->obooktime == 0) ) continue; if ( iter == 0 ) { From a4d2a05883ccc1e804f15dd929d7f412d15972d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 3 Oct 2017 19:46:48 +0300 Subject: [PATCH 504/520] Dont use /tmp --- iguana/exchanges/LP_nativeDEX.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8fe03c09e..cddae12d2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -21,14 +21,12 @@ // // new features: // -check for completed one being spent -// make remember remember +// make remember remember or maybe to just fix? // sign, spv check // bittrex balancing -// stats +// withdraw +// stats, fix pricearray // so alice doesnt detect swap complete and electrum doesnt get .finished after swapstatus. ok, seems like an electrum tx construction/detection issue in the swapstatus path and some wonkiness with SWAP complete detection in general. I need to cleanup that logic a lot -// gettxout mempool a few other local network calls -// electrum cache for blockchain.transaction.get -// scan history for electrum after swap // unduplicated bugs: // swap cancel should cleanly cancel @@ -655,9 +653,9 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_messagemutex); portable_mutex_init(&LP_portfoliomutex); portable_mutex_init(&LP_butxomutex); - if ( system("curl -s4 checkip.amazonaws.com > /tmp/myipaddr") == 0 ) + if ( system("curl -s4 checkip.amazonaws.com > DB/myipaddr") == 0 ) { - if ( (myipaddr= OS_filestr(&filesize,"/tmp/myipaddr")) != 0 && myipaddr[0] != 0 ) + if ( (myipaddr= OS_filestr(&filesize,"DB/myipaddr")) != 0 && myipaddr[0] != 0 ) { n = strlen(myipaddr); if ( myipaddr[n-1] == '\n' ) From 8fd398bb42c0b6976c8d2c66687c54f8b4b29c3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 14:38:10 +0300 Subject: [PATCH 505/520] Test --- iguana/exchanges/LP_nativeDEX.c | 4 +++- iguana/exchanges/LP_remember.c | 15 +++++++++------ iguana/exchanges/LP_transaction.c | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cddae12d2..0c43d6503 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -26,7 +26,9 @@ // bittrex balancing // withdraw // stats, fix pricearray -// so alice doesnt detect swap complete and electrum doesnt get .finished after swapstatus. ok, seems like an electrum tx construction/detection issue in the swapstatus path and some wonkiness with SWAP complete detection in general. I need to cleanup that logic a lot +// better error message in ordermatch +// verify portfolio +// alice doesnt detect swap complete and electrum doesnt get .finished after swapstatus. ok, seems like an electrum tx construction/detection issue in the swapstatus path and some wonkiness with SWAP complete detection in general. I need to cleanup that logic a lot // unduplicated bugs: // swap cancel should cleanly cancel diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 74f0f4f53..eefab2383 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -957,9 +957,12 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti Apaymentspent = txids[BASILISK_BOBSPEND]; else Apaymentspent = txids[BASILISK_ALICERECLAIM]; } - bits256_str(str,paymentspent), jaddbits256(item,"paymentspent",paymentspent); - bits256_str(str,Apaymentspent), jaddbits256(item,"Apaymentspent",Apaymentspent); - bits256_str(str,depositspent), jaddbits256(item,"depositspent",depositspent); + jaddbits256(item,"bobdeposit",txids[BASILISK_BOBDEPOSIT]); + jaddbits256(item,"alicepayment",txids[BASILISK_ALICEPAYMENT]); + jaddbits256(item,"bobpayment",txids[BASILISK_BOBPAYMENT]); + jaddbits256(item,"paymentspent",paymentspent); + jaddbits256(item,"Apaymentspent",Apaymentspent); + jaddbits256(item,"depositspent",depositspent); if ( origfinishedflag == 0 && finishedflag != 0 ) { //printf("SWAP %u-%u finished!\n",requestid,quoteid); @@ -1014,7 +1017,7 @@ char *basilisk_swaplist() } jaddstr(retjson,"result","success"); jadd(retjson,"swaps",array); - if ( cJSON_GetArraySize(array) > 0 ) + if ( 0 && cJSON_GetArraySize(array) > 0 ) { totalsobj = cJSON_CreateObject(); for (Btotal=i=0; i 0 ) jaddnum(retjson,"avesell",(double)-Btotal/Ktotal); } - array = cJSON_CreateArray(); - /*for (i=0; ilinfos)/sizeof(*myinfo->linfos); i++) + /*array = cJSON_CreateArray(); + for (i=0; ilinfos)/sizeof(*myinfo->linfos); i++) { if ( myinfo->linfos[i].base[0] != 0 && myinfo->linfos[i].rel[0] != 0 ) jaddi(array,linfo_json(&myinfo->linfos[i])); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 1facc6725..2c8bcff35 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -49,7 +49,10 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi { decode_hex(txid.bytes,32,retstr); if ( bits256_cmp(txid,expectedtxid) == 0 || (bits256_nonz(expectedtxid) == 0 && bits256_nonz(txid) != 0) ) + { sentflag = 1; + expectedtxid = txid; + } } else if ( (retjson= cJSON_Parse(retstr)) != 0 ) { From 66a538e671dde868f45ec39f2c6796e55a300467 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 16:07:19 +0300 Subject: [PATCH 506/520] Test --- iguana/exchanges/LP_remember.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index eefab2383..303d27935 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -921,6 +921,13 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti finishedflag = basilisk_swap_isfinished(iambob,txids,sentflags,paymentspent,Apaymentspent,depositspent); jaddnum(item,"requestid",requestid); jaddnum(item,"quoteid",quoteid); + jaddnum(item,"iambob",iambob); + jaddstr(item,"bob",bob->symbol); + jaddnum(item,"bobamount",dstr(values[BASILISK_BOBPAYMENT])); + jaddnum(item,"bobtxfee",dstr(Btxfee)); + jaddstr(item,"alice",alice->symbol); + jaddnum(item,"aliceamount",dstr(values[BASILISK_ALICEPAYMENT])); + jaddnum(item,"alicetxfee",dstr(Atxfee)); jadd(item,"txs",array); array = cJSON_CreateArray(); for (i=0; i Date: Wed, 4 Oct 2017 19:42:21 +0300 Subject: [PATCH 507/520] Cleanup code --- iguana/exchanges/LP_remember.c | 664 +++++++++++++++++---------------- 1 file changed, 347 insertions(+), 317 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 303d27935..b685b4a98 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -396,99 +396,188 @@ uint32_t LP_extract(uint32_t requestid,uint32_t quoteid,char *rootfname,char *fi return(t); } -cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) +void LP_totals_update(int32_t iambob,char *alicecoin,char *bobcoin,int64_t *KMDtotals,int64_t *BTCtotals,int32_t *sentflags,int64_t *values) // update to handle all coins { - static void *ctx; - FILE *fp; int32_t sentflags[sizeof(txnames)/sizeof(*txnames)],i,n,j,Predeemlen,Dredeemlen,len,needflag,secretstart,redeemlen,addflag,origfinishedflag = 0,finishedflag = 0,iambob = -1; int64_t srcamount,destamount=0,value,values[sizeof(txnames)/sizeof(*txnames)]; uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],pubkey33[33],Predeemscript[1024],Dredeemscript[1024],redeemscript[1024],userdata[1024]; uint32_t plocktime,dlocktime,expiration=0,r,q,state,otherstate; char *secretstr,*srcstr,*deststr,str[65],src[64],dest[64],fname[512],*fstr,*dest33,*rstr,*symbol,*txname,*Adest,*Bdest,*AAdest,*ABdest,destaddr[64],Adestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[64],bobcoin[64],*txbytes[sizeof(txnames)/sizeof(*txnames)]; long fsize; cJSON *txobj,*item,*sentobj,*array; bits256 checktxid,txid,pubA0,pubB0,pubB1,privAm,privBn,paymentspent,Apaymentspent,depositspent,zero,privkey,rev,myprivs[2],txids[sizeof(txnames)/sizeof(*txnames)],signedtxid; struct iguana_info *bob=0,*alice=0; uint64_t Atxfee=0,Btxfee=0; - if ( ctx == 0 ) - ctx = bitcoin_ctx(); - bobpaymentaddr[0] = bobdepositaddr[0] = alicepaymentaddr[0] = 0; - memset(Predeemscript,0,sizeof(Predeemscript)); - memset(Dredeemscript,0,sizeof(Dredeemscript)); - Predeemlen = Dredeemlen = 0; - memset(values,0,sizeof(values)); - memset(txids,0,sizeof(txids)); - memset(secretAm,0,sizeof(secretAm)); - memset(secretAm256,0,sizeof(secretAm256)); - memset(secretBn,0,sizeof(secretBn)); - memset(secretBn256,0,sizeof(secretBn256)); - memset(pubkey33,0,sizeof(pubkey33)); - memset(txbytes,0,sizeof(txbytes)); - memset(sentflags,0,sizeof(sentflags)); - memset(myprivs,0,sizeof(myprivs)); - Apaymentspent = paymentspent = depositspent = rev = zero = pubA0 = pubB0 = pubB1 = privAm = privBn = myprivs[0]; - plocktime = dlocktime = 0; - src[0] = dest[0] = bobcoin[0] = alicecoin[0] = 0; + values[BASILISK_OTHERFEE] = 0; + if ( iambob == 0 ) + { + if ( strcmp(alicecoin,"BTC") == 0 ) + { + BTCtotals[BASILISK_ALICEPAYMENT] -= values[BASILISK_ALICEPAYMENT] * sentflags[BASILISK_ALICEPAYMENT]; + BTCtotals[BASILISK_ALICERECLAIM] += values[BASILISK_ALICEPAYMENT] * sentflags[BASILISK_ALICERECLAIM]; + BTCtotals[BASILISK_MYFEE] -= values[BASILISK_MYFEE] * sentflags[BASILISK_MYFEE]; + } + else if ( strcmp(alicecoin,"KMD") == 0 ) + { + KMDtotals[BASILISK_ALICEPAYMENT] -= values[BASILISK_ALICEPAYMENT] * sentflags[BASILISK_ALICEPAYMENT]; + KMDtotals[BASILISK_ALICERECLAIM] += values[BASILISK_ALICEPAYMENT] * sentflags[BASILISK_ALICERECLAIM]; + KMDtotals[BASILISK_MYFEE] -= values[BASILISK_MYFEE] * sentflags[BASILISK_MYFEE]; + } + if ( strcmp(bobcoin,"KMD") == 0 ) + { + KMDtotals[BASILISK_ALICESPEND] += values[BASILISK_BOBPAYMENT] * sentflags[BASILISK_ALICESPEND]; + KMDtotals[BASILISK_ALICECLAIM] += values[BASILISK_BOBDEPOSIT] * sentflags[BASILISK_ALICECLAIM]; + } + else if ( strcmp(bobcoin,"BTC") == 0 ) + { + BTCtotals[BASILISK_ALICESPEND] += values[BASILISK_BOBPAYMENT] * sentflags[BASILISK_ALICESPEND]; + BTCtotals[BASILISK_ALICECLAIM] += values[BASILISK_BOBDEPOSIT] * sentflags[BASILISK_ALICECLAIM]; + } + } + else + { + if ( strcmp(bobcoin,"BTC") == 0 ) + { + BTCtotals[BASILISK_BOBPAYMENT] -= values[BASILISK_BOBPAYMENT] * sentflags[BASILISK_BOBPAYMENT]; + BTCtotals[BASILISK_BOBDEPOSIT] -= values[BASILISK_BOBDEPOSIT] * sentflags[BASILISK_BOBDEPOSIT]; + BTCtotals[BASILISK_BOBREFUND] += values[BASILISK_BOBREFUND] * sentflags[BASILISK_BOBREFUND]; + BTCtotals[BASILISK_BOBRECLAIM] += values[BASILISK_BOBRECLAIM] * sentflags[BASILISK_BOBRECLAIM]; + BTCtotals[BASILISK_MYFEE] -= values[BASILISK_MYFEE] * sentflags[BASILISK_MYFEE]; + } + else if ( strcmp(bobcoin,"KMD") == 0 ) + { + KMDtotals[BASILISK_BOBPAYMENT] -= values[BASILISK_BOBPAYMENT] * sentflags[BASILISK_BOBPAYMENT]; + KMDtotals[BASILISK_BOBDEPOSIT] -= values[BASILISK_BOBDEPOSIT] * sentflags[BASILISK_BOBDEPOSIT]; + KMDtotals[BASILISK_BOBREFUND] += values[BASILISK_BOBDEPOSIT] * sentflags[BASILISK_BOBREFUND]; + KMDtotals[BASILISK_BOBRECLAIM] += values[BASILISK_BOBPAYMENT] * sentflags[BASILISK_BOBRECLAIM]; + KMDtotals[BASILISK_MYFEE] -= values[BASILISK_MYFEE] * sentflags[BASILISK_MYFEE]; + } + if ( strcmp(alicecoin,"KMD") == 0 ) + { + KMDtotals[BASILISK_BOBSPEND] += values[BASILISK_BOBSPEND] * sentflags[BASILISK_BOBSPEND]; + } + else if ( strcmp(alicecoin,"BTC") == 0 ) + { + BTCtotals[BASILISK_BOBSPEND] += values[BASILISK_ALICEPAYMENT] * sentflags[BASILISK_BOBSPEND]; + } + } +} + +struct LP_swap_remember +{ + bits256 pubA0,pubB0,pubB1,privAm,privBn,paymentspent,Apaymentspent,depositspent,myprivs[2],txids[sizeof(txnames)/sizeof(*txnames)]; + uint64_t Atxfee,Btxfee,srcamount,destamount; int64_t values[sizeof(txnames)/sizeof(*txnames)]; + uint32_t requestid,quoteid,plocktime,dlocktime,expiration,state,otherstate; + int32_t iambob,finishedflag,origfinishedflag,Predeemlen,Dredeemlen,sentflags[sizeof(txnames)/sizeof(*txnames)]; + uint8_t secretAm[20],secretAm256[32],secretBn[20],secretBn256[32],pubkey33[33],Predeemscript[1024],Dredeemscript[1024]; + char src[64],dest[64],destaddr[64],Adestaddr[64],alicepaymentaddr[64],bobpaymentaddr[64],bobdepositaddr[64],alicecoin[64],bobcoin[64],*txbytes[sizeof(txnames)/sizeof(*txnames)]; +}; + +cJSON *LP_swap_json(struct LP_swap_remember *rswap) +{ + cJSON *item,*array; int32_t i; + item = cJSON_CreateObject(); + jaddnum(item,"requestid",rswap->requestid); + jaddnum(item,"quoteid",rswap->quoteid); + jaddnum(item,"iambob",rswap->iambob); + jaddstr(item,"bob",rswap->src); + jaddnum(item,"srcamount",dstr(rswap->srcamount)); + jaddnum(item,"bobtxfee",dstr(rswap->Btxfee)); + jaddstr(item,"alice",rswap->dest); + jaddnum(item,"destamount",dstr(rswap->destamount)); + jaddnum(item,"alicetxfee",dstr(rswap->Atxfee)); + array = cJSON_CreateArray(); + for (i=0; isentflags[i] != 0 ) + jaddistr(array,txnames[i]); + if ( rswap->txbytes[i] != 0 ) + free(rswap->txbytes[i]); + } + jadd(item,"sentflags",array); + array = cJSON_CreateArray(); + for (i=0; ivalues[i])); + jadd(item,"values",array); + jaddstr(item,"result","success"); + if ( rswap->finishedflag != 0 ) + jaddstr(item,"status","finished"); + else jaddstr(item,"status","pending"); + jaddbits256(item,"bobdeposit",rswap->txids[BASILISK_BOBDEPOSIT]); + jaddbits256(item,"alicepayment",rswap->txids[BASILISK_ALICEPAYMENT]); + jaddbits256(item,"bobpayment",rswap->txids[BASILISK_BOBPAYMENT]); + jaddbits256(item,"paymentspent",rswap->paymentspent); + jaddbits256(item,"Apaymentspent",rswap->Apaymentspent); + jaddbits256(item,"depositspent",rswap->depositspent); + return(item); +} + +int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t quoteid) +{ + char fname[1024],*fstr,*secretstr,*srcstr,*deststr,*dest33,*txname; long fsize; cJSON *item,*txobj,*array; bits256 privkey; uint32_t r,q; int32_t i,j,n; + memset(rswap,0,sizeof(*rswap)); + rswap->requestid = requestid; + rswap->quoteid = quoteid; sprintf(fname,"%s/SWAPS/%u-%u",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname); if ( (fstr= OS_filestr(&fsize,fname)) != 0 ) { if ( (item= cJSON_Parse(fstr)) != 0 ) { - iambob = jint(item,"iambob"); + rswap->iambob = jint(item,"iambob"); if ( (secretstr= jstr(item,"secretAm")) != 0 && strlen(secretstr) == 40 ) - decode_hex(secretAm,20,secretstr); + decode_hex(rswap->secretAm,20,secretstr); if ( (secretstr= jstr(item,"secretAm256")) != 0 && strlen(secretstr) == 64 ) - decode_hex(secretAm256,32,secretstr); + decode_hex(rswap->secretAm256,32,secretstr); if ( (secretstr= jstr(item,"secretBn")) != 0 && strlen(secretstr) == 40 ) - decode_hex(secretBn,20,secretstr); + decode_hex(rswap->secretBn,20,secretstr); if ( (secretstr= jstr(item,"secretBn256")) != 0 && strlen(secretstr) == 64 ) - decode_hex(secretBn256,32,secretstr); + decode_hex(rswap->secretBn256,32,secretstr); if ( (srcstr= jstr(item,"src")) != 0 ) - safecopy(src,srcstr,sizeof(src)); + safecopy(rswap->src,srcstr,sizeof(rswap->src)); if ( (deststr= jstr(item,"dest")) != 0 ) - safecopy(dest,deststr,sizeof(dest)); + safecopy(rswap->dest,deststr,sizeof(rswap->dest)); if ( (dest33= jstr(item,"dest33")) != 0 && strlen(dest33) == 66 ) { - decode_hex(pubkey33,33,dest33); + decode_hex(rswap->pubkey33,33,dest33); //for (i=0; i<33; i++) // printf("%02x",pubkey33[i]); //printf(" <- %s dest33\n",dest33); } - if ( (plocktime= juint(item,"plocktime")) == 0 ) - plocktime = LP_extract(requestid,quoteid,fname,"plocktime"); - if ( (dlocktime= juint(item,"dlocktime")) == 0 ) - dlocktime = LP_extract(requestid,quoteid,fname,"dlocktime"); + if ( (rswap->plocktime= juint(item,"plocktime")) == 0 ) + rswap->plocktime = LP_extract(requestid,quoteid,fname,"plocktime"); + if ( (rswap->dlocktime= juint(item,"dlocktime")) == 0 ) + rswap->dlocktime = LP_extract(requestid,quoteid,fname,"dlocktime"); r = juint(item,"requestid"); q = juint(item,"quoteid"); - Atxfee = j64bits(item,"Atxfee"); - Btxfee = j64bits(item,"Btxfee"); - pubA0 = jbits256(item,"pubA0"); - pubB0 = jbits256(item,"pubB0"); - pubB1 = jbits256(item,"pubB1"); + rswap->Atxfee = j64bits(item,"Atxfee"); + rswap->Btxfee = j64bits(item,"Btxfee"); + rswap->pubA0 = jbits256(item,"pubA0"); + rswap->pubB0 = jbits256(item,"pubB0"); + rswap->pubB1 = jbits256(item,"pubB1"); privkey = jbits256(item,"myprivs0"); if ( bits256_nonz(privkey) != 0 ) - myprivs[0] = privkey; + rswap->myprivs[0] = privkey; privkey = jbits256(item,"myprivs1"); if ( bits256_nonz(privkey) != 0 ) - myprivs[1] = privkey; + rswap->myprivs[1] = privkey; privkey = jbits256(item,"privAm"); if ( bits256_nonz(privkey) != 0 ) { - privAm = privkey; + rswap->privAm = privkey; //printf("set privAm <- %s\n",bits256_str(str,privAm)); } privkey = jbits256(item,"privBn"); if ( bits256_nonz(privkey) != 0 ) { - privBn = privkey; + rswap->privBn = privkey; //printf("set privBn <- %s\n",bits256_str(str,privBn)); } - expiration = juint(item,"expiration"); - state = jint(item,"state"); - otherstate = jint(item,"otherstate"); - srcamount = SATOSHIDEN * jdouble(item,"srcamount"); - destamount = SATOSHIDEN * jdouble(item,"destamount"); - txids[BASILISK_BOBDEPOSIT] = jbits256(item,"Bdeposit"); - txids[BASILISK_BOBREFUND] = jbits256(item,"Brefund"); - txids[BASILISK_ALICECLAIM] = jbits256(item,"Aclaim"); - txids[BASILISK_BOBPAYMENT] = jbits256(item,"Bpayment"); - txids[BASILISK_ALICESPEND] = jbits256(item,"Aspend"); - txids[BASILISK_BOBRECLAIM] = jbits256(item,"Breclaim"); - txids[BASILISK_ALICEPAYMENT] = jbits256(item,"Apayment"); - txids[BASILISK_BOBSPEND] = jbits256(item,"Bspend"); - txids[BASILISK_ALICERECLAIM] = jbits256(item,"Areclaim"); - txids[BASILISK_MYFEE] = jbits256(item,"myfee"); - txids[BASILISK_OTHERFEE] = jbits256(item,"otherfee"); + rswap->expiration = juint(item,"expiration"); + rswap->state = jint(item,"state"); + rswap->otherstate = jint(item,"otherstate"); + rswap->srcamount = SATOSHIDEN * jdouble(item,"srcamount"); + rswap->destamount = SATOSHIDEN * jdouble(item,"destamount"); + rswap->txids[BASILISK_BOBDEPOSIT] = jbits256(item,"Bdeposit"); + rswap->txids[BASILISK_BOBREFUND] = jbits256(item,"Brefund"); + rswap->txids[BASILISK_ALICECLAIM] = jbits256(item,"Aclaim"); + rswap->txids[BASILISK_BOBPAYMENT] = jbits256(item,"Bpayment"); + rswap->txids[BASILISK_ALICESPEND] = jbits256(item,"Aspend"); + rswap->txids[BASILISK_BOBRECLAIM] = jbits256(item,"Breclaim"); + rswap->txids[BASILISK_ALICEPAYMENT] = jbits256(item,"Apayment"); + rswap->txids[BASILISK_BOBSPEND] = jbits256(item,"Bspend"); + rswap->txids[BASILISK_ALICERECLAIM] = jbits256(item,"Areclaim"); + rswap->txids[BASILISK_MYFEE] = jbits256(item,"myfee"); + rswap->txids[BASILISK_OTHERFEE] = jbits256(item,"otherfee"); free_json(item); } free(fstr); @@ -499,12 +588,12 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti //printf("%s -> (%s)\n",fname,fstr); if ( (txobj= cJSON_Parse(fstr)) != 0 ) { - paymentspent = jbits256(txobj,"paymentspent"); - Apaymentspent = jbits256(txobj,"Apaymentspent"); - depositspent = jbits256(txobj,"depositspent"); + rswap->paymentspent = jbits256(txobj,"paymentspent"); + rswap->Apaymentspent = jbits256(txobj,"Apaymentspent"); + rswap->depositspent = jbits256(txobj,"depositspent"); if ( (array= jarray(&n,txobj,"values")) != 0 ) for (i=0; ivalues[i] = SATOSHIDEN * jdouble(jitem(array,i),0); if ( (array= jarray(&n,txobj,"sentflags")) != 0 ) { for (i=0; isentflags[j] = 1; //printf("finished.%s\n",txnames[j]); break; } @@ -522,59 +611,61 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } } } - origfinishedflag = finishedflag = 1; + rswap->origfinishedflag = rswap->finishedflag = 1; free(fstr); } - if ( iambob < 0 ) - return(0); - item = cJSON_CreateObject(); - array = cJSON_CreateArray(); + return(rswap->iambob); +} + +int32_t LP_swap_load(struct LP_swap_remember *rswap) +{ + int32_t i,needflag,addflag; long fsize; char fname[1024],str[65],*fstr,*symbol,*rstr; cJSON *txobj,*sentobj; bits256 txid,checktxid; uint64_t value; for (i=0; irequestid,rswap->quoteid,txnames[i]), OS_compatible_path(fname); if ( (fstr= OS_filestr(&fsize,fname)) != 0 ) { - if ( 0 && finishedflag == 0 ) + if ( 0 && rswap->finishedflag == 0 ) printf("%s\n",fname); //printf("%s -> (%s)\n",fname,fstr); if ( (txobj= cJSON_Parse(fstr)) != 0 ) { //printf("TXOBJ.(%s)\n",jprint(txobj,0)); - iambob = jint(txobj,"iambob"); + rswap->iambob = jint(txobj,"iambob"); txid = jbits256(txobj,"txid"); if ( bits256_nonz(txid) == 0 ) continue; - txids[i] = txid; + rswap->txids[i] = txid; if ( jstr(txobj,"Apayment") != 0 ) - strcpy(alicepaymentaddr,jstr(txobj,"Apayment")); + safecopy(rswap->alicepaymentaddr,jstr(txobj,"Apayment"),sizeof(rswap->alicepaymentaddr)); if ( jstr(txobj,"Bpayment") != 0 ) - strcpy(bobpaymentaddr,jstr(txobj,"Bpayment")); + safecopy(rswap->bobpaymentaddr,jstr(txobj,"Bpayment"),sizeof(rswap->bobpaymentaddr)); if ( jstr(txobj,"Bdeposit") != 0 ) - strcpy(bobdepositaddr,jstr(txobj,"Bdeposit")); + safecopy(rswap->bobdepositaddr,jstr(txobj,"Bdeposit"),sizeof(rswap->bobdepositaddr)); if ( jobj(txobj,"tx") != 0 ) { - txbytes[i] = clonestr(jstr(txobj,"tx")); + rswap->txbytes[i] = clonestr(jstr(txobj,"tx")); //printf("[%s] TX.(%s)\n",txnames[i],txbytes[i]); } - if ( strcmp(txnames[i],"bobpayment") == 0 && (rstr= jstr(txobj,"redeem")) != 0 && (Predeemlen= is_hexstr(rstr,0)) > 0 ) + if ( strcmp(txnames[i],"bobpayment") == 0 && (rstr= jstr(txobj,"redeem")) != 0 && (rswap->Predeemlen= is_hexstr(rstr,0)) > 0 ) { - Predeemlen >>= 1; - decode_hex(Predeemscript,Predeemlen,rstr); + rswap->Predeemlen >>= 1; + decode_hex(rswap->Predeemscript,rswap->Predeemlen,rstr); } - else if ( strcmp(txnames[i],"bobdeposit") == 0 && (rstr= jstr(txobj,"redeem")) != 0 && (Dredeemlen= is_hexstr(rstr,0)) > 0 ) + else if ( strcmp(txnames[i],"bobdeposit") == 0 && (rstr= jstr(txobj,"redeem")) != 0 && (rswap->Dredeemlen= is_hexstr(rstr,0)) > 0 ) { - Dredeemlen >>= 1; - decode_hex(Dredeemscript,Dredeemlen,rstr); + rswap->Dredeemlen >>= 1; + decode_hex(rswap->Dredeemscript,rswap->Dredeemlen,rstr); } - values[i] = value = LP_value_extract(txobj,1); + rswap->values[i] = value = LP_value_extract(txobj,1); if ( (symbol= jstr(txobj,"coin")) != 0 ) { if ( i == BASILISK_ALICESPEND || i == BASILISK_BOBPAYMENT || i == BASILISK_BOBDEPOSIT || i == BASILISK_BOBREFUND || i == BASILISK_BOBRECLAIM || i == BASILISK_ALICECLAIM ) - safecopy(bobcoin,symbol,sizeof(bobcoin)); + safecopy(rswap->bobcoin,symbol,sizeof(rswap->bobcoin)); else if ( i == BASILISK_BOBSPEND || i == BASILISK_ALICEPAYMENT || i == BASILISK_ALICERECLAIM ) - safecopy(alicecoin,symbol,sizeof(alicecoin)); - if ( finishedflag == 0 ) + safecopy(rswap->alicecoin,symbol,sizeof(rswap->alicecoin)); + if ( rswap->finishedflag == 0 ) { if ( (sentobj= LP_gettx(symbol,txid)) == 0 ) { @@ -594,58 +685,80 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( bits256_cmp(checktxid,txid) == 0 ) { //printf(">>>>>> %s txid %s\n",jprint(sentobj,0),bits256_str(str,txid)); - sentflags[i] = 1; + rswap->sentflags[i] = 1; } free_json(sentobj); } - if ( finishedflag == 0 ) + if ( rswap->finishedflag == 0 ) printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value)); } } } //else printf("no symbol\n"); free(fstr); - } else if ( 0 && finishedflag == 0 ) + } else if ( 0 && rswap->finishedflag == 0 ) printf("%s not finished\n",fname); } - //printf("alicepayment.%s bobpayment.%s bobdeposit.%s\n",alicepaymentaddr,bobpaymentaddr,bobdepositaddr); - //printf("iambob.%d src.%s dest.%s bob.%s alice.%s pubA0.(%s)\n",iambob,src,dest,bobcoin,alicecoin,bits256_str(str,pubA0)); - Adestaddr[0] = destaddr[0] = 0; + return(rswap->finishedflag); +} + +/*{ + if ( txbytes[BASILISK_BOBREFUND] != 0 ) + { + txids[BASILISK_BOBREFUND] = LP_broadcast("bobrefund",bobcoin,txbytes[BASILISK_BOBREFUND],zero); + if ( bits256_nonz(txids[BASILISK_BOBREFUND]) != 0 ) // tested + { + sentflags[BASILISK_BOBREFUND] = 1; + depositspent = txids[BASILISK_BOBREFUND]; + } + } +}*/ + +cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) +{ + static void *ctx; + struct LP_swap_remember rswap; int32_t i,j,len,secretstart,redeemlen; char str[65],*Adest,*Bdest,*AAdest,*ABdest; cJSON *item,*sentobj; bits256 rev,signedtxid,zero; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid)) < 0 ) + return(0); + LP_swap_load(&rswap); + memset(zero.bytes,0,sizeof(zero)); Adest = Bdest = AAdest = ABdest = 0; - if ( bobcoin[0] == 0 || alicecoin[0] == 0 ) + if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 ) return(0); - alice = LP_coinfind(alicecoin); - bob = LP_coinfind(bobcoin); - Atxfee = LP_txfeecalc(alice,Atxfee); - Btxfee = LP_txfeecalc(bob,Btxfee); + alice = LP_coinfind(rswap.alicecoin); + bob = LP_coinfind(rswap.bobcoin); + rswap.Atxfee = LP_txfeecalc(alice,rswap.Atxfee); + rswap.Btxfee = LP_txfeecalc(bob,rswap.Btxfee); //printf("%s %.8f txfee, %s %.8f txfee\n",alicecoin,dstr(Atxfee),bobcoin,dstr(Btxfee)); //printf("privAm.(%s) %p/%p\n",bits256_str(str,privAm),Adest,AAdest); //printf("privBn.(%s) %p/%p\n",bits256_str(str,privBn),Bdest,ABdest); - if ( finishedflag == 0 && bobcoin[0] != 0 && alicecoin[0] != 0 ) + if ( rswap.finishedflag == 0 && rswap.bobcoin[0] != 0 && rswap.alicecoin[0] != 0 ) { - if ( iambob == 0 ) + if ( rswap.iambob == 0 ) { if ( alice != 0 ) { - bitcoin_address(Adestaddr,alice->taddr,alice->pubtype,pubkey33,33); - AAdest = Adestaddr; + bitcoin_address(rswap.Adestaddr,alice->taddr,alice->pubtype,rswap.pubkey33,33); + AAdest = rswap.Adestaddr; } - if ( (bob= LP_coinfind(bobcoin)) != 0 ) + if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 ) { - bitcoin_address(destaddr,bob->taddr,bob->pubtype,pubkey33,33); - Adest = destaddr; + bitcoin_address(rswap.destaddr,bob->taddr,bob->pubtype,rswap.pubkey33,33); + Adest = rswap.destaddr; } } else { if ( bob != 0 ) { - bitcoin_address(destaddr,bob->taddr,bob->pubtype,pubkey33,33); - Bdest = destaddr; + bitcoin_address(rswap.destaddr,bob->taddr,bob->pubtype,rswap.pubkey33,33); + Bdest = rswap.destaddr; } - if ( (alice= LP_coinfind(alicecoin)) != 0 ) + if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 ) { - bitcoin_address(Adestaddr,alice->taddr,alice->pubtype,pubkey33,33); - ABdest = Adestaddr; + bitcoin_address(rswap.Adestaddr,alice->taddr,alice->pubtype,rswap.pubkey33,33); + ABdest = rswap.Adestaddr; } } if ( bob == 0 || alice == 0 ) @@ -655,328 +768,245 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } if ( alice->inactive != 0 || bob->inactive != 0 ) { - printf("Alice.%s inactive.%u or Bob.%s inactive.%u\n",alicecoin,alice->inactive,bobcoin,bob->inactive); + printf("Alice.%s inactive.%u or Bob.%s inactive.%u\n",rswap.alicecoin,alice->inactive,rswap.bobcoin,bob->inactive); return(0); } - if ( sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(txids[BASILISK_ALICEPAYMENT]) != 0 ) + if ( rswap.sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 ) { - printf("txbytes.%p Apayment.%s\n",txbytes[BASILISK_ALICEPAYMENT],bits256_str(str,txids[BASILISK_ALICEPAYMENT])); - if ( txbytes[BASILISK_ALICEPAYMENT] != 0 ) - sentflags[BASILISK_ALICEPAYMENT] = 1; - else if ( (sentobj= LP_gettx(alicecoin,txids[BASILISK_ALICEPAYMENT])) != 0 ) + printf("txbytes.%p Apayment.%s\n",rswap.txbytes[BASILISK_ALICEPAYMENT],bits256_str(str,rswap.txids[BASILISK_ALICEPAYMENT])); + if ( rswap.txbytes[BASILISK_ALICEPAYMENT] != 0 ) + rswap.sentflags[BASILISK_ALICEPAYMENT] = 1; + else if ( (sentobj= LP_gettx(rswap.alicecoin,rswap.txids[BASILISK_ALICEPAYMENT])) != 0 ) { - sentflags[BASILISK_ALICEPAYMENT] = 1; + rswap.sentflags[BASILISK_ALICEPAYMENT] = 1; free_json(sentobj); } } - paymentspent = basilisk_swap_spendupdate(bobcoin,sentflags,txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,Adest,Bdest); - Apaymentspent = basilisk_swap_spendupdate(alicecoin,sentflags,txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,AAdest,ABdest); - depositspent = basilisk_swap_spendupdate(bobcoin,sentflags,txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,Adest,Bdest); - finishedflag = basilisk_swap_isfinished(iambob,txids,sentflags,paymentspent,Apaymentspent,depositspent); - if ( iambob == 0 ) + rswap.paymentspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,Adest,Bdest); + rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.alicecoin,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,AAdest,ABdest); + rswap.depositspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,Adest,Bdest); + rswap.finishedflag = basilisk_swap_isfinished(rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent); + if ( rswap.iambob == 0 ) { - if ( sentflags[BASILISK_ALICESPEND] == 0 ) + if ( rswap.sentflags[BASILISK_ALICESPEND] == 0 ) { - if ( sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(paymentspent) == 0 ) + if ( rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.paymentspent) == 0 ) { //if ( txbytes[BASILISK_ALICESPEND] == 0 ) { - if ( bits256_nonz(txids[BASILISK_BOBPAYMENT]) != 0 ) + if ( bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 ) { // alicespend + memset(rev.bytes,0,sizeof(rev)); for (j=0; j<32; j++) - rev.bytes[j] = privAm.bytes[31 - j]; + rev.bytes[j] = rswap.privAm.bytes[31 - j]; //revcalc_rmd160_sha256(secretAm,rev);//privAm); //vcalc_sha256(0,secretAm256,rev.bytes,sizeof(rev)); - if ( Predeemlen != 0 ) - redeemlen = Predeemlen, memcpy(redeemscript,Predeemscript,Predeemlen); - else redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,plocktime,pubA0,pubB0,pubB1,rev,privBn,secretAm,secretAm256,secretBn,secretBn256); - len = basilisk_swapuserdata(userdata,rev,0,myprivs[0],redeemscript,redeemlen); + if ( rswap.Predeemlen != 0 ) + redeemlen = rswap.Predeemlen, memcpy(redeemscript,rswap.Predeemscript,rswap.Predeemlen); + else redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rev,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); + len = basilisk_swapuserdata(userdata,rev,0,rswap.myprivs[0],redeemscript,redeemlen); { char privaddr[64]; uint8_t privpub33[33]; - bitcoin_pubkey33(ctx,privpub33,myprivs[0]); + bitcoin_pubkey33(ctx,privpub33,rswap.myprivs[0]); bitcoin_address(privaddr,0,60,privpub33,33); - printf("alicespend len.%d redeemlen.%d priv0addr.(%s) priv0.(%s)\n",len,redeemlen,privaddr,bits256_str(str,myprivs[0])); + printf("alicespend len.%d redeemlen.%d priv0addr.(%s) priv0.(%s)\n",len,redeemlen,privaddr,bits256_str(str,rswap.myprivs[0])); } for (j=0; j<32; j++) - rev.bytes[j] = myprivs[0].bytes[31 - j]; - if ( (txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,Btxfee,"alicespend",bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,myprivs[0],0,redeemscript,redeemlen,userdata,len,txids[BASILISK_BOBPAYMENT],0,0,pubkey33,1,expiration,&values[BASILISK_ALICESPEND],0,0,bobpaymentaddr,1)) != 0 ) - printf("alicespend.(%s)\n",txbytes[BASILISK_ALICESPEND]); + rev.bytes[j] = rswap.myprivs[0].bytes[31 - j]; + if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1)) != 0 ) + printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]); } } - if ( txbytes[BASILISK_ALICESPEND] != 0 ) + if ( rswap.txbytes[BASILISK_ALICESPEND] != 0 ) { - txids[BASILISK_ALICESPEND] = LP_broadcast("alicespend",bobcoin,txbytes[BASILISK_ALICESPEND],zero); - if ( bits256_nonz(txids[BASILISK_ALICESPEND]) != 0 ) // tested + rswap.txids[BASILISK_ALICESPEND] = LP_broadcast("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],zero); + if ( bits256_nonz(rswap.txids[BASILISK_ALICESPEND]) != 0 ) // tested { - sentflags[BASILISK_ALICESPEND] = 1; - paymentspent = txids[BASILISK_ALICESPEND]; + rswap.sentflags[BASILISK_ALICESPEND] = 1; + rswap.paymentspent = rswap.txids[BASILISK_ALICESPEND]; } } } } - if ( sentflags[BASILISK_ALICECLAIM] == 0 && sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(depositspent) == 0 ) + if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { - if ( time(NULL) > expiration ) + if ( time(NULL) > rswap.expiration ) { //if ( txbytes[BASILISK_ALICECLAIM] == 0 ) { - if ( Dredeemlen != 0 ) - redeemlen = Dredeemlen, memcpy(redeemscript,Dredeemscript,Dredeemlen); - else redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,dlocktime,pubA0,pubB0,pubB1,privAm,zero,secretAm,secretAm256,secretBn,secretBn256); + if ( rswap.Dredeemlen != 0 ) + redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen); + else redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,zero,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); if ( redeemlen > 0 ) { - len = basilisk_swapuserdata(userdata,zero,1,myprivs[0],redeemscript,redeemlen); - if ( (txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,Btxfee,"aliceclaim",bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,myprivs[0],0,redeemscript,redeemlen,userdata,len,txids[BASILISK_BOBDEPOSIT],0,0,pubkey33,0,expiration,&values[BASILISK_ALICECLAIM],0,0,bobdepositaddr,1)) != 0 ) - printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,privBn),txbytes[BASILISK_ALICECLAIM]); + len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen); + if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1)) != 0 ) + printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]); } } - if ( txbytes[BASILISK_ALICECLAIM] != 0 ) + if ( rswap.txbytes[BASILISK_ALICECLAIM] != 0 ) { - txids[BASILISK_ALICECLAIM] = LP_broadcast("aliceclaim",bobcoin,txbytes[BASILISK_ALICECLAIM],zero); - if ( bits256_nonz(txids[BASILISK_ALICECLAIM]) != 0 ) // tested + rswap.txids[BASILISK_ALICECLAIM] = LP_broadcast("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],zero); + if ( bits256_nonz(rswap.txids[BASILISK_ALICECLAIM]) != 0 ) // tested { - sentflags[BASILISK_ALICECLAIM] = 1; - depositspent = txids[BASILISK_ALICECLAIM]; + rswap.sentflags[BASILISK_ALICECLAIM] = 1; + rswap.depositspent = rswap.txids[BASILISK_ALICECLAIM]; } } - } else printf("now %u before expiration %u\n",(uint32_t)time(NULL),expiration); + } else printf("now %u before expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } - if ( sentflags[BASILISK_ALICEPAYMENT] != 0 && bits256_nonz(Apaymentspent) == 0 && sentflags[BASILISK_ALICECLAIM] == 0 ) + if ( rswap.sentflags[BASILISK_ALICEPAYMENT] != 0 && bits256_nonz(rswap.Apaymentspent) == 0 && rswap.sentflags[BASILISK_ALICECLAIM] == 0 ) { //if ( txbytes[BASILISK_ALICERECLAIM] == 0 ) { - privBn = basilisk_swap_privBn_extract(&txids[BASILISK_BOBREFUND],bobcoin,txids[BASILISK_BOBDEPOSIT],privBn); - if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(privAm) != 0 && bits256_nonz(privBn) != 0 ) + rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); + if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { - if ( (txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",alicecoin,Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,privAm,privBn,txids[BASILISK_ALICEPAYMENT],0,pubkey33,expiration,&values[BASILISK_ALICERECLAIM],alicepaymentaddr)) != 0 ) - printf("privBn.(%s) alicereclaim.(%s)\n",bits256_str(str,privBn),txbytes[BASILISK_ALICERECLAIM]); + if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr)) != 0 ) + printf("privBn.(%s) alicereclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICERECLAIM]); } } - if ( txbytes[BASILISK_ALICERECLAIM] != 0 ) + if ( rswap.txbytes[BASILISK_ALICERECLAIM] != 0 ) { - txids[BASILISK_ALICERECLAIM] = LP_broadcast("alicereclaim",alicecoin,txbytes[BASILISK_ALICERECLAIM],zero); - if ( bits256_nonz(txids[BASILISK_ALICERECLAIM]) != 0 ) // tested + rswap.txids[BASILISK_ALICERECLAIM] = LP_broadcast("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],zero); + if ( bits256_nonz(rswap.txids[BASILISK_ALICERECLAIM]) != 0 ) // tested { - sentflags[BASILISK_ALICERECLAIM] = 1; - Apaymentspent = txids[BASILISK_ALICERECLAIM]; + rswap.sentflags[BASILISK_ALICERECLAIM] = 1; + rswap.Apaymentspent = rswap.txids[BASILISK_ALICERECLAIM]; } } } } - else if ( iambob == 1 ) + else if ( rswap.iambob == 1 ) { - if ( sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(Apaymentspent) == 0 ) + if ( rswap.sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(rswap.Apaymentspent) == 0 ) { - printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,txids[BASILISK_ALICESPEND]),bits256_nonz(privAm)); - if ( bits256_nonz(txids[BASILISK_ALICESPEND]) != 0 || bits256_nonz(privAm) != 0 ) + printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); + if ( bits256_nonz(rswap.txids[BASILISK_ALICESPEND]) != 0 || bits256_nonz(rswap.privAm) != 0 ) { //if ( txbytes[BASILISK_BOBSPEND] == 0 ) { - if ( bits256_nonz(privAm) == 0 ) + if ( bits256_nonz(rswap.privAm) == 0 ) { - privAm = basilisk_swap_privbob_extract(bobcoin,txids[BASILISK_ALICESPEND],0,1); + rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.txids[BASILISK_ALICESPEND],0,1); } - if ( bits256_nonz(privAm) != 0 && bits256_nonz(privBn) != 0 ) + if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { - if ( (txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",alicecoin,Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,privAm,privBn,txids[BASILISK_ALICEPAYMENT],0,pubkey33,expiration,&values[BASILISK_BOBSPEND],alicepaymentaddr)) != 0 ) - printf("bobspend.(%s)\n",txbytes[BASILISK_BOBSPEND]); + if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr)) != 0 ) + printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); } } - if ( txbytes[BASILISK_BOBSPEND] != 0 ) + if ( rswap.txbytes[BASILISK_BOBSPEND] != 0 ) { - txids[BASILISK_BOBSPEND] = LP_broadcast("bobspend",alicecoin,txbytes[BASILISK_BOBSPEND],zero); - if ( bits256_nonz(txids[BASILISK_BOBSPEND]) != 0 ) // tested + rswap.txids[BASILISK_BOBSPEND] = LP_broadcast("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],zero); + if ( bits256_nonz(rswap.txids[BASILISK_BOBSPEND]) != 0 ) // tested { - sentflags[BASILISK_BOBSPEND] = 1; - Apaymentspent = txids[BASILISK_BOBSPEND]; + rswap.sentflags[BASILISK_BOBSPEND] = 1; + rswap.Apaymentspent = rswap.txids[BASILISK_BOBSPEND]; } } } } - if ( sentflags[BASILISK_BOBRECLAIM] == 0 && sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(txids[BASILISK_BOBPAYMENT]) != 0 && time(NULL) > expiration && bits256_nonz(paymentspent) == 0 ) + if ( rswap.sentflags[BASILISK_BOBRECLAIM] == 0 && rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 && time(NULL) > rswap.expiration && bits256_nonz(rswap.paymentspent) == 0 ) { //if ( txbytes[BASILISK_BOBRECLAIM] == 0 ) { // bobreclaim - redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,plocktime,pubA0,pubB0,pubB1,zero,privBn,secretAm,secretAm256,secretBn,secretBn256); + redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,zero,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); if ( redeemlen > 0 ) { - len = basilisk_swapuserdata(userdata,zero,1,myprivs[1],redeemscript,redeemlen); - if ( (txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,Btxfee,"bobrefund",bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,myprivs[1],0,redeemscript,redeemlen,userdata,len,txids[BASILISK_BOBPAYMENT],0,0,pubkey33,0,expiration,&values[BASILISK_BOBRECLAIM],0,0,bobpaymentaddr,1)) != 0 ) + len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); + if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1)) != 0 ) { int32_t z; for (z=0; z<20; z++) - printf("%02x",secretAm[z]); - printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,myprivs[1]),txbytes[BASILISK_BOBRECLAIM]); + printf("%02x",rswap.secretAm[z]); + printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,rswap.myprivs[1]),rswap.txbytes[BASILISK_BOBRECLAIM]); } } } - if ( txbytes[BASILISK_BOBRECLAIM] != 0 ) + if ( rswap.txbytes[BASILISK_BOBRECLAIM] != 0 ) { - txids[BASILISK_BOBRECLAIM] = LP_broadcast("bobreclaim",bobcoin,txbytes[BASILISK_BOBRECLAIM],zero); - if ( bits256_nonz(txids[BASILISK_BOBRECLAIM]) != 0 ) // tested + rswap.txids[BASILISK_BOBRECLAIM] = LP_broadcast("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],zero); + if ( bits256_nonz(rswap.txids[BASILISK_BOBRECLAIM]) != 0 ) // tested { - sentflags[BASILISK_BOBRECLAIM] = 1; - paymentspent = txids[BASILISK_BOBRECLAIM]; + rswap.sentflags[BASILISK_BOBRECLAIM] = 1; + rswap.paymentspent = rswap.txids[BASILISK_BOBRECLAIM]; } } } - if ( sentflags[BASILISK_BOBREFUND] == 0 && sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(depositspent) == 0 ) + if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { - if ( bits256_nonz(paymentspent) != 0 || time(NULL) > expiration ) + if ( bits256_nonz(rswap.paymentspent) != 0 || time(NULL) > rswap.expiration ) { printf("do the refund!\n"); //if ( txbytes[BASILISK_BOBREFUND] == 0 ) { - revcalc_rmd160_sha256(secretBn,privBn); - vcalc_sha256(0,secretBn256,privBn.bytes,sizeof(privBn)); - redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,dlocktime,pubA0,pubB0,pubB1,privAm,privBn,secretAm,secretAm256,secretBn,secretBn256); - len = basilisk_swapuserdata(userdata,privBn,0,myprivs[0],redeemscript,redeemlen); - if ( (txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,Btxfee,"bobrefund",bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,myprivs[0],0,redeemscript,redeemlen,userdata,len,txids[BASILISK_BOBDEPOSIT],0,0,pubkey33,1,expiration,&values[BASILISK_BOBREFUND],0,0,bobdepositaddr,1)) != 0 ) - printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,pubB1),txbytes[BASILISK_BOBREFUND]); + revcalc_rmd160_sha256(rswap.secretBn,rswap.privBn); + vcalc_sha256(0,rswap.secretBn256,rswap.privBn.bytes,sizeof(rswap.privBn)); + redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); + len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen); + if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1)) != 0 ) + printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]); } - if ( txbytes[BASILISK_BOBREFUND] != 0 ) + if ( rswap.txbytes[BASILISK_BOBREFUND] != 0 ) { - txids[BASILISK_BOBREFUND] = LP_broadcast("bobrefund",bobcoin,txbytes[BASILISK_BOBREFUND],zero); - if ( bits256_nonz(txids[BASILISK_BOBREFUND]) != 0 ) // tested + rswap.txids[BASILISK_BOBREFUND] = LP_broadcast("bobrefund",rswap.bobcoin,rswap.txbytes[BASILISK_BOBREFUND],zero); + if ( bits256_nonz(rswap.txids[BASILISK_BOBREFUND]) != 0 ) // tested { - sentflags[BASILISK_BOBREFUND] = 1; - depositspent = txids[BASILISK_BOBREFUND]; + rswap.sentflags[BASILISK_BOBREFUND] = 1; + rswap.depositspent = rswap.txids[BASILISK_BOBREFUND]; } } - } else printf("bobrefund's time %u vs expiration %u\n",(uint32_t)time(NULL),expiration); + } else printf("bobrefund's time %u vs expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } } } //printf("finish.%d iambob.%d REFUND %d %d %d %d\n",finishedflag,iambob,sentflags[BASILISK_BOBREFUND] == 0,sentflags[BASILISK_BOBDEPOSIT] != 0,bits256_nonz(txids[BASILISK_BOBDEPOSIT]) != 0,bits256_nonz(depositspent) == 0); - if ( sentflags[BASILISK_ALICESPEND] != 0 || sentflags[BASILISK_BOBRECLAIM] != 0 ) - sentflags[BASILISK_BOBPAYMENT] = 1; - if ( sentflags[BASILISK_ALICERECLAIM] != 0 || sentflags[BASILISK_BOBSPEND] != 0 ) - sentflags[BASILISK_ALICEPAYMENT] = 1; - if ( sentflags[BASILISK_ALICECLAIM] != 0 || sentflags[BASILISK_BOBREFUND] != 0 ) - sentflags[BASILISK_BOBDEPOSIT] = 1; - for (i=0; isymbol); - jaddnum(item,"bobamount",dstr(values[BASILISK_BOBPAYMENT])); - jaddnum(item,"bobtxfee",dstr(Btxfee)); - jaddstr(item,"alice",alice->symbol); - jaddnum(item,"aliceamount",dstr(values[BASILISK_ALICEPAYMENT])); - jaddnum(item,"alicetxfee",dstr(Atxfee)); - jadd(item,"txs",array); - array = cJSON_CreateArray(); + if ( rswap.sentflags[BASILISK_ALICESPEND] != 0 || rswap.sentflags[BASILISK_BOBRECLAIM] != 0 ) + rswap.sentflags[BASILISK_BOBPAYMENT] = 1; + if ( rswap.sentflags[BASILISK_ALICERECLAIM] != 0 || rswap.sentflags[BASILISK_BOBSPEND] != 0 ) + rswap.sentflags[BASILISK_ALICEPAYMENT] = 1; + if ( rswap.sentflags[BASILISK_ALICECLAIM] != 0 || rswap.sentflags[BASILISK_BOBREFUND] != 0 ) + rswap.sentflags[BASILISK_BOBDEPOSIT] = 1; for (i=0; i Date: Wed, 4 Oct 2017 19:55:48 +0300 Subject: [PATCH 508/520] Test --- iguana/exchanges/LP_remember.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index b685b4a98..02a9ea564 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -840,9 +840,14 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti else redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,zero,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); if ( redeemlen > 0 ) { - len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen); - if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1)) != 0 ) - printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]); + if ( bits256_nonz(rswap.privBn) == 0 ) + rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); + if ( bits256_nonz(rswap.privBn) != 0 ) + { + len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[0],redeemscript,redeemlen); + if ( (rswap.txbytes[BASILISK_ALICECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"aliceclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,0,rswap.expiration,&rswap.values[BASILISK_ALICECLAIM],0,0,rswap.bobdepositaddr,1)) != 0 ) + printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]); + } } } if ( rswap.txbytes[BASILISK_ALICECLAIM] != 0 ) From 5012acea8638003d8ba141961f98bd05f7c567bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 20:35:02 +0300 Subject: [PATCH 509/520] Test --- iguana/exchanges/LP_remember.c | 24 +++++++++++++++++++++++- iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 02a9ea564..15c48c4ed 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -713,6 +713,24 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap) } }*/ +int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi) +{ + cJSON *sentobj; char str[65]; + if ( rswap->sentflags[txi] == 0 && bits256_nonz(rswap->txids[txi]) != 0 ) + { + printf("[%s] txbytes.%p Apayment.%s\n",txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi])); + if ( rswap->txbytes[txi] != 0 ) + rswap->sentflags[txi] = 1; + else if ( (sentobj= LP_gettx(symbol,rswap->txids[txi])) != 0 ) + { + rswap->sentflags[txi] = 1; + free_json(sentobj); + return(1); + } + } + return(0); +} + cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) { static void *ctx; @@ -771,6 +789,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti printf("Alice.%s inactive.%u or Bob.%s inactive.%u\n",rswap.alicecoin,alice->inactive,rswap.bobcoin,bob->inactive); return(0); } + LP_rswap_checktx(&rswap,rswap.alicecoin,BASILISK_ALICEPAYMENT); + LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBPAYMENT); + LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBDEPOSIT); +/* if ( rswap.sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 ) { printf("txbytes.%p Apayment.%s\n",rswap.txbytes[BASILISK_ALICEPAYMENT],bits256_str(str,rswap.txids[BASILISK_ALICEPAYMENT])); @@ -781,7 +803,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti rswap.sentflags[BASILISK_ALICEPAYMENT] = 1; free_json(sentobj); } - } + }*/ rswap.paymentspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,Adest,Bdest); rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.alicecoin,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,AAdest,ABdest); rswap.depositspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,Adest,Bdest); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index deffe3bf6..c612cfa3f 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -623,7 +623,7 @@ char *LP_sendrawtransaction(char *symbol,char *signedtx) //electrum sendrawtx (the transaction was rejected by network rules.\n\ntransaction already in block chain) if ( strstr(retstr,"already in block") != 0 ) alreadyflag = 1; - printf("electrum sendrawtx.(%s) -> %s already.%d\n",signedtx,retstr,alreadyflag); + //printf("electrum sendrawtx.(%s) -> %s already.%d\n",signedtx,retstr,alreadyflag); if ( alreadyflag != 0 ) { errobj = cJSON_CreateObject(); From 02f9ec624c539549073d31308b300fc1bb475bf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 20:45:42 +0300 Subject: [PATCH 510/520] Test --- iguana/exchanges/LP_remember.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 15c48c4ed..57ba7f142 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -246,16 +246,12 @@ bits256 basilisk_swap_privBn_extract(bits256 *bobrefundp,char *bobcoin,bits256 b bits256 basilisk_swap_spendupdate(char *symbol,int32_t *sentflags,bits256 *txids,int32_t utxoind,int32_t alicespent,int32_t bobspent,int32_t vout,char *aliceaddr,char *bobaddr) { - bits256 spendtxid,txid; char destaddr[64]; + bits256 spendtxid,txid; char destaddr[64],str[65]; txid = txids[utxoind]; memset(&spendtxid,0,sizeof(spendtxid)); - /*if ( aliceaddr != 0 ) - printf("aliceaddr.(%s)\n",aliceaddr); - if ( bobaddr != 0 ) - printf("bobaddr.(%s)\n",bobaddr);*/ if ( bits256_nonz(txid) != 0 ) { - //char str[65]; + destaddr[0] = 0; spendtxid = LP_swap_spendtxid(symbol,destaddr,txid,vout); if ( bits256_nonz(spendtxid) != 0 ) { @@ -290,7 +286,7 @@ bits256 basilisk_swap_spendupdate(char *symbol,int32_t *sentflags,bits256 *txids txids[alicespent] = spendtxid; } } - } + } else printf("no spend of %s/v%d detected\n",bits256_str(str,txid),vout); } else printf("utxoind.%d null txid\n",utxoind); return(spendtxid); } @@ -734,7 +730,7 @@ int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) { static void *ctx; - struct LP_swap_remember rswap; int32_t i,j,len,secretstart,redeemlen; char str[65],*Adest,*Bdest,*AAdest,*ABdest; cJSON *item,*sentobj; bits256 rev,signedtxid,zero; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; + struct LP_swap_remember rswap; int32_t i,j,len,secretstart,redeemlen; char str[65],*Adest,*Bdest,*AAdest,*ABdest; cJSON *item; bits256 rev,signedtxid,zero; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid)) < 0 ) @@ -792,18 +788,6 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti LP_rswap_checktx(&rswap,rswap.alicecoin,BASILISK_ALICEPAYMENT); LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBPAYMENT); LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBDEPOSIT); -/* - if ( rswap.sentflags[BASILISK_ALICEPAYMENT] == 0 && bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 ) - { - printf("txbytes.%p Apayment.%s\n",rswap.txbytes[BASILISK_ALICEPAYMENT],bits256_str(str,rswap.txids[BASILISK_ALICEPAYMENT])); - if ( rswap.txbytes[BASILISK_ALICEPAYMENT] != 0 ) - rswap.sentflags[BASILISK_ALICEPAYMENT] = 1; - else if ( (sentobj= LP_gettx(rswap.alicecoin,rswap.txids[BASILISK_ALICEPAYMENT])) != 0 ) - { - rswap.sentflags[BASILISK_ALICEPAYMENT] = 1; - free_json(sentobj); - } - }*/ rswap.paymentspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,Adest,Bdest); rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.alicecoin,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,AAdest,ABdest); rswap.depositspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,Adest,Bdest); From aa6ec20c13f0fb97ca1fd8b69beb42e289de677f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 20:54:31 +0300 Subject: [PATCH 511/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0c43d6503..ac628c15f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -511,7 +511,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int coin->lastscanht = coin->firstscanht; continue; } - //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); + printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); From bab2b8530587d1b1f7967fa27a16eefd0950062f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 21:45:49 +0300 Subject: [PATCH 512/520] Test --- iguana/exchanges/LP_remember.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 57ba7f142..fc0bada18 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -244,9 +244,17 @@ bits256 basilisk_swap_privBn_extract(bits256 *bobrefundp,char *bobcoin,bits256 b return(privBn); } -bits256 basilisk_swap_spendupdate(char *symbol,int32_t *sentflags,bits256 *txids,int32_t utxoind,int32_t alicespent,int32_t bobspent,int32_t vout,char *aliceaddr,char *bobaddr) +bits256 basilisk_swap_spendupdate(char *symbol,char *spentaddr,int32_t *sentflags,bits256 *txids,int32_t utxoind,int32_t alicespent,int32_t bobspent,int32_t vout,char *aliceaddr,char *bobaddr) { - bits256 spendtxid,txid; char destaddr[64],str[65]; + bits256 spendtxid,txid; char destaddr[64],str[65]; struct iguana_info *coin; cJSON *histobj; + if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum != 0 ) + { + if ( (histobj= electrum_address_gethistory(symbol,coin->electrum,&histobj,spentaddr)) != 0 ) + { + printf("processed history.(%s)\n",jprint(histobj,0)); + free_json(histobj); + } + } txid = txids[utxoind]; memset(&spendtxid,0,sizeof(spendtxid)); if ( bits256_nonz(txid) != 0 ) @@ -788,9 +796,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti LP_rswap_checktx(&rswap,rswap.alicecoin,BASILISK_ALICEPAYMENT); LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBPAYMENT); LP_rswap_checktx(&rswap,rswap.bobcoin,BASILISK_BOBDEPOSIT); - rswap.paymentspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,Adest,Bdest); - rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.alicecoin,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,AAdest,ABdest); - rswap.depositspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,Adest,Bdest); + rswap.paymentspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.bobpaymentaddr,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,Adest,Bdest); + rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.alicecoin,rswap.alicepaymentaddr,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,AAdest,ABdest); + rswap.depositspent = basilisk_swap_spendupdate(rswap.bobcoin,rswap.bobdepositaddr,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,Adest,Bdest); rswap.finishedflag = basilisk_swap_isfinished(rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent); if ( rswap.iambob == 0 ) { From 0e0558c7e5e20aa345083c3db1f63bc1a617ce64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 21:47:21 +0300 Subject: [PATCH 513/520] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ac628c15f..0c43d6503 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -511,7 +511,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int coin->lastscanht = coin->firstscanht; continue; } - printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); + //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); From 241188e9a08308699079bdc72561e08725151d73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 21:50:27 +0300 Subject: [PATCH 514/520] Test --- iguana/exchanges/LP_remember.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index fc0bada18..b70fc10ff 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -251,7 +251,7 @@ bits256 basilisk_swap_spendupdate(char *symbol,char *spentaddr,int32_t *sentflag { if ( (histobj= electrum_address_gethistory(symbol,coin->electrum,&histobj,spentaddr)) != 0 ) { - printf("processed history.(%s)\n",jprint(histobj,0)); + //printf("processed history.(%s)\n",jprint(histobj,0)); free_json(histobj); } } From 602d865f2a6ee2e76fc58df99974a721f94496bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 21:52:02 +0300 Subject: [PATCH 515/520] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index c3b4ede4d..e4727bada 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -469,7 +469,7 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * height = jint(item,"height"); if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { - char str[65]; printf("history txinit %s ht.%d\n",bits256_str(str,txid),height); + //char str[65]; printf("history txinit %s ht.%d\n",bits256_str(str,txid),height); txobj = LP_transactioninit(coin,txid,0,0); txobj = LP_transactioninit(coin,txid,1,txobj); if ( txobj != 0 ) From 3d08de4ade28bfcf991cd9d96211904b2c62ced2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 21:57:16 +0300 Subject: [PATCH 516/520] Test --- iguana/exchanges/LP_nativeDEX.c | 5 ----- iguana/exchanges/LP_swap.c | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0c43d6503..5968100d5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -21,17 +21,12 @@ // // new features: // -check for completed one being spent -// make remember remember or maybe to just fix? // sign, spv check // bittrex balancing // withdraw // stats, fix pricearray // better error message in ordermatch // verify portfolio -// alice doesnt detect swap complete and electrum doesnt get .finished after swapstatus. ok, seems like an electrum tx construction/detection issue in the swapstatus path and some wonkiness with SWAP complete detection in general. I need to cleanup that logic a lot - -// unduplicated bugs: -// swap cancel should cleanly cancel #include #include "LP_include.h" diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 50fd58e36..1a475a377 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -756,7 +756,7 @@ void LP_bobloop(void *_swap) } } basilisk_swap_finished(swap); - free(swap); + //free(swap); } else printf("swap timed out\n"); } From 7ae3b102a36e9105a3d884cfee7c3eaf2d31d687 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 22:17:39 +0300 Subject: [PATCH 517/520] Detect and skip status for realtime swaps --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- iguana/exchanges/LP_remember.c | 18 +++++++++++++----- iguana/exchanges/LP_swap.c | 3 +++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5968100d5..7923911c3 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -21,11 +21,11 @@ // // new features: // -check for completed one being spent +// better error message in ordermatch +// withdraw // sign, spv check // bittrex balancing -// withdraw // stats, fix pricearray -// better error message in ordermatch // verify portfolio #include @@ -53,16 +53,16 @@ int32_t LP_mypullsock = -1; int32_t LP_showwif,IAMLP = 0; double LP_profitratio = 1.; - struct LP_privkey { bits256 privkey; uint8_t rmd160[20]; }; struct LP_globals { struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; bits256 LP_mypub25519,LP_mypriv25519; + uint64_t LP_skipstatus[10000]; uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; - int32_t LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting; + int32_t LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting,LP_numskips; char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16]; struct LP_privkey LP_privkeys[100]; } G; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index b70fc10ff..edfb8ac2a 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1037,7 +1037,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti char *basilisk_swaplist() { - char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t quoteid,requestid; int64_t KMDtotals[16],BTCtotals[16],Btotal,Ktotal; int32_t i; + char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t r,q,quoteid,requestid; int64_t KMDtotals[16],BTCtotals[16],Btotal,Ktotal; int32_t i; portable_mutex_lock(&LP_swaplistmutex); memset(KMDtotals,0,sizeof(KMDtotals)); memset(BTCtotals,0,sizeof(BTCtotals)); @@ -1052,13 +1052,21 @@ char *basilisk_swaplist() while ( fread(&requestid,1,sizeof(requestid),fp) == sizeof(requestid) && fread("eid,1,sizeof(quoteid),fp) == sizeof(quoteid) ) { flag = 0; - /*for (i=0; inumswaps; i++) - if ( (swap= myinfo->swaps[i]) != 0 && swap->I.req.requestid == requestid && swap->I.req.quoteid == quoteid ) + for (i=0; i> 32); + q = (uint32_t)G.LP_skipstatus[i]; + if ( r == requestid && q == quoteid ) { - jaddi(array,basilisk_swapjson(swap)); + item = cJSON_CreateObject(); + jaddstr(item,"status","realtime"); + jaddnum(item,"requestid",r); + jaddnum(item,"quoteid",q); + jaddi(array,item); flag = 1; break; - }*/ + } + } if ( flag == 0 ) { if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid)) != 0 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 1a475a377..e08f3aa36 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -1071,6 +1071,9 @@ struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256 swap->ctx = bitcoin_ctx(); vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); swap->I.req = *rp; + G.LP_skipstatus[G.LP_numskips] = ((uint64_t)rp->requestid << 32) | rp->quoteid; + if ( G.LP_numskips < sizeof(G.LP_skipstatus)/sizeof(*G.LP_skipstatus) ) + G.LP_numskips++; printf("basilisk_thread_start request.%u iambob.%d (%s/%s) quoteid.%u\n",rp->requestid,iambob,rp->src,rp->dest,rp->quoteid); bitcoin_pubkey33(swap->ctx,pubkey33,privkey); pubkey25519 = curve25519(privkey,curve25519_basepoint9()); From 6ab3edcd50002cc20949835e929bff36ae05a085 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Oct 2017 22:19:02 +0300 Subject: [PATCH 518/520] test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7923911c3..f122b1ddd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -516,7 +516,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int LP_getestimatedrate(coin); break; } - if ( 0 && (counter % 6000) == 60 ) + if ( (counter % 6000) == 60 ) { if ( (retstr= basilisk_swapentry(0,0)) != 0 ) { From c53ef2042eb1250fd86c70679e63f6996f22107d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Oct 2017 06:52:28 +0300 Subject: [PATCH 519/520] 4 new coins --- iguana/exchanges/LP_nativeDEX.c | 9 +++++---- iguana/exchanges/coins | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f122b1ddd..e2dda7882 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -20,13 +20,14 @@ // marketmaker // // new features: -// -check for completed one being spent // better error message in ordermatch // withdraw -// sign, spv check -// bittrex balancing +// sign packets +// spv check // stats, fix pricearray // verify portfolio +// bittrex balancing +// -check for completed one being spent #include #include "LP_include.h" @@ -513,7 +514,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int continue; } coin->lastscanht++; - LP_getestimatedrate(coin); + //LP_getestimatedrate(coin); break; } if ( (counter % 6000) == 60 ) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index 258a3be5e..25af22269 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,2 +1,2 @@ -export coins="[{\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"Mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":50000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":1000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" +export coins="[{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":10000}, {\"coin\":\"ZEN\",\"name\":\"zen\",\"rpcport\":8231,\"pubtype\":137,\"taddr\":32,\"p2shtype\":150,\"wiftype\":128,\"txfee\":10000},{\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"Mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":50000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":1000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" From d96af63dbbfbab8b0cd751ff578e6766aa1ae1ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 6 Oct 2017 15:48:41 +0300 Subject: [PATCH 520/520] MNZ support --- iguana/coins/basilisk/mnz | 2 ++ iguana/coins/mnz_7776 | 2 ++ iguana/exchanges/LP_nativeDEX.c | 2 ++ iguana/iguana_notary.c | 2 +- iguana/m_notary | 1 + 5 files changed, 8 insertions(+), 1 deletion(-) create mode 100755 iguana/coins/basilisk/mnz create mode 100755 iguana/coins/mnz_7776 diff --git a/iguana/coins/basilisk/mnz b/iguana/coins/basilisk/mnz new file mode 100755 index 000000000..d08d34075 --- /dev/null +++ b/iguana/coins/basilisk/mnz @@ -0,0 +1,2 @@ +curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"MNZ.conf\",\"path\":\"${HOME#"/"}/.komodo/MNZ\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":0,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"MNZ\",\"name\":\"MNZ\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"53d06fde\",\"p2p\":14336,\"rpc\":14337,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" + diff --git a/iguana/coins/mnz_7776 b/iguana/coins/mnz_7776 new file mode 100755 index 000000000..cdbe97124 --- /dev/null +++ b/iguana/coins/mnz_7776 @@ -0,0 +1,2 @@ +curl --url "http://127.0.0.1:7778" --data "{\"conf\":\"MNZ.conf\",\"path\":\"${HOME#"/"}/.komodo/MNZ\",\"unitval\":\"20\",\"zcash\":1,\"RELAY\":-1,\"VALIDATE\":0,\"prefetchlag\":-1,\"poll\":100,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":4,\"services\":129,\"maxpeers\":8,\"newcoin\":\"MNZ\",\"name\":\"MNZ\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"53d06fde\",\"p2p\":14336,\"rpc\":14337,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\",\"debug\":0,\"seedipaddr\":\"78.47.196.146\"}" + diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e2dda7882..769670543 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -24,9 +24,11 @@ // withdraw // sign packets // spv check +// dPoW security // stats, fix pricearray // verify portfolio // bittrex balancing + // -check for completed one being spent #include diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index a8518be7b..b04431d4d 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -435,7 +435,7 @@ STRING_ARG(iguana,addnotary,ipaddr) char NOTARY_CURRENCIES[][16] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", "CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", - "REVS", "SUPERNET", "DEX", "PANGEA", "JUMBLR", "BET", "CRYPTO", "HODL", "SHARK", "BOTS", "MGW", "COQUI", "WLC", "KV", "CEAL", "MESH", "LTC" }; + "REVS", "SUPERNET", "DEX", "PANGEA", "JUMBLR", "BET", "CRYPTO", "HODL", "SHARK", "BOTS", "MGW", "COQUI", "WLC", "KV", "CEAL", "MESH", "LTC", "MNZ" }; ZERO_ARGS(dpow,notarychains) { diff --git a/iguana/m_notary b/iguana/m_notary index d2c82c7c0..d514d2680 100755 --- a/iguana/m_notary +++ b/iguana/m_notary @@ -41,6 +41,7 @@ coins/wlc_7776 coins/kv_7776 coins/ceal_7776 coins/mesh_7776 +coins/mnz_7776 curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"passthru\",\"method\":\"paxfiats\",\"timeout\":900000}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"$myip\"}"