currency

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package currency implements conversion backends for different currencies used in a channel.

Use IsSupportedCurrency to check if the currency is supported and NewParser to obtain a parser for that currency.

Index

Constants

View Source
const (
	// ETHSymbol is the symbol for ethereum's native currency ETHSymbol.
	ETHSymbol = "ETH"

	// ETHMaxDecimals is the maximum number of decimal places allowed in ETH representation.
	ETHMaxDecimals uint8 = 18
)

Define symbol and max decimals for ETH, because there is no token contract for ETH, from which these details can be fetched from.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry added in v0.6.0

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

Registry implements a currency registry with currency parsers indexed by symbols.

It uses a slice to keep track of registered symbols because iterating over map to retrieve the symbols each time will result in different ordering of symbols in the list.

func NewRegistry added in v0.6.0

func NewRegistry() *Registry

NewRegistry initializes a currency registry.

func (*Registry) Currency added in v0.6.0

func (r *Registry) Currency(symbol string) perun.Currency

Currency returns the currency parser registered for the given currency symbol. If no parser is registered, it returns nil.

So, caller should do a nil check before using the currency parser.

func (*Registry) IsRegistered added in v0.6.0

func (r *Registry) IsRegistered(symbol string) bool

IsRegistered checks if there is parser registered for the currency represented by the given string.

func (*Registry) Register added in v0.6.0

func (r *Registry) Register(symbol string, maxDecimals uint8) (perun.Currency, error)

Register initializes a currency parser, registers it with the registry and returns it.

Returns an error if the parser is already registered.

func (*Registry) Symbols added in v0.6.0

func (r *Registry) Symbols() []string

Symbols returns a list of all the currencies registered in this module.

Directories

Path Synopsis
Package currencytest implements test helpers for functionalities defined in currency.
Package currencytest implements test helpers for functionalities defined in currency.

Jump to

Keyboard shortcuts

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