From e655f82bfb434533aef90923bca05944d2250165 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Nov 2017 23:02:44 +0200 Subject: [PATCH 1/5] Bot status --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 1 - iguana/exchanges/LP_ordermatch.c | 37 ++++++++++++++++++++++++++++++-- iguana/exchanges/LP_tradebots.c | 28 +++++++++++++++++++++++- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 314cf975a..e5a045e33 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -392,6 +392,7 @@ uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); int32_t LP_coinbus(uint16_t coin_busport); int32_t LP_nanomsg_recvs(void *ctx); +void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid,uint32_t quoteid); uint64_t LP_RTsmartbalance(struct iguana_info *coin); int32_t LP_getheight(struct iguana_info *coin); int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 28be65d12..13b14f8ee 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,7 +19,6 @@ // marketmaker // // detecting new deposits in inventory -// BTC swaps // bot progress // swap started event for bot // bot status 1600% ? diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9f815a585..f6e1f325f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -464,9 +464,15 @@ 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; if ( LP_quoteparse(&Q,argjson) < 0 ) + { + LP_aliceid(Q.tradeid,Q.aliceid,"error0",0,0); clonestr("{\"error\":\"cant parse quote\"}"); + } if ( bits256_cmp(Q.desthash,G.LP_mypub25519) != 0 ) + { + LP_aliceid(Q.tradeid,Q.aliceid,"error1",0,0); return(clonestr("{\"result\",\"update stats\"}")); + } printf("CONNECTED.(%s) numpending.%d tradeid.%u\n",jprint(argjson,0),G.LP_pendingswaps,Q.tradeid); /*if ( LP_alice_eligible() == 0 || LP_quotecmp(&Q,&LP_Alicequery) != 0 ) { @@ -479,16 +485,22 @@ char *LP_connectedalice(cJSON *argjson) // alice if ( (autxo= LP_utxopairfind(0,Q.desttxid,Q.destvout,Q.feetxid,Q.feevout)) == 0 ) { printf("cant find autxo\n"); + LP_aliceid(Q.tradeid,Q.aliceid,"error2",0,0); return(clonestr("{\"error\":\"cant find autxo\"}")); } if ( autxo->S.swap != 0 ) + { + LP_aliceid(Q.tradeid,Q.aliceid,"error3",0,0); return(clonestr("{\"error\":\"ignore duplicate swap\"}")); + } + LP_aliceid(Q.tradeid,Q.aliceid,"connected",Q.R.requestid,Q.R.quoteid); butxo = &B; memset(butxo,0,sizeof(*butxo)); LP_abutxo_set(0,butxo,&Q); if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL ) { LP_availableset(autxo); + LP_aliceid(Q.tradeid,Q.aliceid,"error4",0,0); printf("quote validate error %.0f\n",qprice); return(clonestr("{\"error\":\"quote validation error\"}")); } @@ -496,12 +508,16 @@ 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_aliceid(Q.tradeid,Q.aliceid,"error5",0,0); return(clonestr("{\"error\":\"no price set\"}")); } 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 ) + { + LP_aliceid(Q.tradeid,Q.aliceid,"error6",0,0); return(clonestr("{\"error\":\"cant get alicecoin\"}")); + } Q.privkey = LP_privkey(Q.destaddr,coin->taddr); if ( bits256_nonz(Q.privkey) != 0 )//&& Q.quotetime >= Q.timestamp-3 ) { @@ -511,10 +527,14 @@ char *LP_connectedalice(cJSON *argjson) // alice { jaddstr(retjson,"error","couldnt swapinit"); LP_availableset(autxo); + LP_aliceid(Q.tradeid,Q.aliceid,"error7",Q.R.requestid,Q.R.quoteid); return(jprint(retjson,1)); } if ( (pairstr= jstr(argjson,"pair")) == 0 || (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 ) + { + LP_aliceid(Q.tradeid,Q.aliceid,"error8",Q.R.requestid,Q.R.quoteid); jaddstr(retjson,"error","couldnt create pairsock"); + } else if ( nn_connect(pairsock,pairstr) >= 0 ) { //timeout = 1; @@ -524,6 +544,7 @@ char *LP_connectedalice(cJSON *argjson) // alice swap->N.pair = pairsock; autxo->S.swap = swap; swap->utxo = autxo; + LP_aliceid(Q.tradeid,Q.aliceid,"started",Q.R.requestid,Q.R.quoteid); printf("alice pairstr.(%s) pairsock.%d\n",pairstr,pairsock); if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_aliceloop,(void *)swap) == 0 ) { @@ -531,8 +552,18 @@ char *LP_connectedalice(cJSON *argjson) // alice jaddstr(retjson,"result","success"); //jaddnum(retjson,"requestid",Q.R.requestid); //jaddnum(retjson,"quoteid",Q.R.quoteid); - } else jaddstr(retjson,"error","couldnt aliceloop"); - } else printf("connect error %s\n",nn_strerror(nn_errno())); + } + else + { + LP_aliceid(Q.tradeid,Q.aliceid,"error9",Q.R.requestid,Q.R.quoteid); + jaddstr(retjson,"error","couldnt aliceloop"); + } + } + else + { + LP_aliceid(Q.tradeid,Q.aliceid,"error10",Q.R.requestid,Q.R.quoteid); + printf("connect error %s\n",nn_strerror(nn_errno())); + } printf("connected result.(%s)\n",jprint(retjson,0)); if ( jobj(retjson,"error") != 0 ) LP_availableset(autxo); @@ -541,6 +572,7 @@ char *LP_connectedalice(cJSON *argjson) // alice else { LP_availableset(autxo); + LP_aliceid(Q.tradeid,Q.aliceid,"error11",0,0); printf("no privkey found coin.%s %s taddr.%u\n",Q.destcoin,Q.destaddr,coin->taddr); return(clonestr("{\"error\",\"no privkey\"}")); } @@ -658,6 +690,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && LP_alice_eligible() > 0 ) { + LP_aliceid(Q.tradeid,Q.aliceid,"reserved",0,0); printf("alice %s received RESERVED.(%s)\n",bits256_str(str,G.LP_mypub25519),jprint(argjson,0)); if ( (retstr= LP_quotereceived(argjson)) != 0 ) free(retstr); diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index e42fc369c..862d68883 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -27,7 +27,7 @@ struct LP_tradebot_trade uint64_t aliceid; int32_t dispdir; uint32_t started,finished,requestid,quoteid,tradeid; - char base[32],rel[32]; + char base[32],rel[32],event[32]; }; struct LP_tradebot @@ -100,11 +100,15 @@ cJSON *LP_tradebot_tradejson(struct LP_tradebot_trade *tp,int32_t dispflag) double price,basevol; cJSON *item = cJSON_CreateObject(); if ( tp == 0 ) return(cJSON_Parse("{}")); + if ( tp->event[0] != 0 ) + jaddstr(item,"status",tp->event); if ( tp->requestid != 0 && tp->quoteid != 0 ) { jaddnum(item,"requestid",tp->requestid); jaddnum(item,"quoteid",tp->quoteid); } else jaddnum(item,"tradeid",tp->tradeid); + if ( tp->aliceid != 0 ) + jadd64bits(item,"aliceid",tp->aliceid); if ( tp->basevol > SMALLVAL && tp->relvol > SMALLVAL ) { if ( dispflag > 0 ) @@ -338,6 +342,28 @@ void LP_tradebot_timeslice(void *ctx,struct LP_tradebot *bot) bot->pause = (uint32_t)time(NULL); } +void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid,uint32_t quoteid) +{ + struct LP_tradebot *bot,*tmp; int32_t i; struct LP_tradebot_trade *tp; + DL_FOREACH_SAFE(LP_tradebots,bot,tmp) + { + for (i=0; inumtrades; i++) + { + if ( (tp= bot->trades[i]) != 0 && tp->finished == 0 && tp->tradeid == tradeid ) + { + tp->aliceid = aliceid; + if ( requestid != 0 && quoteid != 0 ) + { + tp->requestid = requestid; + tp->quoteid = quoteid; + } + strcpy(tp->event,event); + break; + } + } + } +} + void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid) { struct LP_tradebot *bot,*tmp; int32_t i; struct LP_tradebot_trade *tp; From 76dcacdbe483d64dbbba7898745bc5f2b755b9b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Nov 2017 23:24:05 +0200 Subject: [PATCH 2/5] Test --- iguana/exchanges/LP_utxo.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 17814f4be..076e6729d 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -118,22 +118,22 @@ 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 ) { - char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); + //char str[65]; printf("%s/v%d not available\n",bits256_str(str,txid),vout); return(utxo); } 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); + //char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); 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); + //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); + //char str[65]; printf("%s/v%d not available2\n",bits256_str(str,txid),vout); return(utxo); } return(0); @@ -976,10 +976,14 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol int32_t LP_inventory_prevent(int32_t iambob,char *symbol,bits256 txid,int32_t vout) { - struct LP_utxoinfo *utxo; struct LP_transaction *tx; struct iguana_info *coin; + struct LP_address_utxo *up; struct LP_utxoinfo *utxo; struct LP_transaction *tx; struct iguana_info *coin; + if ( (coin= LP_coinfind(symbol)) == 0 ) + return(1); + if ( LP_allocated(txid,vout) != 0 ) + return(1); if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 ) { - if ( (coin= LP_coinfind(symbol)) != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) + if ( coin != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) { if ( tx->outpoints[vout].spendheight > 0 ) utxo->T.spentflag = tx->outpoints[vout].spendheight; @@ -991,6 +995,8 @@ int32_t LP_inventory_prevent(int32_t iambob,char *symbol,bits256 txid,int32_t vo return(1); } } + if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) != 0 && up->spendheight > 0 ) + return(1); return(0); } From 58548ead1062c3d924ed411c5ba5925b8ec88b90 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Nov 2017 23:41:59 +0200 Subject: [PATCH 3/5] 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 f7bf6a38f..661c476e6 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -635,7 +635,7 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) sprintf(buf,"[%d, 99999999, [\"%s\"]]",numconfs,coinaddr); return(bitcoin_json(coin,"listunspent",buf)); } else return(LP_address_utxos(coin,coinaddr,0)); - } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr,2)); + } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr,1)); } int32_t LP_listunspent_issue(char *symbol,char *coinaddr,int32_t fullflag) From cd5f624e73ae7490cf7c0865740a233d217233e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 00:30:27 +0200 Subject: [PATCH 4/5] Test --- iguana/exchanges/LP_nativeDEX.c | 3 --- iguana/exchanges/LP_ordermatch.c | 8 ++++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 13b14f8ee..b51741787 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -18,9 +18,6 @@ // LP_nativeDEX.c // marketmaker // -// detecting new deposits in inventory -// bot progress -// swap started event for bot // bot status 1600% ? // BCH signing diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index f6e1f325f..cf4560de3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1010,15 +1010,15 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel destsatoshis = SATOSHIDEN * relvolume; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis + 2*desttxfee)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxo that is big enough\"}")); - if ( destsatoshis - 0*desttxfee < autxo->S.satoshis ) + if ( destsatoshis - desttxfee < autxo->S.satoshis ) { - //destsatoshis -= 2*desttxfee; + destsatoshis -= desttxfee; autxo->S.satoshis = destsatoshis; //printf("first path dest %.8f from %.8f\n",dstr(destsatoshis),dstr(autxo->S.satoshis)); } - else if ( autxo->S.satoshis - 0*desttxfee < destsatoshis ) + else if ( autxo->S.satoshis - desttxfee < destsatoshis ) { - autxo->S.satoshis -= 0*desttxfee; + autxo->S.satoshis -= desttxfee; destsatoshis = autxo->S.satoshis; printf("second path dest %.8f from %.8f\n",dstr(destsatoshis),dstr(autxo->S.satoshis)); } From eb3d403d0c97f4d25e92d5ce2b42996d16e8ad37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 00:44:26 +0200 Subject: [PATCH 5/5] 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 cf4560de3..f6e1f325f 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1010,15 +1010,15 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel destsatoshis = SATOSHIDEN * relvolume; if ( (autxo= LP_utxo_bestfit(rel,destsatoshis + 2*desttxfee)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxo that is big enough\"}")); - if ( destsatoshis - desttxfee < autxo->S.satoshis ) + if ( destsatoshis - 0*desttxfee < autxo->S.satoshis ) { - destsatoshis -= desttxfee; + //destsatoshis -= 2*desttxfee; autxo->S.satoshis = destsatoshis; //printf("first path dest %.8f from %.8f\n",dstr(destsatoshis),dstr(autxo->S.satoshis)); } - else if ( autxo->S.satoshis - desttxfee < destsatoshis ) + else if ( autxo->S.satoshis - 0*desttxfee < destsatoshis ) { - autxo->S.satoshis -= desttxfee; + autxo->S.satoshis -= 0*desttxfee; destsatoshis = autxo->S.satoshis; printf("second path dest %.8f from %.8f\n",dstr(destsatoshis),dstr(autxo->S.satoshis)); }