Show / Hide Table of Contents

Struct Currency

Represents a currency type. Every single value of Currency defines a distinct currency type. To draw a parallel with real world monetary, each Currency value represents such currencies as USD (US Dollar) or EUR (Euro), not values like $100 or €100.

Implements
IEquatable<Currency>
ISerializable
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: Libplanet.Types.Assets
Assembly: Libplanet.Types.dll
Syntax
[Serializable]
public readonly struct Currency : IEquatable<Currency>, ISerializable
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Examples

Here is how US Dollar can be represented using Currency:

var USMint = new PrivateKey();
var USD = Currency.Uncapped(ticker: "USD", decimalPlaces: 2, minter: USMint.ToAddress());
var twentyThreeBucks = 23 * USD;
// Or alternatively: USD * 23;
// Or explicitly: new FungibleAssetValue(USD, 23, 0)

Constructors

| Improve this Doc View Source

Currency(IValue)

Deserializes a Currency type from a Bencodex value.

Declaration
public Currency(IValue serialized)
Parameters
Type Name Description
Bencodex.Types.IValue serialized

The Bencodex value serialized by Serialize() method.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
Serialize()
| Improve this Doc View Source

Currency(HashDigest<SHA1>, String, Byte, IImmutableSet<Address>, Boolean, Nullable<FungibleAssetValue>)

An internal constructor for JSON deserialization. Do not use this directly.

Declaration
[JsonConstructor]
[Obsolete]
public Currency(HashDigest<SHA1> hash, string ticker, byte decimalPlaces, IImmutableSet<Address> minters, bool totalSupplyTrackable, FungibleAssetValue? maximumSupply)
Parameters
Type Name Description
HashDigest<SHA1> hash
String ticker
Byte decimalPlaces
IImmutableSet<Address> minters
Boolean totalSupplyTrackable
Nullable<FungibleAssetValue> maximumSupply
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue

Fields

| Improve this Doc View Source

DecimalPlaces

The number of digits to treat as minor units (i.e., exponent).

Declaration
[JsonInclude]
public readonly byte DecimalPlaces
Field Value
Type Description
Byte
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

Hash

The deterministic hash derived from other fields.

Declaration
[JsonInclude]
public readonly HashDigest<SHA1> Hash
Field Value
Type Description
HashDigest<SHA1>
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

Minters

The Addresses who can mint the currency. If this is null anyone can mint the currency.

Declaration
[JsonInclude]
public readonly IImmutableSet<Address> Minters
Field Value
Type Description
IImmutableSet<Address>
Remarks

Unlike null, an empty set means no one can mint the currency.

See Also
FungibleAssetValue
| Improve this Doc View Source

Ticker

The ticker symbol, e.g., "USD".

Declaration
[JsonInclude]
public readonly string Ticker
Field Value
Type Description
String
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

TotalSupplyTrackable

Whether the total supply of this instance of Currency is trackable.

Declaration
[JsonInclude]
public readonly bool TotalSupplyTrackable
Field Value
Type Description
Boolean
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue

Properties

| Improve this Doc View Source

MaximumSupply

The uppermost quantity of currency allowed to exist. null means unlimited supply.

Declaration
[JsonConverter(typeof(MaximumSupplyJsonConverter))]
public readonly FungibleAssetValue? MaximumSupply { get; }
Property Value
Type Description
Nullable<FungibleAssetValue>
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue

Methods

| Improve this Doc View Source

AllowsToMint(Address)

Returns true if and only if the given address is allowed to mint or burn assets of this currency.

Declaration
[Pure]
public readonly bool AllowsToMint(Address address)
Parameters
Type Name Description
Address address

The account address to test.

Returns
Type Description
Boolean

true if and only if the given address is allowed to mint or burn assets of this currency.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)

Define a Currency with a maximum supply limit.

Declaration
public static Currency Capped(string ticker, byte decimalPlaces, (BigInteger Major, BigInteger Minor) maximumSupply, Address minter)
Parameters
Type Name Description
String ticker

The ticker symbol, e.g., "USD".

Byte decimalPlaces

The number of digits to treat as minor units (i.e., exponent).

(T1 Item1, T2 Item2)<BigInteger, BigInteger> maximumSupply

The uppermost quantity of currency allowed to exist. For example, the maximumSupply parameter in Currency.Capped("ABC", 2, (123, 45), ...) means that the token ABC can be minted up to 123.45 ABC. See also MaximumSupply field which corresponds to this.

Address minter

The address who can mint the currency. To specify multiple minters, use the Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>) See also Minters field which corresponds to this.

Returns
Type Description
Currency

An instance of Currency with a maximum supply limit.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Exceptions
Type Condition
ArgumentException

Thrown when the given ticker is an empty string, or when either the Major or the Minor values of maximumSupply is a negative number, or when the given Minor unit for the maximumSupply is too big for the given decimalPlaces.

See Also
Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
| Improve this Doc View Source

Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)

Define a Currency with a maximum supply limit.

Declaration
public static Currency Capped(string ticker, byte decimalPlaces, (BigInteger Major, BigInteger Minor) maximumSupply, IImmutableSet<Address> minters)
Parameters
Type Name Description
String ticker

The ticker symbol, e.g., "USD".

Byte decimalPlaces

The number of digits to treat as minor units (i.e., exponent).

(T1 Item1, T2 Item2)<BigInteger, BigInteger> maximumSupply

The uppermost quantity of currency allowed to exist. For example, the maximumSupply parameter in Currency.Capped("ABC", 2, (123, 45), ...) means that the token ABC can be minted up to 123.45 ABC. See also MaximumSupply field which corresponds to this.

IImmutableSet<Address> minters

The Addresses who can mint the currency. See also Minters field which corresponds to this.

Returns
Type Description
Currency

An instance of Currency with a maximum supply limit.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Exceptions
Type Condition
ArgumentException

Thrown when the given ticker is an empty string, or when either the Major or the Minor values of maximumSupply is a negative number, or when the given Minor unit for the maximumSupply is too big for the given decimalPlaces.

See Also
FungibleAssetValue
| Improve this Doc View Source

Equals(Currency)

Represents a currency type. Every single value of Currency defines a distinct currency type. To draw a parallel with real world monetary, each Currency value represents such currencies as USD (US Dollar) or EUR (Euro), not values like $100 or €100.

Declaration
[Pure]
public readonly bool Equals(Currency other)
Parameters
Type Name Description
Currency other
Returns
Type Description
Boolean
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

Equals(Object)

Represents a currency type. Every single value of Currency defines a distinct currency type. To draw a parallel with real world monetary, each Currency value represents such currencies as USD (US Dollar) or EUR (Euro), not values like $100 or €100.

Declaration
[Pure]
public override readonly bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
Boolean
Overrides
ValueType.Equals(Object)
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

GetHashCode()

Represents a currency type. Every single value of Currency defines a distinct currency type. To draw a parallel with real world monetary, each Currency value represents such currencies as USD (US Dollar) or EUR (Euro), not values like $100 or €100.

Declaration
[Pure]
public override readonly int GetHashCode()
Returns
Type Description
Int32
Overrides
ValueType.GetHashCode()
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

Legacy(String, Byte, Address)

OBSOLETE! DO NOT USE.

(unless you are upgrading your project from an old version of Libplanet that did not support total supply tracking for Currencies and had a legacy Currency defined.)

Define a legacy Currency without total supply tracking, which is internally compatible with the legacy version.

Declaration
[Obsolete("Obsolete! Use Currency.Capped() or Currency.Uncapped() for new currencies.")]
public static Currency Legacy(string ticker, byte decimalPlaces, Address minter)
Parameters
Type Name Description
String ticker

The ticker symbol, e.g., "USD".

Byte decimalPlaces

The number of digits to treat as minor units (i.e., exponent).

Address minter

The address who can mint the currency. To specify multiple minters, use the Legacy(String, Byte, IImmutableSet<Address>) See also Minters field which corresponds to this.

Returns
Type Description
Currency

An instance of legacy Currency without total supply tracking.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Exceptions
Type Condition
ArgumentException

Thrown when the given ticker is an empty string.

See Also
Legacy(String, Byte, IImmutableSet<Address>)
| Improve this Doc View Source

Legacy(String, Byte, IImmutableSet<Address>)

OBSOLETE! DO NOT USE.

(unless you are upgrading your project from an old version of Libplanet that did not support total supply tracking for Currencies and had a legacy Currency defined.)

Define a legacy Currency without total supply tracking, which is internally compatible with the legacy version.

Declaration
[Obsolete("Obsolete! Use Currency.Capped() or Currency.Uncapped() for new currencies.")]
public static Currency Legacy(string ticker, byte decimalPlaces, IImmutableSet<Address> minters)
Parameters
Type Name Description
String ticker

The ticker symbol, e.g., "USD".

Byte decimalPlaces

The number of digits to treat as minor units (i.e., exponent).

IImmutableSet<Address> minters

The Addresses who can mint the currency. See also Minters field which corresponds to this.

Returns
Type Description
Currency

An instance of legacy Currency without total supply tracking.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Exceptions
Type Condition
ArgumentException

Thrown when the given ticker is an empty string.

See Also
FungibleAssetValue
| Improve this Doc View Source

Serialize()

Serializes the currency into a Bencodex value.

Declaration
[Pure]
public readonly IValue Serialize()
Returns
Type Description
Bencodex.Types.IValue

The serialized Bencodex value.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

ToString()

Represents a currency type. Every single value of Currency defines a distinct currency type. To draw a parallel with real world monetary, each Currency value represents such currencies as USD (US Dollar) or EUR (Euro), not values like $100 or €100.

Declaration
[Pure]
public override readonly string ToString()
Returns
Type Description
String
Overrides
ValueType.ToString()
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue
| Improve this Doc View Source

Uncapped(String, Byte, Address)

Define a Currency without a maximum supply limit.

Declaration
public static Currency Uncapped(string ticker, byte decimalPlaces, Address minter)
Parameters
Type Name Description
String ticker

The ticker symbol, e.g., "USD".

Byte decimalPlaces

The number of digits to treat as minor units (i.e., exponent).

Address minter

The address who can mint the currency. To specify multiple minters, use the Uncapped(String, Byte, IImmutableSet<Address>) See also Minters field which corresponds to this.

Returns
Type Description
Currency

An instance of Currency without a maximum supply limit.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Exceptions
Type Condition
ArgumentException

Thrown when the given ticker is an empty string.

See Also
Uncapped(String, Byte, IImmutableSet<Address>)
| Improve this Doc View Source

Uncapped(String, Byte, IImmutableSet<Address>)

Define a Currency without a maximum supply limit.

Declaration
public static Currency Uncapped(string ticker, byte decimalPlaces, IImmutableSet<Address> minters)
Parameters
Type Name Description
String ticker

The ticker symbol, e.g., "USD".

Byte decimalPlaces

The number of digits to treat as minor units (i.e., exponent).

IImmutableSet<Address> minters

The Addresses who can mint the currency. See also Minters field which corresponds to this.

Returns
Type Description
Currency

An instance of Currency without a maximum supply limit.

Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
Exceptions
Type Condition
ArgumentException

Thrown when the given ticker is an empty string.

See Also
FungibleAssetValue

Operators

| Improve this Doc View Source

Multiply(Currency, BigInteger)

Gets a fungible asset value with the given quantity of the specified currency.

Declaration
[Pure]
public static FungibleAssetValue operator *(Currency currency, BigInteger quantity)
Parameters
Type Name Description
Currency currency

The currency to get a value.

BigInteger quantity

The major unit of the fungible asset value, i.e., digits before the decimal separator.

Returns
Type Description
FungibleAssetValue

A fungible asset value with the given quantity of the specified currency.

Remarks

This cannot specify MinorUnit but only MajorUnit. For more precision, directly use FungibleAssetValue's constructors instead.

See Also
FungibleAssetValue
| Improve this Doc View Source

Multiply(BigInteger, Currency)

Gets a fungible asset value with the given quantity of the specified currency.

Declaration
[Pure]
public static FungibleAssetValue operator *(BigInteger quantity, Currency currency)
Parameters
Type Name Description
BigInteger quantity

The major unit of the fungible asset value, i.e., digits before the decimal separator.

Currency currency

The currency to get a value.

Returns
Type Description
FungibleAssetValue

A fungible asset value with the given quantity of the specified currency.

Remarks

This cannot specify MinorUnit but only MajorUnit. For more precision, directly use FungibleAssetValue's constructors instead.

See Also
FungibleAssetValue

Explicit Interface Implementations

| Improve this Doc View Source

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Represents a currency type. Every single value of Currency defines a distinct currency type. To draw a parallel with real world monetary, each Currency value represents such currencies as USD (US Dollar) or EUR (Euro), not values like $100 or €100.

Declaration
readonly void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info
StreamingContext context
Remarks

There are two types of Currencies: capped and uncapped. Capped currencies have a hard limit on the maximum minted amount, and uncapped currencies do not have the said limit. To define a Currency you may call either of the following.

  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), IImmutableSet<Address>)
  • Capped(String, Byte, (BigInteger Major, BigInteger Minor), Address)
  • Uncapped(String, Byte, IImmutableSet<Address>)
  • Uncapped(String, Byte, Address)
See Also
FungibleAssetValue

Implements

System.IEquatable<T>
System.Runtime.Serialization.ISerializable

See Also

FungibleAssetValue
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2023 Planetarium