Class RippleStateExtensions
Reads a LORippleState from one account's point of view.
Inheritance
Namespace: Xrpl.Models.Ledger
Assembly: Xrpl.dll
Syntax
public static class RippleStateExtensions
Remarks
A trust line is one ledger entry shared by two accounts. rippled puts the account with the
numerically smaller 160-bit AccountID on the Low side and the other on the High side (not the
smaller base58 text: the address text does not sort like the ID), stores
Balance from the Low account's point of view, and keeps the limits,
qualities and the paired lsfLow*/lsfHigh* flags per side.
The side of an account is read from LowLimit and HighLimit: rippled sets the issuer of each limit to the account that owns that side, so the entry names its own sides and nothing has to be derived from the addresses. A helper that takes an account throws System.ArgumentException when the account is on neither side, because answering for an account that is not on the line would be a guess.
Every method here is safe on a sparse entry (the FinalFields of a deleted node, a
PreviousFields projection): an absent flag word reads as "no flag set", an absent
quality as null, and an absent balance as zero. None of them throws
AmountOutOfRangeException for a balance or a limit above
the range of decimal.
Methods
| Edit this page View SourceGetBalanceFor(LORippleState, string)
The balance from the point of view of account: positive when the account
holds the token, negative when it has issued it to the counterparty.
Declaration
public static decimal GetBalanceFor(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| decimal | The balance; zero when a sparse entry does not carry one. |
Remarks
The ledger stores the balance from the Low side, so the High side gets it negated. The value saturates at decimal.MinValue/decimal.MaxValue for a balance beyond decimal (an issuer's supply can be) and is meant for comparisons and display. Use GetBalanceValueFor(LORippleState, string) for an amount that goes back to the ledger.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
| FormatException | The stored balance is not a number. |
GetBalanceValueFor(LORippleState, string)
The balance from the point of view of account as the ledger's own text,
with every digit kept. The counterpart of GetBalanceFor(LORippleState, string) for an amount sent back
to the ledger, where a saturated or rounded decimal would leave part of the
balance behind.
Declaration
public static string GetBalanceValueFor(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| string | The stored text for the Low side; the text with its sign flipped for the High side (a zero stays unsigned). Null when the entry has no balance, and for the High side when the stored text is not a number. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetFlagOf(LORippleState, string, RippleStateFlags, RippleStateFlags)
Whether a flag on the side of account is set: pass the Low and the High
variant of the same flag (for example lsfLowFreeze and lsfHighFreeze) and the
one that belongs to the account is tested.
Declaration
public static bool GetFlagOf(this LORippleState state, string account, RippleStateFlags lowFlag, RippleStateFlags highFlag)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
| RippleStateFlags | lowFlag | The flag as set by the Low account. |
| RippleStateFlags | highFlag | The flag as set by the High account. |
Returns
| Type | Description |
|---|---|
| bool | True when the flag is set; false when it is not or the entry has no flag word. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetLimitOf(LORippleState, string)
The limit account has set on the line. Its issuer is account.
Declaration
public static Currency GetLimitOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| Currency | The limit, or null when a sparse entry does not carry it. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetPeerFlagOf(LORippleState, string, RippleStateFlags, RippleStateFlags)
Whether a flag on the side of the counterparty of account is set. The
mirror of GetFlagOf(LORippleState, string, RippleStateFlags, RippleStateFlags).
Declaration
public static bool GetPeerFlagOf(this LORippleState state, string account, RippleStateFlags lowFlag, RippleStateFlags highFlag)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
| RippleStateFlags | lowFlag | The flag as set by the Low account. |
| RippleStateFlags | highFlag | The flag as set by the High account. |
Returns
| Type | Description |
|---|---|
| bool | True when the flag is set; false when it is not or the entry has no flag word. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetPeerLimitOf(LORippleState, string)
The limit the counterparty of account has set on the line.
Declaration
public static Currency GetPeerLimitOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| Currency | The limit, or null when a sparse entry does not carry it. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetPeerOf(LORippleState, string)
The other account on the trust line.
Declaration
public static string GetPeerOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| string | Classic address of the counterparty. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
| InvalidOperationException | The counterparty's limit is absent from a sparse entry, so its address is unknown. |
GetPeerQualityInOf(LORippleState, string)
The inbound quality the counterparty of account has set.
Declaration
public static uint? GetPeerQualityInOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| uint? | The quality, or null when the field is absent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetPeerQualityOutOf(LORippleState, string)
The outbound quality the counterparty of account has set.
Declaration
public static uint? GetPeerQualityOutOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| uint? | The quality, or null when the field is absent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetQualityInOf(LORippleState, string)
The inbound quality account has set, in billionths. The raw ledger field:
null or 0 means face value, and nothing is substituted for an absent field.
Declaration
public static uint? GetQualityInOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| uint? | The quality, or null when the field is absent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
GetQualityOutOf(LORippleState, string)
The outbound quality account has set. Same encoding as GetQualityInOf(LORippleState, string).
Declaration
public static uint? GetQualityOutOf(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| uint? | The quality, or null when the field is absent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
IsFlagSet(RippleStateFlags?, RippleStateFlags)
Tests a flag on a flag word that may be absent.
Declaration
public static bool IsFlagSet(this RippleStateFlags? flags, RippleStateFlags flag)
Parameters
| Type | Name | Description |
|---|---|---|
| RippleStateFlags? | flags | The flag word, or null when the entry did not carry one. |
| RippleStateFlags | flag | The flag to test. A combination of flags is set only when all of its bits are. |
Returns
| Type | Description |
|---|---|
| bool | true when |
Remarks
An absent word reads as "not set". A RippleState in the ledger always carries
Flags, so a null here is a sparse metadata projection: PreviousFields lists only
the fields a transaction changed, and an unlisted flag word means "unchanged". Combine such a
projection with the entry it belongs to through OverlayPreviousFields(LORippleState, LORippleState) before testing.
Writing the test as (flags & flag) != 0 on the nullable instead would read every
flag as set for a null word, because C# lifts null != 0 to true.
IsLowSide(LORippleState, string)
Whether account is the Low side of this trust line.
Declaration
public static bool IsLowSide(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| bool |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
IsPeerReserveSetFor(LORippleState, string)
Whether the line is in the owner count of the counterparty of account.
The mirror of IsReserveSetFor(LORippleState, string).
Declaration
public static bool IsPeerReserveSetFor(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| bool | True when the line counts toward the counterparty's owner reserve; false when it does not or the entry has no flag word. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
IsReserveSetFor(LORippleState, string)
Whether the line is in the owner count of account: the reserve flag of its
side is set (lsfLowReserve for the Low side, lsfHighReserve for the High side).
Declaration
public static bool IsReserveSetFor(this LORippleState state, string account)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | state | The trust line. |
| string | account | Classic address of an account on the line. |
Returns
| Type | Description |
|---|---|
| bool | True when the line counts toward the account's owner reserve; false when it does not or the entry has no flag word. |
Remarks
A line can sit in the owner count of one side only, of both, or, once a side has cleared its flag, of neither. The flag says whose owner count carries the line; a sponsor (LowSponsor/HighSponsor) may pay the reserve for that side instead of the account itself.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
OverlayPreviousFields(LORippleState, LORippleState)
The trust line as it was before a transaction: the PreviousFields of a metadata node laid
over its FinalFields.
Declaration
public static LORippleState OverlayPreviousFields(this LORippleState final, LORippleState previous)
Parameters
| Type | Name | Description |
|---|---|---|
| LORippleState | final | The entry's |
| LORippleState | previous | The entry's |
Returns
| Type | Description |
|---|---|
| LORippleState |
|
Remarks
PreviousFields lists only the fields the transaction changed, so every field it leaves out
comes from final. That includes Flags: a null
Flags in previous is "unchanged", while a
Flags of 0 is a real value (the transaction cleared every flag) and wins.
A field the transaction added (a quality set for the first time) is not in
PreviousFields either, and the merge cannot tell that from "unchanged": it keeps the
final value.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|