Skip to content

Single Asset Vault #5224

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

Open
wants to merge 182 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 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
3715d7e
Fix bugs related to perm. domain checks, add unit test
Bronek Mar 11, 2025
4c586eb
Merge branch 'develop' into vault
Bronek Mar 11, 2025
840a464
Merge branch 'develop' into vault
Bronek Mar 13, 2025
238db87
Add check for lsfMPTCanClawback and lsfMPTCanLock
Bronek Mar 13, 2025
e093263
Fix formatting
Bronek Mar 13, 2025
b397524
Remove pointless comment
Bronek Mar 13, 2025
7b5680f
Fix VaultClawback and unit test
Bronek Mar 13, 2025
df8761d
Merge branch 'develop' into vault
Bronek Mar 17, 2025
2a8861d
DomainID authorization check moved to doApply
Bronek Mar 17, 2025
8e68838
Remove lsfMPTDomainCheck flag, delete expired MPToken
Bronek Mar 19, 2025
1df3ff8
Merge branch 'develop' into vault
Bronek Mar 19, 2025
d77fc57
Do not delete expired MPToken
Bronek Mar 19, 2025
6db2144
Improve checks in VaultSet VaultCreate and VaultDeposit
Bronek Mar 19, 2025
403ef0d
Allow resetting AssetMaximum to zero
Bronek Mar 19, 2025
4e862e0
AssetMaximum less than zero should yield temMALFORMED
Bronek Mar 19, 2025
b1fc3b7
Do not fail VaultSet if nothing changed
Bronek Mar 20, 2025
9a7def3
Do not apply IOU fees on VaultDeposit/VaultWithdraw
Bronek Mar 20, 2025
6b1cf7c
Fix clang compilation error
Bronek Mar 20, 2025
4c7119b
Add support for Destination field in VaultWithdraw
Bronek Mar 20, 2025
3d21021
Show Share.mpt_issuance_id rather than MPTokenIssuanceID
Bronek Mar 20, 2025
58f1530
Add ShareTotal to ledger_entry output
Bronek Mar 21, 2025
0959bf8
Enforce no negative balance at the end of transaction
Bronek Mar 21, 2025
1f005d2
Add WaiveTransferFee::Yes for consistency
Bronek Mar 21, 2025
d8880dd
Replace getSeqProxy().value() with getSeqValue() where appropriate
Bronek Mar 24, 2025
9c1a0aa
Cleanup handling of unsupported PseudoAccountOwnerType
Bronek Mar 24, 2025
1e565e8
Pseudo-accounts to use sequence 0
Bronek Mar 24, 2025
cc4f877
Merge branch 'develop' into vault
Bronek Mar 24, 2025
a173dd2
Disallow regular Clawback on Vault accounts
Bronek Mar 24, 2025
dd3edbd
Missed one getSeqValue()
Bronek Mar 24, 2025
ae68a09
Supplement ShareTotal in ledger_entry, ledger_data and account_objects.
Bronek Mar 25, 2025
fbe28f6
Switch sfAssetTotal sfAssetAvailable and sfLossUnrealized to required
Bronek Mar 25, 2025
2f06b34
Extend tests for updating permissioned domain
Bronek Mar 25, 2025
372555b
Rename tecVAULT_ACCOUNT to tecPSEUDO_ACCOUNT
Bronek Mar 25, 2025
05ebd0d
Make empty VaultID a temMALFORMED
Bronek Mar 25, 2025
afaa6ae
Add test for nontransferable shares
Bronek Mar 25, 2025
275e02f
Add UNREACHABLE and LCOV_EXCL_LINE
Bronek Mar 26, 2025
3883baf
Update transactions.macro comment for ttVAULT_CLAWBACK
Bronek Mar 26, 2025
d16e051
Remove Env::vault()
Bronek Mar 26, 2025
f5042df
Expand tests for numberFromJson
Bronek Mar 26, 2025
dee06df
Remove tecINVALID_DOMAIN error code
Bronek Mar 26, 2025
2e13dc1
Switch 'vault not found' to tecNO_ENTRY
Bronek Mar 26, 2025
b6d7ef6
Add check for AssetTotal in VaultDelete
Bronek Mar 26, 2025
0636d46
Rename sfAsset... fields to sfAssets...
Bronek Mar 26, 2025
33660ea
Add comment on tecNO_ENTRY vs tecOBJECT_NOT_FOUND
Bronek Mar 26, 2025
7686c3d
Rename ShareTotal to SharesTotal
Bronek Mar 27, 2025
0f99955
Merge branch 'develop' into vault
Bronek Mar 27, 2025
abaf213
Fix clang, minor refactor of createPseudoAccount
Bronek Mar 27, 2025
696cf2b
Merge branch 'develop' into vault
Bronek Mar 28, 2025
aff08b7
Add invariant checks for pseudo-account
Bronek Mar 28, 2025
f77ad36
Merge branch 'develop' into vault
Bronek Mar 28, 2025
d3c1d02
Return terADDRESS_COLLISION from preclaim if cannot allocate AccountID
Bronek Mar 28, 2025
1807b44
Fix bug in pseudoAccountAddress and add unit test
Bronek Mar 28, 2025
124512e
Add terADDRESS_COLLISION to AMMCreate::preclaim
Bronek Mar 28, 2025
83582b6
Add RPC unit test
Bronek Mar 31, 2025
b67d8e6
Add more comments on usage of enforceMPTokenAuthorization
Bronek Mar 31, 2025
a1c21a0
Rename sfMPTokenIssuanceID in Vault to sfShareMPTID
Bronek Mar 31, 2025
b6c7430
Add nullptr checks
Bronek Mar 31, 2025
93bd265
Move addEmptyHolding to VaultCreate and removeEmptyHolding to VaultDe…
Bronek Mar 31, 2025
2b86a1a
Enforce Destination checks on VaultWithdraw
Bronek Apr 1, 2025
ad6e048
Bring back addEmptyHolding and removeEmptyHolding to View
Bronek Apr 1, 2025
dc249b8
Add unit tests
Bronek Apr 1, 2025
09833ab
Improve checks in VaultWithdraw, more tests
Bronek Apr 2, 2025
fa0b021
Add RPC vault_info, remove RPC::supplementJson<ltVAULT>
Bronek Apr 2, 2025
5f53e4d
Change output structure of vault_info
Bronek Apr 2, 2025
dbbf682
Gate VaultCreate on featureMPTokensV1
Bronek Apr 2, 2025
85e7d29
Factor out isPseudoAccount
Bronek Apr 2, 2025
392e384
Change error code to tecLOCKED
Bronek Apr 3, 2025
6f4e7e8
Move isPseudoAccount near createPseudoAccount
Bronek Apr 3, 2025
af8ea3f
Rename 'share' to 'shares' in vault_info RPC
Bronek Apr 3, 2025
591437b
Mark featureSingleAssetVault as Supported::no
Bronek Apr 3, 2025
2737249
Merge branch 'develop' into vault
Bronek Apr 3, 2025
f6a9b4f
Remove unnecessary include
Bronek Apr 3, 2025
676ed9a
Return ter code from dirLink
Bronek Apr 3, 2025
8f9524b
Enforce lsfDefaultRipple flag in addEmptyHolding
Bronek Apr 3, 2025
1494ae3
Fix VaultDeposit::preclaim checks
Bronek Apr 4, 2025
e1e8859
Add // LCOV_EXCL_LINE with UNREACHABLE
Bronek Apr 4, 2025
442795b
Change vault_info to take vault_id or owner&seq
Bronek Apr 7, 2025
9c967f8
Disallow deleting locked MPToken
Bronek Apr 7, 2025
db19760
Both isFrozen and requireAuth are now recursive for vault shares
Bronek Apr 7, 2025
5f051c5
Merge branch 'develop' into vault
Bronek Apr 7, 2025
f839049
Enforce max recursion depth in VaultCreate, improve VaultDeposit checks
Bronek Apr 7, 2025
780d05e
Clang wants an explicit ctor to emplace in a vector
ximinez Apr 9, 2025
870f42e
Merge branch 'develop' into vault
ximinez Apr 9, 2025
cd726f9
Merge remote-tracking branch 'upstream/develop' into vault
ximinez Apr 9, 2025
7537590
Merge remote-tracking branch 'upstream/develop' into vault
ximinez Apr 9, 2025
2abbb25
Fix unit test that fails with varying reference fee
ximinez Apr 9, 2025
5fea68e
Merge branch 'develop' into vault
ximinez Apr 10, 2025
4578771
Merge branch 'develop' into vault
ximinez Apr 11, 2025
b1bf115
Merge branch 'develop' into vault
ximinez Apr 11, 2025
51f1764
Fix formatting
ximinez Apr 11, 2025
d6d07e6
Fix authorization issues
Bronek Apr 14, 2025
20ce0e7
Need to decrement owner counts in removeEmptyHolding
ximinez Apr 14, 2025
0ab7922
Code cleanup
Bronek Apr 23, 2025
7eadb88
Replace tecKILLED with tecLIMIT_EXCEEDED in VaultCreate depth exceeded
Bronek Apr 23, 2025
5cd3b1f
Add check in preclaim and extra tests
Bronek Apr 24, 2025
270355f
Keep existing order of checks
Bronek Apr 24, 2025
fb2eb35
Prohibit VaultCreate to assets without real issuer
Bronek Apr 24, 2025
6a25ac9
Decouple VaultDestroy from MPTokenIssuanceDestroy
Bronek Apr 25, 2025
b2abfc0
Minor cleanup in MPTokenIssuanceCreate
Bronek Apr 25, 2025
afeb628
Cleanup in MPTokenAuthorize
Bronek Apr 25, 2025
77c70d8
Update RPC codes, improve seq parsing
Bronek Apr 25, 2025
e949166
Add unit tests
Bronek Apr 25, 2025
22901af
Minor cleanup
Bronek Apr 25, 2025
7e5845f
Merge branch 'develop' into vault
Bronek Apr 28, 2025
5bfbb09
Minor improvements
Bronek Apr 28, 2025
d46a2d8
Allow resetting DomainID
Bronek Apr 28, 2025
a205906
Prevent pseudo-accounts from receiving checks
Bronek Apr 28, 2025
298aaac
Check for pseudo-account in other transaction types
Bronek Apr 28, 2025
071beca
Allow freezeing trust line to vault, disallow deleting vault when ass…
Bronek Apr 29, 2025
b03cd57
Merge branch 'develop' into vault
Bronek Apr 29, 2025
efe9f99
Unit test fix
Bronek Apr 29, 2025
ffb1959
Disallow deletion of vault if asset is under global lock
Bronek Apr 29, 2025
01cc089
Revert changes preventing deletion of a vault
Bronek Apr 29, 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
11 changes: 11 additions & 0 deletions include/xrpl/json/json_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#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 @@ -216,6 +218,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 Down Expand Up @@ -365,6 +368,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 @@ -436,6 +441,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
1 change: 0 additions & 1 deletion include/xrpl/protocol/IOUAmount.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#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 @@ -191,6 +191,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
10 changes: 10 additions & 0 deletions include/xrpl/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ std::size_t constexpr maxMPTokenMetadataLength = 1024;
/** The maximum amount of MPTokenIssuance */
std::uint64_t constexpr maxMPTokenAmount = 0x7FFF'FFFF'FFFF'FFFFull;

/** The maximum length of Data payload */
std::size_t constexpr maxDataPayloadLength = 256;

/** Vault withdrawal policies */
std::uint8_t constexpr vaultStrategyFirstComeFirstServe = 1;

/** Maximum recursion depth for vault shares being put as an asset inside
* another vault; counted from 0 */
std::uint8_t constexpr maxAssetCheckDepth = 5;

/** 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
12 changes: 11 additions & 1 deletion include/xrpl/protocol/STBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ struct JsonOptions
}
};

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 this right location for this? Should it perhaps go to json_value.h?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, because JsonOptions is defined in this file.

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

namespace detail {
class STVar;
}
Expand Down Expand Up @@ -157,7 +167,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