mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +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>
109 lines
2.9 KiB
C++
109 lines
2.9 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.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#ifndef XRPL_PROTOCOL_STNUMBER_H_INCLUDED
|
|
#define XRPL_PROTOCOL_STNUMBER_H_INCLUDED
|
|
|
|
#include <xrpl/basics/CountedObject.h>
|
|
#include <xrpl/basics/Number.h>
|
|
#include <xrpl/protocol/STBase.h>
|
|
|
|
#include <ostream>
|
|
|
|
namespace ripple {
|
|
|
|
/**
|
|
* A serializable number.
|
|
*
|
|
* This type is-a `Number`, and can be used everywhere that is accepted.
|
|
* This type simply integrates `Number` with the serialization framework,
|
|
* letting it be used for fields in ledger entries and transactions.
|
|
* It is effectively an `STAmount` sans `Asset`:
|
|
* it can represent a value of any token type (XRP, IOU, or MPT)
|
|
* without paying the storage cost of duplicating asset information
|
|
* that may be deduced from the context.
|
|
*/
|
|
class STNumber : public STBase, public CountedObject<STNumber>
|
|
{
|
|
private:
|
|
Number value_;
|
|
|
|
public:
|
|
using value_type = Number;
|
|
|
|
STNumber() = default;
|
|
explicit STNumber(SField const& field, Number const& value = Number());
|
|
STNumber(SerialIter& sit, SField const& field);
|
|
|
|
SerializedTypeID
|
|
getSType() const override;
|
|
std::string
|
|
getText() const override;
|
|
void
|
|
add(Serializer& s) const override;
|
|
|
|
Number const&
|
|
value() const;
|
|
void
|
|
setValue(Number const& v);
|
|
|
|
STNumber&
|
|
operator=(Number const& rhs)
|
|
{
|
|
setValue(rhs);
|
|
return *this;
|
|
}
|
|
|
|
bool
|
|
isEquivalent(STBase const& t) const override;
|
|
bool
|
|
isDefault() const override;
|
|
|
|
operator Number() const
|
|
{
|
|
return value_;
|
|
}
|
|
|
|
private:
|
|
STBase*
|
|
copy(std::size_t n, void* buf) const override;
|
|
STBase*
|
|
move(std::size_t n, void* buf) override;
|
|
};
|
|
|
|
std::ostream&
|
|
operator<<(std::ostream& out, STNumber const& rhs);
|
|
|
|
struct NumberParts
|
|
{
|
|
std::uint64_t mantissa = 0;
|
|
int exponent = 0;
|
|
bool negative = false;
|
|
};
|
|
|
|
NumberParts
|
|
partsFromString(std::string const& number);
|
|
|
|
STNumber
|
|
numberFromJson(SField const& field, Json::Value const& value);
|
|
|
|
} // namespace ripple
|
|
|
|
#endif
|