diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 7bb843f13..0be95d830 100644 --- a/iguana/exchanges/LP_include.h +++ b/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 diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index e4551f0ac..f6c2bc4f5 100644 --- a/iguana/exchanges/LP_peers.c +++ b/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); +} diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 543d6a019..b604f29e8 100644 --- a/iguana/exchanges/LP_prices.c +++ b/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; ielectrum,&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;