mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
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:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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 <
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user