From 86d6ba3d8737b63c63fa6d7cdfe9926d480fcf3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 10 Jul 2019 06:21:04 -1100 Subject: [PATCH] Connect addressutxos to addnormalinputs --- src/cc/CCtx.cpp | 6 +++++- src/komodo_nSPV.h | 10 ++++++++++ src/komodo_nSPV_wallet.h | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 2b02670ca..977c1e37a 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -525,7 +525,11 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { int32_t abovei,belowi,ind,vout,i,n = 0; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; if ( KOMODO_NSPV != 0 ) - return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); + { + if ( ptr != 0 ) + return(NSPV_AddNormalinputs(mtx,mypk,total,maxinputs,ptr)); + else return(0); + } #ifdef ENABLE_WALLET assert(pwalletMain != NULL); const CKeyStore& keystore = *pwalletMain; diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9c577512d..2c8086cae 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -128,6 +128,16 @@ void NSPV_utxosresp_purge(struct NSPV_utxosresp *ptr) } } +void NSPV_utxosresp_copy(struct NSPV_utxosresp *dest,struct NSPV_utxosresp *ptr) +{ + *dest = *ptr; + if ( ptr->utxos != 0 ) + { + dest->utxos = (struct NSPV_utxoresp *)malloc(ptr->numutxos * sizeof(*ptr->utxos)); + memcpy(dest->utxos,ptr->utxos,ptr->numutxos * sizeof(*ptr->utxos)); + } +} + int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) { int32_t len = 0; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index cb2e6ea79..08f2646d7 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -408,8 +408,16 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr) { + char coinaddr[64]; int32_t CCflag = 0; if ( ptr != 0 ) { + Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); + if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 ) + { + NSPV_addressutxos(coinaddr,CCflag); + NSPV_utxosresp_purge(&ptr->U); + NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult); + } memset(ptr->used,0,sizeof(ptr->used)); return(NSPV_addinputs(ptr->used,mtx,total,maxinputs,ptr->U.utxos,ptr->U.numutxos)); } else return(0);