From 4a3172ee06b6970dd026b3b06808c8506552d574 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 15:13:49 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_rpc.c | 7 +----- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxo.c | 42 +++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 201cb492d..b623c71a2 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -303,6 +303,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); void 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); #endif diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index db062d6bc..7d23f6f0a 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -425,12 +425,7 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) { sprintf(buf,"[0, 99999999, [\"%s\"]]",coinaddr); return(bitcoin_json(coin,"listunspent",buf)); - } - else - { - printf("return local RAM listunspent\n"); - return(0); - } + } else return(LP_address_utxos(coin,coinaddr,0)); } else return(electrum_address_listunspent(symbol,coin->electrum,&retjson,coinaddr)); } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 78f83a387..f92fb7bb0 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -470,7 +470,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON strcpy(coin->lastunspent,addr); coin->unspenttime = (uint32_t)time(NULL); } - } + } else retjson = LP_address_utxos(coin,addr,1); return(retjson); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6d0ffdc58..0c013bfe6 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -34,7 +34,7 @@ uint64_t LP_value_extract(cJSON *obj) if ( (val= jdouble(obj,"amount")) < SMALLVAL ) val = jdouble(obj,"value"); if ( val > SMALLVAL ) - value = (val * SATOSHIDEN + 0.0000000049); + value = ((val + jdouble(obj,"interest")) * SATOSHIDEN + 0.0000000049); else value = 0; return(value); } @@ -120,6 +120,44 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int portable_mutex_unlock(&coin->txmutex); } +cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32_t electrumret) +{ + cJSON *item = cJSON_CreateObject(); + if ( electrumret == 0 ) + { + jaddbits256(item,"txid",up->U.txid); + jaddnum(item,"vout",up->U.vout); + jaddnum(item,"confirmations",coin->height - up->U.height); + jaddnum(item,"amount",dstr(up->U.value)); + jaddstr(item,"scriptPubKey",""); + } + else + { + jaddbits256(item,"tx_hash",up->U.txid); + jaddnum(item,"tx_pos",up->U.vout); + jaddnum(item,"height",up->U.height); + jadd64bits(item,"value",up->U.value); + } + return(item); +} + +cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret) +{ + cJSON *array; struct LP_address *ap; struct LP_address_utxo *up,*tmp; + array = cJSON_CreateArray(); + portable_mutex_lock(&coin->txmutex); + if ( (ap= _LP_addressfind(coin,coinaddr)) != 0 ) + { + DL_FOREACH_SAFE(ap->utxos,up,tmp) + { + if ( up->spendheight <= 0 ) + jaddi(array,LP_address_item(up,electrumret)); + } + } + portable_mutex_unlock(&coin->txmutex); + return(array); +} + /*void LP_address_monitor(struct LP_pubkeyinfo *pubp) { struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; @@ -423,7 +461,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) { - value = SATOSHIDEN * jdouble(txobj,"value"); + value = SATOSHIDEN * (jdouble(txobj,"value") + jdouble(txobj,"interest")); if ( coinaddr == 0 ) coinaddr = _coinaddr; LP_destaddr(coinaddr,txobj);