Browse Source

Single utxo edge case auto split

jl777
jl777 7 years ago
parent
commit
f2a2807490
  1. 10
      iguana/exchanges/LP_ordermatch.c
  2. 35
      iguana/exchanges/LP_transaction.c
  3. 4
      iguana/exchanges/LP_utxo.c

10
iguana/exchanges/LP_ordermatch.c

@ -1491,7 +1491,15 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
memset(pubkeys,0,sizeof(pubkeys));
LP_txfees(&txfee,&desttxfee,base,rel);
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
LP_address_utxo_reset(relcoin);
if ( LP_address_utxo_reset(relcoin) == 0 )
{
if ( time(NULL) > relcoin->lastautosplit+300 )
{
relcoin->lastautosplit = (uint32_t)time(NULL);
return(LP_autosplit(relcoin));
}
return(clonestr("{\"error\":\"not enough utxo, please make more deposits\"}"));
}
autxo = 0;
for (i=0; i<maxiters; i++)
{

35
iguana/exchanges/LP_transaction.c

@ -1660,6 +1660,39 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
return(jprint(retjson,1));
}
char *LP_autosplit(struct iguana_info *coin)
{
char *retstr; cJSON *argjson,*withdrawjson,*outputs,*item; int64_t total,balance,halfval;
if ( coin->etomic[0] == 0 )
{
if ( coin->electrum != 0 )
balance = LP_unspents_load(coin->symbol,coin->smartaddr);
else balance = LP_RTsmartbalance(coin);
if ( balance >= 0.001+coin->txfee )
{
halfval = ((balance - coin->txfee - 0.001) / 100) * 45;
argjson = cJSON_CreateObject();
outputs = cJSON_CreateArray();
item = cJSON_CreateObject();
jaddnum(item,coin->smartaddr,dstr(halfval));
jaddi(outputs,item);
item = cJSON_CreateObject();
jaddnum(item,coin->smartaddr,dstr(halfval));
jaddi(outputs,item);
item = cJSON_CreateObject();
jaddnum(item,coin->smartaddr,dstr(balance - 2*halfval));
jaddi(outputs,item);
jadd(argjson,"outputs",outputs);
jaddnum(argjson,"broadcast",1);
printf("autosplit.(%s)\n",jprint(argjson,0));
retstr = LP_withdraw(coin,argjson);
free_json(argjson);
return(retstr);
} else return(clonestr("{\"error\":\"less than 0.0011 in balance\"}"));
}
return(clonestr("{\"error\":\"couldnt autosplit\"}"));
}
#ifndef NOTETOMIC
char *LP_eth_withdraw(struct iguana_info *coin,cJSON *argjson)
@ -1685,6 +1718,8 @@ char *LP_eth_withdraw(struct iguana_info *coin,cJSON *argjson)
#endif
int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pubkey33,int32_t iambob,int32_t lockinputs,struct basilisk_rawtx *rawtx,uint32_t locktime,uint8_t *script,int32_t scriptlen,int64_t txfee,int32_t minconf,int32_t delay,bits256 privkey,uint8_t *changermd160,char *vinaddr)
{
struct iguana_info *coin; int32_t len,retval=-1; char *retstr,*hexstr; cJSON *argjson,*outputs,*item,*retjson,*obj;

4
iguana/exchanges/LP_utxo.c

@ -538,7 +538,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
portable_mutex_unlock(&coin->addrmutex);
portable_mutex_unlock(&LP_gcmutex);
now = (uint32_t)time(NULL);
if ( (n= cJSON_GetArraySize(array)) > 0 )
if ( (n= cJSON_GetArraySize(array)) > 1 )
{
char str[65];
for (i=m=0; i<n; i++)
@ -574,7 +574,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
}
}
printf("added %d of %d from %s listunspents\n",m,n,coin->symbol);
}
} else ap = 0;
free_json(array);
}
portable_mutex_unlock(&coin->addressutxo_mutex);

Loading…
Cancel
Save