diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 61b81b988..16a30ccac 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -383,7 +383,7 @@ cJSON *LP_getblockhashstr(char *symbol,char *blockhashstr) cJSON *LP_listunspent(char *symbol,char *coinaddr) { - char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); + char buf[128]; cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); if ( coin == 0 ) return(cJSON_Parse("{\"error\":\"no coin\"}")); if ( coin->electrum == 0 ) @@ -394,7 +394,9 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr) else { sprintf(buf,"[\"%s\"]",coinaddr); - return(bitcoin_json(coin,"blockchain.address.listunspent",buf)); + if ( (retjson= bitcoin_json(coin,"blockchain.address.listunspent",buf)) != 0 ) + printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); + return(retjson); } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index ebbc93ade..e35e7a0a3 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -808,7 +808,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { - char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,targetval,value,total = 0; + char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,targetval,value,total = 0; if ( coin == 0 ) { printf("coin not active\n"); @@ -831,14 +831,27 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr for (i=0; i 0 ) + if ( coin->electrum == 0 ) { - //printf("%s\n",jprint(item,0)); - values[i] = satoshis; - } else used++; + satoshis = SATOSHIDEN * jdouble(item,"amount"); + if ( satoshis == 0 ) + satoshis = SATOSHIDEN * jdouble(item,"value"); + if ( LP_inventory_prevent(iambob,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) + { + //printf("%s\n",jprint(item,0)); + values[i] = satoshis; + } else used++; + } + else + { + //{"value":1000000,"tx_hash":"4e4f818c53486c0576693b4cd379849e5ff95538b38e4100f48884073a4e7636","tx_pos":0,"height":484877} + satoshis = j64bits(item,"value"); + if ( LP_inventory_prevent(iambob,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) + { + printf("%s\n",jprint(item,0)); + values[i] = satoshis; + } else used++; + } //printf("%.8f ",dstr(satoshis)); } //printf("array.%d\n",n); @@ -850,9 +863,18 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr if ( (i= LP_maxvalue(values,n)) >= 0 ) { item = jitem(array,i); - deposittxid = jbits256(item,"txid"); - depositvout = juint(item,"vout"); - script = jstr(item,"scriptPubKey"); + if ( coin->electrum == 0 ) + { + deposittxid = jbits256(item,"txid"); + depositvout = juint(item,"vout"); + script = jstr(item,"scriptPubKey"); + } + else + { + deposittxid = jbits256(item,"tx_hash"); + depositvout = juint(item,"tx_pos"); + script = coin->smartaddr; + } depositval = values[i]; values[i] = 0, used++; if ( iambob == 0 ) @@ -872,9 +894,21 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr if ( i >= 0 || (i= LP_nearestvalue(iambob,values,n,targetval)) >= 0 ) { item = jitem(array,i); - txid = jbits256(item,"txid"); - vout = juint(item,"vout"); - if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 ) + cmpflag = 0; + if ( coin->electrum == 0 ) + { + txid = jbits256(item,"txid"); + vout = juint(item,"vout"); + if ( jstr(item,"scriptPubKey") != 0 && strcmp(script,jstr(item,"scriptPubKey")) == 0 ) + cmpflag = 1; + } + else + { + txid = jbits256(item,"tx_hash"); + vout = juint(item,"tx_pos"); + cmpflag = 1; + } + if ( cmpflag != 0 ) { value = values[i]; values[i] = 0, used++;