From bf692cf56c4a8684624b952035d0e74711553a13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 28 Nov 2017 15:46:43 +0400 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 4 +- iguana/exchanges/LP_include.h | 6 +- .../{LP_zeroconf.c => LP_instantdex.c} | 131 ++++++++++++++---- iguana/exchanges/LP_nativeDEX.c | 12 +- iguana/exchanges/LP_ordermatch.c | 22 ++- iguana/exchanges/LP_prices.c | 4 +- iguana/exchanges/LP_signatures.c | 25 ++-- 7 files changed, 149 insertions(+), 55 deletions(-) rename iguana/exchanges/{LP_zeroconf.c => LP_instantdex.c} (69%) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 2fb3349a0..aa80406d4 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -198,7 +198,7 @@ zeroconf_claim(address, expiration=0)\n\ { if ( jint(argjson,"weeks") < 0 || jdouble(argjson,"amount") < 10. ) return(clonestr("{\"error\":\"deposit_create needs to have weeks and amount\"}")); - else return(LP_zeroconf_deposit(ptr,juint(argjson,"weeks"),jdouble(argjson,"amount"),jint(argjson,"broadcast"))); + else return(LP_instantdex_deposit(ptr,juint(argjson,"weeks"),jdouble(argjson,"amount"),jint(argjson,"broadcast"))); } return(clonestr("{\"error\":\"cant find KMD\"}")); } @@ -208,7 +208,7 @@ zeroconf_claim(address, expiration=0)\n\ { if ( jstr(argjson,"address") == 0 ) return(clonestr("{\"error\":\"deposit_claim needs to have address\"}")); - else return(LP_zeroconf_claim(ptr,jstr(argjson,"address"),juint(argjson,"expiration"))); + else return(LP_instantdex_claim(ptr,jstr(argjson,"address"),juint(argjson,"expiration"))); } return(clonestr("{\"error\":\"cant find KMD\"}")); } diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 963e9ccda..9885474a4 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -332,7 +332,7 @@ struct LP_address uint32_t timestamp,n,unspenttime; int32_t unspentheight; char coinaddr[40]; - uint8_t pubsecp[33],pad; + uint8_t pubsecp[33],didinstantdex; }; struct LP_peerinfo @@ -404,7 +404,7 @@ struct LP_pubkey_info bits256 pubkey; struct LP_pubkey_quote *quotes; struct LP_pubswap *bobswaps,*aliceswaps; - int64_t dynamictrust,unconfdeposits; + int64_t dynamictrust,unconfcredits; uint32_t timestamp,numerrors,lasttime,slowresponse; int32_t istrusted; uint8_t rmd160[20],sig[65],pubsecp[33],siglen; @@ -428,7 +428,7 @@ struct LP_trade struct LP_trade *next,*prev; UT_hash_handle hh; uint64_t aliceid; - int64_t besttrust; + int64_t besttrust,bestunconfcredits; double bestprice; uint32_t negotiationdone,bestresponse,connectsent,firsttime,lasttime,firstprocessed,lastprocessed,newtime; char pairstr[64],funcid,iambob; diff --git a/iguana/exchanges/LP_zeroconf.c b/iguana/exchanges/LP_instantdex.c similarity index 69% rename from iguana/exchanges/LP_zeroconf.c rename to iguana/exchanges/LP_instantdex.c index 49177b7d5..2a258af19 100644 --- a/iguana/exchanges/LP_zeroconf.c +++ b/iguana/exchanges/LP_instantdex.c @@ -15,10 +15,55 @@ ******************************************************************************/ // -// LP_zeroconf.c +// LP_instantdex.c // marketmaker // +void LP_instantdex_txidaddfname(char *fname) +{ + sprintf(fname,"%s/instantdex.json",GLOBAL_DBDIR); +} + +cJSON *LP_instantdex_txidaddjson() +{ + char *filestr,fname[1024]; long fsize; cJSON *retjson=0; + LP_instantdex_txidaddfname(fname); + if ( (filestr= OS_filestr(&fsize,fname)) != 0 ) + { + retjson = cJSON_Parse(filestr); + free(filestr); + } + return(retjson); +} + +void LP_instantdex_txidadd(bits256 txid) +{ + cJSON *array; int32_t i,n; char fname[1024],*filestr; FILE *fp; + if ( (array= LP_instantdex_txidaddjson()) == 0 ) + array = cJSON_CreateArray(); + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i %s\n",bits256_str(str,txid),fname); + jaddibits256(array,txid); + if ( (fp= fopen(fname,"wb")) != 0 ) + { + filestr = jprint(array,0); + fwrite(filestr,1,strlen(filestr)+1,fp); + fclose(fp); + free(filestr); + } + } + } + if ( array != 0 ) + free_json(array); +} + int32_t LP_deposit_addr(char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2shtype,uint32_t timestamp,uint8_t *pubsecp33) { uint8_t elsepub33[33],p2sh_rmd160[20]; int32_t n; @@ -28,13 +73,13 @@ int32_t LP_deposit_addr(char *p2shaddr,uint8_t *script,uint8_t taddr,uint8_t p2s return(n); } -char *LP_zeroconf_deposit(struct iguana_info *coin,int32_t weeks,double amount,int32_t broadcast) +char *LP_instantdex_deposit(struct iguana_info *coin,int32_t weeks,double amount,int32_t broadcast) { char p2shaddr[64],*retstr,*hexstr; uint8_t script[512]; int32_t weeki,scriptlen; cJSON *argjson,*retjson,*array,*item,*obj; uint32_t timestamp; bits256 txid,sendtxid; uint64_t amount64; if ( strcmp(coin->symbol,"KMD") != 0 ) - return(clonestr("{\"error\":\"zeroconf deposit must be in KMD\"}")); + return(clonestr("{\"error\":\"instantdex deposit must be in KMD\"}")); if ( amount < 10.0 ) - return(clonestr("{\"error\":\"minimum zeroconf deposit is 10 KMD\"}")); + return(clonestr("{\"error\":\"minimum instantdex deposit is 10 KMD\"}")); if ( weeks < 0 || weeks > 52 ) return(clonestr("{\"error\":\"weeks must be between 0 and 52\"}")); if ( weeks > 0 ) @@ -75,6 +120,8 @@ char *LP_zeroconf_deposit(struct iguana_info *coin,int32_t weeks,double amount,i if ( (obj= jobj(retjson,"complete")) != 0 && is_cJSON_True(obj) != 0 && (hexstr= jstr(retjson,"hex")) != 0 ) { txid = jbits256(retjson,"txid"); + if ( bits256_nonz(txid) != 0 ) + LP_instantdex_txidadd(txid); if ( broadcast != 0 ) { if (bits256_nonz(txid) != 0 ) @@ -119,17 +166,17 @@ char *LP_zeroconf_deposit(struct iguana_info *coin,int32_t weeks,double amount,i } free(retstr); } - return(clonestr("{\"error\":\"error with LP_withdraw for zeroconf deposit\"}")); + return(clonestr("{\"error\":\"error with LP_withdraw for instantdex deposit\"}")); } -char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expiration) +char *LP_instantdex_claim(struct iguana_info *coin,char *depositaddr,uint32_t expiration) { static void *ctx; uint8_t redeemscript[512],userdata[64]; char vinaddr[64],str[65],*signedtx=0; uint32_t timestamp,now,redeemlen,claimtime; int32_t i,n,height,utxovout,userdatalen; bits256 signedtxid,utxotxid,sendtxid,zero; int64_t sum,destamount,satoshis; cJSON *array,*item,*txids,*retjson; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( strcmp(coin->symbol,"KMD") != 0 ) - return(clonestr("{\"error\":\"zeroconf deposit must be in KMD\"}")); + return(clonestr("{\"error\":\"instantdex deposit must be in KMD\"}")); now = (uint32_t)time(NULL); sum = 0; txids = cJSON_CreateArray(); @@ -164,7 +211,7 @@ char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expi item = jitem(array,i); satoshis = LP_listunspent_parseitem(coin,&utxotxid,&utxovout,&height,item); printf("satoshis %.8f %s/v%d\n",dstr(satoshis),bits256_str(str,utxotxid),utxovout); - if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,10000,"zeroconfclaim",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript,redeemlen,userdata,userdatalen,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,1,coin->zcash)) != 0 ) + if ( (signedtx= basilisk_swap_bobtxspend(&signedtxid,10000,"instantdexclaim",coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript,redeemlen,userdata,userdatalen,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,1,coin->zcash)) != 0 ) { printf("signedtx.(%s)\n",signedtx); sendtxid = LP_broadcast("claim","KMD",signedtx,signedtxid); @@ -175,7 +222,7 @@ char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expi } else printf("error sending %s\n",bits256_str(str,signedtxid)); free(signedtx); - } else printf("error claiming zeroconf deposit %s/v%d %.8f\n",bits256_str(str,utxotxid),utxovout,dstr(satoshis)); + } else printf("error claiming instantdex deposit %s/v%d %.8f\n",bits256_str(str,utxotxid),utxovout,dstr(satoshis)); } } free_json(array); @@ -190,10 +237,10 @@ char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expi if ( expiration != 0 ) break; } - return(clonestr("{\"error\":\"no zeroconf deposits to claim\"}")); + return(clonestr("{\"error\":\"no instantdex deposits to claim\"}")); } -void LP_zeroconf_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,int32_t weeki,char *p2shaddr) +int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,int32_t weeki,char *p2shaddr) { uint32_t timestamp; struct LP_address *ap; struct iguana_info *coin = LP_coinfind("KMD"); if ( coin != 0 ) @@ -204,11 +251,13 @@ void LP_zeroconf_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,int32_t ap->instantdex_credits += satoshis; if ( dispflag != 0 ) printf("InstantDEX credit.(%s) %.8f weeki.%d (%s) -> sum %.8f\n",coinaddr,dstr(satoshis),weeki,p2shaddr,dstr(ap->instantdex_credits)); + return(satoshis); } } + return(0); } -int64_t LP_zeroconf_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid) +int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr) { cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64]; if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 ) @@ -216,17 +265,27 @@ int64_t LP_zeroconf_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 // vout0 deposit, vout1 botsfee, vout2 smartaddress if ( (vouts= jarray(&numvouts,txjson,"vout")) > 0 && numvouts >= 3 && LP_destaddr(destaddr,jitem(vouts,2)) == 0 ) { - amount64 = LP_value_extract(jitem(vouts,1),0); - weeki = (amount64 % 10000); - item = jitem(vouts,0); - satoshis = LP_value_extract(item,0); - //printf("%s funded %.8f weeki.%d\n",destaddr,dstr(satoshis),weeki); - if ( LP_destaddr(p2shaddr,item) == 0 ) + if ( refaddr != 0 && strcmp(refaddr,destaddr) != 0 ) + { + printf("LP_instantdex_creditcalc for (%s) but deposit sent for (%s)\n",refaddr,destaddr); + } + else { - if ( (txobj= LP_gettxout(coin->symbol,p2shaddr,txid,0)) != 0 ) + amount64 = LP_value_extract(jitem(vouts,1),0); + weeki = (amount64 % 10000); + item = jitem(vouts,0); + satoshis = LP_value_extract(item,0); + //printf("%s funded %.8f weeki.%d\n",destaddr,dstr(satoshis),weeki); + if ( LP_destaddr(p2shaddr,item) == 0 ) { - free_json(txobj); - LP_zeroconf_credit(dispflag,destaddr,satoshis,weeki,p2shaddr); + if ( (txobj= LP_gettxout(coin->symbol,p2shaddr,txid,0)) != 0 ) + { + free_json(txobj); + if ( LP_instantdex_credit(dispflag,destaddr,satoshis,weeki,p2shaddr) > 0 && strcmp(coin->symbol,"KMD") == 0 && strcmp(destaddr,coin->smartaddr) == 0 ) + { + LP_instantdex_txidadd(txid); + } + } } } } @@ -235,11 +294,29 @@ int64_t LP_zeroconf_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 return(satoshis); } -void LP_zeroconf_deposits(struct iguana_info *coin) +void LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num) +{ + uint8_t rmd160[20],addrtype; int32_t i; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0; + if ( (coin= LP_coinfind("KMD")) != 0 && coin->electrum != 0 ) + { + bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr); + bitcoin_address(othersmartaddr,0,60,rmd160,20); + if ((ap= LP_address(coin,othersmartaddr)) != 0 && ap->didinstantdex == 0 ) + { + ap->instantdex_credits = 0; + for (i=0; ididinstantdex = 1; + printf("validated instantdex %s.[%d] proof.(%s)\n",othersmartaddr,num,jprint(proof,0)); + } + } +} + +void LP_instantdex_deposits(struct iguana_info *coin) { static int dispflag = 1; cJSON *array,*item; int32_t i,n,height,vout; bits256 txid; struct LP_address *ap,*tmp; - if ( coin->electrum != 0 )//&& coin->electrumzeroconf != 0 ) + if ( coin->electrum != 0 )//&& coin->electruminstantdex != 0 ) return; HASH_ITER(hh,coin->addresses,ap,tmp) { @@ -247,7 +324,7 @@ void LP_zeroconf_deposits(struct iguana_info *coin) } if ( (array= LP_listreceivedbyaddress("KMD",BOTS_BONDADDRESS)) != 0 ) { - //printf("ZEROCONF.(%s)\n",jprint(array,0)); + //printf("instantdex.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; iswap) != 0 && sp->finished == 0 && sp->expired == 0 ) swaps_kmdvalue += LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis); } - //printf("%s zeroconf_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(ap->zeroconf_credits),dstr(swaps_kmdvalue),dstr(kmdvalue)); - //if ( ap->zeroconf_credits > swaps_kmdvalue+kmdvalue ) + //printf("%s instantdex_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(ap->instantdex_credits),dstr(swaps_kmdvalue),dstr(kmdvalue)); + //if ( ap->instantdex_credits > swaps_kmdvalue+kmdvalue ) return(ap->instantdex_credits - (swaps_kmdvalue+kmdvalue)); } } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 65615c163..88146e810 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -188,7 +188,7 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_ #include "LP_transaction.c" #include "LP_stats.c" #include "LP_remember.c" -#include "LP_zeroconf.c" +#include "LP_instantdex.c" #include "LP_swap.c" #include "LP_peers.c" #include "LP_privkey.c" @@ -651,7 +651,7 @@ void LP_coinsloop(void *_coins) 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,didzeroconf; + static uint32_t counter,didinstantdex; struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t height,nonz = 0; if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; @@ -660,10 +660,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { now = (uint32_t)time(NULL); - if ( coin->inactive == 0 && didzeroconf == 0 && strcmp("KMD",coin->symbol) == 0 ) + if ( coin->inactive == 0 && didinstantdex == 0 && strcmp("KMD",coin->symbol) == 0 ) { - LP_zeroconf_deposits(coin); - didzeroconf = now; + LP_instantdex_deposits(coin); + didinstantdex = now; } if ( (coin->addr_listunspent_requested != 0 && now > coin->lastpushtime+LP_ORDERBOOK_DURATION*.5) || now > coin->lastpushtime+LP_ORDERBOOK_DURATION*5 ) { @@ -811,7 +811,7 @@ void LP_swapsloop(void *ctx) free(retstr); sleep(600); if ( (coin= LP_coinfind("KMD")) != 0 ) - LP_zeroconf_deposits(coin); + LP_instantdex_deposits(coin); } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5ccb2ee8e..739ee4c28 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -887,6 +887,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 ) { reqjson = LP_quotejson(qp); + jadd(reqjson,"proof",LP_instantdex_txidaddjson()); LP_unavailableset(qp->txid,qp->vout,qp->timestamp + LP_RESERVETIME,qp->desthash); LP_unavailableset(qp->txid2,qp->vout2,qp->timestamp + LP_RESERVETIME,qp->desthash); if ( qp->quotetime == 0 ) @@ -963,7 +964,7 @@ struct LP_quoteinfo *LP_trades_gotconnected(void *ctx,struct LP_quoteinfo *qp,st int32_t LP_trades_bestpricecheck(void *ctx,struct LP_trade *tp) { - double qprice; struct LP_quoteinfo Q; int64_t dynamictrust; char *retstr; struct LP_pubkey_info *pubp; + double qprice; int32_t flag = 0; struct LP_quoteinfo Q; int64_t dynamictrust; char *retstr; struct LP_pubkey_info *pubp; Q = tp->Q; //printf("check bestprice %.8f vs new price %.8f\n",tp->bestprice,(double)Q.destsatoshis/Q.satoshis); if ( Q.satoshis != 0 && (pubp= LP_pubkeyfind(Q.srchash)) != 0 )//(qprice= LP_trades_alicevalidate(ctx,&Q)) > 0. ) @@ -974,13 +975,22 @@ int32_t LP_trades_bestpricecheck(void *ctx,struct LP_trade *tp) free(retstr); //LP_trades_gotreserved(ctx,&Q,&tp->Qs[LP_RESERVED]); dynamictrust = LP_dynamictrust(Q.srchash,LP_kmdvalue(Q.srccoin,Q.satoshis)); - if ( tp->bestprice == 0. || (qprice < tp->bestprice && pubp->slowresponse <= tp->bestresponse*1.05) || (qprice < tp->bestprice*1.01 && dynamictrust > tp->besttrust && pubp->slowresponse <= tp->bestresponse*1.1) ) + if ( tp->bestprice == 0. ) + flag = 1; + else if ( qprice < tp->bestprice && pubp->slowresponse <= tp->bestresponse*1.05 ) + flag = 1; + else if ( qprice < tp->bestprice*1.01 && dynamictrust > tp->besttrust && pubp->slowresponse <= tp->bestresponse*1.1 ) + flag = 1; + else if ( qprice <= tp->bestprice && pubp->unconfcredits > tp->bestunconfcredits && pubp->slowresponse <= tp->bestresponse ) + flag = 1; + if ( flag != 0 ) { tp->Qs[LP_CONNECT] = tp->Q; tp->bestprice = qprice; tp->besttrust = dynamictrust; + tp->bestunconfcredits = pubp->unconfcredits; tp->bestresponse = pubp->slowresponse; - printf("aliceid.%llu got new bestprice %.8f dynamictrust %.8f slowresponse.%d\n",(long long)tp->aliceid,tp->bestprice,dstr(dynamictrust),tp->bestresponse); + printf("aliceid.%llu got new bestprice %.8f dynamictrust %.8f (unconf %.8f) slowresponse.%d\n",(long long)tp->aliceid,tp->bestprice,dstr(dynamictrust),dstr(tp->bestunconfcredits),tp->bestresponse); return(qprice); } //else printf("qprice %.8f dynamictrust %.8f not good enough\n",qprice,dstr(dynamictrust)); } else printf("alice didnt validate\n"); @@ -1140,7 +1150,7 @@ void LP_tradecommandQ(struct LP_quoteinfo *qp,char *pairstr,int32_t funcid) int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen) { int32_t Qtrades = 1; - char *method,str[65]; int32_t DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1; + char *method,str[65]; int32_t num,DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; cJSON *proof; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1; if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) ) { LP_quoteparse(&Q,argjson); @@ -1169,6 +1179,8 @@ 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 ) { + if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 ) + LP_instantdex_proofcheck(Q.coinaddr,proof,num); if ( Qtrades == 0 ) { if ( Q.quotetime > time(NULL)-20 && LP_alice_eligible(Q.quotetime) > 0 ) @@ -1215,6 +1227,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, else if ( strcmp(method,"connect") == 0 ) { LP_bob_competition(&counter,aliceid,qprice,1000); + if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 ) + LP_instantdex_proofcheck(Q.coinaddr,proof,num); if ( Qtrades == 0 ) LP_trades_gotconnect(ctx,&Q,&Q2,jstr(argjson,"pair")); else LP_tradecommandQ(&Q,jstr(argjson,"pair"),LP_CONNECT); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index b1f236fc3..8c23d87fb 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -1084,7 +1084,7 @@ cJSON *LP_pricearray(char *base,char *rel,uint32_t firsttime,uint32_t lasttime,i return(retarray); } -void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,char *utxocoin,int32_t numrelutxos,int64_t balance,int64_t minutxo,int64_t maxutxo) +void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,char *utxocoin,int32_t numrelutxos,int64_t balance,int64_t minutxo,int64_t maxutxo,int64_t unconfcredits) { struct LP_priceinfo *basepp,*relpp; uint32_t now; int64_t price64; struct LP_pubkey_info *pubp; char str[65],fname[512]; FILE *fp; //printf("check PRICEFEED UPDATE.(%s/%s) %.8f %s\n",base,rel,price,bits256_str(str,pubkey)); @@ -1120,6 +1120,8 @@ void LP_pricefeedupdate(bits256 pubkey,char *base,char *rel,double price,char *u { if ( (LP_rand() % 1000) == 0 ) printf("PRICEFEED UPDATE.(%-6s/%6s) %12.8f %s %12.8f\n",base,rel,price,bits256_str(str,pubkey),1./price); + if ( unconfcredits > pubp->unconfcredits ) + pubp->unconfcredits = unconfcredits; pubp->timestamp = (uint32_t)time(NULL); LP_pubkey_update(pubp,basepp->ind,relpp->ind,price,balance,utxocoin,numrelutxos,minutxo,maxutxo); //pubp->depthinfo[basepp->ind][relpp->ind] = LP_depthinfo_compact(); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 80b1fb651..c73986f46 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -394,7 +394,7 @@ int32_t LP_price_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pub char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price) { - struct iguana_info *basecoin,*relcoin; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson; + struct iguana_info *basecoin,*relcoin,*kmd; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson; reqjson = cJSON_CreateObject(); // LP_addsig if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 )//&& basecoin->electrum == 0 )//&& relcoin->electrum == 0 ) @@ -411,17 +411,16 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddnum(reqjson,"timestamp",timestamp); init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",pubsecpstr); - //if ( (ap= LP_address(basecoin,basecoin->smartaddr)) != 0 ) + if ( (kmd= LP_coinfind("KMD")) != 0 && (ap= LP_address(kmd,kmd->smartaddr)) != 0 && ap->instantdex_credits != 0 ) + jaddnum(reqjson,"credits",dstr(ap->instantdex_credits)); + if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 ) { - if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 ) - { - //printf("send %s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); - jaddstr(reqjson,"utxocoin",base); - jaddnum(reqjson,"n",numutxos); - jaddnum(reqjson,"bal",dstr(balance)); - jaddnum(reqjson,"min",dstr(minsize)); - jaddnum(reqjson,"max",dstr(maxsize)); - } + //printf("send %s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),dstr(maxsize)); + jaddstr(reqjson,"utxocoin",base); + jaddnum(reqjson,"n",numutxos); + jaddnum(reqjson,"bal",dstr(balance)); + jaddnum(reqjson,"min",dstr(minsize)); + jaddnum(reqjson,"max",dstr(maxsize)); } LP_price_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,base,rel,price64); LP_reserved_msg(0,base,rel,zero,jprint(reqjson,1)); @@ -441,7 +440,7 @@ char *LP_postprice_recv(cJSON *argjson) if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 ) { //printf("call pricefeed update\n"); - LP_pricefeedupdate(pubkey,base,rel,price,jstr(argjson,"utxocoin"),jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN); + LP_pricefeedupdate(pubkey,base,rel,price,jstr(argjson,"utxocoin"),jint(argjson,"n"),jdouble(argjson,"bal")*SATOSHIDEN,jdouble(argjson,"min")*SATOSHIDEN,jdouble(argjson,"max")*SATOSHIDEN,jdouble(argjson,"credits")*SATOSHIDEN); return(clonestr("{\"result\":\"success\"}")); } else @@ -665,6 +664,8 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ jaddstr(reqjson,"method",method); if ( jobj(reqjson,"timestamp") == 0 ) jaddnum(reqjson,"timestamp",time(NULL)); + if ( strcmp(method,"connect") == 0 ) + jadd(reqjson,"proof",LP_instantdex_txidaddjson()); msg = jprint(reqjson,1); printf("QUERY.(%s)\n",msg); //if ( bits256_nonz(qp->srchash) == 0 || strcmp(method,"request") != 0 )