CAsset: GetIdentifier to get label or hex id

This commit is contained in:
Luke Dashjr 2019-01-06 05:53:13 +00:00 committed by Gregory Sanders
parent d81c9f7b3e
commit 047799cb12
3 changed files with 11 additions and 5 deletions

View file

@ -72,6 +72,13 @@ std::string CAssetsDir::GetLabel(const CAsset& asset) const
return GetMetadata(asset).GetLabel();
}
std::string CAssetsDir::GetIdentifier(const CAsset& asset) const
{
const std::string label = GetMetadata(asset).GetLabel();
if (!label.empty()) return label;
return asset.GetHex();
}
std::vector<CAsset> CAssetsDir::GetKnownAssets() const
{
std::vector<CAsset> knownAssets;

View file

@ -40,6 +40,9 @@ public:
/** @return the label associated to the asset id */
std::string GetLabel(const CAsset& asset) const;
/** @return the label associated to the asset id, or some other identifier */
std::string GetIdentifier(const CAsset& asset) const;
std::vector<CAsset> GetKnownAssets() const;
};

View file

@ -790,12 +790,8 @@ QString formatAssetAmount(const CAsset& asset, const CAmount& amount, const int
if (fraction) {
str += QString(".%1").arg(fraction, 8, 10, QLatin1Char('0'));
}
std::string asset_label = gAssetsDir.GetLabel(asset);
if (asset_label.empty()) {
asset_label = asset.GetHex();
}
if (include_asset_name) {
str += QString(" ") + QString::fromStdString(asset_label);
str += QString(" ") + QString::fromStdString(gAssetsDir.GetIdentifier(asset));
}
return str;
}