MCPcopy Create free account
hub / github.com/ElementsProject/elements / AmountMapToUniv

Function AmountMapToUniv

src/rpc/util.cpp:1238–1266  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1236// "" displays *all* assets as VOBJ pairs, while named assets must have
1237// been entered via -assetdir configuration argument and are returned as VNUM.
1238UniValue 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//

Callers 8

getreceivedbyaddressFunction · 0.85
getreceivedbylabelFunction · 0.85
getbalanceFunction · 0.85
getunconfirmedbalanceFunction · 0.85
getbalancesFunction · 0.85
getwalletinfoFunction · 0.85
transactions.cppFile · 0.85
decodepsbtFunction · 0.85

Calls 8

ValueFromAmountFunction · 0.85
GetAssetFromStringFunction · 0.85
GetLabelMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
IsNullMethod · 0.45
GetHexMethod · 0.45
pushKVMethod · 0.45

Tested by

no test coverage detected