Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Asset Vault #5224

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1a032f0
Integrate STNumber with STParsedJSON
thejohnfreeman Nov 7, 2024
ff8c649
Start vault implementation
thejohnfreeman Oct 17, 2024
a8ec8e7
wip
thejohnfreeman Nov 12, 2024
d09e74e
format
thejohnfreeman Nov 12, 2024
1680477
progress
thejohnfreeman Nov 12, 2024
ebc97ae
progress
thejohnfreeman Nov 12, 2024
286612c
progress
thejohnfreeman Nov 12, 2024
6046fa2
progress
thejohnfreeman Nov 13, 2024
1255216
progress
thejohnfreeman Nov 13, 2024
1ff1274
AND_THEN
thejohnfreeman Nov 14, 2024
ea6c040
wip
thejohnfreeman Nov 14, 2024
ea30f44
fix
thejohnfreeman Nov 22, 2024
12646cb
revise tests
thejohnfreeman Dec 3, 2024
54d511b
remove blob constants
thejohnfreeman Dec 6, 2024
b5619fb
bless sfAsset to carry MPT
thejohnfreeman Dec 6, 2024
ad58166
wip clawback
thejohnfreeman Dec 6, 2024
ecec6e5
Fix failing MPToken payment test
Bronek Dec 17, 2024
eae2cd3
Fix compilation errors
Bronek Dec 18, 2024
526f715
Comment out failing test
Bronek Dec 18, 2024
b9f1200
Fix formatting
Bronek Dec 18, 2024
241429b
Simplify conversions to Json::Value
Bronek Dec 18, 2024
8d5cfb9
Merge branch 'develop' into vault
Bronek Jan 13, 2025
bf8bbff
Merge branch 'develop' into vault
Bronek Jan 15, 2025
375614d
Merge branch 'develop' into vault
Bronek Jan 17, 2025
c325b6c
Fix Vault unit tests
Bronek Jan 17, 2025
dbaa12a
WIP permissioned domain support
Bronek Jan 17, 2025
580a85f
WIP support adding domainID in VaultSet
Bronek Jan 20, 2025
c08f86d
Remove temSTRING_TOO_LARGE, fix authorizedDomain, refactor Vault_test
Bronek Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions include/xrpl/json/json_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
#ifndef RIPPLE_JSON_JSON_VALUE_H_INCLUDED
#define RIPPLE_JSON_JSON_VALUE_H_INCLUDED

#include <xrpl/basics/Number.h>
#include <xrpl/json/json_forwards.h>
#include <cstring>
#include <map>
#include <string>
#include <utility>
#include <vector>

/** \brief JSON (JavaScript Object Notation).
Expand Down Expand Up @@ -215,6 +217,7 @@ class Value
Value(UInt value);
Value(double value);
Value(const char* value);
Value(ripple::Number const& value);
/** \brief Constructs a value from a static string.

* Like other value string constructor but do not duplicate the string for
Expand All @@ -237,6 +240,17 @@ class Value
Value&
operator=(Value&& other);

template <typename T>
Value&
operator=(T const& rhs)
requires(
!std::is_convertible_v<T, Value> &&
std::is_convertible_v<decltype(to_json(std::declval<T>())), Value>)
{
*this = to_json(rhs);
return *this;
}

Value(Value&& other) noexcept;

/// Swap values.
Expand Down Expand Up @@ -364,6 +378,8 @@ class Value
*/
Value&
operator[](const StaticString& key);
Value const&
operator[](const StaticString& key) const;

/// Return the member named key if it exist, defaultValue otherwise.
Value
Expand Down Expand Up @@ -435,6 +451,12 @@ class Value
int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
};

inline Value
to_json(ripple::Number const& number)
{
return to_string(number);
}

bool
operator==(const Value&, const Value&);

Expand Down
8 changes: 0 additions & 8 deletions include/xrpl/protocol/AMMCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ class STObject;
class STAmount;
class Rules;

/** Calculate AMM account ID.
*/
AccountID
ammAccountID(
std::uint16_t prefix,
uint256 const& parentHash,
uint256 const& ammID);

/** Calculate Liquidity Provider Token (LPT) Currency.
*/
Currency
Expand Down
16 changes: 13 additions & 3 deletions include/xrpl/protocol/Asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
#ifndef RIPPLE_PROTOCOL_ASSET_H_INCLUDED
#define RIPPLE_PROTOCOL_ASSET_H_INCLUDED

#include <xrpl/basics/Number.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/protocol/Issue.h>
#include <xrpl/protocol/MPTIssue.h>

namespace ripple {

class Asset;
class STAmount;

template <typename TIss>
concept ValidIssueType =
Expand Down Expand Up @@ -92,6 +94,9 @@ class Asset
void
setJson(Json::Value& jv) const;

STAmount
operator()(Number const&) const;

bool
native() const
{
Expand All @@ -114,6 +119,14 @@ class Asset
equalTokens(Asset const& lhs, Asset const& rhs);
};

inline Json::Value
to_json(Asset const& asset)
{
Json::Value jv;
asset.setJson(jv);
return jv;
}

template <ValidIssueType TIss>
constexpr bool
Asset::holds() const
Expand Down Expand Up @@ -219,9 +232,6 @@ validJSONAsset(Json::Value const& jv);
Asset
assetFromJson(Json::Value const& jv);

Json::Value
to_json(Asset const& asset);

} // namespace ripple

#endif // RIPPLE_PROTOCOL_ASSET_H_INCLUDED
2 changes: 1 addition & 1 deletion include/xrpl/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 85;
static constexpr std::size_t numFeatures = 86;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down
1 change: 0 additions & 1 deletion include/xrpl/protocol/IOUAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <boost/operators.hpp>
#include <cstdint>
#include <string>
#include <utility>

namespace ripple {

Expand Down
9 changes: 9 additions & 0 deletions include/xrpl/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@ mptoken(uint256 const& mptokenKey)
Keylet
mptoken(uint256 const& issuanceKey, AccountID const& holder) noexcept;

Keylet
vault(AccountID const& owner, std::uint32_t seq) noexcept;

inline Keylet
vault(uint256 const& vaultKey)
{
return {ltVAULT, vaultKey};
}

Keylet
permissionedDomain(AccountID const& account, std::uint32_t seq) noexcept;

Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/LedgerFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ enum LedgerSpecificFlags {

// ltCREDENTIAL
lsfAccepted = 0x00010000,

// ltVAULT
lsfVaultPrivate = 0x00010000,
};

//------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions include/xrpl/protocol/MPTAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
#include <xrpl/basics/contract.h>
#include <xrpl/basics/safe_cast.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/json/json_value.h>

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/operators.hpp>

#include <cstdint>
#include <optional>
#include <string>
#include <type_traits>

namespace ripple {

Expand Down
7 changes: 5 additions & 2 deletions include/xrpl/protocol/MPTIssue.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class MPTIssue
AccountID const&
getIssuer() const;

MPTID const&
getMptID() const;
constexpr MPTID const&
getMptID() const
{
return mptID_;
}

std::string
getText() const;
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ std::size_t constexpr maxMPTokenMetadataLength = 1024;
/** The maximum amount of MPTokenIssuance */
std::uint64_t constexpr maxMPTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;

/** The maximum length of MPTokenMetadata */
std::size_t constexpr maxVaultDataLength = 256;

/** A ledger index. */
using LedgerIndex = std::uint32_t;

Expand Down
1 change: 0 additions & 1 deletion include/xrpl/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <cstdint>
#include <map>
#include <utility>

namespace ripple {

Expand Down
23 changes: 21 additions & 2 deletions include/xrpl/protocol/STAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ class STAmount final : public STBase, public CountedObject<STAmount>
template <AssetType A>
STAmount(A const& asset, int mantissa, int exponent = 0);

template <AssetType A>
STAmount(A const& asset, Number const& number)
: STAmount(asset, number.mantissa(), number.exponent())
{
}

// Legacy support for new-style amounts
STAmount(IOUAmount const& amount, Issue const& issue);
STAmount(XRPAmount const& amount);
Expand Down Expand Up @@ -230,6 +236,9 @@ class STAmount final : public STBase, public CountedObject<STAmount>
STAmount&
operator=(XRPAmount const& amount);

STAmount&
operator=(Number const&);

//--------------------------------------------------------------------------
//
// Modification
Expand Down Expand Up @@ -268,7 +277,7 @@ class STAmount final : public STBase, public CountedObject<STAmount>
std::string
getText() const override;

Json::Value getJson(JsonOptions) const override;
Json::Value getJson(JsonOptions = JsonOptions::none) const override;

void
add(Serializer& s) const override;
Expand Down Expand Up @@ -417,7 +426,7 @@ STAmount
amountFromQuality(std::uint64_t rate);

STAmount
amountFromString(Asset const& issue, std::string const& amount);
amountFromString(Asset const& asset, std::string const& amount);

STAmount
amountFromJson(SField const& name, Json::Value const& v);
Expand Down Expand Up @@ -541,6 +550,16 @@ STAmount::operator=(XRPAmount const& amount)
return *this;
}

inline STAmount&
STAmount::operator=(Number const& number)
{
mIsNegative = number.mantissa() < 0;
mValue = mIsNegative ? -number.mantissa() : number.mantissa();
mOffset = number.exponent();
canonicalize();
return *this;
}

inline void
STAmount::negate()
{
Expand Down
10 changes: 9 additions & 1 deletion include/xrpl/protocol/STBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ struct JsonOptions
}
};

template <typename T>
requires requires(T const& t) { t.getJson(JsonOptions::none); }
Json::Value
to_json(T const& t)
{
return t.getJson(JsonOptions::none);
}

namespace detail {
class STVar;
}
Expand Down Expand Up @@ -155,7 +163,7 @@ class STBase
virtual std::string
getText() const;

virtual Json::Value getJson(JsonOptions /*options*/) const;
virtual Json::Value getJson(JsonOptions = JsonOptions::none) const;

virtual void
add(Serializer& s) const;
Expand Down
10 changes: 10 additions & 0 deletions include/xrpl/protocol/STIssue.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class STIssue final : public STBase, CountedObject<STIssue>
using value_type = Asset;

STIssue() = default;
STIssue(STIssue const& rhs) = default;

explicit STIssue(SerialIter& sit, SField const& name);

Expand All @@ -45,6 +46,15 @@ class STIssue final : public STBase, CountedObject<STIssue>

explicit STIssue(SField const& name);

STIssue&
operator=(STIssue const& rhs) = default;
STIssue&
operator=(Asset const& rhs)
{
asset_ = rhs;
return *this;
}

template <ValidIssueType TIss>
TIss const&
get() const;
Expand Down
20 changes: 20 additions & 0 deletions include/xrpl/protocol/STNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class STNumber : public STBase, public CountedObject<STNumber>
void
setValue(Number const& v);

STNumber&
operator=(Number const& rhs)
{
setValue(rhs);
return *this;
}

bool
isEquivalent(STBase const& t) const override;
bool
Expand All @@ -83,6 +90,19 @@ class STNumber : public STBase, public CountedObject<STNumber>
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
Loading
Loading