From e10dea243fed348601eadaacc816c66808e552ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Jul 2018 03:19:58 -1100 Subject: [PATCH] Test --- src/cc/CCassets.h | 1 + src/cc/CCassetstx.cpp | 32 ++++++++++++++++++++++++++++++++ src/wallet/rpcwallet.cpp | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 4c531839c..b2eb8fa56 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -45,6 +45,7 @@ bool ConstrainAssetVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue bool AssetExactAmounts(Eval* eval,CTransaction &tx,uint256 assetid); // CCassetstx +uint64_t GetAssetBalance(CPubKey pk,uint256 tokenid); uint64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,uint64_t total,int32_t maxinputs); UniValue AssetOrders(uint256 tokenid); std::string CreateAsset(uint64_t txfee,uint64_t assetsupply,std::string name,std::string description); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index df74e5d85..50b159957 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -15,6 +15,38 @@ #include "CCassets.h" +uint64_t AddAssetInputs(CMutableTransaction &mtx,CPubKey pk,uint256 assetid,uint64_t total,int32_t maxinputs) +{ + char coinaddr[64]; uint64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; + std::vector > unspentOutputs; + GetCCaddress(EVAL_ASSETS,coinaddr,pk); + SetCCunspents(unspentOutputs,coinaddr); + //std::sort(unspentOutputs.begin(), unspentOutputs.end(), heightSort); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + txid = it->first.txhash; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( (nValue= IsAssetvout(price,origpubkey,vintx,(int32_t)it->first.index,assetid)) > 0 ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,(int32_t)it->first.index,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } + } + } + return(totalinputs); +} + +uint64_t GetAssetBalance(CPubKey pk,uint256 tokenid) +{ + CMutableTransaction mtx; + return(AddAssetinputs(mtx,pubkey2pk(pubkey),tokenid,0,0)); +} UniValue AssetOrders(uint256 refassetid) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6933ac028..2c0a76edf 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4872,7 +4872,7 @@ UniValue tokenorders(const UniValue& params, bool fHelp) UniValue tokenbalance(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char destaddr[64]; CMutableTransaction mtx; uint256 tokenid; uint64_t balance; std::vector pubkey; + UniValue result(UniValue::VOBJ); char destaddr[64]; uint256 tokenid; uint64_t balance; std::vector pubkey; if ( fHelp || params.size() > 2 ) throw runtime_error("tokenbalance tokenid [pubkey]\n"); tokenid = Parseuint256((char *)params[0].get_str().c_str()); @@ -4882,7 +4882,7 @@ UniValue tokenbalance(const UniValue& params, bool fHelp) result.push_back(Pair("result", "success")); if ( GetCCaddress(EVAL_ASSETS,destaddr,pubkey2pk(pubkey)) != 0 ) result.push_back(Pair("CCaddress",destaddr)); - balance = AddAssetinputs(mtx,pubkey2pk(pubkey),tokenid,0,0); + balance = GetAssetBalance(pubkey2pk(pubkey),tokenid);//AddAssetinputs(mtx,pubkey2pk(pubkey),tokenid,0,0); result.push_back(Pair("tokenid", params[0].get_str())); result.push_back(Pair("balance", (int64_t)balance)); return(result);