Add Asset and MPTIssue support to more jtx objects / functions

- Unfortunately, to work around some ambiguous symbol compilation
  errors, I had to change the implicit conversion from IOU to Asset to
  a conversion from IOU to PrettyAsset, and add a more explicit
  `asset()` function. This workaround only required changing two
  existing tests, so seems acceptable.
This commit is contained in:
Ed Hennis
2025-04-17 16:44:00 -04:00
parent 79a1a8a9c6
commit 56ff345a99
4 changed files with 40 additions and 3 deletions

View File

@@ -67,7 +67,7 @@ class AMMCalc_test : public beast::unit_test::suite
// drops // drops
else if (match[1] == "XRPA") else if (match[1] == "XRPA")
return XRPAmount{std::stoll(match[2])}; return XRPAmount{std::stoll(match[2])};
return amountFromString(gw[match[1]], match[2]); return amountFromString(gw[match[1]].asset(), match[2]);
} }
return std::nullopt; return std::nullopt;
} }

View File

@@ -469,9 +469,15 @@ public:
Returns 0 if the trust line does not exist. Returns 0 if the trust line does not exist.
*/ */
// VFALCO NOTE This should return a unit-less amount // VFALCO NOTE This should return a unit-less amount
PrettyAmount
balance(Account const& account, Asset const& asset) const;
PrettyAmount PrettyAmount
balance(Account const& account, Issue const& issue) const; balance(Account const& account, Issue const& issue) const;
PrettyAmount
balance(Account const& account, MPTIssue const& mptIssue) const;
/** Return the number of objects owned by an account. /** Return the number of objects owned by an account.
* Returns 0 if the account does not exist. * Returns 0 if the account does not exist.
*/ */

View File

@@ -143,6 +143,12 @@ public:
return amount_; return amount_;
} }
inline int
signum() const
{
return amount_.signum();
}
operator STAmount const&() const operator STAmount const&() const
{ {
return amount_; return amount_;
@@ -367,6 +373,11 @@ public:
{ {
return {currency, account.id()}; return {currency, account.id()};
} }
Asset
asset() const
{
return issue();
}
/** Implicit conversion to Issue or Asset. /** Implicit conversion to Issue or Asset.
@@ -377,9 +388,9 @@ public:
{ {
return issue(); return issue();
} }
operator Asset() const operator PrettyAsset() const
{ {
return issue(); return asset();
} }
template < template <

View File

@@ -199,6 +199,26 @@ Env::balance(Account const& account, Issue const& issue) const
return {amount, lookup(issue.account).name()}; return {amount, lookup(issue.account).name()};
} }
PrettyAmount
Env::balance(Account const& account, MPTIssue const& mptIssue) const
{
auto const sle = le(keylet::mptoken(mptIssue.getMptID(), account));
if (!sle)
{
return {STAmount(mptIssue, 0), account.name()};
}
STAmount const amount{mptIssue, sle->getFieldU64(sfMPTAmount)};
return {amount, lookup(mptIssue.getIssuer()).name()};
}
PrettyAmount
Env::balance(Account const& account, Asset const& asset) const
{
return std::visit(
[&](auto const& issue) { return balance(account, issue); },
asset.value());
}
std::uint32_t std::uint32_t
Env::ownerCount(Account const& account) const Env::ownerCount(Account const& account) const
{ {