jl777 7 years ago
parent
commit
568f41d244
  1. 1
      iguana/exchanges/LP_include.h
  2. 24
      iguana/exchanges/LP_peers.c
  3. 17
      iguana/exchanges/LP_prices.c
  4. 30
      iguana/exchanges/LP_rpc.c

1
iguana/exchanges/LP_include.h

@ -306,6 +306,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid);
int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight);
cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret);
void LP_postutxos(char *symbol);
uint16_t LP_randpeer(char *destip);
#endif

24
iguana/exchanges/LP_peers.c

@ -254,3 +254,27 @@ int32_t LP_numpeers()
}
return(numpeers);
}
uint16_t LP_randpeer(char *destip)
{
struct LP_peerinfo *peer,*tmp; uint16_t port = 0; int32_t n,r,numpeers = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
numpeers++;
}
if ( numpeers > 0 )
{
r = rand() % numpeers;
n = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( n++ == r )
{
strcpy(destip,peer->ipaddr);
port = peer->port;
break;
}
}
}
return(port);
}

17
iguana/exchanges/LP_prices.c

@ -530,11 +530,12 @@ static int _cmp_orderbook(const void *a,const void *b)
#undef ptr_b
}
cJSON *LP_orderbookjson(struct LP_orderbookentry *op)
cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op)
{
cJSON *item = cJSON_CreateObject();
if ( LP_pricevalid(op->price) > 0 )
{
jaddstr(item,"coin",symbol);
jaddstr(item,"address",op->coinaddr);
jaddnum(item,"price",op->price);
jaddnum(item,"numutxos",op->numutxos);
@ -548,6 +549,12 @@ cJSON *LP_orderbookjson(struct LP_orderbookentry *op)
return(item);
}
void LP_check_unspents(char *symbol,struct LP_orderbookentry *op)
{
if ( op->numutxos == 0 )
LP_listunspent_issue(symbol,op->coinaddr);
}
struct LP_orderbookentry *LP_orderbookentry(char *address,char *base,char *rel,double price,int32_t numutxos,uint64_t basesatoshis,uint64_t maxsatoshis,bits256 pubkey,uint32_t timestamp)
{
struct LP_orderbookentry *op;
@ -670,7 +677,9 @@ char *LP_orderbook(char *base,char *rel,int32_t duration)
}
for (i=0; i<numbids; i++)
{
jaddi(array,LP_orderbookjson(bids[i]));
jaddi(array,LP_orderbookjson(rel,bids[i]));
if ( i < 3 )
LP_check_unspents(rel,bids[i]);
free(bids[i]);
bids[i] = 0;
}
@ -679,7 +688,9 @@ char *LP_orderbook(char *base,char *rel,int32_t duration)
array = cJSON_CreateArray();
for (i=0; i<numasks; i++)
{
jaddi(array,LP_orderbookjson(asks[i]));
jaddi(array,LP_orderbookjson(base,asks[i]));
if ( i < 3 )
LP_check_unspents(base,asks[i]);
free(asks[i]);
asks[i] = 0;
}

30
iguana/exchanges/LP_rpc.c

@ -109,6 +109,14 @@ char *issue_LP_getprices(char *destip,uint16_t destport)
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
char *issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coinaddr)
{
char url[512];
sprintf(url,"http://%s:%u/api/stats/listunspent?coin=%s&address=%s",destip,destport,symbol,coinaddr);
//printf("listunspent.(%s)\n",url);
return(LP_issue_curl("listunspent",destip,destport,url));
}
char *LP_apicall(struct iguana_info *coin,char *method,char *params)
{
cJSON *retjson; char *retstr;
@ -435,6 +443,28 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr)
} else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr));
}
void LP_listunspent_issue(char *symbol,char *coinaddr)
{
struct iguana_info *coin; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport;
if ( (coin= LP_coinfind(symbol)) != 0 )
{
if ( coin->electrum != 0 )
retjson = electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr);
else
{
if ( (destport= LP_randpeer(destip)) > 0 )
{
retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr);
printf("rand %s listunspent.(%s) to %s:%u -> %s\n",symbol,coinaddr,destip,destport,retstr);
}
}
if ( retjson != 0 )
free_json(retjson);
if ( retstr != 0 )
free(retstr);
}
}
cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
{
static void *ctx;

Loading…
Cancel
Save