money

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FiatDecimals = int64(2)
	FiatMin      = float64(0.01)
	FiatMax      = float64(10_000_000)
)

Variables

View Source
var (
	ErrInvalidFiatCurrency = errors.New("unsupported fiat currency")
	ErrIncompatibleMoney   = errors.New("incompatible money type")
	ErrNegative            = errors.New("money can't be negative")
	ErrParse               = errors.New("unable to parse value")
)

Functions

This section is empty.

Types

type Blockchain

type Blockchain string

CRYPTO ------------------

func (Blockchain) String

func (b Blockchain) String() string

type CryptoCurrency

type CryptoCurrency struct {
	Blockchain     Blockchain
	BlockchainName string
	NetworkID      string
	TestNetworkID  string

	Type   CryptoCurrencyType
	Ticker string
	Name   string

	Decimals int64

	TokenContractAddress     string
	TestTokenContractAddress string
	Aliases                  []string
	Deprecated               bool
}

CryptoCurrency represents CRYPTO coin or token.

func (CryptoCurrency) ChooseContractAddress

func (c CryptoCurrency) ChooseContractAddress(isTest bool) string

ChooseContractAddress returns contract address and tries to return specific contract for testnet if present

func (CryptoCurrency) ChooseNetwork

func (c CryptoCurrency) ChooseNetwork(isTest bool) string

func (CryptoCurrency) DisplayName

func (c CryptoCurrency) DisplayName() string

func (CryptoCurrency) MakeAmount

func (c CryptoCurrency) MakeAmount(raw string) (Money, error)

func (CryptoCurrency) MakeAmountFromBigInt added in v0.3.0

func (c CryptoCurrency) MakeAmountFromBigInt(amount *big.Int) (Money, error)

type CryptoCurrencyType

type CryptoCurrencyType string
const (
	Coin  CryptoCurrencyType = "coin"
	Token CryptoCurrencyType = "token"
)

type FiatCurrency

type FiatCurrency string

FIAT ------------------

const EUR FiatCurrency = "EUR"
const USD FiatCurrency = "USD"

func MakeFiatCurrency

func MakeFiatCurrency(s string) (FiatCurrency, error)

func (FiatCurrency) MakeAmount

func (f FiatCurrency) MakeAmount(raw string) (Money, error)

func (FiatCurrency) String

func (f FiatCurrency) String() string

type Money

type Money struct {
	// contains filtered or unexported fields
}

func CryptoFromFloat64

func CryptoFromFloat64(ticker string, f float64, decimals int64) (Money, error)

func CryptoFromRaw

func CryptoFromRaw(ticker, value string, decimals int64) (Money, error)

func CryptoFromStringFloat

func CryptoFromStringFloat(ticker, floatString string, decimals int64) (Money, error)

CryptoFromStringFloat constructs crypto from floats string e.g. "0.042"

func CryptoToFiat

func CryptoToFiat(crypto Money, fiat FiatCurrency, exchangeRate float64) (Money, error)

func FiatFromFloat64

func FiatFromFloat64(ticker FiatCurrency, f float64) (Money, error)

func MustCryptoFromRaw

func MustCryptoFromRaw(ticker, value string, decimals int64) Money

func New

func New(moneyType Type, ticker, value string, decimals int64) (Money, error)

func NewFromBigInt

func NewFromBigInt(moneyType Type, ticker string, bigInt *big.Int, decimals int64) (Money, error)

func (Money) Add

func (m Money) Add(amount Money) (Money, error)

Add adds money of the same type.

func (Money) BigInt

func (m Money) BigInt() (*big.Int, int64)

nolint:gocritic

func (Money) CompatibleTo

func (m Money) CompatibleTo(b Money) bool

func (Money) Decimals

func (m Money) Decimals() int64

func (Money) Equals

func (m Money) Equals(b Money) bool

func (Money) FiatToFloat64

func (m Money) FiatToFloat64() (float64, error)

func (Money) GreaterThan

func (m Money) GreaterThan(b Money) bool

func (Money) GreaterThanOrEqual

func (m Money) GreaterThanOrEqual(b Money) bool

func (Money) IsNegative

func (m Money) IsNegative() bool

func (Money) IsPositive

func (m Money) IsPositive() bool

func (Money) IsZero

func (m Money) IsZero() bool

func (Money) LessThan

func (m Money) LessThan(b Money) bool

func (Money) LessThanOrEqual

func (m Money) LessThanOrEqual(b Money) bool

func (Money) MultiplyFloat64

func (m Money) MultiplyFloat64(by float64) (Money, error)

func (Money) MultiplyInt64

func (m Money) MultiplyInt64(by int64) (Money, error)

MultiplyInt64 has less error than MultiplyFloat64

func (Money) String

func (m Money) String() string

func (Money) StringRaw

func (m Money) StringRaw() string

func (Money) Sub

func (m Money) Sub(amount Money) (Money, error)

Sub subtracts money of the same type. Restricts having negative values.

func (Money) SubNegative added in v0.6.0

func (m Money) SubNegative(amount Money) (Money, error)

SubNegative subtracts money allowing negative outcome

func (Money) Ticker

func (m Money) Ticker() string

func (Money) Type

func (m Money) Type() Type

type Type

type Type string

MONEY ------------------

const (
	Fiat   Type = "fiat"
	Crypto Type = "crypto"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL