Browse Source

Merge pull request #506 from jl777/spvdex

disable swap finished utxo make available
etomic
jl777 7 years ago
committed by GitHub
parent
commit
532e8a1c6a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      iguana/exchanges/LP_nativeDEX.c
  2. 6
      iguana/exchanges/LP_ordermatch.c
  3. 2
      iguana/exchanges/LP_rpc.c
  4. 4
      iguana/exchanges/LP_stats.c
  5. 16
      iguana/exchanges/LP_swap.c
  6. 15
      iguana/exchanges/LP_transaction.c
  7. 19
      iguana/exchanges/LP_utxo.c

7
iguana/exchanges/LP_nativeDEX.c

@ -18,11 +18,12 @@
// marketmaker
//
// alice waiting for bestprice
// cancel bid/ask
// big BTC swaps
// delay swap credit back until notarization
// electrum dynamic trust over 1000
// electrum dynamic trust over 1000 tx
// https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG
//
// cancel bid/ask
// portfolio value based on ask?
// verify encrypted destpubkey, broadcast:0 setprice
// USD paxprice based USDvalue in portfolio
@ -790,7 +791,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
void LP_pubkeysloop(void *ctx)
{
static uint32_t lasttime;
struct LP_pubkey_info *pubp,*ptmp; //cJSON *retjson; struct iguana_info *coin,*tmp;
//struct LP_pubkey_info *pubp,*ptmp; //cJSON *retjson; struct iguana_info *coin,*tmp;
strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop");
LP_pubkeysloop_stats.threshold = 15000.;
sleep(10);

6
iguana/exchanges/LP_ordermatch.c

@ -416,7 +416,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
{
if ( (m= LP_address_utxo_ptrs(coin,iambob,utxos,max,ap,coinaddr)) > 1 )
{
if ( 1 )
if ( 0 )
{
int32_t i;
for (i=0; i<m; i++)
@ -429,11 +429,11 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
{
up = utxos[mini];
utxos[mini] = 0;
printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval);
//printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval);
if ( (double)up->U.value/targetval < ratio-1 )
{
if ( 1 )
if ( 0 )
{
int32_t i;
for (i=0; i<m; i++)

2
iguana/exchanges/LP_rpc.c

@ -665,7 +665,7 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr)
{
if ( ap->unspenttime == 0 )
usecache = 0;
else if ( G.LP_pendingswaps != 0 && time(NULL) > ap->unspenttime+3 )
else if ( G.LP_pendingswaps != 0 && time(NULL) > ap->unspenttime+1 )
usecache = 0;
if ( usecache != 0 && (retstr= LP_unspents_filestr(symbol,coinaddr)) != 0 )
{

4
iguana/exchanges/LP_stats.c

@ -519,7 +519,7 @@ struct LP_ohlc
cJSON *LP_ohlc_json(struct LP_ohlc *bar)
{
cJSON *item;
if ( bar->numtrades != 0 && bar->relsum > SMALLVAL && bar->basesum > SMALLVAL )
//if ( bar->numtrades != 0 && bar->relsum > SMALLVAL && bar->basesum > SMALLVAL )
{
item = cJSON_CreateArray();
jaddinum(item,bar->timestamp);
@ -529,7 +529,9 @@ cJSON *LP_ohlc_json(struct LP_ohlc *bar)
jaddinum(item,bar->close);
jaddinum(item,bar->relsum);
jaddinum(item,bar->basesum);
if ( bar->basesum != 0 )
jaddinum(item,bar->relsum / bar->basesum);
else jaddinum(item,0);
jaddinum(item,bar->numtrades);
return(item);
}

16
iguana/exchanges/LP_swap.c

@ -132,7 +132,10 @@ void basilisk_swap_finished(struct basilisk_swap *swap)
LP_availableset(swap->utxo);
swap->utxo = 0;
//LP_butxo_swapfields_set(swap->utxo);
}*/
}
swap->I.finished = (uint32_t)time(NULL);*/
if ( swap->I.finished == 0 )
{
if ( swap->I.iambob != 0 )
{
LP_availableset(swap->bobdeposit.utxotxid,swap->bobdeposit.utxovout);
@ -143,7 +146,7 @@ void basilisk_swap_finished(struct basilisk_swap *swap)
LP_availableset(swap->alicepayment.utxotxid,swap->alicepayment.utxovout);
LP_availableset(swap->myfee.utxotxid,swap->myfee.utxovout);
}
swap->I.finished = (uint32_t)time(NULL);
}
// save to permanent storage
basilisk_rawtx_purge(&swap->bobdeposit);
basilisk_rawtx_purge(&swap->bobpayment);
@ -739,7 +742,7 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
return(0);
}
int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleeptime)
int32_t LP_swapwait(struct basilisk_swap *swap,uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleeptime)
{
char *retstr; cJSON *retjson=0; uint32_t expiration = (uint32_t)(time(NULL) + duration);
printf("wait %d:%d for SWAP.(r%u/q%u) to complete\n",duration,sleeptime,requestid,quoteid);
@ -753,7 +756,10 @@ int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jstr(retjson,"status") != 0 && strcmp(jstr(retjson,"status"),"finished") == 0 )
{
swap->I.finished = (uint32_t)time(NULL);
break;
}
//else printf("NOT FINISHED.(%s)\n",jprint(retjson,0));
free_json(retjson);
retjson = 0;
@ -838,7 +844,7 @@ void LP_bobloop(void *_swap)
if ( swap->N.pair >= 0 )
nn_close(swap->N.pair), swap->N.pair = -1;
LP_swap_endcritical = (uint32_t)time(NULL);
LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
}
}
}
@ -919,7 +925,7 @@ void LP_aliceloop(void *_swap)
}*/
if ( swap->N.pair >= 0 )
nn_close(swap->N.pair), swap->N.pair = -1;
LP_swapwait(swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
}
}
}

15
iguana/exchanges/LP_transaction.c

@ -1210,7 +1210,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
return(0);
}
}
if ( (ap= LP_address_utxo_reset(coin)) == 0 )
if ( (ap= LP_address(coin,coin->smartaddr)) == 0 )
return(0);
memset(utxos,0,sizeof(utxos));
if ( (numutxos= LP_address_utxo_ptrs(coin,0,utxos,max,ap,coin->smartaddr)) <= 0 )
@ -1282,13 +1282,14 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
{
} else printf("error making rawtx suppress.%d\n",suppress_pubkeys);
*txobjp = txobj;
*numvinsp = numvins;
return(rawtxbytes);
}
char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
{
static void *ctx;
int32_t iter,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
if ( ctx == 0 )
ctx = bitcoin_ctx();
if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 )
@ -1317,6 +1318,8 @@ 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 )
return(0);
privkeys = cJSON_CreateArray();
vins = cJSON_CreateArray();
memset(V,0,sizeof(*V) * maxV);
@ -1339,7 +1342,13 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
if ( strcmp(coin->symbol,"BTC") == 0 )
{
newtxfee = LP_txfeecalc(coin,0,datalen);
printf("txfee %.8f -> newtxfee %.8f\n",dstr(txfee),dstr(newtxfee));
printf("txfee %.8f -> newtxfee %.8f, numvins.%d\n",dstr(txfee),dstr(newtxfee),numvins);
for (i=0; i<numvins; i++)
{
item = jitem(vins,i);
//printf("set available %s\n",jprint(item,0));
LP_availableset(jbits256(item,"txid"),jint(item,"vout"));
}
} else break;
} else break;
free_json(vins), vins = 0;

19
iguana/exchanges/LP_utxo.c

@ -41,18 +41,19 @@ struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout)
int32_t _LP_inuse_delete(bits256 txid,int32_t vout)
{
struct LP_inuse_info *lp; int32_t ind;
struct LP_inuse_info *lp; int32_t ind; char str[65];
if ( (lp= _LP_inuse_find(txid,vout)) != 0 )
{
ind = lp->ind;
if ( LP_numinuse > 0 )
*lp = LP_inuse[--LP_numinuse];
lp->ind = ind;
memset(&LP_inuse[LP_numinuse],0,sizeof(struct LP_inuse_info));
printf("_LP_inuse_delete mark as free %s/v%d find.%p\n",bits256_str(str,txid),vout,_LP_inuse_find(txid,vout));
for (ind=0; ind<LP_numinuse; ind++)
if ( LP_inuse[ind].ind != ind )
printf("ind.%d of %d: mismatched ind.%d\n",ind,LP_numinuse,LP_inuse[ind].ind);
}
//char str[65]; printf("_LP_inuse_delete cant find %s/v%d\n",bits256_str(str,txid),vout);
} else printf("_LP_inuse_delete couldnt find %s/v%d\n",bits256_str(str,txid),vout);
return(-1);
}
@ -268,7 +269,8 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a
struct LP_address_utxo *up,*tmp; struct LP_transaction *tx; cJSON *txout; int32_t n = 0;
if ( strcmp(ap->coinaddr,coinaddr) != 0 )
printf("UNEXPECTED coinaddr mismatch (%s) != (%s)\n",ap->coinaddr,coinaddr);
//LP_listunspent_issue(coin->symbol,coin->smartaddr,2);
if ( 0 && coin->electrum != 0 )
LP_listunspent_issue(coin->symbol,coin->smartaddr,2);
//portable_mutex_lock(&LP_utxomutex);
DL_FOREACH_SAFE(ap->utxos,up,tmp)
{
@ -314,7 +316,7 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a
utxos[n++] = up;
if ( n >= max )
break;
} //else printf("LP_allocated skip\n");
} //else printf("LP_allocated skip %u\n",LP_allocated(up->U.txid,up->U.vout));
}
else
{
@ -423,7 +425,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co
struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
{
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,vout,height; cJSON *array,*item,*txobj; int64_t value; bits256 txid; uint32_t now;
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,m,vout,height; cJSON *array,*item,*txobj; int64_t value; bits256 txid; uint32_t now;
LP_address(coin,coin->smartaddr);
LP_listunspent_issue(coin->symbol,coin->smartaddr,2);
if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 )
@ -447,7 +449,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
char str[65];
for (i=0; i<n; i++)
for (i=m=0; i<n; i++)
{
//{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700}
item = jitem(array,i);
@ -458,8 +460,9 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
LP_address_utxoadd(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));
else m++;
}
printf("added %d from listunspents\n",n);
printf("added %d from listunspents\n",m);
}
free_json(array);
}

Loading…
Cancel
Save