mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
- Specification: XRPLF/XRPL-Standards#239 - Amendment: `SingleAssetVault` - Implements a vault feature used to store a fungible asset (XRP, IOU, or MPT, but not NFT) and to receive shares in the vault (an MPT) in exchange. - A vault can be private or public. - A private vault can use permissioned domains, subject to the `PermissionedDomains` amendment. - Shares can be exchanged back into asset with `VaultWithdraw`. - Permissions on the asset in the vault are transitively applied on shares in the vault. - Issuer of the asset in the vault can clawback with `VaultClawback`. - Extended `MPTokenIssuance` with `DomainID`, used by the permissioned domain on the vault shares. Co-authored-by: John Freeman <jfreeman08@gmail.com>
89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2024 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <xrpl/basics/contract.h>
|
|
#include <xrpl/json/json_value.h>
|
|
#include <xrpl/protocol/AccountID.h>
|
|
#include <xrpl/protocol/Asset.h>
|
|
#include <xrpl/protocol/Issue.h>
|
|
#include <xrpl/protocol/MPTIssue.h>
|
|
#include <xrpl/protocol/STAmount.h>
|
|
#include <xrpl/protocol/jss.h>
|
|
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <variant>
|
|
|
|
namespace ripple {
|
|
|
|
AccountID const&
|
|
Asset::getIssuer() const
|
|
{
|
|
return std::visit(
|
|
[&](auto&& issue) -> AccountID const& { return issue.getIssuer(); },
|
|
issue_);
|
|
}
|
|
|
|
std::string
|
|
Asset::getText() const
|
|
{
|
|
return std::visit([&](auto&& issue) { return issue.getText(); }, issue_);
|
|
}
|
|
|
|
void
|
|
Asset::setJson(Json::Value& jv) const
|
|
{
|
|
std::visit([&](auto&& issue) { issue.setJson(jv); }, issue_);
|
|
}
|
|
|
|
STAmount
|
|
Asset::operator()(Number const& number) const
|
|
{
|
|
return STAmount{*this, number};
|
|
}
|
|
|
|
std::string
|
|
to_string(Asset const& asset)
|
|
{
|
|
return std::visit(
|
|
[&](auto const& issue) { return to_string(issue); }, asset.value());
|
|
}
|
|
|
|
bool
|
|
validJSONAsset(Json::Value const& jv)
|
|
{
|
|
if (jv.isMember(jss::mpt_issuance_id))
|
|
return !(jv.isMember(jss::currency) || jv.isMember(jss::issuer));
|
|
return jv.isMember(jss::currency);
|
|
}
|
|
|
|
Asset
|
|
assetFromJson(Json::Value const& v)
|
|
{
|
|
if (!v.isMember(jss::currency) && !v.isMember(jss::mpt_issuance_id))
|
|
Throw<std::runtime_error>(
|
|
"assetFromJson must contain currency or mpt_issuance_id");
|
|
|
|
if (v.isMember(jss::currency))
|
|
return issueFromJson(v);
|
|
return mptIssueFromJson(v);
|
|
}
|
|
|
|
} // namespace ripple
|