From eca43db50ffdb59625ae3e9c41cefd6ac9f3d4b7 Mon Sep 17 00:00:00 2001
From: jl777 <jameslee777@yahoo.com>
Date: Wed, 1 Nov 2017 20:02:05 +0200
Subject: [PATCH] Test

---
 iguana/exchanges/LP_utxos.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c
index 3f1ed5f40..546a6aba0 100644
--- a/iguana/exchanges/LP_utxos.c
+++ b/iguana/exchanges/LP_utxos.c
@@ -229,7 +229,7 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo)
 
 struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis)
 {
-    uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; int32_t iambob = 0;
+    uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; int32_t bestsize,iambob = 0;
     if ( symbol == 0 || destsatoshis == 0 )
     {
         printf("LP_utxo_bestfit error symbol.%p %.8f\n",symbol,dstr(destsatoshis));
@@ -243,7 +243,28 @@ struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis)
             continue;
         if ( LP_isavailable(utxo) > 0 && LP_ismine(utxo) > 0 )
         {
-            if ( utxo->S.satoshis >= destsatoshis && (bestutxo == 0 || (bestutxo->S.satoshis < destsatoshis && utxo->S.satoshis >= destsatoshis) || (bestutxo->S.satoshis >= destsatoshis && utxo->S.satoshis < bestutxo->S.satoshis)) )
+            bestsize = 0;
+            if ( bestutxo == 0 )
+            {
+                if ( utxo->S.satoshis > destsatoshis/LP_MINCLIENTVOL )
+                    bestsize = 1;
+            }
+            else
+            {
+                if ( bestutxo->S.satoshis < destsatoshis )
+                {
+                    if ( utxo->S.satoshis > destsatoshis )
+                        bestsize = 1;
+                    else if ( utxo->S.satoshis > bestutxo->S.satoshis )
+                        bestsize = 1;
+                }
+                else
+                {
+                    if ( utxo->S.satoshis > destsatoshis && utxo->S.satoshis < bestutxo->S.satoshis )
+                        bestsize = 1;
+                }
+            }
+            if ( bestsize > 0 )
             {
                 if ( LP_iseligible(&srcvalue,&srcvalue2,utxo->iambob,symbol,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,utxo->fee.txid,utxo->fee.vout) == 0 )
                 {