Documentation ¶
Index ¶
- type CoinValue
- func (v *CoinValue[D]) Add(other Value) Value
- func (v CoinValue[D]) CoinName() string
- func (v CoinValue[D]) Coins() decimal.Decimal
- func (v *CoinValue[D]) Div(other Value) Value
- func (v *CoinValue[D]) DivScalar(scalar *big.Int) Value
- func (v *CoinValue[D]) Mul(other Value) Value
- func (v *CoinValue[D]) MulScalar(scalar *big.Int) Value
- func (v CoinValue[D]) Same(other Value) bool
- func (v CoinValue[D]) ScaledValue(exp int32) decimal.Decimal
- func (v *CoinValue[D]) Sub(other Value) Value
- func (v CoinValue[D]) Units() *big.Int
- type Value
- type ValueDefinition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CoinValue ¶
type CoinValue[D ValueDefinition] struct { // contains filtered or unexported fields }
func NewCoinValue ¶
func NewCoinValue[D ValueDefinition](value *big.Int) *CoinValue[D]
func NewCoinValueFromCoins ¶
func NewCoinValueFromCoins[D ValueDefinition](value decimal.Decimal) *CoinValue[D]
func NewCoinValueFromScaled ¶
func NewCoinValueFromScaled[D ValueDefinition](value decimal.Decimal, exp int32) *CoinValue[D]
func (*CoinValue[D]) Add ¶
Add adds the value of another CoinValue to the current CoinValue.
It takes a Value as a parameter and returns a Value. The function checks if the current CoinValue and the other Value have the same coin name. If they don't, it panics with the message "cannot add values of different coins". If they are the same, it creates a new CoinValue with the same definition and adds the units of the other Value to the current CoinValue's value. The function returns the new CoinValue.
Parameters: - other: the Value to add with.
Returns: - Value: the new CoinValue after the addition.
func (CoinValue[D]) Coins ¶
Coins returns the value of the CoinValue in whole coin units.
For example for Ethereum this would return the value denomitated in Ether.
Returns: - decimal.Decimal: The value of the CoinValue in whole coind units.
func (*CoinValue[D]) Div ¶
Div divides the value of a CoinValue by another Value.
It takes a Value as a parameter and returns a Value. The function checks if the current CoinValue and the other Value have the same coin name. If they don't, it panics with the message "cannot divide values of different coins". If they are the same, it creates a new CoinValue with the same definition and divides the units of the current CoinValue's value by the units of the other Value. The function returns the new CoinValue.
Parameters: - other: the Value to divide with.
Returns: - Value: the new CoinValue after the division.
func (*CoinValue[D]) DivScalar ¶
DivScalar divides the value of a CoinValue by a scalar value.
It takes a pointer to a big.Int as a parameter and returns a Value. The function creates a new CoinValue with the same definition and divides the units of the current CoinValue's value by the scalar value. The function returns the new CoinValue.
Parameters: - scalar: a pointer to a big.Int representing the scalar value to divide with.
Returns: - Value: the new CoinValue after the division.
func (*CoinValue[D]) Mul ¶
Mul multiplies the value of another CoinValue with the current CoinValue.
It takes a Value as a parameter and returns a Value. The function checks if the current CoinValue and the other Value have the same coin name. If they don't, it panics with the message "cannot multiply values of different coins". If they are the same, it creates a new CoinValue with the same definition and multiplies the units of the other Value with the current CoinValue's value. The function returns the new CoinValue.
Parameters: - other: the Value to multiply with.
Returns: - Value: the new CoinValue after the multiplication.
func (*CoinValue[D]) MulScalar ¶
MulScalar multiplies the value of a CoinValue by a scalar value.
It takes a pointer to a big.Int as a parameter and returns a Value. The function creates a new CoinValue with the same definition and multiplies the units of the current CoinValue's value by the scalar value. The function returns the new CoinValue.
Parameters: - scalar: a pointer to a big.Int representing the scalar value to multiply with.
Returns: - Value: the new CoinValue after the multiplication.
func (CoinValue[D]) Same ¶
Same checks if the CoinValue is the same as another Value by comparing their coin names.
Parameters: - other: the Value to compare with.
Returns: - bool: true if the coin names are the same, false otherwise.
func (CoinValue[D]) ScaledValue ¶
ScaledValue returns the value of the CoinValue in decimal form, scaled by the given exponent.
For example for Ethereum the exponent value 9 would return the value denomitated in Gwei.
Parameters: - exp: the exponent to scale the value by.
Returns: - decimal.Decimal: the scaled value of the CoinValue.
func (*CoinValue[D]) Sub ¶
Sub subtracts the value of another CoinValue from the current CoinValue.
It takes a Value as a parameter and returns a Value. The function checks if the current CoinValue and the other Value have the same coin name. If they don't, it panics with the message "cannot subtract values of different coins". If they are the same, it creates a new CoinValue with the same definition and subtracts the units of the other Value from the current CoinValue's value. The function returns the new CoinValue.
Parameters: - other: the Value to substract with.
Returns: - Value: the new CoinValue after the subtraction.
type Value ¶
type Value interface { Units() *big.Int Coins() decimal.Decimal ScaledValue(exp int32) decimal.Decimal CoinName() string Same(other Value) bool Add(other Value) Value Sub(other Value) Value Mul(other Value) Value Div(other Value) Value MulScalar(scalar *big.Int) Value DivScalar(scalar *big.Int) Value }