Browse Source

Test

etomic
jl777 7 years ago
parent
commit
60776b9707
  1. 1
      iguana/exchanges/LP_include.h
  2. 5
      iguana/exchanges/LP_ordermatch.c
  3. 12
      iguana/exchanges/LP_utxo.c
  4. 37
      iguana/exchanges/LP_utxos.c

1
iguana/exchanges/LP_include.h

@ -429,6 +429,7 @@ struct iguana_info *LP_coinfind(char *symbol);
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32);
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);
int32_t LP_merkleproof(struct iguana_info *coin,struct electrum_info *ep,bits256 txid,int32_t height); int32_t LP_merkleproof(struct iguana_info *coin,struct electrum_info *ep,bits256 txid,int32_t height);
int32_t LP_utxos_remove(bits256 txid,int32_t vout);
struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins); struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins);
void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid); void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid);
uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen); uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen);

5
iguana/exchanges/LP_ordermatch.c

@ -762,6 +762,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
else else
{ {
char tmp[64]; char tmp[64];
LP_utxos_remove(Q.txid,Q.vout);
LP_utxos_remove(Q.txid2,Q.vout2);
value = LP_txvalue(tmp,Q.srccoin,Q.txid,Q.vout); value = LP_txvalue(tmp,Q.srccoin,Q.txid,Q.vout);
value2 = LP_txvalue(tmp,Q.srccoin,Q.txid2,Q.vout2); value2 = LP_txvalue(tmp,Q.srccoin,Q.txid2,Q.vout2);
printf("call LP_utxoadd.(%s) %.8f %.8f\n",Q.coinaddr,dstr(value),dstr(value2)); printf("call LP_utxoadd.(%s) %.8f %.8f\n",Q.coinaddr,dstr(value),dstr(value2));
@ -769,7 +771,8 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
recalc = 1; recalc = 1;
else else
{ {
printf("butxo deposit %s, Q %s\n",bits256_str(str,butxo->deposit.txid),bits256_str(str2,Q.txid2)); if ( bits256_cmp(Q.txid,butxo->payment.txid) != 0 || Q.vout != butxo->payment.vout || bits256_cmp(Q.txid2,butxo->deposit.txid) != 0 || Q.vout2 != butxo->deposit.vout )
recalc = 1;
} }
} }
if ( recalc != 0 ) if ( recalc != 0 )

12
iguana/exchanges/LP_utxo.c

@ -185,7 +185,7 @@ printf("LP_address_utxo_ptrs skips %s/v%u due to SPV.%d ht.%d\n",bits256_str(str
continue; continue;
} }
} }
if ( LP_allocated(up->U.txid,up->U.vout) == 0 ) if ( LP_allocated(up->U.txid,up->U.vout) == 0 && LP_utxos_remove(up->U.txid,up->U.vout) == 0 )
{ {
utxos[n++] = up; utxos[n++] = up;
if ( n >= max ) if ( n >= max )
@ -480,6 +480,16 @@ struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout)
return(utxo); return(utxo);
} }
void _LP_utxo_delete(int32_t iambob,struct LP_utxoinfo *utxo)
{
HASH_DELETE(hh,G.LP_utxoinfos[iambob],utxo);
}
void _LP_utxo2_delete(int32_t iambob,struct LP_utxoinfo *utxo)
{
HASH_DELETE(hh,G.LP_utxoinfos2[iambob],utxo);
}
struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2)
{ {
struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)]; struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)];

37
iguana/exchanges/LP_utxos.c

@ -376,9 +376,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t
// utxo->S.profitmargin = profitmargin; // utxo->S.profitmargin = profitmargin;
utxo->T.lasttime = (uint32_t)time(NULL); utxo->T.lasttime = (uint32_t)time(NULL);
//printf("return existing utxo[%d] %s %s\n",iambob,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid)); //printf("return existing utxo[%d] %s %s\n",iambob,bits256_str(str,utxo->payment.txid),bits256_str(str2,iambob != 0 ? utxo->deposit.txid : utxo->fee.txid));
if ( bits256_cmp(txid,utxo->payment.txid) != 0 || vout != utxo->payment.vout || bits256_cmp(txid2,u.txid) != 0 || vout2 != u.vout ) return(utxo);
printf("unexpected mismatch? %s vs %s\n",bits256_str(str,txid2),bits256_str(str2,u.txid));
else return(utxo);
} }
} }
utxo = calloc(1,sizeof(*utxo)); utxo = calloc(1,sizeof(*utxo));
@ -432,6 +430,39 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,char *symbol,bits256 txid,int32_t
return(utxo); return(utxo);
} }
int32_t LP_utxos_remove(bits256 txid,int32_t vout)
{
struct LP_utxoinfo *utxo,*utxo2; int32_t retval = 0,iambob = 1;
utxo = utxo2 = 0;
portable_mutex_lock(&LP_utxomutex);
if ( (utxo= _LP_utxofind(iambob,txid,vout)) != 0 )
{
if ( LP_isavailable(utxo) == 0 )
retval = -1;
else
{
if ( (utxo2= _LP_utxo2find(iambob,txid,vout)) != 0 )
{
if ( LP_isavailable(utxo) == 0 )
retval = -1;
else
{
_LP_utxo_delete(iambob,utxo);
_LP_utxo2_delete(iambob,utxo2);
}
}
}
}
else if ( (utxo2= _LP_utxo2find(iambob,txid,vout)) != 0 )
{
if ( LP_isavailable(utxo2) == 0 )
retval = -1;
else _LP_utxo2_delete(iambob,utxo2);
}
portable_mutex_unlock(&LP_utxomutex);
return(retval);
}
cJSON *LP_inventory(char *symbol) cJSON *LP_inventory(char *symbol)
{ {
struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; struct iguana_info *coin; struct LP_utxoinfo *utxo,*tmp; struct _LP_utxoinfo u; char *myipaddr; cJSON *array; uint64_t val,val2; int32_t iambob = 0; struct iguana_info *coin;

Loading…
Cancel
Save