altcurrency

package
v0.0.0-...-762ab57 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: MPL-2.0 Imports: 10 Imported by: 10

Documentation

Overview

Package altcurrency provides an enum-like representation of acceptable cryptocurrencies as well as helper functions for tasks like validating addresses and converting currency units.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBTCAddressVersion

func GetBTCAddressVersion(str string) int

GetBTCAddressVersion returns the BTC address version of the address str.

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data. Copied from https://github.com/ethereum/go-ethereum/, licensed under the GNU General Public License v3.0

func ToChecksumETHAddress

func ToChecksumETHAddress(str string) string

ToChecksumETHAddress returns the address str with a checksum encoded in the capitalization per EIP55

Types

type AltCurrency

type AltCurrency int

AltCurrency is an enum-like representing a cryptocurrency FIXME change this to a struct instead of a type alias?

const (

	// BAT Basic Attention Token
	BAT AltCurrency
	// BTC Bitcoin
	BTC
	// ETH Ethereum
	ETH
	// LTC Litecoin
	LTC
)

func FromString

func FromString(text string) (AltCurrency, error)

FromString returns the corresponding AltCurrency or error if there is none

func (AltCurrency) FromProbi

func (a AltCurrency) FromProbi(v decimal.Decimal) decimal.Decimal

FromProbi converts v, denominated in subunits to base units of AltCurrency a.

func (AltCurrency) IsValid

func (a AltCurrency) IsValid() bool

IsValid returns true if a is a valid AltCurrency.

func (*AltCurrency) MarshalText

func (a *AltCurrency) MarshalText() (text []byte, err error)

MarshalText marshalls the altcurrency into text.

func (AltCurrency) Scale

func (a AltCurrency) Scale() decimal.Decimal

Scale returns the scalar used to convert between the subunit and the base unit. For example in bitcoin this will be 10^8, as there are 10^8 satoshis (subunit) in one bitcoin (base unit). https://en.wikipedia.org/wiki/Denomination_(currency)#Subunit_and_super_unit

func (AltCurrency) String

func (a AltCurrency) String() string

func (AltCurrency) ToProbi

func (a AltCurrency) ToProbi(v decimal.Decimal) decimal.Decimal

ToProbi converts v, denominated in base units to sub units of AltCurrency a.

func (*AltCurrency) UnmarshalText

func (a *AltCurrency) UnmarshalText(text []byte) (err error)

UnmarshalText unmarshalls the altcurrency from text.

Jump to

Keyboard shortcuts

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