Browse Source

Test

etomic
jl777 8 years ago
parent
commit
e8aa77d735
  1. 1
      iguana/exchanges/LP_nativeDEX.c
  2. 23
      iguana/exchanges/LP_ordermatch.c
  3. 15
      iguana/exchanges/LP_socket.c
  4. 27
      iguana/exchanges/LP_utxo.c

1
iguana/exchanges/LP_nativeDEX.c

@ -21,6 +21,7 @@
// sign critical api calls
// SPV height errors, autodetect and fix
// stats
// deal with offline pubkeys, reputations, etc.
// dPoW security -> 2: KMD notarized, 3: BTC notarized
// add interest to KMD withdraw
// verify portfolio, pricearray, withdraw

23
iguana/exchanges/LP_ordermatch.c

@ -443,9 +443,9 @@ int32_t LP_nanobind(void *ctx,char *pairstr)
return(pairsock);
}
int32_t LP_nearest_utxovalue(struct iguana_info *coin,struct LP_address_utxo **utxos,int32_t n,uint64_t targetval)
int32_t LP_nearest_utxovalue(struct iguana_info *coin,char *coinaddr,struct LP_address_utxo **utxos,int32_t n,uint64_t targetval)
{
int32_t i,mini = -1; struct LP_address_utxo *up; struct electrum_info *backupep=0,*ep; char str[65]; int64_t dist; uint64_t mindist = (1LL << 60);
int32_t i,oldht,mini = -1; struct LP_address_utxo *up; struct electrum_info *backupep=0,*ep; char str[65]; int64_t dist; uint64_t mindist = (1LL << 60);
if ( (ep= coin->electrum) != 0 )
{
if ( (backupep= ep->prev) == 0 )
@ -462,15 +462,24 @@ int32_t LP_nearest_utxovalue(struct iguana_info *coin,struct LP_address_utxo **u
{
if ( coin->electrum != 0 )
{
if (up->SPV <= 0 )
if ( up->SPV == 0 || up->SPV == -1 )
up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height);
if ( up->SPV < 0 )
if ( up->SPV == 0 || up->SPV == -1 )
{
printf("SPV failure for %s %s\n",coin->symbol,bits256_str(str,up->U.txid));
if ( up->SPV == -1 )
{
oldht = up->U.height;
LP_txheight_check(coin,coinaddr,up);
if ( oldht != up->U.height )
up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height);
if ( up->SPV == -1 )
up->SPV = -2;
}
continue;
} else printf("%s %s: SPV.%d\n",coin->symbol,bits256_str(str,up->U.txid),up->SPV);
}
if ( dist >= 0 && dist < mindist )
if ( up->SPV > 0 && dist >= 0 && dist < mindist )
{
//printf("(%.8f %.8f %.8f).%d ",dstr(up->U.value),dstr(dist),dstr(mindist),mini);
mini = i;
@ -507,7 +516,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **
printf("targetval %.8f vol %.8f price %.8f txfee %.8f %s\n",dstr(targetval),relvolume,price,dstr(txfee),coinaddr);
}
mini = -1;
if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,utxos,m,targetval)) >= 0 )
if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval)) >= 0 )
{
up = utxos[mini];
utxos[mini] = 0;
@ -516,7 +525,7 @@ struct LP_utxoinfo *LP_address_utxopair(int32_t iambob,struct LP_address_utxo **
if ( (double)up->U.value/targetval < LP_MINVOL-1 )
{
if ( (mini= LP_nearest_utxovalue(coin,utxos,m,targetval2 * 1.01)) >= 0 )
if ( (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval2 * 1.01)) >= 0 )
{
if ( up != 0 && (up2= utxos[mini]) != 0 )
{

15
iguana/exchanges/LP_socket.c

@ -457,7 +457,7 @@ cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON **
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr)
{
struct LP_transaction *tx; cJSON *retjson,*txobj,*item; int32_t i,n,height; bits256 txid; struct iguana_info *coin = LP_coinfind(symbol);
char str[65]; struct LP_transaction *tx; cJSON *retjson,*txobj,*item; int32_t i,n,height; bits256 txid; struct iguana_info *coin = LP_coinfind(symbol);
retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT);
//printf("history.(%s)\n",jprint(retjson,0));
if ( retjson != 0 && (n= cJSON_GetArraySize(retjson)) > 0 )
@ -478,6 +478,8 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON *
{
if ( (tx= LP_transactionfind(coin,txid)) != 0 )
{
if ( tx->height > 0 && tx->height != height )
printf("update %s height.%d <- %d\n",bits256_str(str,txid),tx->height,height);
tx->height = height;
LP_address_utxoadd(coin,addr,txid,0,0,height,-1);
}
@ -488,6 +490,17 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON *
return(retjson);
}
int32_t LP_txheight_check(struct iguana_info *coin,char *coinaddr,struct LP_address_utxo *up)
{
cJSON *retjson;
if ( coin->electrum != 0 )
{
if ( (retjson= electrum_address_gethistory(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 )
free_json(retjson);
}
return(0);
}
cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr)
{
cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol);

27
iguana/exchanges/LP_utxo.c

@ -204,8 +204,12 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,
if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 )
{
flag = 1;
if ( up->U.height <= 0 && height > 0 && up->U.height != height )
if ( height > 0 && up->U.height != height )
{
if ( up->U.height > 0 )
printf("update %s/v%d up->U.height %d <- %d\n",bits256_str(str,up->U.txid),up->U.vout,up->U.height,height);
up->U.height = height, flag |= 2;
}
if ( spendheight > 0 && up->spendheight != spendheight )
up->spendheight = spendheight, flag |= 4;
if ( up->U.value == 0 && up->U.value != value )
@ -346,7 +350,7 @@ int32_t LP_merkleproof(struct iguana_info *coin,struct electrum_info *ep,bits256
cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret)
{
cJSON *array,*item; int32_t n; uint64_t total; struct LP_address *ap=0,*atmp; struct LP_address_utxo *up,*tmp; cJSON *txobj; struct electrum_info *ep,*backupep=0;
cJSON *array,*item; int32_t oldht,n; uint64_t total; struct LP_address *ap=0,*atmp; struct LP_address_utxo *up,*tmp; cJSON *txobj; struct electrum_info *ep,*backupep=0;
array = cJSON_CreateArray();
if ( coinaddr != 0 && coinaddr[0] != 0 )
{
@ -371,11 +375,22 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum
}
if ( up->spendheight <= 0 )
{
if ( backupep != 0 && up->SPV <= 0 )
if ( backupep != 0 && (up->SPV == 0 || up->SPV == -1) )
{
up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height);
jaddi(array,LP_address_item(coin,up,electrumret));
n++;
total += up->U.value;
oldht = up->U.height;
LP_txheight_check(coin,coinaddr,up);
if ( oldht != up->U.height )
up->SPV = LP_merkleproof(coin,backupep,up->U.txid,up->U.height);
if ( up->SPV == -1 )
up->SPV = -2;
}
if ( up->SPV > 0 )
{
jaddi(array,LP_address_item(coin,up,electrumret));
n++;
total += up->U.value;
}
}
//printf("new array %s\n",jprint(array,0));
}

Loading…
Cancel
Save