Attaches labeled balance reports to UniValue obj with asset filter "" displays *all* assets as VOBJ pairs, while named assets must have been entered via -assetdir configuration argument and are returned as VNUM.
| 1236 | // "" displays *all* assets as VOBJ pairs, while named assets must have |
| 1237 | // been entered via -assetdir configuration argument and are returned as VNUM. |
| 1238 | UniValue AmountMapToUniv(const CAmountMap& balanceOrig, std::string strasset) |
| 1239 | { |
| 1240 | // Make sure the policyAsset is always present in the balance map. |
| 1241 | CAmountMap balance = balanceOrig; |
| 1242 | balance[::policyAsset] += 0; |
| 1243 | |
| 1244 | // If we don't do assets or a specific asset is given, we filter out once asset. |
| 1245 | if (!g_con_elementsmode || strasset != "") { |
| 1246 | if (g_con_elementsmode) { |
| 1247 | return ValueFromAmount(balance[GetAssetFromString(strasset)]); |
| 1248 | } else { |
| 1249 | return ValueFromAmount(balance[::policyAsset]); |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | UniValue obj(UniValue::VOBJ); |
| 1254 | for(std::map<CAsset, CAmount>::const_iterator it = balance.begin(); it != balance.end(); ++it) { |
| 1255 | // Unknown assets |
| 1256 | if (it->first.IsNull()) |
| 1257 | continue; |
| 1258 | UniValue pair(UniValue::VOBJ); |
| 1259 | std::string label = gAssetsDir.GetLabel(it->first); |
| 1260 | if (label == "") { |
| 1261 | label = it->first.GetHex(); |
| 1262 | } |
| 1263 | obj.pushKV(label, ValueFromAmount(it->second)); |
| 1264 | } |
| 1265 | return obj; |
| 1266 | } |
| 1267 | |
| 1268 | // END ELEMENTS |
| 1269 | // |
no test coverage detected