jl777 7 years ago
parent
commit
b851ae5457
  1. 8
      iguana/exchanges/LP_include.h
  2. 6
      iguana/exchanges/LP_ordermatch.c
  3. 29
      iguana/exchanges/LP_socket.c
  4. 3
      iguana/exchanges/LP_swap.c

8
iguana/exchanges/LP_include.h

@ -185,9 +185,9 @@ struct iguana_info
portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
uint32_t lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,unspenttime,obooktime;
uint32_t 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[16],smartaddr[64],userpass[1024],serverport[128],lastunspent[64];
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx;
@ -231,7 +231,8 @@ struct LP_address
struct LP_address_utxo *utxos;
bits256 pubkey;
int64_t balance,total;
uint32_t timestamp,n;
uint32_t timestamp,n,unspenttime;
int32_t unspentheight;
char coinaddr[40];
uint8_t pubsecp[33],pad;
};
@ -287,6 +288,7 @@ struct LP_pubkeyinfo
int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item);
int32_t LP_pubkey_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp);
struct LP_address *LP_address(struct iguana_info *coin,char *coinaddr);
void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t vout);
void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx);
uint32_t basilisk_requestid(struct basilisk_request *rp);

6
iguana/exchanges/LP_ordermatch.c

@ -485,7 +485,6 @@ char *LP_connectedalice(cJSON *argjson) // alice
if ( (qprice= LP_quote_validate(autxo,butxo,&Q,0)) <= SMALLVAL )
{
LP_availableset(autxo);
//G.LP_pendingswaps--;
printf("quote validate error %.0f\n",qprice);
return(clonestr("{\"error\":\"quote validation error\"}"));
}
@ -493,16 +492,12 @@ char *LP_connectedalice(cJSON *argjson) // alice
{
printf("this node has no price for %s/%s (%.8f %.8f)\n",Q.destcoin,Q.srccoin,bid,ask);
LP_availableset(autxo);
//G.LP_pendingswaps--;
return(clonestr("{\"error\":\"no price set\"}"));
}
printf("%s/%s bid %.8f ask %.8f values %.8f %.8f\n",Q.srccoin,Q.destcoin,bid,ask,dstr(butxo->payment.value),dstr(butxo->deposit.value));
price = bid;
if ( (coin= LP_coinfind(Q.destcoin)) == 0 )
{
//G.LP_pendingswaps--;
return(clonestr("{\"error\":\"cant get alicecoin\"}"));
}
Q.privkey = LP_privkey(Q.destaddr,coin->taddr);
if ( bits256_nonz(Q.privkey) != 0 )//&& Q.quotetime >= Q.timestamp-3 )
{
@ -531,7 +526,6 @@ char *LP_connectedalice(cJSON *argjson) // alice
printf("connected result.(%s)\n",jprint(retjson,0));
if ( jobj(retjson,"error") != 0 )
LP_availableset(autxo);
else G.LP_pendingswaps++;
return(jprint(retjson,1));
}
else

29
iguana/exchanges/LP_socket.c

@ -373,7 +373,7 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
{
*retjsonp = 0;
sprintf(stratumreq,"{ \"jsonrpc\":\"2.0\", \"id\": %u, \"method\":\"%s\", \"params\": %s }\n",ep->stratumid,method,params);
printf("%s\n",stratumreq);
printf("%s %s\n",symbol,stratumreq);
memset(ep->buf,0,ep->bufsize);
sitem = (struct stritem *)queueitem(stratumreq);
sitem->expiration = timeout;
@ -517,17 +517,34 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON *
cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,int32_t electrumflag)
{
cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol);
cJSON *retjson=0; struct LP_address *ap; struct iguana_info *coin; int32_t height,usecache=1;
if ( (coin= LP_coinfind(symbol)) == 0 )
return(0);
if ( ep->heightp == 0 )
height = coin->longestchain;
else height = *(ep->heightp);
if ( (ap= LP_address(coin,addr)) != 0 )
{
if ( ap->unspenttime == 0 )
usecache = 0;
else if ( ap->unspentheight < height )
usecache = 0;
else if ( G.LP_pendingswaps != 0 && time(NULL) > ap->unspenttime+20 )
usecache = 0;
}
//printf("electrum.%s/%s listunspent last.(%s lag %d)\n",ep->symbol,coin->symbol,coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime));
if ( coin != 0 && (strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+30) )
if ( usecache == 0 )
{
if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 )
{
printf("%s %p u.%u t.%ld %s -> %s LISTUNSPENT.(%ld)\n",coin->symbol,&coin->unspenttime,coin->unspenttime,time(NULL),coin->lastunspent,addr,strlen(jprint(retjson,0)));
printf("%s u.%u t.%ld %s LISTUNSPENT.(%ld)\n",coin->symbol,ap->unspenttime,time(NULL),addr,strlen(jprint(retjson,0)));
if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 )
LP_postutxos(coin->symbol,addr);
safecopy(coin->lastunspent,addr,sizeof(coin->lastunspent));
coin->unspenttime = (uint32_t)time(NULL);
if ( ap != 0 )
{
ap->unspenttime = (uint32_t)time(NULL);
ap->unspentheight = height;
}
}
} else retjson = LP_address_utxos(coin,addr,1);
return(retjson);

3
iguana/exchanges/LP_swap.c

@ -746,6 +746,7 @@ int32_t LP_swapwait(uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t
void LP_bobloop(void *_swap)
{
uint8_t *data; int32_t maxlen,m,n; uint32_t expiration; struct basilisk_swap *swap = _swap;
G.LP_pendingswaps++;
fprintf(stderr,"start swap iambob\n");
maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen);
@ -804,11 +805,13 @@ void LP_bobloop(void *_swap)
basilisk_swap_finished(swap);
//free(swap);
} else printf("swap timed out\n");
G.LP_pendingswaps--;
}
void LP_aliceloop(void *_swap)
{
uint8_t *data; int32_t maxlen,n,m; uint32_t expiration; struct basilisk_swap *swap = _swap;
G.LP_pendingswaps++;
maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT;

Loading…
Cancel
Save