Browse Source

Test

etomic
jl777 7 years ago
parent
commit
3c98281e32
  1. 3
      iguana/exchanges/LP_commands.c
  2. 6
      iguana/exchanges/LP_include.h
  3. 5
      iguana/exchanges/LP_nativeDEX.c
  4. 2
      iguana/exchanges/LP_network.c
  5. 23
      iguana/exchanges/LP_prices.c
  6. 37
      iguana/exchanges/LP_swap.c
  7. 7
      iguana/exchanges/LP_transaction.c

3
iguana/exchanges/LP_commands.c

@ -68,6 +68,7 @@ getutxos()\n\
getutxos(coin, lastn)\n\ getutxos(coin, lastn)\n\
orderbook(base, rel)\n\ orderbook(base, rel)\n\
getprices(base, rel)\n\ getprices(base, rel)\n\
trust(pubkey, trust)\n\
register(pubkey,pushaddr)\n\ register(pubkey,pushaddr)\n\
lookup(pubkey)\n\ lookup(pubkey)\n\
forward(pubkey,method2,<argjson>)\n\ forward(pubkey,method2,<argjson>)\n\
@ -168,6 +169,8 @@ forwardhex(pubkey,hex)\n\
} }
else if ( strcmp(method,"myprices") == 0 ) else if ( strcmp(method,"myprices") == 0 )
return(LP_myprices()); 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 ) if ( LP_isdisabled(base,rel) != 0 )
retstr = clonestr("{\"error\":\"at least one of coins disabled\"}"); retstr = clonestr("{\"error\":\"at least one of coins disabled\"}");

6
iguana/exchanges/LP_include.h

@ -40,14 +40,14 @@
#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" #define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu"
#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" #define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf"
#define BASILISK_DISABLEWAITTX //#define BASILISK_DISABLEWAITTX
#define BASILISK_DISABLESENDTX //#define BASILISK_DISABLESENDTX
#define LP_PROPAGATION_SLACK 100 // txid ordering is not enforced, so getting extra recent txid #define LP_PROPAGATION_SLACK 100 // txid ordering is not enforced, so getting extra recent txid
#define LP_RESERVETIME 60 #define LP_RESERVETIME 60
#define LP_AVETXSIZE 200 #define LP_AVETXSIZE 200
#define LP_CACHEDURATION 60 #define LP_CACHEDURATION 60
#define BASILISK_DEFAULT_NUMCONFIRMS 5 #define BASILISK_DEFAULT_NUMCONFIRMS 2
#define DEX_SLEEP 3 #define DEX_SLEEP 3
#define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2)) #define BASILISK_KEYSIZE ((int32_t)(2*sizeof(bits256)+sizeof(uint32_t)*2))

5
iguana/exchanges/LP_nativeDEX.c

@ -38,11 +38,6 @@ double LP_profitratio = 1.;
bits256 LP_mypubkey; bits256 LP_mypubkey;
// stubs // 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) void tradebot_swap_balancingtrade(struct basilisk_swap *swap,int32_t iambob)
{ {

2
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); //else printf("send.[%d] %x offset.%d datalen.%d [%llx]\n",sentbytes,msgbits,offset,datalen,*(long long *)data);
free(buf); free(buf);
return(nextbits); return(nextbits);

23
iguana/exchanges/LP_prices.c

@ -46,7 +46,7 @@ struct LP_pubkeyinfo
UT_hash_handle hh; UT_hash_handle hh;
bits256 pubkey; bits256 pubkey;
double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS]; double matrix[LP_MAXPRICEINFOS][LP_MAXPRICEINFOS];
uint32_t timestamp; uint32_t timestamp,istrusted;
} *LP_pubkeyinfos; } *LP_pubkeyinfos;
struct LP_priceinfo *LP_priceinfofind(char *symbol) struct LP_priceinfo *LP_priceinfofind(char *symbol)
@ -134,6 +134,25 @@ struct LP_pubkeyinfo *LP_pubkeyadd(bits256 pubkey)
return(pubp); 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) cJSON *LP_pubkeyjson(struct LP_pubkeyinfo *pubp)
{ {
int32_t baseid,relid; char *base; double price; cJSON *item,*array,*obj; 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); jaddbits256(obj,"pubkey",pubp->pubkey);
jaddnum(obj,"timestamp",pubp->timestamp); jaddnum(obj,"timestamp",pubp->timestamp);
jadd(obj,"asks",array); jadd(obj,"asks",array);
if ( pubp->istrusted != 0 )
jaddnum(obj,"istrusted",pubp->istrusted);
return(obj); return(obj);
} }

37
iguana/exchanges/LP_swap.c

@ -139,13 +139,10 @@ void basilisk_swap_finished(struct basilisk_swap *swap)
free(swap->messages), swap->messages = 0; free(swap->messages), swap->messages = 0;
swap->nummessages = 0; swap->nummessages = 0;
if ( swap->N.pair >= 0 ) if ( swap->N.pair >= 0 )
nn_close(swap->N.pair); nn_close(swap->N.pair), swap->N.pair = -1;
if ( swap->utxo != 0 ) if ( swap->utxo != 0 )
{
printf("make available\n");
LP_availableset(swap->utxo); LP_availableset(swap->utxo);
} }
}
uint32_t basilisk_quoteid(struct basilisk_request *rp) uint32_t basilisk_quoteid(struct basilisk_request *rp)
{ {
@ -686,7 +683,7 @@ void LP_bobloop(void *_swap)
swap->bobreclaim.utxovout = 0; swap->bobreclaim.utxovout = 0;
swap->bobreclaim.utxotxid = swap->bobpayment.I.signedtxid; swap->bobreclaim.utxotxid = swap->bobpayment.I.signedtxid;
basilisk_bobpayment_reclaim(swap,swap->I.callduration); 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"); printf("waiting for alicepayment to confirm\n");
sleep(3); sleep(3);
@ -731,7 +728,7 @@ void LP_aliceloop(void *_swap)
printf("error sending alicepayment\n"); printf("error sending alicepayment\n");
else else
{ {
while ( LP_numconfirms(swap,&swap->alicepayment) < 1 ) while ( LP_numconfirms(swap,&swap->alicepayment) < swap->I.aliceconfirms )
{ {
printf("waiting for alicepayment to confirm\n"); printf("waiting for alicepayment to confirm\n");
sleep(3); sleep(3);
@ -740,14 +737,14 @@ void LP_aliceloop(void *_swap)
printf("error waiting for bobpayment\n"); printf("error waiting for bobpayment\n");
else else
{ {
while ( LP_numconfirms(swap,&swap->bobpayment) < 1 ) while ( LP_numconfirms(swap,&swap->bobpayment) < swap->I.bobconfirms )
{ {
printf("waiting for bobpayment to confirm\n"); printf("waiting for bobpayment to confirm\n");
sleep(LP_SWAPSTEP_TIMEOUT); sleep(LP_SWAPSTEP_TIMEOUT);
} }
if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 ) if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x20000,data,maxlen,&swap->alicespend,0x40000,0) == 0 )
printf("error sending alicespend\n"); 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"); printf("waiting for alicespend to confirm\n");
sleep(LP_SWAPSTEP_TIMEOUT); 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) 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); strcpy(rawtx->name,name);
rawtx->coin = coin; rawtx->coin = coin;
strcpy(rawtx->I.coinstr,coin->symbol); 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) 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]; //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; swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME;
if ( optionduration < 0 ) if ( optionduration < 0 )
swap->I.putduration -= optionduration; 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.iambob = 0;
swap->I.otherhash = swap->I.req.desthash; swap->I.otherhash = swap->I.req.desthash;
aliceistrusted = 1;
bobistrusted = LP_pubkey_istrusted(swap->I.req.desthash);
} }
else else
{ {
swap->I.iambob = 1; swap->I.iambob = 1;
swap->I.otherhash = swap->I.req.srchash; 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 ) 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 ) if ( strcmp("BTC",swap->bobcoin.symbol) == 0 )
{ {
swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1)); swap->I.bobconfirms = (1 + sqrt(dstr(swap->I.bobsatoshis) * .1));
swap->I.aliceconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.bobconfirms * 3); swap->I.aliceconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.bobconfirms + 1);
} }
else if ( strcmp("BTC",swap->alicecoin.symbol) == 0 ) else if ( strcmp("BTC",swap->alicecoin.symbol) == 0 )
{ {
swap->I.aliceconfirms = (1*0 + sqrt(dstr(swap->I.alicesatoshis) * .1)); swap->I.aliceconfirms = (1 + sqrt(dstr(swap->I.alicesatoshis) * .1));
swap->I.bobconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.bobconfirms * 3); swap->I.bobconfirms = MIN(BASILISK_DEFAULT_NUMCONFIRMS,swap->I.aliceconfirms + 1);
} }
else else
{ {
swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.bobconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS; swap->I.aliceconfirms = BASILISK_DEFAULT_NUMCONFIRMS;
} }
/*if ( swap->I.bobconfirms == 0 ) swap->I.bobconfirms *= !bobistrusted;
swap->I.bobconfirms = swap->bobcoin->chain->minconfirms; swap->I.aliceconfirms *= !aliceistrusted;
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);
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); 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 ) if ( swap->I.iambob != 0 )
{ {

7
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 LP_numconfirms(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx)
{ {
int32_t numconfirms = 100; int32_t numconfirms = 100;
#ifndef BASILISK_DISABLEWAITTX //#ifndef BASILISK_DISABLEWAITTX
cJSON *txobj; cJSON *txobj;
numconfirms = -1; numconfirms = -1;
if ( (txobj= LP_gettx(rawtx->coin->symbol,rawtx->I.signedtxid)) != 0 ) if ( (txobj= LP_gettx(rawtx->coin->symbol,rawtx->I.signedtxid)) != 0 )
{ {
numconfirms = jint(txobj,"confirmations"); numconfirms = jint(txobj,"confirmations");
free_json(txobj); 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; numconfirms = 0;
#endif //#endif
return(numconfirms); return(numconfirms);
} }

Loading…
Cancel
Save