|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <xrpl/beast/utility/Journal.h> |
| 4 | +#include <xrpl/ledger/ReadView.h> |
| 5 | +#include <xrpl/protocol/Issue.h> |
| 6 | +#include <xrpl/protocol/STAmount.h> |
| 7 | +#include <xrpl/protocol/STTx.h> |
| 8 | +#include <xrpl/protocol/TER.h> |
| 9 | + |
| 10 | +#include <map> |
| 11 | +#include <vector> |
| 12 | + |
| 13 | +namespace xrpl { |
| 14 | + |
| 15 | +/** |
| 16 | + * @brief Invariant: frozen trust line balance change is not allowed. |
| 17 | + * |
| 18 | + * We iterate all affected trust lines and ensure that they don't have |
| 19 | + * unexpected change of balance if they're frozen. |
| 20 | + */ |
| 21 | +class TransfersNotFrozen |
| 22 | +{ |
| 23 | + struct BalanceChange |
| 24 | + { |
| 25 | + std::shared_ptr<SLE const> const line; |
| 26 | + int const balanceChangeSign; |
| 27 | + }; |
| 28 | + |
| 29 | + struct IssuerChanges |
| 30 | + { |
| 31 | + std::vector<BalanceChange> senders; |
| 32 | + std::vector<BalanceChange> receivers; |
| 33 | + }; |
| 34 | + |
| 35 | + using ByIssuer = std::map<Issue, IssuerChanges>; |
| 36 | + ByIssuer balanceChanges_; |
| 37 | + |
| 38 | + std::map<AccountID, std::shared_ptr<SLE const> const> possibleIssuers_; |
| 39 | + |
| 40 | +public: |
| 41 | + void |
| 42 | + visitEntry(bool, std::shared_ptr<SLE const> const&, std::shared_ptr<SLE const> const&); |
| 43 | + |
| 44 | + bool |
| 45 | + finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&); |
| 46 | + |
| 47 | +private: |
| 48 | + bool |
| 49 | + isValidEntry(std::shared_ptr<SLE const> const& before, std::shared_ptr<SLE const> const& after); |
| 50 | + |
| 51 | + STAmount |
| 52 | + calculateBalanceChange( |
| 53 | + std::shared_ptr<SLE const> const& before, |
| 54 | + std::shared_ptr<SLE const> const& after, |
| 55 | + bool isDelete); |
| 56 | + |
| 57 | + void |
| 58 | + recordBalance(Issue const& issue, BalanceChange change); |
| 59 | + |
| 60 | + void |
| 61 | + recordBalanceChanges(std::shared_ptr<SLE const> const& after, STAmount const& balanceChange); |
| 62 | + |
| 63 | + std::shared_ptr<SLE const> |
| 64 | + findIssuer(AccountID const& issuerID, ReadView const& view); |
| 65 | + |
| 66 | + bool |
| 67 | + validateIssuerChanges( |
| 68 | + std::shared_ptr<SLE const> const& issuer, |
| 69 | + IssuerChanges const& changes, |
| 70 | + STTx const& tx, |
| 71 | + beast::Journal const& j, |
| 72 | + bool enforce); |
| 73 | + |
| 74 | + bool |
| 75 | + validateFrozenState( |
| 76 | + BalanceChange const& change, |
| 77 | + bool high, |
| 78 | + STTx const& tx, |
| 79 | + beast::Journal const& j, |
| 80 | + bool enforce, |
| 81 | + bool globalFreeze); |
| 82 | +}; |
| 83 | + |
| 84 | +} // namespace xrpl |
0 commit comments