Browse Source

Merge pull request #503 from jl777/spvdex

fix orderbook zeroes
etomic
jl777 7 years ago
committed by GitHub
parent
commit
14e4e395c3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      iguana/exchanges/LP_commands.c
  2. 26
      iguana/exchanges/LP_nativeDEX.c
  3. 4
      iguana/exchanges/LP_ordermatch.c
  4. 13
      iguana/exchanges/LP_prices.c
  5. 18
      iguana/exchanges/LP_signatures.c
  6. 28
      iguana/exchanges/LP_statemachine.c
  7. 28
      iguana/exchanges/LP_utxo.c

8
iguana/exchanges/LP_commands.c

@ -343,7 +343,7 @@ zeroconf_claim(address, expiration=0)\n\
return(clonestr("{\"error\":\"couldnt set price\"}")); return(clonestr("{\"error\":\"couldnt set price\"}"));
//else if ( LP_mypriceset(&changed,rel,base,1./price) < 0 ) //else if ( LP_mypriceset(&changed,rel,base,1./price) < 0 )
// return(clonestr("{\"error\":\"couldnt set price\"}")); // return(clonestr("{\"error\":\"couldnt set price\"}"));
else if ( jint(argjson,"broadcast") != 0 || jobj(argjson,"broadcast") == 0 ) else if ( jobj(argjson,"broadcast") == 0 || jint(argjson,"broadcast") != 0 )
return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio)); return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio));
else return(clonestr("{\"result\":\"success\"}")); else return(clonestr("{\"result\":\"success\"}"));
} }
@ -624,12 +624,8 @@ zeroconf_claim(address, expiration=0)\n\
else if ( strcmp(method,"tradestatus") == 0 ) else if ( strcmp(method,"tradestatus") == 0 )
{ {
bits256 zero; cJSON *tmpjson; struct LP_quoteinfo Q;
LP_tradecommand_log(argjson); LP_tradecommand_log(argjson);
LP_quoteparse(&Q,argjson); printf("%-4d tradestatus | aliceid.%llu RT.%d %d\n",(uint32_t)time(NULL) % 3600,(long long)j64bits(argjson,"aliceid"),LP_RTcount,LP_swapscount);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,0);
LP_tradecommand_log(argjson);
printf("%-4d (%-10u %10u) %12s id.%22llu %5s/%-5s %12.8f -> %11.8f price %11.8f | RT.%d %d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount);
retstr = clonestr("{\"result\":\"success\"}"); retstr = clonestr("{\"result\":\"success\"}");
} }
else if ( strcmp(method,"wantnotify") == 0 ) else if ( strcmp(method,"wantnotify") == 0 )

26
iguana/exchanges/LP_nativeDEX.c

@ -807,10 +807,10 @@ void LP_pubkeysloop(void *ctx)
coin->lastunspent = (uint32_t)time(NULL); coin->lastunspent = (uint32_t)time(NULL);
} }
}*/ }*/
HASH_ITER(hh,LP_pubkeyinfos,pubp,ptmp) /*HASH_ITER(hh,LP_pubkeyinfos,pubp,ptmp)
{ {
pubp->dynamictrust = LP_dynamictrust(pubp->pubkey,0); pubp->dynamictrust = LP_dynamictrust(pubp->pubkey,0);
} }*/
if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 )
{ {
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); //printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
@ -821,7 +821,7 @@ void LP_pubkeysloop(void *ctx)
} }
} }
void LP_privkeysloop(void *ctx) /*void LP_privkeysloop(void *ctx)
{ {
strcpy(LP_privkeysloop_stats.name,"LP_privkeysloop"); strcpy(LP_privkeysloop_stats.name,"LP_privkeysloop");
LP_privkeysloop_stats.threshold = (LP_ORDERBOOK_DURATION * .8 * 1000) + 10000; LP_privkeysloop_stats.threshold = (LP_ORDERBOOK_DURATION * .8 * 1000) + 10000;
@ -834,7 +834,7 @@ void LP_privkeysloop(void *ctx)
LP_privkey_updates(ctx,LP_mypubsock,0); LP_privkey_updates(ctx,LP_mypubsock,0);
sleep(LP_ORDERBOOK_DURATION * .777); sleep(LP_ORDERBOOK_DURATION * .777);
} }
} }*/
void LP_swapsloop(void *ignore) void LP_swapsloop(void *ignore)
{ {
@ -1050,20 +1050,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS); printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS);
exit(-1); exit(-1);
} }
if ( 0 )
{
char *p2sh = "bJVtQF2o8B6sdNjeXupzNw5rnidJUNwPJD",p2shaddr[64]; uint8_t script[512],pub33[33]; uint32_t timestamp;
decode_hex(pub33,33,"03fe754763c176e1339a3f62ee6b9484720e17ee4646b65a119e9f6370c7004abc");
for (timestamp=1510934803-3600*24; timestamp<1510934803+3600*24; timestamp++)
{
LP_deposit_addr(p2shaddr,script,0,85,timestamp,pub33);
if ( strcmp(p2shaddr,p2sh) == 0 )
{
printf("matched timestamp.%u\n",timestamp);
break;
} else printf("%s ",p2shaddr);
}
}
LP_showwif = juint(argjson,"wif"); LP_showwif = juint(argjson,"wif");
if ( passphrase == 0 || passphrase[0] == 0 ) if ( passphrase == 0 || passphrase[0] == 0 )
{ {
@ -1275,11 +1261,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); printf("error launching LP_pubkeysloop for ctx.%p\n",ctx);
exit(-1); exit(-1);
} }
if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 ) /*if ( 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)myipaddr) != 0 )
{ {
printf("error launching LP_privkeysloop for ctx.%p\n",ctx); printf("error launching LP_privkeysloop for ctx.%p\n",ctx);
exit(-1); exit(-1);
} }*/
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)myipaddr) != 0 )
{ {
printf("error launching LP_swapsloop for port.%u\n",myport); printf("error launching LP_swapsloop for port.%u\n",myport);

4
iguana/exchanges/LP_ordermatch.c

@ -496,7 +496,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c
bits256 zero; bits256 zero;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,base,rel,zero,jprint(retjson,0)); LP_reserved_msg(1,base,rel,zero,jprint(retjson,0));
//LP_reserved_msg(0,base,rel,zero,jprint(retjson,0)); LP_reserved_msg(0,base,rel,zero,jprint(retjson,0));
free_json(retjson); free_json(retjson);
retval = 0; retval = 0;
} else printf("error launching swaploop\n"); } else printf("error launching swaploop\n");
@ -1005,7 +1005,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
bits256 zero; bits256 zero;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,clonestr(msg)); LP_reserved_msg(1,Q.srccoin,Q.destcoin,zero,clonestr(msg));
//LP_reserved_msg(0,Q.srccoin,Q.destcoin,zero,clonestr(msg)); LP_reserved_msg(0,Q.srccoin,Q.destcoin,zero,clonestr(msg));
free(msg); free(msg);
butxo->T.lasttime = (uint32_t)time(NULL); butxo->T.lasttime = (uint32_t)time(NULL);
return(retval); return(retval);

13
iguana/exchanges/LP_prices.c

@ -99,7 +99,9 @@ void LP_pubkey_update(struct LP_pubkey_info *pubp,uint32_t baseind,uint32_t reli
pq->relind = relind; pq->relind = relind;
pq->scale = 6; // millions of SATOSHIS, ie. 0.01 pq->scale = 6; // millions of SATOSHIS, ie. 0.01
DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON() DL_APPEND(pubp->quotes,pq); // already serialized as only path is via stats_JSON()
//printf("create pubp quotes %d/%d\n",baseind,relind);
} }
//printf("%d/%d price %.8f balance %.8f %s num.%d %.8f %.8f\n",baseind,relind,price,dstr(balance),utxocoin,numutxos,dstr(minutxo),dstr(maxutxo));
pq->price = price; pq->price = price;
if ( utxocoin != 0 && utxocoin[0] != 0 ) if ( utxocoin != 0 && utxocoin[0] != 0 )
{ {
@ -122,10 +124,13 @@ void LP_pubkey_update(struct LP_pubkey_info *pubp,uint32_t baseind,uint32_t reli
max64 = (1LL << 32) - 1; max64 = (1LL << 32) - 1;
pq->aveutxo = (uint32_t)ave64; pq->aveutxo = (uint32_t)ave64;
pq->maxutxo = (uint32_t)max64; pq->maxutxo = (uint32_t)max64;
//printf("price %.8f base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",price,LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64); if ( 0 )
//int64_t avesatoshis,maxsatoshis; {
//price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseind,relind); printf("price %.8f base.%s rel.%s utxocoin.%s balance %.8f numutxos.%u %u scale64 = %llu, ave %llu, ave32 %u (%llu) max32 %u (%llu)\n",price,LP_priceinfos[baseind].symbol,LP_priceinfos[relind].symbol,utxocoin,dstr(balance),numutxos,pq->numutxos,(long long)scale64,(long long)aveutxo,pq->aveutxo,(long long)pq->aveutxo * scale64,pq->maxutxo,(long long)pq->maxutxo * scale64);
//printf("checkprice %.8f numutxos.%d ave %.8f max %.8f\n",price,numutxos,dstr(avesatoshis),dstr(maxsatoshis)); int64_t avesatoshis,maxsatoshis;
price = LP_pubkey_price(&numutxos,&avesatoshis,&maxsatoshis,pubp,baseind,relind);
printf("checkprice %.8f numutxos.%d ave %.8f max %.8f\n",price,numutxos,dstr(avesatoshis),dstr(maxsatoshis));
}
} }
} }

18
iguana/exchanges/LP_signatures.c

@ -451,7 +451,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) char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price)
{ {
struct iguana_info *basecoin,*relcoin; struct LP_address *ap; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson; struct iguana_info *basecoin,*relcoin; char pubsecpstr[67]; uint32_t numutxos,timestamp; uint64_t price64,balance,minsize,maxsize; bits256 zero; cJSON *reqjson;
reqjson = cJSON_CreateObject(); reqjson = cJSON_CreateObject();
// LP_addsig // LP_addsig
if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 )//&& basecoin->electrum == 0 )//&& relcoin->electrum == 0 ) if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 )//&& basecoin->electrum == 0 )//&& relcoin->electrum == 0 )
@ -468,11 +468,11 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
jaddnum(reqjson,"timestamp",timestamp); jaddnum(reqjson,"timestamp",timestamp);
init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33);
jaddstr(reqjson,"pubsecp",pubsecpstr); jaddstr(reqjson,"pubsecp",pubsecpstr);
if ( (ap= LP_address(basecoin,basecoin->smartaddr)) != 0 ) //if ( (ap= LP_address(basecoin,basecoin->smartaddr)) != 0 )
{ {
if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,ap)) != 0 ) if ( (numutxos= LP_address_minmax(&balance,&minsize,&maxsize,basecoin,basecoin->smartaddr)) != 0 )
{ {
//printf("%s numutxos.%d balance %.8f min %.8f max %.8f\n",base,numutxos,dstr(balance),dstr(minsize),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); jaddstr(reqjson,"utxocoin",base);
jaddnum(reqjson,"n",numutxos); jaddnum(reqjson,"n",numutxos);
jaddnum(reqjson,"bal",dstr(balance)); jaddnum(reqjson,"bal",dstr(balance));
@ -497,9 +497,15 @@ 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 ) 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);
return(clonestr("{\"result\":\"success\"}")); return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"sig failure\"}")); }
else
{
printf("sig failure\n");
return(clonestr("{\"error\":\"sig failure\"}"));
}
} }
} }
return(clonestr("{\"error\":\"missing fields in posted price\"}")); return(clonestr("{\"error\":\"missing fields in posted price\"}"));
@ -723,7 +729,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,clonestr(msg)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,clonestr(msg));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));
//LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,clonestr(msg)); LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,clonestr(msg));
free(msg); free(msg);
/*portable_mutex_lock(&LP_reservedmutex); /*portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[1] < sizeof(Reserved_msgs[1])/sizeof(*Reserved_msgs[1])-2 ) if ( num_Reserved_msgs[1] < sizeof(Reserved_msgs[1])/sizeof(*Reserved_msgs[1])-2 )

28
iguana/exchanges/LP_statemachine.c

@ -3239,6 +3239,34 @@ while ( 1 )
return(clonestr("{\"error\":\"cant get here\"}")); return(clonestr("{\"error\":\"cant get here\"}"));
#endif #endif
if ( 0 )
{
char *p2sh = "bJVtQF2o8B6sdNjeXupzNw5rnidJUNwPJD",p2shaddr[64]; uint8_t script[512],pub33[33]; uint32_t timestamp;
decode_hex(pub33,33,"03fe754763c176e1339a3f62ee6b9484720e17ee4646b65a119e9f6370c7004abc");
for (timestamp=1510934803-3600*24; timestamp<1510934803+3600*24; timestamp++)
{
LP_deposit_addr(p2shaddr,script,0,85,timestamp,pub33);
if ( strcmp(p2shaddr,p2sh) == 0 )
{
printf("matched timestamp.%u\n",timestamp);
break;
} else printf("%s ",p2shaddr);
}
}
/*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;
*balancep += up->U.value;
n++;
}
}*/
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) 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; struct LP_quoteinfo Q; int64_t bestsatoshis=0,bestdestsatoshis = 0; double ordermatchprice = 0.; struct LP_utxoinfo *autxo,*bestutxo;

28
iguana/exchanges/LP_utxo.c

@ -238,24 +238,28 @@ struct LP_address *LP_address(struct iguana_info *coin,char *coinaddr)
return(ap); return(ap);
} }
int32_t LP_address_minmax(uint64_t *balancep,uint64_t *minp,uint64_t *maxp,struct LP_address *ap) int32_t LP_address_minmax(uint64_t *balancep,uint64_t *minp,uint64_t *maxp,struct iguana_info *coin,char *coinaddr)
{ {
struct LP_address_utxo *up,*tmp; int32_t n = 0; cJSON *array,*item; bits256 txid; int64_t value; int32_t i,vout,height,n = 0;
*minp = *maxp = *balancep = 0; *minp = *maxp = *balancep = 0;
DL_FOREACH_SAFE(ap->utxos,up,tmp) if ( (array= LP_listunspent(coin->symbol,coinaddr)) != 0 )
{ {
if ( up->spendheight <= 0 ) //printf("address minmax.(%s)\n",jprint(array,0));
if ( (n= cJSON_GetArraySize(array)) > 0 )
{ {
if ( up->U.value > *maxp ) for (i=0; i<n; i++)
*maxp = up->U.value; {
if ( *minp == 0 || up->U.value < *minp ) item = jitem(array,i);
*minp = up->U.value; value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
*balancep += up->U.value; if ( value > *maxp )
n++; *maxp = value;
if ( *minp == 0 || value < *minp )
*minp = value;
*balancep += value;
}
} }
free_json(array);
} }
if ( 0 && n > 0 )
printf("n.%d %s min %.8f max %.8f\n",n,ap->coinaddr,dstr(*minp),dstr(*maxp));
return(n); return(n);
} }

Loading…
Cancel
Save