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

Open
wants to merge 69 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
69 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
25a20ad
Add VaultID to account
Bronek Jan 23, 2025
2c4a224
Verify credentials in VaultDeposit
Bronek Jan 23, 2025
9bf9a1e
Merge branch 'develop' into vault
Bronek Jan 24, 2025
86d249a
Fix checo of expired credential
Bronek Jan 24, 2025
65d6c48
Unit tests naming fix
Bronek Jan 24, 2025
02dec4f
Merge branch 'develop' into vault
Bronek Jan 27, 2025
3eebdae
Implement MPT domain checks
Bronek Jan 27, 2025
ad68074
MPT permissioned domain checks
Bronek Jan 30, 2025
06a8a61
WIP trying to fix MSVC compilation error
Bronek Jan 31, 2025
a98e59a
Revert "WIP trying to fix MSVC compilation error"
ximinez Jan 31, 2025
21e0e7e
Fix ICE errors by reusing a global static const object
ximinez Jan 31, 2025
eed18d1
Remove unnecessary ValueProxy friend operator !=
ximinez Jan 31, 2025
c3f9a4c
Fix MSVC build: Get the intended const& for some fields
ximinez Jan 31, 2025
d1c7d1a
Merge branch 'develop' into vault
Bronek Feb 3, 2025
8baadd5
Fix clang build error
Bronek Feb 3, 2025
9decc05
Rename getSequence to getSeqValue
Bronek Feb 3, 2025
6765c10
Check permissioned domain enabled if DomainID is used
Bronek Feb 4, 2025
1884ec5
Check for frozen assets in preclaim
Bronek Feb 4, 2025
acaed58
Prevent deposit when asset is frozen for depositor
Bronek Feb 4, 2025
ffaa8bd
Improve checks in Vault
Bronek Feb 6, 2025
b7c9577
Remove unnecessary check
Bronek Feb 6, 2025
87d8881
Merge branch 'develop' into vault
Bronek Feb 7, 2025
c1d8bc4
Enforce freeze of pseudo-account
Bronek Feb 7, 2025
e9ed800
Optimise isFrozen check for pair of accounts
Bronek Feb 7, 2025
9d619b9
Merge branch 'develop' into vault
Bronek Feb 7, 2025
3f5df80
Merge branch 'develop' into vault
Bronek Feb 24, 2025
a0632a0
Add WithdrawalPolicy
Bronek Feb 25, 2025
04503c9
Enforce non-negative amounts
Bronek Feb 25, 2025
6370448
Merge branch 'develop' into vault
Bronek Mar 6, 2025
152da6e
Use unchecked for negative amount in unit tests
Bronek Mar 6, 2025
ac6d26a
Switch error code for non-transferable to tecNO_AUTH
Bronek Mar 6, 2025
1756fa7
Switch sfAmount in VaultClawback from defaulted to optional
Bronek Mar 6, 2025
fc2e1a2
Remove unused Json::Value operator=
Bronek Mar 6, 2025
4dc2025
Rename maxVaultDataLength to maxDataPayloadLength
Bronek Mar 7, 2025
1589498
Improve VaultClawback checks
Bronek Mar 7, 2025
b0c2b97
Enforce PD is enabled if sfDomainID is set
Bronek Mar 7, 2025
1441c91
Merge branch 'develop' into vault
Bronek Mar 7, 2025
65fdac0
Fix logic error in isVaultPseudoAccountFrozen
Bronek Mar 10, 2025
8ca6a62
Error codes change in accountHolds must be amendment gated
Bronek Mar 10, 2025
7b4e901
Replace assert with XRPL_ASSERT
Bronek Mar 10, 2025
90fef02
Factor out static Number getShareTotal() from View.cpp
Bronek Mar 10, 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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not used and should be removed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this function implementation changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose to give the equivalent output to both setJson and to_json

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 = 83;
static constexpr std::size_t numFeatures = 84;

/** 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};
}

} // namespace keylet

// Everything below is deprecated and should be removed in favor of keylets:
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 @@ -111,6 +111,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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to suggest renaming this to maxMetaDataLength. I'm seeing a trend in specs to define metadata fields with a limit of 256 bytes. I'm thinking one variable that can be used everywhere would be more useful than a proliferation of identical variables for every use case. The exceptions (like maxMPTokenMetaDataLength) can create one-offs as needed. Also, this comment still refers to MPToken.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe maxDataPayloadLength would be more accurate.


/** 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
22 changes: 20 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,15 @@ 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();
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