From 7a45609a229de81f1f5dcb615c565a1f755e567e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 02:22:58 -1100 Subject: [PATCH] Handle single utxo case --- src/cc/CCtx.cpp | 9 +++++++-- src/komodo_nSPV.h | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7435defbf..5c2fcf10d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -585,8 +585,13 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->nValue; remains -= up->nValue; - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); + if ( n > 1 ) + { + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + } else --n; + //utxos[ind] = utxos[--n]; + //memset(&utxos[n],0,sizeof(utxos[n])); //fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9d0450c0f..f7fc577d5 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -1285,8 +1285,11 @@ int64_t NSPV_addinputs(CMutableTransaction &mtx,int64_t total,int32_t maxinputs, mtx.vin.push_back(CTxIn(up->txid,up->vout,CScript())); totalinputs += up->satoshis; remains -= up->satoshis; - utxos[ind] = utxos[--n]; - memset(&utxos[n],0,sizeof(utxos[n])); + if ( n > 1 ) + { + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); + } else --n; fprintf(stderr,"totalinputs %.8f vs total %.8f i.%d vs max.%d\n",(double)totalinputs/COIN,(double)total/COIN,i,maxinputs); if ( totalinputs >= total || (i+1) >= maxinputs ) break;