From 3c98281e3277be214dfb8b65dd1f0e05435a9a4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 17 Jun 2017 18:30:00 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 3 +++ iguana/exchanges/LP_include.h | 6 ++--- iguana/exchanges/LP_nativeDEX.c | 5 ----- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/LP_prices.c | 23 ++++++++++++++++++- iguana/exchanges/LP_swap.c | 37 ++++++++++++++++--------------- iguana/exchanges/LP_transaction.c | 7 +++--- 7 files changed, 52 insertions(+), 31 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 05088c558..bcbd2541b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -68,6 +68,7 @@ getutxos()\n\ getutxos(coin, lastn)\n\ orderbook(base, rel)\n\ getprices(base, rel)\n\ +trust(pubkey, trust)\n\ register(pubkey,pushaddr)\n\ lookup(pubkey)\n\ forward(pubkey,method2,)\n\ @@ -168,6 +169,8 @@ forwardhex(pubkey,hex)\n\ } else if ( strcmp(method,"myprices") == 0 ) return(LP_myprices()); + else if ( strcmp(method,"trust") == 0 ) + return(LP_pubkey_trustset(jbits256(argjson,"pubkey"),jint(argjson,"trust"))); } if ( LP_isdisabled(base,rel) != 0 ) retstr = clonestr("{\"error\":\"at least one of coins disabled\"}"); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 8a2636dd3..34a4bd009 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -40,14 +40,14 @@ #define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" #define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" -#define BASILISK_DISABLEWAITTX -#define BASILISK_DISABLESENDTX +//#define BASILISK_DISABLEWAITTX +//#define BASILISK_DISABLESENDTX #define LP_PROPAGATION_SLACK 100 // txid ordering is not enforced, so getting extra recent txid #define LP_RESERVETIME 60 #define LP_AVETXSIZE 200 #define LP_CACHEDURATION 60 -#define BASILISK_DEFAULT_NUMCONFIRMS 5 +#define BASILISK_DEFAULT_NUMCONFIRMS 2 #define DEX_SLEEP 3 #define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2)) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9b7c42610..4678cbce7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -38,11 +38,6 @@ double LP_profitratio = 1.; bits256 LP_mypubkey; // stubs -int32_t basilisk_istrustedbob(struct basilisk_swap *swap) -{ - // for BTC and if trusted LP - return(0); -} void tradebot_swap_balancingtrade(struct basilisk_swap *swap,int32_t iambob) { diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 7fd4414b4..58783ad03 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -77,7 +77,7 @@ uint32_t LP_swapsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbit { } } - printf("sent %d bytes\n",sentbytes); + //printf("sent %d bytes\n",sentbytes); //else printf("send.[%d] %x offset.%d datalen.%d [%llx]\n",sentbytes,msgbits,offset,datalen,*(long long *)data); free(buf); return(nextbits); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 8d55d3e02..3bbdfe01c 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -46,7 +46,7 @@ struct LP_pubkeyinfo UT_hash_handle hh; bits256 pubkey; double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; - uint32_t timestamp; + uint32_t timestamp,istrusted; } *LP_pubkeyinfos; struct LP_priceinfo *LP_priceinfofind(char *symbol) @@ -134,6 +134,25 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey) return(pubp); } +int32_t LP_pubkey_istrusted(bits256 pubkey) +{ + struct LP_pubkeyinfo *pubp; + if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) + return(pubp->istrusted != 0); + return(0); +} + +char *LP_pubkey_trustedset(bits256 pubkey,uint32_t trustval) +{ + struct LP_pubkeyinfo *pubp; + if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) + { + pubp->istrusted = trustval; + return(clonestr("{\"result\":\"success\"}")); + } + return(clonestr("{\"error\":\"pubkey not found\"}")); +} + cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) { int32_t baseid,relid; char *base; double price; cJSON *item,*array,*obj; @@ -157,6 +176,8 @@ cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp) jaddbits256(obj,"pubkey",pubp->pubkey); jaddnum(obj,"timestamp",pubp->timestamp); jadd(obj,"asks",array); + if ( pubp->istrusted != 0 ) + jaddnum(obj,"istrusted",pubp->istrusted); return(obj); } diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index ef8cc573f..f310e0fa2 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -139,12 +139,9 @@ void basilisk_swap_finished(struct basilisk_swap *swap) free(swap->messages), swap->messages = 0; swap->nummessages = 0; if ( swap->N.pair >= 0 ) - nn_close(swap->N.pair); + nn_close(swap->N.pair), swap->N.pair = -1; if ( swap->utxo != 0 ) - { - printf("make available\n"); LP_availableset(swap->utxo); - } } uint32_t basilisk_quoteid(struct basilisk_request *rp) @@ -686,7 +683,7 @@ void LP_bobloop(void *_swap) swap->bobreclaim.utxovout = 0; swap->bobreclaim.utxotxid = swap->bobpayment.I.signedtxid; basilisk_bobpayment_reclaim(swap,swap->I.callduration); - while ( LP_numconfirms(swap,&swap->alicepayment) < 1 ) + while ( LP_numconfirms(swap,&swap->alicepayment) < swap->I.aliceconfirms ) { printf("waiting for alicepayment to confirm\n"); sleep(3); @@ -731,7 +728,7 @@ void LP_aliceloop(void *_swap) printf("error sending alicepayment\n"); else { - while ( LP_numconfirms(swap,&swap->alicepayment) < 1 ) + while ( LP_numconfirms(swap,&swap->alicepayment) < swap->I.aliceconfirms ) { printf("waiting for alicepayment to confirm\n"); sleep(3); @@ -740,14 +737,14 @@ void LP_aliceloop(void *_swap) printf("error waiting for bobpayment\n"); else { - while ( LP_numconfirms(swap,&swap->bobpayment) < 1 ) + while ( LP_numconfirms(swap,&swap->bobpayment) < swap->I.bobconfirms ) { printf("waiting for bobpayment to confirm\n"); 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 ( LP_numconfirms(swap,&swap->alicespend) < 1 ) + while ( LP_numconfirms(swap,&swap->alicespend) < swap->I.aliceconfirms ) { printf("waiting for alicespend to confirm\n"); sleep(LP_SWAPSTEP_TIMEOUT); @@ -843,6 +840,9 @@ int32_t instantdex_pubkeyargs(struct basilisk_swap *swap,int32_t numpubs,bits256 void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33,int32_t jumblrflag) { +#ifdef BASILISK_DISABLEWAITTX + numconfirms = 0; +#endif strcpy(rawtx->name,name); rawtx->coin = coin; strcpy(rawtx->I.coinstr,coin->symbol); @@ -874,7 +874,7 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx * struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,struct LP_quoteinfo *qp) { //FILE *fp; char fname[512]; - uint8_t *alicepub33=0,*bobpub33=0; int32_t jumblrflag=-2,x = -1; struct iguana_info *coin; + uint8_t *alicepub33=0,*bobpub33=0; int32_t bobistrusted,aliceistrusted,jumblrflag=-2,x = -1; struct iguana_info *coin; swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME; if ( optionduration < 0 ) swap->I.putduration -= optionduration; @@ -900,11 +900,15 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 { swap->I.iambob = 0; swap->I.otherhash = swap->I.req.desthash; + aliceistrusted = 1; + bobistrusted = LP_pubkey_istrusted(swap->I.req.desthash); } else { swap->I.iambob = 1; swap->I.otherhash = swap->I.req.srchash; + bobistrusted = 1; + aliceistrusted = LP_pubkey_istrusted(swap->I.req.desthash); } if ( bits256_nonz(privkey) == 0 || (x= instantdex_pubkeyargs(swap,2 + INSTANTDEX_DECKSIZE,privkey,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE ) { @@ -929,24 +933,21 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 } if ( strcmp("BTC",swap->bobcoin.symbol) == 0 ) { - swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1)); - swap->I.aliceconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.bobconfirms * 3); + swap->I.bobconfirms = (1 + sqrt(dstr(swap->I.bobsatoshis) * .1)); + swap->I.aliceconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.bobconfirms + 1); } else if ( strcmp("BTC",swap->alicecoin.symbol) == 0 ) { - swap->I.aliceconfirms = (1*0 + sqrt(dstr(swap->I.alicesatoshis) * .1)); - swap->I.bobconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.bobconfirms * 3); + swap->I.aliceconfirms = (1 + sqrt(dstr(swap->I.alicesatoshis) * .1)); + swap->I.bobconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.aliceconfirms + 1); } else { swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; } - /*if ( swap->I.bobconfirms == 0 ) - swap->I.bobconfirms = swap->bobcoin->chain->minconfirms; - if ( swap->I.aliceconfirms == 0 ) - swap->I.aliceconfirms = swap->alicecoin->chain->minconfirms;*/ - //jumblrflag = (bits256_cmp(pubkey25519,myinfo->jumblr_pubkey) == 0 || bits256_cmp(pubkey25519,myinfo->jumblr_depositkey) == 0); + swap->I.bobconfirms *= !bobistrusted; + swap->I.aliceconfirms *= !aliceistrusted; printf(">>>>>>>>>> jumblrflag.%d <<<<<<<<< use smart address, %.8f bobconfs.%d, %.8f aliceconfs.%d\n",jumblrflag,dstr(swap->I.bobsatoshis),swap->I.bobconfirms,dstr(swap->I.alicesatoshis),swap->I.aliceconfirms); if ( swap->I.iambob != 0 ) { diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 2ba86473c..54fd5da35 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -251,16 +251,17 @@ int32_t LP_mempool_vinscan(bits256 *spendtxidp,int32_t *spendvinp,char *symbol,b int32_t LP_numconfirms(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx) { int32_t numconfirms = 100; -#ifndef BASILISK_DISABLEWAITTX +//#ifndef BASILISK_DISABLEWAITTX cJSON *txobj; numconfirms = -1; if ( (txobj= LP_gettx(rawtx->coin->symbol,rawtx->I.signedtxid)) != 0 ) { numconfirms = jint(txobj,"confirmations"); free_json(txobj); - } else if ( LP_mempoolscan(rawtx->coin->symbol,rawtx->I.signedtxid) >= 0 ) + } + else if ( LP_mempoolscan(rawtx->coin->symbol,rawtx->I.signedtxid) >= 0 ) numconfirms = 0; -#endif +//#endif return(numconfirms); }