nano

package
v0.0.0-...-6c241ae Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package nano provides a number of useful types for Nano like Address and Balance. The actual implementation of the Nano protocol an be found in sub-packages.

Index

Constants

View Source
const (
	// AddressLen represents the string length of a Nano address.
	AddressLen = 64
	// AddressLenOld represents the string length of an old Nano address.
	AddressLenOld = 65
	// AddressSize represents the binary size of a Nano address (a public key).
	AddressSize = ed25519.PublicKeySize
	// AddressPrefix is the prefix of Nano addresses.
	AddressPrefix = "nano_"
	// AddressPrefixOld is the old prefix of Nano addresses.
	AddressPrefixOld = "xrb_"

	// AddressEncodingAlphabet is Nano's custom alphabet for base32 encoding
	AddressEncodingAlphabet = "13456789abcdefghijkmnopqrstuwxyz"
)
View Source
const (
	// BalanceSize represents the size of a balance in bytes.
	BalanceSize         = 16
	BalanceMaxPrecision = 33
)

Variables

View Source
var (
	// AddressEncoding is a base32 encoding using NanoEncodingAlphabet as its
	// alphabet.
	AddressEncoding = base32.NewEncoding(AddressEncodingAlphabet)

	ErrAddressLen      = errors.New("bad address length")
	ErrAddressPrefix   = errors.New("bad address prefix")
	ErrAddressEncoding = errors.New("bad address encoding")
	ErrAddressChecksum = errors.New("bad address checksum")
)
View Source
var (
	ZeroBalance = Balance(uint128.Uint128{})

	ErrBadBalanceSize = errors.New("balances should be 16 bytes in size")
)

Functions

This section is empty.

Types

type Address

type Address [AddressSize]byte

Address represents a Nano address.

func ParseAddress

func ParseAddress(s string) (Address, error)

ParseAddress parses the given Nano address string to a public key.

func (Address) Checksum

func (a Address) Checksum() []byte

Checksum calculates the checksum for this address' public key.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Address) String

func (a Address) String() string

String implements the fmt.Stringer interface.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Address) Verify

func (a Address) Verify(data []byte, signature []byte) bool

Verify reports whether the given signature is valid for the given data.

type Balance

type Balance uint128.Uint128

func ParseBalance

func ParseBalance(s string, unit string) (Balance, error)

ParseBalance parses the given balance string.

func ParseBalanceInts

func ParseBalanceInts(hi uint64, lo uint64) Balance

func (Balance) Add

func (b Balance) Add(n Balance) Balance

func (Balance) BigInt

func (b Balance) BigInt() *big.Int

func (Balance) Bytes

func (b Balance) Bytes(order binary.ByteOrder) []byte

Bytes returns the binary representation of this Balance with the given endianness.

func (Balance) Compare

func (b Balance) Compare(n Balance) BalanceComp

func (Balance) Equal

func (b Balance) Equal(b2 Balance) bool

Equal reports whether this balance and the given balance are equal.

func (Balance) MarshalBinary

func (b Balance) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Balance) MarshalText

func (b Balance) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Balance) String

func (b Balance) String() string

String implements the fmt.Stringer interface. It returns the balance in Mxrb with maximum precision.

func (Balance) Sub

func (b Balance) Sub(n Balance) Balance

func (Balance) UnitString

func (b Balance) UnitString(unit string, precision int32) string

UnitString returns a decimal representation of this uint128 converted to the given unit.

func (*Balance) UnmarshalBinary

func (b *Balance) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Balance) UnmarshalText

func (b *Balance) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type BalanceComp

type BalanceComp byte
const (
	BalanceCompEqual BalanceComp = iota
	BalanceCompBigger
	BalanceCompSmaller
)

Directories

Path Synopsis
Package block provides implementations for Nano's block types.
Package block provides implementations for Nano's block types.
Package crypto provides some helpful crypto functions (used internally).
Package crypto provides some helpful crypto functions (used internally).
ed25519
Package ed25519 implements the Ed25519 signature algorithm.
Package ed25519 implements the Ed25519 signature algorithm.
random
Package random provides some functions to securely generate random bytes and numbers.
Package random provides some functions to securely generate random bytes and numbers.
internal
Package node provides a node implementation that can participate in the Nano network.
Package node provides a node implementation that can participate in the Nano network.
proto
Package proto provides an implementation of the Nano network protocol.
Package proto provides an implementation of the Nano network protocol.
Package store provides a storage implementation for the Nano block lattice.
Package store provides a storage implementation for the Nano block lattice.
genesis
Package genesis provides the genesis constants for the live Nano network.
Package genesis provides the genesis constants for the live Nano network.
Package wallet provides some helpful wallet functionality like seed generation and key derivation.
Package wallet provides some helpful wallet functionality like seed generation and key derivation.

Jump to

Keyboard shortcuts

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