Options
All
• Public
• Public/Protected
• All

Class ChainValue

A Value Object to facilitate calculations for token and coin values (QNT/NQT).

For efficiency reasons, the monetary values/quantities are stored as integers with a prefined set of decimals, e.g. Signa has 8 decimals and stores the values as Planck that is 1 Signa = 100_000_000 Planck (NQT) and tokens have configurable decimals (0 to 8), so that a custom FooCoin can hav 2 decimals only where 1 FOO = 100 FOOQNT

In this context integer quantities are denominates as _atomic values and fractional values considering the decimals are denominated as compound values.

Note: This class uses a big number representation (ES5 compatible) under the hood, so number limits and numeric calculations are much more precise than JS number type

• ChainValue

Constructors

constructor

• Constructs a value object instance for calculations. The initial value is 0;

Parameters

• decimals: number

The number of decimals of the amount. Must be between 0 and 8

Methods

• Adds another value to this value

Parameters

• chainValue: ChainValue

The other value to be added

Returns ChainValue

the mutated value object

divide

• Divides this value object with a numeric value (not ChainValue!)

Parameters

• value: number | string

A numeric value to be divided by

Returns ChainValue

the mutated value object

equals

• Checks for equality

Parameters

• value: ChainValue

The other value to be compared

Returns boolean

true if equal, otherwise false

getAtomic

• getAtomic(): string

getCompound

• getCompound(): string
• Gets the 'compound' representation

Returns string

value in decimal related representation, i.e. 100 QNT with 3 decimals results in `'0.3'`

getDecimals

• getDecimals(): number

getRaw

• getRaw(): BigNumber

greater

• Checks for greater value

Parameters

• chainValue: ChainValue

The other value to be compared

Returns boolean

true if greater, otherwise false

greaterOrEqual

• Checks for greater or equality value

Parameters

• chainValue: ChainValue

The other value to be compared

Returns boolean

true if greater or equal, otherwise false

less

• Checks for lesser value

Parameters

• chainValue: ChainValue

The other value to be compared

Returns boolean

true if less, otherwise false

lessOrEqual

• Checks for lesser or equality

Parameters

• chainValue: ChainValue

The other value to be compared

Returns boolean

true if less or equal, otherwise false

multiply

• Multiplies this value object with a numeric value (not ChainValue!)

Parameters

• value: number | string

A numeric value to be multiplied with

Returns ChainValue

the mutated value object

setAtomic

• Sets value as atomic value, i.e. overwrites current hold value

Parameters

• a: number | string

The atomic value. Float numbers are floored to first lower integer, i.e. `1.23` -> `1`

Returns ChainValue

the updated value object

setCompound

• Sets as 'compound' representation

Parameters

• c: string | number

compound value

Returns ChainValue

the updated value object

subtract

• Subtracts another value from this value

Parameters

• chainValue: ChainValue

The other value to be subtracted

Returns ChainValue

the mutated value object

Static create

• Constructs a value object instance for calculations. The initial value is 0;

Parameters

• decimals: number

The number of decimals of the amount. Must be between 0 and 8