amt

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount int64

Amount represents the base bitcoin monetary unit (colloquially referred to as a `Satoshi'). A single Amount is equal to 1e-8 of a bitcoin.

const (
	// SatoshiPerBitcent is the number of satoshi in one bitcoin cent.
	SatoshiPerBitcent Amount = 1e6
	// SatoshiPerBitcoin is the number of satoshi in one bitcoin (1 DUO).
	SatoshiPerBitcoin Amount = 1e8
	// MaxSatoshi is the maximum transaction amount allowed in satoshi.
	MaxSatoshi = 21e6 * SatoshiPerBitcoin
)

func NewAmount

func NewAmount(f float64) (Amount, error)

NewAmount creates an Amount from a floating point value representing some value in bitcoin. NewAmount errors if f is NaN or +-Infinity, but does not check that the amount is within the total amount of bitcoin producible as f may not refer to an amount at a single moment in time. NewAmount is for specifically for converting DUO to Satoshi. For creating a new Amount with an int64 value which denotes a quantity of Satoshi, do a simple type conversion from type int64 to Amount. See GoDoc for example: http://godoc.org/github.com/p9c/monorepo/util#example-Amount

func (Amount) Format

func (a Amount) Format(u Unit) string

Format formats a monetary amount counted in bitcoin base units as a string for a given unit. The conversion will succeed for any unit, however, known units will be formated with an appended label describing the units with SI notation, or "Satoshi" for the base unit.

func (Amount) Int64

func (a Amount) Int64() int64

func (Amount) MulF64

func (a Amount) MulF64(f float64) Amount

MulF64 multiplies an Amount by a floating point value. While this is not an operation that must typically be done by a full node or wallet, it is useful for services that podbuild on top of bitcoin (for example, calculating a fee by multiplying by a percentage).

func (Amount) String

func (a Amount) String() string

String is the equivalent of calling Format with AmountDUO.

func (Amount) ToDUO

func (a Amount) ToDUO() float64

ToDUO is the equivalent of calling ToUnit with AmountDUO.

func (Amount) ToUnit

func (a Amount) ToUnit(u Unit) float64

ToUnit converts a monetary amount counted in bitcoin base units to a floating point value representing an amount of bitcoin.

type Unit

type Unit int

Unit describes a method of converting an Amount to something other than the base unit of a bitcoin. The value of the AmountUnit is the exponent component of the decadic multiple to convert from an amount in bitcoin to an amount counted in units.

const (
	MegaDUO  Unit = 6
	KiloDUO  Unit = 3
	DUO      Unit = 0
	MilliDUO Unit = -3
	MicroDUO Unit = -6
	Satoshi  Unit = -8
)

These constants define various units used when describing a bitcoin monetary amount.

func (Unit) String

func (u Unit) String() string

String returns the unit as a string. For recognized units, the SI prefix is used, or "Satoshi" for the base unit. For all unrecognized units, "1eN DUO" is returned, where N is the AmountUnit.

Jump to

Keyboard shortcuts

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