colored

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: Apache-2.0, BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ColorLength = ledgerstate.ColorLength

Variables

View Source
var Balances1Iota = NewBalancesForIotas(1)
View Source
var Balances1IotaL1 = map[ledgerstate.Color]uint64{ledgerstate.ColorIOTA: 1}

Functions

func Sort

func Sort(arr []Color)

func ToL1Map

func ToL1Map(bals Balances) map[ledgerstate.Color]uint64

Types

type Balances

type Balances map[Color]uint64

Balances represents a collection of balances associated to their respective Color that maintains a deterministic order of the present Colors.

func BalancesFromBytes

func BalancesFromBytes(data []byte) (Balances, error)

BalancesFromBytes unmarshals Balances from a sequence of bytes.

func BalancesFromDict

func BalancesFromDict(d dict.Dict) (Balances, error)

func BalancesFromL1Balances

func BalancesFromL1Balances(cb *ledgerstate.ColoredBalances) Balances

BalancesFromL1Balances creates Balances from ledgerstate.ColoredBalances

func BalancesFromL1Map

func BalancesFromL1Map(cb map[ledgerstate.Color]uint64) Balances

BalancesFromL1Map creates Balances from map[ledgerstate.Color]uint64

func BalancesFromMarshalUtil

func BalancesFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (Balances, error)

BalancesFromMarshalUtil unmarshals Balances using a MarshalUtil (for easier unmarshaling).

func NewBalances

func NewBalances() Balances

NewBalances returns a new Balances. In general, it has not deterministic order

func NewBalancesForColor

func NewBalancesForColor(col Color, s uint64) Balances

func NewBalancesForIotas

func NewBalancesForIotas(s uint64) Balances

func OutputBalancesByColor

func OutputBalancesByColor(outputs []ledgerstate.Output) (Balances, uint64)

func (Balances) Add

func (c Balances) Add(col Color, bal uint64) Balances

func (Balances) AddAll

func (c Balances) AddAll(another Balances)

func (Balances) Bytes

func (c Balances) Bytes() []byte

Bytes returns a marshaled version of the Balances.

func (Balances) Clone

func (c Balances) Clone() Balances

Clone returns a copy of the Balances.

func (Balances) Diff

func (c Balances) Diff(another Balances) map[Color]int64

Diff returns difference between two Balances color-by-color

func (Balances) Equals

func (c Balances) Equals(another Balances) bool

func (Balances) ForEachRandomly

func (c Balances) ForEachRandomly(consumer func(col Color, bal uint64) bool)

ForEach calls the consumer for each element in the collection and aborts the iteration if the consumer returns false. Non-deterministic order of iteration

func (Balances) ForEachSorted

func (c Balances) ForEachSorted(consumer func(col Color, bal uint64) bool)

ForEach calls the consumer for each element in the collection and aborts the iteration if the consumer returns false. Deterministic order of iteration

func (Balances) Get

func (c Balances) Get(color Color) uint64

Get returns the balance of the given Color. 0 means balance is empty

func (Balances) IsEmpty

func (c Balances) IsEmpty() bool

func (Balances) Set

func (c Balances) Set(col Color, bal uint64) Balances

Get returns the balance of the given Color.

func (Balances) String

func (c Balances) String() string

String returns a human readable version of the Balances.

func (Balances) SubNoOverflow

func (c Balances) SubNoOverflow(col Color, bal uint64) Balances

SubNoOverflow securely subtracts amount from color balance. Set to 0 is subtracted amount > existing

type Color

type Color [ColorLength]byte

Color is abstract color code used in ISCP. It can be mapped into specific implementations of Goshimmer or Chrysalis by calling Init

func ColorFromBase58EncodedString

func ColorFromBase58EncodedString(base58String string) (ret Color, err error)

ColorFromBase58EncodedString creates a Color from a base58 encoded string.

func ColorFromBytes

func ColorFromBytes(colorBytes []byte) (ret Color, err error)

ColorFromBytes unmarshals a Color from a sequence of bytes.

func ColorFromL1Color

func ColorFromL1Color(col ledgerstate.Color) (ret Color)

func ColorFromMarshalUtil

func ColorFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (ret Color, err error)

ColorFromMarshalUtil unmarshals a Color using a MarshalUtil (for easier unmarshaling).

func ColorRandom

func ColorRandom() (ret Color)

func (*Color) Base58

func (c *Color) Base58() string

Base58 returns a base58 encoded version of the Color.

func (*Color) Bytes

func (c *Color) Bytes() []byte

Bytes marshals the Color into a sequence of bytes.

func (*Color) Clone

func (c *Color) Clone() (ret Color)

func (*Color) Compare

func (c *Color) Compare(another *Color) int

func (*Color) String

func (c *Color) String() string

String creates a human readable string of the Color.

Jump to

Keyboard shortcuts

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