mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
- Refactor Number internals away from int64 to uint64 & a sign flag
- ctors and accessors return `rep`. Very few things expose
`internalrep`.
- An exception is "unchecked" and the new "normalized", which explicitly
take an internalrep. But with those special control flags, it's easier
to distinguish and control when they are used.
- For now, skip the larger mantissas in AMM transactions and tests
- Remove trailing zeros from scientific notation Number strings
- Update tests. This has the happy side effect of making some of the string
representations _more_ consistent between the small and large
mantissa ranges.
- Add semi-automatic rounding of STNumbers based on Asset types
- Create a new SField metadata enum, sMD_NeedsAsset, which indicates
the field should be associated with an Asset so it can be rounded.
- Add a new STTakesAsset intermediate class to handle the Asset
association to a derived ST class. Currently only used in STNumber,
but could be used by other types in the future.
- Add "associateAsset" which takes an SLE and an Asset, finds the
sMD_NeedsAsset fields, and associates the Asset to them. In the case
of STNumber, that both stores the Asset, and rounds the value
immediately.
- Transactors only need to add a call to associateAsset _after_ all of
the STNumbers have been set. Unfortunately, the inner workings of
STObject do not do the association correctly with uninitialized
fields.
- When serializing an STNumber that has an Asset, round it before
serializing.
- Add an override of roundToAsset, which rounds a Number value in place
to an Asset, but without any additional scale.
- Update and fix a bunch of Loan-related tests to accommodate the
expanded Number class.
---------
Co-authored-by: Vito <5780819+Tapanito@users.noreply.github.com>
Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com>
64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#ifndef XRPL_PROTOCOL_STTAKESASSET_H_INCLUDED
|
|
#define XRPL_PROTOCOL_STTAKESASSET_H_INCLUDED
|
|
|
|
#include <xrpl/protocol/Asset.h>
|
|
#include <xrpl/protocol/STBase.h>
|
|
|
|
namespace ripple {
|
|
|
|
/** Intermediate class for any STBase-derived class to store an Asset.
|
|
*
|
|
* In the class definition, this class should be specified as a base class
|
|
* _instead_ of STBase.
|
|
*
|
|
* Specifically, the Asset is only stored and used at runtime. It should not be
|
|
* serialized to the ledger.
|
|
*
|
|
* The derived class decides what to do with the Asset, and when. It will not
|
|
* necessarily be set at any given time. As of this writing, only STNumber uses
|
|
* it to round the stored Number to the Asset's precision both when associated,
|
|
* and when serializing the Number.
|
|
*/
|
|
class STTakesAsset : public STBase
|
|
{
|
|
protected:
|
|
std::optional<Asset> asset_;
|
|
|
|
public:
|
|
using STBase::STBase;
|
|
using STBase::operator=;
|
|
|
|
virtual void
|
|
associateAsset(Asset const& a);
|
|
};
|
|
|
|
inline void
|
|
STTakesAsset::associateAsset(Asset const& a)
|
|
{
|
|
asset_.emplace(a);
|
|
}
|
|
|
|
class STLedgerEntry;
|
|
|
|
/** Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
|
|
*
|
|
* This function iterates over all fields in the given ledger entry. For each
|
|
* field that is set and has the SField::sMD_NeedsAsset metadata flag, it calls
|
|
* `associateAsset` on that field with the given Asset. Such field must be
|
|
* derived from STTakesAsset - if it is not, the conversion will throw.
|
|
*
|
|
* Typically, associateAsset should be called near the end of doApply() of any
|
|
* Transactor classes on the SLEs of any new or modified ledger entries
|
|
* containing STNumber fields, after doing all of the modifications t the SLEs.
|
|
*
|
|
* @param sle The ledger entry whose fields will be updated.
|
|
* @param asset The Asset to associate with the relevant fields.
|
|
*
|
|
*/
|
|
void
|
|
associateAsset(STLedgerEntry& sle, Asset const& asset);
|
|
|
|
} // namespace ripple
|
|
|
|
#endif
|