Class Currency
Class defining how to encode and decode Currencies
Implements
Namespace: Xrpl.BinaryCodec.Types
Assembly: Xrpl.BinaryCodec.dll
Syntax
public class Currency : Hash160, ISerializedType
Constructors
| Edit this page View SourceCurrency(byte[])
Constructs a Currency object
Declaration
public Currency(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | bytes buffer |
Fields
| Edit this page View SourceIsNative
Test if this amount is in units of Native Currency(XRP)
Declaration
public readonly bool IsNative
Field Value
| Type | Description |
|---|---|
| bool |
IsoCode
ISO code of this currency
Declaration
public readonly string IsoCode
Field Value
| Type | Description |
|---|---|
| string |
Xrp
Native XRP Currency
Declaration
public static readonly Currency Xrp
Field Value
| Type | Description |
|---|---|
| Currency |
Methods
| Edit this page View SourceEncodeCurrency(string)
Legacy method for standard XRPL currency encoding (bytes 12-14). Used for issued currency tokens, not Oracle PriceData.
Declaration
public static byte[] EncodeCurrency(string currencyCode)
Parameters
| Type | Name | Description |
|---|---|---|
| string | currencyCode | currency code |
Returns
| Type | Description |
|---|---|
| byte[] |
EncodeOracleCurrency(string)
Encode currency for Oracle XLS-47 format (left-aligned at bytes 0-2). This format is used for BaseAsset and QuoteAsset in PriceData objects.
Declaration
public static byte[] EncodeOracleCurrency(string currencyCode)
Parameters
| Type | Name | Description |
|---|---|---|
| string | currencyCode | 3-letter currency code. |
Returns
| Type | Description |
|---|---|
| byte[] | 20-byte array with currency at bytes 0-2. |
FromJson(JsonNode)
decode currency from json field
Declaration
public static Currency FromJson(JsonNode token)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonNode | token | json field |
Returns
| Type | Description |
|---|---|
| Currency |
FromOracleJson(JsonNode)
Decode currency from JSON for Oracle fields (XLS-47 format). Uses left-aligned ASCII encoding for 3-letter codes.
Declaration
public static Currency FromOracleJson(JsonNode token)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonNode | token | JSON token containing currency code. |
Returns
| Type | Description |
|---|---|
| Currency | Currency with Oracle encoding. |
FromOracleString(string)
Create a Currency for Oracle PriceData fields (XLS-47 format). Uses left-aligned ASCII encoding (bytes 0-2) for 3-letter codes, or direct hex for 40-character non-standard currencies. This differs from standard IOU currencies which use bytes 12-14.
Declaration
public static Currency FromOracleString(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | Currency code (XRP, 3-letter code, or 40-hex). |
Returns
| Type | Description |
|---|---|
| Currency | Currency with XLS-47 Oracle encoding. |
FromParser(BinaryParser, int?)
Defines how to read a Currency from a BinaryParser
Declaration
public static Currency FromParser(BinaryParser parser, int? hint = null)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryParser | parser | The binary parser to read Currency |
| int? | hint |
Returns
| Type | Description |
|---|---|
| Currency | A Blob object |
FromString(string)
decode currency from string
Declaration
public static Currency FromString(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | string currency code |
Returns
| Type | Description |
|---|---|
| Currency |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException |
GetCurrencyCodeFromTlcBytes(byte[], out bool)
get currency code from bytes. Supports both standard XRPL format (bytes 12-14) and Oracle XLS-47 format (left-aligned bytes 0-2).
Declaration
public static string GetCurrencyCodeFromTlcBytes(byte[] bytes, out bool isNative)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | bytes | bytes |
| bool | isNative | will true if currency is XRP |
Returns
| Type | Description |
|---|---|
| string |
ToString()
hash to string value
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
Operators
| Edit this page View Sourceimplicit operator Currency(string)
Declaration
public static implicit operator Currency(string v)
Parameters
| Type | Name | Description |
|---|---|---|
| string | v |
Returns
| Type | Description |
|---|---|
| Currency |
implicit operator Currency(JsonNode)
Declaration
public static implicit operator Currency(JsonNode v)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonNode | v |
Returns
| Type | Description |
|---|---|
| Currency |
implicit operator JsonNode(Currency)
Declaration
public static implicit operator JsonNode(Currency v)
Parameters
| Type | Name | Description |
|---|---|---|
| Currency | v |
Returns
| Type | Description |
|---|---|
| JsonNode |