Browse Source

Merge pull request #718 from jl777/jl777

single utxo autosplit
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
ea1956625e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      iguana/exchanges/LP_include.h
  2. 10
      iguana/exchanges/LP_ordermatch.c
  3. 1
      iguana/exchanges/LP_rpc.c
  4. 49
      iguana/exchanges/LP_transaction.c
  5. 14
      iguana/exchanges/LP_utxo.c

2
iguana/exchanges/LP_include.h

@ -303,7 +303,7 @@ struct iguana_info
portable_mutex_t txmutex,addrmutex,addressutxo_mutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset;
uint32_t txversion,dPoWtime,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint32_t txversion,dPoWtime,lastautosplit,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64],estimatefeestr[32],getinfostr[32],etomic[64];
// portfolio

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++)
{

1
iguana/exchanges/LP_rpc.c

@ -150,6 +150,7 @@ uint64_t LP_RTsmartbalance(struct iguana_info *coin)
item = jitem(array,i);
value = LP_value_extract(item,1);
valuesum += value;
//printf("%s -> %.8f\n",jprint(item,0),dstr(value));
}
}
free_json(array);

49
iguana/exchanges/LP_transaction.c

@ -1526,7 +1526,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) == 0 )
return(0);
return(clonestr("{\"error\":\"use LP_eth_withdraw for ETH or ERC20\"}"));
}
if ( ctx == 0 )
ctx = bitcoin_ctx();
@ -1569,14 +1569,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
V = malloc(maxV * sizeof(*V));
for (iter=0; iter<2; iter++)
{
if ( (ap= LP_address_utxo_reset(coin)) == 0 )
{
printf("LP_withdraw error utxo reset %s\n",coin->symbol);
free(V);
if ( allocated_outputs != 0 )
free_json(outputs);
return(0);
}
LP_address_utxo_reset(coin);
privkeys = cJSON_CreateArray();
vins = cJSON_CreateArray();
memset(V,0,sizeof(*V) * maxV);
@ -1660,6 +1653,42 @@ 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);
//printf("%s balance %.8f\n",coin->symbol,dstr(balance));
balance -= coin->txfee - 0.001;
if ( balance > coin->txfee )
{
halfval = (balance / 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);
jaddstr(argjson,"coin",coin->symbol);
//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 +1714,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;

14
iguana/exchanges/LP_utxo.c

@ -353,7 +353,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a
{
if ( LP_value_extract(txout,0) == 0 )
{
//printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout);
//char str[65]; printf("LP_address_utxo_ptrs skip zero value %s/v%d\n",bits256_str(str,up->U.txid),up->U.vout);
free_json(txout);
up->spendheight = 1;
if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts )
@ -364,7 +364,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a
}
else
{
//printf("LP_address_utxo_ptrs skips %s %s payment %s/v%d is spent\n",coin->symbol,coinaddr,bits256_str(str,up->U.txid),up->U.vout);
//char str[65]; printf("LP_address_utxo_ptrs skips %s %s payment %s/v%d is spent\n",coin->symbol,coinaddr,bits256_str(str,up->U.txid),up->U.vout);
up->spendheight = 1;
if ( (tx= LP_transactionfind(coin,up->U.txid)) != 0 && up->U.vout < tx->numvouts )
tx->outpoints[up->U.vout].spendheight = 1;
@ -526,7 +526,6 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
portable_mutex_lock(&coin->addressutxo_mutex);
if ( (array= LP_listunspent(coin->symbol,coin->smartaddr,zero,zero)) != 0 )
{
//printf("reset %s ap->utxos\n",coin->symbol);
portable_mutex_lock(&coin->addrmutex);
portable_mutex_lock(&LP_gcmutex);
DL_FOREACH_SAFE(ap->utxos,up,tmp)
@ -543,7 +542,6 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
char str[65];
for (i=m=0; i<n; i++)
{
//{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700}
item = jitem(array,i);
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
if ( bits256_nonz(txid) == 0 )
@ -552,20 +550,20 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
{
if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,txid,vout)) == 0 )
{
//printf("skip null gettxout %s.v%d\n",bits256_str(str,txid),vout);
//printf("skip null gettxout %s.v%d\n",bits256_str(str,txid),vout);
continue;
}
else free_json(txobj);
if ( (numconfs= LP_numconfirms(coin->symbol,coin->smartaddr,txid,vout,0)) <= 0 )
{
//printf("skip numconfs.%d %s.v%d\n",numconfs,bits256_str(str,txid),vout);
//printf("skip numconfs.%d %s.v%d\n",numconfs,bits256_str(str,txid),vout);
continue;
}
}
LP_address_utxoadd(1,now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1);
if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 )
{
//printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value));
//printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value));
}
else
{
@ -575,6 +573,8 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
}
printf("added %d of %d from %s listunspents\n",m,n,coin->symbol);
}
if ( n <= 1 )
ap = 0;
free_json(array);
}
portable_mutex_unlock(&coin->addressutxo_mutex);

Loading…
Cancel
Save