Skip to content

Commit

Permalink
Merge pull request #24 from dimxy/tkltest-fix-tokelallbalances
Browse files Browse the repository at this point in the history
fix tokelallbalances tokenlist
  • Loading branch information
NutellaLicka authored Oct 23, 2021
2 parents 5e4b791 + 6e35248 commit dc4c247
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/cc/CCtokens_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,16 @@ UniValue GetAllTokenBalances(CPubKey pk, bool useMempool)
LOGSTREAM(cctokens_log, CCLOG_DEBUG1, stream << funcname << "()" << " checking tx vout destaddress=" << destaddr << " amount=" << tx.vout[index].nValue << std::endl);

uint8_t funcId = 0;
uint256 tokenIdInOpret;
uint256 tokenIdOut;
CScript opret;
std::string errorStr;

CAmount retAmount = V::CheckTokensvout(cp, NULL, tx, index, opret, tokenIdInOpret, funcId, errorStr);
CAmount retAmount = V::CheckTokensvout(cp, NULL, tx, index, opret, tokenIdOut, funcId, errorStr);

if (retAmount > 0 && !myIsutxo_spentinmempool(ignoretxid, ignorevin, txhash, index))
{
CAmount prevAmount = result[tokenIdInOpret.GetHex()].get_int64();
mapBalances[tokenIdInOpret] += retAmount;
{
CAmount prevAmount = mapBalances[tokenIdOut];
mapBalances[tokenIdOut] = prevAmount + retAmount;
}
}
}; // auto add_token_amount
Expand Down Expand Up @@ -615,8 +615,11 @@ UniValue GetAllTokenBalances(CPubKey pk, bool useMempool)
add_token_amount(it->first.txhash, it->first.index, it->second.satoshis);
}

for(auto const &m : mapBalances)
result.pushKV(m.first.GetHex(), m.second);
for(auto const &m : mapBalances) {
UniValue elem(UniValue::VOBJ);
elem.pushKV(m.first.GetHex(), m.second);
result.push_back(elem);
}

return result;
}
Expand Down
3 changes: 1 addition & 2 deletions src/cc/CCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,7 @@ void SetCCunspentsCCIndex(std::vector<std::pair<CUnspentCCIndexKey, CUnspentCCIn

if (address.GetIndexKey(hashBytes, type, true) == 0)
return;
if (!creationId.IsNull())
searchKeys.push_back(std::make_pair(hashBytes, creationId));
searchKeys.push_back(std::make_pair(hashBytes, creationId));
for (std::vector<std::pair<uint160, uint256> >::iterator it = searchKeys.begin(); it != searchKeys.end(); it++)
{
if (GetUnspentCCIndex((*it).first, (*it).second, unspentOutputs, -1, -1, 0) == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/tokensrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ static const CRPCCommand commands[] =
{ "tokens v2", "mytokenv2orders", &mytokenv2orders, true },
{ "tokens", "tokenaddress", &tokenaddress, true },
{ "tokens v2", "tokenv2address", &tokenv2address, true },
// { "tokens v2", "tokenv2indexkey", &tokenv2indexkey, true },
{ "tokens v2", "tokenv2indexkey", &tokenv2indexkey, true },
{ "tokens", "tokenbalance", &tokenbalance, true },
{ "tokens v2", "tokenv2balance", &tokenv2balance, true },
{ "tokens", "tokenallbalances", &tokenallbalances, true },
Expand Down

0 comments on commit dc4c247

Please sign in to comment.